You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.8 KiB
60 lines
2.8 KiB
3 years ago
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
|
||
|
<head>
|
||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
||
|
<meta content="utf-8" http-equiv="encoding">
|
||
|
|
||
3 years ago
|
<script src="../dist/index.dev.js" type="text/javascript"></script>
|
||
3 years ago
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<div id="chart" style="width: 500px; height: 500px;"></div>
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
const startTime = 1590590148;
|
||
|
const arrayLength = 100;
|
||
3 years ago
|
this.isZoomed = false; // TODO: temporary hack to have zoomin|zoomout with `appendData`. It will be moved to Pod.
|
||
3 years ago
|
var data1 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 40)]);
|
||
|
var data2 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 100)]);
|
||
|
var data3 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 20) + 90]);
|
||
3 years ago
|
const zoomIn = (ranges) => { const xRange = ranges[0]; options.axis.x.range = xRange; pod.updateData(undefined, options); this.isZoomed = true }
|
||
|
const zoomOut = (ranges) => { options.axis.x.range = undefined; pod.updateData(undefined, options); this.isZoomed = false }
|
||
|
let options = { renderLegend: false, axis: { y: { invert: false, range: [0, 350] }, x: { format: 'time' } }, eventsCallbacks: { zoomIn: zoomIn, zoomOut } };
|
||
3 years ago
|
var pod = new LinePod(
|
||
3 years ago
|
document.getElementById('chart'),
|
||
|
[
|
||
|
{ target: 'test1', datapoints: data1, color: 'green', maxLength: arrayLength + 30, renderDots: true },
|
||
|
{ target: 'test2', datapoints: data2, color: 'blue', maxLength: arrayLength + 30, renderDots: true },
|
||
|
{ target: 'test3', datapoints: data3, color: 'orange', maxLength: arrayLength + 30, renderDots: true },
|
||
|
],
|
||
|
options
|
||
|
);
|
||
|
pod.render();
|
||
|
let rerenderIdx = arrayLength;
|
||
|
var test = setInterval(() => {
|
||
|
rerenderIdx += 1;
|
||
3 years ago
|
const d1 = [startTime + rerenderIdx * 10000, Math.floor(Math.random() * 20) + 90];
|
||
|
const d2 = [startTime + rerenderIdx * 10000, Math.floor(Math.random() * 100)];
|
||
|
const d3 = [startTime + rerenderIdx * 10000, Math.floor(Math.random() * 20) + 90];
|
||
3 years ago
|
console.log('d1', data1)
|
||
3 years ago
|
const shouldRerender = !this.isZoomed;
|
||
3 years ago
|
console.time('rerender');
|
||
3 years ago
|
data1.push(d1);
|
||
|
data2.push(d2);
|
||
|
data3.push(d3);
|
||
|
pod.updateData([
|
||
|
{ target: 'test1', datapoints: data1, color: 'green', maxLength: arrayLength + 30, renderDots: false },
|
||
|
{ target: 'test2', datapoints: data2, color: 'blue', maxLength: arrayLength + 30, renderDots: false },
|
||
|
{ target: 'test3', datapoints: data3, color: 'orange', maxLength: arrayLength + 30, renderDots: false },
|
||
|
]);
|
||
3 years ago
|
console.timeEnd('rerender');
|
||
|
if(rerenderIdx > arrayLength + 100) {
|
||
|
clearInterval(test);
|
||
|
}
|
||
|
}, 1000);
|
||
|
</script>
|
||
|
</body>
|
||
|
|
||
|
</html>
|