Skip to content

Commit

Permalink
fix(axis): Fix adding duplicated <title> element
Browse files Browse the repository at this point in the history
When <title> element is already appended, make to use them rather than appending.

Fix #1271
  • Loading branch information
netil authored Mar 4, 2020
1 parent 86b6806 commit 8d45075
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 15 additions & 0 deletions spec/internals/axis-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,21 @@ describe("AXIS", function() {
// check when toggling displaying data series
expect(() => chart.hide("data1")).to.not.throw();
});

it("shouldn't be addede duplicated tooltip <title> elements", done => {
chart.load({
columns: [
["data1", 130, 120, 150, 140]
],
done: function() {
chart.$.main.selectAll(`.${CLASS.axisX} .tick text`).each(function() {
expect(d3Select(this).selectAll("title").size()).to.be.equal(1);
});

done();
}
});
})
});

describe("rotated", () => {
Expand Down
10 changes: 6 additions & 4 deletions src/axis/AxisRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,12 @@ export default class AxisRenderer {
ctx.setTickLineTextPosition(lineUpdate, textUpdate);

// Append <title> for tooltip display
params.tickTitle && textUpdate.append && textUpdate.append("title")
.each(function(index) {
d3Select(this).text(params.tickTitle[index]);
});
if (params.tickTitle) {
const title = textUpdate.select("title");

(title.empty() ? textUpdate.append("title") : title)
.text(index => params.tickTitle[index]);
}

if (scale1.bandwidth) {
const x = scale1;
Expand Down

0 comments on commit 8d45075

Please sign in to comment.