@teachinglab/omd 0.6.1 → 0.6.3
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 +257 -251
- package/README.old.md +137 -137
- package/canvas/core/canvasConfig.js +202 -202
- package/canvas/drawing/segment.js +167 -167
- package/canvas/drawing/stroke.js +385 -385
- package/canvas/events/eventManager.js +444 -444
- package/canvas/events/pointerEventHandler.js +262 -262
- package/canvas/index.js +48 -48
- package/canvas/tools/PointerTool.js +71 -71
- package/canvas/tools/tool.js +222 -222
- package/canvas/utils/boundingBox.js +377 -377
- package/canvas/utils/mathUtils.js +258 -258
- package/docs/api/configuration-options.md +198 -198
- package/docs/api/eventManager.md +82 -82
- package/docs/api/focusFrameManager.md +144 -144
- package/docs/api/index.md +105 -105
- package/docs/api/main.md +62 -62
- package/docs/api/omdBinaryExpressionNode.md +86 -86
- package/docs/api/omdCanvas.md +83 -83
- package/docs/api/omdConfigManager.md +112 -112
- package/docs/api/omdConstantNode.md +52 -52
- package/docs/api/omdDisplay.md +87 -87
- package/docs/api/omdEquationNode.md +174 -174
- package/docs/api/omdEquationSequenceNode.md +258 -258
- package/docs/api/omdEquationStack.md +192 -192
- package/docs/api/omdFunctionNode.md +82 -82
- package/docs/api/omdGroupNode.md +78 -78
- package/docs/api/omdHelpers.md +87 -87
- package/docs/api/omdLeafNode.md +85 -85
- package/docs/api/omdNode.md +201 -201
- package/docs/api/omdOperationDisplayNode.md +117 -117
- package/docs/api/omdOperatorNode.md +91 -91
- package/docs/api/omdParenthesisNode.md +133 -133
- package/docs/api/omdPopup.md +191 -191
- package/docs/api/omdPowerNode.md +131 -131
- package/docs/api/omdRationalNode.md +144 -144
- package/docs/api/omdSequenceNode.md +128 -128
- package/docs/api/omdSimplification.md +78 -78
- package/docs/api/omdSqrtNode.md +144 -144
- package/docs/api/omdStepVisualizer.md +146 -146
- package/docs/api/omdStepVisualizerHighlighting.md +65 -65
- package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
- package/docs/api/omdStepVisualizerLayout.md +70 -70
- package/docs/api/omdStepVisualizerNodeUtils.md +140 -140
- package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
- package/docs/api/omdToolbar.md +130 -130
- package/docs/api/omdTranscriptionService.md +95 -95
- package/docs/api/omdTreeDiff.md +169 -169
- package/docs/api/omdUnaryExpressionNode.md +137 -137
- package/docs/api/omdUtilities.md +82 -82
- package/docs/api/omdVariableNode.md +123 -123
- package/docs/api/selectTool.md +74 -74
- package/docs/api/simplificationEngine.md +97 -97
- package/docs/api/simplificationRules.md +76 -76
- package/docs/api/simplificationUtils.md +64 -64
- package/docs/api/transcribe.md +43 -43
- package/docs/api-reference.md +85 -85
- package/docs/index.html +453 -453
- package/docs/index.md +38 -38
- package/docs/omd-objects.md +258 -258
- package/index.js +79 -79
- package/jsvg/index.js +3 -0
- package/jsvg/jsvg.js +898 -898
- package/jsvg/jsvgComponents.js +357 -358
- package/npm-docs/DOCUMENTATION_SUMMARY.md +220 -220
- package/npm-docs/README.md +251 -251
- package/npm-docs/api/api-reference.md +85 -85
- package/npm-docs/api/configuration-options.md +198 -198
- package/npm-docs/api/eventManager.md +82 -82
- package/npm-docs/api/expression-nodes.md +561 -561
- package/npm-docs/api/focusFrameManager.md +144 -144
- package/npm-docs/api/index.md +105 -105
- package/npm-docs/api/main.md +62 -62
- package/npm-docs/api/omdBinaryExpressionNode.md +86 -86
- package/npm-docs/api/omdCanvas.md +83 -83
- package/npm-docs/api/omdConfigManager.md +112 -112
- package/npm-docs/api/omdConstantNode.md +52 -52
- package/npm-docs/api/omdDisplay.md +87 -87
- package/npm-docs/api/omdEquationNode.md +174 -174
- package/npm-docs/api/omdEquationSequenceNode.md +258 -258
- package/npm-docs/api/omdEquationStack.md +192 -192
- package/npm-docs/api/omdFunctionNode.md +82 -82
- package/npm-docs/api/omdGroupNode.md +78 -78
- package/npm-docs/api/omdHelpers.md +87 -87
- package/npm-docs/api/omdLeafNode.md +85 -85
- package/npm-docs/api/omdNode.md +201 -201
- package/npm-docs/api/omdOperationDisplayNode.md +117 -117
- package/npm-docs/api/omdOperatorNode.md +91 -91
- package/npm-docs/api/omdParenthesisNode.md +133 -133
- package/npm-docs/api/omdPopup.md +191 -191
- package/npm-docs/api/omdPowerNode.md +131 -131
- package/npm-docs/api/omdRationalNode.md +144 -144
- package/npm-docs/api/omdSequenceNode.md +128 -128
- package/npm-docs/api/omdSimplification.md +78 -78
- package/npm-docs/api/omdSqrtNode.md +144 -144
- package/npm-docs/api/omdStepVisualizer.md +146 -146
- package/npm-docs/api/omdStepVisualizerHighlighting.md +65 -65
- package/npm-docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
- package/npm-docs/api/omdStepVisualizerLayout.md +70 -70
- package/npm-docs/api/omdStepVisualizerNodeUtils.md +140 -140
- package/npm-docs/api/omdStepVisualizerTextBoxes.md +76 -76
- package/npm-docs/api/omdToolbar.md +130 -130
- package/npm-docs/api/omdTranscriptionService.md +95 -95
- package/npm-docs/api/omdTreeDiff.md +169 -169
- package/npm-docs/api/omdUnaryExpressionNode.md +137 -137
- package/npm-docs/api/omdUtilities.md +82 -82
- package/npm-docs/api/omdVariableNode.md +123 -123
- package/npm-docs/api/selectTool.md +74 -74
- package/npm-docs/api/simplificationEngine.md +97 -97
- package/npm-docs/api/simplificationRules.md +76 -76
- package/npm-docs/api/simplificationUtils.md +64 -64
- package/npm-docs/api/transcribe.md +43 -43
- package/npm-docs/guides/equations.md +854 -854
- package/npm-docs/guides/factory-functions.md +354 -354
- package/npm-docs/guides/getting-started.md +318 -318
- package/npm-docs/guides/quick-examples.md +525 -525
- package/npm-docs/guides/visualizations.md +682 -682
- package/npm-docs/index.html +12 -0
- package/npm-docs/json-schemas.md +826 -826
- package/omd/config/omdConfigManager.js +279 -267
- package/omd/core/index.js +158 -158
- package/omd/core/omdEquationStack.js +606 -547
- package/omd/core/omdUtilities.js +113 -113
- package/omd/display/omdDisplay.js +1045 -963
- package/omd/display/omdToolbar.js +501 -501
- package/omd/nodes/omdBinaryExpressionNode.js +459 -459
- package/omd/nodes/omdConstantNode.js +141 -141
- package/omd/nodes/omdEquationNode.js +1327 -1327
- package/omd/nodes/omdFunctionNode.js +351 -351
- package/omd/nodes/omdGroupNode.js +67 -67
- package/omd/nodes/omdLeafNode.js +76 -76
- package/omd/nodes/omdNode.js +556 -556
- package/omd/nodes/omdOperationDisplayNode.js +321 -321
- package/omd/nodes/omdOperatorNode.js +108 -108
- package/omd/nodes/omdParenthesisNode.js +292 -292
- package/omd/nodes/omdPowerNode.js +235 -235
- package/omd/nodes/omdRationalNode.js +295 -295
- package/omd/nodes/omdSqrtNode.js +307 -307
- package/omd/nodes/omdUnaryExpressionNode.js +227 -227
- package/omd/nodes/omdVariableNode.js +122 -122
- package/omd/simplification/omdSimplification.js +140 -140
- package/omd/simplification/omdSimplificationEngine.js +887 -887
- package/omd/simplification/package.json +5 -5
- package/omd/simplification/rules/binaryRules.js +1037 -1037
- package/omd/simplification/rules/functionRules.js +111 -111
- package/omd/simplification/rules/index.js +48 -48
- package/omd/simplification/rules/parenthesisRules.js +19 -19
- package/omd/simplification/rules/powerRules.js +143 -143
- package/omd/simplification/rules/rationalRules.js +725 -725
- package/omd/simplification/rules/sqrtRules.js +48 -48
- package/omd/simplification/rules/unaryRules.js +37 -37
- package/omd/simplification/simplificationRules.js +31 -31
- package/omd/simplification/simplificationUtils.js +1055 -1055
- package/omd/step-visualizer/omdStepVisualizer.js +947 -947
- package/omd/step-visualizer/omdStepVisualizerHighlighting.js +246 -246
- package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
- package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +200 -200
- package/omd/utils/aiNextEquationStep.js +106 -106
- package/omd/utils/omdNodeOverlay.js +638 -638
- package/omd/utils/omdPopup.js +1203 -1203
- package/omd/utils/omdStepVisualizerInteractiveSteps.js +684 -684
- package/omd/utils/omdStepVisualizerNodeUtils.js +267 -267
- package/omd/utils/omdTranscriptionService.js +123 -123
- package/omd/utils/omdTreeDiff.js +733 -733
- package/package.json +59 -57
- package/readme.html +184 -120
- package/src/index.js +74 -74
- package/src/json-schemas.md +576 -576
- package/src/omd-json-samples.js +147 -147
- package/src/omdApp.js +391 -391
- package/src/omdAppCanvas.js +335 -335
- package/src/omdBalanceHanger.js +199 -199
- package/src/omdColor.js +13 -13
- package/src/omdCoordinatePlane.js +541 -541
- package/src/omdExpression.js +115 -115
- package/src/omdFactory.js +150 -150
- package/src/omdFunction.js +114 -114
- package/src/omdMetaExpression.js +290 -290
- package/src/omdNaturalExpression.js +563 -563
- package/src/omdNode.js +383 -383
- package/src/omdNumber.js +52 -52
- package/src/omdNumberLine.js +114 -112
- package/src/omdNumberTile.js +118 -118
- package/src/omdOperator.js +72 -72
- package/src/omdPowerExpression.js +91 -91
- package/src/omdProblem.js +259 -259
- package/src/omdRatioChart.js +251 -251
- package/src/omdRationalExpression.js +114 -114
- package/src/omdSampleData.js +215 -215
- package/src/omdShapes.js +512 -512
- package/src/omdSpinner.js +151 -151
- package/src/omdString.js +49 -49
- package/src/omdTable.js +498 -498
- package/src/omdTapeDiagram.js +244 -244
- package/src/omdTerm.js +91 -91
- package/src/omdTileEquation.js +349 -349
- package/src/omdUtils.js +84 -84
- package/src/omdVariable.js +51 -51
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
# omdSqrtNode
|
|
2
|
-
|
|
3
|
-
Represents a square root node in the mathematical expression tree. It handles the rendering of the radical symbol (√) and the expression under the root (radicand), ensuring correct visual layout and mathematical behavior.
|
|
4
|
-
|
|
5
|
-
## Class Definition
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
export class omdSqrtNode extends omdNode
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Constructor
|
|
12
|
-
|
|
13
|
-
### `new omdSqrtNode(astNodeData)`
|
|
14
|
-
|
|
15
|
-
Creates a new `omdSqrtNode` instance.
|
|
16
|
-
|
|
17
|
-
- **`astNodeData`** (`object`): The math.js AST node containing square root function information. It should have an `args` property, which is an array containing a single AST node for the radicand. The constructor also initializes the visual `radicalPath` and `radicalLine` elements.
|
|
18
|
-
|
|
19
|
-
## Static Methods
|
|
20
|
-
|
|
21
|
-
### `fromString(expressionString)`
|
|
22
|
-
|
|
23
|
-
Creates an `omdSqrtNode` from a string representation of a square root function. Requires `window.math` (math.js) to be available globally for parsing.
|
|
24
|
-
|
|
25
|
-
- **`expressionString`** (`string`): The square root expression as a string (e.g., `"sqrt(x+1)"`).
|
|
26
|
-
- **Returns**: `omdSqrtNode` - A new instance.
|
|
27
|
-
- **Throws**: `Error` if `math.js` is not available, if the string cannot be parsed, or if it does not represent a valid `sqrt` function.
|
|
28
|
-
|
|
29
|
-
## Public Properties
|
|
30
|
-
|
|
31
|
-
- **`argument`** (`omdNode`): The node representing the radicand (the expression under the root).
|
|
32
|
-
- **`value`** (`string`): Always `"sqrt"` for this node type.
|
|
33
|
-
- **`radicalPath`** (`jsvgPath`): The SVG path element that draws the radical symbol (√).
|
|
34
|
-
- **`radicalLine`** (`jsvgLine`): The SVG line element that draws the horizontal line above the radicand.
|
|
35
|
-
- **`args`** (`Array<object>`): The raw AST arguments passed to the constructor.
|
|
36
|
-
|
|
37
|
-
## Public Methods
|
|
38
|
-
|
|
39
|
-
### `computeDimensions()`
|
|
40
|
-
|
|
41
|
-
Calculates the dimensions of the square root node. It scales down the font size of the `argument`, computes its dimensions, and then determines the overall width (radical width + spacing + argument width) and height (argument height + extra height for the radical top).
|
|
42
|
-
|
|
43
|
-
- **Overrides**: `omdNode.computeDimensions()`.
|
|
44
|
-
|
|
45
|
-
### `updateLayout()`
|
|
46
|
-
|
|
47
|
-
Updates the layout of the square root node. It positions the `argument` node, then draws and positions the `radicalPath` and `radicalLine` elements relative to the argument, ensuring the radical symbol correctly encloses the radicand.
|
|
48
|
-
|
|
49
|
-
- **Overrides**: `omdNode.updateLayout()`.
|
|
50
|
-
|
|
51
|
-
### `clone()`
|
|
52
|
-
|
|
53
|
-
Creates a deep, structural clone of the square root node, including its `argument` node and visual elements. The cloned node's `provenance` array is updated to include the original node's ID.
|
|
54
|
-
|
|
55
|
-
- **Returns**: `omdSqrtNode` - A new, identical instance of the square root node.
|
|
56
|
-
|
|
57
|
-
### `highlightAll()`
|
|
58
|
-
|
|
59
|
-
Applies a highlight to the square root node itself and recursively highlights its `argument` node.
|
|
60
|
-
|
|
61
|
-
### `unhighlightAll()`
|
|
62
|
-
|
|
63
|
-
Removes the highlight from the square root node and recursively unhighlights its `argument` node.
|
|
64
|
-
|
|
65
|
-
### `toMathJSNode()`
|
|
66
|
-
|
|
67
|
-
Converts the `omdSqrtNode` back into its math.js AST representation. It creates a `FunctionNode` with `fn: 'sqrt'` and the converted `argument` AST.
|
|
68
|
-
|
|
69
|
-
- **Returns**: `object` - A math.js `FunctionNode` for the square root operation. The returned object also includes a `clone` method for compatibility.
|
|
70
|
-
|
|
71
|
-
### `toString()`
|
|
72
|
-
|
|
73
|
-
Converts the square root node to its string representation (e.g., `"sqrt(x+1)"`).
|
|
74
|
-
|
|
75
|
-
- **Returns**: `string`.
|
|
76
|
-
|
|
77
|
-
### `evaluate(variables)`
|
|
78
|
-
|
|
79
|
-
Evaluates the square root expression. It evaluates the `argument` and then calculates its square root.
|
|
80
|
-
|
|
81
|
-
- **`variables`** (`object`): A map of variable names to their numeric values.
|
|
82
|
-
- **Returns**: `number` - The evaluated square root, or `NaN` if the radicand cannot be evaluated or is negative.
|
|
83
|
-
|
|
84
|
-
### `isSquareRoot()`
|
|
85
|
-
|
|
86
|
-
Checks if the node represents a square root. Always returns `true` for `omdSqrtNode`.
|
|
87
|
-
|
|
88
|
-
- **Returns**: `boolean`.
|
|
89
|
-
|
|
90
|
-
### `isCubeRoot()`
|
|
91
|
-
|
|
92
|
-
Checks if the node represents a cube root. Always returns `false` for `omdSqrtNode`.
|
|
93
|
-
|
|
94
|
-
- **Returns**: `boolean`.
|
|
95
|
-
|
|
96
|
-
### `toPowerForm()`
|
|
97
|
-
|
|
98
|
-
Converts the square root node into an equivalent `omdPowerNode` representation (e.g., `sqrt(x)` becomes `x^(0.5)`).
|
|
99
|
-
|
|
100
|
-
- **Returns**: `omdPowerNode` - The equivalent power expression, or `null` if the `argument` is missing.
|
|
101
|
-
|
|
102
|
-
## Internal Methods
|
|
103
|
-
|
|
104
|
-
- **`parseValue()`**: Sets the `value` property to `"sqrt"`.
|
|
105
|
-
- **`createArgumentNode()`**: Creates an `omdNode` instance for the radicand from its AST, and adds it as a child.
|
|
106
|
-
- **`createRadicalElements()`**: Creates and initializes the `jsvgPath` for the radical symbol and the `jsvgLine` for the horizontal bar, adding them as children.
|
|
107
|
-
|
|
108
|
-
## Example
|
|
109
|
-
|
|
110
|
-
```javascript
|
|
111
|
-
import { omdSqrtNode } from '@teachinglab/omd';
|
|
112
|
-
import * as math from 'mathjs';
|
|
113
|
-
|
|
114
|
-
// Create from AST
|
|
115
|
-
const node = new omdSqrtNode({
|
|
116
|
-
type: 'FunctionNode',
|
|
117
|
-
fn: { name: 'sqrt' },
|
|
118
|
-
args: [ { type: 'SymbolNode', name: 'x' } ]
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// Or from string
|
|
122
|
-
const node2 = omdSqrtNode.fromString('sqrt(x+1)');
|
|
123
|
-
|
|
124
|
-
// Render and layout
|
|
125
|
-
node.setFontSize(24);
|
|
126
|
-
node.initialize();
|
|
127
|
-
|
|
128
|
-
// Evaluate
|
|
129
|
-
const val = node.evaluate({ x: 9 }); // 3
|
|
130
|
-
|
|
131
|
-
// Convert to power form
|
|
132
|
-
const powerNode = node.toPowerForm(); // x^(1/2)
|
|
133
|
-
|
|
134
|
-
// Add to an SVG container to display
|
|
135
|
-
// const svgContainer = new jsvgContainer();
|
|
136
|
-
// svgContainer.addChild(node);
|
|
137
|
-
// document.body.appendChild(svgContainer.svgObject);
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## See Also
|
|
141
|
-
|
|
142
|
-
- [`omdNode`](./omdNode.md) - The base class.
|
|
143
|
-
- [`omdPowerNode`](./omdPowerNode.md) - For power form (e.g., `x^(1/2)`).
|
|
144
|
-
- [`omdFunctionNode`](./omdFunctionNode.md) - For other mathematical functions.
|
|
1
|
+
# omdSqrtNode
|
|
2
|
+
|
|
3
|
+
Represents a square root node in the mathematical expression tree. It handles the rendering of the radical symbol (√) and the expression under the root (radicand), ensuring correct visual layout and mathematical behavior.
|
|
4
|
+
|
|
5
|
+
## Class Definition
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
export class omdSqrtNode extends omdNode
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Constructor
|
|
12
|
+
|
|
13
|
+
### `new omdSqrtNode(astNodeData)`
|
|
14
|
+
|
|
15
|
+
Creates a new `omdSqrtNode` instance.
|
|
16
|
+
|
|
17
|
+
- **`astNodeData`** (`object`): The math.js AST node containing square root function information. It should have an `args` property, which is an array containing a single AST node for the radicand. The constructor also initializes the visual `radicalPath` and `radicalLine` elements.
|
|
18
|
+
|
|
19
|
+
## Static Methods
|
|
20
|
+
|
|
21
|
+
### `fromString(expressionString)`
|
|
22
|
+
|
|
23
|
+
Creates an `omdSqrtNode` from a string representation of a square root function. Requires `window.math` (math.js) to be available globally for parsing.
|
|
24
|
+
|
|
25
|
+
- **`expressionString`** (`string`): The square root expression as a string (e.g., `"sqrt(x+1)"`).
|
|
26
|
+
- **Returns**: `omdSqrtNode` - A new instance.
|
|
27
|
+
- **Throws**: `Error` if `math.js` is not available, if the string cannot be parsed, or if it does not represent a valid `sqrt` function.
|
|
28
|
+
|
|
29
|
+
## Public Properties
|
|
30
|
+
|
|
31
|
+
- **`argument`** (`omdNode`): The node representing the radicand (the expression under the root).
|
|
32
|
+
- **`value`** (`string`): Always `"sqrt"` for this node type.
|
|
33
|
+
- **`radicalPath`** (`jsvgPath`): The SVG path element that draws the radical symbol (√).
|
|
34
|
+
- **`radicalLine`** (`jsvgLine`): The SVG line element that draws the horizontal line above the radicand.
|
|
35
|
+
- **`args`** (`Array<object>`): The raw AST arguments passed to the constructor.
|
|
36
|
+
|
|
37
|
+
## Public Methods
|
|
38
|
+
|
|
39
|
+
### `computeDimensions()`
|
|
40
|
+
|
|
41
|
+
Calculates the dimensions of the square root node. It scales down the font size of the `argument`, computes its dimensions, and then determines the overall width (radical width + spacing + argument width) and height (argument height + extra height for the radical top).
|
|
42
|
+
|
|
43
|
+
- **Overrides**: `omdNode.computeDimensions()`.
|
|
44
|
+
|
|
45
|
+
### `updateLayout()`
|
|
46
|
+
|
|
47
|
+
Updates the layout of the square root node. It positions the `argument` node, then draws and positions the `radicalPath` and `radicalLine` elements relative to the argument, ensuring the radical symbol correctly encloses the radicand.
|
|
48
|
+
|
|
49
|
+
- **Overrides**: `omdNode.updateLayout()`.
|
|
50
|
+
|
|
51
|
+
### `clone()`
|
|
52
|
+
|
|
53
|
+
Creates a deep, structural clone of the square root node, including its `argument` node and visual elements. The cloned node's `provenance` array is updated to include the original node's ID.
|
|
54
|
+
|
|
55
|
+
- **Returns**: `omdSqrtNode` - A new, identical instance of the square root node.
|
|
56
|
+
|
|
57
|
+
### `highlightAll()`
|
|
58
|
+
|
|
59
|
+
Applies a highlight to the square root node itself and recursively highlights its `argument` node.
|
|
60
|
+
|
|
61
|
+
### `unhighlightAll()`
|
|
62
|
+
|
|
63
|
+
Removes the highlight from the square root node and recursively unhighlights its `argument` node.
|
|
64
|
+
|
|
65
|
+
### `toMathJSNode()`
|
|
66
|
+
|
|
67
|
+
Converts the `omdSqrtNode` back into its math.js AST representation. It creates a `FunctionNode` with `fn: 'sqrt'` and the converted `argument` AST.
|
|
68
|
+
|
|
69
|
+
- **Returns**: `object` - A math.js `FunctionNode` for the square root operation. The returned object also includes a `clone` method for compatibility.
|
|
70
|
+
|
|
71
|
+
### `toString()`
|
|
72
|
+
|
|
73
|
+
Converts the square root node to its string representation (e.g., `"sqrt(x+1)"`).
|
|
74
|
+
|
|
75
|
+
- **Returns**: `string`.
|
|
76
|
+
|
|
77
|
+
### `evaluate(variables)`
|
|
78
|
+
|
|
79
|
+
Evaluates the square root expression. It evaluates the `argument` and then calculates its square root.
|
|
80
|
+
|
|
81
|
+
- **`variables`** (`object`): A map of variable names to their numeric values.
|
|
82
|
+
- **Returns**: `number` - The evaluated square root, or `NaN` if the radicand cannot be evaluated or is negative.
|
|
83
|
+
|
|
84
|
+
### `isSquareRoot()`
|
|
85
|
+
|
|
86
|
+
Checks if the node represents a square root. Always returns `true` for `omdSqrtNode`.
|
|
87
|
+
|
|
88
|
+
- **Returns**: `boolean`.
|
|
89
|
+
|
|
90
|
+
### `isCubeRoot()`
|
|
91
|
+
|
|
92
|
+
Checks if the node represents a cube root. Always returns `false` for `omdSqrtNode`.
|
|
93
|
+
|
|
94
|
+
- **Returns**: `boolean`.
|
|
95
|
+
|
|
96
|
+
### `toPowerForm()`
|
|
97
|
+
|
|
98
|
+
Converts the square root node into an equivalent `omdPowerNode` representation (e.g., `sqrt(x)` becomes `x^(0.5)`).
|
|
99
|
+
|
|
100
|
+
- **Returns**: `omdPowerNode` - The equivalent power expression, or `null` if the `argument` is missing.
|
|
101
|
+
|
|
102
|
+
## Internal Methods
|
|
103
|
+
|
|
104
|
+
- **`parseValue()`**: Sets the `value` property to `"sqrt"`.
|
|
105
|
+
- **`createArgumentNode()`**: Creates an `omdNode` instance for the radicand from its AST, and adds it as a child.
|
|
106
|
+
- **`createRadicalElements()`**: Creates and initializes the `jsvgPath` for the radical symbol and the `jsvgLine` for the horizontal bar, adding them as children.
|
|
107
|
+
|
|
108
|
+
## Example
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
import { omdSqrtNode } from '@teachinglab/omd';
|
|
112
|
+
import * as math from 'mathjs';
|
|
113
|
+
|
|
114
|
+
// Create from AST
|
|
115
|
+
const node = new omdSqrtNode({
|
|
116
|
+
type: 'FunctionNode',
|
|
117
|
+
fn: { name: 'sqrt' },
|
|
118
|
+
args: [ { type: 'SymbolNode', name: 'x' } ]
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Or from string
|
|
122
|
+
const node2 = omdSqrtNode.fromString('sqrt(x+1)');
|
|
123
|
+
|
|
124
|
+
// Render and layout
|
|
125
|
+
node.setFontSize(24);
|
|
126
|
+
node.initialize();
|
|
127
|
+
|
|
128
|
+
// Evaluate
|
|
129
|
+
const val = node.evaluate({ x: 9 }); // 3
|
|
130
|
+
|
|
131
|
+
// Convert to power form
|
|
132
|
+
const powerNode = node.toPowerForm(); // x^(1/2)
|
|
133
|
+
|
|
134
|
+
// Add to an SVG container to display
|
|
135
|
+
// const svgContainer = new jsvgContainer();
|
|
136
|
+
// svgContainer.addChild(node);
|
|
137
|
+
// document.body.appendChild(svgContainer.svgObject);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## See Also
|
|
141
|
+
|
|
142
|
+
- [`omdNode`](./omdNode.md) - The base class.
|
|
143
|
+
- [`omdPowerNode`](./omdPowerNode.md) - For power form (e.g., `x^(1/2)`).
|
|
144
|
+
- [`omdFunctionNode`](./omdFunctionNode.md) - For other mathematical functions.
|
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
# omdStepVisualizer
|
|
2
|
-
|
|
3
|
-
Visualizes a sequence of mathematical steps (typically equations) and provides interactive explanations for how one step transforms into the next. It extends `omdEquationSequenceNode` by adding a visual track of dots and lines to the right of the steps, which can be clicked to reveal details about the simplification or operation applied.
|
|
4
|
-
|
|
5
|
-
## Class Hierarchy
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
omdNode
|
|
9
|
-
└─ omdEquationSequenceNode
|
|
10
|
-
└─ omdStepVisualizer
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
See: [`omdEquationSequenceNode`](./omdEquationSequenceNode.md) for base sequence functionality.
|
|
14
|
-
|
|
15
|
-
## Constructor
|
|
16
|
-
|
|
17
|
-
### `new omdStepVisualizer(steps)`
|
|
18
|
-
|
|
19
|
-
Creates a new `omdStepVisualizer` instance.
|
|
20
|
-
|
|
21
|
-
- **`steps`** (`Array<omdNode>`): An array of nodes (usually `omdEquationNode`) representing the initial steps in the sequence.
|
|
22
|
-
|
|
23
|
-
During construction, it initializes internal arrays for `stepDots` and `stepLines`, creates a `visualContainer` for these elements, and sets up managers for `highlighting`, `textBoxes`, and `layout`. It also populates `nodeToStepMap` for efficient lookup.
|
|
24
|
-
|
|
25
|
-
## Public Properties
|
|
26
|
-
|
|
27
|
-
- **`stepDots`** (`Array<jsvgEllipse>`): An array of `jsvgEllipse` objects representing the clickable dots for each equation step.
|
|
28
|
-
- **`stepLines`** (`Array<jsvgLine>`): An array of `jsvgLine` objects connecting the step dots.
|
|
29
|
-
- **`visualContainer`** (`jsvgLayoutGroup`): The `jsvgLayoutGroup` that holds the `stepDots` and `stepLines`.
|
|
30
|
-
- **`dotRadius`** (`number`): The radius of the step dots, determined by `omdConfigManager`.
|
|
31
|
-
- **`lineWidth`** (`number`): The stroke width of the connecting lines.
|
|
32
|
-
- **`visualSpacing`** (`number`): The horizontal spacing between the equation sequence and the visual tracker.
|
|
33
|
-
- **`activeDotIndex`** (`number`): The 0-based index of the currently active (clicked) dot. `-1` if none.
|
|
34
|
-
- **`dotsClickable`** (`boolean`): Controls whether the step dots can be clicked to show explanations. Default: `true`.
|
|
35
|
-
- **`nodeToStepMap`** (`Map<string, number>`): A map from `omdNode` IDs to their corresponding step index in the sequence.
|
|
36
|
-
- **`stepVisualizerHighlights`** (`Set<string>`): A set of node IDs that are currently highlighted by the visualizer.
|
|
37
|
-
- **`highlighting`** ([`omdStepVisualizerHighlighting`](./omdStepVisualizerHighlighting.md)): The manager responsible for all highlighting logic.
|
|
38
|
-
- **`textBoxManager`** ([`omdStepVisualizerTextBoxes`](./omdStepVisualizerTextBoxes.md)): The manager responsible for creating, positioning, and removing the explanation text boxes.
|
|
39
|
-
- **`layoutManager`** ([`omdStepVisualizerLayout`](./omdStepVisualizerLayout.md)): The manager responsible for layout and z-ordering of all visual elements.
|
|
40
|
-
|
|
41
|
-
## Public Methods
|
|
42
|
-
|
|
43
|
-
### `rebuildVisualizer()`
|
|
44
|
-
|
|
45
|
-
Forces a complete rebuild of the visual elements (dots and lines) from scratch. This is useful after significant changes to the underlying `steps` array.
|
|
46
|
-
|
|
47
|
-
### `addStep(step, options)`
|
|
48
|
-
|
|
49
|
-
Adds a new step to the sequence. This method overrides the base `omdEquationSequenceNode.addStep` to also create and manage the corresponding visual dot and connecting line for the new step.
|
|
50
|
-
|
|
51
|
-
- **`step`** (`omdNode` | `string`): The node object or expression string for the step.
|
|
52
|
-
- **`options`** (`object`): Options for the step, such as `description` and `stepMark` (importance level).
|
|
53
|
-
|
|
54
|
-
### `getNodeStepNumber(nodeId)`
|
|
55
|
-
|
|
56
|
-
Retrieves the step number (index) associated with a given `omdNode` ID within the sequence.
|
|
57
|
-
|
|
58
|
-
- **`nodeId`** (`string`): The ID of the node to look up.
|
|
59
|
-
- **Returns**: `number` | `undefined` - The 0-based step index, or `undefined` if the node is not found within a step.
|
|
60
|
-
|
|
61
|
-
### `computeDimensions()`
|
|
62
|
-
|
|
63
|
-
Calculates the overall dimensions of the visualizer, accounting for the width and height of the equation sequence and the additional space required for the visual tracker (dots and lines).
|
|
64
|
-
|
|
65
|
-
- **Overrides**: `omdEquationSequenceNode.computeDimensions()`.
|
|
66
|
-
|
|
67
|
-
### `updateLayout()`
|
|
68
|
-
|
|
69
|
-
Updates the layout of the visualizer, positioning both the equation sequence and the visual tracker elements. It delegates to the `layoutManager` for precise positioning of dots and lines.
|
|
70
|
-
|
|
71
|
-
- **Overrides**: `omdEquationSequenceNode.updateLayout()`.
|
|
72
|
-
|
|
73
|
-
### `undoLastOperation()`
|
|
74
|
-
|
|
75
|
-
Removes the most recent operation and its resulting equation from the sequence. This method overrides the base `omdEquationSequenceNode.undoLastOperation` to also trigger a `rebuildVisualizer()` to ensure visual elements are synchronized.
|
|
76
|
-
|
|
77
|
-
- **Returns**: `boolean` - `true` if an operation was undone, `false` otherwise.
|
|
78
|
-
|
|
79
|
-
### `setDotColor(dotIndex, color)`
|
|
80
|
-
|
|
81
|
-
Sets the fill and stroke color of a specific step dot.
|
|
82
|
-
|
|
83
|
-
- **`dotIndex`** (`number`): The index of the dot to color.
|
|
84
|
-
- **`color`** (`string`): The new color.
|
|
85
|
-
|
|
86
|
-
### `setLineAboveColor(dotIndex, color)`
|
|
87
|
-
|
|
88
|
-
Sets the stroke color of the line segment directly above a specific step dot.
|
|
89
|
-
|
|
90
|
-
- **`dotIndex`** (`number`): The index of the dot whose preceding line should be colored.
|
|
91
|
-
- **`color`** (`string`): The new color.
|
|
92
|
-
|
|
93
|
-
### `setDotsClickable(enabled)`
|
|
94
|
-
|
|
95
|
-
Enables or disables the ability for users to click on the step dots to reveal explanations.
|
|
96
|
-
|
|
97
|
-
- **`enabled`** (`boolean`): `true` to enable clicking, `false` to disable.
|
|
98
|
-
|
|
99
|
-
### `getStepTextBoxes()`
|
|
100
|
-
|
|
101
|
-
Retrieves the array of currently visible explanation text box components managed by the `textBoxManager`.
|
|
102
|
-
|
|
103
|
-
- **Returns**: `Array<omdStepVisualizerTextBox>` - The active text box instances.
|
|
104
|
-
|
|
105
|
-
## Internal Methods
|
|
106
|
-
|
|
107
|
-
- **`_initializeVisualElements()`**: Creates and initializes the visual dots and lines for all existing equation steps, and populates the `nodeToStepMap`.
|
|
108
|
-
- **`_createStepDot(equation, index)`**: Creates a single `jsvgEllipse` representing a step dot, associates it with an equation, and adds it to the `visualContainer`.
|
|
109
|
-
- **`_createStepLine(fromIndex, toIndex)`**: Creates a `jsvgLine` connecting two step dots and adds it to the `visualContainer`.
|
|
110
|
-
- **`_clearVisualElements()`**: Removes all existing dots, lines, and text boxes from the display and resets internal arrays.
|
|
111
|
-
- **`_handleDotClick(dot, dotIndex)`**: Event handler for when a step dot is clicked. It manages the active dot state, triggers highlighting, and creates/removes explanation text boxes.
|
|
112
|
-
- **`setActiveDot(dotIndex)`**: Sets a specific dot as the visually active one, changing its color and triggering the display of its explanation text box.
|
|
113
|
-
- **`_clearActiveDot()`**: Clears the currently active dot, resetting its color, removing its text box, and clearing highlights.
|
|
114
|
-
- **`_getSimplificationDataForDot(dotIndex)`**: Gathers and formats the simplification and operation data relevant to a specific step dot, used to populate the explanation text box.
|
|
115
|
-
- **`_createDefaultSimplificationData(message)`**: Helper to create a default data object for step explanations.
|
|
116
|
-
- **`_findPreviousVisibleEquationIndex(currentIndex)`**: Finds the index of the last visible equation step before the given `currentIndex`.
|
|
117
|
-
- **`_getRelevantSimplifications(simplificationHistory, startIndex, endIndex)`**: Filters the full simplification history to find entries relevant to a specific range of steps.
|
|
118
|
-
- **`_createMultipleSimplificationsData(simplifications)`**: Formats data for displaying multiple simplification events in a single text box.
|
|
119
|
-
- **`_checkForOperationStep(equationIndex)`**: Checks if a step at a given index is an `omdOperationDisplayNode` and extracts its data.
|
|
120
|
-
- **`_checkForSingleSimplification(simplificationHistory, equationIndex)`**: Checks for a single simplification entry relevant to a specific step.
|
|
121
|
-
- **`_getFallbackSimplificationData(equationIndex)`**: Provides a default explanation if no specific simplification or operation data is found for a step.
|
|
122
|
-
|
|
123
|
-
## Example
|
|
124
|
-
|
|
125
|
-
```javascript
|
|
126
|
-
import { omdStepVisualizer } from '@teachinglab/omd';
|
|
127
|
-
import { omdEquationNode } from '@teachinglab/omd';
|
|
128
|
-
import { omdDisplay } from '@teachinglab/omd';
|
|
129
|
-
|
|
130
|
-
// 1. Define the steps of a solution (must be omdEquationNode for dots to appear)
|
|
131
|
-
const steps = [
|
|
132
|
-
omdEquationNode.fromString('2x + 4 = 10'),
|
|
133
|
-
omdEquationNode.fromString('2x = 6'),
|
|
134
|
-
omdEquationNode.fromString('x = 3')
|
|
135
|
-
];
|
|
136
|
-
|
|
137
|
-
// 2. Create the visualizer
|
|
138
|
-
const visualizer = new omdStepVisualizer(steps);
|
|
139
|
-
|
|
140
|
-
// 3. Add it to a display container
|
|
141
|
-
const display = new omdDisplay(document.getElementById('container'));
|
|
142
|
-
display.render(visualizer);
|
|
143
|
-
|
|
144
|
-
// Now the steps will be displayed with interactive dots on the right.
|
|
145
|
-
// Only omdEquationNode steps are visualized with dots/lines.
|
|
146
|
-
// Clicking the dot next to "2x = 6" will explain that 4 was subtracted from both sides.
|
|
1
|
+
# omdStepVisualizer
|
|
2
|
+
|
|
3
|
+
Visualizes a sequence of mathematical steps (typically equations) and provides interactive explanations for how one step transforms into the next. It extends `omdEquationSequenceNode` by adding a visual track of dots and lines to the right of the steps, which can be clicked to reveal details about the simplification or operation applied.
|
|
4
|
+
|
|
5
|
+
## Class Hierarchy
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
omdNode
|
|
9
|
+
└─ omdEquationSequenceNode
|
|
10
|
+
└─ omdStepVisualizer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
See: [`omdEquationSequenceNode`](./omdEquationSequenceNode.md) for base sequence functionality.
|
|
14
|
+
|
|
15
|
+
## Constructor
|
|
16
|
+
|
|
17
|
+
### `new omdStepVisualizer(steps)`
|
|
18
|
+
|
|
19
|
+
Creates a new `omdStepVisualizer` instance.
|
|
20
|
+
|
|
21
|
+
- **`steps`** (`Array<omdNode>`): An array of nodes (usually `omdEquationNode`) representing the initial steps in the sequence.
|
|
22
|
+
|
|
23
|
+
During construction, it initializes internal arrays for `stepDots` and `stepLines`, creates a `visualContainer` for these elements, and sets up managers for `highlighting`, `textBoxes`, and `layout`. It also populates `nodeToStepMap` for efficient lookup.
|
|
24
|
+
|
|
25
|
+
## Public Properties
|
|
26
|
+
|
|
27
|
+
- **`stepDots`** (`Array<jsvgEllipse>`): An array of `jsvgEllipse` objects representing the clickable dots for each equation step.
|
|
28
|
+
- **`stepLines`** (`Array<jsvgLine>`): An array of `jsvgLine` objects connecting the step dots.
|
|
29
|
+
- **`visualContainer`** (`jsvgLayoutGroup`): The `jsvgLayoutGroup` that holds the `stepDots` and `stepLines`.
|
|
30
|
+
- **`dotRadius`** (`number`): The radius of the step dots, determined by `omdConfigManager`.
|
|
31
|
+
- **`lineWidth`** (`number`): The stroke width of the connecting lines.
|
|
32
|
+
- **`visualSpacing`** (`number`): The horizontal spacing between the equation sequence and the visual tracker.
|
|
33
|
+
- **`activeDotIndex`** (`number`): The 0-based index of the currently active (clicked) dot. `-1` if none.
|
|
34
|
+
- **`dotsClickable`** (`boolean`): Controls whether the step dots can be clicked to show explanations. Default: `true`.
|
|
35
|
+
- **`nodeToStepMap`** (`Map<string, number>`): A map from `omdNode` IDs to their corresponding step index in the sequence.
|
|
36
|
+
- **`stepVisualizerHighlights`** (`Set<string>`): A set of node IDs that are currently highlighted by the visualizer.
|
|
37
|
+
- **`highlighting`** ([`omdStepVisualizerHighlighting`](./omdStepVisualizerHighlighting.md)): The manager responsible for all highlighting logic.
|
|
38
|
+
- **`textBoxManager`** ([`omdStepVisualizerTextBoxes`](./omdStepVisualizerTextBoxes.md)): The manager responsible for creating, positioning, and removing the explanation text boxes.
|
|
39
|
+
- **`layoutManager`** ([`omdStepVisualizerLayout`](./omdStepVisualizerLayout.md)): The manager responsible for layout and z-ordering of all visual elements.
|
|
40
|
+
|
|
41
|
+
## Public Methods
|
|
42
|
+
|
|
43
|
+
### `rebuildVisualizer()`
|
|
44
|
+
|
|
45
|
+
Forces a complete rebuild of the visual elements (dots and lines) from scratch. This is useful after significant changes to the underlying `steps` array.
|
|
46
|
+
|
|
47
|
+
### `addStep(step, options)`
|
|
48
|
+
|
|
49
|
+
Adds a new step to the sequence. This method overrides the base `omdEquationSequenceNode.addStep` to also create and manage the corresponding visual dot and connecting line for the new step.
|
|
50
|
+
|
|
51
|
+
- **`step`** (`omdNode` | `string`): The node object or expression string for the step.
|
|
52
|
+
- **`options`** (`object`): Options for the step, such as `description` and `stepMark` (importance level).
|
|
53
|
+
|
|
54
|
+
### `getNodeStepNumber(nodeId)`
|
|
55
|
+
|
|
56
|
+
Retrieves the step number (index) associated with a given `omdNode` ID within the sequence.
|
|
57
|
+
|
|
58
|
+
- **`nodeId`** (`string`): The ID of the node to look up.
|
|
59
|
+
- **Returns**: `number` | `undefined` - The 0-based step index, or `undefined` if the node is not found within a step.
|
|
60
|
+
|
|
61
|
+
### `computeDimensions()`
|
|
62
|
+
|
|
63
|
+
Calculates the overall dimensions of the visualizer, accounting for the width and height of the equation sequence and the additional space required for the visual tracker (dots and lines).
|
|
64
|
+
|
|
65
|
+
- **Overrides**: `omdEquationSequenceNode.computeDimensions()`.
|
|
66
|
+
|
|
67
|
+
### `updateLayout()`
|
|
68
|
+
|
|
69
|
+
Updates the layout of the visualizer, positioning both the equation sequence and the visual tracker elements. It delegates to the `layoutManager` for precise positioning of dots and lines.
|
|
70
|
+
|
|
71
|
+
- **Overrides**: `omdEquationSequenceNode.updateLayout()`.
|
|
72
|
+
|
|
73
|
+
### `undoLastOperation()`
|
|
74
|
+
|
|
75
|
+
Removes the most recent operation and its resulting equation from the sequence. This method overrides the base `omdEquationSequenceNode.undoLastOperation` to also trigger a `rebuildVisualizer()` to ensure visual elements are synchronized.
|
|
76
|
+
|
|
77
|
+
- **Returns**: `boolean` - `true` if an operation was undone, `false` otherwise.
|
|
78
|
+
|
|
79
|
+
### `setDotColor(dotIndex, color)`
|
|
80
|
+
|
|
81
|
+
Sets the fill and stroke color of a specific step dot.
|
|
82
|
+
|
|
83
|
+
- **`dotIndex`** (`number`): The index of the dot to color.
|
|
84
|
+
- **`color`** (`string`): The new color.
|
|
85
|
+
|
|
86
|
+
### `setLineAboveColor(dotIndex, color)`
|
|
87
|
+
|
|
88
|
+
Sets the stroke color of the line segment directly above a specific step dot.
|
|
89
|
+
|
|
90
|
+
- **`dotIndex`** (`number`): The index of the dot whose preceding line should be colored.
|
|
91
|
+
- **`color`** (`string`): The new color.
|
|
92
|
+
|
|
93
|
+
### `setDotsClickable(enabled)`
|
|
94
|
+
|
|
95
|
+
Enables or disables the ability for users to click on the step dots to reveal explanations.
|
|
96
|
+
|
|
97
|
+
- **`enabled`** (`boolean`): `true` to enable clicking, `false` to disable.
|
|
98
|
+
|
|
99
|
+
### `getStepTextBoxes()`
|
|
100
|
+
|
|
101
|
+
Retrieves the array of currently visible explanation text box components managed by the `textBoxManager`.
|
|
102
|
+
|
|
103
|
+
- **Returns**: `Array<omdStepVisualizerTextBox>` - The active text box instances.
|
|
104
|
+
|
|
105
|
+
## Internal Methods
|
|
106
|
+
|
|
107
|
+
- **`_initializeVisualElements()`**: Creates and initializes the visual dots and lines for all existing equation steps, and populates the `nodeToStepMap`.
|
|
108
|
+
- **`_createStepDot(equation, index)`**: Creates a single `jsvgEllipse` representing a step dot, associates it with an equation, and adds it to the `visualContainer`.
|
|
109
|
+
- **`_createStepLine(fromIndex, toIndex)`**: Creates a `jsvgLine` connecting two step dots and adds it to the `visualContainer`.
|
|
110
|
+
- **`_clearVisualElements()`**: Removes all existing dots, lines, and text boxes from the display and resets internal arrays.
|
|
111
|
+
- **`_handleDotClick(dot, dotIndex)`**: Event handler for when a step dot is clicked. It manages the active dot state, triggers highlighting, and creates/removes explanation text boxes.
|
|
112
|
+
- **`setActiveDot(dotIndex)`**: Sets a specific dot as the visually active one, changing its color and triggering the display of its explanation text box.
|
|
113
|
+
- **`_clearActiveDot()`**: Clears the currently active dot, resetting its color, removing its text box, and clearing highlights.
|
|
114
|
+
- **`_getSimplificationDataForDot(dotIndex)`**: Gathers and formats the simplification and operation data relevant to a specific step dot, used to populate the explanation text box.
|
|
115
|
+
- **`_createDefaultSimplificationData(message)`**: Helper to create a default data object for step explanations.
|
|
116
|
+
- **`_findPreviousVisibleEquationIndex(currentIndex)`**: Finds the index of the last visible equation step before the given `currentIndex`.
|
|
117
|
+
- **`_getRelevantSimplifications(simplificationHistory, startIndex, endIndex)`**: Filters the full simplification history to find entries relevant to a specific range of steps.
|
|
118
|
+
- **`_createMultipleSimplificationsData(simplifications)`**: Formats data for displaying multiple simplification events in a single text box.
|
|
119
|
+
- **`_checkForOperationStep(equationIndex)`**: Checks if a step at a given index is an `omdOperationDisplayNode` and extracts its data.
|
|
120
|
+
- **`_checkForSingleSimplification(simplificationHistory, equationIndex)`**: Checks for a single simplification entry relevant to a specific step.
|
|
121
|
+
- **`_getFallbackSimplificationData(equationIndex)`**: Provides a default explanation if no specific simplification or operation data is found for a step.
|
|
122
|
+
|
|
123
|
+
## Example
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { omdStepVisualizer } from '@teachinglab/omd';
|
|
127
|
+
import { omdEquationNode } from '@teachinglab/omd';
|
|
128
|
+
import { omdDisplay } from '@teachinglab/omd';
|
|
129
|
+
|
|
130
|
+
// 1. Define the steps of a solution (must be omdEquationNode for dots to appear)
|
|
131
|
+
const steps = [
|
|
132
|
+
omdEquationNode.fromString('2x + 4 = 10'),
|
|
133
|
+
omdEquationNode.fromString('2x = 6'),
|
|
134
|
+
omdEquationNode.fromString('x = 3')
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
// 2. Create the visualizer
|
|
138
|
+
const visualizer = new omdStepVisualizer(steps);
|
|
139
|
+
|
|
140
|
+
// 3. Add it to a display container
|
|
141
|
+
const display = new omdDisplay(document.getElementById('container'));
|
|
142
|
+
display.render(visualizer);
|
|
143
|
+
|
|
144
|
+
// Now the steps will be displayed with interactive dots on the right.
|
|
145
|
+
// Only omdEquationNode steps are visualized with dots/lines.
|
|
146
|
+
// Clicking the dot next to "2x = 6" will explain that 4 was subtracted from both sides.
|
|
147
147
|
```
|