[Pkg-javascript-commits] [d3-tip.js] 58/277: use transformation matrix based on user screen to determine bbox

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:57:16 UTC 2016


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

bhuvan-guest pushed a commit to branch master
in repository d3-tip.js.

commit ad81aa3aa81182cf5120a4163057d21c973aa57e
Author: Justin Palmer <justin at github.com>
Date:   Fri Apr 5 11:08:06 2013 -0700

    use transformation matrix based on user screen to determine bbox
---
 src/d3.tip.js | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/src/d3.tip.js b/src/d3.tip.js
index c3ff36e..dea1783 100644
--- a/src/d3.tip.js
+++ b/src/d3.tip.js
@@ -4,10 +4,14 @@
 d3.svg.tip = function() {
   var orient = 'top',
       offset = d3_svg_offset,
-      text = d3_svg_text,
-      node = init_node()
+      text   = d3_svg_text,
+      node   = init_node(),
+      svg    = null,
+      point  = null;
 
-  function tip() {
+  function tip(svg) {
+    svg = get_svg_node(svg)
+    point = svg.createSVGPoint()
     document.body.appendChild(node)
   }
 
@@ -20,6 +24,8 @@ d3.svg.tip = function() {
   }
 
   tip.show = function(v) {
+    var bbox = get_screen_bbox()
+    console.log(bbox)
     node.style.display = 'block'
     var content = text.apply(this, arguments)
     node.innerText = content
@@ -87,5 +93,38 @@ d3.svg.tip = function() {
     return node
   }
 
+  function get_svg_node(el) {
+    el = el.node()
+    if(el.tagName.toLowerCase() == 'svg') {
+      return el
+    } else {
+      while(el.parentNode) {
+        el = el.parentNode
+        if(el.tagName.toLowerCase() == 'svg')
+          return el
+      }
+    }
+
+    return null
+  }
+
+  function get_screen_bbox() {
+    var target = d3.event.target,
+        bbox   = {},
+        matrix = target.getScreenCTM()
+
+    point.x = target.x.animVal.value + document.body.scrollLeft
+    point.y = target.y.animVal.value + document.body.scrollTop
+    bbox.nw = point.matrixTransform(matrix)
+    point.x += target.width.animVal.value
+    bbox.ne = point.matrixTransform(matrix)
+    point.y += target.height.animVal.value
+    bbox.se = point.matrixTransform(matrix)
+    point.x -= target.width.animVal.value
+    bbox.sw = point.matrixTransform(matrix)
+
+    return bbox
+  }
+
   return tip;
 }

-- 
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