@teachinglab/omd 0.3.0 → 0.3.1

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.
Files changed (57) hide show
  1. package/docs/api/configuration-options.md +198 -198
  2. package/docs/api/eventManager.md +82 -82
  3. package/docs/api/focusFrameManager.md +144 -144
  4. package/docs/api/index.md +105 -105
  5. package/docs/api/main.md +62 -62
  6. package/docs/api/omdBinaryExpressionNode.md +86 -86
  7. package/docs/api/omdCanvas.md +83 -83
  8. package/docs/api/omdConfigManager.md +112 -112
  9. package/docs/api/omdConstantNode.md +52 -52
  10. package/docs/api/omdDisplay.md +87 -87
  11. package/docs/api/omdEquationNode.md +174 -174
  12. package/docs/api/omdEquationSequenceNode.md +258 -258
  13. package/docs/api/omdEquationStack.md +156 -156
  14. package/docs/api/omdFunctionNode.md +82 -82
  15. package/docs/api/omdGroupNode.md +78 -78
  16. package/docs/api/omdHelpers.md +87 -87
  17. package/docs/api/omdLeafNode.md +85 -85
  18. package/docs/api/omdNode.md +201 -201
  19. package/docs/api/omdOperationDisplayNode.md +117 -117
  20. package/docs/api/omdOperatorNode.md +91 -91
  21. package/docs/api/omdParenthesisNode.md +133 -133
  22. package/docs/api/omdPopup.md +191 -191
  23. package/docs/api/omdPowerNode.md +131 -131
  24. package/docs/api/omdRationalNode.md +144 -144
  25. package/docs/api/omdSimplification.md +78 -78
  26. package/docs/api/omdSqrtNode.md +144 -144
  27. package/docs/api/omdStepVisualizer.md +146 -146
  28. package/docs/api/omdStepVisualizerHighlighting.md +65 -65
  29. package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
  30. package/docs/api/omdStepVisualizerLayout.md +70 -70
  31. package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
  32. package/docs/api/omdTranscriptionService.md +95 -95
  33. package/docs/api/omdTreeDiff.md +169 -169
  34. package/docs/api/omdUnaryExpressionNode.md +137 -137
  35. package/docs/api/omdUtilities.md +82 -82
  36. package/docs/api/omdVariableNode.md +123 -123
  37. package/omd/nodes/omdConstantNode.js +141 -141
  38. package/omd/nodes/omdGroupNode.js +67 -67
  39. package/omd/nodes/omdLeafNode.js +76 -76
  40. package/omd/nodes/omdOperatorNode.js +108 -108
  41. package/omd/nodes/omdParenthesisNode.js +292 -292
  42. package/omd/nodes/omdPowerNode.js +235 -235
  43. package/omd/nodes/omdRationalNode.js +295 -295
  44. package/omd/nodes/omdVariableNode.js +122 -122
  45. package/omd/simplification/omdSimplification.js +140 -140
  46. package/omd/step-visualizer/omdStepVisualizer.js +947 -947
  47. package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
  48. package/package.json +1 -1
  49. package/src/index.js +11 -0
  50. package/src/omdBalanceHanger.js +2 -1
  51. package/src/omdEquation.js +1 -1
  52. package/src/omdNumber.js +1 -1
  53. package/src/omdNumberLine.js +13 -7
  54. package/src/omdRatioChart.js +11 -0
  55. package/src/omdShapes.js +1 -1
  56. package/src/omdTapeDiagram.js +1 -1
  57. package/src/omdTerm.js +1 -1
@@ -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
  ```
@@ -1,66 +1,66 @@
1
- # omdStepVisualizerHighlighting
2
-
3
- Manages the highlighting of nodes within mathematical expressions displayed by the `omdStepVisualizer`. It uses a robust tree differencing algorithm to identify changes between consecutive steps and highlights affected nodes, providing visual feedback on transformations.
4
-
5
- ## Class Definition
6
-
7
- ```javascript
8
- export class omdStepVisualizerHighlighting
9
- ```
10
-
11
- ## Constructor
12
-
13
- ### `new omdStepVisualizerHighlighting(stepVisualizer)`
14
-
15
- Creates a new `omdStepVisualizerHighlighting` instance.
16
-
17
- - **`stepVisualizer`** (`omdStepVisualizer`): The step visualizer instance this highlighting manager is associated with.
18
-
19
- During construction, it initializes a `Set` to track `highlightedNodes` and sets `educationalMode` to `true` by default.
20
-
21
- ## Public Properties
22
-
23
- - **`stepVisualizer`** (`omdStepVisualizer`): The associated step visualizer instance.
24
- - **`highlightedNodes`** (`Set<omdNode>`): A set of `omdNode` instances that are currently highlighted by this manager.
25
- - **`educationalMode`** (`boolean`): If `true`, enables highlighting of pedagogical simplifications (e.g., intermediate steps that might be skipped in a final solution). Default: `true`.
26
-
27
- ## Public Methods
28
-
29
- ### `highlightAffectedNodes(dotIndex, isOperation = false)`
30
-
31
- This is the main method to trigger highlighting. It compares the equation at `dotIndex` with the previous visible equation in the sequence to identify changes and then applies appropriate highlighting.
32
-
33
- - **`dotIndex`** (`number`): The index of the dot (step) for which to highlight affected nodes.
34
- - **`isOperation`** (`boolean`, optional): If `true`, indicates that the step is an operation (e.g., adding to both sides), which affects how provenance is highlighted. Default: `false`.
35
-
36
- **How it Works:**
37
-
38
- 1. **Clear Existing Highlights**: First, any previously active highlights are cleared.
39
- 2. **Identify Equations**: It determines the `currentEquation` (associated with `dotIndex`) and finds the `previousEquation` (the nearest visible equation before the current one).
40
- 3. **Tree Differencing**: It uses `omdTreeDiff.findChangedNodes` to perform a robust comparison between the `previousEquation` and `currentEquation`. This algorithm identifies nodes that have been added, removed, or modified.
41
- 4. **Direct Highlighting**: Nodes identified as directly changed by the diff algorithm are highlighted with a primary explanation color (`omdColor.explainColor`).
42
- 5. **Provenance Highlighting**: For non-operation steps, the system traces the `provenance` (history) of the directly changed nodes back to their origins in the `previousEquation`. These originating nodes are then highlighted with a secondary provenance color (`omdColor.provenanceColor`), visually connecting the transformation.
43
-
44
- ### `clearHighlights()`
45
-
46
- Removes all active highlights managed by this class from the expression tree. It iterates through all `highlightedNodes` and calls `setExplainHighlight(false)` on them, then clears its internal `highlightedNodes` set.
47
-
48
- ## Internal Methods
49
-
50
- - **`_highlightNode(node)`**: Applies the standard explanation highlight color (`omdColor.explainColor`) to a single `omdNode` by calling its `setExplainHighlight(true)` method and adds the node to `highlightedNodes`.
51
- - **`_findNearestVisibleEquationAbove(currentIndex)`**: Searches backward from `currentIndex` in the `stepVisualizer.steps` array to find the closest `omdEquationNode` that is currently visible.
52
- - **`_highlightProvenanceNodes(changedNodes, previousEquation)`**: Iterates through `changedNodes` and their `provenance` chains to identify and highlight corresponding nodes in the `previousEquation` with `omdColor.provenanceColor`. It uses `rootNode.nodeMap` for efficient node lookup and a `visited` set to prevent redundant processing.
53
- - **`_belongsToEquation(node, targetEquation)`**: Checks if a given `omdNode` is part of the subtree of a `targetEquation` by traversing up its parent chain.
54
- - **`_highlightProvenanceNode(node)`**: Applies the secondary provenance highlighting style (`omdColor.provenanceColor`) to a single `omdNode` by calling its `setExplainHighlight(true, omdColor.provenanceColor)` method.
55
-
56
- ## Example
57
-
58
- This class is typically used internally by `omdStepVisualizer` when a step dot is clicked:
59
-
60
- ```javascript
61
- // Inside omdStepVisualizer's _handleDotClick method:
62
- this.highlighting.highlightAffectedNodes(dotIndex, isOperation);
63
-
64
- // Inside omdStepVisualizer's _clearActiveDot method:
65
- this.highlighting.clearHighlights();
1
+ # omdStepVisualizerHighlighting
2
+
3
+ Manages the highlighting of nodes within mathematical expressions displayed by the `omdStepVisualizer`. It uses a robust tree differencing algorithm to identify changes between consecutive steps and highlights affected nodes, providing visual feedback on transformations.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdStepVisualizerHighlighting
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdStepVisualizerHighlighting(stepVisualizer)`
14
+
15
+ Creates a new `omdStepVisualizerHighlighting` instance.
16
+
17
+ - **`stepVisualizer`** (`omdStepVisualizer`): The step visualizer instance this highlighting manager is associated with.
18
+
19
+ During construction, it initializes a `Set` to track `highlightedNodes` and sets `educationalMode` to `true` by default.
20
+
21
+ ## Public Properties
22
+
23
+ - **`stepVisualizer`** (`omdStepVisualizer`): The associated step visualizer instance.
24
+ - **`highlightedNodes`** (`Set<omdNode>`): A set of `omdNode` instances that are currently highlighted by this manager.
25
+ - **`educationalMode`** (`boolean`): If `true`, enables highlighting of pedagogical simplifications (e.g., intermediate steps that might be skipped in a final solution). Default: `true`.
26
+
27
+ ## Public Methods
28
+
29
+ ### `highlightAffectedNodes(dotIndex, isOperation = false)`
30
+
31
+ This is the main method to trigger highlighting. It compares the equation at `dotIndex` with the previous visible equation in the sequence to identify changes and then applies appropriate highlighting.
32
+
33
+ - **`dotIndex`** (`number`): The index of the dot (step) for which to highlight affected nodes.
34
+ - **`isOperation`** (`boolean`, optional): If `true`, indicates that the step is an operation (e.g., adding to both sides), which affects how provenance is highlighted. Default: `false`.
35
+
36
+ **How it Works:**
37
+
38
+ 1. **Clear Existing Highlights**: First, any previously active highlights are cleared.
39
+ 2. **Identify Equations**: It determines the `currentEquation` (associated with `dotIndex`) and finds the `previousEquation` (the nearest visible equation before the current one).
40
+ 3. **Tree Differencing**: It uses `omdTreeDiff.findChangedNodes` to perform a robust comparison between the `previousEquation` and `currentEquation`. This algorithm identifies nodes that have been added, removed, or modified.
41
+ 4. **Direct Highlighting**: Nodes identified as directly changed by the diff algorithm are highlighted with a primary explanation color (`omdColor.explainColor`).
42
+ 5. **Provenance Highlighting**: For non-operation steps, the system traces the `provenance` (history) of the directly changed nodes back to their origins in the `previousEquation`. These originating nodes are then highlighted with a secondary provenance color (`omdColor.provenanceColor`), visually connecting the transformation.
43
+
44
+ ### `clearHighlights()`
45
+
46
+ Removes all active highlights managed by this class from the expression tree. It iterates through all `highlightedNodes` and calls `setExplainHighlight(false)` on them, then clears its internal `highlightedNodes` set.
47
+
48
+ ## Internal Methods
49
+
50
+ - **`_highlightNode(node)`**: Applies the standard explanation highlight color (`omdColor.explainColor`) to a single `omdNode` by calling its `setExplainHighlight(true)` method and adds the node to `highlightedNodes`.
51
+ - **`_findNearestVisibleEquationAbove(currentIndex)`**: Searches backward from `currentIndex` in the `stepVisualizer.steps` array to find the closest `omdEquationNode` that is currently visible.
52
+ - **`_highlightProvenanceNodes(changedNodes, previousEquation)`**: Iterates through `changedNodes` and their `provenance` chains to identify and highlight corresponding nodes in the `previousEquation` with `omdColor.provenanceColor`. It uses `rootNode.nodeMap` for efficient node lookup and a `visited` set to prevent redundant processing.
53
+ - **`_belongsToEquation(node, targetEquation)`**: Checks if a given `omdNode` is part of the subtree of a `targetEquation` by traversing up its parent chain.
54
+ - **`_highlightProvenanceNode(node)`**: Applies the secondary provenance highlighting style (`omdColor.provenanceColor`) to a single `omdNode` by calling its `setExplainHighlight(true, omdColor.provenanceColor)` method.
55
+
56
+ ## Example
57
+
58
+ This class is typically used internally by `omdStepVisualizer` when a step dot is clicked:
59
+
60
+ ```javascript
61
+ // Inside omdStepVisualizer's _handleDotClick method:
62
+ this.highlighting.highlightAffectedNodes(dotIndex, isOperation);
63
+
64
+ // Inside omdStepVisualizer's _clearActiveDot method:
65
+ this.highlighting.clearHighlights();
66
66
  ```