[Pkg-javascript-commits] [d3-tip.js] 21/277: fix left orientation for rects

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:57:12 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 3658b9f9864a22ad3b401b5476b196134e2ed5d5
Author: Justin Palmer <justin at labratrevenge.com>
Date:   Mon Jan 9 08:41:29 2012 -0800

    fix left orientation for rects
---
 examples/bars.html |  2 +-
 src/d3.tip.js      | 27 +++++++++++++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/examples/bars.html b/examples/bars.html
index bd58375..92425c5 100644
--- a/examples/bars.html
+++ b/examples/bars.html
@@ -35,7 +35,7 @@
         x  = d3.scale.ordinal().domain(d3.range(data.length)).rangeRoundBands([0, w], 0.1),
         y  = d3.scale.linear().domain([0, d3.max(data)]).range([h, 0]),
         tip = d3.svg.tip()
-          .orient('top')
+          .orient('left')
           .padding(5)
           .text(function(d) { return d; })
           .attr('class', 'd3-tip')
diff --git a/src/d3.tip.js b/src/d3.tip.js
index 07be67e..2d5243c 100644
--- a/src/d3.tip.js
+++ b/src/d3.tip.js
@@ -2,7 +2,7 @@ d3.svg.tip = function() {
   var orient = 'top',
       padding = 5,
       cornerRadius = 2,
-      stemSize = 90,
+      stemSize = 60,
       offset = d3_svg_offset,
       text = d3_svg_text,
       node = make('g');
@@ -13,6 +13,7 @@ d3.svg.tip = function() {
     var tipOffset = offset.apply(this, arguments),
         tipText   = text.apply(this, arguments),
         container = d3.select(node),
+        tag = this.tagName.toLowerCase(),
         x, y, stem, backingRect, containerRect, stemRect;
     
     // Elements and Bounds
@@ -55,23 +56,37 @@ d3.svg.tip = function() {
         containerRect = container.node().getBBox()
         x = targetRect.x + (targetRect.width / 2) - (containerRect.width / 2) + tipOffset[0];
         y = targetRect.y - containerRect.height + tipOffset[1];
-        break;
-      
+      break;
       case 'bottom':
         stem.attr('transform', 'translate(' + (backingRect.width / 2) + ',' + -(stemRect.height / 2) + ')');
         
         containerRect = container.node().getBBox()
         x = targetRect.x + (targetRect.width / 2) - (containerRect.width / 2) + tipOffset[0];
         y = targetRect.y + targetRect.height + stemRect.height - tipOffset[1];
-        break;
-      
+      break;
       case 'left':
         stem.attr('transform', 'translate(' + backingRect.width + ',' + (backingRect.height / 2) + ') rotate(-90)');
         
         containerRect = container.node().getBBox()
+        x = targetRect.x - (stemRect.height / 2) + tipOffset[0];
+        y = targetRect.y + tipOffset[1];
+
+        if(tag == 'circle') {
+          x -= targetRect.width + (containerRect.width / 2);
+          y -= targetRect.height / 2
+        } else if(tag == 'rect') {
+          x -= containerRect.width - (stemRect.height / 2)
+          y -= containerRect.height / 2
+        }
+
+      break;
+      case 'right':
+        stem.attr('transform', 'translate(' + backingRect.width + ',' + (backingRect.height / 2) + ') rotate(-90)');
+        
+        containerRect = container.node().getBBox()
         x = targetRect.x - targetRect.width - (containerRect.width / 2) - (stemRect.height / 2) + tipOffset[0];
         y = targetRect.y - (targetRect.height / 2) + tipOffset[1];
-        break;
+      break;    
     }
 
     container.attr('transform', 'translate(' + x + ',' + y + ')')

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