aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/FunctionPlotBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/FunctionPlotBox.tsx')
-rw-r--r--src/client/views/nodes/FunctionPlotBox.tsx20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/client/views/nodes/FunctionPlotBox.tsx b/src/client/views/nodes/FunctionPlotBox.tsx
index 3d1bd7563..6b439cd64 100644
--- a/src/client/views/nodes/FunctionPlotBox.tsx
+++ b/src/client/views/nodes/FunctionPlotBox.tsx
@@ -1,4 +1,4 @@
-import functionPlot from 'function-plot';
+import functionPlot, { Chart } from 'function-plot';
import { computed, makeObservable, reaction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
@@ -22,11 +22,11 @@ export class FunctionPlotBox extends ViewBoxAnnotatableComponent<FieldViewProps>
return FieldView.LayoutString(FunctionPlotBox, fieldKey);
}
public static GraphCount = 0;
- _plot: any;
+ _plot: Chart | undefined;
_plotId = '';
- _plotEle: any;
+ _plotEle: HTMLDivElement | null = null;
- constructor(props: any) {
+ constructor(props: FieldViewProps) {
super(props);
makeObservable(this);
this._plotId = 'graph' + FunctionPlotBox.GraphCount++;
@@ -42,8 +42,10 @@ export class FunctionPlotBox extends ViewBoxAnnotatableComponent<FieldViewProps>
getAnchor = (addAsAnnotation: boolean, pinProps?: PinProps) => {
const anchor = Docs.Create.ConfigDocument({ annotationOn: this.Document });
PinDocView(anchor, { pinDocLayout: pinProps?.pinDocLayout, pinData: { ...(pinProps?.pinData ?? {}), datarange: true } }, this.Document);
- anchor.config_xRange = new List<number>(Array.from(this._plot.options.xAxis.domain));
- anchor.config_yRange = new List<number>(Array.from(this._plot.options.yAxis.domain));
+ if (this._plot) {
+ anchor.config_xRange = new List<number>(Array.from(this._plot.options.xAxis?.domain ?? []));
+ anchor.config_yRange = new List<number>(Array.from(this._plot.options.yAxis?.domain ?? []));
+ }
if (addAsAnnotation) this.addDocument(anchor);
return anchor;
};
@@ -68,9 +70,9 @@ export class FunctionPlotBox extends ViewBoxAnnotatableComponent<FieldViewProps>
const width = this._props.PanelWidth();
const height = this._props.PanelHeight();
try {
- this._plotEle.children.length && this._plotEle.removeChild(this._plotEle.children[0]);
+ this._plotEle?.children.length && this._plotEle.removeChild(this._plotEle.children[0]);
this._plot = functionPlot({
- target: '#' + this._plotEle.id,
+ target: '#' + this._plotEle?.id,
width,
height,
xAxis: { domain: Cast(this.layoutDoc.xRange, listSpec('number'), [-10, 10]) },
@@ -104,7 +106,7 @@ export class FunctionPlotBox extends ViewBoxAnnotatableComponent<FieldViewProps>
return false;
};
- _dropDisposer: any;
+ _dropDisposer: DragManager.DragDropDisposer | undefined;
protected createDropTarget = (ele: HTMLDivElement) => {
this._dropDisposer?.();
if (ele) {