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.
114 lines
3.5 KiB
114 lines
3.5 KiB
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> |
|
<meta content="utf-8" http-equiv="encoding"> |
|
|
|
<script src="../dist/index.js" type="text/javascript"></script> |
|
</head> |
|
<body> |
|
<div id="charts"> |
|
</div> |
|
|
|
<script type="text/javascript"> |
|
|
|
const startTime = 1590590148; |
|
const arrayLength = 200; |
|
const chartsNumber = 150; |
|
const data1 = createDatapoints(arrayLength, startTime, 40); |
|
const data2 = createDatapoints(arrayLength, startTime, 30, 50); |
|
const data3 = createDatapoints(arrayLength, startTime, 20, 90); |
|
|
|
insertHtml(chartsNumber); |
|
|
|
let options = { |
|
renderLegend: false, |
|
axis: { |
|
y: { invert: true, valueFormatter: timeValueFormatter, format: 'custom', colorFormatter: colorFormatter, ticksCount: 6 }, |
|
x: { format: 'numeric' } |
|
}, |
|
// grid: { |
|
// y: { ticksCount: 2000 } |
|
// }, |
|
zoomEvents: { |
|
mouse: { |
|
pan: { isActive: true, orientation: 'vertical', keyEvent: 'shift' }, |
|
zoom: { isActive: true, orientation: 'vertical', keyEvent: 'main' } |
|
}, |
|
scroll: { |
|
pan: { isActive: true, orientation: 'vertical', keyEvent: 'main' }, |
|
zoom: { isActive: false, keyEvent: 'shift' } |
|
} |
|
}, |
|
eventsCallbacks: { zoomIn: zoomIn, zoomOut, panning: onPanning, }, |
|
crosshair: { orientation: 'horizontal' }, |
|
margin: { top: 30, right: 20, bottom: 20, left: 50 } |
|
} |
|
|
|
multileRender(chartsNumber); |
|
|
|
function zoomIn(ranges) { |
|
const range = ranges[1]; |
|
options.axis.y.range = range; |
|
pod.updateData(undefined, options); |
|
} |
|
|
|
function zoomOut() { |
|
options.axis.y.range = undefined; |
|
console.log('zoomOut', pod.updateData); |
|
pod.updateData(undefined, options) |
|
} |
|
|
|
function onPanning() { |
|
console.log('panning', pod); |
|
} |
|
|
|
function createDatapoints(arrayLength, startTime, randomValue, randomOffset = 0) { |
|
return Array.from({ length: arrayLength }, (el, idx) => [ |
|
Math.floor(Math.random() * randomValue) + randomOffset, // x axis |
|
startTime + idx * 10000 // y axis |
|
]); |
|
} |
|
|
|
function timeValueFormatter(value) { |
|
const date = new Date(value); |
|
const hours = date.getHours(); |
|
const minutes = '0' + date.getMinutes(); |
|
const seconds = '0' + date.getSeconds(); |
|
return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); |
|
} |
|
|
|
function colorFormatter(value, index) { |
|
if(index % 2 === 0) { |
|
return 'red'; |
|
} |
|
return 'black'; |
|
} |
|
|
|
function insertHtml(chartsNumber) { |
|
let chartsHtml = ''; |
|
|
|
for(let i = 1; i <= chartsNumber; i++) { |
|
chartsHtml += `<div id="chart-${i}" style="height: 640px; width: 880px"></div>`; |
|
} |
|
|
|
document.getElementById('charts').innerHTML = chartsHtml; |
|
} |
|
|
|
function multileRender(chartsNumber) { |
|
for (let i = 1; i <= chartsNumber; i++) { |
|
const pod = new LinePod( |
|
document.getElementById(`chart-${i}`), |
|
[ |
|
{ target: 'test1', datapoints: data1, color: 'green' }, |
|
{ target: 'test2', datapoints: data2, color: 'blue' }, |
|
{ target: 'test3', datapoints: data3, color: 'orange' }, |
|
], |
|
options |
|
); |
|
pod.render(); |
|
} |
|
} |
|
</script> |
|
</body> |
|
</html>
|
|
|