Repository navigation
Rework spec function/expression taxonomy - #6505
Conversation
anandthakker
left a comment
There was a problem hiding this comment.
This feels so much cleaner
| type ExpressionParameters = Array<'zoom' | 'feature' | 'heatmap-density' | 'line-progress'>; | ||
|
|
||
| type ExpressionSpecification = { | ||
| type: ExpressionType, |
There was a problem hiding this comment.
Looks like field is currently called property-type, not type
There was a problem hiding this comment.
It feels slightly weird to me to have property-type nested under expression. Would it make sense to move it up to the layout/paint property specification, and also add constant as one of the options for properties that can't take any expression? E.g.:
"visibility": {
"property-type": "constant",
// no "expression" field
"type": "enum",
/* ... */
}"line-cap": {
"property-type": "data-constant",
"expression": {
"interpolated": false,
"parameters": ["zoom"]
},
"type": "enum",
/* ... */
}Then we could always use propertySpec["property-type"] and never have to rely on the presence/absence of the "expression" field
| // @flow | ||
|
|
||
| export function isPropertyFunction(spec: Object): boolean { | ||
| const dataDrivenTypes = new Set(['data-driven', 'cross-faded-data-driven']); |
There was a problem hiding this comment.
I don't think we can use Set / Map, since they'd require polyfills for IE 😢
There was a problem hiding this comment.
Ah, this would have showed up in the style-spec build test, but it's not getting run on CI 😬 #6433
|
|
||
| export function isZoomFunction(spec: Object): boolean { | ||
| return spec.expression && spec.expression.parameters.indexOf('zoom') > -1; | ||
| } |
There was a problem hiding this comment.
Rename to isPropertyExpression and isZoomExpression?
| return `ColorRampProperty`; | ||
| case 'data-constant': | ||
| default: | ||
| return `DataConstantProperty<${flowType(property)}>`; |
There was a problem hiding this comment.
Just for completeness, should we also list case 'constant': here? (Alternatively, since DataConstantProperty<T> isn't really intended to represent a totally constant property, it could be case 'constant': throw new Error("Constant properties unimplemented");)
| return `new ColorRampProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`; | ||
| case 'data-constant': | ||
| default: | ||
| return `new DataConstantProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`; |
| @@ -0,0 +1,13 @@ | |||
| // @flow | |||
|
|
|||
| export function isPropertyExpression(spec: Object): boolean { | |||
There was a problem hiding this comment.
isPropertyExpression → supportsPropertyExpressions -- or something similar that doesn't imply that the function is testing whether the input itself is a property expression. (Similarly for isZoomExpression and isInterpolated.)
Also, can spec be typed as StylePropertySpecification?
| return parameters.type; | ||
| } else if (propertySpec.function) { | ||
| return propertySpec.function === 'interpolated' ? 'exponential' : 'interval'; | ||
| } else if (propertySpec.expression) { |
There was a problem hiding this comment.
Should this be asserting propertySpec.expression? We shouldn't be trying to create a function for something that doesn't support expressions.
There was a problem hiding this comment.
👍 this was a bad workaround for a flow error — will fix.
This PR reworks the taxonomy to describe how a property can use functions/expressions, as described in #6389 (comment) and #6389 (comment):
so now any property all properties include a
property-typekey, and for all property-types exceptconstantalso anexpressionproperty, i.e.Benchmarks: http://bl.ocks.org/lbud/raw/2ac3b8869074c112802166978cea8345/ (I couldn't reproduce the Layer discrepancies on subsequent isolated bench runs).
Closes #6389
Supersedes / closes #4194
Refs #6430
Refs #6303
Launch Checklist