Conversation
|
@jfirebaugh Discrete scales should be explicitly denoted by their |
|
Ok, now I pinky swear to not make any more commits to this PR |
test/test.js
Outdated
There was a problem hiding this comment.
What's the thinking behind supporting things like scale({mapbox: 1}, {mapbox: 3}), scale(3, {mapbox: 1}), and scale({mapbox: 1}, 3)?
There was a problem hiding this comment.
In the short term we're going to call a scale as scale(5, {mapbox: 1}) (where 5 is the zoom) but in the long term, we might want additional attributes like $hover or $time. This argument syntax gives us flexibility to pass in a bunch of different attributes without having to do too much object construction.
|
Nice work. There are a few stylistic nits that I'll give line-by-line comments for, and a few architectural issues. I still think we will want scales to be explicitly typed. I'll write up why in detail later. The API here has some features that I'm not sure are justified in terms of their cost-benefit:
Parameter passing and partial evaluationSee the discussion thread on mapbox/mapbox-gl-js#1267. I think we want this module to support partial evaluation of functions over what you elsewhere called "Global Attributes", which is a term I like. Example of proposed API use: This is nice because we can optimize the result of |
index.js
Outdated
There was a problem hiding this comment.
Don't mutate input parameters.
I have definitely come to agree with you here. I think specifying a
Ok! I'll do that.
I'm on board with dropping support for numeric arguments, automatically converted to The main goal with the
Dropping the The
Yup, this seems pretty obvious in retrospect. Next Steps
|
test/test.js
Outdated
There was a problem hiding this comment.
Add tests for:
- string-valued domains
- boolean-valued domains
Scale({domain: [1], range: [2], property: 'p'})({p: 'omg'})Scale({domain: ['A', 'B', 'C'], range: [1, 2, 3], property: 'p'})({p: 42})Scale({domain: ['A', 'B', 'C'], range: [1, 2, 3], property: 'p'})({p: 'D'})
What other corner cases are there?
|
API proposal: |
👍 -- perfect |
…mation to a separate function
|
@jfirebaugh Is this ready to go? |
index.js
Outdated
There was a problem hiding this comment.
Pull the inner function out so it's not creating a new one every time:
var constant = function() { return parameters; };
return function() { return constant; }
index.js
Outdated
There was a problem hiding this comment.
This is where partial evaluation is implemented:
var value = evaluate(parameters, attribute);
return function() { return value; }
…ons, added isConstant method
|
Ok! I made the changes you requested as well as
|
package.json
Outdated
There was a problem hiding this comment.
I'd like to merge mapbox/mapbox-gl-style-spec#290 before we merge this PR so that we can use the slightly more stable v8 branch as a dependency instead.
index.js
Outdated
There was a problem hiding this comment.
it would be useful to have isConstant on the outer function here
There was a problem hiding this comment.
Ok. I was just going with undefined == false but its probably good to be explicit here.
There was a problem hiding this comment.
oh, I didn't realize isConstant applies to the partial function so I was thinking it would be true.
When creating the buffers we don't need to evaluate the scale at all if it's zoom based. Right now there is no way to tell unless you evaluate the first half. It's probably fine performance-wise to always evaluate it, but it might be nice to not need not.
I was trying https://github.com/mapbox/mapbox-gl-js/blob/83ca3f19cf8fd428f3fa1338b0209292eb9a97a3/js/data/line_bucket.js#L19 but I guess I need to evaluate the first half always
There was a problem hiding this comment.
Makes sense. We could have isGlobalConstant / isFeatureConstant properties.
There was a problem hiding this comment.
Or would you rather have an isConstantWithRespectToZoom property?
There was a problem hiding this comment.
I think isFeatureConstant would be good for this case
There was a problem hiding this comment.
Cool! Added in the latest diff.
|
@jfirebaugh this is ready for 👀 |
|
|
|
@jfirebaugh Are we going to break anything by merging this into master right now? Maybe we should keep this in a separate branch for now or pin upstream dependencies to a specific tag of this repository |
|
Merging is safe. Dependent modules are using a versioned release from npm, so they will be fine. If integration in gl-js goes well, we'll publish the changes as v2.0.0. |
|
Ok, just bumped the version. Will merge as soon as CI passes. |
Add data driven styling capabilities
This pull request adds support for the new scale syntax including
domainandrangeproperties in addition tostepspropertyparameterroundingparameter for more flexible and explicit discrete scalescc @ansis @jfirebaugh