From a6f0e3c5b6a310bb57f86aa750c6005968e5943c Mon Sep 17 00:00:00 2001 From: bryan brancotte Date: Thu, 14 Sep 2017 13:45:25 +0200 Subject: [PATCH] Ability to force the tip to remain visible Can be used like this : ```javascript svg.data(data) .enter() .append('svg:circle') .on('mouseenter', tip.show) .on('mouseleave', tip.hide) .on('click', tip.toggle_keep_visible); ``` --- d3-tip.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/d3-tip.js b/d3-tip.js index ddc6100..4c74cd6 100644 --- a/d3-tip.js +++ b/d3-tip.js @@ -44,6 +44,7 @@ d3.tip = function() { scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft nodel.html(content) + .attr("keep_visible", "false") .style('position', 'absolute') .style('opacity', 1) .style('pointer-events', 'all') @@ -62,12 +63,21 @@ d3.tip = function() { // Returns a tip tip.hide = function() { var nodel = getNodeEl() - nodel + if (nodel.attr("keep_visible") != "true") nodel .style('opacity', 0) .style('pointer-events', 'none') return tip } + // Public - toggle foring or not the tip to remain visible + // + // Returns a tip + tip.toggle_keep_visible = function() { + var nodel = getNodeEl() + nodel.attr("keep_visible", nodel.attr("keep_visible") == "false") + return tip + } + // Public: Proxy attr calls to the d3 tip container. Sets or gets attribute value. // // n - name of the attribute