|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 4 | + * See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 5 | + * All rights not expressly granted are reserved. |
| 6 | + * |
| 7 | + * This software is distributed under the terms of the GNU General Public |
| 8 | + * License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 9 | + * |
| 10 | + * In applying this license CERN does not waive the privileges and immunities |
| 11 | + * granted to it by virtue of its status as an Intergovernmental Organization |
| 12 | + * or submit itself to any jurisdiction. |
| 13 | + */ |
| 14 | + |
| 15 | +import {mount, h, Observable, chartTimeSeries} from '/js/src/index.js'; |
| 16 | + |
| 17 | +// Example of chart integration with template engine |
| 18 | +const view = (model) => [ |
| 19 | + h('div.m4', [ |
| 20 | + chartTimeSeries({ |
| 21 | + series: model.series1, |
| 22 | + title: 'Sinus', |
| 23 | + colorPrimary: 'red', |
| 24 | + width: '800', |
| 25 | + }), |
| 26 | + ]), |
| 27 | + h('div.m4', [ |
| 28 | + chartTimeSeries({ |
| 29 | + series: model.series1, |
| 30 | + title: 'Sinus', |
| 31 | + colorPrimary: 'red', |
| 32 | + width: '800', |
| 33 | + timeWindow: 100, |
| 34 | + }), |
| 35 | + ]), |
| 36 | + h('div.m4', [ |
| 37 | + chartTimeSeries({ |
| 38 | + series: model.series2, |
| 39 | + title: 'Random', |
| 40 | + colorPrimary: 'blue', |
| 41 | + width: '800', |
| 42 | + }), |
| 43 | + ]), |
| 44 | + h('div.m4', [ |
| 45 | + chartTimeSeries({ |
| 46 | + series: model.series3, |
| 47 | + title: 'Sinus rounded', |
| 48 | + colorPrimary: 'green', |
| 49 | + width: '800', |
| 50 | + }), |
| 51 | + ]), |
| 52 | +]; |
| 53 | + |
| 54 | +// Create some basic model |
| 55 | +const model = new Observable(); |
| 56 | +model.series1 = []; |
| 57 | +model.series2 = []; |
| 58 | +model.series3 = []; |
| 59 | +model.notify(); |
| 60 | + |
| 61 | +// Add points at 30 FPS but keep only first 800 points for memory leak |
| 62 | +let i = 0; |
| 63 | +setInterval(() => { |
| 64 | + i++; |
| 65 | + model.series1.push({value: Math.cos(i / 10), timestamp: Date.now()}); |
| 66 | + model.series2.push({value: Math.random() * 10, timestamp: Date.now()}); |
| 67 | + model.series3.push({value: Math.round(Math.cos(i / 10)), timestamp: Date.now()}); |
| 68 | + |
| 69 | + model.series1.splice(0, model.series1.length - 800); |
| 70 | + model.series2.splice(0, model.series2.length - 800); |
| 71 | + model.series3.splice(0, model.series3.length - 800); |
| 72 | + |
| 73 | + model.notify(); |
| 74 | +}, 33); |
| 75 | + |
| 76 | +mount(document.body, view, model, true); |
| 77 | + |
| 78 | +window.model = model; |
0 commit comments