Skip to content

Commit

Permalink
Revert "Rework spec function/expression taxonomy" #6505
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick authored Apr 16, 2018
1 parent 77b9821 commit c01e491
Show file tree
Hide file tree
Showing 37 changed files with 734 additions and 1,463 deletions.
7 changes: 3 additions & 4 deletions build/generate-flow-typed-style-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const spec = require('../src/style-spec/reference/v8.json');
const properties = require('../src/style-spec/util/properties');
const fs = require('fs');

function flowEnum(values) {
Expand Down Expand Up @@ -41,11 +40,11 @@ function flowType(property) {
}
})();

if (properties.supportsPropertyExpression(property)) {
if (property['property-function']) {
return `DataDrivenPropertyValueSpecification<${baseType}>`;
} else if (properties.supportsZoomExpression(property)) {
} else if (property['zoom-function']) {
return `PropertyValueSpecification<${baseType}>`;
} else if (property.expression) {
} else if (property.function) {
return `ExpressionSpecification`;
} else {
return baseType;
Expand Down
3 changes: 1 addition & 2 deletions build/generate-struct-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,5 @@ ${arraysWithStructAccessors.map(structArrayJs).join('\n')}
export {
${layouts.map(layout => layout.className).join(',\n ')},
${[...arrayTypeEntries].join(',\n ')}
};
`);
};`);

44 changes: 20 additions & 24 deletions build/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ global.camelize = function (str) {
});
};

global.isDataDriven = function (property) {
return property['property-function'] === true;
};

global.flowType = function (property) {
switch (property.type) {
case 'boolean':
Expand All @@ -35,18 +39,14 @@ global.flowType = function (property) {
};

global.propertyType = function (property) {
switch (property['property-type']) {
case 'data-driven':
return `DataDrivenProperty<${flowType(property)}>`;
case 'cross-faded':
return `CrossFadedProperty<${flowType(property)}>`;
case 'color-ramp':
return `ColorRampProperty`;
case 'data-constant':
case 'constant':
return `DataConstantProperty<${flowType(property)}>`;
default:
throw new Error(`unknown property-type "${property['property-type']}" for ${property.name}`);
if (isDataDriven(property)) {
return `DataDrivenProperty<${flowType(property)}>`;
} else if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') {
return `CrossFadedProperty<${flowType(property)}>`;
} else if (property.name === 'heatmap-color' || property.name === 'line-gradient') {
return `ColorRampProperty`;
} else {
return `DataConstantProperty<${flowType(property)}>`;
}
};

Expand Down Expand Up @@ -91,18 +91,14 @@ global.defaultValue = function (property) {
};

global.propertyValue = function (property, type) {
switch (property['property-type']) {
case 'data-driven':
return `new DataDrivenProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
case 'cross-faded':
return `new CrossFadedProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
case 'color-ramp':
return `new ColorRampProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
case 'data-constant':
case 'constant':
return `new DataConstantProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
default:
throw new Error(`unknown property-type "${property['property-type']}" for ${property.name}`);
if (isDataDriven(property)) {
return `new DataDrivenProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
} else if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') {
return `new CrossFadedProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
} else if (property.name === 'heatmap-color' || property.name === 'line-gradient') {
return `new ColorRampProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
} else {
return `new DataConstantProperty(styleSpec["${type}_${property.layerType}"]["${property.name}"])`;
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"test-render": "node --max-old-space-size=2048 test/render.test.js",
"test-query": "node test/query.test.js",
"test-expressions": "build/run-node test/expression.test.js",
"test-flow": "build/run-node build/generate-flow-typed-style-spec && flow .",
"test-flow": "node build/generate-flow-typed-style-spec && flow .",
"test-flow-cov": "flow-coverage-report -i 'src/**/*.js' -t html",
"test-cov": "nyc --require=@mapbox/flow-remove-types/register --reporter=text-summary --reporter=lcov --cache run-s test-unit test-expressions test-query test-render",
"prepublish": "in-publish && run-s build-dev build-min || not-in-publish",
Expand Down
3 changes: 1 addition & 2 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { packUint8ToFloat } from '../shaders/encode_attribute';
import Color from '../style-spec/util/color';
import { supportsPropertyExpression } from '../style-spec/util/properties';
import { register } from '../util/web_worker_transfer';
import { PossiblyEvaluatedPropertyValue } from '../style/properties';
import { StructArrayLayout1f4, StructArrayLayout2f8, StructArrayLayout4f16 } from './array_types';
Expand Down Expand Up @@ -292,7 +291,7 @@ export default class ProgramConfiguration {
for (const property in layer.paint._values) {
if (!filterProperties(property)) continue;
const value = layer.paint.get(property);
if (!(value instanceof PossiblyEvaluatedPropertyValue) || !supportsPropertyExpression(value.property.specification)) {
if (!(value instanceof PossiblyEvaluatedPropertyValue) || !value.property.specification['property-function']) {
continue;
}
const name = paintAttributeName(property, layer.type);
Expand Down
7 changes: 3 additions & 4 deletions src/style-spec/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import definitions from './definitions';
import * as isConstant from './is_constant';
import RuntimeError from './runtime_error';
import { success, error } from '../util/result';
import { supportsPropertyExpression, supportsZoomExpression, supportsInterpolation } from '../util/properties';

import type {Type} from './types';
import type {Value} from './values';
Expand Down Expand Up @@ -208,12 +207,12 @@ export function createPropertyExpression(expression: mixed, propertySpec: StyleP
const parsed = expression.value.expression;

const isFeatureConstant = isConstant.isFeatureConstant(parsed);
if (!isFeatureConstant && !supportsPropertyExpression(propertySpec)) {
if (!isFeatureConstant && !propertySpec['property-function']) {
return error([new ParsingError('', 'property expressions not supported')]);
}

const isZoomConstant = isConstant.isGlobalPropertyConstant(parsed, ['zoom']);
if (!isZoomConstant && !supportsZoomExpression(propertySpec)) {
if (!isZoomConstant && propertySpec['zoom-function'] === false) {
return error([new ParsingError('', 'zoom expressions not supported')]);
}

Expand All @@ -222,7 +221,7 @@ export function createPropertyExpression(expression: mixed, propertySpec: StyleP
return error([new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.')]);
} else if (zoomCurve instanceof ParsingError) {
return error([zoomCurve]);
} else if (zoomCurve instanceof Interpolate && !supportsInterpolation(propertySpec)) {
} else if (zoomCurve instanceof Interpolate && propertySpec['function'] === 'piecewise-constant') {
return error([new ParsingError('', '"interpolate" expressions cannot be used with this property')]);
}

Expand Down
8 changes: 3 additions & 5 deletions src/style-spec/feature_filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ function isExpressionFilter(filter: any) {
const filterSpec = {
'type': 'boolean',
'default': false,
'property-type': 'data-driven',
'expression': {
'interpolated': true,
'parameters': ['zoom', 'feature']
}
'function': true,
'property-function': true,
'zoom-function': true
};

/**
Expand Down
5 changes: 3 additions & 2 deletions src/style-spec/function/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ 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 {
assert(propertySpec.expression);
return (propertySpec.expression: any).interpolated ? 'exponential' : 'interval';
return 'exponential';
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/style-spec/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import extend from '../util/extend';
import getType from '../util/get_type';
import * as interpolate from '../util/interpolate';
import Interpolate from '../expression/definitions/interpolate';
import { supportsInterpolation } from '../util/properties';

export function isFunction(value) {
return typeof value === 'object' && value !== null && !Array.isArray(value);
Expand All @@ -20,7 +19,7 @@ export function createFunction(parameters, propertySpec) {
const zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
const featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
const zoomDependent = zoomAndFeatureDependent || !featureDependent;
const type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
const type = parameters.type || (propertySpec.function === 'interpolated' ? 'exponential' : 'interval');

if (isColor) {
parameters = extend({}, parameters);
Expand Down
Loading

0 comments on commit c01e491

Please sign in to comment.