Skip to content

Commit

Permalink
fix(area-line-range): Fix working with grouped data
Browse files Browse the repository at this point in the history
Correct on getting correct coordinate values evaluating
if data is grouped or not

Fix #630
Close #644
  • Loading branch information
netil committed Nov 8, 2018
1 parent 3af15a5 commit 1546dda
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
33 changes: 33 additions & 0 deletions spec/shape/shape.line-spec.js
Expand Up @@ -306,6 +306,39 @@ describe("SHAPE LINE", () => {
});
});

describe("combined area-range type with grouped data", () => {
before(() => {
args = {
data: {
columns: [
["data1", 30, 20, 50, 40, 60, 50],
["data2", 200, 130, 90, 240, 130, 220],
["data3", [130,120,110], [120,110,100], [150,140,130], [140,130,120],[160,150,140],[150,140,130]],
],
type: "bar",
types: {
data3: "area-line-range"
},
groups: [
["data1", "data2"]
]
}
}
});

it("check for correct generation", () => {
const d = chart.$.line.lines.attr("d");
const box = d3.select(`.${CLASS.chartLine}.${CLASS.target}-data3`).node().getBBox();;

// check for correct path data
expect(/NaN/.test(d)).to.be.false;

// check for correct pos
expect(Math.round(box.height)).to.be.equal(83);
expect(Math.round(box.y)).to.be.equal(205);
});
});

describe("rotated step type", () => {
before(() => {
args = {
Expand Down
5 changes: 5 additions & 0 deletions src/data/data.js
Expand Up @@ -46,6 +46,11 @@ extend(ChartInternal.prototype, {
return config.data_stack_normalize && config.data_groups.length;
},

isGrouped(id) {
return this.config.data_groups
.map(v => v.indexOf(id) >= 0)[0];
},

getXKey(id) {
const $$ = this;
const config = $$.config;
Expand Down
22 changes: 9 additions & 13 deletions src/shape/line.js
Expand Up @@ -153,7 +153,7 @@ extend(ChartInternal.prototype, {
const yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale;

const xValue = d => (isSub ? $$.subxx : $$.xx).call($$, d);
const yValue = (d, i) => (config.data_groups.length > 0 ?
const yValue = (d, i) => ($$.isGrouped(d.id) ?
getPoints(d, i)[0][1] :
yScaleGetter.call($$, d.id)($$.getBaseValue(d))
);
Expand Down Expand Up @@ -389,19 +389,18 @@ extend(ChartInternal.prototype, {
const config = $$.config;
const lineConnectNull = config.line_connectNull;
const isRotated = config.axis_rotated;
const isGrouped = config.data_groups.length > 0;

const getPoints = $$.generateGetAreaPoints(areaIndices, isSub);
const yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale;

const xValue = d => (isSub ? $$.subxx : $$.xx).call($$, d);
const value0 = (d, i) => (isGrouped ?
const value0 = (d, i) => ($$.isGrouped(d.id) ?
getPoints(d, i)[0][1] :
yScaleGetter.call($$, d.id)(
$$.isAreaRangeType(d) ?
$$.getAreaRangeData(d, "high") : $$.getAreaBaseValue(d.id)
));
const value1 = (d, i) => (isGrouped ?
const value1 = (d, i) => ($$.isGrouped(d.id) ?
getPoints(d, i)[1][1] :
yScaleGetter.call($$, d.id)(
$$.isAreaRangeType(d) ?
Expand Down Expand Up @@ -542,17 +541,14 @@ extend(ChartInternal.prototype, {

updateCircleY() {
const $$ = this;
let lineIndices;
let getPoints;

if ($$.config.data_groups.length > 0) {
lineIndices = $$.getShapeIndices($$.isLineType);
getPoints = $$.generateGetLinePoints(lineIndices);
$$.circleY = (d, i) => {
const id = d.id;

$$.circleY = (d, i) => getPoints(d, i)[0][1];
} else {
$$.circleY = d => $$.getYScale(d.id)($$.getBaseValue(d));
}
return $$.isGrouped(id) ?
$$.generateGetLinePoints($$.getShapeIndices($$.isLineType))(d, i)[0][1] :
$$.getYScale(id)($$.getBaseValue(d));
};
},

getCircles(i, id) {
Expand Down

0 comments on commit 1546dda

Please sign in to comment.