From bee01d84979aef474acb0cb8e646d1d9ca7d1273 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 5 Dec 2018 00:35:45 -0500 Subject: [PATCH] Destroy all old background layer tooltips before making new ones (closes #5551) --- modules/ui/background.js | 4 ++-- modules/util/tooltip.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) 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);