@teachinglab/omd 0.6.1 → 0.6.3
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/README.md +257 -251
- package/README.old.md +137 -137
- package/canvas/core/canvasConfig.js +202 -202
- package/canvas/drawing/segment.js +167 -167
- package/canvas/drawing/stroke.js +385 -385
- package/canvas/events/eventManager.js +444 -444
- package/canvas/events/pointerEventHandler.js +262 -262
- package/canvas/index.js +48 -48
- package/canvas/tools/PointerTool.js +71 -71
- package/canvas/tools/tool.js +222 -222
- package/canvas/utils/boundingBox.js +377 -377
- package/canvas/utils/mathUtils.js +258 -258
- package/docs/api/configuration-options.md +198 -198
- package/docs/api/eventManager.md +82 -82
- package/docs/api/focusFrameManager.md +144 -144
- package/docs/api/index.md +105 -105
- package/docs/api/main.md +62 -62
- package/docs/api/omdBinaryExpressionNode.md +86 -86
- package/docs/api/omdCanvas.md +83 -83
- package/docs/api/omdConfigManager.md +112 -112
- package/docs/api/omdConstantNode.md +52 -52
- package/docs/api/omdDisplay.md +87 -87
- package/docs/api/omdEquationNode.md +174 -174
- package/docs/api/omdEquationSequenceNode.md +258 -258
- package/docs/api/omdEquationStack.md +192 -192
- package/docs/api/omdFunctionNode.md +82 -82
- package/docs/api/omdGroupNode.md +78 -78
- package/docs/api/omdHelpers.md +87 -87
- package/docs/api/omdLeafNode.md +85 -85
- package/docs/api/omdNode.md +201 -201
- package/docs/api/omdOperationDisplayNode.md +117 -117
- package/docs/api/omdOperatorNode.md +91 -91
- package/docs/api/omdParenthesisNode.md +133 -133
- package/docs/api/omdPopup.md +191 -191
- package/docs/api/omdPowerNode.md +131 -131
- package/docs/api/omdRationalNode.md +144 -144
- package/docs/api/omdSequenceNode.md +128 -128
- package/docs/api/omdSimplification.md +78 -78
- package/docs/api/omdSqrtNode.md +144 -144
- package/docs/api/omdStepVisualizer.md +146 -146
- package/docs/api/omdStepVisualizerHighlighting.md +65 -65
- package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
- package/docs/api/omdStepVisualizerLayout.md +70 -70
- package/docs/api/omdStepVisualizerNodeUtils.md +140 -140
- package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
- package/docs/api/omdToolbar.md +130 -130
- package/docs/api/omdTranscriptionService.md +95 -95
- package/docs/api/omdTreeDiff.md +169 -169
- package/docs/api/omdUnaryExpressionNode.md +137 -137
- package/docs/api/omdUtilities.md +82 -82
- package/docs/api/omdVariableNode.md +123 -123
- package/docs/api/selectTool.md +74 -74
- package/docs/api/simplificationEngine.md +97 -97
- package/docs/api/simplificationRules.md +76 -76
- package/docs/api/simplificationUtils.md +64 -64
- package/docs/api/transcribe.md +43 -43
- package/docs/api-reference.md +85 -85
- package/docs/index.html +453 -453
- package/docs/index.md +38 -38
- package/docs/omd-objects.md +258 -258
- package/index.js +79 -79
- package/jsvg/index.js +3 -0
- package/jsvg/jsvg.js +898 -898
- package/jsvg/jsvgComponents.js +357 -358
- package/npm-docs/DOCUMENTATION_SUMMARY.md +220 -220
- package/npm-docs/README.md +251 -251
- package/npm-docs/api/api-reference.md +85 -85
- package/npm-docs/api/configuration-options.md +198 -198
- package/npm-docs/api/eventManager.md +82 -82
- package/npm-docs/api/expression-nodes.md +561 -561
- package/npm-docs/api/focusFrameManager.md +144 -144
- package/npm-docs/api/index.md +105 -105
- package/npm-docs/api/main.md +62 -62
- package/npm-docs/api/omdBinaryExpressionNode.md +86 -86
- package/npm-docs/api/omdCanvas.md +83 -83
- package/npm-docs/api/omdConfigManager.md +112 -112
- package/npm-docs/api/omdConstantNode.md +52 -52
- package/npm-docs/api/omdDisplay.md +87 -87
- package/npm-docs/api/omdEquationNode.md +174 -174
- package/npm-docs/api/omdEquationSequenceNode.md +258 -258
- package/npm-docs/api/omdEquationStack.md +192 -192
- package/npm-docs/api/omdFunctionNode.md +82 -82
- package/npm-docs/api/omdGroupNode.md +78 -78
- package/npm-docs/api/omdHelpers.md +87 -87
- package/npm-docs/api/omdLeafNode.md +85 -85
- package/npm-docs/api/omdNode.md +201 -201
- package/npm-docs/api/omdOperationDisplayNode.md +117 -117
- package/npm-docs/api/omdOperatorNode.md +91 -91
- package/npm-docs/api/omdParenthesisNode.md +133 -133
- package/npm-docs/api/omdPopup.md +191 -191
- package/npm-docs/api/omdPowerNode.md +131 -131
- package/npm-docs/api/omdRationalNode.md +144 -144
- package/npm-docs/api/omdSequenceNode.md +128 -128
- package/npm-docs/api/omdSimplification.md +78 -78
- package/npm-docs/api/omdSqrtNode.md +144 -144
- package/npm-docs/api/omdStepVisualizer.md +146 -146
- package/npm-docs/api/omdStepVisualizerHighlighting.md +65 -65
- package/npm-docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
- package/npm-docs/api/omdStepVisualizerLayout.md +70 -70
- package/npm-docs/api/omdStepVisualizerNodeUtils.md +140 -140
- package/npm-docs/api/omdStepVisualizerTextBoxes.md +76 -76
- package/npm-docs/api/omdToolbar.md +130 -130
- package/npm-docs/api/omdTranscriptionService.md +95 -95
- package/npm-docs/api/omdTreeDiff.md +169 -169
- package/npm-docs/api/omdUnaryExpressionNode.md +137 -137
- package/npm-docs/api/omdUtilities.md +82 -82
- package/npm-docs/api/omdVariableNode.md +123 -123
- package/npm-docs/api/selectTool.md +74 -74
- package/npm-docs/api/simplificationEngine.md +97 -97
- package/npm-docs/api/simplificationRules.md +76 -76
- package/npm-docs/api/simplificationUtils.md +64 -64
- package/npm-docs/api/transcribe.md +43 -43
- package/npm-docs/guides/equations.md +854 -854
- package/npm-docs/guides/factory-functions.md +354 -354
- package/npm-docs/guides/getting-started.md +318 -318
- package/npm-docs/guides/quick-examples.md +525 -525
- package/npm-docs/guides/visualizations.md +682 -682
- package/npm-docs/index.html +12 -0
- package/npm-docs/json-schemas.md +826 -826
- package/omd/config/omdConfigManager.js +279 -267
- package/omd/core/index.js +158 -158
- package/omd/core/omdEquationStack.js +606 -547
- package/omd/core/omdUtilities.js +113 -113
- package/omd/display/omdDisplay.js +1045 -963
- package/omd/display/omdToolbar.js +501 -501
- package/omd/nodes/omdBinaryExpressionNode.js +459 -459
- package/omd/nodes/omdConstantNode.js +141 -141
- package/omd/nodes/omdEquationNode.js +1327 -1327
- package/omd/nodes/omdFunctionNode.js +351 -351
- package/omd/nodes/omdGroupNode.js +67 -67
- package/omd/nodes/omdLeafNode.js +76 -76
- package/omd/nodes/omdNode.js +556 -556
- package/omd/nodes/omdOperationDisplayNode.js +321 -321
- package/omd/nodes/omdOperatorNode.js +108 -108
- package/omd/nodes/omdParenthesisNode.js +292 -292
- package/omd/nodes/omdPowerNode.js +235 -235
- package/omd/nodes/omdRationalNode.js +295 -295
- package/omd/nodes/omdSqrtNode.js +307 -307
- package/omd/nodes/omdUnaryExpressionNode.js +227 -227
- package/omd/nodes/omdVariableNode.js +122 -122
- package/omd/simplification/omdSimplification.js +140 -140
- package/omd/simplification/omdSimplificationEngine.js +887 -887
- package/omd/simplification/package.json +5 -5
- package/omd/simplification/rules/binaryRules.js +1037 -1037
- package/omd/simplification/rules/functionRules.js +111 -111
- package/omd/simplification/rules/index.js +48 -48
- package/omd/simplification/rules/parenthesisRules.js +19 -19
- package/omd/simplification/rules/powerRules.js +143 -143
- package/omd/simplification/rules/rationalRules.js +725 -725
- package/omd/simplification/rules/sqrtRules.js +48 -48
- package/omd/simplification/rules/unaryRules.js +37 -37
- package/omd/simplification/simplificationRules.js +31 -31
- package/omd/simplification/simplificationUtils.js +1055 -1055
- package/omd/step-visualizer/omdStepVisualizer.js +947 -947
- package/omd/step-visualizer/omdStepVisualizerHighlighting.js +246 -246
- package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
- package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +200 -200
- package/omd/utils/aiNextEquationStep.js +106 -106
- package/omd/utils/omdNodeOverlay.js +638 -638
- package/omd/utils/omdPopup.js +1203 -1203
- package/omd/utils/omdStepVisualizerInteractiveSteps.js +684 -684
- package/omd/utils/omdStepVisualizerNodeUtils.js +267 -267
- package/omd/utils/omdTranscriptionService.js +123 -123
- package/omd/utils/omdTreeDiff.js +733 -733
- package/package.json +59 -57
- package/readme.html +184 -120
- package/src/index.js +74 -74
- package/src/json-schemas.md +576 -576
- package/src/omd-json-samples.js +147 -147
- package/src/omdApp.js +391 -391
- package/src/omdAppCanvas.js +335 -335
- package/src/omdBalanceHanger.js +199 -199
- package/src/omdColor.js +13 -13
- package/src/omdCoordinatePlane.js +541 -541
- package/src/omdExpression.js +115 -115
- package/src/omdFactory.js +150 -150
- package/src/omdFunction.js +114 -114
- package/src/omdMetaExpression.js +290 -290
- package/src/omdNaturalExpression.js +563 -563
- package/src/omdNode.js +383 -383
- package/src/omdNumber.js +52 -52
- package/src/omdNumberLine.js +114 -112
- package/src/omdNumberTile.js +118 -118
- package/src/omdOperator.js +72 -72
- package/src/omdPowerExpression.js +91 -91
- package/src/omdProblem.js +259 -259
- package/src/omdRatioChart.js +251 -251
- package/src/omdRationalExpression.js +114 -114
- package/src/omdSampleData.js +215 -215
- package/src/omdShapes.js +512 -512
- package/src/omdSpinner.js +151 -151
- package/src/omdString.js +49 -49
- package/src/omdTable.js +498 -498
- package/src/omdTapeDiagram.js +244 -244
- package/src/omdTerm.js +91 -91
- package/src/omdTileEquation.js +349 -349
- package/src/omdUtils.js +84 -84
- package/src/omdVariable.js +51 -51
package/src/omdAppCanvas.js
CHANGED
|
@@ -1,336 +1,336 @@
|
|
|
1
|
-
|
|
2
|
-
import { omdColor } from "./omdColor.js";
|
|
3
|
-
import { omdNumber } from "./omdNumber.js";
|
|
4
|
-
import { omdVariable } from "./omdVariable.js";
|
|
5
|
-
import { omdTerm } from "./omdTerm.js";
|
|
6
|
-
import { omdOperator } from "./omdOperator.js";
|
|
7
|
-
import { omdExpression } from "./omdExpression.js";
|
|
8
|
-
import { omdPowerExpression } from "./omdPowerExpression.js";
|
|
9
|
-
import { omdRationalExpression } from "./omdRationalExpression.js";
|
|
10
|
-
import { omdEquation } from "./omdEquation.js";
|
|
11
|
-
import { omdFunction } from "./omdFunction.js";
|
|
12
|
-
import { omdNumberLine } from "./omdNumberLine.js";
|
|
13
|
-
import { omdTapeDiagram } from "./omdTapeDiagram.js";
|
|
14
|
-
import { omdBalanceHanger } from "./omdBalanceHanger.js";
|
|
15
|
-
import { omdNumberTile } from "./omdNumberTile.js";
|
|
16
|
-
import { omdRatioChart } from "./omdRatioChart.js";
|
|
17
|
-
import { omdCoordinatePlane } from "./omdCoordinatePlane.js";
|
|
18
|
-
import { omdSpinner } from "./omdSpinner.js";
|
|
19
|
-
import { omdRightTriangle } from "./omdShapes.js";
|
|
20
|
-
import { omdIsoscelesTriangle } from "./omdShapes.js";
|
|
21
|
-
import { omdRectangle } from "./omdShapes.js";
|
|
22
|
-
import { omdEllipse } from "./omdShapes.js";
|
|
23
|
-
import { omdCircle } from "./omdShapes.js";
|
|
24
|
-
import { omdRegularPolygon } from "./omdShapes.js";
|
|
25
|
-
import { omdProblem } from "./omdProblem.js";
|
|
26
|
-
import { jsvgGroup, jsvgTextBox, jsvgTextArea, jsvgButton, jsvgEllipse } from "@teachinglab/jsvg";
|
|
27
|
-
|
|
28
|
-
export class omdAppCanvas extends jsvgGroup
|
|
29
|
-
{
|
|
30
|
-
constructor()
|
|
31
|
-
{
|
|
32
|
-
// initialization
|
|
33
|
-
super();
|
|
34
|
-
|
|
35
|
-
console.log("canvas!!!");
|
|
36
|
-
|
|
37
|
-
window.theApp = this;
|
|
38
|
-
|
|
39
|
-
window.addEventListener("resize", this.onResize.bind(this) );
|
|
40
|
-
window.addEventListener("keydown", this.onKeydown.bind(this) );
|
|
41
|
-
|
|
42
|
-
// upward shift
|
|
43
|
-
this.setPosition( 0, -50 );
|
|
44
|
-
|
|
45
|
-
// AI stuff
|
|
46
|
-
this.inputField = new jsvgTextArea();
|
|
47
|
-
this.inputField.setPlaceholderText( "please enter your request here" );
|
|
48
|
-
this.inputField.setWidthAndHeight( 600, 100 );
|
|
49
|
-
this.inputField.setPosition( 100, 100 );
|
|
50
|
-
this.inputField.setFontFamily( "Albert Sans" );
|
|
51
|
-
this.inputField.setFontColor( "black" );
|
|
52
|
-
this.inputField.setFontSize( 18 );
|
|
53
|
-
this.inputField.div.style.backgroundColor = "#FFDD00"; //omdColor.lightGray;
|
|
54
|
-
this.inputField.div.style.border = "0px";
|
|
55
|
-
this.inputField.div.style.padding = "10px";
|
|
56
|
-
this.addChild( this.inputField );
|
|
57
|
-
|
|
58
|
-
this.inputButton = new jsvgButton();
|
|
59
|
-
this.inputButton.setText( "submit" );
|
|
60
|
-
this.inputButton.setFillColor( omdColor.lightGray );
|
|
61
|
-
this.inputButton.setPosition( 100, 220 );
|
|
62
|
-
this.inputButton.setClickCallback( this.handleSubmitClick.bind(this) );
|
|
63
|
-
this.addChild( this.inputButton );
|
|
64
|
-
|
|
65
|
-
this.responseText = new jsvgTextBox();
|
|
66
|
-
this.responseText.setText("");
|
|
67
|
-
this.responseText.setWidthAndHeight( 400, 30 );
|
|
68
|
-
this.responseText.setPosition( 100, 260 );
|
|
69
|
-
this.responseText.setFontFamily( "Albert Sans" );
|
|
70
|
-
this.responseText.setFontColor( omdColor.darkGray );
|
|
71
|
-
this.responseText.setFontSize( 14 );
|
|
72
|
-
this.addChild( this.responseText );
|
|
73
|
-
|
|
74
|
-
this.AIholder = new jsvgGroup();
|
|
75
|
-
this.AIholder.setPosition( 100, 350 );
|
|
76
|
-
this.addChild( this.AIholder );
|
|
77
|
-
|
|
78
|
-
// resize
|
|
79
|
-
this.onResize();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
onKeydown( event )
|
|
83
|
-
{
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
update()
|
|
87
|
-
{
|
|
88
|
-
super.update();
|
|
89
|
-
|
|
90
|
-
window.equatorScale = 1.5;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
onResize()
|
|
94
|
-
{
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
handleSubmitClick( B )
|
|
98
|
-
{
|
|
99
|
-
this.responseText.setText( "working..." );
|
|
100
|
-
|
|
101
|
-
var text = this.inputField.getText();
|
|
102
|
-
console.log( text );
|
|
103
|
-
this.fetchAI( text );
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
handleAIResponse( jsonData )
|
|
107
|
-
{
|
|
108
|
-
var N = null;
|
|
109
|
-
|
|
110
|
-
if ( jsonData.omdType == "number" ) { var N = new omdNumber(); }
|
|
111
|
-
|
|
112
|
-
if ( jsonData.omdType == "variable" ) { var N = new omdVariable(); }
|
|
113
|
-
|
|
114
|
-
if ( jsonData.omdType == "operator" ) { var N = new omdOperator(); }
|
|
115
|
-
|
|
116
|
-
if ( jsonData.omdType == "term" ) { var N = new omdTerm(); }
|
|
117
|
-
|
|
118
|
-
if ( jsonData.omdType == "expression" ) { var N = new omdExpression(); }
|
|
119
|
-
|
|
120
|
-
if ( jsonData.omdType == "powerExpression" ) { var N = new omdPowerExpression(); }
|
|
121
|
-
|
|
122
|
-
if ( jsonData.omdType == "rationalExpression" ) { var N = new omdRationalExpression(); }
|
|
123
|
-
|
|
124
|
-
if ( jsonData.omdType == "function" ) { var N = new omdFunction(); }
|
|
125
|
-
|
|
126
|
-
if ( jsonData.omdType == "equation" ) { var N = new omdEquation(); }
|
|
127
|
-
|
|
128
|
-
if ( jsonData.omdType == "numberLine" ) { var N = new omdNumberLine(); }
|
|
129
|
-
|
|
130
|
-
if ( jsonData.omdType == "balanceHanger" )
|
|
131
|
-
{
|
|
132
|
-
var N = new omdBalanceHanger();
|
|
133
|
-
N.setPosition( 150, 0 );
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if ( jsonData.omdType == "tapeDiagram" ) { var N = new omdTapeDiagram(); }
|
|
137
|
-
|
|
138
|
-
if ( jsonData.omdType == "numberTile" ) { var N = new omdNumberTile(); }
|
|
139
|
-
|
|
140
|
-
if ( jsonData.omdType == "ratioChart" ) { var N = new omdRatioChart(); }
|
|
141
|
-
|
|
142
|
-
if ( jsonData.omdType == "coordinatePlane" ) { var N = new omdCoordinatePlane(); }
|
|
143
|
-
|
|
144
|
-
if ( jsonData.omdType == "spinner" ) { var N = new omdSpinner(); }
|
|
145
|
-
|
|
146
|
-
if ( jsonData.omdType == "rightTriangle" ) { var N = new omdRightTriangle(); }
|
|
147
|
-
|
|
148
|
-
if ( jsonData.omdType == "isoscelesTriangle" ) { var N = new omdIsoscelesTriangle(); }
|
|
149
|
-
|
|
150
|
-
if ( jsonData.omdType == "rectangle" ) { var N = new omdRectangle(); }
|
|
151
|
-
|
|
152
|
-
if ( jsonData.omdType == "ellipse" ) { var N = new omdEllipse(); }
|
|
153
|
-
|
|
154
|
-
if ( jsonData.omdType == "circle" ) { var N = new omdCircle(); }
|
|
155
|
-
|
|
156
|
-
if ( jsonData.omdType == "regularPolygon" ) { var N = new omdRegularPolygon(); }
|
|
157
|
-
|
|
158
|
-
if ( jsonData.omdType == "problem" ) { var N = new omdProblem(); }
|
|
159
|
-
|
|
160
|
-
// load from json
|
|
161
|
-
N.loadFromJSON( jsonData );
|
|
162
|
-
|
|
163
|
-
// add to the AI holder
|
|
164
|
-
var E = new omdCanvasEntry();
|
|
165
|
-
E.addObject( N );
|
|
166
|
-
this.AIholder.addChild( E );
|
|
167
|
-
return E;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
fetchAI( topic )
|
|
171
|
-
{
|
|
172
|
-
// console.log( "=== fetchAI ===" );
|
|
173
|
-
// console.log( topic );
|
|
174
|
-
|
|
175
|
-
// consturct url based on topic
|
|
176
|
-
var urlToFetch = "";
|
|
177
|
-
if ( window.location.hostname.includes("localhost") )
|
|
178
|
-
urlToFetch = "http://localhost:8888/.netlify/functions/ai-omd-lookup/";
|
|
179
|
-
else
|
|
180
|
-
urlToFetch = "https://teaching-lab-omd.netlify.app/.netlify/functions/ai-omd-lookup/";
|
|
181
|
-
|
|
182
|
-
// add topic
|
|
183
|
-
urlToFetch += "?topic='" + topic + "'";
|
|
184
|
-
// console.log( "URL: " + urlToFetch );
|
|
185
|
-
|
|
186
|
-
// fetch the data
|
|
187
|
-
fetch( urlToFetch )
|
|
188
|
-
.then((response) => response.text())
|
|
189
|
-
.then((body) => {
|
|
190
|
-
|
|
191
|
-
// console.log("==== raw data ======");
|
|
192
|
-
// console.log( body );
|
|
193
|
-
|
|
194
|
-
// console.log("==== preParseData ======");
|
|
195
|
-
var preParseData = body;
|
|
196
|
-
preParseData = preParseData.replaceAll( "`", "" );
|
|
197
|
-
preParseData = preParseData.replaceAll( "json", "" );
|
|
198
|
-
console.log( "=== pre-parse ===" );
|
|
199
|
-
console.log( preParseData );
|
|
200
|
-
|
|
201
|
-
try
|
|
202
|
-
{
|
|
203
|
-
var data = JSON.parse( preParseData );
|
|
204
|
-
console.log( "=== parsedData ===" );
|
|
205
|
-
console.log( data );
|
|
206
|
-
|
|
207
|
-
this.responseText.setText( "" );
|
|
208
|
-
this.handleAIResponse( data );
|
|
209
|
-
}
|
|
210
|
-
catch
|
|
211
|
-
{
|
|
212
|
-
// if parsing failed, try again
|
|
213
|
-
console.log( preParseData );
|
|
214
|
-
console.log(">>> data not parse-able");
|
|
215
|
-
this.responseText.setText( "An error occured. Please try again." );
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
class omdCanvasEntry extends jsvgGroup
|
|
224
|
-
{
|
|
225
|
-
constructor()
|
|
226
|
-
{
|
|
227
|
-
// initialization
|
|
228
|
-
super();
|
|
229
|
-
|
|
230
|
-
this.clickRect = new jsvgEllipse();
|
|
231
|
-
this.clickRect.setWidthAndHeight( 40,40 );
|
|
232
|
-
this.clickRect.setPosition( 10,10 );
|
|
233
|
-
this.clickRect.setFillColor( "transparent" );
|
|
234
|
-
this.addChild( this.clickRect );
|
|
235
|
-
|
|
236
|
-
this.clickRect.svgObject.onmousedown = this.handleMouseDown.bind( this );
|
|
237
|
-
this.clickRect.svgObject.ontouchstart = this.handleMouseDown.bind( this );
|
|
238
|
-
this.clickRect.svgObject.style.cursor = "pointer";
|
|
239
|
-
|
|
240
|
-
this.backRect = new jsvgEllipse();
|
|
241
|
-
this.backRect.setWidthAndHeight( 20,20 );
|
|
242
|
-
this.backRect.setPosition( 10,10 );
|
|
243
|
-
this.backRect.setFillColor( "#DDDDDD" );
|
|
244
|
-
this.addChild( this.backRect );
|
|
245
|
-
|
|
246
|
-
this.backRect.svgObject.onmousedown = this.handleMouseDown.bind( this );
|
|
247
|
-
this.backRect.svgObject.ontouchstart = this.handleMouseDown.bind( this );
|
|
248
|
-
this.backRect.svgObject.style.cursor = "pointer";
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
addObject( obj )
|
|
252
|
-
{
|
|
253
|
-
this.theObject = obj;
|
|
254
|
-
obj.setPosition( 10,10 );
|
|
255
|
-
this.addChild( obj );
|
|
256
|
-
|
|
257
|
-
//var W = this.theObject.width;
|
|
258
|
-
//var H = this.theObject.height;
|
|
259
|
-
//this.backRect.setWidthAndHeight( W+20,H+20 );
|
|
260
|
-
//this.backRect.setWidthAndHeight( 20,20 );
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
handleMouseDown( event )
|
|
264
|
-
{
|
|
265
|
-
if ( ! this.visible )
|
|
266
|
-
return;
|
|
267
|
-
|
|
268
|
-
// select
|
|
269
|
-
// window.theApp.setActiveEntry( this );
|
|
270
|
-
|
|
271
|
-
// handle dragging
|
|
272
|
-
function handleMouseMove(event)
|
|
273
|
-
{
|
|
274
|
-
event.preventDefault();
|
|
275
|
-
|
|
276
|
-
// get mouseX and mouseY
|
|
277
|
-
var mouseX, mouseY;
|
|
278
|
-
if ( event.touches && event.touches.length >= 1 )
|
|
279
|
-
{
|
|
280
|
-
mouseX = event.touches[0].clientX;
|
|
281
|
-
mouseY = event.touches[0].clientY;
|
|
282
|
-
}
|
|
283
|
-
else
|
|
284
|
-
{
|
|
285
|
-
mouseX = event.clientX;
|
|
286
|
-
mouseY = event.clientY;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// calculate dX and dY
|
|
290
|
-
if ( this.oldMouseX && this.oldMouseY )
|
|
291
|
-
{
|
|
292
|
-
var dX = mouseX - this.oldMouseX;
|
|
293
|
-
var dY = mouseY - this.oldMouseY;
|
|
294
|
-
|
|
295
|
-
// dX /= window.dragScale; // adjust for drag scale
|
|
296
|
-
// dY /= window.dragScale; // adjust for drag scale
|
|
297
|
-
|
|
298
|
-
var pX = this.xpos + dX;
|
|
299
|
-
var pY = this.ypos + dY;
|
|
300
|
-
|
|
301
|
-
// move the circle
|
|
302
|
-
this.setPosition( pX, pY );
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// set oldMouseX and oldMouseY
|
|
306
|
-
this.oldMouseX = mouseX;
|
|
307
|
-
this.oldMouseY = mouseY;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// on mouse up
|
|
311
|
-
function handleMouseUp(event)
|
|
312
|
-
{
|
|
313
|
-
// set active dot
|
|
314
|
-
// window.theApp.setActiveEntry( this ); // this forces an update to the detail panel
|
|
315
|
-
|
|
316
|
-
// update data in firebase
|
|
317
|
-
// this.updateEntryInDatabase();
|
|
318
|
-
|
|
319
|
-
// console.log("handleMouseUp");
|
|
320
|
-
// this.activeDot = null;
|
|
321
|
-
window.onmousemove = null;
|
|
322
|
-
window.ontouchmove = null;
|
|
323
|
-
window.onmouseup = null;
|
|
324
|
-
window.ontouchend = null;
|
|
325
|
-
this.oldMouseX = 0;
|
|
326
|
-
this.oldMouseY = 0;
|
|
327
|
-
|
|
328
|
-
// this.dotHilite.hide();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
window.onmousemove = handleMouseMove.bind(this);
|
|
332
|
-
window.ontouchmove = handleMouseMove.bind(this);;
|
|
333
|
-
window.onmouseup = handleMouseUp.bind(this);
|
|
334
|
-
window.ontouchend = handleMouseUp.bind(this);;
|
|
335
|
-
}
|
|
1
|
+
|
|
2
|
+
import { omdColor } from "./omdColor.js";
|
|
3
|
+
import { omdNumber } from "./omdNumber.js";
|
|
4
|
+
import { omdVariable } from "./omdVariable.js";
|
|
5
|
+
import { omdTerm } from "./omdTerm.js";
|
|
6
|
+
import { omdOperator } from "./omdOperator.js";
|
|
7
|
+
import { omdExpression } from "./omdExpression.js";
|
|
8
|
+
import { omdPowerExpression } from "./omdPowerExpression.js";
|
|
9
|
+
import { omdRationalExpression } from "./omdRationalExpression.js";
|
|
10
|
+
import { omdEquation } from "./omdEquation.js";
|
|
11
|
+
import { omdFunction } from "./omdFunction.js";
|
|
12
|
+
import { omdNumberLine } from "./omdNumberLine.js";
|
|
13
|
+
import { omdTapeDiagram } from "./omdTapeDiagram.js";
|
|
14
|
+
import { omdBalanceHanger } from "./omdBalanceHanger.js";
|
|
15
|
+
import { omdNumberTile } from "./omdNumberTile.js";
|
|
16
|
+
import { omdRatioChart } from "./omdRatioChart.js";
|
|
17
|
+
import { omdCoordinatePlane } from "./omdCoordinatePlane.js";
|
|
18
|
+
import { omdSpinner } from "./omdSpinner.js";
|
|
19
|
+
import { omdRightTriangle } from "./omdShapes.js";
|
|
20
|
+
import { omdIsoscelesTriangle } from "./omdShapes.js";
|
|
21
|
+
import { omdRectangle } from "./omdShapes.js";
|
|
22
|
+
import { omdEllipse } from "./omdShapes.js";
|
|
23
|
+
import { omdCircle } from "./omdShapes.js";
|
|
24
|
+
import { omdRegularPolygon } from "./omdShapes.js";
|
|
25
|
+
import { omdProblem } from "./omdProblem.js";
|
|
26
|
+
import { jsvgGroup, jsvgTextBox, jsvgTextArea, jsvgButton, jsvgEllipse } from "@teachinglab/jsvg";
|
|
27
|
+
|
|
28
|
+
export class omdAppCanvas extends jsvgGroup
|
|
29
|
+
{
|
|
30
|
+
constructor()
|
|
31
|
+
{
|
|
32
|
+
// initialization
|
|
33
|
+
super();
|
|
34
|
+
|
|
35
|
+
console.log("canvas!!!");
|
|
36
|
+
|
|
37
|
+
window.theApp = this;
|
|
38
|
+
|
|
39
|
+
window.addEventListener("resize", this.onResize.bind(this) );
|
|
40
|
+
window.addEventListener("keydown", this.onKeydown.bind(this) );
|
|
41
|
+
|
|
42
|
+
// upward shift
|
|
43
|
+
this.setPosition( 0, -50 );
|
|
44
|
+
|
|
45
|
+
// AI stuff
|
|
46
|
+
this.inputField = new jsvgTextArea();
|
|
47
|
+
this.inputField.setPlaceholderText( "please enter your request here" );
|
|
48
|
+
this.inputField.setWidthAndHeight( 600, 100 );
|
|
49
|
+
this.inputField.setPosition( 100, 100 );
|
|
50
|
+
this.inputField.setFontFamily( "Albert Sans" );
|
|
51
|
+
this.inputField.setFontColor( "black" );
|
|
52
|
+
this.inputField.setFontSize( 18 );
|
|
53
|
+
this.inputField.div.style.backgroundColor = "#FFDD00"; //omdColor.lightGray;
|
|
54
|
+
this.inputField.div.style.border = "0px";
|
|
55
|
+
this.inputField.div.style.padding = "10px";
|
|
56
|
+
this.addChild( this.inputField );
|
|
57
|
+
|
|
58
|
+
this.inputButton = new jsvgButton();
|
|
59
|
+
this.inputButton.setText( "submit" );
|
|
60
|
+
this.inputButton.setFillColor( omdColor.lightGray );
|
|
61
|
+
this.inputButton.setPosition( 100, 220 );
|
|
62
|
+
this.inputButton.setClickCallback( this.handleSubmitClick.bind(this) );
|
|
63
|
+
this.addChild( this.inputButton );
|
|
64
|
+
|
|
65
|
+
this.responseText = new jsvgTextBox();
|
|
66
|
+
this.responseText.setText("");
|
|
67
|
+
this.responseText.setWidthAndHeight( 400, 30 );
|
|
68
|
+
this.responseText.setPosition( 100, 260 );
|
|
69
|
+
this.responseText.setFontFamily( "Albert Sans" );
|
|
70
|
+
this.responseText.setFontColor( omdColor.darkGray );
|
|
71
|
+
this.responseText.setFontSize( 14 );
|
|
72
|
+
this.addChild( this.responseText );
|
|
73
|
+
|
|
74
|
+
this.AIholder = new jsvgGroup();
|
|
75
|
+
this.AIholder.setPosition( 100, 350 );
|
|
76
|
+
this.addChild( this.AIholder );
|
|
77
|
+
|
|
78
|
+
// resize
|
|
79
|
+
this.onResize();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
onKeydown( event )
|
|
83
|
+
{
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
update()
|
|
87
|
+
{
|
|
88
|
+
super.update();
|
|
89
|
+
|
|
90
|
+
window.equatorScale = 1.5;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onResize()
|
|
94
|
+
{
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
handleSubmitClick( B )
|
|
98
|
+
{
|
|
99
|
+
this.responseText.setText( "working..." );
|
|
100
|
+
|
|
101
|
+
var text = this.inputField.getText();
|
|
102
|
+
console.log( text );
|
|
103
|
+
this.fetchAI( text );
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
handleAIResponse( jsonData )
|
|
107
|
+
{
|
|
108
|
+
var N = null;
|
|
109
|
+
|
|
110
|
+
if ( jsonData.omdType == "number" ) { var N = new omdNumber(); }
|
|
111
|
+
|
|
112
|
+
if ( jsonData.omdType == "variable" ) { var N = new omdVariable(); }
|
|
113
|
+
|
|
114
|
+
if ( jsonData.omdType == "operator" ) { var N = new omdOperator(); }
|
|
115
|
+
|
|
116
|
+
if ( jsonData.omdType == "term" ) { var N = new omdTerm(); }
|
|
117
|
+
|
|
118
|
+
if ( jsonData.omdType == "expression" ) { var N = new omdExpression(); }
|
|
119
|
+
|
|
120
|
+
if ( jsonData.omdType == "powerExpression" ) { var N = new omdPowerExpression(); }
|
|
121
|
+
|
|
122
|
+
if ( jsonData.omdType == "rationalExpression" ) { var N = new omdRationalExpression(); }
|
|
123
|
+
|
|
124
|
+
if ( jsonData.omdType == "function" ) { var N = new omdFunction(); }
|
|
125
|
+
|
|
126
|
+
if ( jsonData.omdType == "equation" ) { var N = new omdEquation(); }
|
|
127
|
+
|
|
128
|
+
if ( jsonData.omdType == "numberLine" ) { var N = new omdNumberLine(); }
|
|
129
|
+
|
|
130
|
+
if ( jsonData.omdType == "balanceHanger" )
|
|
131
|
+
{
|
|
132
|
+
var N = new omdBalanceHanger();
|
|
133
|
+
N.setPosition( 150, 0 );
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if ( jsonData.omdType == "tapeDiagram" ) { var N = new omdTapeDiagram(); }
|
|
137
|
+
|
|
138
|
+
if ( jsonData.omdType == "numberTile" ) { var N = new omdNumberTile(); }
|
|
139
|
+
|
|
140
|
+
if ( jsonData.omdType == "ratioChart" ) { var N = new omdRatioChart(); }
|
|
141
|
+
|
|
142
|
+
if ( jsonData.omdType == "coordinatePlane" ) { var N = new omdCoordinatePlane(); }
|
|
143
|
+
|
|
144
|
+
if ( jsonData.omdType == "spinner" ) { var N = new omdSpinner(); }
|
|
145
|
+
|
|
146
|
+
if ( jsonData.omdType == "rightTriangle" ) { var N = new omdRightTriangle(); }
|
|
147
|
+
|
|
148
|
+
if ( jsonData.omdType == "isoscelesTriangle" ) { var N = new omdIsoscelesTriangle(); }
|
|
149
|
+
|
|
150
|
+
if ( jsonData.omdType == "rectangle" ) { var N = new omdRectangle(); }
|
|
151
|
+
|
|
152
|
+
if ( jsonData.omdType == "ellipse" ) { var N = new omdEllipse(); }
|
|
153
|
+
|
|
154
|
+
if ( jsonData.omdType == "circle" ) { var N = new omdCircle(); }
|
|
155
|
+
|
|
156
|
+
if ( jsonData.omdType == "regularPolygon" ) { var N = new omdRegularPolygon(); }
|
|
157
|
+
|
|
158
|
+
if ( jsonData.omdType == "problem" ) { var N = new omdProblem(); }
|
|
159
|
+
|
|
160
|
+
// load from json
|
|
161
|
+
N.loadFromJSON( jsonData );
|
|
162
|
+
|
|
163
|
+
// add to the AI holder
|
|
164
|
+
var E = new omdCanvasEntry();
|
|
165
|
+
E.addObject( N );
|
|
166
|
+
this.AIholder.addChild( E );
|
|
167
|
+
return E;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
fetchAI( topic )
|
|
171
|
+
{
|
|
172
|
+
// console.log( "=== fetchAI ===" );
|
|
173
|
+
// console.log( topic );
|
|
174
|
+
|
|
175
|
+
// consturct url based on topic
|
|
176
|
+
var urlToFetch = "";
|
|
177
|
+
if ( window.location.hostname.includes("localhost") )
|
|
178
|
+
urlToFetch = "http://localhost:8888/.netlify/functions/ai-omd-lookup/";
|
|
179
|
+
else
|
|
180
|
+
urlToFetch = "https://teaching-lab-omd.netlify.app/.netlify/functions/ai-omd-lookup/";
|
|
181
|
+
|
|
182
|
+
// add topic
|
|
183
|
+
urlToFetch += "?topic='" + topic + "'";
|
|
184
|
+
// console.log( "URL: " + urlToFetch );
|
|
185
|
+
|
|
186
|
+
// fetch the data
|
|
187
|
+
fetch( urlToFetch )
|
|
188
|
+
.then((response) => response.text())
|
|
189
|
+
.then((body) => {
|
|
190
|
+
|
|
191
|
+
// console.log("==== raw data ======");
|
|
192
|
+
// console.log( body );
|
|
193
|
+
|
|
194
|
+
// console.log("==== preParseData ======");
|
|
195
|
+
var preParseData = body;
|
|
196
|
+
preParseData = preParseData.replaceAll( "`", "" );
|
|
197
|
+
preParseData = preParseData.replaceAll( "json", "" );
|
|
198
|
+
console.log( "=== pre-parse ===" );
|
|
199
|
+
console.log( preParseData );
|
|
200
|
+
|
|
201
|
+
try
|
|
202
|
+
{
|
|
203
|
+
var data = JSON.parse( preParseData );
|
|
204
|
+
console.log( "=== parsedData ===" );
|
|
205
|
+
console.log( data );
|
|
206
|
+
|
|
207
|
+
this.responseText.setText( "" );
|
|
208
|
+
this.handleAIResponse( data );
|
|
209
|
+
}
|
|
210
|
+
catch
|
|
211
|
+
{
|
|
212
|
+
// if parsing failed, try again
|
|
213
|
+
console.log( preParseData );
|
|
214
|
+
console.log(">>> data not parse-able");
|
|
215
|
+
this.responseText.setText( "An error occured. Please try again." );
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class omdCanvasEntry extends jsvgGroup
|
|
224
|
+
{
|
|
225
|
+
constructor()
|
|
226
|
+
{
|
|
227
|
+
// initialization
|
|
228
|
+
super();
|
|
229
|
+
|
|
230
|
+
this.clickRect = new jsvgEllipse();
|
|
231
|
+
this.clickRect.setWidthAndHeight( 40,40 );
|
|
232
|
+
this.clickRect.setPosition( 10,10 );
|
|
233
|
+
this.clickRect.setFillColor( "transparent" );
|
|
234
|
+
this.addChild( this.clickRect );
|
|
235
|
+
|
|
236
|
+
this.clickRect.svgObject.onmousedown = this.handleMouseDown.bind( this );
|
|
237
|
+
this.clickRect.svgObject.ontouchstart = this.handleMouseDown.bind( this );
|
|
238
|
+
this.clickRect.svgObject.style.cursor = "pointer";
|
|
239
|
+
|
|
240
|
+
this.backRect = new jsvgEllipse();
|
|
241
|
+
this.backRect.setWidthAndHeight( 20,20 );
|
|
242
|
+
this.backRect.setPosition( 10,10 );
|
|
243
|
+
this.backRect.setFillColor( "#DDDDDD" );
|
|
244
|
+
this.addChild( this.backRect );
|
|
245
|
+
|
|
246
|
+
this.backRect.svgObject.onmousedown = this.handleMouseDown.bind( this );
|
|
247
|
+
this.backRect.svgObject.ontouchstart = this.handleMouseDown.bind( this );
|
|
248
|
+
this.backRect.svgObject.style.cursor = "pointer";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
addObject( obj )
|
|
252
|
+
{
|
|
253
|
+
this.theObject = obj;
|
|
254
|
+
obj.setPosition( 10,10 );
|
|
255
|
+
this.addChild( obj );
|
|
256
|
+
|
|
257
|
+
//var W = this.theObject.width;
|
|
258
|
+
//var H = this.theObject.height;
|
|
259
|
+
//this.backRect.setWidthAndHeight( W+20,H+20 );
|
|
260
|
+
//this.backRect.setWidthAndHeight( 20,20 );
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
handleMouseDown( event )
|
|
264
|
+
{
|
|
265
|
+
if ( ! this.visible )
|
|
266
|
+
return;
|
|
267
|
+
|
|
268
|
+
// select
|
|
269
|
+
// window.theApp.setActiveEntry( this );
|
|
270
|
+
|
|
271
|
+
// handle dragging
|
|
272
|
+
function handleMouseMove(event)
|
|
273
|
+
{
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
|
|
276
|
+
// get mouseX and mouseY
|
|
277
|
+
var mouseX, mouseY;
|
|
278
|
+
if ( event.touches && event.touches.length >= 1 )
|
|
279
|
+
{
|
|
280
|
+
mouseX = event.touches[0].clientX;
|
|
281
|
+
mouseY = event.touches[0].clientY;
|
|
282
|
+
}
|
|
283
|
+
else
|
|
284
|
+
{
|
|
285
|
+
mouseX = event.clientX;
|
|
286
|
+
mouseY = event.clientY;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// calculate dX and dY
|
|
290
|
+
if ( this.oldMouseX && this.oldMouseY )
|
|
291
|
+
{
|
|
292
|
+
var dX = mouseX - this.oldMouseX;
|
|
293
|
+
var dY = mouseY - this.oldMouseY;
|
|
294
|
+
|
|
295
|
+
// dX /= window.dragScale; // adjust for drag scale
|
|
296
|
+
// dY /= window.dragScale; // adjust for drag scale
|
|
297
|
+
|
|
298
|
+
var pX = this.xpos + dX;
|
|
299
|
+
var pY = this.ypos + dY;
|
|
300
|
+
|
|
301
|
+
// move the circle
|
|
302
|
+
this.setPosition( pX, pY );
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// set oldMouseX and oldMouseY
|
|
306
|
+
this.oldMouseX = mouseX;
|
|
307
|
+
this.oldMouseY = mouseY;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// on mouse up
|
|
311
|
+
function handleMouseUp(event)
|
|
312
|
+
{
|
|
313
|
+
// set active dot
|
|
314
|
+
// window.theApp.setActiveEntry( this ); // this forces an update to the detail panel
|
|
315
|
+
|
|
316
|
+
// update data in firebase
|
|
317
|
+
// this.updateEntryInDatabase();
|
|
318
|
+
|
|
319
|
+
// console.log("handleMouseUp");
|
|
320
|
+
// this.activeDot = null;
|
|
321
|
+
window.onmousemove = null;
|
|
322
|
+
window.ontouchmove = null;
|
|
323
|
+
window.onmouseup = null;
|
|
324
|
+
window.ontouchend = null;
|
|
325
|
+
this.oldMouseX = 0;
|
|
326
|
+
this.oldMouseY = 0;
|
|
327
|
+
|
|
328
|
+
// this.dotHilite.hide();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
window.onmousemove = handleMouseMove.bind(this);
|
|
332
|
+
window.ontouchmove = handleMouseMove.bind(this);;
|
|
333
|
+
window.onmouseup = handleMouseUp.bind(this);
|
|
334
|
+
window.ontouchend = handleMouseUp.bind(this);;
|
|
335
|
+
}
|
|
336
336
|
}
|