@teachinglab/omd 0.1.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.
Files changed (144) hide show
  1. package/README.md +138 -0
  2. package/canvas/core/canvasConfig.js +203 -0
  3. package/canvas/core/omdCanvas.js +475 -0
  4. package/canvas/drawing/segment.js +168 -0
  5. package/canvas/drawing/stroke.js +386 -0
  6. package/canvas/events/eventManager.js +435 -0
  7. package/canvas/events/pointerEventHandler.js +263 -0
  8. package/canvas/features/focusFrameManager.js +287 -0
  9. package/canvas/index.js +49 -0
  10. package/canvas/tools/eraserTool.js +322 -0
  11. package/canvas/tools/pencilTool.js +319 -0
  12. package/canvas/tools/selectTool.js +457 -0
  13. package/canvas/tools/tool.js +223 -0
  14. package/canvas/tools/toolManager.js +394 -0
  15. package/canvas/ui/cursor.js +438 -0
  16. package/canvas/ui/toolbar.js +304 -0
  17. package/canvas/utils/boundingBox.js +378 -0
  18. package/canvas/utils/mathUtils.js +259 -0
  19. package/docs/api/configuration-options.md +104 -0
  20. package/docs/api/eventManager.md +68 -0
  21. package/docs/api/focusFrameManager.md +150 -0
  22. package/docs/api/index.md +91 -0
  23. package/docs/api/main.md +58 -0
  24. package/docs/api/omdBinaryExpressionNode.md +227 -0
  25. package/docs/api/omdCanvas.md +142 -0
  26. package/docs/api/omdConfigManager.md +192 -0
  27. package/docs/api/omdConstantNode.md +117 -0
  28. package/docs/api/omdDisplay.md +121 -0
  29. package/docs/api/omdEquationNode.md +161 -0
  30. package/docs/api/omdEquationSequenceNode.md +301 -0
  31. package/docs/api/omdEquationStack.md +139 -0
  32. package/docs/api/omdFunctionNode.md +141 -0
  33. package/docs/api/omdGroupNode.md +182 -0
  34. package/docs/api/omdHelpers.md +96 -0
  35. package/docs/api/omdLeafNode.md +163 -0
  36. package/docs/api/omdNode.md +101 -0
  37. package/docs/api/omdOperationDisplayNode.md +139 -0
  38. package/docs/api/omdOperatorNode.md +127 -0
  39. package/docs/api/omdParenthesisNode.md +122 -0
  40. package/docs/api/omdPopup.md +117 -0
  41. package/docs/api/omdPowerNode.md +127 -0
  42. package/docs/api/omdRationalNode.md +128 -0
  43. package/docs/api/omdSequenceNode.md +128 -0
  44. package/docs/api/omdSimplification.md +110 -0
  45. package/docs/api/omdSqrtNode.md +79 -0
  46. package/docs/api/omdStepVisualizer.md +115 -0
  47. package/docs/api/omdStepVisualizerHighlighting.md +61 -0
  48. package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
  49. package/docs/api/omdStepVisualizerLayout.md +60 -0
  50. package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
  51. package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
  52. package/docs/api/omdToolbar.md +102 -0
  53. package/docs/api/omdTranscriptionService.md +76 -0
  54. package/docs/api/omdTreeDiff.md +134 -0
  55. package/docs/api/omdUnaryExpressionNode.md +174 -0
  56. package/docs/api/omdUtilities.md +70 -0
  57. package/docs/api/omdVariableNode.md +148 -0
  58. package/docs/api/selectTool.md +74 -0
  59. package/docs/api/simplificationEngine.md +98 -0
  60. package/docs/api/simplificationRules.md +77 -0
  61. package/docs/api/simplificationUtils.md +64 -0
  62. package/docs/api/transcribe.md +43 -0
  63. package/docs/api-reference.md +85 -0
  64. package/docs/index.html +454 -0
  65. package/docs/user-guide.md +9 -0
  66. package/index.js +67 -0
  67. package/omd/config/omdConfigManager.js +267 -0
  68. package/omd/core/index.js +150 -0
  69. package/omd/core/omdEquationStack.js +347 -0
  70. package/omd/core/omdUtilities.js +115 -0
  71. package/omd/display/omdDisplay.js +443 -0
  72. package/omd/display/omdToolbar.js +502 -0
  73. package/omd/nodes/omdBinaryExpressionNode.js +460 -0
  74. package/omd/nodes/omdConstantNode.js +142 -0
  75. package/omd/nodes/omdEquationNode.js +1223 -0
  76. package/omd/nodes/omdEquationSequenceNode.js +1273 -0
  77. package/omd/nodes/omdFunctionNode.js +352 -0
  78. package/omd/nodes/omdGroupNode.js +68 -0
  79. package/omd/nodes/omdLeafNode.js +77 -0
  80. package/omd/nodes/omdNode.js +557 -0
  81. package/omd/nodes/omdOperationDisplayNode.js +322 -0
  82. package/omd/nodes/omdOperatorNode.js +109 -0
  83. package/omd/nodes/omdParenthesisNode.js +293 -0
  84. package/omd/nodes/omdPowerNode.js +236 -0
  85. package/omd/nodes/omdRationalNode.js +295 -0
  86. package/omd/nodes/omdSqrtNode.js +308 -0
  87. package/omd/nodes/omdUnaryExpressionNode.js +178 -0
  88. package/omd/nodes/omdVariableNode.js +123 -0
  89. package/omd/simplification/omdSimplification.js +171 -0
  90. package/omd/simplification/omdSimplificationEngine.js +886 -0
  91. package/omd/simplification/package.json +6 -0
  92. package/omd/simplification/rules/binaryRules.js +1037 -0
  93. package/omd/simplification/rules/functionRules.js +111 -0
  94. package/omd/simplification/rules/index.js +48 -0
  95. package/omd/simplification/rules/parenthesisRules.js +19 -0
  96. package/omd/simplification/rules/powerRules.js +143 -0
  97. package/omd/simplification/rules/rationalRules.js +475 -0
  98. package/omd/simplification/rules/sqrtRules.js +48 -0
  99. package/omd/simplification/rules/unaryRules.js +37 -0
  100. package/omd/simplification/simplificationRules.js +32 -0
  101. package/omd/simplification/simplificationUtils.js +1056 -0
  102. package/omd/step-visualizer/omdStepVisualizer.js +597 -0
  103. package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
  104. package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
  105. package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
  106. package/omd/utils/omdNodeOverlay.js +638 -0
  107. package/omd/utils/omdPopup.js +1084 -0
  108. package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
  109. package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
  110. package/omd/utils/omdTranscriptionService.js +125 -0
  111. package/omd/utils/omdTreeDiff.js +734 -0
  112. package/package.json +46 -0
  113. package/src/index.js +62 -0
  114. package/src/json-schemas.md +109 -0
  115. package/src/omd-json-samples.js +115 -0
  116. package/src/omd.js +109 -0
  117. package/src/omdApp.js +391 -0
  118. package/src/omdAppCanvas.js +336 -0
  119. package/src/omdBalanceHanger.js +172 -0
  120. package/src/omdColor.js +13 -0
  121. package/src/omdCoordinatePlane.js +467 -0
  122. package/src/omdEquation.js +125 -0
  123. package/src/omdExpression.js +104 -0
  124. package/src/omdFunction.js +113 -0
  125. package/src/omdMetaExpression.js +287 -0
  126. package/src/omdNaturalExpression.js +564 -0
  127. package/src/omdNode.js +384 -0
  128. package/src/omdNumber.js +53 -0
  129. package/src/omdNumberLine.js +107 -0
  130. package/src/omdNumberTile.js +119 -0
  131. package/src/omdOperator.js +73 -0
  132. package/src/omdPowerExpression.js +92 -0
  133. package/src/omdProblem.js +55 -0
  134. package/src/omdRatioChart.js +232 -0
  135. package/src/omdRationalExpression.js +115 -0
  136. package/src/omdSampleData.js +215 -0
  137. package/src/omdShapes.js +476 -0
  138. package/src/omdSpinner.js +148 -0
  139. package/src/omdString.js +39 -0
  140. package/src/omdTable.js +369 -0
  141. package/src/omdTapeDiagram.js +245 -0
  142. package/src/omdTerm.js +92 -0
  143. package/src/omdTileEquation.js +349 -0
  144. package/src/omdVariable.js +51 -0
@@ -0,0 +1,215 @@
1
+
2
+
3
+ let numberSample =
4
+ {
5
+ "omdType": "number",
6
+ "value" : 7
7
+ }
8
+
9
+ let variableSample =
10
+ {
11
+ "omdType": "variable",
12
+ "name" : "C"
13
+ }
14
+
15
+ let operatorSample =
16
+ {
17
+ "omdType": "operator",
18
+ "operator" : "+"
19
+ }
20
+
21
+ let termSample =
22
+ {
23
+ "omdType": "term",
24
+ "coefficient": 3,
25
+ "variable": "x",
26
+ "exponent": 1
27
+ }
28
+
29
+ let expressionSample =
30
+ {
31
+ "omdType": "expression",
32
+ "termsAndOpers":
33
+ [
34
+ {
35
+ "omdType": "term",
36
+ "coefficient": 3,
37
+ "variable": '',
38
+ "exponent": 1
39
+ },
40
+ {
41
+ "omdType": "operator",
42
+ "operator" : "+"
43
+ },
44
+ {
45
+ "omdType": "term",
46
+ "coefficient": 5,
47
+ "variable": 'x',
48
+ "exponent": 2
49
+ },
50
+ {
51
+ "omdType": "operator",
52
+ "operator" : "+"
53
+ },
54
+ {
55
+ "omdType": "variable",
56
+ "name": "x",
57
+ }
58
+ ],
59
+ }
60
+
61
+
62
+
63
+ let numberLineSample =
64
+ {
65
+ "omdType": "numberLine",
66
+ "dotValues": [3, 5, 7],
67
+ "min": 0,
68
+ "max": 10,
69
+ "label": "",
70
+ }
71
+
72
+ let tapeDiagramSample =
73
+ {
74
+ "omdType": "tapeDiagram",
75
+ //"values": ['x','x','x+1'],
76
+ "values": [1,2,3,4],
77
+ "showValues": true,
78
+ "colors": [],
79
+ "unitWidth": 30,
80
+ "labelSet": [
81
+ {
82
+ "omdType": "omdTapeLabel",
83
+ "startValue": 0,
84
+ "endValue": 3,
85
+ "label": "3",
86
+ "showBelow": false
87
+ },
88
+ {
89
+ "omdType": "omdTapeLabel",
90
+ "startValue": 1,
91
+ "endValue": 6,
92
+ "label": "5",
93
+ "showBelow": true
94
+ }
95
+ ]
96
+ }
97
+
98
+ let tapeDiagramSample2 =
99
+ {
100
+ "omdType": "tapeDiagram",
101
+ "values": ['2','x','x+1'],
102
+ "showValues": true,
103
+ "colors": [],
104
+ "unitWidth": 30,
105
+ "labelSet": [
106
+ {
107
+ "omdType": "omdTapeLabel",
108
+ "startIndex": 0,
109
+ "endIndex": 3,
110
+ "label": "9",
111
+ "showBelow": false
112
+ }
113
+ ]
114
+ }
115
+
116
+ let balanceHangerSample =
117
+ {
118
+ "leftValues": [1, 2, 3, 4],
119
+ "rightValues": [1, 2, 3],
120
+ "tilt": "right"
121
+ }
122
+
123
+ let balanceHangerSample2 =
124
+ {
125
+ "leftValues": [1, 'x', 3],
126
+ "rightValues": [1, 4, 5],
127
+ "tilt": "none"
128
+ }
129
+
130
+ let numberTileSample1 =
131
+ {
132
+ "omdType": "numberTile",
133
+ "value": 3
134
+ }
135
+
136
+ let numberTileSample2 =
137
+ {
138
+ "omdType": "numberTile",
139
+ "value": 8,
140
+ "size": "medium" // small, medium or large
141
+ }
142
+
143
+ let rightTriangleSample =
144
+ {
145
+ "omdType": "rightTriangle",
146
+ "verticalLeg": 6, // length of vertical leg
147
+ "horizontalLeg": 3, // length of horizontal leg
148
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
149
+ }
150
+
151
+ let isoscelesTriangleSample =
152
+ {
153
+ "omdType": "isoscelesTriangle",
154
+ "base": 4, // triangle base
155
+ "height": 6, // triangle height
156
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
157
+ }
158
+
159
+ let rightTriangleSample2 =
160
+ {
161
+ "omdType": "rightTriangle",
162
+ "angleA": 60, // angle A
163
+ "hypotenuse": 50, // hypotenuse
164
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
165
+ }
166
+
167
+ let rectangleSample =
168
+ {
169
+ "omdType": "rectangle",
170
+ "width": 10, // width
171
+ "height": 6, // height
172
+ "unitScale": 10 // unit scale should be 10 unless otherwise specified
173
+ }
174
+
175
+ let ellipseSample =
176
+ {
177
+ "omdType": "ellipse",
178
+ "width": 10, // width
179
+ "height": 6, // height (same as width for circle)
180
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
181
+ }
182
+
183
+ let circleSample =
184
+ {
185
+ "omdType": "circle",
186
+ "radius": 3, // radius
187
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
188
+ }
189
+
190
+ let regularPolygonSample =
191
+ {
192
+ "omdType": "regularPolygon",
193
+ "radius": 3, // radius
194
+ "numberOfSides": 6, // number of sides
195
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
196
+ }
197
+
198
+ let planeWithShapes =
199
+ {
200
+ "omdType": "coordinatePlane",
201
+ "size": "medium",
202
+ "shapeSet": [
203
+ {
204
+ "omdType": "circle",
205
+ "radius": 3,
206
+ "unitScale": 10
207
+ },
208
+ {
209
+ "omdType": "isoscelesTriangle",
210
+ "base": 2, // triangle base
211
+ "height": 3, // triangle height
212
+ "unitScale":10 // unit scale should be 10 unless otherwise specified
213
+ }
214
+ ]
215
+ }
@@ -0,0 +1,476 @@
1
+
2
+ import { omdColor } from "./omdColor.js";
3
+ import { jsvgGroup, jsvgPath, jsvgLine, jsvgTextLine } 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
+ this.shapePath.clearPoints();
72
+
73
+ this.shapePath.addPoint( 0,0 );
74
+ this.shapePath.addPoint( this.unitScale*this.horizontalLeg,0 );
75
+ this.shapePath.addPoint( this.unitScale*this.horizontalLeg, -1.0*this.unitScale*this.verticalLeg );
76
+ this.shapePath.addPoint( 0,0 );
77
+
78
+ this.shapePath.updatePath();
79
+
80
+ if ( this.showLabels )
81
+ {
82
+ this.labelsHolder.removeAllChildren();
83
+ var L = new omdShapeLabelSet();
84
+ var A = this.horizontalLeg.toString();
85
+ var B = this.verticalLeg.toString();
86
+ var C = "";
87
+ L.initializeWithShapePath( this.shapePath, [A,B,C] );
88
+ this.labelsHolder.addChild( L );
89
+ }
90
+ }
91
+ }
92
+
93
+
94
+
95
+ export class omdIsoscelesTriangle extends jsvgGroup
96
+ {
97
+ constructor()
98
+ {
99
+ // initialization
100
+ super();
101
+
102
+ this.type = "omdIsoscelesTriangle";
103
+
104
+ this.triangleBase = 5;
105
+ this.triangleHeight = 10;
106
+ this.unitScale = 10;
107
+
108
+ this.showLabels = false;
109
+
110
+ this.shapePath = new jsvgPath();
111
+ this.shapePath.setStrokeColor( "black" );
112
+ this.shapePath.setStrokeWidth( 2 );
113
+ this.shapePath.setFillColor( omdColor.lightGray );
114
+ this.addChild( this.shapePath );
115
+
116
+ this.labelsHolder = new jsvgGroup();
117
+ this.addChild( this.labelsHolder );
118
+
119
+ this.updateLayout();
120
+ }
121
+
122
+ loadFromJSON( data )
123
+ {
124
+ if ( typeof data.base != "undefined" )
125
+ this.triangleBase = data.base;
126
+
127
+ if ( typeof data.height != "undefined" )
128
+ this.triangleHeight = data.height;
129
+
130
+ if ( typeof data.unitScale != "undefined" )
131
+ this.unitScale = data.unitScale;
132
+
133
+ if ( typeof data.showLabels != "undefined" )
134
+ this.showLabels = data.showLabels;
135
+
136
+ this.updateLayout();
137
+ }
138
+
139
+ updateLayout()
140
+ {
141
+ this.shapePath.clearPoints();
142
+
143
+ this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
144
+ this.shapePath.addPoint( 0.5*this.unitScale*this.triangleBase, 0 );
145
+ this.shapePath.addPoint( 0, -1.0*this.unitScale*this.triangleHeight );
146
+ this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
147
+
148
+ this.shapePath.updatePath();
149
+
150
+ if ( this.showLabels )
151
+ {
152
+ this.labelsHolder.removeAllChildren();
153
+ var L = new omdShapeLabelSet();
154
+ L.initializeWithShapePath( this.shapePath );
155
+ this.labelsHolder.addChild( L );
156
+ }
157
+ }
158
+ }
159
+
160
+ export class omdRectangle extends jsvgGroup
161
+ {
162
+ constructor()
163
+ {
164
+ // initialization
165
+ super();
166
+
167
+ this.type = "omdRectangle";
168
+
169
+ this.rectWidth = 10;
170
+ this.rectHeight = 10;
171
+ this.unitScale = 10;
172
+
173
+ this.showLabels = false;
174
+
175
+ this.shapePath = new jsvgPath();
176
+ this.shapePath.setStrokeColor( "black" );
177
+ this.shapePath.setStrokeWidth( 2 );
178
+ this.shapePath.setFillColor( omdColor.lightGray );
179
+ this.addChild( this.shapePath );
180
+
181
+ this.labelsHolder = new jsvgGroup();
182
+ this.addChild( this.labelsHolder );
183
+
184
+ this.updateLayout();
185
+ }
186
+
187
+ loadFromJSON( data )
188
+ {
189
+ if ( typeof data.width != "undefined" )
190
+ this.rectWidth = data.width;
191
+
192
+ if ( typeof data.height != "undefined" )
193
+ this.rectHeight = data.height;
194
+
195
+ if ( typeof data.unitScale != "undefined" )
196
+ this.unitScale = data.unitScale;
197
+
198
+ if ( typeof data.showLabels != "undefined" )
199
+ this.showLabels = data.showLabels;
200
+
201
+ this.updateLayout();
202
+ }
203
+
204
+ updateLayout()
205
+ {
206
+ this.shapePath.clearPoints();
207
+
208
+ this.shapePath.addPoint( 0,0 );
209
+ this.shapePath.addPoint( this.unitScale*this.rectWidth, 0 );
210
+ this.shapePath.addPoint( this.unitScale*this.rectWidth, -1.0*this.unitScale*this.rectHeight );
211
+ this.shapePath.addPoint( 0, -1.0*this.unitScale*this.rectHeight );
212
+ this.shapePath.addPoint( 0,0 );
213
+
214
+ this.shapePath.updatePath();
215
+
216
+ if ( this.showLabels )
217
+ {
218
+ this.labelsHolder.removeAllChildren();
219
+ var L = new omdShapeLabelSet();
220
+ var A = this.rectWidth.toString();
221
+ var B = this.rectHeight.toString();
222
+ L.initializeWithShapePath( this.shapePath, [A,B,"",""] );
223
+ this.labelsHolder.addChild( L );
224
+ }
225
+ }
226
+ }
227
+
228
+
229
+ export class omdEllipse extends jsvgGroup
230
+ {
231
+ constructor()
232
+ {
233
+ // initialization
234
+ super();
235
+
236
+ this.type = "omdEllipse";
237
+
238
+ this.rectWidth = 10;
239
+ this.rectHeight = 5;
240
+ this.unitScale = 10;
241
+
242
+ this.shapePath = new jsvgEllipse();
243
+ this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
244
+ this.shapePath.setStrokeColor( "black" );
245
+ this.shapePath.setStrokeWidth( 2 );
246
+ this.shapePath.setFillColor( omdColor.lightGray );
247
+ this.addChild( this.shapePath );
248
+
249
+ this.updateLayout();
250
+ }
251
+
252
+ loadFromJSON( data )
253
+ {
254
+ if ( typeof data.width != "undefined" )
255
+ this.rectWidth = data.width;
256
+
257
+ if ( typeof data.height != "undefined" )
258
+ this.rectHeight = data.height;
259
+
260
+ if ( typeof data.unitScale != "undefined" )
261
+ this.unitScale = data.unitScale;
262
+
263
+ this.updateLayout();
264
+ }
265
+
266
+ updateLayout()
267
+ {
268
+ this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
269
+ }
270
+ }
271
+
272
+ export class omdCircle extends jsvgGroup
273
+ {
274
+ constructor()
275
+ {
276
+ // initialization
277
+ super();
278
+
279
+ this.type = "omdCircle";
280
+
281
+ this.radius = 5;
282
+ this.unitScale = 10;
283
+
284
+ this.shapePath = new jsvgEllipse();
285
+ this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
286
+ this.shapePath.setStrokeColor( "black" );
287
+ this.shapePath.setStrokeWidth( 2 );
288
+ this.shapePath.setFillColor( omdColor.lightGray );
289
+ this.addChild( this.shapePath );
290
+
291
+ this.updateLayout();
292
+ }
293
+
294
+ loadFromJSON( data )
295
+ {
296
+ if ( typeof data.radius != "undefined" )
297
+ this.radius = data.radius;
298
+
299
+ if ( typeof data.unitScale != "undefined" )
300
+ this.unitScale = data.unitScale;
301
+
302
+ this.updateLayout();
303
+ }
304
+
305
+ updateLayout()
306
+ {
307
+ this.shapePath.setWidthAndHeight( 2.0*this.radius*this.unitScale, 2.0*this.radius*this.unitScale );
308
+ }
309
+ }
310
+
311
+ export class omdRegularPolygon extends jsvgGroup
312
+ {
313
+ constructor()
314
+ {
315
+ // initialization
316
+ super();
317
+
318
+ this.type = "omdRegularPolygon";
319
+
320
+ this.radius = 5;
321
+ this.numberOfSides = 5;
322
+ this.unitScale = 10;
323
+
324
+ this.showLabels = false;
325
+
326
+ this.shapePath = new jsvgPath();
327
+ this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
328
+ this.shapePath.setStrokeColor( "black" );
329
+ this.shapePath.setStrokeWidth( 2 );
330
+ this.shapePath.setFillColor( omdColor.lightGray );
331
+ this.addChild( this.shapePath );
332
+
333
+ this.labelsHolder = new jsvgGroup();
334
+ this.addChild( this.labelsHolder );
335
+
336
+ this.updateLayout();
337
+ }
338
+
339
+ loadFromJSON( data )
340
+ {
341
+ if ( typeof data.radius != "undefined" )
342
+ this.radius = data.radius;
343
+
344
+ if ( typeof data.numberOfSides != "undefined" )
345
+ this.numberOfSides = data.numberOfSides;
346
+
347
+ if ( typeof data.unitScale != "undefined" )
348
+ this.unitScale = data.unitScale;
349
+
350
+
351
+ if ( typeof data.showLabels != "undefined" )
352
+ this.showLabels = data.showLabels;
353
+
354
+ this.updateLayout();
355
+ }
356
+
357
+ updateLayout()
358
+ {
359
+ this.shapePath.clearPoints();
360
+
361
+ var angleOffset = 0;
362
+ if ( this.numberOfSides % 2 == 1 )
363
+ {
364
+ angleOffset = Math.PI / this.numberOfSides * 0.5; // shift angle for odd number of sides
365
+ if ( ((this.numberOfSides-1)/2) % 2 == 0 )
366
+ angleOffset *= -1.0;
367
+ }
368
+
369
+ for( var i=0; i<=this.numberOfSides; i++ )
370
+ {
371
+ var A = -2.0 * Math.PI / this.numberOfSides * i;
372
+ A += angleOffset;
373
+ var pX = Math.cos(A) * this.radius * this.unitScale;
374
+ var pY = Math.sin(A) * this.radius * this.unitScale;
375
+ this.shapePath.addPoint( pX, pY );
376
+ }
377
+
378
+ this.shapePath.updatePath();
379
+
380
+ if ( this.showLabels )
381
+ {
382
+ // make label
383
+ this.labelsHolder.removeAllChildren();
384
+ var L = new omdShapeLabelSet();
385
+ var sideLength = 2.0 * this.radius * Math.sin( Math.PI / this.numberOfSides );
386
+ var A = sideLength.toFixed(2);
387
+ L.initializeWithShapePath( this.shapePath, [ A ] );
388
+ this.labelsHolder.addChild( L );
389
+ }
390
+ }
391
+ }
392
+
393
+
394
+ export class omdShapeLabelSet extends jsvgGroup
395
+ {
396
+ constructor()
397
+ {
398
+ // initialization
399
+ super();
400
+ }
401
+
402
+ initializeWithShapePath( shapePath, labelTextArray=[] )
403
+ {
404
+ // this assumes counterclockwise path
405
+
406
+ // create lines
407
+ for( var i=0; i<shapePath.points.length-1; i++ )
408
+ {
409
+ if ( i >= labelTextArray.length || labelTextArray[i].length == 0 )
410
+ continue;
411
+
412
+ // get points
413
+ var point0 = shapePath.points[i];
414
+ var x0 = point0.x;
415
+ var y0 = point0.y;
416
+
417
+ var point1 = shapePath.points[i+1];
418
+ var x1 = point1.x;
419
+ var y1 = point1.y;
420
+
421
+ // get normalized vector
422
+ var dX = x1 - x0;
423
+ var dY = y1 - y0;
424
+ var L = Math.sqrt( dX*dX + dY*dY );
425
+ dX /= L;
426
+ dY /= L;
427
+
428
+ // get normal
429
+ var normalX = -1.0 * dY;
430
+ var normalY = dX;
431
+
432
+ // make line
433
+ var labelLine = new jsvgLine();
434
+ var newLineX0 = x0 + normalX * 10.0;
435
+ var newLineY0 = y0 + normalY * 10.0;
436
+ var newLineX1 = x1 + normalX * 10.0;
437
+ var newLineY1 = y1 + normalY * 10.0;
438
+ labelLine.setEndpoints( newLineX0, newLineY0, newLineX1, newLineY1 );
439
+ this.addChild( labelLine );
440
+
441
+ // center point
442
+ var centerX = (x0 + x1) / 2.0;
443
+ var centerY = (y0 + y1) / 2.0;
444
+
445
+ var angle = Math.atan2( dY, dX );
446
+ angle *= 180 / Math.PI;
447
+ angle += 180.0;
448
+ angle = angle % 360.0;
449
+ var originalAngle = angle;
450
+
451
+ // flip upside-down text
452
+ var offset = 0;
453
+ if ( angle > 90 && angle < 270 )
454
+ {
455
+ angle -= 180.0;
456
+ offset += 10.0;
457
+ }
458
+
459
+ // label text
460
+ var textCenterX = centerX + normalX * (15.0+offset);
461
+ var textCenterY = centerY + normalY * (15.0+offset);
462
+ var labelText = new jsvgTextLine();
463
+ labelText.setAlignment("center");
464
+ labelText.setFontFamily( "Albert Sans" );
465
+ labelText.setFontColor( "black" );
466
+ labelText.setFontSize( 12 );
467
+ labelText.setPosition( textCenterX, textCenterY );
468
+ labelText.setRotation( angle );
469
+ this.addChild( labelText );
470
+
471
+ labelText.setText( labelTextArray[i] );
472
+ }
473
+ }
474
+
475
+ }
476
+