forked from Linho1219/function-plot-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotation.ts
More file actions
32 lines (29 loc) · 690 Bytes
/
annotation.ts
File metadata and controls
32 lines (29 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { FunctionPlotAnnotation } from "function-plot";
export type PrivateAnnotation = {
/** @private */
key: number;
variable: "x" | "y";
value: number;
text: string;
};
export const toPublicAnnotation = ({
variable,
value,
text,
}: PrivateAnnotation): FunctionPlotAnnotation => {
const result: FunctionPlotAnnotation = {};
if (text !== "") result.text = text;
if (variable === "x") result.x = value;
else result.y = value;
return result;
};
export const toPrivateAnnotation = ({
x,
y,
text,
}: FunctionPlotAnnotation): PrivateAnnotation => ({
key: Math.random(),
variable: x !== undefined ? "x" : "y",
value: x ?? y ?? 0,
text: text ?? "",
});