diff options
author | bobzel <zzzman@gmail.com> | 2024-09-02 09:26:37 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-09-02 09:26:37 -0400 |
commit | cda69e48361fce8d71a4dc66edd9dd976a27f52d (patch) | |
tree | 82b9a1a5967ae88a9534f89f7eaed3aeb289652f /src/client/views/nodes/FunctionPlotBox.tsx | |
parent | c01828308714874589d1f60c33ca59df4c656c0c (diff) | |
parent | a958577d4c27b276aa37484e3f895e196138b17c (diff) |
Merge branch 'master' into alyssa-starter
Diffstat (limited to 'src/client/views/nodes/FunctionPlotBox.tsx')
-rw-r--r-- | src/client/views/nodes/FunctionPlotBox.tsx | 20 |
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) { |