[Pkg-javascript-commits] [d3-tip.js] 02/277: Sane defaults for common string and number content

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:57:10 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 6f377507f905c64d7628bcd4550066f86e9e1633
Author: Justin Palmer <justin at labratrevenge.com>
Date:   Fri Jan 6 15:00:58 2012 -0800

    Sane defaults for common string and number content
---
 examples/circles.html | 10 +++++-----
 src/d3.tip.js         | 21 ++++++++++++++++-----
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/examples/circles.html b/examples/circles.html
index f32d0fd..6ef9507 100644
--- a/examples/circles.html
+++ b/examples/circles.html
@@ -9,11 +9,15 @@
   <style type="text/css">
   .d3-tip {
     fill: #c00;
+    stroke-width: 2px;
+    stroke: #333;
+    font-weight: bold;
   }
 
   .d3-tip text {
     fill: #fff;
     font-size: 14px;
+    stroke: none;
     font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
   }
   </style>
@@ -29,11 +33,7 @@
         tip = d3.svg.tip()
           .orient('top')
           .content(function(d, i, t) { 
-            var txt = t.append('text').text(d).attr('text-anchor', 'middle'),
-                bbox = t.node().getBBox();
-
-            txt.attr('dx', bbox.width / 2).attr('dy', bbox.height / 2 + 5) 
-            return txt;
+            return d;
           })
 
 
diff --git a/src/d3.tip.js b/src/d3.tip.js
index fdd225b..f555a45 100644
--- a/src/d3.tip.js
+++ b/src/d3.tip.js
@@ -9,7 +9,7 @@ d3.svg.tip = function() {
         doc = d3.select(this.ownerSVGElement),
         group = doc.select('#' + id).empty() ? doc.append('g').attr('id', id) : doc.select('#' + id);
     
-    el.on('mouseout', function() { group.remove() })
+    //el.on('mouseout', function() { group.remove() })
 
     group.classed(className, true);
     group.text(' ')
@@ -18,12 +18,23 @@ d3.svg.tip = function() {
     var rect = group.append('rect').attr('transform', 'translate(0,0)').attr('rx', 2).attr('ry', 2),
         cnt = content(d, i, group),
         ebbox = el.node().getBBox(),
-        cbbox = cnt.node().getBBox(),
         bounds = el.node().getBoundingClientRect();
     
-    rect.attr('width', cbbox.width + pad * 2)
-      .attr('height', cbbox.height + pad * 2)
-    
+    // rect.attr('width', cbbox.width + pad * 2)
+    //   .attr('height', cbbox.height + pad * 2)
+    if(typeof cnt === 'string' || typeof cnt === 'number') {
+      var str = group.append('text')
+          .text(cnt)
+          .attr('text-anchor', 'middle')
+          .attr('alignment-baseline', 'middle'),
+          bbox = str.node().getBoundingClientRect();
+
+      rect.attr('width', bbox.width + pad * 2).attr('height', bbox.height + pad * 2)
+      var rbbox = rect.node().getBBox();
+
+      str.attr('dx', rbbox.width / 2).attr('dy', rbbox.height / 2)
+    }
+
     group.attr('transform', "translate(" + (bounds.left + bounds.width) + "," + (bounds.top - bounds.height) + ")")
     
   }

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