Skip to content

Commit 50cdc23

Browse files
committed
Added dropdown to Legend for dataPointThreshold
1 parent 22c6952 commit 50cdc23

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

src/App.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default function App() {
4343
serialPort: serialPortExtracted,
4444
connected,
4545
generate,
46+
dataPointThreshold,
4647
} = message.data.monitorUISettings || {};
4748

4849
let updateTitle = false;
@@ -130,6 +131,10 @@ export default function App() {
130131
typeof generate === "undefined"
131132
? prevConfig?.monitorUISettings?.generate
132133
: generate,
134+
dataPointThreshold:
135+
typeof dataPointThreshold === "undefined"
136+
? prevConfig?.monitorUISettings?.dataPointThreshold
137+
: dataPointThreshold,
133138
},
134139
}));
135140

@@ -195,6 +200,9 @@ export default function App() {
195200
serialPort: urlParams.get("serialPort") || "/serial/port/address",
196201
connected: urlParams.get("connected") === "true",
197202
generate: urlParams.get("generate") === "true",
203+
dataPointThreshold: parseInt(
204+
urlParams.get("dataPointThreshold") || "50"
205+
),
198206
},
199207
};
200208

src/ChartPlotter.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ function _Chart(
4343
const [connected, setConnected] = useState(
4444
config?.monitorUISettings?.connected
4545
);
46-
const [dataPointThreshold] = useState(50);
46+
const [dataPointThreshold, setDataPointThreshold] = useState<number>(
47+
config?.monitorUISettings?.dataPointThreshold || 50
48+
);
4749
const [cubicInterpolationMode, setCubicInterpolationMode] = useState<
4850
"default" | "monotone"
4951
>(config?.monitorUISettings?.interpolate ? "monotone" : "default");
@@ -230,6 +232,8 @@ function _Chart(
230232
wsSend={wsSend}
231233
setPause={togglePause}
232234
setInterpolate={setInterpolate}
235+
dataPointThreshold={dataPointThreshold}
236+
setDataPointThreshold={setDataPointThreshold}
233237
/>
234238
<div className="canvas-container">
235239
<Line data={initialData} ref={chartRef as any} options={opts} />

src/Legend.tsx

+40
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LegendItem } from "./LegendItem";
44
import { MonitorSettings, PluggableMonitor } from "./utils";
55
import { Scrollbars } from "react-custom-scrollbars";
66
import Switch from "react-switch";
7+
import Select from "react-select";
78
import classNames from "classnames";
89

910
export function Legend({
@@ -14,16 +15,20 @@ export function Legend({
1415
wsSend,
1516
setPause,
1617
setInterpolate,
18+
dataPointThreshold,
19+
setDataPointThreshold,
1720
}: {
1821
chartRef: ChartJSOrUndefined<"line">;
1922
pause: boolean;
2023
config: Partial<MonitorSettings>;
2124
cubicInterpolationMode: "monotone" | "default";
25+
dataPointThreshold: number;
2226
wsSend: (
2327
clientCommand: PluggableMonitor.Protocol.ClientCommandMessage
2428
) => void;
2529
setPause: (pause: boolean) => void;
2630
setInterpolate: (interpolate: boolean) => void;
31+
setDataPointThreshold: (dataPointThreshold: number) => void;
2732
}): React.ReactElement {
2833
const scrollRef = useRef<Scrollbars>(null);
2934

@@ -131,6 +136,41 @@ export function Legend({
131136
)}
132137
</div>
133138
<div className="actions">
139+
<label className="interpolate">
140+
<span>Number of Datapoints</span>
141+
<Select
142+
className="singleselect datapointscount"
143+
classNamePrefix="select"
144+
value={{
145+
value: dataPointThreshold,
146+
label: dataPointThreshold.toString(),
147+
}}
148+
name="datapointscount"
149+
options={[
150+
{ value: 50, label: "50" },
151+
{ value: 100, label: "100" },
152+
{ value: 200, label: "200" },
153+
{ value: 500, label: "500" },
154+
{ value: 1000, label: "1000" },
155+
{ value: 5000, label: "5000" },
156+
]}
157+
menuPlacement="top"
158+
onChange={(event) => {
159+
if (event) {
160+
setDataPointThreshold(event.value);
161+
wsSend({
162+
command:
163+
PluggableMonitor.Protocol.ClientCommand.CHANGE_SETTINGS,
164+
data: {
165+
monitorUISettings: {
166+
dataPointThreshold: event.value,
167+
},
168+
},
169+
});
170+
}
171+
}}
172+
/>
173+
</label>
134174
<label className="interpolate">
135175
<span>Interpolate</span>
136176
<Switch

src/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface MonitorModelState {
3232
serialPort: string;
3333
connected: boolean;
3434
generate?: boolean;
35+
dataPointThreshold: number;
3536
}
3637

3738
export interface MonitorSettings {

0 commit comments

Comments
 (0)