omdStepVisualizerHighlighting
omdStepVisualizerHighlighting
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.
Class Definition
export class omdStepVisualizerHighlighting
Constructor
new omdStepVisualizerHighlighting(stepVisualizer)
Creates a new omdStepVisualizerHighlighting instance.
stepVisualizer(omdStepVisualizer): The step visualizer instance this highlighting manager is associated with.
During construction, it initializes a Set to track highlightedNodes and sets educationalMode to true by default.
Public Properties
stepVisualizer(omdStepVisualizer): The associated step visualizer instance.highlightedNodes(Set<omdNode>): A set ofomdNodeinstances that are currently highlighted by this manager.educationalMode(boolean): Iftrue, enables highlighting of pedagogical simplifications (e.g., intermediate steps that might be skipped in a final solution). Default:true.
Public Methods
highlightAffectedNodes(dotIndex, isOperation = false)
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.
dotIndex(number): The index of the dot (step) for which to highlight affected nodes.isOperation(boolean, optional): Iftrue, indicates that the step is an operation (e.g., adding to both sides), which affects how provenance is highlighted. Default:false.
How it Works:
- Clear Existing Highlights: First, any previously active highlights are cleared.
- Identify Equations: It determines the
currentEquation(associated withdotIndex) and finds thepreviousEquation(the nearest visible equation before the current one). - Tree Differencing: It uses
omdTreeDiff.findChangedNodesto perform a robust comparison between thepreviousEquationandcurrentEquation. This algorithm identifies nodes that have been added, removed, or modified. - Direct Highlighting: Nodes identified as directly changed by the diff algorithm are highlighted with a primary explanation color (
omdColor.explainColor). - Provenance Highlighting: For non-operation steps, the system traces the
provenance(history) of the directly changed nodes back to their origins in thepreviousEquation. These originating nodes are then highlighted with a secondary provenance color (omdColor.provenanceColor), visually connecting the transformation.
clearHighlights()
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.
Internal Methods
_highlightNode(node): Applies the standard explanation highlight color (omdColor.explainColor) to a singleomdNodeby calling itssetExplainHighlight(true)method and adds the node tohighlightedNodes._findNearestVisibleEquationAbove(currentIndex): Searches backward fromcurrentIndexin thestepVisualizer.stepsarray to find the closestomdEquationNodethat is currently visible._highlightProvenanceNodes(changedNodes, previousEquation): Iterates throughchangedNodesand theirprovenancechains to identify and highlight corresponding nodes in thepreviousEquationwithomdColor.provenanceColor. It usesrootNode.nodeMapfor efficient node lookup and avisitedset to prevent redundant processing._belongsToEquation(node, targetEquation): Checks if a givenomdNodeis part of the subtree of atargetEquationby traversing up its parent chain._highlightProvenanceNode(node): Applies the secondary provenance highlighting style (omdColor.provenanceColor) to a singleomdNodeby calling itssetExplainHighlight(true, omdColor.provenanceColor)method.
Example
This class is typically used internally by omdStepVisualizer when a step dot is clicked:
// Inside omdStepVisualizer's _handleDotClick method:
this.highlighting.highlightAffectedNodes(dotIndex, isOperation);
// Inside omdStepVisualizer's _clearActiveDot method:
this.highlighting.clearHighlights();