From dc3cfa2318eed11b43746a159ec9b22e90218e48 Mon Sep 17 00:00:00 2001 From: Jo Date: Mon, 16 Dec 2019 16:33:49 +0100 Subject: [PATCH] Edit convert functions to output linear interpolation (#9107) * Edit convert functions to output linear interpolation * Edit unit tests to reflect linear interpolation * Refactor code to make it succint * minor whitespace updates --- src/style-spec/function/convert.js | 10 ++++++++-- test/unit/style-spec/migrate.test.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/style-spec/function/convert.js b/src/style-spec/function/convert.js index e248b9f0e5a..a177604b953 100644 --- a/src/style-spec/function/convert.js +++ b/src/style-spec/function/convert.js @@ -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); } @@ -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}"`); } diff --git a/test/unit/style-spec/migrate.test.js b/test/unit/style-spec/migrate.test.js index 441e9037673..f6581dc4a18 100644 --- a/test/unit/style-spec/migrate.test.js +++ b/test/unit/style-spec/migrate.test.js @@ -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, @@ -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]],