Debian Codegraph @

debian/missing-sources/epoch/tests/render/real-time/area.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link rel="stylesheet" type="text/css" href="../css/tests.css">
5 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
6 <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
7 <script src="../../../dist/js/epoch.js"></script>
8 <link rel="stylesheet" type="text/css" href="../../../dist/css/epoch.css">
9
10 <script>
11 var nextTime = (function() {
12 var currentTime = parseInt(new Date().getTime() / 1000);
13 return function() { return currentTime++; }
14 })();
15 </script>
16 </head>
17 <body>
18 <h1>Real-time Area Plot Test</h1>
19 <p class="breadcrumbs"><a href="../index.html">Epoch Chart Tests</a> &raquo; Real-time Area</p>
20 <ol>
21 <li><a href="#test-1">Single Series</a></li>
22 <li><a href="#test-2">Single Series Single Transition</a></li>
23 <li><a href="#test-3">Single Seires Stream</a></li>
24 <li><a href="#test-4">Multi Series</a></li>
25 <li><a href="#test-5">Multi Series Single Transition</a></li>
26 <li><a href="#test-6">Multi Seires Stream</a></li>
27 <li><a href="#test-7">Color Override</a></li>
28 <li><a href="#test-8">Categorical Colors</a></li>
29 <li><a href="#test-9">Show/Hide Layers</a></li>
30 </ol>
31
32 <!-- Test 1 -->
33 <div id="test-1" class="test">
34 <h2>1. Single Series</h2>
35 <p>
36 Correctly render a single series plot of <code>y = cos(x) + 1</code> over the range <code>[0, 2&pi;]</code>.
37 </p>
38 <div class="epoch"></div>
39 </div>
40
41 <script>
42 $(function() {
43 var data = [{ label: 'A', values: [] }],
44 length = 40;
45
46 for (var i = 0; i < length; i++) {
47 var x = i * 2 * Math.PI / length,
48 y = Math.cos(x) + 1,
49 time = nextTime();
50 data[0].values.push({time: time, y: y});
51 }
52
53 $('#test-1 .epoch').epoch({ type: 'time.area', data: data });
54 });
55 </script>
56
57 <!-- Test 2 -->
58 <div id="test-2" class="test">
59 <h2>2. Single Series Single Transition</h2>
60 <p>
61 Correctly render a single series plot of <code>y = sin(x) + 1</code>. When the button is pressed push a new data point to the chart and correctly animate/render the transiton.
62 </p>
63 <div class="epoch"></div>
64 <p><button>Next</button></p>
65 </div>
66
67 <script>
68 $(function() {
69 var data = [{ label: 'A', values: [] }],
70 length = 40,
71 nextIndex = length;
72
73 for (var i = 0; i < length; i++) {
74 var x = i * 2 * Math.PI / length,
75 y = Math.sin(x) + 1,
76 time = nextTime();
77 data[0].values.push({time: time, y: y});
78 }
79
80 var chart = $('#test-2 .epoch').epoch({
81 type: 'time.area',
82 data: data
83 });
84
85 $('#test-2 button').on('click', function(e) {
86 var x = nextIndex * 2 * Math.PI / length,
87 y = Math.sin(x) + 1,
88 time = nextTime();
89 nextIndex++;
90 chart.push([{ time: time, y: y }]);
91 });
92 });
93 </script>
94
95
96 <!-- Test 3 -->
97 <div id="test-3" class="test">
98 <h2>3. Single Seires Stream</h2>
99 <p>Correctly play / pause a single series stream of values from the plot <code>y = cos(x) + 1</code>.</p>
100 <div class="epoch"></div>
101 <p><button>Play</button></p>
102 </div>
103
104 <script>
105 $(function() {
106 var data = [{ label: 'A', values: [] }],
107 length = 40,
108 nextIndex = length,
109 playing = false,
110 interval = null;
111
112 for (var i = 0; i < length; i++) {
113 var x = i * 2 * Math.PI / length,
114 y = Math.cos(x) + 1,
115 time = nextTime();
116 data[0].values.push({time: time, y: y});
117 }
118
119 var chart = $('#test-3 .epoch').epoch({
120 type: 'time.area',
121 data: data
122 });
123
124 var pushPoint = function() {
125 var x = nextIndex * 2 * Math.PI / length,
126 y = Math.cos(x) + 1,
127 time = nextTime();
128 chart.push([{ time: time, y: y}]);
129 nextIndex++;
130 };
131
132 $('#test-3 button').on('click', function(e) {
133 if (playing) {
134 $(e.target).text('Play');
135 clearInterval(interval);
136 }
137 else {
138 $(e.target).text('Pause');
139 pushPoint();
140 interval = setInterval(pushPoint, 1000);
141 }
142 playing = !playing;
143 });
144 });
145 </script>
146
147 <!-- Test 4 -->
148 <div id="test-4" class="test">
149 <h2>4. Multi Series</h2>
150 <p>Correctly render a multi series plot of the following functions:</p>
151 <ul>
152 <li><code>y = log(x+1)</code></li>
153 <li><code>y = 2*log(x+1)</code></li>
154 <li><code>y = 3*log(x+1)</code></li>
155 </ul>
156 <div class="epoch"></div>
157 </div>
158
159 <script>
160 $(function() {
161 var data = [
162 {label: 'A', values: []},
163 {label: 'B', values: []},
164 {label: 'C', values: []}
165 ],
166 length = 40;
167
168 for (var i = 0; i < length; i++) {
169 var x = i + 1,
170 time = nextTime();
171 for (var j = 0; j < data.length; j++) {
172 data[j].values.push({time: time, y: (j+1) * Math.log(x)});
173 }
174 }
175
176 $('#test-4 .epoch').epoch({
177 type: 'time.area',
178 data: data,
179 axes: ['left', 'right', 'bottom']
180 });
181 });
182 </script>
183
184
185 <!-- Test 5 -->
186 <div id="test-5" class="test">
187 <h2>5. Multi Series Single Transition</h2>
188 <p>
189 Correctly render a multi series plot of the following functions:
190 <ul>
191 <li><code>y = x</code></li>
192 <li><code>y = x<sup>1.25</sup></code></li>
193 <li><code>y = x<sup>1.5</sup></code></li>
194 </ul>
195 and correctly render/animate the transiton after pressing the "Next" button.
196 </p>
197 <div class="epoch"></div>
198 <p>
199 <button>Next</button>
200 </p>
201 </div>
202
203 <script>
204 $(function() {
205 var data = [
206 {label: 'A', values: []},
207 {label: 'B', values: []},
208 {label: 'C', values: []}
209 ],
210 length = 40,
211 scale = 0.1,
212 nextIndex = length;
213
214 for (var i = 0; i < length; i++) {
215 var x = i * scale,
216 time = nextTime();
217 data[0].values.push({time: time, y: x});
218 data[1].values.push({time: time, y: Math.pow(x, 1.25)});
219 data[2].values.push({time: time, y: Math.pow(x, 1.5)});
220 }
221
222 var chart = $('#test-5 .epoch').epoch({
223 type: 'time.area',
224 data: data,
225 axes: ['left', 'right', 'bottom']
226 });
227
228 $('#test-5 button').on('click', function(e) {
229 var x = nextIndex * scale,
230 time = nextTime();
231 nextIndex++;
232 chart.push([
233 {time: time, y: x},
234 {time: time, y: Math.pow(x, 1.25)},
235 {time: time, y: Math.pow(x, 1.5)}
236 ]);
237 });
238 });
239 </script>
240
241 <!-- Test 6 -->
242 <div id="test-6" class="test">
243 <h2>6. Multi Seires Stream</h2>
244 <p>
245 Correctly play / pause a multi series stream of values over the following plots:
246 <ul>
247 <li><code>x</code></li>
248 <li><code>x * log(x)</code></li>
249 <li><code>x * log<sup>2</sup>(x)</code></li>
250 </ul>
251 </p>
252 <div class="epoch"></div>
253 <p><button>Play</button></p>
254 </div>
255
256 <script>
257 $(function() {
258 var data = [
259 {label: 'A', values: []},
260 {label: 'B', values: []},
261 {label: 'C', values: []}
262 ],
263 length = 40,
264 nextIndex = length,
265 scale = 0.1,
266 playing = false,
267 interval = null;
268
269 for (var i = 0; i < length; i++) {
270 var x = (i+1) * scale,
271 time = nextTime();
272 data[0].values.push({time: time, y: x});
273 data[1].values.push({time: time, y: x * Math.log(x)});
274 data[2].values.push({time: time, y: x * Math.pow(Math.log(x), 2)});
275 }
276
277 var chart = $('#test-6 .epoch').epoch({
278 type: 'time.area',
279 data: data,
280 axes: ['right', 'bottom']
281 });
282
283 var pushPoint = function() {
284 var x = (nextIndex +1) * scale,
285 time = nextTime();
286 chart.push([
287 { time: time, y: x},
288 { time: time, y: x * Math.log(x)},
289 { time: time, y: x * Math.pow(Math.log(x), 2)}
290 ]);
291 nextIndex++;
292 };
293
294 $('#test-6 button').on('click', function(e) {
295 if (playing) {
296 $(e.target).text('Play');
297 clearInterval(interval);
298 }
299 else {
300 $(e.target).text('Pause');
301 interval = setInterval(pushPoint, 1000);
302 pushPoint();
303 }
304 playing = !playing;
305 });
306 });
307 </script>
308
309 <!-- Test 7 -->
310 <div id="test-7" class="test">
311 <h2>7. Color Override</h2>
312 <p>The first layer should pink, the second green, and the third blue.</p>
313 <div id="test-7-plot" class="epoch"></div>
314 </div>
315
316 <style>
317 #test-7-plot .a .area { fill: pink; }
318 #test-7-plot .b .area { fill: green; }
319 #test-7-plot .c .area { fill: blue; }
320 </style>
321
322 <script>
323 $(function() {
324 var data = [
325 {label: 'A', values: []},
326 {label: 'B', values: []},
327 {label: 'C', values: []}
328 ],
329 length = 40;
330
331 for (var i = 0; i < length; i++) {
332 var x = i + 1,
333 time = nextTime();
334 for (var j = 0; j < data.length; j++) {
335 data[j].values.push({time: time, y: (j+1) * Math.log(x)});
336 }
337 }
338
339 $('#test-7 .epoch').epoch({
340 type: 'time.area',
341 data: data
342 });
343 });
344 </script>
345
346 <!-- Test 8 -->
347 <div id="test-8" class="test">
348 <h2>8. Categorical Colors</h2>
349 <p>Correctly render and switch between different categorical colors. Unlike with the basic charts this doesn't occur just by switching the class name on the containing element. The CSS query engine must be purge and the plot must be manually redrawn, like so:<code><pre>
350 Epoch.QueryCSS.purge();
351 chart.draw();
352 </pre></code>
353 </p>
354
355 <div class="epoch category10"></div>
356
357 <p>
358 <button data-class="category10">category10</button>
359 <button data-class="category20">category20</button>
360 <button data-class="category20b">category20b</button>
361 <button data-class="category20c">category20c</button>
362 </p>
363 </div>
364
365 <script>
366 $(function() {
367 var data = [],
368 length = 41,
369 className = "category10",
370 layers = 8,
371 time = nextTime();
372
373 for (var i = 0; i < layers; i++) {
374 var layer = { label: String.fromCharCode(i+65), values: [] };
375 for (var j = 0; j < length; j++) {
376 var x = j + 1,
377 y = Math.pow(x, 1 + 0.3 * Math.log(Math.log(Math.log(x+1) + 1) + 1));
378 layer.values.push({ time: time + j, y: y });
379 }
380 data.push(layer);
381 }
382
383 var chart = $('#test-8 .epoch').epoch({ type: 'time.area', data: data });
384
385 $('#test-8 button').on('click', function(e) {
386 $('#test-8 .epoch').removeClass(className);
387 className = $(e.target).attr('data-class');
388 $('#test-8 .epoch').addClass(className);
389 Epoch.QueryCSS.purge();
390 chart.draw();
391 });
392 });
393 </script>
394
395 <!-- Test 9 -->
396 <div id="test-9" class="test">
397 <h2>9. Show/Hide Layers</h2>
398 <div class="epoch"></div>
399 <p>
400 <button class="toggle" data-index="0">Toggle A</button>
401 <button class="toggle" data-index="1">Toggle B</button>
402 <button class="toggle" data-index="2">Toggle C</button> |
403 <button class="playback">Play</button>
404 </p>
405 </div>
406 <script>
407 $(function() {
408 var data = [
409 {label: 'A', values: []},
410 {label: 'B', values: []},
411 {label: 'C', values: []}
412 ],
413 length = 40,
414 nextIndex = length,
415 scale = 0.1,
416 playing = false,
417 interval = null;
418
419 for (var i = 0; i < length; i++) {
420 var x = (i+1) * scale,
421 time = nextTime();
422 data[0].values.push({time: time, y: x});
423 data[1].values.push({time: time, y: 1.5*x});
424 data[2].values.push({time: time, y: 2*x});
425 }
426
427 var chart = $('#test-9 .epoch').epoch({
428 type: 'time.area',
429 data: data,
430 axes: ['right', 'bottom']
431 });
432
433 var pushPoint = function() {
434 var x = (nextIndex +1) * scale,
435 time = nextTime();
436 chart.push([
437 { time: time, y: x},
438 { time: time, y: 1.5*x},
439 { time: time, y: 2*x}
440 ]);
441 nextIndex++;
442 };
443
444 $('#test-9 button.toggle').click(function(e) {
445 var index = parseInt($(e.target).attr('data-index'));
446 chart.toggleLayer(index);
447 });
448
449 $('#test-9 button.playback').on('click', function(e) {
450 if (playing) {
451 $(e.target).text('Play');
452 clearInterval(interval);
453 }
454 else {
455 $(e.target).text('Pause');
456 interval = setInterval(pushPoint, 1000);
457 pushPoint();
458 }
459 playing = !playing;
460 });
461 });
462 </script>
463
464 <!-- Test 10 -->
465 <div id="test-10" class="test">
466 <h2>10. Fixed Range</h2>
467 <p>
468 Render a single series plot of <code>y = cos(x)</code>. Instead of automatically setting the range to <code>[-1, 1]</code>, the range is manually set to <code>[-2, 5]</code>.
469 </p>
470 <div class="epoch"></div>
471 </div>
472
473 <script>
474 $(function() {
475 var data = [{ label: 'A', values: [] }],
476 length = 40;
477
478 for (var i = 0; i < length; i++) {
479 var x = i * 2 * Math.PI / length,
480 y = Math.cos(x),
481 time = nextTime();
482 data[0].values.push({time: time, y: y});
483 }
484
485 $('#test-10 .epoch').epoch({
486 type: 'time.area',
487 axes: ['right', 'bottom'],
488 data: data,
489 range: [-2, 5]
490 });
491 });
492 </script>
493 </body>
494 </html>