-
Notifications
You must be signed in to change notification settings - Fork 6
/
tokenvol - Copy.html
297 lines (229 loc) · 8.37 KB
/
tokenvol - Copy.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<html>
<head>
<meta charset="utf-8">
<title>Token Volume</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="datahelper.js"></script>
<style>
.graph {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
/*shape-rendering: crispEdges;*/
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1px;
}
.y .tick line{
opacity: 0.2;
}
.svg-container {
display: inline-block;
position: relative;
width: 100%;
padding-bottom: 60%; /* aspect ratio */
vertical-align: top;
overflow: hidden;
}
.svg-content-responsive {
display: inline-block;
position: absolute;
top: 10px;
left: 0;
}
.fadeLabel{
opacity: 0.8;
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">DAO Stats</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Home</a></li>
<li><a href="nav.html">Search</a></li>
<li><a href="biggest.html">Accounts</a></li>
<li class="active"><a href="tokenvol.html">Graphs</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="about.html">About</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<h3>Number of tokens in existence</h3>
<div id="graphBox" class="graph">
</div>
<h3>Ether in contract</h3>
<div>
<div id="graphBoxEth" class="graph">
</div>
</div>
</div>
</div><!-- Container end -->
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
//data = [[0, 0], [1, 5], [2, 10], [3, 11], [4, 5], [5, 20]];
function plotGraph(id, data, dd, xLabel, yLabel, yTick, colours, textLabels){
var bStart = data[0][0];
var bEnd = data[data.length-1][0];
var volMin = data[0][1];
var volMax = data[0][1];
for(var i=0; i<data.length; i++){
v = data[i][1];
if(v > volMax) volMax = v*2;
else if(v < volMin) volMin = v;
}
var boxW = 800;
var boxH = 400;
var margin = {top: 20, right: 20, bottom: 35, left: 35},
width = boxW - margin.left - margin.right,
height = boxH - margin.top - margin.bottom;
var formatDate = d3.time.format("%d-%b-%y");
var x = d3.scale.linear()
.range([0, width])
.domain([bStart, bEnd]);
var y = d3.scale.linear()
.range([height, 0])
.domain([0, volMax]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(yTick)
.innerTickSize(-width)
.outerTickSize(0)
.tickPadding(10);
var line = d3.svg.line()
.x(function(d) { return x(d[0]); })
.y(function(d) { return y(d[1]); });
/*
var svg = d3.select("#graphBox").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");*/
var svg = d3.select("#"+id)
.append("div")
.classed("svg-container", true) //container class to make it responsive
.append("svg")
//responsive SVG needs these 2 attributes and no width and height attr
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 " + boxW + " " + boxH)
//class to make it responsive
.classed("svg-content-responsive", true).append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
x.domain(d3.extent(data[dd], function(d) { return d[0]; }));
y.domain([0, d3.max(data[dd], function(d) { return d[1]; })*1.2]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("y", 35)
.attr("x", width/2)
.text(xLabel);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text(yLabel);
for(var i=0; i<data.length; i++){
console.log("+");
var p =svg.append("path")
.datum(data[i])
.attr("class", "line")
.attr("d", line);
if(colours !== undefined && colours[i] !== undefined){
p.style("stroke", colours[i]);
}
}
if(textLabels !== undefined){
for(var i=0; i<textLabels.length; i++){
var l = textLabels[i];
var t = svg.append("text")
.text(l["text"]);
if (l.link == "abs"){
t.attr("y", y(textLabels[0]["y"]) - textLabels[0]["py"])
}
else if (l.link == "right"){
var d = data[l.y];
t.attr("y", y(d[d.length-1][1]) + textLabels[0]["py"]);
}
if (l.x == "right"){
t.attr("x", boxW - margin.right + l.px);
}
else if (l.x == "left"){
var d = data[t.y];
t.attr("x", margin.left);
}
if(l.c !== undefined){
t.classed(l.c, true);
}
}
}
}
getData("volhistory", function(data, status){
plotGraph("graphBox", [data], 0, "Block", "Volume", function(n){
return Math.round(n/1000000).toLocaleString() + "M";
});
getData("bal", function(eth, status){
var startEth = 99999999;
if (eth.length != 0) startEth = eth[0][0];
var ethData = [];
var i=0;
while(data[i][0] < startEth){
ethData.push([data[i][0], data[i][1] * 0.01, 0]);
i++;
if(i == data.length) break;
}
ethData = ethData.concat(eth);
ethData1st = ethData[0][0];
ethDataLast = ethData[ethData.length-1][0];
eth1pc = [[ethData1st, ethSupply(ethData1st)*0.01], [ethDataLast, ethSupply(ethDataLast)*0.01]];
eth2pc = [[ethData1st, ethSupply(ethData1st)*0.02], [ethDataLast, ethSupply(ethDataLast)*0.02]];
console.log(ethData1st)
var pcLabel1 = {x: "right", link: "right", y: 1, py: 15, px: -100, text: "1% ETH supply", c: "fadeLabel"};
var pcLabel2 = {x: "right", link: "right", y: 2, py: 15, px: -100, text: "2% ETH supply", c: "fadeLabel"};
var labels = [pcLabel1, pcLabel2];
console.log(labels);
plotGraph("graphBoxEth", [ethData, eth1pc, eth2pc], 0, "Block", "Ether", function(n){console.log(n);
return (Math.round(n/100000)/10).toLocaleString() + "M";
}, [undefined, "#c32", "#c32"], labels);
});
});
</script>
<script src="https://www.w3counter.com/tracker.js?id=101014"></script>
</body>
</html>