Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getY0 prop on AreaSeries #971

Merged
merged 4 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/utils/scales-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ function _createScaleObjectForValue(attr, value, type, accessor, accessor0) {
attr,
baseValue: undefined,
isValue: true,
accessor
accessor,
accessor0
};
}
if (typeof value === 'undefined') {
Expand All @@ -256,7 +257,8 @@ function _createScaleObjectForValue(attr, value, type, accessor, accessor0) {
attr,
baseValue: undefined,
isValue: true,
accessor
accessor,
accessor0
};
}

Expand Down Expand Up @@ -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);
};
}
Expand Down
30 changes: 30 additions & 0 deletions tests/utils/scales-utils-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -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(
{
Expand Down