-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast_random_circles.html
82 lines (71 loc) · 2 KB
/
fast_random_circles.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
circle {
fill: red;
stroke: black;
}
</style>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="fast_fisheye.em.js"></script>
<script type="text/javascript" src="fast_fisheye.js"></script>
</head>
<body>
<div id="container">
<svg width="1500" height="900"></svg>
</div>
</body>
<script type="text/javascript" src="http://www.numericjs.com/lib/numeric-1.2.6.min.js"></script>
<script type="text/javascript">
var seed = 0;
numeric.seedrandom.seedrandom(seed);
Math.random = numeric.seedrandom.random;
</script>
<script type="text/javascript">
function randomArray(n, min, max) {
return d3.range(n).map(function() {
return Math.random() * (max-min) + min;
})
}
</script>
<script type="text/javascript">
var minr = 1,
maxr = 3;
var n = 20000;
var svg = d3.select('svg');
var width = svg.attr('width');
var height = svg.attr('height');
var margin = maxr;
var cxArray = randomArray(n, margin, width-margin);
var cyArray = randomArray(n, margin, height-margin);
var rArray = randomArray(n, minr, maxr);
var circleArray = new Array(n);
for (var i = 0; i < n; i++) {
circleArray[i] = {'x': cxArray[i], 'y': cyArray[i], 'r': rArray[i]};
}
var circles = svg
.append('g')
.selectAll('circle')
.data(circleArray)
.enter()
.append('circle')
.attr('cx', function(d) {return d.x})
.attr('cy', function(d) {return d.y})
.attr('r', function(d) {return d.r});
var fisheye = d3.fisheye.circular()
.radius(200)
.distortion(2)
.prepare(circleArray);
var applyDistortion = function(circleIdx, distortion) {
var circle = d3.select(circles[0][circleIdx]);
circle.attr('cx', distortion.x);
circle.attr('cy', distortion.y);
circle.attr('r', distortion.z * rArray[circleIdx]);
};
svg.on("mousemove", function() {
fisheye.fast_distort_at(d3.mouse(this), applyDistortion);
});
</script>
</html>