Skip to content

Added dropdown to Legend for dataPointThreshold #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function App() {
serialPort: serialPortExtracted,
connected,
generate,
dataPointThreshold,
} = message.data.monitorUISettings || {};

let updateTitle = false;
Expand Down Expand Up @@ -130,6 +131,10 @@ export default function App() {
typeof generate === "undefined"
? prevConfig?.monitorUISettings?.generate
: generate,
dataPointThreshold:
typeof dataPointThreshold === "undefined"
? prevConfig?.monitorUISettings?.dataPointThreshold
: dataPointThreshold,
},
}));

Expand Down Expand Up @@ -195,6 +200,9 @@ export default function App() {
serialPort: urlParams.get("serialPort") || "/serial/port/address",
connected: urlParams.get("connected") === "true",
generate: urlParams.get("generate") === "true",
dataPointThreshold: parseInt(
urlParams.get("dataPointThreshold") || "50"
),
},
};

Expand Down
6 changes: 5 additions & 1 deletion src/ChartPlotter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ function _Chart(
const [connected, setConnected] = useState(
config?.monitorUISettings?.connected
);
const [dataPointThreshold] = useState(50);
const [dataPointThreshold, setDataPointThreshold] = useState<number>(
config?.monitorUISettings?.dataPointThreshold || 50
);
const [cubicInterpolationMode, setCubicInterpolationMode] = useState<
"default" | "monotone"
>(config?.monitorUISettings?.interpolate ? "monotone" : "default");
Expand Down Expand Up @@ -230,6 +232,8 @@ function _Chart(
wsSend={wsSend}
setPause={togglePause}
setInterpolate={setInterpolate}
dataPointThreshold={dataPointThreshold}
setDataPointThreshold={setDataPointThreshold}
/>
<div className="canvas-container">
<Line data={initialData} ref={chartRef as any} options={opts} />
Expand Down
40 changes: 40 additions & 0 deletions src/Legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LegendItem } from "./LegendItem";
import { MonitorSettings, PluggableMonitor } from "./utils";
import { Scrollbars } from "react-custom-scrollbars";
import Switch from "react-switch";
import Select from "react-select";
import classNames from "classnames";

export function Legend({
Expand All @@ -14,16 +15,20 @@ export function Legend({
wsSend,
setPause,
setInterpolate,
dataPointThreshold,
setDataPointThreshold,
}: {
chartRef: ChartJSOrUndefined<"line">;
pause: boolean;
config: Partial<MonitorSettings>;
cubicInterpolationMode: "monotone" | "default";
dataPointThreshold: number;
wsSend: (
clientCommand: PluggableMonitor.Protocol.ClientCommandMessage
) => void;
setPause: (pause: boolean) => void;
setInterpolate: (interpolate: boolean) => void;
setDataPointThreshold: (dataPointThreshold: number) => void;
}): React.ReactElement {
const scrollRef = useRef<Scrollbars>(null);

Expand Down Expand Up @@ -131,6 +136,41 @@ export function Legend({
)}
</div>
<div className="actions">
<label className="datapoints">
<span>Datapoints</span>
<Select
className="singleselect datapointscount"
classNamePrefix="select"
value={{
value: dataPointThreshold,
label: dataPointThreshold.toString(),
}}
name="datapointscount"
options={[
{ value: 50, label: "50" },
{ value: 100, label: "100" },
{ value: 200, label: "200" },
{ value: 500, label: "500" },
{ value: 1000, label: "1000" },
{ value: 5000, label: "5000" },
]}
menuPlacement="top"
onChange={(event) => {
if (event) {
setDataPointThreshold(event.value);
wsSend({
command:
PluggableMonitor.Protocol.ClientCommand.CHANGE_SETTINGS,
data: {
monitorUISettings: {
dataPointThreshold: event.value,
},
},
});
}
}}
/>
</label>
<label className="interpolate">
<span>Interpolate</span>
<Switch
Expand Down
14 changes: 14 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ body {
}
}

.datapoints {
display: flex;
align-items: center;

span {
margin-right: 10px;
font-size: 14px;
}
}

.pause-button {
width: 75px;
text-align: center;
Expand Down Expand Up @@ -339,6 +349,10 @@ body {
}
}

.datapointscount{
min-width:50px;
}


input:focus,
select:focus,
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface MonitorModelState {
serialPort: string;
connected: boolean;
generate?: boolean;
dataPointThreshold: number;
}

export interface MonitorSettings {
Expand Down