-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
126 lines (103 loc) · 3.17 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0>
<style> body {padding: 0; margin: 0;} </style>
<style>
#svg {
margin:0;
height:500px;
width:500px;
background-color: #ffffff;
}
#text-output, div{
font-size:14px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.8/d3.min.js" type="text/JavaScript"></script>
</head>
<body>
<div>Number of Elements</div>
<input type="text" id="text-input" value="500">
<div id='text-output'></div>
<div id='svg'></div>
<script>
var width = 500;
var height = 500;
var data = [];
var numElements = 50;
for (var i=0; i<numElements; i+=10){
for (var j=0; j<numElements; j+=10){
data.push({x:i,y:j});
}
}
// console.log(data);
var svg = d3.select('#svg');
function indata(data){
var dataJoin = svg.selectAll('.shadow')
.data(data);
var dataEnter = dataJoin.enter()
.append('custom')
.attr('class', 'shadow')
.attr('x',0)
.attr('y',0)
.attr('radius', 0);
dataJoin.merge(dataEnter)
.transition()
.duration(1000)
.attr('x',function(d){
return d.x;
})
.attr('y', function(d){
return d.y;
})
.attr('radius', function(d){
return 500/numElements;
});
var dataExit = dataJoin.exit()
.transition()
.duration(1000)
.attr('x', 0)
.attr('y', 0)
.attr('radius',0)
.remove();
};
function outdata() {
var shadowElements = svg.selectAll('custom.shadow');
shadowElements.each(function(d){
var node = d3.select(this);
// console.log(node.attr('x'));
// console.log(node.attr('y'));
// console.log(node.attr('radius'));
d3.select('#text-output')
.html(function(){
return 'Width/Number of Elements=' + node.attr('radius');
})
});
};
indata(data);
var dataTimer = d3.timer(function(elapsed){
outdata();
if (elapsed>1000) {dataTimer.stop();}
});
d3.select('#text-input').on('keydown', function(){
if (d3.event.keyCode === 13){
data = [];
numElements = +this.value;
for (var i=0; i<numElements; i+=10){
for (var j=0; j<numElements; j+=10){
data.push({x:i,y:j});
}
}
// console.log(data.length);
indata(data);
var dataTimer = d3.timer(function(elapsed){
outdata();
if (elapsed>1000) {dataTimer.stop();}
});
}
})
</script>
</body>
</html>