Skip to content

Commit

Permalink
fix(tooltip): Enhancement for overlapped points
Browse files Browse the repository at this point in the history
Show overlapped data points tooltip as grouped even tooltip.grouped=false is set.

Fix #568
Close #569
  • Loading branch information
netil authored Aug 29, 2018
1 parent 851ec3e commit 3ee694d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
22 changes: 20 additions & 2 deletions spec/internals/tooltip-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ describe("TOOLTIP", function() {
const spy2 = sinon.spy();

// hover chart
const hoverChart = (hoverChart, eventName = "mousemove", pos = {clientX: 100, clientY: 100}) => {
const hoverChart = (hoverChart, eventName = "mousemove", pos = {clientX: 100, clientY: 100}, dataIndex = 2) => {
const eventRect = hoverChart.$.main
.select(`.${CLASS.eventRect}-2`)
.select(`.${CLASS.eventRect}-${dataIndex}`)
.node();

util.fireEvent(eventRect, eventName, pos, hoverChart);
Expand Down Expand Up @@ -615,5 +615,23 @@ describe("TOOLTIP", function() {

expect(value).to.be.equal(1000);
});

it("check for overlapped data points", () => {
const expectedData = {
data1: 500,
data3: 500
};

// check for custom point shape
hoverChart(chart, undefined, {clientX: 581, clientY: 214}, 4);

chart.$.tooltip.selectAll(".name")
.each(function() {
const name = this.textContent;

expect(name in expectedData).to.be.true;
expect(+this.nextSibling.textContent).to.be.equal(expectedData[name]);
});
});
});
});
1 change: 1 addition & 0 deletions src/config/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,7 @@ export default class Options {
* @type {Object}
* @property {Boolean} [tooltip.show=true] Show or hide tooltip.<br>
* @property {Boolean} [tooltip.grouped=true] Set if tooltip is grouped or not for the data points.
* - **NOTE:** The overlapped data points will be displayed as grouped even if set false.
* @property {Boolean} [tooltip.linked=false] Set if tooltips on all visible charts with like x points are shown together when one is shown.
* @property {String} [tooltip.linked.name=""] Groping name for linked tooltip.<br>If specified, linked tooltip will be groped interacting to be worked only with the same name.
* @property {Function} [tooltip.format.title] Set format for the title of tooltip.<br>
Expand Down
18 changes: 10 additions & 8 deletions src/interactions/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,19 @@ extend(ChartInternal.prototype, {
.filter(function(d) {
return $$.isWithinShape(this, d);
})
.each(function(d) {
if (isSelectionEnabled) {
if (isSelectionGrouped || config.data_selection_isselectable(d)) {
eventRect.style("cursor", "pointer");
}
.call(selected => {
const d = selected.data();

if (isSelectionEnabled && (isSelectionGrouped || config.data_selection_isselectable(d))) {
eventRect.style("cursor", "pointer");
}

if (!isTooltipGrouped) {
$$.showTooltip([d], this);
$$.showXGridFocus([d]);
$$.expandCirclesBars(index, d.id, true);
$$.showTooltip(d, context);
$$.showXGridFocus(d);

$$.unexpandCircles();
selected.each(d => $$.expandCirclesBars(index, d.id));
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion src/shape/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ extend(ChartInternal.prototype, {
circles.attr("r", r);
} else {
// transform must be applied to each node individually
circles.each(function(d) {
circles.each(function() {
const point = d3Select(this);

const box = this.getBBox();
Expand Down

0 comments on commit 3ee694d

Please sign in to comment.