-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcircles.js
48 lines (41 loc) · 1.57 KB
/
circles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// First undefine 'circles' so we can easily reload this file.
require.undef('circles');
define('circles', ['d3'], function (d3) {
function draw(container, data, width, height) {
width = width || 600;
height = height || 200;
var svg = d3.select(container).append("svg")
.attr('width', width)
.attr('height', height)
.append("g");
var x = d3.scaleLinear()
.domain([0, data.length - 1])
.range([50, width - 50]);
var circles = svg.selectAll('circle').data(data);
circles.enter()
.append('circle')
.attr("cx", function (d, i) {return x(i);})
.attr("cy", height / 2)
.attr("r", 20)
.style("fill", "#1f77b4")
.style("opacity", 0.7)
.on('mouseover', function() {
d3.select(this)
.interrupt('fade')
.style('fill', '#ff850e')
.style("opacity", 1)
.attr("r", function (d) {return 1.1 * d + 10;});
})
.on('mouseout', function() {
d3.select(this)
.transition('fade').duration(500)
.style("fill", "#1f77b4")
.style("opacity", 0.7)
.attr("r", function (d) {return d;});
})
.transition().duration(2000)
.attr("r", function (d) {return d;});
}
return draw;
});
element.append('<small>◉ ○ ◯ Loaded circles.js ◌ ◎ ●</small>');