Debian Codegraph @

debian/missing-sources/epoch/tests/render/real-time/line.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.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 Line Plot Test</h1>
19 <p class="breadcrumbs"><a href="../index.html">Epoch Chart Tests</a> &raquo; Real-time Line</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 <li><a href="#test-10">Show/Hide Layers</a></li>
31 <li><a href="#test-11">Multiaxes</a></li>
32 </ol>
33
34 <!-- Test 1 -->
35 <div id="test-1" class="test">
36 <h2>1. Single Series</h2>
37 <p>
38 Correctly render a single series plot of <code>y = cos(x) + 1</code> over the range <code>[0, 2&pi;]</code>.
39 </p>
40 <div class="epoch"></div>
41 </div>
42
43 <script>
44 $(function() {
45 var data = [{ label: 'A', values: [] }],
46 length = 40;
47
48 for (var i = 0; i < length; i++) {
49 var x = i * 2 * Math.PI / length,
50 y = Math.cos(x) + 1,
51 time = nextTime();
52 data[0].values.push({time: time, y: y});
53 }
54
55 $('#test-1 .epoch').epoch({ type: 'time.line', data: data });
56 });
57 </script>
58
59 <!-- Test 2 -->
60 <div id="test-2" class="test">
61 <h2>2. Single Series Single Transition</h2>
62 <p>
63 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.
64 </p>
65 <div class="epoch"></div>
66 <p><button>Next</button></p>
67 </div>
68
69 <script>
70 $(function() {
71 var data = [{ label: 'A', values: [] }],
72 length = 40,
73 nextIndex = length;
74
75 for (var i = 0; i < length; i++) {
76 var x = i * 2 * Math.PI / length,
77 y = Math.sin(x) + 1,
78 time = nextTime();
79 data[0].values.push({time: time, y: y});
80 }
81
82 var chart = $('#test-2 .epoch').epoch({
83 type: 'time.line',
84 data: data
85 });
86
87 $('#test-2 button').on('click', function(e) {
88 var x = nextIndex * 2 * Math.PI / length,
89 y = Math.sin(x) + 1,
90 time = nextTime();
91 nextIndex++;
92 chart.push([{ time: time, y: y }]);
93 });
94 });
95 </script>
96
97
98 <!-- Test 3 -->
99 <div id="test-3" class="test">
100 <h2>3. Single Seires Stream</h2>
101 <p>Correctly play / pause a single series stream of values from the plot <code>y = cos(x) + 1</code>.</p>
102 <div class="epoch"></div>
103 <p><button>Play</button></p>
104 </div>
105
106 <script>
107 $(function() {
108 var data = [{ label: 'A', values: [] }],
109 length = 40,
110 nextIndex = length,
111 playing = false,
112 interval = null;
113
114 for (var i = 0; i < length; i++) {
115 var x = i * 2 * Math.PI / length,
116 y = Math.cos(x) + 1,
117 time = nextTime();
118 data[0].values.push({time: time, y: y});
119 }
120
121 var chart = $('#test-3 .epoch').epoch({
122 type: 'time.line',
123 data: data
124 });
125
126 var pushPoint = function() {
127 var x = nextIndex * 2 * Math.PI / length,
128 y = Math.cos(x) + 1,
129 time = nextTime();
130 chart.push([{ time: time, y: y}]);
131 nextIndex++;
132 };
133
134 $('#test-3 button').on('click', function(e) {
135 if (playing) {
136 $(e.target).text('Play');
137 clearInterval(interval);
138 }
139 else {
140 $(e.target).text('Pause');
141 pushPoint();
142 interval = setInterval(pushPoint, 1000);
143 }
144 playing = !playing;
145 });
146 });
147 </script>
148
149 <!-- Test 4 -->
150 <div id="test-4" class="test">
151 <h2>4. Multi Series</h2>
152 <p>Correctly render a multi series plot of the following functions:</p>
153 <ul>
154 <li><code>y = log(x+1)</code></li>
155 <li><code>y = 2*log(x+1)</code></li>
156 <li><code>y = 3*log(x+1)</code></li>
157 </ul>
158 <div class="epoch"></div>
159 </div>
160
161 <script>
162 $(function() {
163 var data = [
164 {label: 'A', values: []},
165 {label: 'B', values: []},
166 {label: 'C', values: []}
167 ],
168 length = 40;
169
170 for (var i = 0; i < length; i++) {
171 var x = i + 1,
172 time = nextTime();
173 for (var j = 0; j < data.length; j++) {
174 data[j].values.push({time: time, y: (j+1) * Math.log(x)});
175 }
176 }
177
178 $('#test-4 .epoch').epoch({
179 type: 'time.line',
180 data: data,
181 axes: ['left', 'right', 'bottom']
182 });
183 });
184 </script>
185
186
187 <!-- Test 5 -->
188 <div id="test-5" class="test">
189 <h2>5. Multi Series Single Transition</h2>
190 <p>
191 Correctly render a multi series plot of the following functions:
192 <ul>
193 <li><code>y = x</code></li>
194 <li><code>y = x<sup>1.25</sup></code></li>
195 <li><code>y = x<sup>1.5</sup></code></li>
196 </ul>
197 and correctly render/animate the transiton after pressing the "Next" button.
198 </p>
199 <div class="epoch"></div>
200 <p>
201 <button>Next</button>
202 </p>
203 </div>
204
205 <script>
206 $(function() {
207 var data = [
208 {label: 'A', values: []},
209 {label: 'B', values: []},
210 {label: 'C', values: []}
211 ],
212 length = 40,
213 scale = 0.1,
214 nextIndex = length;
215
216 for (var i = 0; i < length; i++) {
217 var x = i * scale,
218 time = nextTime();
219 data[0].values.push({time: time, y: x});
220 data[1].values.push({time: time, y: Math.pow(x, 1.25)});
221 data[2].values.push({time: time, y: Math.pow(x, 1.5)});
222 }
223
224 var chart = $('#test-5 .epoch').epoch({
225 type: 'time.line',
226 data: data,
227 axes: ['left', 'right', 'bottom']
228 });
229
230 $('#test-5 button').on('click', function(e) {
231 var x = nextIndex * scale,
232 time = nextTime();
233 nextIndex++;
234 chart.push([
235 {time: time, y: x},
236 {time: time, y: Math.pow(x, 1.25)},
237 {time: time, y: Math.pow(x, 1.5)}
238 ]);
239 });
240 });
241 </script>
242
243 <!-- Test 6 -->
244 <div id="test-6" class="test">
245 <h2>6. Multi Seires Stream</h2>
246 <p>
247 Correctly play / pause a multi series stream of values over the following plots:
248 <ul>
249 <li><code>x</code></li>
250 <li><code>x * log(x)</code></li>
251 <li><code>x * log<sup>2</sup>(x)</code></li>
252 </ul>
253 </p>
254 <div class="epoch"></div>
255 <p><button>Play</button></p>
256 </div>
257
258 <script>
259 $(function() {
260 var data = [
261 {label: 'A', values: []},
262 {label: 'B', values: []},
263 {label: 'C', values: []}
264 ],
265 length = 40,
266 nextIndex = length,
267 scale = 0.1,
268 playing = false,
269 interval = null;
270
271 for (var i = 0; i < length; i++) {
272 var x = (i+1) * scale,
273 time = nextTime();
274 data[0].values.push({time: time, y: x});
275 data[1].values.push({time: time, y: x * Math.log(x)});
276 data[2].values.push({time: time, y: x * Math.pow(Math.log(x), 2)});
277 }
278
279 var chart = $('#test-6 .epoch').epoch({
280 type: 'time.line',
281 data: data,
282 axes: ['right', 'bottom']
283 });
284
285 var pushPoint = function() {
286 var x = (nextIndex +1) * scale,
287 time = nextTime();
288 chart.push([
289 { time: time, y: x},
290 { time: time, y: x * Math.log(x)},
291 { time: time, y: x * Math.pow(Math.log(x), 2)}
292 ]);
293 nextIndex++;
294 };
295
296 $('#test-6 button').on('click', function(e) {
297 if (playing) {
298 $(e.target).text('Play');
299 clearInterval(interval);
300 }
301 else {
302 $(e.target).text('Pause');
303 interval = setInterval(pushPoint, 1000);
304 pushPoint();
305 }
306 playing = !playing;
307 });
308 });
309 </script>
310
311 <!-- Test 7 -->
312 <div id="test-7" class="test">
313 <h2>7. Color Override</h2>
314 <p>The first layer should pink, the second green, and the third blue.</p>
315 <div id="test-7-plot" class="epoch"></div>
316 </div>
317
318 <style>
319 #test-7-plot .a .line { stroke: pink; }
320 #test-7-plot .b .line { stroke: green; }
321 #test-7-plot .c .line { stroke: blue; }
322 </style>
323
324 <script>
325 $(function() {
326 var data = [
327 {label: 'A', values: []},
328 {label: 'B', values: []},
329 {label: 'C', values: []}
330 ],
331 length = 40;
332
333 for (var i = 0; i < length; i++) {
334 var x = i + 1,
335 time = nextTime();
336 for (var j = 0; j < data.length; j++) {
337 data[j].values.push({time: time, y: (j+1) * Math.log(x)});
338 }
339 }
340
341 $('#test-7 .epoch').epoch({
342 type: 'time.line',
343 data: data
344 });
345 });
346 </script>
347
348 <!-- Test 8 -->
349 <div id="test-8" class="test">
350 <h2>8. Categorical Colors</h2>
351 <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>
352 Epoch.QueryCSS.purge();
353 chart.draw();
354 </pre></code>
355 </p>
356
357 <div class="epoch category10"></div>
358
359 <p>
360 <button data-class="category10">category10</button>
361 <button data-class="category20">category20</button>
362 <button data-class="category20b">category20b</button>
363 <button data-class="category20c">category20c</button>
364 </p>
365 </div>
366
367 <script>
368 $(function() {
369 var data = [],
370 length = 41,
371 className = "category10",
372 layers = 8,
373 time = nextTime();
374
375 for (var i = 0; i < layers; i++) {
376 var layer = { label: String.fromCharCode(i+65), values: [] };
377 for (var j = 0; j < length; j++) {
378 var x = j + 1,
379 y = Math.pow(x, i * 0.02);
380 layer.values.push({ time: time + j, y: y });
381 }
382 data.push(layer);
383 }
384
385 var chart = $('#test-8 .epoch').epoch({ type: 'time.line', data: data });
386
387 $('#test-8 button').on('click', function(e) {
388 $('#test-8 .epoch').removeClass(className);
389 className = $(e.target).attr('data-class');
390 $('#test-8 .epoch').addClass(className);
391 Epoch.QueryCSS.purge();
392 chart.draw();
393 });
394 });
395 </script>
396
397 <!-- Test 9 -->
398 <div id="test-9" class="test">
399 <h2>9. Show/Hide Layers</h2>
400 <div class="epoch"></div>
401 <p>
402 <button class="toggle" data-index="0">Toggle A</button>
403 <button class="toggle" data-index="1">Toggle B</button>
404 <button class="toggle" data-index="2">Toggle C</button> |
405 <button class="playback">Play</button>
406 </p>
407 </div>
408 <script>
409 $(function() {
410 var data = [
411 {label: 'A', values: []},
412 {label: 'B', values: []},
413 {label: 'C', values: []}
414 ],
415 length = 40,
416 nextIndex = length,
417 scale = 0.1,
418 playing = false,
419 interval = null;
420
421 for (var i = 0; i < length; i++) {
422 var x = (i+1) * scale,
423 time = nextTime();
424 data[0].values.push({time: time, y: x});
425 data[1].values.push({time: time, y: x * Math.log(x)});
426 data[2].values.push({time: time, y: x * Math.pow(Math.log(x), 2)});
427 }
428
429 var chart = $('#test-9 .epoch').epoch({
430 type: 'time.line',
431 data: data,
432 axes: ['right', 'bottom']
433 });
434
435 $('#test-9 .toggle').click(function(e) {
436 var index = parseInt($(e.target).attr('data-index'));
437 chart.toggleLayer(index);
438 });
439
440 var pushPoint = function() {
441 var x = (nextIndex +1) * scale,
442 time = nextTime();
443 chart.push([
444 { time: time, y: x},
445 { time: time, y: x * Math.log(x)},
446 { time: time, y: x * Math.pow(Math.log(x), 2)}
447 ]);
448 nextIndex++;
449 };
450
451 $('#test-9 .playback').on('click', function(e) {
452 if (playing) {
453 $(e.target).text('Play');
454 clearInterval(interval);
455 }
456 else {
457 $(e.target).text('Pause');
458 interval = setInterval(pushPoint, 1000);
459 pushPoint();
460 }
461 playing = !playing;
462 });
463 });
464 </script>
465
466 <!-- Test 10 -->
467 <div id="test-10" class="test">
468 <h2>10. Fixed Range</h2>
469 <p>
470 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>.
471 </p>
472 <div class="epoch"></div>
473 </div>
474
475 <script>
476 $(function() {
477 var data = [{ label: 'A', values: [] }],
478 length = 40;
479
480 for (var i = 0; i < length; i++) {
481 var x = i * 2 * Math.PI / length,
482 y = Math.cos(x),
483 time = nextTime();
484 data[0].values.push({time: time, y: y});
485 }
486
487 $('#test-10 .epoch').epoch({
488 type: 'time.line',
489 axes: ['right', 'bottom'],
490 data: data,
491 range: [-2, 5]
492 });
493 });
494 </script>
495
496 <!-- Test 11 -->
497 <div id="test-11" class="test">
498 <h2>11. Multi-axes</h2>
499 <p>
500 Render a plot that uses independent axes ranges for the left and
501 right sides.
502 </p>
503 <div class="epoch"></div>
504 </div>
505
506 <script>
507 $(function() {
508 var data = [
509 {
510 label: 'A',
511 values: [],
512 range: [-5, 5]
513 },
514 {
515 label: 'B',
516 values: [],
517 range: [0, 100]
518 }
519 ];
520 var length = 40;
521
522 for (var i = 0; i < length; i++) {
523 var x = i * 2 * Math.PI / length,
524 y = Math.cos(x) + x / 4,
525 y2 = i * 100/40,
526 time = nextTime();
527 data[0].values.push({time: time, y: y});
528 data[1].values.push({time: time, y: y2});
529 }
530
531 $('#test-11 .epoch').epoch({
532 type: 'time.line',
533 axes: ['left', 'right'],
534 data: data,
535 range: {
536 right: [-5, 5],
537 left: [0, 100]
538 }
539 });
540 });
541 </script>
542
543 <!-- Test 12 -->
544 <div id="test-12" class="test">
545 <h2>12. Multi-axes with Labeled Ranges</h2>
546 <p>
547 Render a plot that uses independent axes ranges for the left and
548 right sides that are associated to labels in the chart data.
549 </p>
550 <div class="epoch"></div>
551 </div>
552
553 <script>
554 $(function() {
555 var data = [
556 {
557 label: 'A',
558 values: [],
559 range: 'range-one'
560 },
561 {
562 label: 'B',
563 values: [],
564 range: 'range-two'
565 },
566 {
567 label: 'C',
568 values: [],
569 range: 'range-one'
570 }
571 ];
572 var length = 50;
573
574 for (var i = 0; i < length; i++) {
575 var y = Math.random() * 100;
576 var y2 = Math.random() * 2;
577 var y3 = Math.random() * 50 + 75
578 var time = nextTime();
579 data[0].values.push({time: time, y: y});
580 data[1].values.push({time: time, y: y2});
581 data[2].values.push({time: time, y: y3});
582 }
583
584 $('#test-12 .epoch').epoch({
585 type: 'time.line',
586 axes: ['left', 'right'],
587 data: data,
588 range: {
589 right: 'range-one',
590 left: 'range-two'
591 }
592 });
593 });
594 </script>
595 </body>
596 </html>