From 321683789915245ca937236c9b4d544a0a42a569 Mon Sep 17 00:00:00 2001 From: Xiaoji Chen Date: Thu, 20 Sep 2018 23:09:44 -0700 Subject: [PATCH] Fix `getY0` prop on AreaSeries (#971) --- src/utils/scales-utils.js | 9 +++++---- tests/utils/scales-utils-tests.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/utils/scales-utils.js b/src/utils/scales-utils.js index 443848159..f4b5bef9a 100644 --- a/src/utils/scales-utils.js +++ b/src/utils/scales-utils.js @@ -242,7 +242,8 @@ function _createScaleObjectForValue(attr, value, type, accessor, accessor0) { attr, baseValue: undefined, isValue: true, - accessor + accessor, + accessor0 }; } if (typeof value === 'undefined') { @@ -256,7 +257,8 @@ function _createScaleObjectForValue(attr, value, type, accessor, accessor0) { attr, baseValue: undefined, isValue: true, - accessor + accessor, + accessor0 }; } @@ -648,12 +650,11 @@ export function getAttributeFunctor(props, attr) { export function getAttr0Functor(props, attr) { const scaleObject = getScaleObjectFromProps(props, attr); if (scaleObject) { - const attr0 = `${attr}0`; const {domain} = scaleObject; const {baseValue = domain[0]} = scaleObject; const scaleFn = getScaleFnFromScaleObject(scaleObject); return d => { - const value = _getAttrValue(d, el => el[attr0]); + const value = _getAttrValue(d, scaleObject.accessor0); return scaleFn(_isDefined(value) ? value : baseValue); }; } diff --git a/tests/utils/scales-utils-tests.js b/tests/utils/scales-utils-tests.js index 807e26589..7c5f559d5 100644 --- a/tests/utils/scales-utils-tests.js +++ b/tests/utils/scales-utils-tests.js @@ -152,6 +152,17 @@ test('scales-utils #getAttributeFunctor', t => { 225, 'should find the correct transformed value' ); + + // with custom accessor + result = getAttributeFunctor({xRange, xDomain, getX: d => d.value}, 'x'); + t.ok(typeof result === 'function', 'Result should be a function'); + + t.equal( + result({data: {x: 10, value: 1}}), + 0, + 'should find the correct transformed value' + ); + t.end(); }); @@ -190,6 +201,25 @@ test('scales-utils #getAttr0Functor', t => { 'should find the correct transformed value' ); + // with custom accessor + result = getAttr0Functor( + { + xRange, + _allData: exNaughtData, + getX0: d => d.z, + xDomain, + xType: 'literal', + xDistance + }, + 'x' + ); + t.ok(typeof result === 'function', 'Result should be a function'); + t.equal( + result({data: {x: 10, x0: 5, z: 1}}), + 1, + 'should find the correct transformed value' + ); + // now with a linear scale result = getAttr0Functor( {