[Pkg-javascript-commits] [d3-tip.js] 03/277: account for overlapping bounds
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 629d673e35b2144a4ac818c58310b2b5a64276dd
Author: Justin Palmer <justin at labratrevenge.com>
Date: Fri Jan 6 15:50:06 2012 -0800
account for overlapping bounds
---
examples/circles.html | 6 ++----
src/d3.tip.js | 30 ++++++++++++++++--------------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/examples/circles.html b/examples/circles.html
index 6ef9507..4297ab1 100644
--- a/examples/circles.html
+++ b/examples/circles.html
@@ -9,14 +9,12 @@
<style type="text/css">
.d3-tip {
fill: #c00;
- stroke-width: 2px;
- stroke: #333;
font-weight: bold;
}
.d3-tip text {
fill: #fff;
- font-size: 14px;
+ font-size: 12px;
stroke: none;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
@@ -27,7 +25,7 @@
var w = 500,
h = 500,
r = 10,
- data = [10, 20, 30, 40],
+ data = [1220, 2230, 3002, 4012],
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()
diff --git a/src/d3.tip.js b/src/d3.tip.js
index f555a45..145e282 100644
--- a/src/d3.tip.js
+++ b/src/d3.tip.js
@@ -7,36 +7,38 @@ d3.svg.tip = function() {
function tip(d, i) {
var el = d3.select(this),
doc = d3.select(this.ownerSVGElement),
- group = doc.select('#' + id).empty() ? doc.append('g').attr('id', id) : doc.select('#' + id);
+ group = doc.select('#' + id).empty() ? doc.append('g').attr('id', id) : doc.select('#' + id),
+ bounds = doc.node().getBoundingClientRect();
- //el.on('mouseout', function() { group.remove() })
+ el.on('mouseout', function() { group.remove() })
- group.classed(className, true);
- group.text(' ')
- group.attr('transform', 'translate(50, 50)')
+ group.classed(className, true).text(' ');
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(),
- bounds = el.node().getBoundingClientRect();
+ ebbox = el.node().getBBox();
- // 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();
+ sbbox = str.node().getBBox();
- rect.attr('width', bbox.width + pad * 2).attr('height', bbox.height + pad * 2)
+ rect.attr('width', sbbox.width + pad * 2).attr('height', sbbox.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) + ")")
-
+ var x = (ebbox.x - sbbox.width / 2),
+ y = (ebbox.y - rbbox.height);
+
+ if(x <= 0) { x = 0 }
+ if(x + rbbox.width > bounds.width) { x = bounds.width - rbbox.width }
+ if(y <= 0) { y = 0 }
+
+ group.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