-
Notifications
You must be signed in to change notification settings - Fork 4
/
Stickler+4.4.2a.php
230 lines (189 loc) · 6.34 KB
/
Stickler+4.4.2a.php
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
<?php
/**
* Created by JetBrains PhpStorm.
* User: DStickler
* Date: 5/12/12
* Time: 10:06 PM
* To change this template use File | Settings | File Templates.
*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Scale Graph</title>
</head>
<body>
<div id="demoContainer">
<div id="option">
<input name="updateButton" type="button" value="Update" onclick="updateData()" />
</div>
<div id="mainGraph">
</div>
</div>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.27.1"></script>
<script type="text/javascript">
/* Global variables */
/* Definition code */
function randomData() {
return d3.range(10).map(function(i) {
return {x: i / 9, y: Math.random()};
});
}
function reDomain(maxValue) {
var dy = Math.pow(10, Math.round(Math.log(maxValue) / Math.log(10)) - 1);
return Math.ceil(maxValue / dy) * dy;
}
function updateData() {
var data = randomData();
var newMaxY = d3.max(data, function(d) {return d.y;});
var newCeilY = reDomain(newMaxY);
var w = 450,
h = 450,
x = d3.scale.linear().domain([0, 1]).range([0, w]),
y = d3.scale.linear().domain([0, newCeilY]).range([h, 0]);
var vis = d3.select("#mainGraph svg g");
var yrule = vis.selectAll("g.y")
.data(y.ticks(10));
// yRule Enter
var newrule = yrule.enter().append("svg:g")
.attr("class", "y");
newrule.append("svg:line")
.attr("class", "yLine")
.style("stroke", "#ccc")
.style("shape-rendering", "crispEdges")
.attr("x1", 0)
.attr("x2", w)
.attr("y1", 0)
.attr("y2", 0)
.transition()
.duration(2000)
.attr("y1", y)
.attr("y2", y);
newrule.append("svg:text")
.attr("class", "yText")
.attr("x", -3)
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("y", 0)
.transition()
.duration(2000)
.attr("y", y)
.text(y.tickFormat(10));
// yLine Update
yrule.select("line.yLine")
.transition()
.duration(2000)
.attr("y1", y)
.attr("y2", y);
// yText Update
yrule.select("text.yText")
.transition()
.duration(2000)
.attr("y", y)
.text(y.tickFormat(10));
// yrule Remove
var oldrule = yrule.exit();
oldrule.select("line.yLine")
.transition()
.duration(2000)
.attr("y1", 0)
.attr("y2", 0)
.remove();
oldrule.select("text.yText")
.transition()
.duration(2000)
.attr("y", 0)
.remove();
oldrule.transition()
.duration(2000).remove();
// Dots
var node = vis.selectAll("path.dot")
.data(data)
.transition()
.duration(2000)
.attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; });
node.select("title.dotTitle")
.text(function(d) { return "X: " + d.x.toFixed(3) + ", Y: " + d.y.toFixed(3); });
}
var initData = function () {
var data = randomData();
var newMaxY = d3.max(data, function (d) {
return d.y;
});
var newCeilY = reDomain(newMaxY);
var w = 450,
h = 450,
p = 50,
x = d3.scale.linear().domain([0, 1]).range([0, w]),
y = d3.scale.linear().domain([0, newCeilY]).range([h, 0]);
var chart = d3.select("#mainGraph")
.append("svg:svg")
.attr("width", w + p * 2)
.attr("height", h + p * 2);
var vis = chart.append("svg:g")
.attr("transform", "translate(" + p + "," + p + ")");
var xrule = vis.selectAll("g.x")
.data(x.ticks(10))
.enter().append("svg:g")
.attr("class", "x");
xrule.append("svg:line")
.style("stroke", "#ccc")
.style("shape-rendering", "crispEdges")
.attr("x1", x)
.attr("x2", x)
.attr("y1", 0)
.attr("y2", h);
xrule.append("svg:text")
.attr("x", x)
.attr("y", h + 3)
.attr("dy", ".71em")
.attr("text-anchor", "middle")
.text(x.tickFormat(10));
var yrule = vis.selectAll("g.y")
.data(y.ticks(10))
.enter().append("svg:g")
.attr("class", "y");
yrule.append("svg:line")
.attr("class", "yLine")
.style("stroke", "#ccc")
.style("shape-rendering", "crispEdges")
.attr("x1", 0)
.attr("x2", w)
.attr("y1", y)
.attr("y2", y);
yrule.append("svg:text")
.attr("class", "yText")
.attr("x", -3)
.attr("y", y)
.attr("dy", ".35em")
.attr("text-anchor", "end")
.text(y.tickFormat(10));
var node = vis.selectAll("path.dot")
.data(data)
.enter().append("svg:path")
.attr("class", "dot")
.style("fill", "white")
.style("stroke-width", "1.5px")
.attr("stroke", "#9acd32")
.attr("transform", function (d) {
return "translate(" + x(d.x) + "," + y(d.y) + ")";
})
.attr("d", d3.svg.symbol())
.on("mouseover", function (d, i) {
d3.select(this).transition().duration(300).style("fill", "#00ffff");
})
.on("mouseout", function (d, i) {
d3.select(this).transition().duration(300).style("fill", "white");
});
node.append("svg:title")
.attr("class", "dotTitle")
.text(function (d) {
return "X: " + d.x.toFixed(3) + ", Y: " + d.y.toFixed(3);
});
};
/* UI Events */
/* Execution code */
initData();
</script>
</body>
</html>