Skip to content

Commit

Permalink
fix(interaction): Fix on eventRect generation
Browse files Browse the repository at this point in the history
- Make sure to get x Axis tick values
- Revert .updateXs()

Fix #1019
  • Loading branch information
netil authored Aug 9, 2019
1 parent c011b89 commit 3dd9439
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
40 changes: 40 additions & 0 deletions spec/interactions/interaction-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,46 @@ describe("INTERACTION", () => {
});
});

describe("timeseries #3", () => {
before(() => {
args = {
data: {
x: "x",
json: {
Temperature:["29.39", "29.7", "29.37", "28.87", "28.62"],
x:["01-01-2015 00:00", "02-01-2015 00:00", "03-01-2015 00:00", "04-01-2015 00:00", "05-01-2015 00:00"]
},
type: "area",
xFormat: "%m-%d-%Y %H:%M"
},
axis: {
x: {
tick: {
fit: false
},
type: "timeseries"
}
}
};
});

it("check if rect element generated correctly", () => {
const rect = chart.$.main.selectAll(`.${CLASS.eventRectsSingle} rect`);
let lastX = 0;

expect(rect.size()).to.be.equal(args.data.json.x.length);

rect.each(function(d, i) {
const x = +this.getAttribute("x");

expect(+this.getAttribute("x")).to.be.above(lastX);
expect(+this.getAttribute("width")).to.be.above(0);

lastX = x;
});
});
});

describe("indexed", () => {
before(() => {
args = {
Expand Down
9 changes: 8 additions & 1 deletion src/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,15 @@ extend(ChartInternal.prototype, {

updateXs() {
const $$ = this;
const targets = $$.data.targets;

$$.xs = $$.axis.getTickValues("x") || [];
if (targets.length) {
$$.xs = [];

targets[0].values.forEach(v => {
$$.xs[v.index] = v.x;
});
}
},

getPrevX(i) {
Expand Down
6 changes: 4 additions & 2 deletions src/interactions/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ extend(ChartInternal.prototype, {
.merge(eventRectUpdate);
} else {
// Set data and update $$.eventRect
const xAxisTickValues = $$.flowing ?
let xAxisTickValues = $$.axis.getTickValues("x");

xAxisTickValues = ($$.flowing || !xAxisTickValues || config.axis_x_tick_count) ?
$$.getMaxDataCountTarget($$.data.targets).values :
($$.axis.getTickValues("x") || []).map((x, index) => ({x, index}));
xAxisTickValues.map((x, index) => ({x, index}));

eventRects.datum(xAxisTickValues);

Expand Down

0 comments on commit 3dd9439

Please sign in to comment.