OMD Objects Reference (Verified)
This file documents the high-level JSON shapes accepted by the OMD classes and the low-level Class().loadFromJSON(data) APIs for each OMD visual. All shapes were verified against the code in src/.
Usage
- Instantiate the appropriate OMD class and call
loadFromJSON(...)with the JSON object below. - Many classes also accept a plain string where documented (e.g., expression/equation strings).
Notes
- Some components accept multiple, backward-compatible shapes (string, legacy fields, or structured objects). Where a field can be a string or structured object the docs indicate both.
- Field names shown are exactly as used by the source files.
COMMON: Expression / Terms / Number / Variable / Operator
Expression objects appear in several places; there are two common forms used across the codebase:
- Compact expression string
- Example:
"2x + 5" - Many components accept a simple string which will be parsed (e.g.,
omdExpression.loadFromJSON("2x+5")).
- Structured expression (preferred for programmatic usage)
expression/termsAndOpersobject form used byomdExpressionand others:
{
// either a high-level expression object (terms) or the parsed low-level form
// Low-level parser output used in the codebase is termsAndOpers
"termsAndOpers": [
{ "omdType": "term", "coefficient": number, "variable"?: string, "exponent"?: number },
{ "omdType": "number", "value": number },
{ "omdType": "variable", "name": string },
{ "omdType": "operator", "operator": "+"|"-"|"/"|"÷"|"x"|"*"|"•"|"×"|"=" }
]
}
Legacy/alternate simple structured form used in some places (terms array):
{
"terms": [ { "coefficient"?: number, "variable"?: string, "value"?: number } ]
}
Primitive pieces
- number:
{ omdType: "number", value: number }(low-levelomdNumber.loadFromJSON({ value })accepts{ value }) - variable:
{ omdType: "variable", name: string }(low-levelomdVariable.loadFromJSON({ name })) - operator:
{ omdType: "operator", operator: "+"|"-"|"/"|"÷"|"x"|"*"|"•"|"×"|"=" }(low-levelomdOperator.loadFromJSON({ operator })) - term:
{ omdType: "term", coefficient: number, variable?: string, exponent?: number }(low-levelomdTerm.loadFromJSONaccepts{ coefficient, variable?, exponent? })
Examples
- Number:
{ "omdType": "number", "value": 42 } - Term:
{ "omdType": "term", "coefficient": 3, "variable": "x", "exponent": 2 } - Expression string:
"2x + 3" - Expression structured:
{ "termsAndOpers": [ { "omdType": "term", "coefficient": 2, "variable": "x" }, { "omdType": "operator", "operator": "+" }, { "omdType": "number", "value": 3 } ] }
SPECIFIC OBJECTS (by omdType / class)
-- omd (root container)
The
omdcontainer class exists as a convenience to hold child visuals. To configure visuals, instantiate the specific class and callloadFromJSONon it.equation /
omdEquation
High-level:
{ "omdType": "equation", "equation": string }equationstring parsed if provided (preferred for simple cases).
Legacy / structured:
{ "omdType": "equation", "leftExpression": ExpressionObject, "rightExpression": ExpressionObject }- Either side may be an
expressionstring/structured object or a primitive{ omdType: 'number'|... }. omdEquation.loadFromJSONalso accepts anequationstring and will attempt to parse it into left/right.
expression /
omdExpression- Accepts either a string (e.g.,
"2x+5") or a structured object withtermsAndOpersas shown above. - Example:
{ "omdType": "expression", "termsAndOpers": [...] }or simply"2x + 5".
- Accepts either a string (e.g.,
number /
omdNumber- High-level:
{ "omdType": "number", "value": number } - Low-level:
loadFromJSON({ value: number })
- High-level:
variable /
omdVariable{ "omdType": "variable", "name": string }loadFromJSON({ name: string })
operator /
omdOperator{ "omdType": "operator", "operator": "+"|"-"|"/"|"÷"|"x"|"*"|"•"|"×"|"=" }loadFromJSON({ operator: "..." })— note several symbols are normalized in code (e.g.,'*'=>×,'-'mapped to Unicode minus for display).
term /
omdTerm- High-level: `{ "omdType": "term", "coefficient": number, "variable"?: string, "exponent"?: number }
loadFromJSONaccepts{ coefficient, variable?, exponent? }.
powerExpression /
omdPowerExpression- Structured:
{
"omdType": "powerExpression",
"baseExpression": ExpressionObject, // object with omdType 'expression'|'number'|'variable'|'term' (or a string for expression)
"exponentExpression": ExpressionObject // same shape
} - Note:
loadFromJSONexpectsbaseExpressionandexponentExpressionnamed fields (the code uses these names).
- Structured:
rationalExpression /
omdRationalExpression- Structured:
{
"omdType": "rationalExpression",
"numeratorExpression": ExpressionObject,
"denominatorExpression": ExpressionObject
} - Note:
loadFromJSONexpectsnumeratorExpression/denominatorExpressionfields.
- Structured:
function /
omdFunction- Structured:
{
"omdType": "function",
"name": string,
"inputVariables": [ string, ... ],
"expression": ExpressionObject
} - Note:
inputVariablesis an array of variable names (strings).
- Structured:
numberLine /
omdNumberLine- Structured:
{
"omdType": "numberLine",
"min": number,
"max": number,
"dotValues": [ number, ... ],
"label"?: string
} - Note:
dotValuesis an array of positions for dots on the line.
- Structured:
balanceHanger /
omdBalanceHanger- Structured:
{
"omdType": "balanceHanger",
"leftValues": [ number, ... ],
"rightValues": [ number, ... ],
"tilt"?: "left"|"right"
} - Note:
leftValues/rightValuesare arrays of value numbers.
- Structured:
tapeDiagram /
omdTapeDiagramandomdTapeLabel- Structured:
{
"omdType": "tapeDiagram",
"values": [ number, ... ],
"unitWidth": number,
"labelSet": [ { "omdType": "omdTapeLabel", "startIndex": number, "endIndex": number, "label": string, "showBelow"?: boolean } ]
} - Note:
valuesis an array of tape segment values.
- Structured:
tileEquation /
omdTileEquation- Structured:
{
"omdType": "tileEquation",
"left": [ /* tileSpec / ],
"right": [ / tileSpec */ ]
} - Note:
left/rightare arrays of tile specifications.
- Structured:
numberTile /
omdNumberTile- Structured:
{
"omdType": "numberTile",
"value": number,
"size"?: "small"|"medium"|"large",
"dotsPerColumn"?: number
} - Note:
sizeanddotsPerColumnare optional.
- Structured:
ratioChart /
omdRatioChart- Structured:
{
"omdType": "ratioChart",
"numerator": number,
"denominator": number,
"renderType"?: "pie"|"bar"
} - Note:
renderTypespecifies how to render the ratio.
- Structured:
coordinatePlane /
omdCoordinatePlane- Structured:
{
"omdType": "coordinatePlane",
"xMin": number, "xMax": number,
"yMin": number, "yMax": number,
"graphEquations": [ { "equation": string, "color"?: string, "strokeWidth"?: number } ]
} - Note:
graphEquationsis an array of equations to graph.
- Structured:
shapes (in omdShapes.js)
- rectangle, circle, ellipse, regularPolygon, rightTriangle, isoscelesTriangle — load shapes via their respective classes and
loadFromJSONwith the fields shown above.
spinner / omdSpinner
- Structured:
{
"omdType": "spinner",
"divisions": number,
"arrowPosition": number
} - Note:
divisionsis the number of divisions on the spinner,arrowPositionis the initial position of the arrow.
table / omdTable
- See
omdTablefor fields likeheaders,data,fontSize,cellHeight,backgroundColor.
problem / omdProblem
- Structured:
{
"omdType": "problem",
"problemText": string,
"visualization": { /* forwarded object */ }
}- Note:
visualizationforwards to the specific visualization object.
- Note:
Examples (call loadFromJSON on instances)
- Equation (string form)
const eq = new omdEquation();
eq.loadFromJSON({ omdType: 'equation', equation: '2x + 3 = 11' });
- Coordinate plane with a function
const plane = new omdCoordinatePlane();
plane.loadFromJSON({
omdType: 'coordinatePlane',
xMin: -10, xMax: 10,
yMin: -10, yMax: 10,
graphEquations: [{ equation: 'y = x^2 - 4', color: '#e11d48', strokeWidth: 2 }]
});
- Tape diagram (values)
const tape = new omdTapeDiagram();
tape.loadFromJSON({ omdType: 'tapeDiagram', values: [1,2,3], unitWidth: 30, labelSet: [{ omdType: 'omdTapeLabel', startIndex: 0, endIndex: 3, label: '6', showBelow: true }] });
- Number tile
const tile = new omdNumberTile();
tile.loadFromJSON({ omdType: 'numberTile', value: 8, size: 'medium', dotsPerColumn: 10 });
Appendix / Implementation notes
- Parsers in
src/omdUtils.jsaccept and normalize expression/equation strings intotermsAndOpersarrays used byomdExpression. - The codebase supports some legacy field names for backward compatibility; prefer the modern names documented here.
If you want, I can:
- Generate a one-line
loadFromJSONexample for every class insrc/and insert them into this doc. - Or run a script that extracts
loadFromJSONparameter names from the source files to produce machine-readable JSON schema files.
Which would you like next?