-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Rework spec function/expression taxonomy #6505
Conversation
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.
This feels so much cleaner
src/style-spec/style-spec.js
Outdated
type ExpressionParameters = Array<'zoom' | 'feature' | 'heatmap-density' | 'line-progress'>; | ||
|
||
type ExpressionSpecification = { | ||
type: ExpressionType, |
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.
Looks like field is currently called property-type
, not type
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.
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
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.
Sounds good to me @anandthakker!
src/style-spec/util/properties.js
Outdated
// @flow | ||
|
||
export function isPropertyFunction(spec: Object): boolean { | ||
const dataDrivenTypes = new Set(['data-driven', 'cross-faded-data-driven']); |
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 don't think we can use Set / Map, since they'd require polyfills for IE 😢
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.
Ah, this would have showed up in the style-spec build test, but it's not getting run on CI 😬 #6433
src/style-spec/util/properties.js
Outdated
|
||
export function isZoomFunction(spec: Object): boolean { | ||
return spec.expression && spec.expression.parameters.indexOf('zoom') > -1; | ||
} |
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.
Rename to isPropertyExpression
and isZoomExpression
?
build/generate-style-code.js
Outdated
return `ColorRampProperty`; | ||
case 'data-constant': | ||
default: | ||
return `DataConstantProperty<${flowType(property)}>`; |
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.
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");
)
build/generate-style-code.js
Outdated
return `new ColorRampProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`; | ||
case 'data-constant': | ||
default: | ||
return `new DataConstantProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`; |
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.
Same as above
src/style-spec/util/properties.js
Outdated
@@ -0,0 +1,13 @@ | |||
// @flow | |||
|
|||
export function isPropertyExpression(spec: Object): boolean { |
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.
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
?
src/style-spec/function/convert.js
Outdated
@@ -236,8 +236,8 @@ function appendStopPair(curve, input, output, isStep) { | |||
function getFunctionType(parameters, propertySpec) { | |||
if (parameters.type) { | |||
return parameters.type; | |||
} else if (propertySpec.function) { | |||
return propertySpec.function === 'interpolated' ? 'exponential' : 'interval'; | |||
} else if (propertySpec.expression) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 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-type
key, and for all property-types exceptconstant
also anexpression
property, 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