@teachinglab/omd 0.3.7 → 0.3.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teachinglab/omd",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "omd",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -1,109 +1,577 @@
1
- # OMD JSON Schemas
1
+ # Unified Schemas and Examples for `loadFromJSON`
2
2
 
3
- ## tapeDiagram
3
+ This document provides schemas and examples for the `loadFromJSON` method used in various visual components. Each section includes a brief explanation of the component, its schema, and an example JSON object.
4
+
5
+ ## 1. `omdVariable`
6
+
7
+ `omdVariable` represents a single variable, such as "x" or "y", used in mathematical expressions.
8
+
9
+ ### Schema
10
+ ```json
11
+ {
12
+ "name": "string"
13
+ }
14
+ ```
15
+
16
+ ### Example
17
+ ```json
18
+ {
19
+ "name": "VariableName"
20
+ }
21
+ ```
22
+
23
+ ---
24
+
25
+ ## 2. `omdTileEquation`
26
+
27
+ `omdTileEquation` is used to represent equations visually with tiles, such as "x + y = z".
28
+
29
+ ### Schema
30
+ ```json
31
+ {
32
+ "left": ["array"],
33
+ "right": ["array"],
34
+ "equation": "string | object",
35
+ "tileSize": "number",
36
+ "tileGap": "number",
37
+ "equalGap": "number",
38
+ "tileRadius": "number",
39
+ "showLabels": "boolean",
40
+ "fontFamily": "string",
41
+ "fontSize": "number",
42
+ "plusColor": "string",
43
+ "equalsColor": "string",
44
+ "xPillColor": "string",
45
+ "numberTileDefaults": {
46
+ "backgroundColor": "string",
47
+ "dotColor": "string"
48
+ }
49
+ }
50
+ ```
51
+
52
+ ### Example
53
+ ```json
54
+ {
55
+ "left": ["x", "y"],
56
+ "right": ["z"],
57
+ "equation": "x + y = z",
58
+ "tileSize": 28,
59
+ "tileGap": 6,
60
+ "equalGap": 24,
61
+ "tileRadius": 6,
62
+ "showLabels": true,
63
+ "fontFamily": "Albert Sans",
64
+ "fontSize": 16,
65
+ "plusColor": "#79BBFD",
66
+ "equalsColor": "#FF6B6B",
67
+ "xPillColor": "#CCCCCC",
68
+ "numberTileDefaults": {
69
+ "backgroundColor": "#FFFFFF",
70
+ "dotColor": "#000000"
71
+ }
72
+ }
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 3. `omdTerm`
78
+
79
+ `omdTerm` represents a single term in a mathematical expression, such as "2x" or "3y^2".
80
+
81
+ ### Schema
82
+ ```json
83
+ {
84
+ "coefficient": "number",
85
+ "variable": "string",
86
+ "exponent": "number"
87
+ }
88
+ ```
89
+
90
+ ### Example
91
+ ```json
92
+ {
93
+ "coefficient": 2,
94
+ "variable": "x",
95
+ "exponent": 3
96
+ }
97
+ ```
98
+
99
+ ---
100
+
101
+ ## 4. `omdTapeDiagram`
102
+
103
+ `omdTapeDiagram` is used to represent proportional relationships or part-whole relationships visually.
104
+
105
+ ### Schema
106
+ ```json
107
+ {
108
+ "values": ["array"],
109
+ "showValues": "boolean",
110
+ "colors": ["array"],
111
+ "labelSet": ["array"],
112
+ "unitWidth": "number"
113
+ }
114
+ ```
115
+
116
+ ### Example
4
117
  ```json
5
118
  {
6
- "omdType": "tapeDiagram",
7
- "values": [number|string, ...], //any numbers should be inputted as NUMBERS, e.g 4 not '4'
8
- "colors": [string, ...],
119
+ "values": [1, 2, 3],
120
+ "showValues": true,
121
+ "colors": ["#FF0000", "#00FF00", "#0000FF"],
9
122
  "labelSet": [
10
- {
11
- "omdType": "omdTapeLabel",
12
- "startIndex": number, //inclusive
13
- "endIndex": number, //exclusive
14
- "label": string,
15
- "showBelow": boolean
16
- }
123
+ { "startIndex": 0, "endIndex": 2, "label": "Example Label", "showBelow": true }
17
124
  ],
18
- "unitWidth": number,
19
- "showValues": boolean
125
+ "unitWidth": 30
126
+ }
127
+ ```
128
+
129
+ ---
130
+
131
+ ## 5. `omdTable`
132
+
133
+ `omdTable` is used to display tabular data, often generated from equations or datasets.
134
+
135
+ ### Schema
136
+ ```json
137
+ {
138
+ "equation": "string",
139
+ "data": ["array"],
140
+ "headers": ["array"],
141
+ "xMin": "number",
142
+ "xMax": "number",
143
+ "stepSize": "number",
144
+ "title": "string",
145
+ "fontSize": "number",
146
+ "headerFontSize": "number",
147
+ "fontFamily": "string",
148
+ "headerFontFamily": "string",
149
+ "cellHeight": "number",
150
+ "headerHeight": "number",
151
+ "minCellWidth": "number",
152
+ "maxCellWidth": "number",
153
+ "padding": "number",
154
+ "backgroundColor": "string",
155
+ "backgroundCornerRadius": "number",
156
+ "backgroundOpacity": "number",
157
+ "showBackground": "boolean",
158
+ "alternatingRowColors": ["array"]
159
+ }
160
+ ```
161
+
162
+ ### Example
163
+ ```json
164
+ {
165
+ "equation": "y = x^2",
166
+ "data": [[-1, 1], [0, 0], [1, 1]],
167
+ "headers": ["x", "y"],
168
+ "xMin": -5,
169
+ "xMax": 5,
170
+ "stepSize": 1,
171
+ "title": "Quadratic Table",
172
+ "fontSize": 14,
173
+ "headerFontSize": 16,
174
+ "fontFamily": "Albert Sans",
175
+ "headerFontFamily": "Albert Sans",
176
+ "cellHeight": 35,
177
+ "headerHeight": 40,
178
+ "minCellWidth": 80,
179
+ "maxCellWidth": 300,
180
+ "padding": 10,
181
+ "backgroundColor": "#FFFFFF",
182
+ "backgroundCornerRadius": 15,
183
+ "backgroundOpacity": 1.0,
184
+ "showBackground": true,
185
+ "alternatingRowColors": ["#F0F0F0", "#FFFFFF"]
20
186
  }
21
187
  ```
22
188
 
23
- - values: segment magnitudes or expressions (strings allowed).
24
- - colors: per-segment fills (optional; falls back to lightGray).
25
- - labelSet: range labels either by indices (startIndex/endIndex) or by absolute values (startValue/endValue).
26
- - unitWidth: pixel width per numeric unit.
189
+ ---
27
190
 
28
- ## balanceHanger
191
+ ## 6. `omdString`
192
+
193
+ `omdString` represents a simple string value, often used as labels or annotations.
194
+
195
+ ### Schema
196
+ ```json
197
+ {
198
+ "name": "string"
199
+ }
200
+ ```
201
+
202
+ ### Example
203
+ ```json
204
+ {
205
+ "name": "Example String"
206
+ }
207
+ ```
208
+
209
+ ---
210
+
211
+ ## 7. `omdSpinner`
212
+
213
+ `omdSpinner` is a circular spinner used to represent divisions or selections visually.
214
+
215
+ ### Schema
216
+ ```json
217
+ {
218
+ "divisions": "number",
219
+ "arrowPosition": "number",
220
+ "size": "string"
221
+ }
222
+ ```
223
+
224
+ ### Example
225
+ ```json
226
+ {
227
+ "divisions": 8,
228
+ "arrowPosition": 3,
229
+ "size": "medium"
230
+ }
231
+ ```
232
+
233
+ ---
234
+
235
+ ## 8. `omdShapes`
236
+
237
+ `omdShapes` represents geometric shapes such as circles, rectangles, and polygons.
238
+
239
+ ### Schema
240
+ ```json
241
+ {
242
+ "type": "string",
243
+ "dimensions": "object",
244
+ "color": "string"
245
+ }
246
+ ```
247
+
248
+ ### Example
249
+ ```json
250
+ {
251
+ "type": "circle",
252
+ "dimensions": { "radius": 10 },
253
+ "color": "#FF0000"
254
+ }
255
+ ```
256
+
257
+ ---
258
+
259
+ ## 9. `omdRationalExpression`
260
+
261
+ `omdRationalExpression` represents a fraction or rational expression, such as "(x+1)/(x-1)".
262
+
263
+ ### Schema
264
+ ```json
265
+ {
266
+ "numeratorExpression": "object",
267
+ "denominatorExpression": "object"
268
+ }
269
+ ```
270
+
271
+ ### Example
29
272
  ```json
30
273
  {
31
- "omdType": "balanceHanger",
32
- "leftValues": [number|string, ...],
33
- "rightValues": [number|string, ...],
34
- "tilt": "left" | "right" | "none",
35
- "fontFamily": string,
36
- "fontSize": number
274
+ "numeratorExpression": { "omdType": "number", "value": 3 },
275
+ "denominatorExpression": { "omdType": "variable", "name": "x" }
37
276
  }
38
277
  ```
39
278
 
40
- - leftValues/rightValues: stacks rendered on each side.
41
- - tilt: beam visual tilt.
279
+ ---
280
+
281
+ ## 10. `omdRatioChart`
282
+
283
+ `omdRatioChart` is used to represent ratios visually, such as pie charts or bar charts.
284
+
285
+ ### Schema
286
+ ```json
287
+ {
288
+ "valueA": "number",
289
+ "valueB": "number",
290
+ "renderType": "string",
291
+ "size": "string"
292
+ }
293
+ ```
42
294
 
43
- ## coordinatePlane
295
+ ### Example
296
+ ```json
297
+ {
298
+ "valueA": 3,
299
+ "valueB": 2,
300
+ "renderType": "pie",
301
+ "size": "large"
302
+ }
303
+ ```
304
+
305
+ ---
306
+
307
+ ## 11. `omdProblem`
308
+
309
+ `omdProblem` represents a problem statement, often with an associated visualization.
310
+
311
+ ### Schema
312
+ ```json
313
+ {
314
+ "problemText": "string",
315
+ "visualization": "object"
316
+ }
317
+ ```
318
+
319
+ ### Example
320
+ ```json
321
+ {
322
+ "problemText": "Solve for x",
323
+ "visualization": { "type": "omdEquation", "data": { "left": "x+2", "right": "5" } }
324
+ }
325
+ ```
326
+
327
+ ---
328
+
329
+ ## 12. `omdPowerExpression`
330
+
331
+ `omdPowerExpression` represents an expression raised to a power, such as "(x+1)^2".
332
+
333
+ ### Schema
334
+ ```json
335
+ {
336
+ "baseExpression": "object",
337
+ "exponentExpression": "object"
338
+ }
339
+ ```
340
+
341
+ ### Example
342
+ ```json
343
+ {
344
+ "baseExpression": { "omdType": "variable", "name": "x" },
345
+ "exponentExpression": { "omdType": "number", "value": 2 }
346
+ }
347
+ ```
348
+
349
+ ---
350
+
351
+ ## 13. `omdOperator`
352
+
353
+ `omdOperator` represents a mathematical operator, such as "+", "-", "*", or "/".
354
+
355
+ ### Schema
356
+ ```json
357
+ {
358
+ "operator": "string"
359
+ }
360
+ ```
361
+
362
+ ### Example
363
+ ```json
364
+ {
365
+ "operator": "+"
366
+ }
367
+ ```
368
+
369
+ ---
370
+
371
+ ## 14. `omdNumberTile`
372
+
373
+ `omdNumberTile` represents a visual tile with dots, often used in counting or grouping activities.
374
+
375
+ ### Schema
376
+ ```json
377
+ {
378
+ "value": "number",
379
+ "size": "string",
380
+ "dotsPerColumn": "number",
381
+ "backgroundColor": "string",
382
+ "dotColor": "string"
383
+ }
384
+ ```
385
+
386
+ ### Example
387
+ ```json
388
+ {
389
+ "value": 10,
390
+ "size": "medium",
391
+ "dotsPerColumn": 5,
392
+ "backgroundColor": "#FFFFFF",
393
+ "dotColor": "#000000"
394
+ }
395
+ ```
396
+
397
+ ---
398
+
399
+ ## 15. `omdNumberLine`
400
+
401
+ `omdNumberLine` represents a number line with labeled ticks and optional dots.
402
+
403
+ ### Schema
404
+ ```json
405
+ {
406
+ "min": "number",
407
+ "max": "number",
408
+ "dotValues": ["array"],
409
+ "label": "string"
410
+ }
411
+ ```
412
+
413
+ ### Example
414
+ ```json
415
+ {
416
+ "min": 0,
417
+ "max": 10,
418
+ "dotValues": [1, 5, 7],
419
+ "label": "Number Line"
420
+ }
421
+ ```
422
+
423
+ ---
424
+
425
+ ## 16. `omdNumber`
426
+
427
+ `omdNumber` represents a single numeric value, such as "42".
428
+
429
+ ### Schema
430
+ ```json
431
+ {
432
+ "value": "number"
433
+ }
434
+ ```
435
+
436
+ ### Example
437
+ ```json
438
+ {
439
+ "value": 42
440
+ }
441
+ ```
442
+
443
+ ---
444
+
445
+ ## 17. `omdFunction`
446
+
447
+ `omdFunction` represents a mathematical function, such as "f(x) = 2x + 1".
448
+
449
+ ### Schema
450
+ ```json
451
+ {
452
+ "name": "string",
453
+ "inputVariables": ["array"],
454
+ "expression": "object"
455
+ }
456
+ ```
457
+
458
+ ### Example
459
+ ```json
460
+ {
461
+ "name": "f",
462
+ "inputVariables": ["x"],
463
+ "expression": { "omdType": "term", "coefficient": 2, "variable": "x", "exponent": 1 }
464
+ }
465
+ ```
466
+
467
+ ---
468
+
469
+ ## 18. `omdExpression`
470
+
471
+ `omdExpression` represents a mathematical expression, such as "3x^2 + 5".
472
+
473
+ ### Schema
474
+ ```json
475
+ {
476
+ "termsAndOpers": ["array"]
477
+ }
478
+ ```
479
+
480
+ ### Example
481
+ ```json
482
+ {
483
+ "termsAndOpers": [
484
+ { "omdType": "term", "coefficient": 3, "variable": "x", "exponent": 2 },
485
+ { "omdType": "operator", "operator": "+" },
486
+ { "omdType": "number", "value": 5 }
487
+ ]
488
+ }
489
+ ```
490
+
491
+ ---
492
+
493
+ ## 19. `omdCoordinatePlane`
494
+
495
+ `omdCoordinatePlane` represents a 2D coordinate plane with axes, gridlines, and optional shapes or plots.
496
+
497
+ ### Schema
498
+ ```json
499
+ {
500
+ "graphEquations": ["array"],
501
+ "lineSegments": ["array"],
502
+ "dotValues": ["array"],
503
+ "shapeSet": ["array"],
504
+ "xMin": "number",
505
+ "xMax": "number",
506
+ "yMin": "number",
507
+ "yMax": "number",
508
+ "xLabel": "string",
509
+ "yLabel": "string",
510
+ "axisLabelOffsetPx": "number",
511
+ "size": "string",
512
+ "tickInterval": "number",
513
+ "forceAllTickLabels": "boolean",
514
+ "tickLabelOffsetPx": "number",
515
+ "showTickLabels": "boolean",
516
+ "backgroundColor": "string",
517
+ "backgroundCornerRadius": "number",
518
+ "backgroundOpacity": "number",
519
+ "showBackground": "boolean"
520
+ }
521
+ ```
522
+
523
+ ### Example
44
524
  ```json
45
525
  {
46
- "omdType": "coordinatePlane",
47
- "xMin": number,
48
- "xMax": number,
49
- "yMin": number,
50
- "yMax": number,
51
- "xLabel": string,
52
- "yLabel": string,
53
- "axisLabelOffsetPx": number,
54
- "size": "small" | "medium" | "large",
55
- "tickInterval": number,
56
- "tickLabelOffsetPx": number,
57
- "forceAllTickLabels": boolean,
58
526
  "graphEquations": [
59
- {
60
- "equation": string, // supports 'y = ...' or expression in x
61
- "domain": { "min": number, "max": number },
62
- "color": string,
63
- "strokeWidth": number,
64
- "label": string,
65
- "labelAtX": number,
66
- "labelPosition": "above" | "below" | "left" | "right"
67
- }
527
+ { "equation": "y = x^2", "color": "blue", "strokeWidth": 2, "domain": { "min": -5, "max": 5 } }
68
528
  ],
69
529
  "lineSegments": [
70
- { "point1": [number, number], "point2": [number, number], "color": string, "strokeWidth": number }
530
+ { "point1": [0, 0], "point2": [1, 1], "color": "red", "strokeWidth": 2 }
71
531
  ],
72
- "dotValues": [ [number, number, string?], ... ],
532
+ "dotValues": [[0, 0, "green"], [1, 1, "blue"]],
73
533
  "shapeSet": [
74
- { "omdType": "rightTriangle" | "isoscelesTriangle" | "rectangle" | "ellipse" | "circle" | "regularPolygon", /* shape-specific fields */ }
75
- ]
534
+ { "omdType": "circle", "radius": 5, "color": "yellow" }
535
+ ],
536
+ "xMin": -5,
537
+ "xMax": 5,
538
+ "yMin": -5,
539
+ "yMax": 5,
540
+ "xLabel": "X-Axis",
541
+ "yLabel": "Y-Axis",
542
+ "axisLabelOffsetPx": 20,
543
+ "size": "medium",
544
+ "tickInterval": 1,
545
+ "forceAllTickLabels": true,
546
+ "tickLabelOffsetPx": 5,
547
+ "showTickLabels": true,
548
+ "backgroundColor": "#FFFFFF",
549
+ "backgroundCornerRadius": 15,
550
+ "backgroundOpacity": 1.0,
551
+ "showBackground": true
76
552
  }
77
553
  ```
78
554
 
79
- - graphEquations: each equation plotted within its domain.
80
- - lineSegments: raw segment overlays.
81
- - dotValues: points as [x, y, optionalColor].
82
- - shapeSet: geometric overlays rendered in plane units.
555
+ ---
556
+
557
+ ## 20. `omdEquation`
83
558
 
84
- ## table
559
+ `omdEquation` represents a mathematical equation, such as "x + 2 = 5".
560
+
561
+ ### Schema
85
562
  ```json
86
563
  {
87
- "omdType": "table",
88
- "title": string,
89
- "headers": [string, ...],
90
- "data": [ [any, ...], ... ], // array-of-arrays; columns align with headers
91
- "equation": string, // optional; generates rows from y=f(x) takes precendence over any data provided
92
- "xMin": number,
93
- "xMax": number,
94
- "stepSize": number,
95
- "fontFamily": string,
96
- "headerFontFamily": string,
97
- "fontSize": number,
98
- "headerFontSize": number,
99
- "cellHeight": number,
100
- "headerHeight": number,
101
- "minCellWidth": number,
102
- "maxCellWidth": number,
103
- "padding": number
564
+ "leftExpression": "object",
565
+ "rightExpression": "object",
566
+ "equation": "string"
104
567
  }
105
568
  ```
106
569
 
107
- - If equation is provided, rows are generated in range [xMin, xMax] with stepSize.
108
- - When autoSizeCells is true, widths are inferred from content.
109
-
570
+ ### Example
571
+ ```json
572
+ {
573
+ "leftExpression": { "omdType": "term", "coefficient": 1, "variable": "x", "exponent": 1 },
574
+ "rightExpression": { "omdType": "number", "value": 5 },
575
+ "equation": "x + 2 = 5"
576
+ }
577
+ ```