[Pkg-javascript-commits] [d3-tip.js] 13/17: rootElement copied from stetro/d3-tip

Sunil Mohan Adapa sunilmohan-guest at moszumanska.debian.org
Thu Dec 8 10:37:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

sunilmohan-guest pushed a commit to branch upstream
in repository d3-tip.js.

commit d6e653ab2c2c01d3753b0ecdaad4e1db26337567
Author: Isaac Mann <isaacplmann at gmail.com>
Date:   Wed Sep 21 10:16:11 2016 -0400

    rootElement copied from stetro/d3-tip
---
 docs/positioning-tooltips.md | 11 +++++++++++
 examples/bars.html           |  3 +++
 index.js                     | 35 ++++++++++++++++++++++++-----------
 3 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/docs/positioning-tooltips.md b/docs/positioning-tooltips.md
index 5845d78..01cab02 100644
--- a/docs/positioning-tooltips.md
+++ b/docs/positioning-tooltips.md
@@ -40,3 +40,14 @@ tip.offset(function() {
   return [this.getBBox().height / 2, 0]
 })
 ```
+
+### tip.rootElement([function|Node])
+You can also specify the rootElement which is `document.body` by default.
+
+```javascript
+var tip = d3.tip()
+  .attr('class', 'd3-tip')
+  .rootElement(document.getElementById('graph'))
+  .html(function(d) { return d; })
+
+```
diff --git a/examples/bars.html b/examples/bars.html
index 498e150..de9d49c 100644
--- a/examples/bars.html
+++ b/examples/bars.html
@@ -53,6 +53,9 @@
   <script type="text/javascript">
     var tip = d3.tip()
       .attr('class', 'd3-tip')
+      .rootElement(function(){
+        return document.getElementById('graph');
+      })
       .html(function(d) { return '<span>' + d.total + '</span>' + ' entries' })
       .offset([-12, 0])
 
diff --git a/index.js b/index.js
index 371ad77..d80b9bc 100644
--- a/index.js
+++ b/index.js
@@ -30,19 +30,20 @@
   //
   // Returns a tip
   return function() {
-    var direction = d3TipDirection,
-        offset    = d3TipOffset,
-        html      = d3TipHTML,
-        node      = initNode(),
-        svg       = null,
-        point     = null,
-        target    = null
+    var direction   = d3TipDirection,
+        offset      = d3TipOffset,
+        html        = d3TipHTML,
+        rootElement = document.body,
+        node        = initNode(),
+        svg         = null,
+        point       = null,
+        target      = null
 
     function tip(vis) {
       svg = getSVGNode(vis)
       if (!svg) return
       point = svg.createSVGPoint()
-      document.body.appendChild(node)
+      rootElement.appendChild(node)
     }
 
     // Public - show the tooltip on the screen
@@ -59,9 +60,9 @@
           i       = directions.length,
           coords,
           scrollTop  = document.documentElement.scrollTop ||
-            document.body.scrollTop,
+            rootElement.scrollTop,
           scrollLeft = document.documentElement.scrollLeft ||
-            document.body.scrollLeft
+            rootElement.scrollLeft
 
       nodel.html(content)
         .style('opacity', 1).style('pointer-events', 'all')
@@ -157,6 +158,18 @@
       return tip
     }
 
+    // Public: sets or gets the root element anchor of the tooltip
+    //
+    // v - root element of the tooltip
+    //
+    // Returns root node of tip
+    tip.rootElement = function(v) {
+      if (!arguments.length) return rootElement
+      rootElement = v == null ? v : d3.functor(v)()
+
+      return tip
+    }
+
     // Public: destroys the tooltip and removes it from the DOM
     //
     // Returns a tip
@@ -271,7 +284,7 @@
       if (node == null) {
         node = initNode()
         // re-add node to DOM
-        document.body.appendChild(node)
+        rootElement.appendChild(node)
       }
       return d3Selection.select(node)
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/d3-tip.js.git



More information about the Pkg-javascript-commits mailing list