[Pkg-javascript-commits] [d3-tip.js] 18/277: formatting fixes
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 ca18d18cd211d585ca267c665d15f336a59873f5
Author: Justin Palmer <justin at labratrevenge.com>
Date: Mon Jan 9 07:42:25 2012 -0800
formatting fixes
---
examples/line.html | 6 ++---
src/d3.tip.js | 79 ++++++++++++++----------------------------------------
2 files changed, 23 insertions(+), 62 deletions(-)
diff --git a/examples/line.html b/examples/line.html
index 4918882..c61f9bb 100644
--- a/examples/line.html
+++ b/examples/line.html
@@ -7,7 +7,7 @@
<script type="text/javascript" src="../src/d3.tip.js"></script>
<style type="text/css">
.d3-tip path, .d3-tip rect {
- fill: #c00;
+ fill: #005dae;
font-weight: bold;
}
@@ -45,9 +45,9 @@
max = d3.max(data, function(d) { return d3.max(d) }),
linex, liney,
tip = d3.svg.tip()
- .orient('top')
+ .orient('bottom')
.padding(4)
- .offset([20, 20])
+ .offset([20, -20])
.text(function(d) { return d; })
.attr('class', 'd3-tip');
diff --git a/src/d3.tip.js b/src/d3.tip.js
index b3c7108..5b3c4ef 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 = 60,
+ stemSize = 90,
offset = d3_svg_offset,
text = d3_svg_text,
node = make('g');
@@ -13,7 +13,7 @@ d3.svg.tip = function() {
var tipOffset = offset.apply(this, arguments),
tipText = text.apply(this, arguments),
container = d3.select(node),
- x, y, stem, backingRect, containerRect;
+ x, y, stem, backingRect, containerRect, stemRect;
// Elements and Bounds
var doc = d3.select(this.ownerSVGElement),
@@ -28,83 +28,44 @@ d3.svg.tip = function() {
container.text(' ').node().appendChild(backing.node())
// The value to show in the tooltip
- var val = container.append('text').text(tipText).attr('text-anchor', 'middle').attr('alignment-baseline', 'middle'),
+ var val = container.append('text').text(tipText).attr('text-anchor', 'middle').attr('alignment-baseline', 'middle'),
valRect = val.node().getBBox();
valRect.width = valRect.width + (padding * 2)
valRect.height = valRect.height + (padding * 2)
- backing.attr('width', valRect.width).attr('height', valRect.height).attr('rx', cornerRadius).attr('ry', cornerRadius)
+ backing.attr('width', valRect.width)
+ .attr('height', valRect.height)
+ .attr('rx', cornerRadius)
+ .attr('ry', cornerRadius)
+
val.attr('dx', valRect.width / 2).attr('dy', valRect.height / 2)
- backingRect = backing.node().getBBox();
+ backingRect = backing.node().getBBox()
+
+ // TODO: stem seems to report the wrong height, so it's never completely flush
+ // against the backing rect.
+ stem = container.append('path').attr('d', d3_svg_stem())
+ stemRect = stem.node().getBBox()
switch(orient) {
case 'top':
- stem = container.append('path')
- .attr('d', d3_svg_stem())
- .attr('transform', 'translate(' + (backingRect.width / 2) + ',' + backingRect.height + ')');
-
- containerRect = container.node().getBBox()
+ stem.attr('transform', 'translate(' + (backingRect.width / 2) + ',' + backingRect.height + ')');
+ containerRect = container.node().getBBox()
x = targetRect.x + (targetRect.width / 2) - (containerRect.width / 2) + tipOffset[0];
y = targetRect.y - containerRect.height + tipOffset[1];
break;
case 'bottom':
- // stem = d3.svg.symbol().type('triangle-down').size(stemSize);
- // stem = d3.select(make('path')).attr('d', stem);
- // container.node().appendChild(stem.node())
- var containerRect = container.node().getBBox()
-
+ 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 - tipOffset[1];
+ y = targetRect.y + targetRect.height + stemRect.height - tipOffset[1];
break;
}
container.attr('transform', 'translate(' + x + ',' + y + ')')
- //ele.on('mouseout', function() { container.remove() })
- // var pad = padding.apply(this, arguments),
- // oset = offset.apply(this, arguments),
- // cnt = text.apply(this, arguments),
- // klass = className.apply(this, arguments),
- // el = d3.select(this),
- // doc = d3.select(this.ownerSVGElement),
- // group = doc.select('#' + id).empty() ? doc.append('g').attr('id', id) : doc.select('#' + id),
- // bounds = doc.node().getBoundingClientRect(),
- // symbol = d3.svg.symbol().type('triangle-down').size(stemSize),
- // rect = group.append('rect').attr('transform', 'translate(0,0)').attr('rx', 3).attr('ry', 3),
- // stem = group.append('path').attr('d', symbol),
- // ebbox = el.node().getBoundingClientRect(),
- // stemBounds = stem.node().getBBox();
-
- // //var rect = group.append('rect').attr('transform', 'translate(0,0)').attr('rx', 3).attr('ry', 3);
- // //el.on('mouseout', function() { group.remove() })
-
- // group.classed(klass, true) //.text(' ');
-
- // if(typeof cnt === 'string' || typeof cnt === 'number') {
- // var str = group.append('text')
- // .text(cnt)
- // .attr('text-anchor', 'middle')
- // .attr('alignment-baseline', 'middle'),
- // sbbox = str.node().getBoundingClientRect(),
- // rectw = sbbox.width + padding(d, i) * 2,
- // recth = sbbox.height + padding(d, i) * 2;
-
- // rect.attr('width', rectw).attr('height', recth)
- // var rbbox = rect.node().getBBox(),
- // x = (ebbox.right - (ebbox.width / 2) - (rbbox.width / 2) - (stemBounds.width / 2)) + oset[0],
- // y = (ebbox.top - rbbox.height) - stemBounds.height + oset[1];
-
- // if(x <= 0) { x = 0 }
- // if(x + rbbox.width > bounds.width) { x = bounds.width - rbbox.width }
- // if(y <= 0) { y = 0 }
-
- // str.attr('dx', rbbox.width / 2).attr('dy', rbbox.height / 2)
- // group.attr('transform', "translate(" + x + "," + y + ")")
- // stem.attr('transform','translate(' + rbbox.width / 2 + ',' + (rbbox.height + stemBounds.height / 2) + ')')
- // }
-
}
function d3_svg_offset() {
--
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