@teachinglab/omd 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,258 @@
1
+ # OMD Objects Reference (Verified)
2
+
3
+
4
+ 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/`.
5
+
6
+ Usage
7
+ - Instantiate the appropriate OMD class and call `loadFromJSON(...)` with the JSON object below.
8
+ - Many classes also accept a plain string where documented (e.g., expression/equation strings).
9
+
10
+ Notes
11
+ - 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.
12
+ - Field names shown are exactly as used by the source files.
13
+
14
+ ----------------------------------------------------------------
15
+ COMMON: Expression / Terms / Number / Variable / Operator
16
+ ----------------------------------------------------------------
17
+ Expression objects appear in several places; there are two common forms used across the codebase:
18
+
19
+ 1) Compact expression string
20
+ - Example: `"2x + 5"`
21
+ - Many components accept a simple string which will be parsed (e.g., `omdExpression.loadFromJSON("2x+5")`).
22
+
23
+ 2) Structured expression (preferred for programmatic usage)
24
+ - `expression` / `termsAndOpers` object form used by `omdExpression` and others:
25
+
26
+ {
27
+ // either a high-level expression object (terms) or the parsed low-level form
28
+ // Low-level parser output used in the codebase is `termsAndOpers`
29
+ "termsAndOpers": [
30
+ { "omdType": "term", "coefficient": number, "variable"?: string, "exponent"?: number },
31
+ { "omdType": "number", "value": number },
32
+ { "omdType": "variable", "name": string },
33
+ { "omdType": "operator", "operator": "+"|"-"|"/"|"÷"|"x"|"*"|"•"|"×"|"=" }
34
+ ]
35
+ }
36
+
37
+ Legacy/alternate simple structured form used in some places (terms array):
38
+ {
39
+ "terms": [ { "coefficient"?: number, "variable"?: string, "value"?: number } ]
40
+ }
41
+
42
+ Primitive pieces
43
+ - number: `{ omdType: "number", value: number }` (low-level `omdNumber.loadFromJSON({ value })` accepts `{ value }`)
44
+ - variable: `{ omdType: "variable", name: string }` (low-level `omdVariable.loadFromJSON({ name })`)
45
+ - operator: `{ omdType: "operator", operator: "+"|"-"|"/"|"÷"|"x"|"*"|"•"|"×"|"=" }` (low-level `omdOperator.loadFromJSON({ operator })`)
46
+ - term: `{ omdType: "term", coefficient: number, variable?: string, exponent?: number }` (low-level `omdTerm.loadFromJSON` accepts `{ coefficient, variable?, exponent? }`)
47
+
48
+ Examples
49
+ - Number: `{ "omdType": "number", "value": 42 }`
50
+ - Term: `{ "omdType": "term", "coefficient": 3, "variable": "x", "exponent": 2 }`
51
+ - Expression string: `"2x + 3"`
52
+ - Expression structured: `{ "termsAndOpers": [ { "omdType": "term", "coefficient": 2, "variable": "x" }, { "omdType": "operator", "operator": "+" }, { "omdType": "number", "value": 3 } ] }`
53
+
54
+ ----------------------------------------------------------------
55
+ SPECIFIC OBJECTS (by `omdType` / class)
56
+ ----------------------------------------------------------------
57
+ -- omd (root container)
58
+ - The `omd` container class exists as a convenience to hold child visuals. To configure visuals, instantiate the specific class and call `loadFromJSON` on it.
59
+
60
+ - equation / `omdEquation`
61
+ High-level:
62
+ { "omdType": "equation", "equation": string }
63
+ - `equation` string parsed if provided (preferred for simple cases).
64
+
65
+ Legacy / structured:
66
+ { "omdType": "equation", "leftExpression": ExpressionObject, "rightExpression": ExpressionObject }
67
+ - Either side may be an `expression` string/structured object or a primitive `{ omdType: 'number'|... }`.
68
+ - `omdEquation.loadFromJSON` also accepts an `equation` string and will attempt to parse it into left/right.
69
+
70
+ - expression / `omdExpression`
71
+ - Accepts either a string (e.g., `"2x+5"`) or a structured object with `termsAndOpers` as shown above.
72
+ - Example: `{ "omdType": "expression", "termsAndOpers": [...] }` or simply `"2x + 5"`.
73
+
74
+ - number / `omdNumber`
75
+ - High-level: `{ "omdType": "number", "value": number }`
76
+ - Low-level: `loadFromJSON({ value: number })`
77
+
78
+ - variable / `omdVariable`
79
+ - `{ "omdType": "variable", "name": string }`
80
+ - `loadFromJSON({ name: string })`
81
+
82
+ - operator / `omdOperator`
83
+ - `{ "omdType": "operator", "operator": "+"|"-"|"/"|"÷"|"x"|"*"|"•"|"×"|"=" }`
84
+ - `loadFromJSON({ operator: "..." })` — note several symbols are normalized in code (e.g., `'*'` => `×`, `'-'` mapped to Unicode minus for display).
85
+
86
+ - term / `omdTerm`
87
+ - High-level: `{ "omdType": "term", "coefficient": number, "variable"?: string, "exponent"?: number }
88
+ - `loadFromJSON` accepts `{ coefficient, variable?, exponent? }`.
89
+
90
+ - powerExpression / `omdPowerExpression`
91
+ - Structured:
92
+ {
93
+ "omdType": "powerExpression",
94
+ "baseExpression": ExpressionObject, // object with omdType 'expression'|'number'|'variable'|'term' (or a string for expression)
95
+ "exponentExpression": ExpressionObject // same shape
96
+ }
97
+ - Note: `loadFromJSON` expects `baseExpression` and `exponentExpression` named fields (the code uses these names).
98
+
99
+ - rationalExpression / `omdRationalExpression`
100
+ - Structured:
101
+ {
102
+ "omdType": "rationalExpression",
103
+ "numeratorExpression": ExpressionObject,
104
+ "denominatorExpression": ExpressionObject
105
+ }
106
+ - Note: `loadFromJSON` expects `numeratorExpression` / `denominatorExpression` fields.
107
+
108
+ - function / `omdFunction`
109
+ - Structured:
110
+ {
111
+ "omdType": "function",
112
+ "name": string,
113
+ "inputVariables": [ string, ... ],
114
+ "expression": ExpressionObject
115
+ }
116
+ - Note: `inputVariables` is an array of variable names (strings).
117
+
118
+ - numberLine / `omdNumberLine`
119
+ - Structured:
120
+ {
121
+ "omdType": "numberLine",
122
+ "min": number,
123
+ "max": number,
124
+ "dotValues": [ number, ... ],
125
+ "label"?: string
126
+ }
127
+ - Note: `dotValues` is an array of positions for dots on the line.
128
+
129
+ - balanceHanger / `omdBalanceHanger`
130
+ - Structured:
131
+ {
132
+ "omdType": "balanceHanger",
133
+ "leftValues": [ number, ... ],
134
+ "rightValues": [ number, ... ],
135
+ "tilt"?: "left"|"right"
136
+ }
137
+ - Note: `leftValues`/`rightValues` are arrays of value numbers.
138
+
139
+ - tapeDiagram / `omdTapeDiagram` and `omdTapeLabel`
140
+ - Structured:
141
+ {
142
+ "omdType": "tapeDiagram",
143
+ "values": [ number, ... ],
144
+ "unitWidth": number,
145
+ "labelSet": [ { "omdType": "omdTapeLabel", "startIndex": number, "endIndex": number, "label": string, "showBelow"?: boolean } ]
146
+ }
147
+ - Note: `values` is an array of tape segment values.
148
+
149
+ - tileEquation / `omdTileEquation`
150
+ - Structured:
151
+ {
152
+ "omdType": "tileEquation",
153
+ "left": [ /* tileSpec */ ],
154
+ "right": [ /* tileSpec */ ]
155
+ }
156
+ - Note: `left`/`right` are arrays of tile specifications.
157
+
158
+ - numberTile / `omdNumberTile`
159
+ - Structured:
160
+ {
161
+ "omdType": "numberTile",
162
+ "value": number,
163
+ "size"?: "small"|"medium"|"large",
164
+ "dotsPerColumn"?: number
165
+ }
166
+ - Note: `size` and `dotsPerColumn` are optional.
167
+
168
+ - ratioChart / `omdRatioChart`
169
+ - Structured:
170
+ {
171
+ "omdType": "ratioChart",
172
+ "numerator": number,
173
+ "denominator": number,
174
+ "renderType"?: "pie"|"bar"
175
+ }
176
+ - Note: `renderType` specifies how to render the ratio.
177
+
178
+ - coordinatePlane / `omdCoordinatePlane`
179
+ - Structured:
180
+ {
181
+ "omdType": "coordinatePlane",
182
+ "xMin": number, "xMax": number,
183
+ "yMin": number, "yMax": number,
184
+ "graphEquations": [ { "equation": string, "color"?: string, "strokeWidth"?: number } ]
185
+ }
186
+ - Note: `graphEquations` is an array of equations to graph.
187
+
188
+ shapes (in `omdShapes.js`)
189
+ - rectangle, circle, ellipse, regularPolygon, rightTriangle, isoscelesTriangle — load shapes via their respective classes and `loadFromJSON` with the fields shown above.
190
+
191
+ spinner / `omdSpinner`
192
+ - Structured:
193
+ {
194
+ "omdType": "spinner",
195
+ "divisions": number,
196
+ "arrowPosition": number
197
+ }
198
+ - Note: `divisions` is the number of divisions on the spinner, `arrowPosition` is the initial position of the arrow.
199
+
200
+ table / `omdTable`
201
+ - See `omdTable` for fields like `headers`, `data`, `fontSize`, `cellHeight`, `backgroundColor`.
202
+
203
+ problem / `omdProblem`
204
+ - Structured:
205
+ {
206
+ "omdType": "problem",
207
+ "problemText": string,
208
+ "visualization": { /* forwarded object */ }
209
+ }
210
+ - Note: `visualization` forwards to the specific visualization object.
211
+
212
+ ----------------------------------------------------------------
213
+ Examples (call `loadFromJSON` on instances)
214
+ ----------------------------------------------------------------
215
+
216
+ 1) Equation (string form)
217
+
218
+ ```js
219
+ const eq = new omdEquation();
220
+ eq.loadFromJSON({ omdType: 'equation', equation: '2x + 3 = 11' });
221
+ ```
222
+
223
+ 2) Coordinate plane with a function
224
+
225
+ ```js
226
+ const plane = new omdCoordinatePlane();
227
+ plane.loadFromJSON({
228
+ omdType: 'coordinatePlane',
229
+ xMin: -10, xMax: 10,
230
+ yMin: -10, yMax: 10,
231
+ graphEquations: [{ equation: 'y = x^2 - 4', color: '#e11d48', strokeWidth: 2 }]
232
+ });
233
+ ```
234
+
235
+ 3) Tape diagram (values)
236
+
237
+ ```js
238
+ const tape = new omdTapeDiagram();
239
+ tape.loadFromJSON({ omdType: 'tapeDiagram', values: [1,2,3], unitWidth: 30, labelSet: [{ omdType: 'omdTapeLabel', startIndex: 0, endIndex: 3, label: '6', showBelow: true }] });
240
+ ```
241
+
242
+ 4) Number tile
243
+
244
+ ```js
245
+ const tile = new omdNumberTile();
246
+ tile.loadFromJSON({ omdType: 'numberTile', value: 8, size: 'medium', dotsPerColumn: 10 });
247
+ ```
248
+
249
+ ----------------------------------------------------------------
250
+ Appendix / Implementation notes
251
+ - Parsers in `src/omdUtils.js` accept and normalize expression/equation strings into `termsAndOpers` arrays used by `omdExpression`.
252
+ - The codebase supports some legacy field names for backward compatibility; prefer the modern names documented here.
253
+
254
+ If you want, I can:
255
+ - Generate a one-line `loadFromJSON` example for every class in `src/` and insert them into this doc.
256
+ - Or run a script that extracts `loadFromJSON` parameter names from the source files to produce machine-readable JSON schema files.
257
+ Which would you like next?
258
+