OMD Documentation

omdOperationDisplayNode

Represents a visual node for displaying an operation applied to both sides of an equation. This node is designed to show the operation (e.g., +5 or ×2) on both the left and right sides of an equation, typically used in step-by-step solution visualizers. It is non-interactive and non-highlightable by design.

Class Definition

export class omdOperationDisplayNode extends omdNode

Static Properties

OPERATOR_SYMBOLS

A static map that defines the display symbols for various operations.

static OPERATOR_SYMBOLS = {
    'add': '+',
    'subtract': '-',
    'multiply': '×',
    'divide': '÷'
};

Constructor

new omdOperationDisplayNode(operation, value)

Creates a new omdOperationDisplayNode instance.

During construction, the node initializes its display, creates the visual elements for the operation, disables all user interactions and highlighting, and adds the elements as children.

Public Properties

Public Methods

computeDimensions()

Calculates the dimensions (width and height) of the operation display node. It determines the total width by summing the widths of the left and right tokens and the gap between them. The height is based on the tallest token with some vertical padding.

updateLayout()

Updates the layout of the operation display node. It positions the leftToken at the beginning and the rightToken after the calculated gap, ensuring they are vertically centered within the node's height.

getLeftWidthForAlignment()

Returns the effective width of the left operation cluster. This is used by omdEquationSequenceNode to align the equals signs of equations with the center of the gap in the operation display.

showLeftOnly()

Hides the right operation token and recalculates the dimensions and layout to display only the left operation. This is useful for scenarios where only one side of the operation needs to be shown.

clone()

Creates a deep clone of the omdOperationDisplayNode. The cloned node will have the same operation and value, and its provenance will link back to the original node. The cloned node is also made non-highlightable.

Internal Methods

Example

// Create operation display for subtracting 3
const subtractNode = new omdOperationDisplayNode('subtract', 3);

// Create operation display for multiplying by 'x'
const multiplyNode = new omdOperationDisplayNode('multiply', 'x');

// Create operation display for dividing by a complex expression
const complexDivideNode = new omdOperationDisplayNode('divide', {
  type: 'OperatorNode',
  op: '+',
  args: [
    { type: 'ConstantNode', value: 1 },
    { type: 'SymbolNode', name: 'x' }
  ]
});

// To render these, you would typically add them to an omdEquationSequenceNode
// or an omdDisplay.
// For example:
// const display = new omdDisplay(document.getElementById('container'));
// display.render(subtractNode);

See Also

↑ Top