feat: working scrolling example
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
f31c9a7022
commit
d5d1a30a4c
19
index.html
19
index.html
@ -10,6 +10,9 @@
|
|||||||
display: block;
|
display: block;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
.y-axis {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -87,22 +90,29 @@
|
|||||||
value: Math.random() * 100,
|
value: Math.random() * 100,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Append new data and remove older ones beyond the last 60 seconds
|
||||||
allData = [...allData, ...newData].filter(d =>
|
allData = [...allData, ...newData].filter(d =>
|
||||||
new Date(d.timestamp) >= new Date(Date.now() - 60000)
|
new Date(d.timestamp) >= new Date(Date.now() - 60000)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continuous scroll
|
// Continuous scroll
|
||||||
|
let lastTimestamp = Date.now();
|
||||||
|
|
||||||
d3.timer(elapsed => {
|
d3.timer(elapsed => {
|
||||||
|
const now = Date.now();
|
||||||
|
const delta = now - lastTimestamp;
|
||||||
|
|
||||||
// Generate data periodically (every 1 second)
|
// Generate data periodically (every 1 second)
|
||||||
if (Math.floor(elapsed) % 1000 === 0) {
|
if (delta >= 1000) {
|
||||||
generateData();
|
generateData();
|
||||||
|
lastTimestamp = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the domain of the y-axis
|
// Update the domain of the y-axis
|
||||||
const now = new Date();
|
const currentTime = new Date();
|
||||||
const past = new Date(now.getTime() - 60000);
|
const pastTime = new Date(currentTime.getTime() - 60000);
|
||||||
y.domain([past, now]);
|
y.domain([pastTime, currentTime]);
|
||||||
|
|
||||||
// Update positions of all heatmap cells
|
// Update positions of all heatmap cells
|
||||||
updateHeatmap(allData);
|
updateHeatmap(allData);
|
||||||
@ -113,3 +123,4 @@
|
|||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user