Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When update() is called, we need to reset the tooltip. #4840

Merged
merged 2 commits into from Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/core/core.controller.js
Expand Up @@ -371,6 +371,14 @@ module.exports = function(Chart) {

me.updateDatasets();

// Need to reset tooltip in case it is displayed with elements that are removed
// after update.
me.tooltip.initialize();

// Last active contains items that were previously in the tooltip.
// When we reset the tooltip, we need to clear it
me.lastActive = [];

// Do this before render so that any plugins that need final scale updates can use it
plugins.notify(me, 'afterUpdate');

Expand Down
1 change: 1 addition & 0 deletions src/core/core.tooltip.js
Expand Up @@ -384,6 +384,7 @@ module.exports = function(Chart) {
Chart.Tooltip = Element.extend({
initialize: function() {
this._model = getBaseModel(this._options);
this._lastActive = [];
},

// Get the title
Expand Down
48 changes: 48 additions & 0 deletions test/specs/core.controller.tests.js
Expand Up @@ -822,6 +822,54 @@ describe('Chart', function() {
expect(chart.tooltip._options).toEqual(jasmine.objectContaining(newTooltipConfig));
});

it ('should reset the tooltip on update', function() {
var chart = acquireChart({
type: 'line',
data: {
labels: ['A', 'B', 'C', 'D'],
datasets: [{
data: [10, 20, 30, 100]
}]
},
options: {
responsive: true,
tooltip: {
mode: 'nearest'
}
}
});

// Trigger an event over top of a point to
// put an item into the tooltip
var meta = chart.getDatasetMeta(0);
var point = meta.data[1];

var node = chart.canvas;
var rect = node.getBoundingClientRect();

var evt = new MouseEvent('mousemove', {
view: window,
bubbles: true,
cancelable: true,
clientX: rect.left + point._model.x,
clientY: 0
});

// Manually trigger rather than having an async test
node.dispatchEvent(evt);

// Check and see if tooltip was displayed
var tooltip = chart.tooltip;

expect(chart.lastActive).toEqual([point]);
expect(tooltip._lastActive).toEqual([]);

// Update and confirm tooltip is reset
chart.update();
expect(chart.lastActive).toEqual([]);
expect(tooltip._lastActive).toEqual([]);
});

it ('should update the metadata', function() {
var cfg = {
data: {
Expand Down