Add the no sensors test.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<b>value</b>
|
||||
<div id="value"><svg></svg></div>
|
||||
|
||||
<script type="module">
|
||||
import * as d3_module from "https://cdn.jsdelivr.net/npm/d3@7";
|
||||
import * as Plot from "https://cdn.skypack.dev/@observablehq/plot@0.4";
|
||||
|
||||
var current_dataset = [];
|
||||
while (true) {
|
||||
// fetch new data
|
||||
await d3.json("/data").then(function(data) {
|
||||
// then append to list
|
||||
current_dataset.push(data);
|
||||
// Map to a 10s (n S) sliding window
|
||||
// ie find the most recent value, then reduce/filter anything more than 10s earlier than that.
|
||||
const most_recent_time = current_dataset[current_dataset.length - 1].time;
|
||||
const window_start = Math.max(0, most_recent_time - 10);
|
||||
// filter the list
|
||||
current_dataset = current_dataset.filter(
|
||||
value => value.time >= window_start
|
||||
);
|
||||
// render dist graph
|
||||
var value_graph = Plot.plot({
|
||||
x: { grid: true},
|
||||
y: { grid: true},
|
||||
marks: [
|
||||
Plot.line(current_dataset, {x: "time", y: "value", stroke: "red"}),
|
||||
]
|
||||
});
|
||||
var graphNode = document.getElementById("value");
|
||||
graphNode.replaceChild(value_graph, graphNode.firstChild);
|
||||
});
|
||||
}
|
||||
// }
|
||||
</script>
|
||||
Reference in New Issue
Block a user