OMD Documentation

omdHelpers

omdHelpers is a collection of convenience functions designed to simplify common tasks when working with the OMD library. These helpers abstract away underlying complexities, making it easier to create and manipulate mathematical expressions and visualizations.

Overview

The omdHelpers object is exported from the main omd/core/index.js entry point, making its functions readily available for use in your project.

Functions

createNodeFromExpression(expression, mathInstance)

Creates an omdNode instance from a string representation of a mathematical expression. This function parses the expression using the provided math.js instance and instantiates the appropriate omdNode subclass.

import { omdHelpers } from '@teachinglab/omd';
// Assuming math.js is loaded globally as window.math

const expressionNode = omdHelpers.createNodeFromExpression('2x + 5', window.math);
// expressionNode will be an instance of omdBinaryExpressionNode or another omdNode subclass

createEquation(equationString)

Creates an omdEquationNode instance from a string representation of an equation. This is a specialized helper for equations, ensuring proper parsing and node creation.

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

const equation = omdHelpers.createEquation('3y - 7 = 14');
// equation will be an instance of omdEquationNode

createStepVisualizer(equationStrings)

Creates an omdStepVisualizer instance from an array of equation strings. This is useful for quickly setting up a step-by-step solution display.

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

const steps = [
    '4x + 8 = 20',
    '4x = 12',
    'x = 3'
];
const visualizer = omdHelpers.createStepVisualizer(steps);
// visualizer will be an instance of omdStepVisualizer

Example Usage

import { omdDisplay, omdHelpers } from '@teachinglab/omd';
// Assuming math.js is loaded globally as window.math

// Get a container element (assuming it exists in your HTML)
const container = document.getElementById('math-display-area');

// Create an expression node using a helper
const expression = omdHelpers.createNodeFromExpression('a^2 + b^2', window.math);

// Create an equation using a helper
const equation = omdHelpers.createEquation('E = mc^2');

// Create a step visualizer using a helper
const solutionSteps = [
    'x + 5 = 10',
    'x = 5'
];
const stepVisualizer = omdHelpers.createStepVisualizer(solutionSteps);

// You can then render these nodes using omdDisplay or omdCanvas
const display = new omdDisplay(container);
display.render(expression);

// Or for the step visualizer
// display.render(stepVisualizer);
↑ Top