Skip to content

Commit

Permalink
fix(interaction): Fix null data point interaction
Browse files Browse the repository at this point in the history
Make sure to filter nullish data when finding closest data points.

Fix #1199
  • Loading branch information
netil committed Jan 14, 2020
1 parent 1e0ac62 commit 901da84
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
64 changes: 64 additions & 0 deletions spec/interactions/interaction-spec.js
Expand Up @@ -1038,4 +1038,68 @@ describe("INTERACTION", () => {
}).to.not.throw();
});
});

describe("check for bubble null data", () => {
before(() => {
args = {
data: {
json: [
{
"x":1,
"b":null,
"a":[1,2]
},
{
"x":2,
"b":null,
"a":[3,1]
},
{
"x":3,
"b":[0,2],
"a":null
},
{
"x":4,
"b":[3,2],
"a":[7,5]
},
{
"x":5,
"b":[5,3],
"a":[2,10]
}
],
keys: {
"x":"x",
"value":[
"a",
"b"
]
},
type: "bubble"
}
};
});

it("should show tooltip", () => {
const point = chart.$.line.circles.filter(v => v.id === "b" && v.index === 2);
const r = +point.attr("r");

// when
chart.tooltip.show({
mouse: [308.5, 400]
});

chart.$.tooltip.selectAll(".name, .value").each(function() {
if (this.classList.contains("name")) {
expect(this.textContent).to.be.equal("b");
} else if (this.classList.contains("value")) {
expect(+this.textContent).to.be.equal(2);
}
});

expect(+point.attr("r")).to.be.above(r);
});
});
});
9 changes: 5 additions & 4 deletions src/data/data.js
Expand Up @@ -628,12 +628,13 @@ extend(ChartInternal.prototype, {

findClosest(values, pos) {
const $$ = this;
const data = values.filter(v => v && isValue(v.value));
let minDist = $$.config.point_sensitivity;
let closest;

// find mouseovering bar
values
.filter(v => v && $$.isBarType(v.id))
data
.filter(v => $$.isBarType(v.id))
.forEach(v => {
const shape = $$.main.select(`.${CLASS.bars}${$$.getTargetSelectorSuffix(v.id)} .${CLASS.bar}-${v.index}`).node();

Expand All @@ -643,8 +644,8 @@ extend(ChartInternal.prototype, {
});

// find closest point from non-bar
values
.filter(v => v && !$$.isBarType(v.id))
data
.filter(v => !$$.isBarType(v.id))
.forEach(v => {
const d = $$.dist(v, pos);

Expand Down

0 comments on commit 901da84

Please sign in to comment.