From 4c13350c14376706735cc69c5d9f25f9fc8a78a0 Mon Sep 17 00:00:00 2001 From: Robin Summerhill Date: Wed, 3 Oct 2018 20:11:53 +0100 Subject: [PATCH] Issue #380 - fix for data functions --- src/components/fields/FunctionSpecField.jsx | 18 +++++++++++++++--- src/components/fields/_DataProperty.jsx | 8 ++++---- src/components/fields/_FunctionButtons.jsx | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/components/fields/FunctionSpecField.jsx b/src/components/fields/FunctionSpecField.jsx index 3067c1b..36d7930 100644 --- a/src/components/fields/FunctionSpecField.jsx +++ b/src/components/fields/FunctionSpecField.jsx @@ -32,6 +32,16 @@ export default class FunctionSpecProperty extends React.Component { ]), } + getFieldFunctionType(fieldSpec) { + if (fieldSpec.expression.interpolated) { + return "exponential" + } + if (fieldSpec.type === "number") { + return "interval" + } + return "categorical" + } + addStop = () => { const stops = this.props.value.stops.slice(0) const lastStop = stops[stops.length - 1] @@ -80,12 +90,14 @@ export default class FunctionSpecProperty extends React.Component { } makeDataFunction = () => { + const functionType = this.getFieldFunctionType(this.props.fieldSpec); + const stopValue = functionType === 'categorical' ? '' : 0; const dataFunc = { property: "", - type: "categorical", + type: functionType, stops: [ - [{zoom: 6, value: 0}, this.props.value], - [{zoom: 10, value: 0}, this.props.value] + [{zoom: 6, value: stopValue}, this.props.value || stopValue], + [{zoom: 10, value: stopValue}, this.props.value || stopValue] ] } this.props.onChange(this.props.fieldName, dataFunc) diff --git a/src/components/fields/_DataProperty.jsx b/src/components/fields/_DataProperty.jsx index 9fa1e44..4116031 100644 --- a/src/components/fields/_DataProperty.jsx +++ b/src/components/fields/_DataProperty.jsx @@ -30,7 +30,7 @@ export default class DataProperty extends React.Component { } getFieldFunctionType(fieldSpec) { - if (fieldSpec.function === "interpolated") { + if (fieldSpec.expression.interpolated) { return "exponential" } if (fieldSpec.type === "number") { @@ -39,8 +39,8 @@ export default class DataProperty extends React.Component { return "categorical" } - getDataFunctionTypes(functionType) { - if (functionType === "interpolated") { + getDataFunctionTypes(fieldSpec) { + if (fieldSpec.expression.interpolated) { return ["categorical", "interval", "exponential"] } else { @@ -150,7 +150,7 @@ export default class DataProperty extends React.Component { this.changeDataProperty("type", propVal)} - options={this.getDataFunctionTypes(this.props.fieldSpec.function)} + options={this.getDataFunctionTypes(this.props.fieldSpec)} /> diff --git a/src/components/fields/_FunctionButtons.jsx b/src/components/fields/_FunctionButtons.jsx index 9975613..ffd6552 100644 --- a/src/components/fields/_FunctionButtons.jsx +++ b/src/components/fields/_FunctionButtons.jsx @@ -28,7 +28,7 @@ export default class FunctionButtons extends React.Component { /> - if (this.props.fieldSpec['property-function'] && ['piecewise-constant', 'interpolated'].indexOf(this.props.fieldSpec['function']) !== -1) { + if (this.props.fieldSpec['property-type'] === 'data-driven') { makeDataButton =