OMD Documentation

omdOperatorNode

Represents an operator symbol (e.g., +, -, *, ÷) as a leaf node in the expression tree. This node handles the visual representation of operators, including mapping common operation names to their appropriate symbols and applying styling.

Class Definition

export class omdOperatorNode extends omdLeafNode

Constructor

new omdOperatorNode(nodeData)

Creates a new omdOperatorNode instance.

Public Properties

Public Methods

computeDimensions()

Calculates the dimensions of the node based on its text content, adding a small amount of padding around the operator symbol to improve visual spacing.

updateLayout()

Updates the layout of the node. This method primarily calls the superclass's updateLayout.

toMathJSNode()

Converts the omdOperatorNode to a math.js-compatible AST format. It creates a minimal OperatorNode AST object.

toString()

Converts the operator node to its string representation, which is simply its opName.

highlight(color)

Applies a highlight to the node's background and sets the operator's text color to white for better contrast. This method respects the isExplainHighlighted lock.

clearProvenanceHighlights()

Clears any provenance-related highlights from the node and resets the operator's text color to its default (black).

Internal Methods

Example

import { omdOperatorNode } from '@teachinglab/omd';

// Create operator nodes from strings
const plus = new omdOperatorNode('+');
const times = new omdOperatorNode('*'); // Displays as × (configurable via omdConfigManager)

// Create operator node from AST data (e.g., from math.js parse result)
const minus = new omdOperatorNode({
  type: 'OperatorNode',
  op: '-',
  fn: 'subtract'
}); // Displays as −

// To render, typically add to a parent node or an omdDisplay
// node.setFontSize(24);
// node.initialize(); // Computes dimensions and layout

See Also

↑ Top