@teachinglab/omd 0.6.1 → 0.6.2

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.
Files changed (198) hide show
  1. package/README.md +257 -251
  2. package/README.old.md +137 -137
  3. package/canvas/core/canvasConfig.js +202 -202
  4. package/canvas/drawing/segment.js +167 -167
  5. package/canvas/drawing/stroke.js +385 -385
  6. package/canvas/events/eventManager.js +444 -444
  7. package/canvas/events/pointerEventHandler.js +262 -262
  8. package/canvas/index.js +48 -48
  9. package/canvas/tools/PointerTool.js +71 -71
  10. package/canvas/tools/tool.js +222 -222
  11. package/canvas/utils/boundingBox.js +377 -377
  12. package/canvas/utils/mathUtils.js +258 -258
  13. package/docs/api/configuration-options.md +198 -198
  14. package/docs/api/eventManager.md +82 -82
  15. package/docs/api/focusFrameManager.md +144 -144
  16. package/docs/api/index.md +105 -105
  17. package/docs/api/main.md +62 -62
  18. package/docs/api/omdBinaryExpressionNode.md +86 -86
  19. package/docs/api/omdCanvas.md +83 -83
  20. package/docs/api/omdConfigManager.md +112 -112
  21. package/docs/api/omdConstantNode.md +52 -52
  22. package/docs/api/omdDisplay.md +87 -87
  23. package/docs/api/omdEquationNode.md +174 -174
  24. package/docs/api/omdEquationSequenceNode.md +258 -258
  25. package/docs/api/omdEquationStack.md +192 -192
  26. package/docs/api/omdFunctionNode.md +82 -82
  27. package/docs/api/omdGroupNode.md +78 -78
  28. package/docs/api/omdHelpers.md +87 -87
  29. package/docs/api/omdLeafNode.md +85 -85
  30. package/docs/api/omdNode.md +201 -201
  31. package/docs/api/omdOperationDisplayNode.md +117 -117
  32. package/docs/api/omdOperatorNode.md +91 -91
  33. package/docs/api/omdParenthesisNode.md +133 -133
  34. package/docs/api/omdPopup.md +191 -191
  35. package/docs/api/omdPowerNode.md +131 -131
  36. package/docs/api/omdRationalNode.md +144 -144
  37. package/docs/api/omdSequenceNode.md +128 -128
  38. package/docs/api/omdSimplification.md +78 -78
  39. package/docs/api/omdSqrtNode.md +144 -144
  40. package/docs/api/omdStepVisualizer.md +146 -146
  41. package/docs/api/omdStepVisualizerHighlighting.md +65 -65
  42. package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
  43. package/docs/api/omdStepVisualizerLayout.md +70 -70
  44. package/docs/api/omdStepVisualizerNodeUtils.md +140 -140
  45. package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
  46. package/docs/api/omdToolbar.md +130 -130
  47. package/docs/api/omdTranscriptionService.md +95 -95
  48. package/docs/api/omdTreeDiff.md +169 -169
  49. package/docs/api/omdUnaryExpressionNode.md +137 -137
  50. package/docs/api/omdUtilities.md +82 -82
  51. package/docs/api/omdVariableNode.md +123 -123
  52. package/docs/api/selectTool.md +74 -74
  53. package/docs/api/simplificationEngine.md +97 -97
  54. package/docs/api/simplificationRules.md +76 -76
  55. package/docs/api/simplificationUtils.md +64 -64
  56. package/docs/api/transcribe.md +43 -43
  57. package/docs/api-reference.md +85 -85
  58. package/docs/index.html +453 -453
  59. package/docs/index.md +38 -38
  60. package/docs/omd-objects.md +258 -258
  61. package/index.js +79 -79
  62. package/jsvg/index.js +3 -0
  63. package/jsvg/jsvg.js +898 -898
  64. package/jsvg/jsvgComponents.js +357 -358
  65. package/npm-docs/DOCUMENTATION_SUMMARY.md +220 -220
  66. package/npm-docs/README.md +251 -251
  67. package/npm-docs/api/api-reference.md +85 -85
  68. package/npm-docs/api/configuration-options.md +198 -198
  69. package/npm-docs/api/eventManager.md +82 -82
  70. package/npm-docs/api/expression-nodes.md +561 -561
  71. package/npm-docs/api/focusFrameManager.md +144 -144
  72. package/npm-docs/api/index.md +105 -105
  73. package/npm-docs/api/main.md +62 -62
  74. package/npm-docs/api/omdBinaryExpressionNode.md +86 -86
  75. package/npm-docs/api/omdCanvas.md +83 -83
  76. package/npm-docs/api/omdConfigManager.md +112 -112
  77. package/npm-docs/api/omdConstantNode.md +52 -52
  78. package/npm-docs/api/omdDisplay.md +87 -87
  79. package/npm-docs/api/omdEquationNode.md +174 -174
  80. package/npm-docs/api/omdEquationSequenceNode.md +258 -258
  81. package/npm-docs/api/omdEquationStack.md +192 -192
  82. package/npm-docs/api/omdFunctionNode.md +82 -82
  83. package/npm-docs/api/omdGroupNode.md +78 -78
  84. package/npm-docs/api/omdHelpers.md +87 -87
  85. package/npm-docs/api/omdLeafNode.md +85 -85
  86. package/npm-docs/api/omdNode.md +201 -201
  87. package/npm-docs/api/omdOperationDisplayNode.md +117 -117
  88. package/npm-docs/api/omdOperatorNode.md +91 -91
  89. package/npm-docs/api/omdParenthesisNode.md +133 -133
  90. package/npm-docs/api/omdPopup.md +191 -191
  91. package/npm-docs/api/omdPowerNode.md +131 -131
  92. package/npm-docs/api/omdRationalNode.md +144 -144
  93. package/npm-docs/api/omdSequenceNode.md +128 -128
  94. package/npm-docs/api/omdSimplification.md +78 -78
  95. package/npm-docs/api/omdSqrtNode.md +144 -144
  96. package/npm-docs/api/omdStepVisualizer.md +146 -146
  97. package/npm-docs/api/omdStepVisualizerHighlighting.md +65 -65
  98. package/npm-docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
  99. package/npm-docs/api/omdStepVisualizerLayout.md +70 -70
  100. package/npm-docs/api/omdStepVisualizerNodeUtils.md +140 -140
  101. package/npm-docs/api/omdStepVisualizerTextBoxes.md +76 -76
  102. package/npm-docs/api/omdToolbar.md +130 -130
  103. package/npm-docs/api/omdTranscriptionService.md +95 -95
  104. package/npm-docs/api/omdTreeDiff.md +169 -169
  105. package/npm-docs/api/omdUnaryExpressionNode.md +137 -137
  106. package/npm-docs/api/omdUtilities.md +82 -82
  107. package/npm-docs/api/omdVariableNode.md +123 -123
  108. package/npm-docs/api/selectTool.md +74 -74
  109. package/npm-docs/api/simplificationEngine.md +97 -97
  110. package/npm-docs/api/simplificationRules.md +76 -76
  111. package/npm-docs/api/simplificationUtils.md +64 -64
  112. package/npm-docs/api/transcribe.md +43 -43
  113. package/npm-docs/guides/equations.md +854 -854
  114. package/npm-docs/guides/factory-functions.md +354 -354
  115. package/npm-docs/guides/getting-started.md +318 -318
  116. package/npm-docs/guides/quick-examples.md +525 -525
  117. package/npm-docs/guides/visualizations.md +682 -682
  118. package/npm-docs/index.html +12 -0
  119. package/npm-docs/json-schemas.md +826 -826
  120. package/omd/config/omdConfigManager.js +279 -267
  121. package/omd/core/index.js +158 -158
  122. package/omd/core/omdEquationStack.js +546 -546
  123. package/omd/core/omdUtilities.js +113 -113
  124. package/omd/display/omdDisplay.js +969 -962
  125. package/omd/display/omdToolbar.js +501 -501
  126. package/omd/nodes/omdBinaryExpressionNode.js +459 -459
  127. package/omd/nodes/omdConstantNode.js +141 -141
  128. package/omd/nodes/omdEquationNode.js +1327 -1327
  129. package/omd/nodes/omdFunctionNode.js +351 -351
  130. package/omd/nodes/omdGroupNode.js +67 -67
  131. package/omd/nodes/omdLeafNode.js +76 -76
  132. package/omd/nodes/omdNode.js +556 -556
  133. package/omd/nodes/omdOperationDisplayNode.js +321 -321
  134. package/omd/nodes/omdOperatorNode.js +108 -108
  135. package/omd/nodes/omdParenthesisNode.js +292 -292
  136. package/omd/nodes/omdPowerNode.js +235 -235
  137. package/omd/nodes/omdRationalNode.js +295 -295
  138. package/omd/nodes/omdSqrtNode.js +307 -307
  139. package/omd/nodes/omdUnaryExpressionNode.js +227 -227
  140. package/omd/nodes/omdVariableNode.js +122 -122
  141. package/omd/simplification/omdSimplification.js +140 -140
  142. package/omd/simplification/omdSimplificationEngine.js +887 -887
  143. package/omd/simplification/package.json +5 -5
  144. package/omd/simplification/rules/binaryRules.js +1037 -1037
  145. package/omd/simplification/rules/functionRules.js +111 -111
  146. package/omd/simplification/rules/index.js +48 -48
  147. package/omd/simplification/rules/parenthesisRules.js +19 -19
  148. package/omd/simplification/rules/powerRules.js +143 -143
  149. package/omd/simplification/rules/rationalRules.js +725 -725
  150. package/omd/simplification/rules/sqrtRules.js +48 -48
  151. package/omd/simplification/rules/unaryRules.js +37 -37
  152. package/omd/simplification/simplificationRules.js +31 -31
  153. package/omd/simplification/simplificationUtils.js +1055 -1055
  154. package/omd/step-visualizer/omdStepVisualizer.js +947 -947
  155. package/omd/step-visualizer/omdStepVisualizerHighlighting.js +246 -246
  156. package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
  157. package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +200 -200
  158. package/omd/utils/aiNextEquationStep.js +106 -106
  159. package/omd/utils/omdNodeOverlay.js +638 -638
  160. package/omd/utils/omdPopup.js +1203 -1203
  161. package/omd/utils/omdStepVisualizerInteractiveSteps.js +684 -684
  162. package/omd/utils/omdStepVisualizerNodeUtils.js +267 -267
  163. package/omd/utils/omdTranscriptionService.js +123 -123
  164. package/omd/utils/omdTreeDiff.js +733 -733
  165. package/package.json +59 -57
  166. package/readme.html +184 -120
  167. package/src/index.js +74 -74
  168. package/src/json-schemas.md +576 -576
  169. package/src/omd-json-samples.js +147 -147
  170. package/src/omdApp.js +391 -391
  171. package/src/omdAppCanvas.js +335 -335
  172. package/src/omdBalanceHanger.js +199 -199
  173. package/src/omdColor.js +13 -13
  174. package/src/omdCoordinatePlane.js +541 -541
  175. package/src/omdExpression.js +115 -115
  176. package/src/omdFactory.js +150 -150
  177. package/src/omdFunction.js +114 -114
  178. package/src/omdMetaExpression.js +290 -290
  179. package/src/omdNaturalExpression.js +563 -563
  180. package/src/omdNode.js +383 -383
  181. package/src/omdNumber.js +52 -52
  182. package/src/omdNumberLine.js +114 -112
  183. package/src/omdNumberTile.js +118 -118
  184. package/src/omdOperator.js +72 -72
  185. package/src/omdPowerExpression.js +91 -91
  186. package/src/omdProblem.js +259 -259
  187. package/src/omdRatioChart.js +251 -251
  188. package/src/omdRationalExpression.js +114 -114
  189. package/src/omdSampleData.js +215 -215
  190. package/src/omdShapes.js +512 -512
  191. package/src/omdSpinner.js +151 -151
  192. package/src/omdString.js +49 -49
  193. package/src/omdTable.js +498 -498
  194. package/src/omdTapeDiagram.js +244 -244
  195. package/src/omdTerm.js +91 -91
  196. package/src/omdTileEquation.js +349 -349
  197. package/src/omdUtils.js +84 -84
  198. package/src/omdVariable.js +51 -51
package/src/omdShapes.js CHANGED
@@ -1,512 +1,512 @@
1
-
2
- import { omdColor } from "./omdColor.js";
3
- import { jsvgGroup, jsvgPath, jsvgLine, jsvgTextLine, jsvgEllipse } from "@teachinglab/jsvg";
4
-
5
- export class omdRightTriangle extends jsvgGroup
6
- {
7
- constructor()
8
- {
9
- // initialization
10
- super();
11
-
12
- this.type = "omdRightTriangle";
13
-
14
- this.horizontalLeg = 5;
15
- this.verticalLeg = 10;
16
- this.angleA = 0;
17
- this.angleB = 0;
18
- this.hypotenuse = 0;
19
- this.unitScale = 10;
20
-
21
- this.showLabels = false;
22
-
23
- this.shapePath = new jsvgPath();
24
- this.shapePath.setStrokeColor( "black" );
25
- this.shapePath.setStrokeWidth( 2 );
26
- this.shapePath.setFillColor( omdColor.lightGray );
27
- this.addChild( this.shapePath );
28
-
29
- this.labelsHolder = new jsvgGroup();
30
- this.addChild( this.labelsHolder );
31
-
32
- this.updateLayout();
33
- }
34
-
35
- loadFromJSON( data )
36
- {
37
- if ( typeof data.horizontalLeg != "undefined" )
38
- this.horizontalLeg = data.horizontalLeg;
39
-
40
- if ( typeof data.verticalLeg != "undefined" )
41
- this.verticalLeg = data.verticalLeg;
42
-
43
- if ( typeof data.angleA != "undefined" )
44
- this.angleA = data.angleA;
45
-
46
- if ( typeof data.angleB != "undefined" )
47
- this.angleB = data.angleB;
48
-
49
- if ( typeof data.hypotenuse != "undefined" )
50
- this.hypotenuse = data.hypotenuse;
51
-
52
- if ( typeof data.unitScale != "undefined" )
53
- this.unitScale = data.unitScale;
54
-
55
- if ( typeof data.showLabels != "undefined" )
56
- this.showLabels = data.showLabels;
57
-
58
- // calculate leg lengths
59
- if ( this.angleA && this.hypotenuse )
60
- {
61
- var A = Math.PI * this.angleA / 180.0;
62
- this.horizontalLeg = Math.cos(A) * this.hypotenuse;
63
- this.verticalLeg = Math.sin(A) * this.hypotenuse;
64
- }
65
-
66
- this.updateLayout();
67
- }
68
-
69
- updateLayout()
70
- {
71
- // Center the triangle within the viewBox
72
- const offsetX = 10; // Left margin
73
- const offsetY = this.unitScale * this.verticalLeg + 10; // Bottom margin
74
-
75
- this.shapePath.clearPoints();
76
- this.shapePath.addPoint(offsetX, offsetY);
77
- this.shapePath.addPoint(offsetX + this.unitScale * this.horizontalLeg, offsetY);
78
- this.shapePath.addPoint(offsetX + this.unitScale * this.horizontalLeg, offsetY - this.unitScale * this.verticalLeg);
79
- this.shapePath.addPoint(offsetX, offsetY);
80
-
81
- this.shapePath.updatePath();
82
-
83
- if ( this.showLabels )
84
- {
85
- this.labelsHolder.removeAllChildren();
86
- var L = new omdShapeLabelSet();
87
- var A = this.horizontalLeg.toString();
88
- var B = this.verticalLeg.toString();
89
- var C = "";
90
- L.initializeWithShapePath( this.shapePath, [A,B,C] );
91
- this.labelsHolder.addChild( L );
92
- }
93
-
94
- // Set viewBox to center the shape
95
- this.width = this.unitScale * this.horizontalLeg + 20;
96
- this.height = this.unitScale * this.verticalLeg + 20;
97
- this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
98
- }
99
- }
100
-
101
-
102
-
103
- export class omdIsoscelesTriangle extends jsvgGroup
104
- {
105
- constructor()
106
- {
107
- // initialization
108
- super();
109
-
110
- this.type = "omdIsoscelesTriangle";
111
-
112
- this.triangleBase = 5;
113
- this.triangleHeight = 10;
114
- this.unitScale = 10;
115
-
116
- this.showLabels = false;
117
-
118
- this.shapePath = new jsvgPath();
119
- this.shapePath.setStrokeColor( "black" );
120
- this.shapePath.setStrokeWidth( 2 );
121
- this.shapePath.setFillColor( omdColor.lightGray );
122
- this.addChild( this.shapePath );
123
-
124
- this.labelsHolder = new jsvgGroup();
125
- this.addChild( this.labelsHolder );
126
-
127
- this.updateLayout();
128
- }
129
-
130
- loadFromJSON( data )
131
- {
132
- if ( typeof data.base != "undefined" )
133
- this.triangleBase = data.base;
134
-
135
- if ( typeof data.height != "undefined" )
136
- this.triangleHeight = data.height;
137
-
138
- if ( typeof data.unitScale != "undefined" )
139
- this.unitScale = data.unitScale;
140
-
141
- if ( typeof data.showLabels != "undefined" )
142
- this.showLabels = data.showLabels;
143
-
144
- this.updateLayout();
145
- }
146
-
147
- updateLayout()
148
- {
149
- this.shapePath.clearPoints();
150
-
151
- this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
152
- this.shapePath.addPoint( 0.5*this.unitScale*this.triangleBase, 0 );
153
- this.shapePath.addPoint( 0, -1.0*this.unitScale*this.triangleHeight );
154
- this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
155
-
156
- this.shapePath.updatePath();
157
-
158
- if ( this.showLabels )
159
- {
160
- this.labelsHolder.removeAllChildren();
161
- var L = new omdShapeLabelSet();
162
- L.initializeWithShapePath( this.shapePath );
163
- this.labelsHolder.addChild( L );
164
- }
165
-
166
- // Set dimensions and viewBox for API compatibility
167
- this.width = this.unitScale * this.triangleBase + 20;
168
- this.height = this.unitScale * this.triangleHeight + 20;
169
- this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
170
- }
171
- }
172
-
173
- export class omdRectangle extends jsvgGroup
174
- {
175
- constructor()
176
- {
177
- // initialization
178
- super();
179
-
180
- this.type = "omdRectangle";
181
-
182
- this.rectWidth = 10;
183
- this.rectHeight = 10;
184
- this.unitScale = 10;
185
-
186
- this.showLabels = false;
187
-
188
- this.shapePath = new jsvgPath();
189
- this.shapePath.setStrokeColor( "black" );
190
- this.shapePath.setStrokeWidth( 2 );
191
- this.shapePath.setFillColor( omdColor.lightGray );
192
- this.addChild( this.shapePath );
193
-
194
- this.labelsHolder = new jsvgGroup();
195
- this.addChild( this.labelsHolder );
196
-
197
- this.updateLayout();
198
- }
199
-
200
- loadFromJSON( data )
201
- {
202
- if ( typeof data.width != "undefined" )
203
- this.rectWidth = data.width;
204
-
205
- if ( typeof data.height != "undefined" )
206
- this.rectHeight = data.height;
207
-
208
- if ( typeof data.unitScale != "undefined" )
209
- this.unitScale = data.unitScale;
210
-
211
- if ( typeof data.showLabels != "undefined" )
212
- this.showLabels = data.showLabels;
213
-
214
- this.updateLayout();
215
- }
216
-
217
- updateLayout()
218
- {
219
- // Center the rectangle within the viewBox
220
- const offsetX = 10;
221
- const offsetY = this.unitScale * this.rectHeight + 10;
222
-
223
- this.shapePath.clearPoints();
224
- this.shapePath.addPoint(offsetX, offsetY);
225
- this.shapePath.addPoint(offsetX + this.unitScale * this.rectWidth, offsetY);
226
- this.shapePath.addPoint(offsetX + this.unitScale * this.rectWidth, offsetY - this.unitScale * this.rectHeight);
227
- this.shapePath.addPoint(offsetX, offsetY - this.unitScale * this.rectHeight);
228
- this.shapePath.addPoint(offsetX, offsetY);
229
-
230
- this.shapePath.updatePath();
231
-
232
- if ( this.showLabels )
233
- {
234
- this.labelsHolder.removeAllChildren();
235
- var L = new omdShapeLabelSet();
236
- var A = this.rectWidth.toString();
237
- var B = this.rectHeight.toString();
238
- L.initializeWithShapePath( this.shapePath, [A,B,"",""] );
239
- this.labelsHolder.addChild( L );
240
- }
241
-
242
- // Set viewBox
243
- this.width = this.unitScale * this.rectWidth + 20;
244
- this.height = this.unitScale * this.rectHeight + 20;
245
- this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
246
- }
247
- }
248
-
249
-
250
- export class omdEllipse extends jsvgGroup
251
- {
252
- constructor()
253
- {
254
- // initialization
255
- super();
256
-
257
- this.type = "omdEllipse";
258
-
259
- this.rectWidth = 10;
260
- this.rectHeight = 5;
261
- this.unitScale = 10;
262
-
263
- this.shapePath = new jsvgEllipse();
264
- this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
265
- this.shapePath.setStrokeColor( "black" );
266
- this.shapePath.setStrokeWidth( 2 );
267
- this.shapePath.setFillColor( omdColor.lightGray );
268
- this.addChild( this.shapePath );
269
-
270
- this.updateLayout();
271
- }
272
-
273
- loadFromJSON( data )
274
- {
275
- if ( typeof data.width != "undefined" )
276
- this.rectWidth = data.width;
277
-
278
- if ( typeof data.height != "undefined" )
279
- this.rectHeight = data.height;
280
-
281
- if ( typeof data.unitScale != "undefined" )
282
- this.unitScale = data.unitScale;
283
-
284
- this.updateLayout();
285
- }
286
-
287
- updateLayout()
288
- {
289
- this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
290
-
291
- // Set dimensions and viewBox for API compatibility
292
- this.width = this.rectWidth * this.unitScale + 20;
293
- this.height = this.rectHeight * this.unitScale + 20;
294
- this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
295
- }
296
- }
297
-
298
- export class omdCircle extends jsvgGroup
299
- {
300
- constructor()
301
- {
302
- // initialization
303
- super();
304
-
305
- this.type = "omdCircle";
306
-
307
- this.radius = 5;
308
- this.unitScale = 10;
309
-
310
- this.shapePath = new jsvgEllipse();
311
- this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
312
- this.shapePath.setStrokeColor( "black" );
313
- this.shapePath.setStrokeWidth( 2 );
314
- this.shapePath.setFillColor( omdColor.lightGray );
315
- this.addChild( this.shapePath );
316
-
317
- this.updateLayout();
318
- }
319
-
320
- loadFromJSON( data )
321
- {
322
- if ( typeof data.radius != "undefined" )
323
- this.radius = data.radius;
324
-
325
- if ( typeof data.unitScale != "undefined" )
326
- this.unitScale = data.unitScale;
327
-
328
- this.updateLayout();
329
- }
330
-
331
- updateLayout()
332
- {
333
- this.shapePath.setWidthAndHeight( 2.0*this.radius*this.unitScale, 2.0*this.radius*this.unitScale );
334
-
335
- // Set dimensions and viewBox for API compatibility
336
- this.width = 2.0 * this.radius * this.unitScale + 20;
337
- this.height = 2.0 * this.radius * this.unitScale + 20;
338
- this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
339
- }
340
- }
341
-
342
- export class omdRegularPolygon extends jsvgGroup
343
- {
344
- constructor()
345
- {
346
- // initialization
347
- super();
348
-
349
- this.type = "omdRegularPolygon";
350
-
351
- this.radius = 5;
352
- this.numberOfSides = 5;
353
- this.unitScale = 10;
354
-
355
- this.showLabels = false;
356
-
357
- this.shapePath = new jsvgPath();
358
- this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
359
- this.shapePath.setStrokeColor( "black" );
360
- this.shapePath.setStrokeWidth( 2 );
361
- this.shapePath.setFillColor( omdColor.lightGray );
362
- this.addChild( this.shapePath );
363
-
364
- this.labelsHolder = new jsvgGroup();
365
- this.addChild( this.labelsHolder );
366
-
367
- this.updateLayout();
368
- }
369
-
370
- loadFromJSON( data )
371
- {
372
- if ( typeof data.radius != "undefined" )
373
- this.radius = data.radius;
374
-
375
- if ( typeof data.numberOfSides != "undefined" )
376
- this.numberOfSides = data.numberOfSides;
377
-
378
- if ( typeof data.unitScale != "undefined" )
379
- this.unitScale = data.unitScale;
380
-
381
-
382
- if ( typeof data.showLabels != "undefined" )
383
- this.showLabels = data.showLabels;
384
-
385
- this.updateLayout();
386
- }
387
-
388
- updateLayout()
389
- {
390
- this.shapePath.clearPoints();
391
-
392
- var angleOffset = 0;
393
- if ( this.numberOfSides % 2 == 1 )
394
- {
395
- angleOffset = Math.PI / this.numberOfSides * 0.5; // shift angle for odd number of sides
396
- if ( ((this.numberOfSides-1)/2) % 2 == 0 )
397
- angleOffset *= -1.0;
398
- }
399
-
400
- for( var i=0; i<=this.numberOfSides; i++ )
401
- {
402
- var A = -2.0 * Math.PI / this.numberOfSides * i;
403
- A += angleOffset;
404
- var pX = Math.cos(A) * this.radius * this.unitScale;
405
- var pY = Math.sin(A) * this.radius * this.unitScale;
406
- this.shapePath.addPoint( pX, pY );
407
- }
408
-
409
- this.shapePath.updatePath();
410
-
411
- if ( this.showLabels )
412
- {
413
- // make label
414
- this.labelsHolder.removeAllChildren();
415
- var L = new omdShapeLabelSet();
416
- var sideLength = 2.0 * this.radius * Math.sin( Math.PI / this.numberOfSides );
417
- var A = sideLength.toFixed(2);
418
- L.initializeWithShapePath( this.shapePath, [ A ] );
419
- this.labelsHolder.addChild( L );
420
- }
421
-
422
- // Set dimensions and viewBox for API compatibility
423
- this.width = 2.0 * this.radius * this.unitScale + 20;
424
- this.height = 2.0 * this.radius * this.unitScale + 20;
425
- this.svgObject.setAttribute('viewBox', `-${this.width/2} -${this.height/2} ${this.width} ${this.height}`);
426
- }
427
- }
428
-
429
-
430
- export class omdShapeLabelSet extends jsvgGroup
431
- {
432
- constructor()
433
- {
434
- // initialization
435
- super();
436
- }
437
-
438
- initializeWithShapePath( shapePath, labelTextArray=[] )
439
- {
440
- // this assumes counterclockwise path
441
-
442
- // create lines
443
- for( var i=0; i<shapePath.points.length-1; i++ )
444
- {
445
- if ( i >= labelTextArray.length || labelTextArray[i].length == 0 )
446
- continue;
447
-
448
- // get points
449
- var point0 = shapePath.points[i];
450
- var x0 = point0.x;
451
- var y0 = point0.y;
452
-
453
- var point1 = shapePath.points[i+1];
454
- var x1 = point1.x;
455
- var y1 = point1.y;
456
-
457
- // get normalized vector
458
- var dX = x1 - x0;
459
- var dY = y1 - y0;
460
- var L = Math.sqrt( dX*dX + dY*dY );
461
- dX /= L;
462
- dY /= L;
463
-
464
- // get normal
465
- var normalX = -1.0 * dY;
466
- var normalY = dX;
467
-
468
- // make line
469
- var labelLine = new jsvgLine();
470
- var newLineX0 = x0 + normalX * 10.0;
471
- var newLineY0 = y0 + normalY * 10.0;
472
- var newLineX1 = x1 + normalX * 10.0;
473
- var newLineY1 = y1 + normalY * 10.0;
474
- labelLine.setEndpoints( newLineX0, newLineY0, newLineX1, newLineY1 );
475
- this.addChild( labelLine );
476
-
477
- // center point
478
- var centerX = (x0 + x1) / 2.0;
479
- var centerY = (y0 + y1) / 2.0;
480
-
481
- var angle = Math.atan2( dY, dX );
482
- angle *= 180 / Math.PI;
483
- angle += 180.0;
484
- angle = angle % 360.0;
485
- var originalAngle = angle;
486
-
487
- // flip upside-down text
488
- var offset = 0;
489
- if ( angle > 90 && angle < 270 )
490
- {
491
- angle -= 180.0;
492
- offset += 10.0;
493
- }
494
-
495
- // label text
496
- var textCenterX = centerX + normalX * (15.0+offset);
497
- var textCenterY = centerY + normalY * (15.0+offset);
498
- var labelText = new jsvgTextLine();
499
- labelText.setAlignment("center");
500
- labelText.setFontFamily( "Albert Sans" );
501
- labelText.setFontColor( "black" );
502
- labelText.setFontSize( 12 );
503
- labelText.setPosition( textCenterX, textCenterY );
504
- labelText.setRotation( angle );
505
- this.addChild( labelText );
506
-
507
- labelText.setText( labelTextArray[i] );
508
- }
509
- }
510
-
511
- }
512
-
1
+
2
+ import { omdColor } from "./omdColor.js";
3
+ import { jsvgGroup, jsvgPath, jsvgLine, jsvgTextLine, jsvgEllipse } from "@teachinglab/jsvg";
4
+
5
+ export class omdRightTriangle extends jsvgGroup
6
+ {
7
+ constructor()
8
+ {
9
+ // initialization
10
+ super();
11
+
12
+ this.type = "omdRightTriangle";
13
+
14
+ this.horizontalLeg = 5;
15
+ this.verticalLeg = 10;
16
+ this.angleA = 0;
17
+ this.angleB = 0;
18
+ this.hypotenuse = 0;
19
+ this.unitScale = 10;
20
+
21
+ this.showLabels = false;
22
+
23
+ this.shapePath = new jsvgPath();
24
+ this.shapePath.setStrokeColor( "black" );
25
+ this.shapePath.setStrokeWidth( 2 );
26
+ this.shapePath.setFillColor( omdColor.lightGray );
27
+ this.addChild( this.shapePath );
28
+
29
+ this.labelsHolder = new jsvgGroup();
30
+ this.addChild( this.labelsHolder );
31
+
32
+ this.updateLayout();
33
+ }
34
+
35
+ loadFromJSON( data )
36
+ {
37
+ if ( typeof data.horizontalLeg != "undefined" )
38
+ this.horizontalLeg = data.horizontalLeg;
39
+
40
+ if ( typeof data.verticalLeg != "undefined" )
41
+ this.verticalLeg = data.verticalLeg;
42
+
43
+ if ( typeof data.angleA != "undefined" )
44
+ this.angleA = data.angleA;
45
+
46
+ if ( typeof data.angleB != "undefined" )
47
+ this.angleB = data.angleB;
48
+
49
+ if ( typeof data.hypotenuse != "undefined" )
50
+ this.hypotenuse = data.hypotenuse;
51
+
52
+ if ( typeof data.unitScale != "undefined" )
53
+ this.unitScale = data.unitScale;
54
+
55
+ if ( typeof data.showLabels != "undefined" )
56
+ this.showLabels = data.showLabels;
57
+
58
+ // calculate leg lengths
59
+ if ( this.angleA && this.hypotenuse )
60
+ {
61
+ var A = Math.PI * this.angleA / 180.0;
62
+ this.horizontalLeg = Math.cos(A) * this.hypotenuse;
63
+ this.verticalLeg = Math.sin(A) * this.hypotenuse;
64
+ }
65
+
66
+ this.updateLayout();
67
+ }
68
+
69
+ updateLayout()
70
+ {
71
+ // Center the triangle within the viewBox
72
+ const offsetX = 10; // Left margin
73
+ const offsetY = this.unitScale * this.verticalLeg + 10; // Bottom margin
74
+
75
+ this.shapePath.clearPoints();
76
+ this.shapePath.addPoint(offsetX, offsetY);
77
+ this.shapePath.addPoint(offsetX + this.unitScale * this.horizontalLeg, offsetY);
78
+ this.shapePath.addPoint(offsetX + this.unitScale * this.horizontalLeg, offsetY - this.unitScale * this.verticalLeg);
79
+ this.shapePath.addPoint(offsetX, offsetY);
80
+
81
+ this.shapePath.updatePath();
82
+
83
+ if ( this.showLabels )
84
+ {
85
+ this.labelsHolder.removeAllChildren();
86
+ var L = new omdShapeLabelSet();
87
+ var A = this.horizontalLeg.toString();
88
+ var B = this.verticalLeg.toString();
89
+ var C = "";
90
+ L.initializeWithShapePath( this.shapePath, [A,B,C] );
91
+ this.labelsHolder.addChild( L );
92
+ }
93
+
94
+ // Set viewBox to center the shape
95
+ this.width = this.unitScale * this.horizontalLeg + 20;
96
+ this.height = this.unitScale * this.verticalLeg + 20;
97
+ this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
98
+ }
99
+ }
100
+
101
+
102
+
103
+ export class omdIsoscelesTriangle extends jsvgGroup
104
+ {
105
+ constructor()
106
+ {
107
+ // initialization
108
+ super();
109
+
110
+ this.type = "omdIsoscelesTriangle";
111
+
112
+ this.triangleBase = 5;
113
+ this.triangleHeight = 10;
114
+ this.unitScale = 10;
115
+
116
+ this.showLabels = false;
117
+
118
+ this.shapePath = new jsvgPath();
119
+ this.shapePath.setStrokeColor( "black" );
120
+ this.shapePath.setStrokeWidth( 2 );
121
+ this.shapePath.setFillColor( omdColor.lightGray );
122
+ this.addChild( this.shapePath );
123
+
124
+ this.labelsHolder = new jsvgGroup();
125
+ this.addChild( this.labelsHolder );
126
+
127
+ this.updateLayout();
128
+ }
129
+
130
+ loadFromJSON( data )
131
+ {
132
+ if ( typeof data.base != "undefined" )
133
+ this.triangleBase = data.base;
134
+
135
+ if ( typeof data.height != "undefined" )
136
+ this.triangleHeight = data.height;
137
+
138
+ if ( typeof data.unitScale != "undefined" )
139
+ this.unitScale = data.unitScale;
140
+
141
+ if ( typeof data.showLabels != "undefined" )
142
+ this.showLabels = data.showLabels;
143
+
144
+ this.updateLayout();
145
+ }
146
+
147
+ updateLayout()
148
+ {
149
+ this.shapePath.clearPoints();
150
+
151
+ this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
152
+ this.shapePath.addPoint( 0.5*this.unitScale*this.triangleBase, 0 );
153
+ this.shapePath.addPoint( 0, -1.0*this.unitScale*this.triangleHeight );
154
+ this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
155
+
156
+ this.shapePath.updatePath();
157
+
158
+ if ( this.showLabels )
159
+ {
160
+ this.labelsHolder.removeAllChildren();
161
+ var L = new omdShapeLabelSet();
162
+ L.initializeWithShapePath( this.shapePath );
163
+ this.labelsHolder.addChild( L );
164
+ }
165
+
166
+ // Set dimensions and viewBox for API compatibility
167
+ this.width = this.unitScale * this.triangleBase + 20;
168
+ this.height = this.unitScale * this.triangleHeight + 20;
169
+ this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
170
+ }
171
+ }
172
+
173
+ export class omdRectangle extends jsvgGroup
174
+ {
175
+ constructor()
176
+ {
177
+ // initialization
178
+ super();
179
+
180
+ this.type = "omdRectangle";
181
+
182
+ this.rectWidth = 10;
183
+ this.rectHeight = 10;
184
+ this.unitScale = 10;
185
+
186
+ this.showLabels = false;
187
+
188
+ this.shapePath = new jsvgPath();
189
+ this.shapePath.setStrokeColor( "black" );
190
+ this.shapePath.setStrokeWidth( 2 );
191
+ this.shapePath.setFillColor( omdColor.lightGray );
192
+ this.addChild( this.shapePath );
193
+
194
+ this.labelsHolder = new jsvgGroup();
195
+ this.addChild( this.labelsHolder );
196
+
197
+ this.updateLayout();
198
+ }
199
+
200
+ loadFromJSON( data )
201
+ {
202
+ if ( typeof data.width != "undefined" )
203
+ this.rectWidth = data.width;
204
+
205
+ if ( typeof data.height != "undefined" )
206
+ this.rectHeight = data.height;
207
+
208
+ if ( typeof data.unitScale != "undefined" )
209
+ this.unitScale = data.unitScale;
210
+
211
+ if ( typeof data.showLabels != "undefined" )
212
+ this.showLabels = data.showLabels;
213
+
214
+ this.updateLayout();
215
+ }
216
+
217
+ updateLayout()
218
+ {
219
+ // Center the rectangle within the viewBox
220
+ const offsetX = 10;
221
+ const offsetY = this.unitScale * this.rectHeight + 10;
222
+
223
+ this.shapePath.clearPoints();
224
+ this.shapePath.addPoint(offsetX, offsetY);
225
+ this.shapePath.addPoint(offsetX + this.unitScale * this.rectWidth, offsetY);
226
+ this.shapePath.addPoint(offsetX + this.unitScale * this.rectWidth, offsetY - this.unitScale * this.rectHeight);
227
+ this.shapePath.addPoint(offsetX, offsetY - this.unitScale * this.rectHeight);
228
+ this.shapePath.addPoint(offsetX, offsetY);
229
+
230
+ this.shapePath.updatePath();
231
+
232
+ if ( this.showLabels )
233
+ {
234
+ this.labelsHolder.removeAllChildren();
235
+ var L = new omdShapeLabelSet();
236
+ var A = this.rectWidth.toString();
237
+ var B = this.rectHeight.toString();
238
+ L.initializeWithShapePath( this.shapePath, [A,B,"",""] );
239
+ this.labelsHolder.addChild( L );
240
+ }
241
+
242
+ // Set viewBox
243
+ this.width = this.unitScale * this.rectWidth + 20;
244
+ this.height = this.unitScale * this.rectHeight + 20;
245
+ this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
246
+ }
247
+ }
248
+
249
+
250
+ export class omdEllipse extends jsvgGroup
251
+ {
252
+ constructor()
253
+ {
254
+ // initialization
255
+ super();
256
+
257
+ this.type = "omdEllipse";
258
+
259
+ this.rectWidth = 10;
260
+ this.rectHeight = 5;
261
+ this.unitScale = 10;
262
+
263
+ this.shapePath = new jsvgEllipse();
264
+ this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
265
+ this.shapePath.setStrokeColor( "black" );
266
+ this.shapePath.setStrokeWidth( 2 );
267
+ this.shapePath.setFillColor( omdColor.lightGray );
268
+ this.addChild( this.shapePath );
269
+
270
+ this.updateLayout();
271
+ }
272
+
273
+ loadFromJSON( data )
274
+ {
275
+ if ( typeof data.width != "undefined" )
276
+ this.rectWidth = data.width;
277
+
278
+ if ( typeof data.height != "undefined" )
279
+ this.rectHeight = data.height;
280
+
281
+ if ( typeof data.unitScale != "undefined" )
282
+ this.unitScale = data.unitScale;
283
+
284
+ this.updateLayout();
285
+ }
286
+
287
+ updateLayout()
288
+ {
289
+ this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
290
+
291
+ // Set dimensions and viewBox for API compatibility
292
+ this.width = this.rectWidth * this.unitScale + 20;
293
+ this.height = this.rectHeight * this.unitScale + 20;
294
+ this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
295
+ }
296
+ }
297
+
298
+ export class omdCircle extends jsvgGroup
299
+ {
300
+ constructor()
301
+ {
302
+ // initialization
303
+ super();
304
+
305
+ this.type = "omdCircle";
306
+
307
+ this.radius = 5;
308
+ this.unitScale = 10;
309
+
310
+ this.shapePath = new jsvgEllipse();
311
+ this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
312
+ this.shapePath.setStrokeColor( "black" );
313
+ this.shapePath.setStrokeWidth( 2 );
314
+ this.shapePath.setFillColor( omdColor.lightGray );
315
+ this.addChild( this.shapePath );
316
+
317
+ this.updateLayout();
318
+ }
319
+
320
+ loadFromJSON( data )
321
+ {
322
+ if ( typeof data.radius != "undefined" )
323
+ this.radius = data.radius;
324
+
325
+ if ( typeof data.unitScale != "undefined" )
326
+ this.unitScale = data.unitScale;
327
+
328
+ this.updateLayout();
329
+ }
330
+
331
+ updateLayout()
332
+ {
333
+ this.shapePath.setWidthAndHeight( 2.0*this.radius*this.unitScale, 2.0*this.radius*this.unitScale );
334
+
335
+ // Set dimensions and viewBox for API compatibility
336
+ this.width = 2.0 * this.radius * this.unitScale + 20;
337
+ this.height = 2.0 * this.radius * this.unitScale + 20;
338
+ this.svgObject.setAttribute('viewBox', `0 0 ${this.width} ${this.height}`);
339
+ }
340
+ }
341
+
342
+ export class omdRegularPolygon extends jsvgGroup
343
+ {
344
+ constructor()
345
+ {
346
+ // initialization
347
+ super();
348
+
349
+ this.type = "omdRegularPolygon";
350
+
351
+ this.radius = 5;
352
+ this.numberOfSides = 5;
353
+ this.unitScale = 10;
354
+
355
+ this.showLabels = false;
356
+
357
+ this.shapePath = new jsvgPath();
358
+ this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
359
+ this.shapePath.setStrokeColor( "black" );
360
+ this.shapePath.setStrokeWidth( 2 );
361
+ this.shapePath.setFillColor( omdColor.lightGray );
362
+ this.addChild( this.shapePath );
363
+
364
+ this.labelsHolder = new jsvgGroup();
365
+ this.addChild( this.labelsHolder );
366
+
367
+ this.updateLayout();
368
+ }
369
+
370
+ loadFromJSON( data )
371
+ {
372
+ if ( typeof data.radius != "undefined" )
373
+ this.radius = data.radius;
374
+
375
+ if ( typeof data.numberOfSides != "undefined" )
376
+ this.numberOfSides = data.numberOfSides;
377
+
378
+ if ( typeof data.unitScale != "undefined" )
379
+ this.unitScale = data.unitScale;
380
+
381
+
382
+ if ( typeof data.showLabels != "undefined" )
383
+ this.showLabels = data.showLabels;
384
+
385
+ this.updateLayout();
386
+ }
387
+
388
+ updateLayout()
389
+ {
390
+ this.shapePath.clearPoints();
391
+
392
+ var angleOffset = 0;
393
+ if ( this.numberOfSides % 2 == 1 )
394
+ {
395
+ angleOffset = Math.PI / this.numberOfSides * 0.5; // shift angle for odd number of sides
396
+ if ( ((this.numberOfSides-1)/2) % 2 == 0 )
397
+ angleOffset *= -1.0;
398
+ }
399
+
400
+ for( var i=0; i<=this.numberOfSides; i++ )
401
+ {
402
+ var A = -2.0 * Math.PI / this.numberOfSides * i;
403
+ A += angleOffset;
404
+ var pX = Math.cos(A) * this.radius * this.unitScale;
405
+ var pY = Math.sin(A) * this.radius * this.unitScale;
406
+ this.shapePath.addPoint( pX, pY );
407
+ }
408
+
409
+ this.shapePath.updatePath();
410
+
411
+ if ( this.showLabels )
412
+ {
413
+ // make label
414
+ this.labelsHolder.removeAllChildren();
415
+ var L = new omdShapeLabelSet();
416
+ var sideLength = 2.0 * this.radius * Math.sin( Math.PI / this.numberOfSides );
417
+ var A = sideLength.toFixed(2);
418
+ L.initializeWithShapePath( this.shapePath, [ A ] );
419
+ this.labelsHolder.addChild( L );
420
+ }
421
+
422
+ // Set dimensions and viewBox for API compatibility
423
+ this.width = 2.0 * this.radius * this.unitScale + 20;
424
+ this.height = 2.0 * this.radius * this.unitScale + 20;
425
+ this.svgObject.setAttribute('viewBox', `-${this.width/2} -${this.height/2} ${this.width} ${this.height}`);
426
+ }
427
+ }
428
+
429
+
430
+ export class omdShapeLabelSet extends jsvgGroup
431
+ {
432
+ constructor()
433
+ {
434
+ // initialization
435
+ super();
436
+ }
437
+
438
+ initializeWithShapePath( shapePath, labelTextArray=[] )
439
+ {
440
+ // this assumes counterclockwise path
441
+
442
+ // create lines
443
+ for( var i=0; i<shapePath.points.length-1; i++ )
444
+ {
445
+ if ( i >= labelTextArray.length || labelTextArray[i].length == 0 )
446
+ continue;
447
+
448
+ // get points
449
+ var point0 = shapePath.points[i];
450
+ var x0 = point0.x;
451
+ var y0 = point0.y;
452
+
453
+ var point1 = shapePath.points[i+1];
454
+ var x1 = point1.x;
455
+ var y1 = point1.y;
456
+
457
+ // get normalized vector
458
+ var dX = x1 - x0;
459
+ var dY = y1 - y0;
460
+ var L = Math.sqrt( dX*dX + dY*dY );
461
+ dX /= L;
462
+ dY /= L;
463
+
464
+ // get normal
465
+ var normalX = -1.0 * dY;
466
+ var normalY = dX;
467
+
468
+ // make line
469
+ var labelLine = new jsvgLine();
470
+ var newLineX0 = x0 + normalX * 10.0;
471
+ var newLineY0 = y0 + normalY * 10.0;
472
+ var newLineX1 = x1 + normalX * 10.0;
473
+ var newLineY1 = y1 + normalY * 10.0;
474
+ labelLine.setEndpoints( newLineX0, newLineY0, newLineX1, newLineY1 );
475
+ this.addChild( labelLine );
476
+
477
+ // center point
478
+ var centerX = (x0 + x1) / 2.0;
479
+ var centerY = (y0 + y1) / 2.0;
480
+
481
+ var angle = Math.atan2( dY, dX );
482
+ angle *= 180 / Math.PI;
483
+ angle += 180.0;
484
+ angle = angle % 360.0;
485
+ var originalAngle = angle;
486
+
487
+ // flip upside-down text
488
+ var offset = 0;
489
+ if ( angle > 90 && angle < 270 )
490
+ {
491
+ angle -= 180.0;
492
+ offset += 10.0;
493
+ }
494
+
495
+ // label text
496
+ var textCenterX = centerX + normalX * (15.0+offset);
497
+ var textCenterY = centerY + normalY * (15.0+offset);
498
+ var labelText = new jsvgTextLine();
499
+ labelText.setAlignment("center");
500
+ labelText.setFontFamily( "Albert Sans" );
501
+ labelText.setFontColor( "black" );
502
+ labelText.setFontSize( 12 );
503
+ labelText.setPosition( textCenterX, textCenterY );
504
+ labelText.setRotation( angle );
505
+ this.addChild( labelText );
506
+
507
+ labelText.setText( labelTextArray[i] );
508
+ }
509
+ }
510
+
511
+ }
512
+