Debian Codegraph @

debian/missing-sources/epoch/tests/render/real-time/bar.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 Bar Test</h1>
19 <p class="breadcrumbs"><a href="../index.html">Epoch Chart Tests</a> &raquo; Real-time Bar</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.bar', 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.bar',
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.bar',
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.bar',
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.bar',
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.bar',
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 .bar.a { fill: pink; }
318 #test-7-plot .bar.b { fill: green; }
319 #test-7-plot .bar.c { 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.bar',
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.bar', 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 time = nextTime(),
414 j = 0,
415 interval = null;
416
417 for (var i = 0; i < data.length; i++) {
418 for (j = 0; j < 60; j++) {
419 data[i].values.push({time: time+j, y: 0.25*(i+4)*j })
420 }
421 }
422
423 function nextPoint() {
424 var entry = []
425 for (var i = 0; i < data.length; i++) {
426 entry.push({time: time+j, y: 0.25*(i+4)*j });
427 }
428 chart.push(entry);
429 j++;
430 }
431
432 var chart = $('#test-9 .epoch').epoch({ type: 'time.bar', data: data });
433
434 $('#test-9 .toggle').click(function(e) {
435 var index = parseInt($(e.target).attr('data-index'));
436 chart.toggleLayer(index);
437 });
438
439 $('#test-9 .playback').click(function(e) {
440 if (interval == null) {
441 interval = setInterval(nextPoint, 1000);
442 nextPoint();
443 $(e.target).text('Pause');
444 }
445 else {
446 clearInterval(interval);
447 interval = null;
448 $(e.target).text('Play');
449 }
450 });
451 });
452 </script>
453
454 <!-- Test 10 -->
455 <div id="test-10" class="test">
456 <h2>10. Fixed Range</h2>
457 <p>
458 Render a single series plot of <code>y = cos(x) + 1</code>. Instead of automatically setting the range to <code>[0, 2]</code>, the range is manually set to <code>[0, 5]</code>.
459 </p>
460 <div class="epoch"></div>
461 </div>
462
463 <script>
464 $(function() {
465 var data = [{ label: 'A', values: [] }],
466 length = 40;
467
468 for (var i = 0; i < length; i++) {
469 var x = i * 2 * Math.PI / length,
470 y = Math.cos(x) + 1,
471 time = nextTime();
472 data[0].values.push({time: time, y: y});
473 }
474
475 $('#test-10 .epoch').epoch({
476 type: 'time.bar',
477 axes: ['right', 'bottom'],
478 data: data,
479 range: [0, 5]
480 });
481 });
482 </script>
483 </body>
484 </html>