diff --git a/modules/ui/background.js b/modules/ui/background.js index 4d98aedfd..5c2f3ebdb 100644 --- a/modules/ui/background.js +++ b/modules/ui/background.js @@ -52,6 +52,8 @@ export function uiBackground(context) { var description = d.description(); var isOverflowing = (span.property('clientWidth') !== span.property('scrollWidth')); + item.call(tooltip().destroyAny); + if (d === _previousBackground) { item.call(tooltip() .placement(placement) @@ -66,8 +68,6 @@ export function uiBackground(context) { .placement(placement) .title(description || d.name()) ); - } else { - item.call(tooltip().destroy); } }); } diff --git a/modules/util/tooltip.js b/modules/util/tooltip.js index fc7ada3fb..637229aee 100644 --- a/modules/util/tooltip.js +++ b/modules/util/tooltip.js @@ -69,7 +69,10 @@ export function tooltip() { }; - tooltip.destroy = function(selection) { + tooltip.destroy = function(selection, selector) { + // by default, just destroy the current tooltip + selector = selector || '.tooltip-' + _id; + selection .on('mouseenter.tooltip', null) .on('mouseleave.tooltip', null) @@ -77,11 +80,16 @@ export function tooltip() { return this.getAttribute('data-original-title') || this.getAttribute('title'); }) .attr('data-original-title', null) - .selectAll('.tooltip-' + _id) + .selectAll(selector) .remove(); }; + tooltip.destroyAny = function(selection) { + selection.call(tooltip.destroy, '.tooltip'); + }; + + function setup() { var root = d3_select(this); var animate = _animation.apply(this, arguments);