Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
right tips for circles
Browse files Browse the repository at this point in the history
  • Loading branch information
caged committed Jan 9, 2012
1 parent 3658b9f commit c842b3b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/bars.html
Original file line number Diff line number Diff line change
Expand Up @@ -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('left')
.orient('right')
.padding(5)
.text(function(d) { return d; })
.attr('class', 'd3-tip')
Expand Down
2 changes: 1 addition & 1 deletion examples/circles.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
x = d3.scale.linear().domain([0, data.length - 1]).range([r, w - r]),
y = d3.scale.linear().domain([0, d3.max(data)]).range([h, r]),
tip = d3.svg.tip()
.orient('left')
.orient('right')
.padding(10)
.text(function(d) { return d; })
.attr('class', 'd3-tip')
Expand Down
16 changes: 12 additions & 4 deletions src/d3.tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ d3.svg.tip = function() {
var orient = 'top',
padding = 5,
cornerRadius = 2,
stemSize = 60,
stemSize = 50,
offset = d3_svg_offset,
text = d3_svg_text,
node = make('g');
Expand Down Expand Up @@ -81,11 +81,19 @@ d3.svg.tip = function() {

break;
case 'right':
stem.attr('transform', 'translate(' + backingRect.width + ',' + (backingRect.height / 2) + ') rotate(-90)');
stem.attr('transform', 'translate(' + -(stemRect.height / 2) + ',' + (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];
x = targetRect.x + (targetRect.width / 2) + stemRect.height + containerRect.width + 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;
}

Expand Down

0 comments on commit c842b3b

Please sign in to comment.