@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.
Files changed (144) hide show
  1. package/README.md +138 -0
  2. package/canvas/core/canvasConfig.js +203 -0
  3. package/canvas/core/omdCanvas.js +475 -0
  4. package/canvas/drawing/segment.js +168 -0
  5. package/canvas/drawing/stroke.js +386 -0
  6. package/canvas/events/eventManager.js +435 -0
  7. package/canvas/events/pointerEventHandler.js +263 -0
  8. package/canvas/features/focusFrameManager.js +287 -0
  9. package/canvas/index.js +49 -0
  10. package/canvas/tools/eraserTool.js +322 -0
  11. package/canvas/tools/pencilTool.js +319 -0
  12. package/canvas/tools/selectTool.js +457 -0
  13. package/canvas/tools/tool.js +223 -0
  14. package/canvas/tools/toolManager.js +394 -0
  15. package/canvas/ui/cursor.js +438 -0
  16. package/canvas/ui/toolbar.js +304 -0
  17. package/canvas/utils/boundingBox.js +378 -0
  18. package/canvas/utils/mathUtils.js +259 -0
  19. package/docs/api/configuration-options.md +104 -0
  20. package/docs/api/eventManager.md +68 -0
  21. package/docs/api/focusFrameManager.md +150 -0
  22. package/docs/api/index.md +91 -0
  23. package/docs/api/main.md +58 -0
  24. package/docs/api/omdBinaryExpressionNode.md +227 -0
  25. package/docs/api/omdCanvas.md +142 -0
  26. package/docs/api/omdConfigManager.md +192 -0
  27. package/docs/api/omdConstantNode.md +117 -0
  28. package/docs/api/omdDisplay.md +121 -0
  29. package/docs/api/omdEquationNode.md +161 -0
  30. package/docs/api/omdEquationSequenceNode.md +301 -0
  31. package/docs/api/omdEquationStack.md +139 -0
  32. package/docs/api/omdFunctionNode.md +141 -0
  33. package/docs/api/omdGroupNode.md +182 -0
  34. package/docs/api/omdHelpers.md +96 -0
  35. package/docs/api/omdLeafNode.md +163 -0
  36. package/docs/api/omdNode.md +101 -0
  37. package/docs/api/omdOperationDisplayNode.md +139 -0
  38. package/docs/api/omdOperatorNode.md +127 -0
  39. package/docs/api/omdParenthesisNode.md +122 -0
  40. package/docs/api/omdPopup.md +117 -0
  41. package/docs/api/omdPowerNode.md +127 -0
  42. package/docs/api/omdRationalNode.md +128 -0
  43. package/docs/api/omdSequenceNode.md +128 -0
  44. package/docs/api/omdSimplification.md +110 -0
  45. package/docs/api/omdSqrtNode.md +79 -0
  46. package/docs/api/omdStepVisualizer.md +115 -0
  47. package/docs/api/omdStepVisualizerHighlighting.md +61 -0
  48. package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
  49. package/docs/api/omdStepVisualizerLayout.md +60 -0
  50. package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
  51. package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
  52. package/docs/api/omdToolbar.md +102 -0
  53. package/docs/api/omdTranscriptionService.md +76 -0
  54. package/docs/api/omdTreeDiff.md +134 -0
  55. package/docs/api/omdUnaryExpressionNode.md +174 -0
  56. package/docs/api/omdUtilities.md +70 -0
  57. package/docs/api/omdVariableNode.md +148 -0
  58. package/docs/api/selectTool.md +74 -0
  59. package/docs/api/simplificationEngine.md +98 -0
  60. package/docs/api/simplificationRules.md +77 -0
  61. package/docs/api/simplificationUtils.md +64 -0
  62. package/docs/api/transcribe.md +43 -0
  63. package/docs/api-reference.md +85 -0
  64. package/docs/index.html +454 -0
  65. package/docs/user-guide.md +9 -0
  66. package/index.js +67 -0
  67. package/omd/config/omdConfigManager.js +267 -0
  68. package/omd/core/index.js +150 -0
  69. package/omd/core/omdEquationStack.js +347 -0
  70. package/omd/core/omdUtilities.js +115 -0
  71. package/omd/display/omdDisplay.js +443 -0
  72. package/omd/display/omdToolbar.js +502 -0
  73. package/omd/nodes/omdBinaryExpressionNode.js +460 -0
  74. package/omd/nodes/omdConstantNode.js +142 -0
  75. package/omd/nodes/omdEquationNode.js +1223 -0
  76. package/omd/nodes/omdEquationSequenceNode.js +1273 -0
  77. package/omd/nodes/omdFunctionNode.js +352 -0
  78. package/omd/nodes/omdGroupNode.js +68 -0
  79. package/omd/nodes/omdLeafNode.js +77 -0
  80. package/omd/nodes/omdNode.js +557 -0
  81. package/omd/nodes/omdOperationDisplayNode.js +322 -0
  82. package/omd/nodes/omdOperatorNode.js +109 -0
  83. package/omd/nodes/omdParenthesisNode.js +293 -0
  84. package/omd/nodes/omdPowerNode.js +236 -0
  85. package/omd/nodes/omdRationalNode.js +295 -0
  86. package/omd/nodes/omdSqrtNode.js +308 -0
  87. package/omd/nodes/omdUnaryExpressionNode.js +178 -0
  88. package/omd/nodes/omdVariableNode.js +123 -0
  89. package/omd/simplification/omdSimplification.js +171 -0
  90. package/omd/simplification/omdSimplificationEngine.js +886 -0
  91. package/omd/simplification/package.json +6 -0
  92. package/omd/simplification/rules/binaryRules.js +1037 -0
  93. package/omd/simplification/rules/functionRules.js +111 -0
  94. package/omd/simplification/rules/index.js +48 -0
  95. package/omd/simplification/rules/parenthesisRules.js +19 -0
  96. package/omd/simplification/rules/powerRules.js +143 -0
  97. package/omd/simplification/rules/rationalRules.js +475 -0
  98. package/omd/simplification/rules/sqrtRules.js +48 -0
  99. package/omd/simplification/rules/unaryRules.js +37 -0
  100. package/omd/simplification/simplificationRules.js +32 -0
  101. package/omd/simplification/simplificationUtils.js +1056 -0
  102. package/omd/step-visualizer/omdStepVisualizer.js +597 -0
  103. package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
  104. package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
  105. package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
  106. package/omd/utils/omdNodeOverlay.js +638 -0
  107. package/omd/utils/omdPopup.js +1084 -0
  108. package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
  109. package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
  110. package/omd/utils/omdTranscriptionService.js +125 -0
  111. package/omd/utils/omdTreeDiff.js +734 -0
  112. package/package.json +46 -0
  113. package/src/index.js +62 -0
  114. package/src/json-schemas.md +109 -0
  115. package/src/omd-json-samples.js +115 -0
  116. package/src/omd.js +109 -0
  117. package/src/omdApp.js +391 -0
  118. package/src/omdAppCanvas.js +336 -0
  119. package/src/omdBalanceHanger.js +172 -0
  120. package/src/omdColor.js +13 -0
  121. package/src/omdCoordinatePlane.js +467 -0
  122. package/src/omdEquation.js +125 -0
  123. package/src/omdExpression.js +104 -0
  124. package/src/omdFunction.js +113 -0
  125. package/src/omdMetaExpression.js +287 -0
  126. package/src/omdNaturalExpression.js +564 -0
  127. package/src/omdNode.js +384 -0
  128. package/src/omdNumber.js +53 -0
  129. package/src/omdNumberLine.js +107 -0
  130. package/src/omdNumberTile.js +119 -0
  131. package/src/omdOperator.js +73 -0
  132. package/src/omdPowerExpression.js +92 -0
  133. package/src/omdProblem.js +55 -0
  134. package/src/omdRatioChart.js +232 -0
  135. package/src/omdRationalExpression.js +115 -0
  136. package/src/omdSampleData.js +215 -0
  137. package/src/omdShapes.js +476 -0
  138. package/src/omdSpinner.js +148 -0
  139. package/src/omdString.js +39 -0
  140. package/src/omdTable.js +369 -0
  141. package/src/omdTapeDiagram.js +245 -0
  142. package/src/omdTerm.js +92 -0
  143. package/src/omdTileEquation.js +349 -0
  144. package/src/omdVariable.js +51 -0
@@ -0,0 +1,115 @@
1
+
2
+ # omdStepVisualizer
3
+
4
+ Visualizes a sequence of mathematical steps (typically equations) and provides interactive explanations for how one step transforms into the next. 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.
5
+
6
+ ## Import
7
+
8
+ ```js
9
+ import { omdStepVisualizer } from './omd/step-visualizer/omdStepVisualizer.js';
10
+ ```
11
+
12
+ ## Class Hierarchy
13
+
14
+ ```
15
+ omdNode
16
+ └─ omdEquationSequenceNode
17
+ └─ omdStepVisualizer
18
+ ```
19
+
20
+ See: [`omdEquationSequenceNode`](./omdEquationSequenceNode.md) for base sequence functionality.
21
+
22
+ ## Constructor
23
+
24
+ ```js
25
+ new omdStepVisualizer(steps)
26
+ ```
27
+
28
+ - `steps` (`Array<omdNode>`): An array of nodes (usually `omdEquationNode`) representing the steps in the sequence.
29
+
30
+ ## Key Features
31
+
32
+ - **Interactive Dots:** Each step is represented by a clickable dot. Clicking a dot reveals a text box explaining the transformation from the previous step.
33
+ - **Highlighting:** When a dot is clicked, the parts of the equations that were changed or involved in the transformation are highlighted.
34
+ - **Automatic Layout:** The visualizer automatically handles the layout of the steps, the visual tracker, and the explanation text boxes.
35
+ - **Simplification Analysis:** Analyzes the sequence to determine the mathematical justification for each step, whether it's a simplification rule (e.g., "Combine like terms") or a direct operation (e.g., "Add 3 to both sides").
36
+
37
+ ## Properties
38
+
39
+ In addition to properties from `omdEquationSequenceNode`:
40
+
41
+ - `activeDotIndex` (`number`): The index of the currently active (clicked) dot. `-1` if none.
42
+ - `dotsClickable` (`boolean`): Controls whether the step dots can be clicked to show explanations. Defaults to `true`.
43
+ - `highlighting` ([`omdStepVisualizerHighlighting`](./omdStepVisualizerHighlighting.md)): The manager responsible for all highlighting logic.
44
+ - `textBoxManager` ([`omdStepVisualizerTextBoxes`](./omdStepVisualizerTextBoxes.md)): The manager responsible for creating, positioning, and removing the explanation text boxes.
45
+ - `layoutManager` ([`omdStepVisualizerLayout`](./omdStepVisualizerLayout.md)): The manager responsible for layout and z-ordering of all visual elements.
46
+ - `stepDots`, `stepLines` (`Array`): Internal arrays holding the dot and line objects for the visual tracker. Not part of the public API, but useful for advanced customization.
47
+ - `steps` (`Array<omdNode>`): The sequence of steps (usually `omdEquationNode`). Only `omdEquationNode` steps are visualized with dots/lines; other node types are ignored for the visual tracker.
48
+
49
+ ## Methods
50
+
51
+ This class inherits all methods from `omdEquationSequenceNode`. Overridden and new methods include:
52
+
53
+ ### `addStep(step, options)`
54
+ Adds a new step to the sequence and creates its corresponding visual dot and connecting line.
55
+
56
+ ```js
57
+ const newStep = omdEquationNode.fromString('x = 5');
58
+ visualizer.addStep(newStep);
59
+ ```
60
+
61
+ ### `getNodeStepNumber(nodeId)`
62
+ Gets the step number (index) associated with a given node ID.
63
+
64
+ ```js
65
+ const stepIndex = visualizer.getNodeStepNumber('some-node-id');
66
+ ```
67
+ - **Returns:** `number` (the step number, or `undefined` if the node is not found within a step)
68
+
69
+ ### `setDotsClickable(enabled)`
70
+ Enables or disables the ability to click on the step dots.
71
+
72
+ ```js
73
+ visualizer.setDotsClickable(false); // Explanations are now disabled
74
+ ```
75
+
76
+ ### `getStepTextBoxes()`
77
+ Retrieves the array of currently visible text box components.
78
+ - **Returns:** `Array` (the active text box instances)
79
+
80
+ ## Internal Helpers
81
+
82
+ Contains several private methods (`_handleDotClick`, `_getSimplificationDataForDot`, etc.) that manage the internal logic of handling user interaction, analyzing the step sequence, and coordinating the display of highlights and text boxes. These are not intended for external use but are crucial to the component's functionality.
83
+
84
+ ## Supporting Classes
85
+
86
+ Relies on three main helper classes to organize its complex logic:
87
+ - **`omdStepVisualizerLayout`**: Manages the positioning of all visual elements, including the sequence itself, the dots, the lines, and the text boxes.
88
+ - **`omdStepVisualizerTextBoxes`**: Handles the lifecycle of the explanation text boxes that appear when a dot is clicked.
89
+ - **`omdStepVisualizerHighlighting`**: Manages the logic for highlighting nodes within the equations to show what has changed between steps.
90
+
91
+ ## Example
92
+
93
+ ```js
94
+ import { omdStepVisualizer } from './omd/step-visualizer/omdStepVisualizer.js';
95
+ import { omdEquationNode } from './omd/nodes/omdEquationNode.js';
96
+ import { omdDisplay } from './omd/display/omdDisplay.js';
97
+
98
+ // 1. Define the steps of a solution (must be omdEquationNode for dots to appear)
99
+ const steps = [
100
+ omdEquationNode.fromString('2x + 4 = 10'),
101
+ omdEquationNode.fromString('2x = 6'),
102
+ omdEquationNode.fromString('x = 3')
103
+ ];
104
+
105
+ // 2. Create the visualizer
106
+ const visualizer = new omdStepVisualizer(steps);
107
+
108
+ // 3. Add it to a display container
109
+ const display = new omdDisplay(document.getElementById('container'));
110
+ display.render(visualizer);
111
+
112
+ // Now the steps will be displayed with interactive dots on the right.
113
+ // Only omdEquationNode steps are visualized with dots/lines.
114
+ // Clicking the dot next to "2x = 6" will explain that 4 was subtracted from both sides.
115
+ ```
@@ -0,0 +1,61 @@
1
+
2
+ # omdStepVisualizerHighlighting
3
+
4
+ Manages the highlighting of nodes within mathematical expressions displayed by the `omdStepVisualizer`. Uses a robust tree differencing algorithm to identify changes between consecutive steps and highlights affected nodes, providing visual feedback on transformations.
5
+
6
+ ## Import
7
+
8
+ ```js
9
+ import { omdStepVisualizerHighlighting } from './omd/step-visualizer/omdStepVisualizerHighlighting.js';
10
+ ```
11
+
12
+ ## Constructor
13
+
14
+ ```js
15
+ new omdStepVisualizerHighlighting(stepVisualizer)
16
+ ```
17
+
18
+ - `stepVisualizer` (`omdStepVisualizer`): The step visualizer instance this highlighting manager is associated with.
19
+
20
+ ## Properties
21
+
22
+ - `stepVisualizer` (`omdStepVisualizer`): The associated step visualizer instance.
23
+ - `highlightedNodes` (`Set<omdNode>`): Set of currently highlighted nodes.
24
+ - `educationalMode` (`boolean`): If `true`, enables highlighting of pedagogical simplifications. Default: `true`.
25
+
26
+ ## Methods
27
+
28
+ ### `highlightAffectedNodes(dotIndex, isOperation = false)`
29
+ Main method to trigger highlighting. Compares the equation at `dotIndex` with the previous visible equation to identify changes and applies highlighting.
30
+ - `dotIndex` (`number`): The index of the dot (step) for which to highlight affected nodes.
31
+ - `isOperation` (`boolean`): If `true`, indicates the step is an operation (e.g., adding to both sides), which affects how provenance is highlighted.
32
+
33
+ ### `clearHighlights()`
34
+ Removes all active highlights from the expression tree.
35
+
36
+ ### Private/Internal Methods
37
+
38
+ - `_highlightNode(node)`: Applies the standard explanation highlight color to a single node.
39
+ - `_findNearestVisibleEquationAbove(currentIndex)`: Finds the closest visible `omdEquationNode` preceding the given index.
40
+ - `_highlightProvenanceNodes(changedNodes, previousEquation)`: Highlights nodes in the previous equation that are linked by provenance to the `changedNodes` in the current equation.
41
+ - `_belongsToEquation(node, targetEquation)`: Checks if a given node is part of a specific equation's subtree.
42
+ - `_highlightProvenanceNode(node)`: Applies a secondary highlighting style to nodes identified through provenance.
43
+
44
+ ## How it Works
45
+
46
+ 1. **Tree Differencing:** When `highlightAffectedNodes` is called, it uses `omdTreeDiff.findChangedNodes` to compare the current equation and the previous visible equation in the sequence.
47
+ 2. **Change Identification:** `omdTreeDiff` identifies nodes that have been added, removed, or modified between the two steps.
48
+ 3. **Direct Highlighting:** Nodes identified as directly changed are highlighted with a primary color.
49
+ 4. **Provenance Highlighting:** For non-operation steps, the system traces the `provenance` (history) of the changed nodes back to their origins in the previous equation. These originating nodes are then highlighted with a secondary color, visually connecting the transformation.
50
+
51
+ ## Example
52
+
53
+ This class is typically used internally by `omdStepVisualizer` when a step dot is clicked:
54
+
55
+ ```js
56
+ // Inside omdStepVisualizer's _handleDotClick method:
57
+ this.highlighting.highlightAffectedNodes(dotIndex, isOperation);
58
+
59
+ // Inside omdStepVisualizer's _clearActiveDot method:
60
+ this.highlighting.clearHighlights();
61
+ ```
@@ -0,0 +1,129 @@
1
+ # omdStepVisualizerInteractiveSteps
2
+
3
+ This class creates and manages the interactive text boxes that display detailed explanations for simplification steps within the `omdStepVisualizer`. It formats the messages, handles styling, and sets up hover and click interactions.
4
+
5
+ ## Class: `omdStepVisualizerInteractiveSteps`
6
+
7
+ ```javascript
8
+ import { omdStepVisualizerInteractiveSteps } from './omd/utils/omdStepVisualizerInteractiveSteps.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdStepVisualizerInteractiveSteps(stepVisualizer, simplificationData)
15
+ ```
16
+
17
+ **Parameters:**
18
+ - `stepVisualizer` {omdStepVisualizer} - A reference to the `omdStepVisualizer` instance.
19
+ - `simplificationData` {Object} - An object containing the simplification details for the step, typically including `message`, `rawMessages`, and `ruleNames`.
20
+
21
+ ### Properties
22
+
23
+ #### `stepVisualizer`
24
+ - **Type:** `omdStepVisualizer`
25
+ - **Description:** A reference to the associated `omdStepVisualizer` instance.
26
+
27
+ #### `simplificationData`
28
+ - **Type:** `Object`
29
+ - **Description:** The raw data describing the simplification step.
30
+
31
+ #### `messages`
32
+ - **Type:** `Array<string>`
33
+ - **Description:** Cleaned and extracted messages for each sub-step.
34
+
35
+ #### `ruleNames`
36
+ - **Type:** `Array<string>`
37
+ - **Description:** Extracted names of the simplification rules applied.
38
+
39
+ #### `stepElements`
40
+ - **Type:** `Array<jsvgTextBox>`
41
+ - **Description:** An array of `jsvgTextBox` instances, each representing a line of explanation.
42
+
43
+ #### `layoutGroup`
44
+ - **Type:** `jsvgLayoutGroup`
45
+ - **Description:** The main `jsvgLayoutGroup` that contains all the visual elements of the interactive steps, including the background and individual step messages.
46
+
47
+ ### Methods
48
+
49
+ #### `setOnStepHover(callback)`
50
+
51
+ Sets a callback function to be executed when the user hovers over a step explanation.
52
+
53
+ - **Parameters:**
54
+ - `callback` {Function} - A function that receives `(stepIndex, message, isEntering)` as arguments.
55
+
56
+ ---
57
+
58
+ #### `setOnStepClick(callback)`
59
+
60
+ Sets a callback function to be executed when the user clicks on a step explanation.
61
+
62
+ - **Parameters:**
63
+ - `callback` {Function} - A function that receives `(stepIndex, message)` as arguments.
64
+
65
+ ---
66
+
67
+ #### `getLayoutGroup()`
68
+
69
+ Returns the main `jsvgLayoutGroup` containing all the interactive step elements. This group should be added to the parent container (e.g., `omdStepVisualizer`'s `visualContainer`).
70
+
71
+ - **Returns:** `jsvgLayoutGroup`
72
+
73
+ ---
74
+
75
+ #### `setPosition(x, y)`
76
+
77
+ Sets the position of the entire interactive step group.
78
+
79
+ - **Parameters:**
80
+ - `x` {number} - The X-coordinate.
81
+ - `y` {number} - The Y-coordinate.
82
+
83
+ ---
84
+
85
+ #### `getDimensions()`
86
+
87
+ Returns the calculated width and height of the interactive step group.
88
+
89
+ - **Returns:** {Object} An object with `width` and `height` properties.
90
+
91
+ ---
92
+
93
+ #### `destroy()`
94
+
95
+ Cleans up the component by removing all its children and clearing references.
96
+
97
+ ### Private Methods
98
+
99
+ - `_extractMessages(data)`: Extracts and cleans messages from the `simplificationData`.
100
+ - `_extractRuleNames(data)`: Extracts rule names from the `simplificationData`.
101
+ - `setupLayoutGroup()`: Initializes the main `layoutGroup` and its background rectangle.
102
+ - `createStepElements()`: Creates individual `jsvgTextBox` elements for each message.
103
+ - `createSingleStepElement(message, index)`: Creates elements for a single step explanation.
104
+ - `createMultipleStepElements()`: Creates elements for multiple step explanations, including a header.
105
+ - `createHeaderBox(headerText)`: Creates a styled header `jsvgTextBox`.
106
+ - `createStepTextBox(message, index, isMultiple)`: Creates an individual styled `jsvgTextBox` for a step message.
107
+ - `formatStepContent(message, index, isMultiple)`: Formats the message content with styling and optional step numbers.
108
+ - `applyStepStyling(stepBox, content, isMultiple)`: Applies CSS styling to the `jsvgTextBox`'s underlying DOM element.
109
+ - `setupStepInteractions(stepBox)`: Sets up `mouseenter`, `mouseleave`, and `click` event listeners for a step box.
110
+ - `calculateStepHeight(message)`: Dynamically calculates the required height for a step box based on its content.
111
+ - `updateBackgroundSize()`: Adjusts the size of the background rectangle to fit the content.
112
+ - `isOperationMessage(message)`: Checks if a message describes an operation (e.g., "Added X to both sides").
113
+ - `extractOperationAction(message)`: Extracts the action (e.g., "Added") from an operation message.
114
+ - `extractOperationValue(message)`: Extracts the value (e.g., "3") from an operation message.
115
+ - `extractOperationValueNode(message)`: Attempts to extract the `omdNode` representing the value from an operation message.
116
+
117
+ ### How it Works
118
+
119
+ This class takes simplification data and renders it as a series of interactive text boxes. Each box represents a sub-step or a part of the explanation. It dynamically calculates sizes and positions to ensure the text boxes are readable and visually appealing. Hover and click events on these boxes can be used to trigger further actions, such as highlighting specific nodes in the main equation display.
120
+
121
+ ### Example
122
+
123
+ This class is typically used internally by `omdStepVisualizerTextBoxes`.
124
+
125
+ ```javascript
126
+ // Example of internal usage within omdStepVisualizerTextBoxes:
127
+ // const interactiveSteps = new omdStepVisualizerInteractiveSteps(this.stepVisualizer, simplificationData);
128
+ // this.stepVisualizer.visualContainer.addChild(interactiveSteps.getLayoutGroup());
129
+ ```
@@ -0,0 +1,60 @@
1
+
2
+ # omdStepVisualizerLayout
3
+
4
+ Manages the visual layout, positioning, and visibility of elements within the `omdStepVisualizer`. Ensures that step dots, connecting lines, and associated text boxes are correctly positioned relative to the mathematical equations.
5
+
6
+ ## Import
7
+
8
+ ```js
9
+ import { omdStepVisualizerLayout } from './omd/step-visualizer/omdStepVisualizerLayout.js';
10
+ ```
11
+
12
+ ## Constructor
13
+
14
+ ```js
15
+ new omdStepVisualizerLayout(stepVisualizer)
16
+ ```
17
+
18
+ - `stepVisualizer` (`omdStepVisualizer`): Reference to the step visualizer instance this layout manager will control.
19
+
20
+ ## Properties
21
+
22
+ - `stepVisualizer` (`omdStepVisualizer`): The associated step visualizer instance.
23
+
24
+ ## Methods
25
+
26
+ ### `updateVisualLayout()`
27
+ Calculates and applies the positions of all visual elements (dots, lines, text boxes) relative to the mathematical equations in the sequence. Ensures proper alignment and spacing.
28
+
29
+ ### `findDotIndexForEquation(equation)`
30
+ Finds the index of the step dot associated with a given `omdEquationNode`.
31
+ - `equation` (`omdEquationNode`): The equation node to find the corresponding dot for.
32
+ - **Returns:** `number` (index of the dot, or `-1` if not found)
33
+
34
+ ### `updateVisualZOrder()`
35
+ Manages the z-order (stacking order) of the visual elements to ensure they are rendered correctly (e.g., lines behind dots, text boxes on top).
36
+
37
+ ### `updateAllLinePositions()`
38
+ Recalculates and updates the start and end points of all connecting lines between the step dots.
39
+
40
+ ### `updateVisualVisibility()`
41
+ Adjusts the visibility of the step dots and lines based on the visibility of their corresponding equations. Re-creates lines only between currently visible dots.
42
+
43
+ ### `updateDotClickability(dot)`
44
+ Enables or disables the click functionality for a specific step dot, changing its cursor style accordingly.
45
+ - `dot` (`jsvgEllipse`): The `jsvgEllipse` element representing the dot.
46
+
47
+ ## How it Works
48
+
49
+ This class works in conjunction with `omdStepVisualizer` to dynamically arrange the visual components. When the sequence of equations changes (e.g., steps are added or hidden), `omdStepVisualizer` calls methods on this layout manager to re-calculate and apply the new visual arrangement.
50
+
51
+ ## Example
52
+
53
+ This class is primarily used internally by `omdStepVisualizer`:
54
+
55
+ ```js
56
+ // Inside omdStepVisualizer's updateLayout method:
57
+ this.layoutManager.updateVisualLayout();
58
+ this.layoutManager.updateVisualVisibility();
59
+ this.layoutManager.updateAllLinePositions();
60
+ ```
@@ -0,0 +1,140 @@
1
+ # omdStepVisualizerNodeUtils
2
+
3
+ This module provides a collection of utility functions specifically designed to assist with node operations and analysis within the context of step visualizations, particularly for identifying and extracting information from `omdNode` instances.
4
+
5
+ ## Class: `omdStepVisualizerNodeUtils`
6
+
7
+ This class is not meant to be instantiated. All its methods are static.
8
+
9
+ ### Static Methods
10
+
11
+ #### `isLeafNode(node)`
12
+
13
+ Checks if a given `omdNode` is a leaf node (e.g., `omdConstantNode`, `omdVariableNode`, `omdOperatorNode`).
14
+
15
+ - **Parameters:**
16
+ - `node` {omdNode} - The node to check.
17
+ - **Returns:** {boolean} `true` if the node is a leaf node, `false` otherwise.
18
+
19
+ ---
20
+
21
+ #### `isBinaryNode(node)`
22
+
23
+ Checks if a given `omdNode` is an `omdBinaryExpressionNode` and has both `left` and `right` children.
24
+
25
+ - **Parameters:**
26
+ - `node` {omdNode} - The node to check.
27
+ - **Returns:** {boolean} `true` if it's a binary node, `false` otherwise.
28
+
29
+ ---
30
+
31
+ #### `isUnaryNode(node)`
32
+
33
+ Checks if a given `omdNode` is an `omdUnaryExpressionNode` and has an `argument` child.
34
+
35
+ - **Parameters:**
36
+ - `node` {omdNode} - The node to check.
37
+ - **Returns:** {boolean} `true` if it's a unary node, `false` otherwise.
38
+
39
+ ---
40
+
41
+ #### `hasExpression(node)`
42
+
43
+ Checks if a given `omdNode` has an `expression` property (common in nodes like `omdParenthesisNode`).
44
+
45
+ - **Parameters:**
46
+ - `node` {omdNode} - The node to check.
47
+ - **Returns:** {boolean} `true` if it has an expression property, `false` otherwise.
48
+
49
+ ---
50
+
51
+ #### `getNodeValue(node)`
52
+
53
+ Attempts to retrieve a string representation of the node's value. This is particularly useful for leaf nodes (constants, variables) but can also provide a string for more complex nodes.
54
+
55
+ - **Parameters:**
56
+ - `node` {omdNode} - The node to get the value from.
57
+ - **Returns:** {string} The string representation of the node's value.
58
+
59
+ ---
60
+
61
+ #### `findLeafNodes(node)`
62
+
63
+ Recursively finds all leaf nodes within the subtree rooted at the given node.
64
+
65
+ - **Parameters:**
66
+ - `node` {omdNode} - The root node to start the search from.
67
+ - **Returns:** {Array<omdNode>} An array of `omdNode` instances that are leaf nodes.
68
+
69
+ ---
70
+
71
+ #### `findVariableNodes(node)`
72
+
73
+ Finds all `omdVariableNode` instances within the subtree rooted at the given node.
74
+
75
+ - **Parameters:**
76
+ - `node` {omdNode} - The root node to start the search from.
77
+ - **Returns:** {Array<omdVariableNode>} An array of `omdVariableNode` instances.
78
+
79
+ ---
80
+
81
+ #### `findConstantNodes(node)`
82
+
83
+ Finds all `omdConstantNode` instances within the subtree rooted at the given node.
84
+
85
+ - **Parameters:**
86
+ - `node` {omdNode} - The root node to start the search from.
87
+ - **Returns:** {Array<omdConstantNode>} An array of `omdConstantNode` instances.
88
+
89
+ ---
90
+
91
+ #### `findLeafNodesWithValue(node, value)`
92
+
93
+ Finds leaf nodes within a subtree that match a specific string `value`. It performs exact matches first, then numeric matches for constants, and finally partial string matches.
94
+
95
+ - **Parameters:**
96
+ - `node` {omdNode} - The root node to start the search from.
97
+ - `value` {string} - The value to search for.
98
+ - **Returns:** {Array<omdNode>} An array of matching leaf nodes.
99
+
100
+ ---
101
+
102
+ #### `findAllNodes(node)`
103
+
104
+ Recursively finds all `omdNode` instances (including non-leaf nodes) within the subtree rooted at the given node.
105
+
106
+ - **Parameters:**
107
+ - `node` {omdNode} - The root node to start the search from.
108
+ - **Returns:** {Array<omdNode>} An array of all `omdNode` instances in the tree.
109
+
110
+ ---
111
+
112
+ #### `findRightmostNodeWithValue(node, value)`
113
+
114
+ Finds the rightmost leaf node within a subtree that matches a specific `value`. It has special handling for nodes that are the right operand of a subtraction.
115
+
116
+ - **Parameters:**
117
+ - `node` {omdNode} - The root node to start the search from.
118
+ - `value` {string} - The value to search for.
119
+ - **Returns:** {omdNode | null} The rightmost matching leaf node, or `null` if not found.
120
+
121
+ ### Example
122
+
123
+ ```javascript
124
+ import { omdStepVisualizerNodeUtils } from './omd/utils/omdStepVisualizerNodeUtils.js';
125
+ import { omdEquationNode } from './omd/nodes/omdEquationNode.js';
126
+
127
+ const equation = omdEquationNode.fromString('2x + 3 = 7');
128
+
129
+ // Find all leaf nodes
130
+ const leafNodes = omdStepVisualizerNodeUtils.findLeafNodes(equation);
131
+ console.log(leafNodes.map(node => node.toString())); // Output: ['2', 'x', '3', '7']
132
+
133
+ // Find all constant nodes
134
+ const constantNodes = omdStepVisualizerNodeUtils.findConstantNodes(equation);
135
+ console.log(constantNodes.map(node => node.getValue())); // Output: [2, 3, 7]
136
+
137
+ // Get the value of a specific node
138
+ const firstLeaf = leafNodes[0];
139
+ console.log(omdStepVisualizerNodeUtils.getNodeValue(firstLeaf)); // Output: '2'
140
+ ```
@@ -0,0 +1,68 @@
1
+
2
+ # omdStepVisualizerTextBoxes
3
+
4
+ Manages the interactive text boxes that appear when a step dot is clicked in the `omdStepVisualizer`. Handles creation, positioning, and removal of these popups, and integrates with highlighting and layout managers for a cohesive user experience.
5
+
6
+ ## Import
7
+
8
+ ```js
9
+ import { omdStepVisualizerTextBoxes } from './omd/step-visualizer/omdStepVisualizerTextBoxes.js';
10
+ ```
11
+
12
+ ## Constructor
13
+
14
+ ```js
15
+ new omdStepVisualizerTextBoxes(stepVisualizer, highlighting)
16
+ ```
17
+
18
+ - `stepVisualizer` (`omdStepVisualizer`): Reference to the step visualizer instance.
19
+ - `highlighting` (`omdStepVisualizerHighlighting`): Reference to the highlighting manager.
20
+
21
+ ## Properties
22
+
23
+ - `stepVisualizer` (`omdStepVisualizer`): The associated step visualizer instance.
24
+ - `highlighting` (`omdStepVisualizerHighlighting`): The associated highlighting instance.
25
+ - `stepTextBoxes` (`Array<Object>`): Array of active text box objects, each with `dotIndex`, `interactiveSteps`, and `layoutGroup`.
26
+
27
+ ## Methods
28
+
29
+ ### `createTextBoxForDot(dotIndex)`
30
+ Creates and displays an interactive text box for the specified step dot. Retrieves simplification data and positions the text box appropriately.
31
+ - `dotIndex` (`number`): The index of the dot for which to create the text box.
32
+
33
+ ### `removeTextBoxForDot(dotIndex)`
34
+ Removes the text box associated with the specified step dot.
35
+ - `dotIndex` (`number`): The index of the dot whose text box should be removed.
36
+
37
+ ### `clearAllTextBoxes()`
38
+ Removes all active text boxes from the visualizer.
39
+
40
+ ### `getStepTextBoxes()`
41
+ Returns an array of all currently active text box objects.
42
+ - **Returns:** `Array<Object>`
43
+
44
+ ### Private/Internal Methods
45
+
46
+ - `_createInteractiveStepsForDot(dotIndex, targetDot, simplificationData)`: Creates and configures the `omdStepVisualizerInteractiveSteps` instance for a dot.
47
+ - `_findDotAboveForPositioning(dotIndex)`: Determines the appropriate dot to position the text box relative to, ensuring correct placement even if some steps are hidden.
48
+ - `_getSimplificationDataForDot(dotIndex)`: Retrieves simplification data for a given dot from the step visualizer.
49
+
50
+ ## How it Works
51
+
52
+ When a user clicks a step dot in the `omdStepVisualizer`, this class:
53
+ 1. **Fetches Data:** Requests simplification data from the step visualizer for the clicked step.
54
+ 2. **Creates UI:** Instantiates an `omdStepVisualizerInteractiveSteps` component, which renders the explanation text and interactive elements.
55
+ 3. **Positions:** Calculates the optimal position for the text box, usually to the right of the step dot, and ensures it doesn't overlap with other elements.
56
+ 4. **Highlighting Integration:** Works with `omdStepVisualizerHighlighting` to trigger visual feedback when the text box is displayed or interacted with.
57
+
58
+ ## Example
59
+
60
+ This class is primarily used internally by `omdStepVisualizer`:
61
+
62
+ ```js
63
+ // Inside omdStepVisualizer's _handleDotClick method:
64
+ this.textBoxManager.createTextBoxForDot(dotIndex);
65
+
66
+ // Inside omdStepVisualizer's _clearActiveDot method:
67
+ this.textBoxManager.removeTextBoxForDot(this.activeDotIndex);
68
+ ```
@@ -0,0 +1,102 @@
1
+
2
+ # omdToolbar
3
+
4
+ Provides a visual toolbar UI for applying mathematical operations and functions to an `omdEquationSequenceNode` in the OMD system. The toolbar is rendered as an SVG group and supports operations like add, subtract, multiply, divide, and function application (e.g., sqrt, cos, etc.).
5
+
6
+ ## Import
7
+
8
+ ```js
9
+ import { omdToolbar } from './omd/omdToolbar.js';
10
+ ```
11
+
12
+ ## Constructor
13
+
14
+ ```js
15
+ new omdToolbar(parentContainer, sequence, options)
16
+ ```
17
+
18
+ - `parentContainer` (`jsvgGroup`): The parent SVG group where the toolbar will be rendered.
19
+ - `sequence` (`omdEquationSequenceNode`): The sequence node to which operations will be applied.
20
+ - `options` (`object`, optional): Toolbar configuration options:
21
+ - `height` (`number`): Toolbar height. Default: `60`.
22
+ - `padding` (`number`): Padding around elements. Default: `6`.
23
+ - `spacing` (`number`): Spacing between elements. Default: `8`.
24
+ - `borderRadius` (`number`): Corner radius for background. Default: `30`.
25
+ - `fontFamily` (`string`): Font family. Default: `'Albert Sans', sans-serif`.
26
+ - `fontWeight` (`string`): Font weight. Default: `'500'`.
27
+ - `colors` (`object`): Color scheme:
28
+ - `background` (`string`): Toolbar background. Default: `omdColor.mediumGray`.
29
+ - `button` (`string`): Button background. Default: `'white'`.
30
+ - `popup` (`string`): Popup menu background. Default: `omdColor.lightGray`.
31
+ - `buttonSize` (`number`): Button size. Default: `48`.
32
+ - `checkMarkSize` (`number`): Checkmark SVG size. Default: `24`.
33
+ - `mainFontSize` (`number`): Main button font size. Default: `32`.
34
+ - `inputFontSize` (`number`): Input text font size. Default: `28`.
35
+ - `menuFontSize` (`number`): Menu item font size. Default: `24`.
36
+ - `inputWidth` (`number`): Input button width. Default: `120`.
37
+ - `x`, `y` (`number`): Optional position of the toolbar in the parent container.
38
+
39
+ ## Properties
40
+
41
+ - `parentContainer` (`jsvgGroup`): The SVG group where the toolbar is rendered.
42
+ - `sequence` (`omdEquationSequenceNode`): The sequence node the toolbar interacts with.
43
+ - `config` (`object`): Merged configuration options.
44
+ - `state` (`object`): Internal state, including `activePopup`, `selectedOperation`, and `inputValue`.
45
+ - `elements` (`object`): References to the various `jsvg` elements in the toolbar UI.
46
+
47
+ ## Methods
48
+
49
+ ### `setInputText(text)`
50
+ Sets the text displayed in the middle input button.
51
+ - `text` (`string`): The text to display.
52
+
53
+ ### Private/Internal Methods
54
+
55
+ - `_render()`: Renders the toolbar UI components.
56
+ - `_togglePopup(popupType)`: Toggles a popup menu (operations or input).
57
+ - `_renderPopup(contentFactory, anchorButton)`: Creates and positions a popup group.
58
+ - `_renderOperationsMenu()`: Renders the operations menu popup (`f`, `÷`, `×`, `–`, `+`).
59
+ - `_renderFunctionMenu()`: Renders the function selection menu popup (`sqrt`, `cos`, etc.).
60
+ - `_renderDigitGrid()`: Renders the digit grid (number pad) popup.
61
+ - `_handleFunctionClick(func)`: Handles function menu button clicks.
62
+ - `_handleDigitClick(digit)`: Handles digit grid button clicks.
63
+ - `_selectOperation(operation)`: Handles operation selection from the menu.
64
+ - `_applyOperation()`: Applies the selected operation and value to the sequence.
65
+ - `_createButton(config)`: Creates a button component.
66
+ - `_updateApplyButtonState()`: Updates the enabled/disabled state of the apply button.
67
+ - `_updateToolbarLayout()`: Updates the positions of toolbar elements.
68
+
69
+ ## Example
70
+
71
+ ```js
72
+ import { omdToolbar } from './omd/omdToolbar.js';
73
+ import { omdEquationSequenceNode } from './omd/nodes/omdEquationSequenceNode.js';
74
+ import { omdEquationNode } from './omd/nodes/omdEquationNode.js';
75
+
76
+ // Create an SVG container (e.g., from jsvgContainer)
77
+ const svgContainer = new jsvgContainer();
78
+ document.body.appendChild(svgContainer.svgObject);
79
+
80
+ // Create an initial sequence
81
+ const initialEquation = omdEquationNode.fromString('2x + 5 = 15');
82
+ const sequence = new omdEquationSequenceNode([initialEquation]);
83
+
84
+ // Create the toolbar and add it to the SVG container
85
+ const toolbar = new omdToolbar(svgContainer, sequence, {
86
+ x: 50, // Position the toolbar
87
+ y: 50
88
+ });
89
+
90
+ // Interact with the toolbar to apply operations to the sequence.
91
+ // For example, click the '-' button and enter '5' to subtract 5 from both sides.
92
+ ```
93
+
94
+ ## Notes
95
+
96
+ - The toolbar can be styled via CSS for custom appearance.
97
+ - Supports dynamic updates (e.g., adding/removing tools or buttons at runtime).
98
+
99
+ ## See Also
100
+
101
+ - [`omdEquationSequenceNode`](./omdEquationSequenceNode.md)
102
+ - [`omdEquationNode`](./omdEquationNode.md)