Skip to content

Commit

Permalink
Merge f2d2895 into 0992bb9
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Sep 21, 2018
2 parents 0992bb9 + f2d2895 commit aabd81c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/scales-utils.js
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
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

0 comments on commit aabd81c

Please sign in to comment.