-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_D3.html
133 lines (100 loc) · 2.29 KB
/
example_D3.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
<div>
<script src="node_modules/d3/d3.min.js"></script>
<style>
<style>
svg {
font: 10px sans-serif;
}
rect {
fill: #ddd;
}
.axis path,
.axis line {
fill: none;
stroke: #fff;
}
svg {
border : 1px solid red;
}
</style>
</style>
<h1 id="title">D3</h1>
<div class="form-group">
<label for="input_fname">rrd file</label>
<select id="file" onchange="input_update()">
</select>
</div>
<button onclick="input_update()" class="btn btn-default">Update</button>
<hr />
<svg id="example" />
<script type="text/javascript">
//<![CDATA[
function update_info(bf) {
var rrd_Graph = new RRDGraph();
rrd_Graph.addRrdFile(new RRDFile(bf));
datas(rrd_Graph.getFlotData()[0].data);
}
function datas(data) {
var margin = {top: 40, right: 40, bottom: 40, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.time.scale()
.domain(d3.extent(data, function(d) { return d[0]; }))
.range([0, width]);
var y = d3.scale.linear()
.domain(d3.extent(data, function(d) { return d[1]; }))
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickSize(-height);
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.ticks(5)
.tickSize(-width);
// ZOOM
function zoomed() {
svg.select(".x.axis").call(xAxis);
svg.select(".y.axis").call(yAxis);
svg.select("path")
.attr("class", "area")
.attr("d", line);
}
var zoom = d3.behavior.zoom()
.x(x)
.y(y)
.scaleExtent([1, 10])
.on("zoom", zoomed);
// remove old graph
d3.select("svg").remove();
var svg = d3.select("body")
.append("svg")
.datum(data)
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.call(zoom);
var line = d3.svg.area()
.defined(function(d) { return !isNaN(d[1]); })
.x(function(d) { return x(d[0]); })
.y0(height)
.y1(function(d) { return y(d[1]); });
svg.append("path")
.attr("class", "area")
.attr("d", line);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
}
function input_update() {
new BinaryFile("rrd/"+$('#file').val()+".rrd", update_info);
}
fillFileOptions($('#file'));
//]]>
</script>
</div>