Skip to content
Browse files

top position working for circles

  • Loading branch information...
1 parent 4f91d28 commit de494366b4800d283a8dbc6ee5800a97eda05aa9 @Caged committed Feb 7, 2012
Showing with 22 additions and 8 deletions.
  1. +7 −3 examples/nested-groups.html
  2. +15 −5 src/d3.tip.js
View
10 examples/nested-groups.html
@@ -80,7 +80,12 @@
.padding(4)
.text(function(d) { return d; })
.attr('class', 'd3-tip');
-
+ tip2 = d3.svg.tip()
+ .orient('top')
+ .offset([-11, -32])
+ .padding(4)
+ .text(function(d) { return d; })
+ .attr('class', 'd3-tip');
// CIRCLES HERE
(function() {
@@ -124,7 +129,7 @@
dots.append('circle')
.attr('r', 4)
.on('mouseover', function(d, i) {
- tip.apply(this, arguments)
+ tip2.apply(this, arguments)
var rect = this.getBoundingClientRect(),
bbox = this.getBBox(),
// trans = this.getTransformToElement(),
@@ -193,7 +198,6 @@
.attr('height', function(d) { return h - y(d) })
.attr('y', function(d) { return y(d) })
.on('mouseover', function(d) {
- d3.select(this).style('fill', 'red')
tip.apply(this, arguments)
var rect = this.getBoundingClientRect(),
bbox = this.getBBox(),
View
20 src/d3.tip.js
@@ -28,7 +28,7 @@ d3.svg.tip = function() {
targetCTM = this.getCTM();
// TODO: Allow ability to specify this in someway
- target.on('mouseout', function() { container.remove() })
+ // target.on('mouseout', function() { container.remove() })
// FIXME: d3 has problems using `append` with nodes that were created
// but not immediately added to the SVG dom.
@@ -63,8 +63,13 @@ d3.svg.tip = function() {
containerRect = container.node().getBBox()
stemRect = stem.node().getBBox()
- x = targetCTM.e + (targetRect.width / 2) - (containerRect.width / 2) + tipOffset[0];
- y = targetRect.y - stemRect.height + tipOffset[1];
+ if(tag == 'circle') {
+ x = targetCTM.e + tipOffset[0];
+ y = targetCTM.f + tipOffset[1];
+ } else {
+ x = targetCTM.e + (targetRect.width / 2) - (containerRect.width / 2) + tipOffset[0];
+ y = targetRect.y - stemRect.height + tipOffset[1];
+ }
return {x: x, y: y}
},
@@ -80,8 +85,13 @@ d3.svg.tip = function() {
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]
+ if(tag == 'circle') {
+ x = targetCTM.e;
+ y = targetCTM.f;
+ } else {
+ x = targetRect.x + (targetRect.width / 2) - (containerRect.width / 2) + tipOffset[0];
+ y = targetRect.y + targetRect.height + stemRect.height - tipOffset[1];
+ }
return {x: x, y: y}
},

0 comments on commit de49436

Please sign in to comment.
Something went wrong with that request. Please try again.