Skip to content

Commit 3a9cb57

Browse files
committed
web: MqttComponents: snap to specified y-axis dimensions
As of now the y-Axis auto-scales to match the values in the plot. This means it expands the axis to arbitrarily small values, making every bit of ADC noise look huge. Specify explicit ranges to snap to instead. The selected values are not completely random. The DUT voltage ranges for example are choosen just above typical supply voltages (5V, 12V, 24V, 48V). Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent 93d4728 commit 3a9cb57

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

web/src/DashboardDut.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@ export default function DashboardDut() {
106106
<MqttChart
107107
title="DUT Voltage"
108108
topic="/v1/dut/feedback/voltage"
109+
maxSnapPoints={[6, 13, 25, 50]}
110+
minSnapPoints={[-1]}
109111
/>
110112
</Box>
111113
<Box>
112114
<Box variant="awsui-key-label">DUT current (A)</Box>
113115
<MqttChart
114116
title="DUT Current"
115117
topic="/v1/dut/feedback/current"
118+
maxSnapPoints={[0.5, 1, 2, 3, 4, 5]}
119+
minSnapPoints={[-0.1, -1]}
116120
/>
117121
</Box>
118122
</ColumnLayout>
@@ -248,6 +252,8 @@ export default function DashboardDut() {
248252
<MqttChart
249253
title={`OUT_${port} Voltage`}
250254
topic={`/v1/output/out_${port}/feedback/voltage`}
255+
maxSnapPoints={[4, 6]}
256+
minSnapPoints={[-4, -6]}
251257
/>
252258
</UnloadingSection>
253259
</SpaceBetween>
@@ -316,6 +322,8 @@ export default function DashboardDut() {
316322
<MqttChart
317323
title="IOBus current"
318324
topic="/v1/iobus/feedback/current"
325+
maxSnapPoints={[0.25]}
326+
minSnapPoints={[0]}
319327
/>
320328
</UnloadingSection>
321329
<MqttBarMeter
@@ -333,6 +341,8 @@ export default function DashboardDut() {
333341
<MqttChart
334342
title="IOBus current"
335343
topic="/v1/iobus/feedback/voltage"
344+
maxSnapPoints={[13]}
345+
minSnapPoints={[0]}
336346
/>
337347
</UnloadingSection>
338348
</SpaceBetween>
@@ -397,6 +407,8 @@ export default function DashboardDut() {
397407
<MqttChart
398408
title={`Port ${port} current`}
399409
topic={`/v1/usb/host/port${port}/feedback/current`}
410+
maxSnapPoints={[0.5]}
411+
minSnapPoints={[0]}
400412
/>
401413
</UnloadingSection>
402414
</SpaceBetween>

web/src/MqttComponents.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ function measToPoint(m: Measurement) {
262262
interface MqttChartProps {
263263
title: string;
264264
topic: string;
265+
maxSnapPoints: Array<number>;
266+
minSnapPoints: Array<number>;
265267
}
266268

267269
export function MqttChart(props: MqttChartProps) {
@@ -272,6 +274,26 @@ export function MqttChart(props: MqttChartProps) {
272274
);
273275
let values = history.current;
274276

277+
// Find y-axis snap points that are smaller/larger than all samples in view.
278+
let minSnap = 0;
279+
let maxSnap = 0;
280+
281+
for (let i = 0; i < values.length; i++) {
282+
while (
283+
minSnap < props.minSnapPoints.length - 1 &&
284+
values[i]["y"] < props.minSnapPoints[minSnap]
285+
) {
286+
minSnap++;
287+
}
288+
289+
while (
290+
maxSnap < props.maxSnapPoints.length - 1 &&
291+
values[i]["y"] > props.maxSnapPoints[maxSnap]
292+
) {
293+
maxSnap++;
294+
}
295+
}
296+
275297
let end = values.length >= 1 ? values[values.length - 1]["x"] : new Date();
276298

277299
let series: MixedLineBarChartProps.ChartSeries<Date> = {
@@ -291,6 +313,7 @@ export function MqttChart(props: MqttChartProps) {
291313
((Number(e) - Number(end)) / 1000).toFixed(1) + "s",
292314
}}
293315
height={200}
316+
yDomain={[props.minSnapPoints[minSnap], props.maxSnapPoints[maxSnap]]}
294317
hideFilter
295318
hideLegend
296319
/>

0 commit comments

Comments
 (0)