Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 9f6c2483791609600b3364db46dcfed261211334 @Caged committed Jan 6, 2012
Showing with 6,707 additions and 0 deletions.
  1. +10 −0 examples/bars.html
  2. +55 −0 examples/circles.html
  3. +58 −0 src/d3.tip.js
  4. +4,695 −0 vendor/d3.js
  5. +1,889 −0 vendor/d3.layout.js
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>d3.tip.js - Tooltips for D3</title>
+ <meta charset="utf-8" />
+</head>
+<body>
+
+</body>
+</html>
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>d3.tip.js - Tooltips for D3</title>
+ <meta charset="utf-8" />
+ <title>Bar Chart</title>
+ <script type="text/javascript" src="../vendor/d3.js"></script>
+ <script type="text/javascript" src="../src/d3.tip.js"></script>
+ <style type="text/css">
+ .d3-tip {
+ fill: #c00;
+ }
+
+ .d3-tip text {
+ fill: #fff;
+ font-size: 14px;
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ }
+ </style>
+</head>
+<body>
+ <script type="text/javascript">
+ var w = 500,
+ h = 500,
+ r = 10,
+ data = [10, 20, 30, 40],
+ 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('top')
+ .content(function(d, i, t) {
+ var txt = t.append('text').text(d).attr('text-anchor', 'middle'),
+ bbox = t.node().getBBox();
+
+ txt.attr('dx', bbox.width / 2).attr('dy', bbox.height / 2 + 5)
+ return txt;
+ })
+
+
+ vis = d3.select(document.body)
+ .append('svg')
+ .attr('width', 500)
+ .attr('height', 500)
+
+ vis.selectAll('circle')
+ .data(data)
+ .enter().append('circle')
+ .attr('r', r)
+ .attr('cx', function(d, i) { return x(i) })
+ .attr('cy', y)
+ .on('mouseover', tip)
+
+ </script>
+</body>
+</html>
@@ -0,0 +1,58 @@
+d3.svg.tip = function() {
+ var orient = 'top',
+ id = 'd3-tip',
+ className = 'd3-tip',
+ pad = 5;
+
+ 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);
+
+ el.on('mouseout', function() { group.remove() })
+
+ group.classed(className, true);
+ group.text(' ')
+ group.attr('transform', 'translate(50, 50)')
+
+ 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(),
+ cbbox = cnt.node().getBBox(),
+ bounds = el.node().getBoundingClientRect();
+
+ rect.attr('width', cbbox.width + pad * 2)
+ .attr('height', cbbox.height + pad * 2)
+
+ group.attr('transform', "translate(" + (bounds.left + bounds.width) + "," + (bounds.top - bounds.height) + ")")
+
+ }
+
+
+ tip.orient = function(v) {
+ if (!arguments.length) return orient;
+ orient = v == null ? v: d3.functor(v);
+ return tip;
+ };
+
+ tip.id = function(v) {
+ if (!arguments.length) return id;
+ id = v == null ? v: d3.functor(v);
+ return tip;
+ };
+
+ tip.className = function(v) {
+ if (!arguments.length) return className;
+ className = v == null ? v: d3.functor(v);
+ return tip;
+ };
+
+ tip.content = function(v) {
+ if (!arguments.length) return content;
+ content = v == null ? v: d3.functor(v);
+
+ return tip;
+ };
+
+ return tip;
+}
Oops, something went wrong.

0 comments on commit 9f6c248

Please sign in to comment.