OMD Documentation

omdEquationStack

A renderable component that bundles a sequence of mathematical equations with optional UI controls (toolbar). It extends jsvgGroup and acts as a node that can be rendered by an omdDisplay.

Class Definition

import { omdEquationStack } from './omd/core/omdEquationStack.js';

Constructor

new omdEquationStack(steps, options)

Creates a new omdEquationStack instance.

Public Properties

Public Methods

updateLayout()

Updates the layout and positioning of internal components. This method ensures the sequence and toolbar are correctly arranged and that the toolbar is horizontally centered if it's in-flow.

getSequence()

Returns the underlying sequence instance (either omdEquationSequenceNode or omdStepVisualizer).

getToolbar()

Returns the toolbar instance, if one was created during construction.

getOverlayPadding()

Returns the padding value used for positioning the toolbar when it's in an overlay mode.

getToolbarVisualHeight()

Returns the unscaled visual height of the toolbar's background element, if the toolbar is present.

isToolbarOverlay()

Checks if the toolbar is configured to be overlaid at the bottom of the container.

positionToolbarOverlay(containerWidth, containerHeight, padding)

Positions the toolbar overlay at the bottom center of the container. This method is typically called by the omdDisplay to ensure the toolbar remains visible and correctly placed even when the main content scales.

undoLastOperation()

Removes the last equation step and any preceding operation display node from the sequence. This method also triggers a re-layout and updates any associated step visualizer.

Usage

The omdEquationStack component is a complete equation solving interface that combines an equation sequence with an optional toolbar. It automatically handles layout and positioning.

import { omdDisplay } from 'omd';
import { omdEquationStack } from 'omd';
import { omdEquationNode } from 'omd';

// Create display
const container = document.getElementById('math-display');
const display = new omdDisplay(container);

// Create equation steps
const steps = [
    omdEquationNode.fromString('2x + 3 = 11'),
    omdEquationNode.fromString('2x = 8'),
    omdEquationNode.fromString('x = 4')
];

// Basic equation stack with toolbar
const stack = new omdEquationStack(steps, {
    toolbar: true
});

// Render the stack
display.render(stack);

// Alternative: Create with step visualizer and custom toolbar options
const stackWithVisualizer = new omdEquationStack(steps, {
    toolbar: {
        enabled: true,
        showUndoButton: true,
        position: 'overlay-bottom'
    },
    stepVisualizer: true,
    styling: {
        equationBackground: {
            backgroundColor: '#e0f7fa',
            cornerRadius: 10,
            pill: true
        }
    }
});

display.render(stackWithVisualizer);

Integration

The equation stack integrates seamlessly with the step visualizer:

import { omdEquationStack } from 'omd';
import { omdEquationNode } from 'omd';
import { omdDisplay } from 'omd';

// Create steps for a more complex equation
const steps = [
    omdEquationNode.fromString('x/2 + 3 = 7'),
    omdEquationNode.fromString('x/2 = 4'),
    omdEquationNode.fromString('x = 8')
];

// Enable step visualizer with highlighting
const stack = new omdEquationStack(steps, {
    toolbar: true,
    stepVisualizer: true
});

// Render in display
const container = document.getElementById('equation-display');
const display = new omdDisplay(container);
display.render(stack);

// Access the visualizer for programmatic control
const visualizer = stack.getSequence();
// visualizer.nextStep(); // Progress through solution steps if interactive

Layout Behavior

The equation stack automatically manages its internal layout:

// Create a stack and let it handle layout automatically
const stack = new omdEquationStack(steps, { toolbar: true });

// Manual layout update (rarely needed)
stack.updateLayout();

// Access components
const sequence = stack.getSequence();
const toolbar = stack.getToolbar();

See Also

↑ Top