-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds numeric value comparison filters #79
base: master
Are you sure you want to change the base?
Conversation
Added numeric value comparison filters for ">", "<", ">=", and "<=".
Added numeric value comparison filters
@MikeGodin this looks great. Thanks for the PR! The failing CI seems to be package rot isolated to node v0.8. We should be able to safely ignore it for this PR. Mind if I ask how you're using Nodetiles? |
@bensheldon, I'm using nodetiles to generate chloropleth maps based on data attached to US census block groups... hence the need for numeric filters. |
if (feature.properties[filter.key] !== filter.val) { | ||
return false; | ||
} | ||
break; | ||
case "<": | ||
if (feature.properties[filter.key] >= filter.val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing the obvious, but why not use the same comparison operator that you’re handling? (e.g. do feature.properties[filter.key] < filter.val
here because you are evaluating ">"
instead of >=
.) What you’ve got is technically equivalent, so it works, but makes reading it a bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, nevermind, that was a dumb comment. Ignore me :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filters work by returning early from the property loop based on a single false
match, rather than iterating over the entire set of properties to ensure they all are true
.
I don't know if it would be more performant to use a true functional method, but it's following the pattern of the previous implementation of the =
matcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that’s what I realized right after posting. Too distracted this morning, I guess. Also been a while since I wrote this :P
I think encapsulating each of the kinds of tests in this method might be better for reading, though it would be slower. Either way, not really in the scope of work for this PR. My bad.
Can you add some tests? Otherwise, this looks pretty great to me. |
(And thanks for contributing, @MikeGodin!) |
Not to detract from the awesome primary repo, but we also have some changes in LocalData/nodetiles-core that might be relevant/helpful for @MikeGodin. Most of our work there is considered "experimental", and I know there's at least one place we compromised on compatibility for performance, so we haven't done the work to port changes back to nodetiles/nodetiles-core. Sorry @bensheldon! |
@bensheldon Should we just kill the 0.8 tests on Travis? Seems old enough now it might not be worth supporting. (By the way, I’ve noticed in several projects lately that NPM often has trouble resolving a workable set of dependencies for 0.8, so shrinkwrapping for the test environment might also be a good idea.) |
@MikeGodin if you need any pointers on the tests, let me know. BUT it should be as simple as dropping three files into
Then, in You don’t have to use the name “numericComparison” for all those. They just have to have the same name, whatever it is. |
Adds numeric value comparison filters for ">", "<", ">=", and "<=".