Skip to content

Commit ab57286

Browse files
authored
Merge pull request #25 from hnez/chart-y-scaling
web: MqttComponents: Snap MqttChart y-axis dimensions to a list of fixed values
2 parents 32a0924 + 3a9cb57 commit ab57286

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

web/src/DashboardDut.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,21 @@ export default function DashboardDut() {
103103
<ColumnLayout columns={2} variant="text-grid">
104104
<Box>
105105
<Box variant="awsui-key-label">DUT voltage (V)</Box>
106-
<MqttChart topic="/v1/dut/feedback/voltage" />
106+
<MqttChart
107+
title="DUT Voltage"
108+
topic="/v1/dut/feedback/voltage"
109+
maxSnapPoints={[6, 13, 25, 50]}
110+
minSnapPoints={[-1]}
111+
/>
107112
</Box>
108113
<Box>
109114
<Box variant="awsui-key-label">DUT current (A)</Box>
110-
<MqttChart topic="/v1/dut/feedback/current" />
115+
<MqttChart
116+
title="DUT Current"
117+
topic="/v1/dut/feedback/current"
118+
maxSnapPoints={[0.5, 1, 2, 3, 4, 5]}
119+
minSnapPoints={[-0.1, -1]}
120+
/>
111121
</Box>
112122
</ColumnLayout>
113123
<ColumnLayout columns={4} variant="text-grid">
@@ -239,7 +249,12 @@ export default function DashboardDut() {
239249
additionalInfo="The absolute voltage is independent of pin orientation"
240250
/>
241251
<UnloadingSection header={`OUT_${port} voltage plot (V)`}>
242-
<MqttChart topic={`/v1/output/out_${port}/feedback/voltage`} />
252+
<MqttChart
253+
title={`OUT_${port} Voltage`}
254+
topic={`/v1/output/out_${port}/feedback/voltage`}
255+
maxSnapPoints={[4, 6]}
256+
minSnapPoints={[-4, -6]}
257+
/>
243258
</UnloadingSection>
244259
</SpaceBetween>
245260
</ColumnLayout>
@@ -304,7 +319,12 @@ export default function DashboardDut() {
304319
additionalInfo="Too many devices may overload the bus"
305320
/>
306321
<UnloadingSection header="IOBus current plot">
307-
<MqttChart topic="/v1/iobus/feedback/current" />
322+
<MqttChart
323+
title="IOBus current"
324+
topic="/v1/iobus/feedback/current"
325+
maxSnapPoints={[0.25]}
326+
minSnapPoints={[0]}
327+
/>
308328
</UnloadingSection>
309329
<MqttBarMeter
310330
topic="/v1/iobus/feedback/voltage"
@@ -318,7 +338,12 @@ export default function DashboardDut() {
318338
additionalInfo="The voltage will go down if the bus is overloaded"
319339
/>
320340
<UnloadingSection header="IOBus voltage plot">
321-
<MqttChart topic="/v1/iobus/feedback/voltage" />
341+
<MqttChart
342+
title="IOBus current"
343+
topic="/v1/iobus/feedback/voltage"
344+
maxSnapPoints={[13]}
345+
minSnapPoints={[0]}
346+
/>
322347
</UnloadingSection>
323348
</SpaceBetween>
324349
</ColumnLayout>
@@ -380,7 +405,10 @@ export default function DashboardDut() {
380405
/>
381406
<UnloadingSection header={`USB Port ${port} current plot`}>
382407
<MqttChart
408+
title={`Port ${port} current`}
383409
topic={`/v1/usb/host/port${port}/feedback/current`}
410+
maxSnapPoints={[0.5]}
411+
minSnapPoints={[0]}
384412
/>
385413
</UnloadingSection>
386414
</SpaceBetween>

web/src/MqttComponents.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ function measToPoint(m: Measurement) {
260260
}
261261

262262
interface MqttChartProps {
263+
title: string;
263264
topic: string;
265+
maxSnapPoints: Array<number>;
266+
minSnapPoints: Array<number>;
264267
}
265268

266269
export function MqttChart(props: MqttChartProps) {
@@ -271,11 +274,31 @@ export function MqttChart(props: MqttChartProps) {
271274
);
272275
let values = history.current;
273276

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+
274297
let end = values.length >= 1 ? values[values.length - 1]["x"] : new Date();
275298

276299
let series: MixedLineBarChartProps.ChartSeries<Date> = {
277300
type: "line",
278-
title: "eh",
301+
title: props.title,
279302
data: values,
280303
};
281304

@@ -290,6 +313,7 @@ export function MqttChart(props: MqttChartProps) {
290313
((Number(e) - Number(end)) / 1000).toFixed(1) + "s",
291314
}}
292315
height={200}
316+
yDomain={[props.minSnapPoints[minSnap], props.maxSnapPoints[maxSnap]]}
293317
hideFilter
294318
hideLegend
295319
/>

0 commit comments

Comments
 (0)