OMD Documentation

omdFunctionNode

Represents a mathematical function call, such as sin(x), sqrt(9), or log(x, 10). This node handles the rendering of the function name, its arguments, and surrounding parentheses. It supports evaluation, simplification, and conversion to/from math.js AST.

Class Definition

export class omdFunctionNode extends omdNode

Constructor

new omdFunctionNode(astNodeData)

Creates a new omdFunctionNode instance.

Static Methods

fromString(functionString)

Creates an omdFunctionNode from a string representation of a function call. This method requires window.math (math.js library) to be available globally for parsing.

Public Properties

Public Methods

computeDimensions()

Calculates the bounding box of the function node, taking into account the dimensions of the function name, arguments, and parentheses. It also sets the font sizes for the function name and arguments (arguments are typically scaled down slightly).

updateLayout()

Positions the function name, arguments, and parentheses within the node's bounding box. It ensures proper spacing and vertical alignment of all elements.

highlightAll()

Applies a highlight to the function node itself (its background rectangle) and recursively highlights all of its argument nodes.

unhighlightAll()

Removes the highlight from the function node and recursively unhighlights all of its argument nodes.

clone()

Creates a deep, structural clone of the function node, including all its argument nodes and their associated SVG elements. The clone's provenance array is updated to include the original node's ID.

toMathJSNode()

Converts the omdFunctionNode back into its math.js AST representation. This includes converting its function name and all argument nodes.

toString()

Converts the function node to its string representation (e.g., "sqrt(x^2)", "log(100, 10)").

evaluate(variables)

Evaluates the function by first evaluating its arguments and then applying the function to the results. It primarily uses window.math (math.js) for evaluation. If math.js is not available, it falls back to standard JavaScript Math functions for common cases (e.g., sin, cos, sqrt).

Internal Methods

↑ Top