@teachinglab/omd 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/canvas/core/canvasConfig.js +203 -0
- package/canvas/core/omdCanvas.js +475 -0
- package/canvas/drawing/segment.js +168 -0
- package/canvas/drawing/stroke.js +386 -0
- package/canvas/events/eventManager.js +435 -0
- package/canvas/events/pointerEventHandler.js +263 -0
- package/canvas/features/focusFrameManager.js +287 -0
- package/canvas/index.js +49 -0
- package/canvas/tools/eraserTool.js +322 -0
- package/canvas/tools/pencilTool.js +319 -0
- package/canvas/tools/selectTool.js +457 -0
- package/canvas/tools/tool.js +223 -0
- package/canvas/tools/toolManager.js +394 -0
- package/canvas/ui/cursor.js +438 -0
- package/canvas/ui/toolbar.js +304 -0
- package/canvas/utils/boundingBox.js +378 -0
- package/canvas/utils/mathUtils.js +259 -0
- package/docs/api/configuration-options.md +104 -0
- package/docs/api/eventManager.md +68 -0
- package/docs/api/focusFrameManager.md +150 -0
- package/docs/api/index.md +91 -0
- package/docs/api/main.md +58 -0
- package/docs/api/omdBinaryExpressionNode.md +227 -0
- package/docs/api/omdCanvas.md +142 -0
- package/docs/api/omdConfigManager.md +192 -0
- package/docs/api/omdConstantNode.md +117 -0
- package/docs/api/omdDisplay.md +121 -0
- package/docs/api/omdEquationNode.md +161 -0
- package/docs/api/omdEquationSequenceNode.md +301 -0
- package/docs/api/omdEquationStack.md +139 -0
- package/docs/api/omdFunctionNode.md +141 -0
- package/docs/api/omdGroupNode.md +182 -0
- package/docs/api/omdHelpers.md +96 -0
- package/docs/api/omdLeafNode.md +163 -0
- package/docs/api/omdNode.md +101 -0
- package/docs/api/omdOperationDisplayNode.md +139 -0
- package/docs/api/omdOperatorNode.md +127 -0
- package/docs/api/omdParenthesisNode.md +122 -0
- package/docs/api/omdPopup.md +117 -0
- package/docs/api/omdPowerNode.md +127 -0
- package/docs/api/omdRationalNode.md +128 -0
- package/docs/api/omdSequenceNode.md +128 -0
- package/docs/api/omdSimplification.md +110 -0
- package/docs/api/omdSqrtNode.md +79 -0
- package/docs/api/omdStepVisualizer.md +115 -0
- package/docs/api/omdStepVisualizerHighlighting.md +61 -0
- package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
- package/docs/api/omdStepVisualizerLayout.md +60 -0
- package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
- package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
- package/docs/api/omdToolbar.md +102 -0
- package/docs/api/omdTranscriptionService.md +76 -0
- package/docs/api/omdTreeDiff.md +134 -0
- package/docs/api/omdUnaryExpressionNode.md +174 -0
- package/docs/api/omdUtilities.md +70 -0
- package/docs/api/omdVariableNode.md +148 -0
- package/docs/api/selectTool.md +74 -0
- package/docs/api/simplificationEngine.md +98 -0
- package/docs/api/simplificationRules.md +77 -0
- package/docs/api/simplificationUtils.md +64 -0
- package/docs/api/transcribe.md +43 -0
- package/docs/api-reference.md +85 -0
- package/docs/index.html +454 -0
- package/docs/user-guide.md +9 -0
- package/index.js +67 -0
- package/omd/config/omdConfigManager.js +267 -0
- package/omd/core/index.js +150 -0
- package/omd/core/omdEquationStack.js +347 -0
- package/omd/core/omdUtilities.js +115 -0
- package/omd/display/omdDisplay.js +443 -0
- package/omd/display/omdToolbar.js +502 -0
- package/omd/nodes/omdBinaryExpressionNode.js +460 -0
- package/omd/nodes/omdConstantNode.js +142 -0
- package/omd/nodes/omdEquationNode.js +1223 -0
- package/omd/nodes/omdEquationSequenceNode.js +1273 -0
- package/omd/nodes/omdFunctionNode.js +352 -0
- package/omd/nodes/omdGroupNode.js +68 -0
- package/omd/nodes/omdLeafNode.js +77 -0
- package/omd/nodes/omdNode.js +557 -0
- package/omd/nodes/omdOperationDisplayNode.js +322 -0
- package/omd/nodes/omdOperatorNode.js +109 -0
- package/omd/nodes/omdParenthesisNode.js +293 -0
- package/omd/nodes/omdPowerNode.js +236 -0
- package/omd/nodes/omdRationalNode.js +295 -0
- package/omd/nodes/omdSqrtNode.js +308 -0
- package/omd/nodes/omdUnaryExpressionNode.js +178 -0
- package/omd/nodes/omdVariableNode.js +123 -0
- package/omd/simplification/omdSimplification.js +171 -0
- package/omd/simplification/omdSimplificationEngine.js +886 -0
- package/omd/simplification/package.json +6 -0
- package/omd/simplification/rules/binaryRules.js +1037 -0
- package/omd/simplification/rules/functionRules.js +111 -0
- package/omd/simplification/rules/index.js +48 -0
- package/omd/simplification/rules/parenthesisRules.js +19 -0
- package/omd/simplification/rules/powerRules.js +143 -0
- package/omd/simplification/rules/rationalRules.js +475 -0
- package/omd/simplification/rules/sqrtRules.js +48 -0
- package/omd/simplification/rules/unaryRules.js +37 -0
- package/omd/simplification/simplificationRules.js +32 -0
- package/omd/simplification/simplificationUtils.js +1056 -0
- package/omd/step-visualizer/omdStepVisualizer.js +597 -0
- package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
- package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
- package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
- package/omd/utils/omdNodeOverlay.js +638 -0
- package/omd/utils/omdPopup.js +1084 -0
- package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
- package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
- package/omd/utils/omdTranscriptionService.js +125 -0
- package/omd/utils/omdTreeDiff.js +734 -0
- package/package.json +46 -0
- package/src/index.js +62 -0
- package/src/json-schemas.md +109 -0
- package/src/omd-json-samples.js +115 -0
- package/src/omd.js +109 -0
- package/src/omdApp.js +391 -0
- package/src/omdAppCanvas.js +336 -0
- package/src/omdBalanceHanger.js +172 -0
- package/src/omdColor.js +13 -0
- package/src/omdCoordinatePlane.js +467 -0
- package/src/omdEquation.js +125 -0
- package/src/omdExpression.js +104 -0
- package/src/omdFunction.js +113 -0
- package/src/omdMetaExpression.js +287 -0
- package/src/omdNaturalExpression.js +564 -0
- package/src/omdNode.js +384 -0
- package/src/omdNumber.js +53 -0
- package/src/omdNumberLine.js +107 -0
- package/src/omdNumberTile.js +119 -0
- package/src/omdOperator.js +73 -0
- package/src/omdPowerExpression.js +92 -0
- package/src/omdProblem.js +55 -0
- package/src/omdRatioChart.js +232 -0
- package/src/omdRationalExpression.js +115 -0
- package/src/omdSampleData.js +215 -0
- package/src/omdShapes.js +476 -0
- package/src/omdSpinner.js +148 -0
- package/src/omdString.js +39 -0
- package/src/omdTable.js +369 -0
- package/src/omdTapeDiagram.js +245 -0
- package/src/omdTerm.js +92 -0
- package/src/omdTileEquation.js +349 -0
- package/src/omdVariable.js +51 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
|
|
2
|
+
Represents a leaf in the AST tree, such as an operator, constant, variable, or grouping symbol. This is a base class for other specific leaf node types.
|
|
3
|
+
|
|
4
|
+
## Class: `omdLeafNode extends omdNode`
|
|
5
|
+
|
|
6
|
+
```javascript
|
|
7
|
+
import { omdLeafNode } from './omd/nodes/omdLeafNode.js';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
### Constructor
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
new omdLeafNode(nodeData)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Parameters:**
|
|
17
|
+
|
|
18
|
+
**Description:**
|
|
19
|
+
Creates a new leaf node. This is an abstract base class - use concrete subclasses instead.
|
|
20
|
+
|
|
21
|
+
### Methods
|
|
22
|
+
|
|
23
|
+
Inherits all methods from [omdNode](./omdNode.md), plus:
|
|
24
|
+
|
|
25
|
+
#### `createTextElement(text)`
|
|
26
|
+
Creates and positions the text element for the node.
|
|
27
|
+
- Text anchor set to 'middle'
|
|
28
|
+
- Dominant baseline set to 'middle'
|
|
29
|
+
- Added as a child of this node
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
#### `clone()`
|
|
33
|
+
Creates a clone of the leaf node.
|
|
34
|
+
- Same constructor as original
|
|
35
|
+
- Original node's ID added to provenance array
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
#### `updateTextElement(text)`
|
|
39
|
+
Updates the text content.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
#### `computeDimensions()`
|
|
43
|
+
Calculates node dimensions based on text content.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
#### `updateLayout()`
|
|
47
|
+
Updates the position of the node.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
#### `updateTextPosition()`
|
|
51
|
+
Internal method to center text in node.
|
|
52
|
+
|
|
53
|
+
### Examples
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// This is an abstract class - use concrete subclasses
|
|
57
|
+
const constant = new omdConstantNode(5);
|
|
58
|
+
const variable = new omdVariableNode('x');
|
|
59
|
+
const operator = new omdOperatorNode('+');
|
|
60
|
+
|
|
61
|
+
// All leaf nodes handle text rendering
|
|
62
|
+
constant.createTextElement('5');
|
|
63
|
+
constant.computeDimensions();
|
|
64
|
+
constant.updateLayout();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### See Also
|
|
68
|
+
|
|
69
|
+
Concrete implementations:
|
|
70
|
+
|
|
71
|
+
Base class:
|
|
72
|
+
# omdLeafNode
|
|
73
|
+
|
|
74
|
+
Represents a leaf in the AST tree, such as an operator, constant, variable, or grouping symbol. This is a base class for other specific leaf node types.
|
|
75
|
+
|
|
76
|
+
## Class: `omdLeafNode extends omdNode`
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
import { omdLeafNode } from './omd/nodes/omdLeafNode.js';
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Constructor
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
new omdLeafNode(nodeData)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Parameters:**
|
|
89
|
+
- `nodeData` {Object} - The AST node data
|
|
90
|
+
|
|
91
|
+
**Description:**
|
|
92
|
+
Creates a new leaf node. This is an abstract base class—use concrete subclasses instead.
|
|
93
|
+
|
|
94
|
+
### Methods
|
|
95
|
+
|
|
96
|
+
Inherits all methods from [omdNode](./omdNode.md), plus:
|
|
97
|
+
|
|
98
|
+
#### `createTextElement(text)`
|
|
99
|
+
Creates and positions the text element for the node.
|
|
100
|
+
- `text` {string|number} - The text content to display
|
|
101
|
+
- **Returns:** jsvgTextLine - The created text element with:
|
|
102
|
+
- Text anchor set to 'middle'
|
|
103
|
+
- Dominant baseline set to 'middle'
|
|
104
|
+
- Added as a child of this node
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
#### `clone()`
|
|
109
|
+
Creates a clone of the leaf node.
|
|
110
|
+
- **Returns:** omdLeafNode - A new instance with:
|
|
111
|
+
- Same constructor as original
|
|
112
|
+
- Original node's ID added to provenance array
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
#### `updateTextElement(text)`
|
|
117
|
+
Updates the text content.
|
|
118
|
+
- `text` {string|number} - The new text content
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
#### `computeDimensions()`
|
|
123
|
+
Calculates node dimensions based on text content.
|
|
124
|
+
- Gets font size from parent
|
|
125
|
+
- Updates text element font size
|
|
126
|
+
- Sets width and height based on text bounds
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
#### `updateLayout()`
|
|
131
|
+
Updates the position of the node.
|
|
132
|
+
- Calls updateTextPosition()
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
#### `updateTextPosition()`
|
|
137
|
+
Internal method to center text in node.
|
|
138
|
+
- Sets text position to (width/2, height/2)
|
|
139
|
+
|
|
140
|
+
### Example
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
// This is an abstract class—use concrete subclasses
|
|
144
|
+
const constant = new omdConstantNode(5);
|
|
145
|
+
const variable = new omdVariableNode('x');
|
|
146
|
+
const operator = new omdOperatorNode('+');
|
|
147
|
+
|
|
148
|
+
// All leaf nodes handle text rendering
|
|
149
|
+
constant.createTextElement('5');
|
|
150
|
+
constant.computeDimensions();
|
|
151
|
+
constant.updateLayout();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### See Also
|
|
155
|
+
|
|
156
|
+
Concrete implementations:
|
|
157
|
+
- [omdConstantNode](./omdConstantNode.md) - For numeric values
|
|
158
|
+
- [omdVariableNode](./omdVariableNode.md) - For variables
|
|
159
|
+
- [omdOperatorNode](./omdOperatorNode.md) - For operators
|
|
160
|
+
- [omdGroupNode](./omdGroupNode.md) - For grouping symbols
|
|
161
|
+
|
|
162
|
+
Base class:
|
|
163
|
+
- [omdNode](./omdNode.md) - Parent class
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# omdNode
|
|
2
|
+
|
|
3
|
+
The abstract base class for all nodes in the mathematical expression tree. It provides the core functionality for tree structure (parent-child relationships), layout calculations, rendering, and provenance tracking.
|
|
4
|
+
|
|
5
|
+
## Class: `omdNode extends omdMetaExpression`
|
|
6
|
+
|
|
7
|
+
This class is not meant to be instantiated directly. Instead, you should use one of its concrete subclasses (e.g., `omdConstantNode`, `omdBinaryExpressionNode`).
|
|
8
|
+
|
|
9
|
+
### Key Concepts
|
|
10
|
+
|
|
11
|
+
- **AST (Abstract Syntax Tree):** Each `omdNode` is created from a node in the math.js AST.
|
|
12
|
+
- **Tree Structure:** Nodes are organized in a tree with `parent` and `childList` properties.
|
|
13
|
+
- **Layout:** The `computeDimensions()` and `updateLayout()` methods are responsible for determining the size and position of a node and its children.
|
|
14
|
+
- **Provenance:** The `provenance` array on each node tracks its history. When a node is cloned (e.g., during a simplification step), the new node's provenance array will contain the ID of the original node, creating a link back to its predecessor.
|
|
15
|
+
|
|
16
|
+
### Properties
|
|
17
|
+
|
|
18
|
+
#### `id`
|
|
19
|
+
- **Type:** `number`
|
|
20
|
+
- **Description:** A unique identifier for the node instance.
|
|
21
|
+
|
|
22
|
+
#### `parent`
|
|
23
|
+
- **Type:** `omdNode` | `null`
|
|
24
|
+
- **Description:** A reference to the parent node in the tree.
|
|
25
|
+
|
|
26
|
+
#### `astNodeData`
|
|
27
|
+
- **Type:** `Object`
|
|
28
|
+
- **Description:** The original math.js AST node from which this `omdNode` was created.
|
|
29
|
+
|
|
30
|
+
#### `provenance`
|
|
31
|
+
- **Type:** `Array<number>`
|
|
32
|
+
- **Description:** An array of IDs from which this node was derived, forming a historical chain.
|
|
33
|
+
|
|
34
|
+
#### `argumentNodeList`
|
|
35
|
+
- **Type:** `Object`
|
|
36
|
+
- **Description:** A map of the node's meaningful children (e.g., `{ left: omdNode, right: omdNode }` for a binary expression).
|
|
37
|
+
|
|
38
|
+
### Core Methods
|
|
39
|
+
|
|
40
|
+
These methods form the essential public API for interacting with nodes.
|
|
41
|
+
|
|
42
|
+
#### `initialize()`
|
|
43
|
+
|
|
44
|
+
Initializes the node by recursively computing its dimensions and updating its layout. This should be called after a node and its children have been constructed.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
#### `clone()`
|
|
49
|
+
|
|
50
|
+
Creates a deep, structural clone of the node. The new node will have a new `id`, and its `provenance` will link back to the original node's `id`.
|
|
51
|
+
|
|
52
|
+
- **Returns:** `omdNode` - A new instance of the same type as the original.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
#### `replaceWith(newNode, options)`
|
|
57
|
+
|
|
58
|
+
Replaces this node with a new node in the tree, updating all parent and child references and re-rendering the SVG.
|
|
59
|
+
|
|
60
|
+
- **Parameters:**
|
|
61
|
+
- `newNode` {omdNode} - The node to substitute in.
|
|
62
|
+
- `options` {Object} (optional) - e.g., `{ updateLayout: true }`.
|
|
63
|
+
- **Returns:** `boolean` - `true` if the replacement was successful.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
#### `simplify()`
|
|
68
|
+
|
|
69
|
+
Asynchronously attempts to simplify the expression rooted at this node by invoking the central simplification engine.
|
|
70
|
+
|
|
71
|
+
- **Returns:** `Promise<Object>` - A promise that resolves to an object like `{ success, foldedCount, newRoot, message }`.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
#### `toMathJSNode()`
|
|
76
|
+
|
|
77
|
+
Converts the `omdNode` and its children back into a math.js-compatible AST object. This must be implemented by all subclasses.
|
|
78
|
+
|
|
79
|
+
- **Returns:** `Object` - The math.js AST node.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
#### `toString()`
|
|
84
|
+
|
|
85
|
+
Converts the node into a human-readable string representation.
|
|
86
|
+
|
|
87
|
+
- **Returns:** `string`.
|
|
88
|
+
|
|
89
|
+
### Layout and Rendering Methods
|
|
90
|
+
|
|
91
|
+
These methods are primarily for internal use and are overridden by subclasses to define specific layout and rendering logic.
|
|
92
|
+
|
|
93
|
+
- `computeDimensions()`: Calculates the `width` and `height` of the node.
|
|
94
|
+
- `updateLayout()`: Positions the node's children relative to itself.
|
|
95
|
+
- `getAlignmentBaseline()`: Returns the vertical y-coordinate used to align this node with its siblings.
|
|
96
|
+
|
|
97
|
+
### See Also
|
|
98
|
+
|
|
99
|
+
- [`omdLeafNode`](./omdLeafNode.md) - The base class for nodes with no children (constants, variables).
|
|
100
|
+
- [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - For nodes with two children (e.g., addition, subtraction).
|
|
101
|
+
- [`omdFunctionNode`](./omdFunctionNode.md) - For function calls.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# omdOperationDisplayNode
|
|
2
|
+
|
|
3
|
+
Represents a visual node for displaying an operation applied to both sides of an equation. Example: -3 -3
|
|
4
|
+
|
|
5
|
+
## Class: `omdOperationDisplayNode extends omdNode`
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
import { omdOperationDisplayNode } from './omd/nodes/omdOperationDisplayNode.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
new omdOperationDisplayNode(operation, value)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Parameters:**
|
|
18
|
+
- `operation` {string} - The type of operation (e.g., 'add', 'subtract', 'multiply', 'divide')
|
|
19
|
+
- `value` {number|string|omdNode} - The value being applied. Can be a number, variable name, or an omdNode
|
|
20
|
+
|
|
21
|
+
**Description:**
|
|
22
|
+
Creates a node that visually represents an operation on both sides of an equation. The node has no visible background and disables mouse interactions.
|
|
23
|
+
|
|
24
|
+
### Properties
|
|
25
|
+
|
|
26
|
+
Inherits all properties from [omdNode](./omdNode.md), plus:
|
|
27
|
+
|
|
28
|
+
#### `operation`
|
|
29
|
+
- **Type:** string
|
|
30
|
+
- **Description:** The operation type (e.g., 'add', 'subtract')
|
|
31
|
+
|
|
32
|
+
#### `value`
|
|
33
|
+
- **Type:** number|string|omdNode
|
|
34
|
+
- **Description:** The value used in the operation
|
|
35
|
+
|
|
36
|
+
#### `type`
|
|
37
|
+
- **Type:** string
|
|
38
|
+
- **Description:** Always "omdOperationDisplayNode"
|
|
39
|
+
|
|
40
|
+
#### `operatorLeft`, `operatorRight`
|
|
41
|
+
- **Type:** omdOperator
|
|
42
|
+
- **Description:** The operator symbols for each side
|
|
43
|
+
|
|
44
|
+
#### `valueLeft`, `valueRight`
|
|
45
|
+
- **Type:** omdNode
|
|
46
|
+
- **Description:** The value nodes for each side
|
|
47
|
+
|
|
48
|
+
### Methods
|
|
49
|
+
|
|
50
|
+
Inherits all methods from [omdNode](./omdNode.md), plus:
|
|
51
|
+
|
|
52
|
+
#### `_getOperatorSymbol(operation)`
|
|
53
|
+
Internal method to get display symbol.
|
|
54
|
+
- `operation` {string} - Operation type
|
|
55
|
+
- **Returns:** string - Symbol for operation:
|
|
56
|
+
- 'add' → '+'
|
|
57
|
+
- 'subtract' → '-'
|
|
58
|
+
- 'multiply' → '×'
|
|
59
|
+
- 'divide' → '÷'
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
#### `_createValueElement(value)`
|
|
64
|
+
Internal method to create value node.
|
|
65
|
+
- `value` {number|string|omdNode} - Value to convert
|
|
66
|
+
- **Returns:** omdNode - Appropriate node type:
|
|
67
|
+
- omdNode → cloned
|
|
68
|
+
- AST → parsed
|
|
69
|
+
- number → omdNumber
|
|
70
|
+
- single letter → omdVariable
|
|
71
|
+
- string → omdTerm
|
|
72
|
+
- other → omdExpression
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
#### `_disableElement(element)`
|
|
77
|
+
Internal method to disable interactions.
|
|
78
|
+
- `element` {omdNode} - Element to disable
|
|
79
|
+
- Hides background
|
|
80
|
+
- Removes mouse events
|
|
81
|
+
- Disables recursively
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
#### `computeDimensions()`
|
|
86
|
+
Calculates node dimensions.
|
|
87
|
+
- Adds padding between operator and value
|
|
88
|
+
- Adds gap between sides
|
|
89
|
+
- Sets width and height based on children
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
#### `updateLayout()`
|
|
94
|
+
Updates positions of all elements.
|
|
95
|
+
- Updates child layouts
|
|
96
|
+
- Positions left side elements
|
|
97
|
+
- Adds gap
|
|
98
|
+
- Positions right side elements
|
|
99
|
+
- Centers vertically
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
#### `clone()`
|
|
104
|
+
Creates deep clone of node.
|
|
105
|
+
- **Returns:** omdOperationDisplayNode - New instance with:
|
|
106
|
+
- Same operation and value
|
|
107
|
+
- Original node's ID in provenance
|
|
108
|
+
|
|
109
|
+
### Examples
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
// Create operation display
|
|
113
|
+
const node = new omdOperationDisplayNode('subtract', 3);
|
|
114
|
+
|
|
115
|
+
// With variable
|
|
116
|
+
const varNode = new omdOperationDisplayNode('multiply', 'x');
|
|
117
|
+
|
|
118
|
+
// With complex value
|
|
119
|
+
const complexNode = new omdOperationDisplayNode('divide', {
|
|
120
|
+
type: 'OperatorNode',
|
|
121
|
+
op: '+',
|
|
122
|
+
args: [
|
|
123
|
+
{ type: 'ConstantNode', value: 1 },
|
|
124
|
+
{ type: 'SymbolNode', name: 'x' }
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Render with proper spacing
|
|
129
|
+
node.setFontSize(24);
|
|
130
|
+
node.computeDimensions();
|
|
131
|
+
node.updateLayout();
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### See Also
|
|
135
|
+
|
|
136
|
+
- [omdNode](./omdNode.md) - Parent class
|
|
137
|
+
- [omdOperator](./omdOperator.md) - For operator symbols
|
|
138
|
+
- [omdEquationNode](./omdEquationNode.md) - For equations
|
|
139
|
+
- [omdEquationSequenceNode](./omdEquationSequenceNode.md) - For step sequences
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# omdOperatorNode
|
|
2
|
+
|
|
3
|
+
Represents an operator symbol (e.g., `+`, `-`, `*`, `÷`) as a leaf node in the expression tree.
|
|
4
|
+
|
|
5
|
+
## Class: `omdOperatorNode extends omdLeafNode`
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
import { omdOperatorNode } from './omd/nodes/omdOperatorNode.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
new omdOperatorNode(nodeData)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Parameters:**
|
|
18
|
+
- `nodeData` {Object|string} - The AST node data or the operator symbol as a string.
|
|
19
|
+
|
|
20
|
+
**Description:**
|
|
21
|
+
Creates a leaf node that represents an operator. It handles mapping from operation names (e.g., 'multiply') to symbols (e.g., `×`).
|
|
22
|
+
|
|
23
|
+
### Properties
|
|
24
|
+
|
|
25
|
+
Inherits all properties from [`omdLeafNode`](./omdLeafNode.md), plus:
|
|
26
|
+
|
|
27
|
+
#### `opName`
|
|
28
|
+
- **Type:** string
|
|
29
|
+
- **Description:** The name of the operator (e.g., `*`, `+`)
|
|
30
|
+
|
|
31
|
+
#### `type`
|
|
32
|
+
- **Type:** string
|
|
33
|
+
- **Description:** Always "operator"
|
|
34
|
+
|
|
35
|
+
#### `textElement`
|
|
36
|
+
- **Type:** SVGElement
|
|
37
|
+
- **Description:** The SVG text element displaying the operator symbol
|
|
38
|
+
|
|
39
|
+
### Methods
|
|
40
|
+
|
|
41
|
+
Inherits all methods from [`omdLeafNode`](./omdLeafNode.md), plus:
|
|
42
|
+
|
|
43
|
+
#### `parseOpName(nodeData)`
|
|
44
|
+
Internal method to extract operator name from AST data.
|
|
45
|
+
- **Returns:** string
|
|
46
|
+
- **Supported Operators:**
|
|
47
|
+
- multiply: `×` (configurable)
|
|
48
|
+
- divide: `÷`
|
|
49
|
+
- add: `+`
|
|
50
|
+
- subtract: `−`
|
|
51
|
+
- pow: `^`
|
|
52
|
+
- unaryMinus: `-`
|
|
53
|
+
- unaryPlus: `+`
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
#### `parseType()`
|
|
58
|
+
Internal method to set node type.
|
|
59
|
+
- **Returns:** "operator"
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
#### `computeDimensions()`
|
|
64
|
+
Calculates dimensions with padding around the operator.
|
|
65
|
+
Overrides base class method.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
#### `updateLayout()`
|
|
70
|
+
Updates the layout of the node.
|
|
71
|
+
Overrides base class method.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
#### `toMathJSNode()`
|
|
76
|
+
Converts to math.js AST format.
|
|
77
|
+
- **Returns:** Object - A math.js-compatible AST node with:
|
|
78
|
+
- `type`: "OperatorNode"
|
|
79
|
+
- `op`: Operator name
|
|
80
|
+
- `fn`: Function name (same as op)
|
|
81
|
+
- `args`: Empty array
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
#### `toString()`
|
|
86
|
+
Convert to string representation.
|
|
87
|
+
- **Returns:** string - The operator symbol
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
#### `highlight(color)`
|
|
92
|
+
Highlights the node and sets operator label color to white.
|
|
93
|
+
- `color` {omdColor} - The highlight color
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
#### `clearProvenanceHighlights()`
|
|
98
|
+
Clears highlights and resets operator label color.
|
|
99
|
+
|
|
100
|
+
### Examples
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
// From string
|
|
104
|
+
const plus = new omdOperatorNode('+');
|
|
105
|
+
const times = new omdOperatorNode('*'); // Displays as × (configurable)
|
|
106
|
+
|
|
107
|
+
// From AST data
|
|
108
|
+
const minus = new omdOperatorNode({
|
|
109
|
+
type: 'OperatorNode',
|
|
110
|
+
op: 'subtract'
|
|
111
|
+
}); // Displays as −
|
|
112
|
+
|
|
113
|
+
// Rendering
|
|
114
|
+
const node = new omdOperatorNode('+');
|
|
115
|
+
node.setFontSize(24);
|
|
116
|
+
node.computeDimensions(); // Calculate size with padding
|
|
117
|
+
node.updateLayout(); // Position the text element
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### See Also
|
|
121
|
+
|
|
122
|
+
- [omdLeafNode](./omdLeafNode.md) - Parent class
|
|
123
|
+
- [omdNode](./omdNode.md) - Base class
|
|
124
|
+
- [omdBinaryExpressionNode](./omdBinaryExpressionNode.md) - Uses operator nodes
|
|
125
|
+
- [omdUnaryExpressionNode](./omdUnaryExpressionNode.md) - Uses operator nodes
|
|
126
|
+
|
|
127
|
+
```
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# omdParenthesisNode
|
|
2
|
+
|
|
3
|
+
Represents a parenthetical grouping in a mathematical expression, such as `(x + 2)`. This node is crucial for enforcing the correct order of operations.
|
|
4
|
+
|
|
5
|
+
## Class: `omdParenthesisNode extends omdNode`
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
import { omdParenthesisNode } from './omd/nodes/omdParenthesisNode.js';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
new omdParenthesisNode(astNodeData)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Parameters:**
|
|
18
|
+
- `astNodeData` {Object} - The math.js AST node, which must have a `content` property containing the AST for the inner expression.
|
|
19
|
+
|
|
20
|
+
### Static Methods
|
|
21
|
+
|
|
22
|
+
#### `fromString(expressionString)`
|
|
23
|
+
|
|
24
|
+
Creates an `omdParenthesisNode` from a string.
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const parenNode = omdParenthesisNode.fromString('(2 * x)');
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **Parameters:**
|
|
31
|
+
- `expressionString` {string} - The expression, which must be enclosed in parentheses.
|
|
32
|
+
- **Returns:** {omdParenthesisNode} A new instance.
|
|
33
|
+
- **Throws:** `Error` if `math.js` is not available or the string is not a valid parenthesized expression.
|
|
34
|
+
|
|
35
|
+
### Properties
|
|
36
|
+
|
|
37
|
+
Inherits properties from [`omdNode`](./omdNode.md), plus:
|
|
38
|
+
|
|
39
|
+
#### `expression`
|
|
40
|
+
- **Type:** [`omdNode`](./omdNode.md)
|
|
41
|
+
- **Description:** The node representing the expression inside the parentheses.
|
|
42
|
+
|
|
43
|
+
### Methods
|
|
44
|
+
|
|
45
|
+
Inherits methods from [`omdNode`](./omdNode.md). Key methods include:
|
|
46
|
+
|
|
47
|
+
#### `evaluate(variables)`
|
|
48
|
+
|
|
49
|
+
Evaluates the inner expression.
|
|
50
|
+
- **Parameters:**
|
|
51
|
+
- `variables` {Object} - A map of variable names to their numeric values.
|
|
52
|
+
- **Returns:** `number` - The result of the inner expression's evaluation.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
#### `simplify()`
|
|
57
|
+
|
|
58
|
+
Delegates to the central simplification engine to simplify the inner expression. The engine may also remove unnecessary parentheses.
|
|
59
|
+
|
|
60
|
+
- **Returns:** `Object` - An object indicating the result: `{ success, newRoot, message }`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
#### `isNecessary()`
|
|
65
|
+
|
|
66
|
+
Checks if the parentheses are mathematically necessary to maintain the order of operations, based on the parent node's context.
|
|
67
|
+
|
|
68
|
+
- **Returns:** `boolean` - `true` if the parentheses are required, `false` otherwise.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
#### `isConstant()`
|
|
73
|
+
|
|
74
|
+
Checks if the inner expression is a constant.
|
|
75
|
+
- **Returns:** `boolean`.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
#### `getValue()`
|
|
80
|
+
|
|
81
|
+
Returns the numeric value of the inner expression, if it is constant.
|
|
82
|
+
- **Returns:** `number`.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
#### `toMathJSNode()`
|
|
87
|
+
|
|
88
|
+
Converts the node back into its math.js AST representation.
|
|
89
|
+
- **Returns:** `Object` - A math.js `ParenthesisNode`.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
#### `toString()`
|
|
94
|
+
|
|
95
|
+
Converts the node to its string representation, including the parentheses.
|
|
96
|
+
- **Returns:** `string` - e.g., `"(x + 2)"`.
|
|
97
|
+
|
|
98
|
+
### Example
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
// Create a node representing (x + 2)
|
|
102
|
+
const innerExpressionAst = math.parse('x + 2');
|
|
103
|
+
const parenNode = new omdParenthesisNode({ content: innerExpressionAst });
|
|
104
|
+
|
|
105
|
+
// Set font size and render
|
|
106
|
+
parenNode.setFontSize(28);
|
|
107
|
+
parenNode.initialize();
|
|
108
|
+
|
|
109
|
+
// The simplification engine might remove these parentheses if the context allows.
|
|
110
|
+
const simplified = parenNode.simplify();
|
|
111
|
+
|
|
112
|
+
// Add to an SVG container to display
|
|
113
|
+
const svgContainer = new jsvgContainer();
|
|
114
|
+
svgContainer.addChild(parenNode);
|
|
115
|
+
document.body.appendChild(svgContainer.svgObject);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### See Also
|
|
119
|
+
|
|
120
|
+
- [`omdNode`](./omdNode.md) - The base class.
|
|
121
|
+
- [`omdGroupNode`](./omdGroupNode.md) - The class used to render the individual `(` and `)` symbols.
|
|
122
|
+
- [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - A common type for the inner expression.
|