Skip to content

Commit

Permalink
fix(data): Fix data indexing
Browse files Browse the repository at this point in the history
Make data indexing to happens on every data convert even 'index'
property value exists.

Fix #863
  • Loading branch information
netil authored May 7, 2019
1 parent e0f5749 commit 2e3010b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
55 changes: 55 additions & 0 deletions spec/api/api.load-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,59 @@ describe("API load", function() {
});
});
});

describe("check for event rect", () => {
const cols = [
["x",0, 10, 15, 20, 25, 30, 35, 40, 45, 50],
["English",12,15,6,23,13,28,71,16,21,10],
["Russian",0,0,1,2,0,0,5,0,1,1],
["Spanish",0,3,0,2,0,0,1,0,1,2],
["Portuguese",1,0,0,0,0,0,0,1,1,0],
["German",0,0,0,0,0,1,0,0,0,1],
["Dutch",0,0,0,0,0,0,0,0,0,0],
["French",0,1,0,0,0,0,0,0,0,1],
["Chinese",0,0,0,0,0,0,0,0,5,0],
];
const cols2 = [
["x",0, 5, 7, 12, 20, 22, 23, 24, 30, 35],
["English",12,9,31,26,17,6,11,23,20,12],
["Russian",0,1,1,1,0,0,4,2,0,0],
["Spanish",0,0,7,2,2,1,1,2,3,0],
["Portuguese",1,1,4,0,0,0,0,0,0,0],
["German",0,0,0,11,0,12,1,0,0,0],
["Dutch",0,0,0,0,0,1,0,0,0,0],
["French",0,0,2,2,0,0,0,0,2,0],
["Chinese",0,0,0,0,0,0,0,0,0,0],
];

before(() => {
args = {
data: {
x: "x",
type: "area-spline",
columns: cols
}
};
});

it("should be correctly updating eventRect elements", done => {
chart.load({
columns: cols2,
done: () => {
let lastX = 0;

chart.$.main.selectAll(`.${CLASS.eventRects} rect`).each(function(v, i) {
const x = +this.getAttribute("x");

expect(x).to.be.above(lastX);
expect(this.classList.contains(`${CLASS.eventRect}-${i}`)).to.be.true;

lastX = x;
});

done();
}
});
});
});
});
2 changes: 1 addition & 1 deletion spec/shape/shape.arc-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ describe("SHAPE ARC", () => {
});

it("the dimension should be 0x0", () => {
["data1", "data2"].forEach(id => {
["data2", "data3"].forEach(id => {
const rect = chart.$.arc.select(`.${CLASS.arc}-${id}`).node().getBBox();

expect(rect.width === 0).to.be.true;
Expand Down
6 changes: 1 addition & 5 deletions src/data/data.convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,7 @@ extend(ChartInternal.prototype, {
}

// indexing each value
t.values.forEach((v, i) => {
const index = $$.data.targets ? $$.getIndexByX(v.x) : null;

v.index = index === null ? i : index;
});
t.values.forEach((v, i) => (v.index = i));

// this needs to be sorted because its index and value.index is identical
$$.data.xs[t.id].sort((v1, v2) => v1 - v2);
Expand Down
7 changes: 1 addition & 6 deletions src/data/data.load.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ extend(ChartInternal.prototype, {

loadFromArgs(args) {
const $$ = this;
let data;

// prevent load when chart is already destroyed
if (!$$.config) {
Expand All @@ -65,11 +64,7 @@ extend(ChartInternal.prototype, {
// reset internally cached data
$$.resetCache();

if (args.data) {
data = args.data;
} else {
data = $$.convertData(args, d => $$.load($$.convertDataToTargets(d), args));
}
const data = args.data || $$.convertData(args, d => $$.load($$.convertDataToTargets(d), args));

$$.load(data ? $$.convertDataToTargets(data) : null, args);
},
Expand Down

0 comments on commit 2e3010b

Please sign in to comment.