aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/FunctionPlotBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2022-10-07 15:03:16 -0400
committerbobzel <zzzman@gmail.com>2022-10-07 15:03:16 -0400
commit0e41cb323c486b23c70e53d14a563adaf0eeef9e (patch)
tree3cc353c16996c58709cdf5ec8ca8fbe88fe6bb89 /src/client/views/nodes/FunctionPlotBox.tsx
parent69eb6d5514c36bd7065d2702cb2fb71e62c039ff (diff)
fixes for equations : :eq as option to ctrl-m inside a text box. added background for equations. fixed cursor focus issues.
Diffstat (limited to 'src/client/views/nodes/FunctionPlotBox.tsx')
-rw-r--r--src/client/views/nodes/FunctionPlotBox.tsx38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/client/views/nodes/FunctionPlotBox.tsx b/src/client/views/nodes/FunctionPlotBox.tsx
index 15d0f88f6..e09155ac2 100644
--- a/src/client/views/nodes/FunctionPlotBox.tsx
+++ b/src/client/views/nodes/FunctionPlotBox.tsx
@@ -4,11 +4,14 @@ import { observer } from 'mobx-react';
import * as React from 'react';
import { Doc, DocListCast } from '../../../fields/Doc';
import { documentSchema } from '../../../fields/documentSchemas';
+import { Id } from '../../../fields/FieldSymbols';
import { List } from '../../../fields/List';
import { createSchema, listSpec, makeInterface } from '../../../fields/Schema';
import { Cast, StrCast } from '../../../fields/Types';
import { TraceMobx } from '../../../fields/util';
import { Docs } from '../../documents/Documents';
+import { DragManager } from '../../util/DragManager';
+import { undoBatch } from '../../util/UndoManager';
import { ViewBoxBaseComponent } from '../DocComponent';
import { FieldView, FieldViewProps } from './FieldView';
@@ -33,7 +36,7 @@ export class FunctionPlotBox extends ViewBoxBaseComponent<FieldViewProps>() {
componentDidMount() {
this.props.setContentView?.(this);
reaction(
- () => [DocListCast(this.dataDoc[this.fieldKey]).lastElement()?.text, this.layoutDoc.width, this.layoutDoc.height, this.dataDoc.xRange, this.dataDoc.yRange],
+ () => [DocListCast(this.dataDoc[this.fieldKey]).map(doc => doc?.text), this.layoutDoc.width, this.layoutDoc.height, this.dataDoc.xRange, this.dataDoc.yRange],
() => this.createGraph()
);
}
@@ -53,8 +56,9 @@ export class FunctionPlotBox extends ViewBoxBaseComponent<FieldViewProps>() {
this._plotEle = ele || this._plotEle;
const width = this.props.PanelWidth();
const height = this.props.PanelHeight();
- const fn = StrCast(DocListCast(this.dataDoc.data).lastElement()?.text, 'x^2').replace(/\\frac\{(.*)\}\{(.*)\}/, '($1/$2)');
+ const fns = DocListCast(this.dataDoc.data).map(doc => StrCast(doc.text, 'x^2').replace(/\\frac\{(.*)\}\{(.*)\}/, '($1/$2)'));
try {
+ this._plotEle.children.length && this._plotEle.removeChild(this._plotEle.children[0]);
this._plot = functionPlot({
target: '#' + this._plotEle.id,
width,
@@ -62,17 +66,34 @@ export class FunctionPlotBox extends ViewBoxBaseComponent<FieldViewProps>() {
xAxis: { domain: Cast(this.dataDoc.xRange, listSpec('number'), [-10, 10]) },
yAxis: { domain: Cast(this.dataDoc.xRange, listSpec('number'), [-1, 9]) },
grid: true,
- data: [
- {
- fn,
- // derivative: { fn: "2 * x", updateOnMouseMove: true }
- },
- ],
+ data: fns.map(fn => ({
+ fn,
+ // derivative: { fn: "2 * x", updateOnMouseMove: true }
+ })),
});
} catch (e) {
console.log(e);
}
};
+
+ @undoBatch
+ drop = (e: Event, de: DragManager.DropEvent) => {
+ if (de.complete.docDragData?.droppedDocuments.length) {
+ e.stopPropagation(); // prevent parent Doc from registering new position so that it snaps back into place
+ de.complete.docDragData.droppedDocuments.map(doc => Doc.AddDocToList(this.dataDoc, this.props.fieldKey, doc));
+ return false;
+ }
+ return false;
+ };
+
+ _dropDisposer: any;
+ protected createDropTarget = (ele: HTMLDivElement) => {
+ this._dropDisposer?.();
+ if (ele) {
+ this._dropDisposer = DragManager.MakeDropTarget(ele, this.drop.bind(this), this.layoutDoc);
+ }
+ // if (this.autoHeight) this.tryUpdateScrollHeight();
+ };
@computed get theGraph() {
return <div id={`${this._plotId}`} ref={r => r && this.createGraph(r)} style={{ position: 'absolute', width: '100%', height: '100%' }} onPointerDown={e => e.stopPropagation()} />;
}
@@ -80,6 +101,7 @@ export class FunctionPlotBox extends ViewBoxBaseComponent<FieldViewProps>() {
TraceMobx();
return (
<div
+ ref={this.createDropTarget}
style={{
pointerEvents: !this.isContentActive() ? 'all' : undefined,
width: this.props.PanelWidth(),