Merge pull request #406 from emuanalytics/bug/#380

Fix for Issue #380
This commit is contained in:
Orange Mug 2018-10-06 13:18:31 +01:00 committed by GitHub
commit c8a004422f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -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 = () => { addStop = () => {
const stops = this.props.value.stops.slice(0) const stops = this.props.value.stops.slice(0)
const lastStop = stops[stops.length - 1] const lastStop = stops[stops.length - 1]
@ -80,12 +90,14 @@ export default class FunctionSpecProperty extends React.Component {
} }
makeDataFunction = () => { makeDataFunction = () => {
const functionType = this.getFieldFunctionType(this.props.fieldSpec);
const stopValue = functionType === 'categorical' ? '' : 0;
const dataFunc = { const dataFunc = {
property: "", property: "",
type: "categorical", type: functionType,
stops: [ stops: [
[{zoom: 6, value: 0}, this.props.value], [{zoom: 6, value: stopValue}, this.props.value || stopValue],
[{zoom: 10, value: 0}, this.props.value] [{zoom: 10, value: stopValue}, this.props.value || stopValue]
] ]
} }
this.props.onChange(this.props.fieldName, dataFunc) this.props.onChange(this.props.fieldName, dataFunc)

View file

@ -30,7 +30,7 @@ export default class DataProperty extends React.Component {
} }
getFieldFunctionType(fieldSpec) { getFieldFunctionType(fieldSpec) {
if (fieldSpec.function === "interpolated") { if (fieldSpec.expression.interpolated) {
return "exponential" return "exponential"
} }
if (fieldSpec.type === "number") { if (fieldSpec.type === "number") {
@ -39,8 +39,8 @@ export default class DataProperty extends React.Component {
return "categorical" return "categorical"
} }
getDataFunctionTypes(functionType) { getDataFunctionTypes(fieldSpec) {
if (functionType === "interpolated") { if (fieldSpec.expression.interpolated) {
return ["categorical", "interval", "exponential"] return ["categorical", "interval", "exponential"]
} }
else { else {
@ -150,7 +150,7 @@ export default class DataProperty extends React.Component {
<SelectInput <SelectInput
value={this.props.value.type} value={this.props.value.type}
onChange={propVal => this.changeDataProperty("type", propVal)} onChange={propVal => this.changeDataProperty("type", propVal)}
options={this.getDataFunctionTypes(this.props.fieldSpec.function)} options={this.getDataFunctionTypes(this.props.fieldSpec)}
/> />
</div> </div>
</div> </div>

View file

@ -28,7 +28,7 @@ export default class FunctionButtons extends React.Component {
/> />
</Button> </Button>
if (this.props.fieldSpec['property-function'] && ['piecewise-constant', 'interpolated'].indexOf(this.props.fieldSpec['function']) !== -1) { if (this.props.fieldSpec['property-type'] === 'data-driven') {
makeDataButton = <Button makeDataButton = <Button
className="maputnik-make-data-function" className="maputnik-make-data-function"
onClick={this.props.onDataClick} onClick={this.props.onDataClick}