Skip to content

Commit

Permalink
Edit convert functions to output linear interpolation (#9107)
Browse files Browse the repository at this point in the history
* Edit convert functions to output linear interpolation

* Edit unit tests to reflect linear interpolation

* Refactor code to make it succint

* minor whitespace updates
  • Loading branch information
Jo-IE authored and mourner committed Dec 16, 2019
1 parent a5b76c8 commit dc3cfa2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/style-spec/function/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ function convertPropertyFunction(parameters, propertySpec, stops) {
];
} else if (type === 'exponential') {
const base = parameters.base !== undefined ? parameters.base : 1;
const expression = [getInterpolateOperator(parameters), ['exponential', base], ['number', get]];
const expression = [
getInterpolateOperator(parameters),
base === 1 ? ["linear"] : ["exponential", base],
["number", get]
];

for (const stop of stops) {
appendStopPair(expression, stop[0], stop[1], false);
}
Expand All @@ -177,7 +182,8 @@ function convertZoomFunction(parameters, propertySpec, stops, input = ['zoom'])
isStep = true;
} else if (type === 'exponential') {
const base = parameters.base !== undefined ? parameters.base : 1;
expression = [getInterpolateOperator(parameters), ['exponential', base], input];
expression = [getInterpolateOperator(parameters), base === 1 ? ["linear"] : ["exponential", base], input];

} else {
throw new Error(`Unknown zoom function type "${type}"`);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/style-spec/migrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test('converts stop functions to expressions', (t) => {
}, spec.latest.$version);
t.deepEqual(migrated.layers[0].paint['background-opacity'], [
'interpolate',
['exponential', 1],
['linear'],
['zoom'],
0,
1,
Expand All @@ -78,7 +78,7 @@ test('converts stop functions to expressions', (t) => {
]);
t.deepEqual(migrated.layers[1].paint['background-opacity'], [
'interpolate',
['exponential', 1],
['linear'],
['zoom'],
0,
['literal', [1, 2]],
Expand Down

1 comment on commit dc3cfa2

@DanielSeehausen
Copy link

Choose a reason for hiding this comment

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

🔥

Please sign in to comment.