Debian Codegraph @

examples/circles.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>d3.tip.js - Tooltips for D3</title>
5 <meta charset="utf-8" />
6 <title>Circles</title>
7 <script type="text/javascript" src="../bower_components/d3/d3.js"></script>
8 <script type="text/javascript" src="../index.js"></script>
9 <link rel="stylesheet" href="example-styles.css">
10 <style type="text/css">
11 body {
12 padding: 40px;
13 font-family: "Helvetica Neue", Helvetica, sans-serif;
14 font-size: 12px;
15 }
16
17 .d3-tip text {
18 fill: #fff;
19 font-size: 12px;
20 stroke: none;
21 font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
22 }
23
24 circle {
25 fill: #ccc;
26 fill-opacity: 0.6;
27 stroke: #bbb;
28 stroke-width: 1px;
29 }
30
31 circle:hover {
32 fill: #bbb;
33 stroke: #999;
34 }
35
36 circle.clickable:hover {
37 cursor: pointer;
38 }
39
40 .rule {
41 stroke-width: 1px;
42 stroke: #c00;
43 shape-rendering: crispedges;
44 }
45 </style>
46 </head>
47 <body>
48 <script type="text/javascript">
49 var data = [],
50 random = d3.randomNormal(5),
51 random2 = d3.randomIrwinHall(1)
52 for(var i = 0; i < 100; i++) data.push(random(i))
53
54 var tip = d3.tip()
55 .attr('class', 'd3-tip')
56 .html(function(d) { return d.toFixed(2) })
57 .direction('nw')
58 .offset([0, 3])
59
60 var tip2 = d3.tip()
61 .attr('class', 'd3-tip')
62 .html(function(d) { return d.toFixed(2) })
63 .direction('n')
64 .offset([-3, 0])
65
66 var w = 1000,
67 h = 500,
68 r = 10,
69 linex, liney,
70 x = d3.scaleLinear().domain([0, data.length - 1]).range([r, w - r]),
71 y = d3.scaleLinear().domain([0, d3.max(data)]).range([h, 0])
72
73 var vis = d3.select(document.body)
74 .append('svg')
75 .attr('width', w)
76 .attr('height', h)
77 .append('g')
78 .attr('transform', 'translate(20, 20)')
79 .call(tip)
80
81 vis.selectAll('circle')
82 .data(data)
83 .enter().append('circle')
84 .attr('r', function(d, i) { return random2(i) * 10 })
85 .attr('cx', function(d, i) { return x(i) })
86 .attr('cy', y)
87 .on('mouseover', tip.show)
88 .on('mouseout', tip.hide)
89
90 var vis2 = d3.select(document.body)
91 .append('svg')
92 .attr('width', w)
93 .attr('height', h)
94 .append('g')
95 .attr('transform', 'translate(20, 20)')
96 .call(tip2)
97
98 vis2.selectAll('circle')
99 .data(data)
100 .enter().append('circle')
101 .attr('class', 'clickable')
102 .attr('r', function(d, i) { return random2(i) * 10 })
103 .attr('cx', function(d, i) { return x(i) })
104 .attr('cy', y)
105 .on('click', function(d) {
106 tip2.hide(d).show(d)
107 })
108
109 </script>
110 </body>
111 </html>