OMD Documentation

omdStepVisualizer

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.

Class Hierarchy

omdNode
  └─ omdEquationSequenceNode
       └─ omdStepVisualizer

See: omdEquationSequenceNode for base sequence functionality.

Constructor

new omdStepVisualizer(steps)

Creates a new omdStepVisualizer instance.

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.

Public Properties

Public Methods

rebuildVisualizer()

Forces a complete rebuild of the visual elements (dots and lines) from scratch. This is useful after significant changes to the underlying steps array.

addStep(step, options)

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.

getNodeStepNumber(nodeId)

Retrieves the step number (index) associated with a given omdNode ID within the sequence.

computeDimensions()

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).

updateLayout()

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.

undoLastOperation()

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.

setDotColor(dotIndex, color)

Sets the fill and stroke color of a specific step dot.

setLineAboveColor(dotIndex, color)

Sets the stroke color of the line segment directly above a specific step dot.

setDotsClickable(enabled)

Enables or disables the ability for users to click on the step dots to reveal explanations.

getStepTextBoxes()

Retrieves the array of currently visible explanation text box components managed by the textBoxManager.

Internal Methods

Example

import { omdStepVisualizer } from '@teachinglab/omd';
import { omdEquationNode } from '@teachinglab/omd';
import { omdDisplay } from '@teachinglab/omd';

// 1. Define the steps of a solution (must be omdEquationNode for dots to appear)
const steps = [
  omdEquationNode.fromString('2x + 4 = 10'),
  omdEquationNode.fromString('2x = 6'),
  omdEquationNode.fromString('x = 3')
];

// 2. Create the visualizer
const visualizer = new omdStepVisualizer(steps);

// 3. Add it to a display container
const display = new omdDisplay(document.getElementById('container'));
display.render(visualizer);

// Now the steps will be displayed with interactive dots on the right.
// Only omdEquationNode steps are visualized with dots/lines.
// Clicking the dot next to "2x = 6" will explain that 4 was subtracted from both sides.
↑ Top