Skip to content
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

Add "default" property for functions #4175

Merged
merged 4 commits into from
Feb 3, 2017
Merged

Add "default" property for functions #4175

merged 4 commits into from
Feb 3, 2017

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented Feb 2, 2017

It is used in the following circumstances:

  • In categorical functions, when the feature value does not match any of the stop domain values.
  • In property and zoom-and-property functions, when a feature does not contain a value for the specified property.
  • In identity functions, when the feature value is not valid for the style property (for example, if the function is being used for a circle-color property but the feature property value is not a string or not a valid color).
  • In interval or exponential property and zoom-and-property functions, when the feature value is not numeric.

If no default is provided, the style property's default is used in these circumstances.

Implementing this required breaking changes to the function API in mapbox-gl-style-spec. The export is now a function which accepts the function definition and the spec JSON for a style property. It handles color parsing and validation of feature values internally.

Fixes #4124
Fixes #4144
Fixes #4146
Fixes #4150
Fixes #4018

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
benchmark master fac6358 function-default a90eaeb
map-load 223 ms 99 ms
style-load 77 ms 77 ms
buffer 1,026 ms 1,036 ms
fps 60 fps 60 fps
frame-duration 3.2 ms, 0% > 16ms 3.1 ms, 0% > 16ms
query-point 0.87 ms 0.89 ms
query-box 64.55 ms 66.92 ms
geojson-setdata-small 7 ms 6 ms
geojson-setdata-large 148 ms 179 ms

definition, and an object defining a style spec property. It handles color parsing and validation of feature values
internally.
* Functions now support a "default" property.
* `parseColor` was promoted from gl-js.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -20,15 +28,38 @@ function createFunction(parameters, defaultType) {
const zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
const featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
const zoomDependent = zoomAndFeatureDependent || !featureDependent;
const type = parameters.type || defaultType || 'exponential';
const type = parameters.type || (propertySpec.function === 'interpolated' ? 'exponential' : 'interval');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about renaming the propertySpec.function "enum" values now that this is part of our public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #4194 for what I think we should do there.

}
fun = function(zoom, feature) {
return outputFunction(evaluateExponentialFunction({
stops: featureFunctionStops,
base: parameters.base
}, zoom)(zoom, feature));
}, propertySpec, zoom)(zoom, feature));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to pass propertySpec to evaluateExponentialFunction both as an argument and embedded within featureFunctionStops?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I misread the code. This is 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it embedded within featureFunctionStops?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oop, didn't see your followup comment. 👍

// Special case for fill-outline-color, which has no spec default.
if (evaluatedLower === undefined || evaluatedUpper === undefined) {
return undefined;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref #4088

package.json Outdated
@@ -16,8 +16,6 @@
"@mapbox/unitbezier": "^0.0.0",
"brfs": "^1.4.0",
"bubleify": "^0.5.1",
"csscolorparser": "^1.0.2",
"csscolorparser": "~1.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't currently install the dependencies from js/style-spec/package.json so this may still be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what this does?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Yes. The postinstall hook. 🚢

* No more than one level of nesting
* Remove nonsensical or redundant tests
* Use correct terminology
* Test identity functions properly
* Complete test coverage
If the text-field property is data-driven, the value of layout['text-field'] is not defined.
It is used in the following circumstances:

* In categorical functions, when the feature value does not match any of the stop domain values.
* In property and zoom-and-property functions, when a feature does not contain a value for the specified property.
* In identity functions, when the feature value is not valid for the style property (for example, if the function is being used for a `circle-color` property but the feature property value is not a string or not a valid color).
* In interval or exponential property and zoom-and-property functions, when the feature value is not numeric.

If no default is provided, the style property's default is used in these circumstances.

Implementing this required breaking changes to the function API in mapbox-gl-style-spec. The export is now a function which accepts the function definition and the spec JSON for a style property. It handles color parsing and validation of feature values internally.
const textFont = layout['text-font'];
const iconImage = layout['icon-image'];

const hasText = layout['text-field'] && textFont;
const hasText = textFont && (!layer.isLayoutValueFeatureConstant('text-field') || layout['text-field']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the text-field property is data-driven, the value of layout['text-field'] is not defined.

@jfirebaugh ah, whoops - I made the bad assumption that layout contained the style JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants