function timeSeriesChart({
lines = [],
page = 0,
limit = 1000,
width = innerWidth,
height = undefined
}) {
const transformedData = lines.map(l => {
let start = Math.trunc(page * limit);
let end = start + limit;
if (start > l.data.length || end > l.data.length) {
start = l.data.length - limit;
end = l.data.length;
}
return m4(l.data.slice(start, end), width)
});
const defaultColor = 'black';
return Plot.plot({
width,
height,
x: {
label: "Time",
grid: true
},
y: {
axis: "right",
grid: true,
nice: true
},
marks: [
...transformedData.map((data, idx) => Plot.line(data, { stroke: lines[idx].color })),
...transformedData.map((data, idx) => Plot.dot(data, Plot.pointerX({
fill: lines[idx].color || defaultColor,
stroke: lines[idx].color || defaultColor
}))),
...transformedData.map((data, idx) => Plot.text(data, Plot.pointerX({
px: "0",
py: "1",
dy: -17,
dx: 120 * idx,
frameAnchor: "top-left",
fontVariant: "tabular-nums",
fontWeight: 'bold',
text: d => `${lines[idx].label || ''}${d[1].toFixed(2)}`,
fill: lines[idx].color || defaultColor
})))
]
})
}