@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.
- package/README.md +138 -0
- package/canvas/core/canvasConfig.js +203 -0
- package/canvas/core/omdCanvas.js +475 -0
- package/canvas/drawing/segment.js +168 -0
- package/canvas/drawing/stroke.js +386 -0
- package/canvas/events/eventManager.js +435 -0
- package/canvas/events/pointerEventHandler.js +263 -0
- package/canvas/features/focusFrameManager.js +287 -0
- package/canvas/index.js +49 -0
- package/canvas/tools/eraserTool.js +322 -0
- package/canvas/tools/pencilTool.js +319 -0
- package/canvas/tools/selectTool.js +457 -0
- package/canvas/tools/tool.js +223 -0
- package/canvas/tools/toolManager.js +394 -0
- package/canvas/ui/cursor.js +438 -0
- package/canvas/ui/toolbar.js +304 -0
- package/canvas/utils/boundingBox.js +378 -0
- package/canvas/utils/mathUtils.js +259 -0
- package/docs/api/configuration-options.md +104 -0
- package/docs/api/eventManager.md +68 -0
- package/docs/api/focusFrameManager.md +150 -0
- package/docs/api/index.md +91 -0
- package/docs/api/main.md +58 -0
- package/docs/api/omdBinaryExpressionNode.md +227 -0
- package/docs/api/omdCanvas.md +142 -0
- package/docs/api/omdConfigManager.md +192 -0
- package/docs/api/omdConstantNode.md +117 -0
- package/docs/api/omdDisplay.md +121 -0
- package/docs/api/omdEquationNode.md +161 -0
- package/docs/api/omdEquationSequenceNode.md +301 -0
- package/docs/api/omdEquationStack.md +139 -0
- package/docs/api/omdFunctionNode.md +141 -0
- package/docs/api/omdGroupNode.md +182 -0
- package/docs/api/omdHelpers.md +96 -0
- package/docs/api/omdLeafNode.md +163 -0
- package/docs/api/omdNode.md +101 -0
- package/docs/api/omdOperationDisplayNode.md +139 -0
- package/docs/api/omdOperatorNode.md +127 -0
- package/docs/api/omdParenthesisNode.md +122 -0
- package/docs/api/omdPopup.md +117 -0
- package/docs/api/omdPowerNode.md +127 -0
- package/docs/api/omdRationalNode.md +128 -0
- package/docs/api/omdSequenceNode.md +128 -0
- package/docs/api/omdSimplification.md +110 -0
- package/docs/api/omdSqrtNode.md +79 -0
- package/docs/api/omdStepVisualizer.md +115 -0
- package/docs/api/omdStepVisualizerHighlighting.md +61 -0
- package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
- package/docs/api/omdStepVisualizerLayout.md +60 -0
- package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
- package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
- package/docs/api/omdToolbar.md +102 -0
- package/docs/api/omdTranscriptionService.md +76 -0
- package/docs/api/omdTreeDiff.md +134 -0
- package/docs/api/omdUnaryExpressionNode.md +174 -0
- package/docs/api/omdUtilities.md +70 -0
- package/docs/api/omdVariableNode.md +148 -0
- package/docs/api/selectTool.md +74 -0
- package/docs/api/simplificationEngine.md +98 -0
- package/docs/api/simplificationRules.md +77 -0
- package/docs/api/simplificationUtils.md +64 -0
- package/docs/api/transcribe.md +43 -0
- package/docs/api-reference.md +85 -0
- package/docs/index.html +454 -0
- package/docs/user-guide.md +9 -0
- package/index.js +67 -0
- package/omd/config/omdConfigManager.js +267 -0
- package/omd/core/index.js +150 -0
- package/omd/core/omdEquationStack.js +347 -0
- package/omd/core/omdUtilities.js +115 -0
- package/omd/display/omdDisplay.js +443 -0
- package/omd/display/omdToolbar.js +502 -0
- package/omd/nodes/omdBinaryExpressionNode.js +460 -0
- package/omd/nodes/omdConstantNode.js +142 -0
- package/omd/nodes/omdEquationNode.js +1223 -0
- package/omd/nodes/omdEquationSequenceNode.js +1273 -0
- package/omd/nodes/omdFunctionNode.js +352 -0
- package/omd/nodes/omdGroupNode.js +68 -0
- package/omd/nodes/omdLeafNode.js +77 -0
- package/omd/nodes/omdNode.js +557 -0
- package/omd/nodes/omdOperationDisplayNode.js +322 -0
- package/omd/nodes/omdOperatorNode.js +109 -0
- package/omd/nodes/omdParenthesisNode.js +293 -0
- package/omd/nodes/omdPowerNode.js +236 -0
- package/omd/nodes/omdRationalNode.js +295 -0
- package/omd/nodes/omdSqrtNode.js +308 -0
- package/omd/nodes/omdUnaryExpressionNode.js +178 -0
- package/omd/nodes/omdVariableNode.js +123 -0
- package/omd/simplification/omdSimplification.js +171 -0
- package/omd/simplification/omdSimplificationEngine.js +886 -0
- package/omd/simplification/package.json +6 -0
- package/omd/simplification/rules/binaryRules.js +1037 -0
- package/omd/simplification/rules/functionRules.js +111 -0
- package/omd/simplification/rules/index.js +48 -0
- package/omd/simplification/rules/parenthesisRules.js +19 -0
- package/omd/simplification/rules/powerRules.js +143 -0
- package/omd/simplification/rules/rationalRules.js +475 -0
- package/omd/simplification/rules/sqrtRules.js +48 -0
- package/omd/simplification/rules/unaryRules.js +37 -0
- package/omd/simplification/simplificationRules.js +32 -0
- package/omd/simplification/simplificationUtils.js +1056 -0
- package/omd/step-visualizer/omdStepVisualizer.js +597 -0
- package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
- package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
- package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
- package/omd/utils/omdNodeOverlay.js +638 -0
- package/omd/utils/omdPopup.js +1084 -0
- package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
- package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
- package/omd/utils/omdTranscriptionService.js +125 -0
- package/omd/utils/omdTreeDiff.js +734 -0
- package/package.json +46 -0
- package/src/index.js +62 -0
- package/src/json-schemas.md +109 -0
- package/src/omd-json-samples.js +115 -0
- package/src/omd.js +109 -0
- package/src/omdApp.js +391 -0
- package/src/omdAppCanvas.js +336 -0
- package/src/omdBalanceHanger.js +172 -0
- package/src/omdColor.js +13 -0
- package/src/omdCoordinatePlane.js +467 -0
- package/src/omdEquation.js +125 -0
- package/src/omdExpression.js +104 -0
- package/src/omdFunction.js +113 -0
- package/src/omdMetaExpression.js +287 -0
- package/src/omdNaturalExpression.js +564 -0
- package/src/omdNode.js +384 -0
- package/src/omdNumber.js +53 -0
- package/src/omdNumberLine.js +107 -0
- package/src/omdNumberTile.js +119 -0
- package/src/omdOperator.js +73 -0
- package/src/omdPowerExpression.js +92 -0
- package/src/omdProblem.js +55 -0
- package/src/omdRatioChart.js +232 -0
- package/src/omdRationalExpression.js +115 -0
- package/src/omdSampleData.js +215 -0
- package/src/omdShapes.js +476 -0
- package/src/omdSpinner.js +148 -0
- package/src/omdString.js +39 -0
- package/src/omdTable.js +369 -0
- package/src/omdTapeDiagram.js +245 -0
- package/src/omdTerm.js +92 -0
- package/src/omdTileEquation.js +349 -0
- package/src/omdVariable.js +51 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
import { omdColor } from "./omdColor.js";
|
|
3
|
+
import { omdMetaExpression } from "./omdMetaExpression.js"
|
|
4
|
+
import { jsvgTextBox } from "@teachinglab/jsvg";
|
|
5
|
+
|
|
6
|
+
export class omdOperator extends omdMetaExpression
|
|
7
|
+
{
|
|
8
|
+
constructor( Oper = '+' )
|
|
9
|
+
{
|
|
10
|
+
// initialization
|
|
11
|
+
super();
|
|
12
|
+
|
|
13
|
+
this.type = "omdOperator";
|
|
14
|
+
this.operator = Oper;
|
|
15
|
+
|
|
16
|
+
this.numText = new jsvgTextBox();
|
|
17
|
+
this.numText.setWidthAndHeight( 30,30 );
|
|
18
|
+
this.numText.setText( this.operator );
|
|
19
|
+
this.numText.setFontFamily( "Albert Sans" );
|
|
20
|
+
this.numText.setFontColor( "black" );
|
|
21
|
+
this.numText.setFontSize( 18 );
|
|
22
|
+
this.numText.setVerticalCentering();
|
|
23
|
+
this.numText.setAlignment("center");
|
|
24
|
+
//]this.numText.div.style.border = "1px solid black";
|
|
25
|
+
this.addChild( this.numText );
|
|
26
|
+
|
|
27
|
+
this.setOperator( Oper );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
loadFromJSON( data )
|
|
31
|
+
{
|
|
32
|
+
if ( typeof data.operator != "undefined" )
|
|
33
|
+
this.setOperator( data.operator );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setOperator( Op )
|
|
37
|
+
{
|
|
38
|
+
if ( Op == '+' )
|
|
39
|
+
this.operator = '+';
|
|
40
|
+
|
|
41
|
+
if ( Op == '-' )
|
|
42
|
+
this.operator = '−';
|
|
43
|
+
|
|
44
|
+
if ( Op == '/' )
|
|
45
|
+
this.operator = '÷';
|
|
46
|
+
if ( Op == '÷' )
|
|
47
|
+
this.operator = '÷';
|
|
48
|
+
|
|
49
|
+
if ( Op == 'x' )
|
|
50
|
+
this.operator = '×';
|
|
51
|
+
if ( Op == '*' )
|
|
52
|
+
this.operator = '×';
|
|
53
|
+
if ( Op == '•' )
|
|
54
|
+
this.operator = '×';
|
|
55
|
+
if ( Op == '×' )
|
|
56
|
+
this.operator = '×';
|
|
57
|
+
if ( Op == '=' )
|
|
58
|
+
this.operator = '=';
|
|
59
|
+
|
|
60
|
+
this.updateLayout();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
updateLayout()
|
|
64
|
+
{
|
|
65
|
+
var T = this.operator;
|
|
66
|
+
var W = 12 + T.length*10;
|
|
67
|
+
this.backRect.setWidthAndHeight( W, 30 );
|
|
68
|
+
this.numText.setWidthAndHeight( W, 30 );
|
|
69
|
+
this.numText.setText ( T );
|
|
70
|
+
|
|
71
|
+
this.setWidthAndHeight( this.backRect.width, this.backRect.height );
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
|
|
2
|
+
import { omdColor } from "./omdColor.js";
|
|
3
|
+
import { omdExpression } from "./omdExpression.js"
|
|
4
|
+
import { omdMetaExpression } from "./omdMetaExpression.js"
|
|
5
|
+
import { omdNumber } from "./omdNumber.js"
|
|
6
|
+
import { omdVariable } from "./omdVariable.js"
|
|
7
|
+
import { omdTerm } from "./omdTerm.js"
|
|
8
|
+
import { jsvgGroup } from "@teachinglab/jsvg";
|
|
9
|
+
|
|
10
|
+
export class omdPowerExpression extends omdMetaExpression
|
|
11
|
+
{
|
|
12
|
+
constructor()
|
|
13
|
+
{
|
|
14
|
+
// initialization
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
this.type = "omdPowerExpression";
|
|
18
|
+
|
|
19
|
+
this.expression = null;
|
|
20
|
+
this.exponent = null;
|
|
21
|
+
|
|
22
|
+
this.expressionHolder = new jsvgGroup();
|
|
23
|
+
this.addChild( this.expressionHolder );
|
|
24
|
+
|
|
25
|
+
this.exponentHolder = new jsvgGroup();
|
|
26
|
+
this.addChild( this.exponentHolder );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// make a power expression of (2x+2)^(3x+3)
|
|
30
|
+
|
|
31
|
+
loadFromJSON( data )
|
|
32
|
+
{
|
|
33
|
+
if ( typeof data.baseExpression != "undefined" )
|
|
34
|
+
{
|
|
35
|
+
// console.log("A");
|
|
36
|
+
// console.log( data.baseExpression );
|
|
37
|
+
if ( data.baseExpression.omdType == "expression" )
|
|
38
|
+
this.expression = new omdExpression();
|
|
39
|
+
if ( data.baseExpression.omdType == "number" )
|
|
40
|
+
this.expression = new omdNumber();
|
|
41
|
+
if ( data.baseExpression.omdType == "variable" )
|
|
42
|
+
this.expression = new omdVariable();
|
|
43
|
+
if ( data.baseExpression.omdType == "term" )
|
|
44
|
+
this.expression = new omdTerm();
|
|
45
|
+
this.expression.loadFromJSON( data.baseExpression );
|
|
46
|
+
this.expressionHolder.removeAllChildren();
|
|
47
|
+
this.expressionHolder.addChild( this.expression );
|
|
48
|
+
}
|
|
49
|
+
if ( typeof data.exponentExpression != "undefined" )
|
|
50
|
+
{
|
|
51
|
+
// console.log("B");
|
|
52
|
+
// console.log( data.exponentExpression );
|
|
53
|
+
if ( data.exponentExpression.omdType == "expression" )
|
|
54
|
+
this.exponent = new omdExpression();
|
|
55
|
+
if ( data.exponentExpression.omdType == "number" )
|
|
56
|
+
this.exponent = new omdNumber();
|
|
57
|
+
if ( data.exponentExpression.omdType == "variable" )
|
|
58
|
+
this.exponent = new omdVariable();
|
|
59
|
+
if ( data.exponentExpression.omdType == "term" )
|
|
60
|
+
this.exponent = new omdTerm();
|
|
61
|
+
this.exponent.loadFromJSON( data.exponentExpression );
|
|
62
|
+
this.exponentHolder.removeAllChildren();
|
|
63
|
+
this.exponentHolder.addChild( this.exponent );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.updateLayout();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setExpressionAndPower( expression, exponent )
|
|
70
|
+
{
|
|
71
|
+
this.expression = expression;
|
|
72
|
+
this.expressionHolder.removeAllChildren();
|
|
73
|
+
this.expressionHolder.addChild( expression );
|
|
74
|
+
|
|
75
|
+
this.exponent = exponent;
|
|
76
|
+
this.exponentHolder.removeAllChildren();
|
|
77
|
+
this.exponentHolder.addChild( exponent );
|
|
78
|
+
|
|
79
|
+
// this.expression.hideBackgroundByDefault();
|
|
80
|
+
// this.exponent.hideBackgroundByDefault();
|
|
81
|
+
|
|
82
|
+
this.updateLayout();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
updateLayout()
|
|
86
|
+
{
|
|
87
|
+
this.expressionHolder.setPosition(0,0);
|
|
88
|
+
|
|
89
|
+
this.exponentHolder.setPosition( this.expression.width-10,-15);
|
|
90
|
+
this.exponentHolder.setScale( 0.70 );
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
import { omdColor } from "./omdColor.js";
|
|
3
|
+
import { jsvgGroup, jsvgTextBox } from "@teachinglab/jsvg";
|
|
4
|
+
|
|
5
|
+
export class omdProblem extends jsvgGroup
|
|
6
|
+
{
|
|
7
|
+
constructor()
|
|
8
|
+
{
|
|
9
|
+
// initialization
|
|
10
|
+
super();
|
|
11
|
+
|
|
12
|
+
this.type = "omdProblem";
|
|
13
|
+
this.theText = "";
|
|
14
|
+
|
|
15
|
+
this.problemText = new jsvgTextBox();
|
|
16
|
+
this.problemText.setWidthAndHeight( 400,130 );
|
|
17
|
+
this.problemText.setText ( "this it the problem text" );
|
|
18
|
+
this.problemText.setFontFamily( "Albert Sans" );
|
|
19
|
+
this.problemText.setFontColor( "black" );
|
|
20
|
+
this.problemText.setFontSize( 18 );
|
|
21
|
+
this.addChild( this.problemText );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
loadFromJSON( data )
|
|
25
|
+
{
|
|
26
|
+
if ( typeof data.problemText != "undefined" )
|
|
27
|
+
this.theText = data.problemText;
|
|
28
|
+
|
|
29
|
+
if ( typeof data.visualization != "undefined" )
|
|
30
|
+
{
|
|
31
|
+
this.visualJSON = data.visualization;
|
|
32
|
+
console.log( this.visualJSON );
|
|
33
|
+
|
|
34
|
+
var obj = window.theApp.handleAIResponse( this.visualJSON );
|
|
35
|
+
obj.parent.removeChild( obj );
|
|
36
|
+
this.addChild( obj );
|
|
37
|
+
obj.setPosition( 0,150 );
|
|
38
|
+
//obj.setPosition( obj.xpos, obj.ypos+120 );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.updateLayout();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setName( newName )
|
|
45
|
+
{
|
|
46
|
+
this.name = newName;
|
|
47
|
+
this.updateLayout();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
updateLayout()
|
|
51
|
+
{
|
|
52
|
+
this.problemText.setText ( this.theText );
|
|
53
|
+
this.setWidthAndHeight( 300,200 );
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
|
|
2
|
+
import { omdColor } from "./omdColor.js";
|
|
3
|
+
import { jsvgGroup, jsvgEllipse, jsvgArc, jsvgLine, jsvgRect } from "@teachinglab/jsvg";
|
|
4
|
+
|
|
5
|
+
export class omdRatioChart extends jsvgGroup
|
|
6
|
+
{
|
|
7
|
+
constructor()
|
|
8
|
+
{
|
|
9
|
+
// initialization
|
|
10
|
+
super();
|
|
11
|
+
|
|
12
|
+
this.type = "omdNumberLine";
|
|
13
|
+
|
|
14
|
+
this.valueA = 1;
|
|
15
|
+
this.valueB = 2;
|
|
16
|
+
this.size = 'large';
|
|
17
|
+
this.renderType = 'pie';
|
|
18
|
+
this.updateLayout();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
loadFromJSON( data )
|
|
22
|
+
{
|
|
23
|
+
if ( typeof data.valueA != "undefined" )
|
|
24
|
+
this.valueA = data.valueA;
|
|
25
|
+
|
|
26
|
+
if ( typeof data.valueB != "undefined" )
|
|
27
|
+
this.valueB = data.valueB;
|
|
28
|
+
|
|
29
|
+
if ( typeof data.renderType != "undefined" )
|
|
30
|
+
this.renderType = data.renderType;
|
|
31
|
+
|
|
32
|
+
if ( typeof data.size != "undefined" )
|
|
33
|
+
this.size = data.size;
|
|
34
|
+
|
|
35
|
+
this.updateLayout();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setValues( A, B )
|
|
39
|
+
{
|
|
40
|
+
this.valueA = A;
|
|
41
|
+
this.valueB = B;
|
|
42
|
+
this.updateLayout();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setRenderType( R )
|
|
46
|
+
{
|
|
47
|
+
this.renderType = R;
|
|
48
|
+
this.updateLayout();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setSize( S )
|
|
52
|
+
{
|
|
53
|
+
this.size = S;
|
|
54
|
+
this.updateLayout();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
updateLayout()
|
|
58
|
+
{
|
|
59
|
+
this.removeAllChildren();
|
|
60
|
+
|
|
61
|
+
if ( this.renderType == 'pie' )
|
|
62
|
+
this.renderAsPie();
|
|
63
|
+
|
|
64
|
+
if ( this.renderType == 'dots' || this.renderType == 'dot' || this.renderType == 'tile' )
|
|
65
|
+
this.renderAsDots();
|
|
66
|
+
|
|
67
|
+
if ( this.renderType == 'bar' )
|
|
68
|
+
this.renderAsBar();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
renderAsPie()
|
|
72
|
+
{
|
|
73
|
+
var circleSize = 120;
|
|
74
|
+
if ( this.size == "large" )
|
|
75
|
+
circleSize = 120;
|
|
76
|
+
if ( this.size == "medium" )
|
|
77
|
+
circleSize = 80;
|
|
78
|
+
if ( this.size == "small" )
|
|
79
|
+
circleSize = 40;
|
|
80
|
+
|
|
81
|
+
// holder group
|
|
82
|
+
var G = new jsvgGroup();
|
|
83
|
+
G.setPosition( circleSize/2, circleSize/2 );
|
|
84
|
+
this.addChild( G );
|
|
85
|
+
|
|
86
|
+
var C = new jsvgEllipse();
|
|
87
|
+
C.setFillColor( omdColor.mediumGray );
|
|
88
|
+
C.setWidthAndHeight( circleSize, circleSize );
|
|
89
|
+
G.addChild( C );
|
|
90
|
+
|
|
91
|
+
var p = this.valueA / ( this.valueA + this.valueB );
|
|
92
|
+
var A1 = 0;
|
|
93
|
+
var A2 = 360 * p;
|
|
94
|
+
|
|
95
|
+
var pieShape = new jsvgArc();
|
|
96
|
+
pieShape.createPieSlice( circleSize / 2.0, A1, A2 );
|
|
97
|
+
pieShape.setFillColor( "black" );
|
|
98
|
+
G.addChild( pieShape );
|
|
99
|
+
|
|
100
|
+
var total = this.valueA + this.valueB;
|
|
101
|
+
var dA = Math.PI*2.0 / total;
|
|
102
|
+
for( var i=0; i<total; i++ )
|
|
103
|
+
{
|
|
104
|
+
var A = i * dA - Math.PI/2.0;
|
|
105
|
+
var pX = Math.cos(A) * circleSize/2;
|
|
106
|
+
var pY = Math.sin(A) * circleSize/2;
|
|
107
|
+
var L = new jsvgLine();
|
|
108
|
+
L.setStrokeColor("white");
|
|
109
|
+
L.setEndpoints( 0, 0, pX, pY );
|
|
110
|
+
G.addChild( L );
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
renderAsDots()
|
|
115
|
+
{
|
|
116
|
+
if ( this.size == 'large' )
|
|
117
|
+
{
|
|
118
|
+
var W = 120;
|
|
119
|
+
var H = 150;
|
|
120
|
+
var dotSize = 15;
|
|
121
|
+
var spacer = W / 4;
|
|
122
|
+
}
|
|
123
|
+
if ( this.size == 'medium' )
|
|
124
|
+
{
|
|
125
|
+
var W = 80;
|
|
126
|
+
var H = 100;
|
|
127
|
+
var dotSize = 12;
|
|
128
|
+
var spacer = W / 4;
|
|
129
|
+
}
|
|
130
|
+
if ( this.size == 'small' )
|
|
131
|
+
{
|
|
132
|
+
var W = 40;
|
|
133
|
+
var H = 50;
|
|
134
|
+
var dotSize = 5;
|
|
135
|
+
var spacer = W / 4;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var R = new jsvgRect();
|
|
139
|
+
R.setWidthAndHeight( W*2,H ); // twice the width
|
|
140
|
+
R.setCornerRadius( dotSize );
|
|
141
|
+
R.setFillColor( omdColor.lightGray );
|
|
142
|
+
this.addChild( R );
|
|
143
|
+
|
|
144
|
+
this.width = R.width;
|
|
145
|
+
this.height = R.height;
|
|
146
|
+
|
|
147
|
+
// make top dots
|
|
148
|
+
var pX = spacer;
|
|
149
|
+
var pY = spacer;
|
|
150
|
+
|
|
151
|
+
for( var i=0; i<this.valueA; i++ )
|
|
152
|
+
{
|
|
153
|
+
var dot = new jsvgEllipse();
|
|
154
|
+
dot.setFillColor( "black" );
|
|
155
|
+
dot.setWidthAndHeight( dotSize,dotSize );
|
|
156
|
+
dot.setPosition( pX, pY );
|
|
157
|
+
this.addChild( dot );
|
|
158
|
+
pX += spacer;
|
|
159
|
+
if ( i != 0 && i%3 == 2 )
|
|
160
|
+
{
|
|
161
|
+
pX = spacer;
|
|
162
|
+
pY += spacer;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// make bottom dots
|
|
167
|
+
var pX = spacer*5;
|
|
168
|
+
var pY = spacer;
|
|
169
|
+
for( var i=0; i<this.valueB; i++ )
|
|
170
|
+
{
|
|
171
|
+
var dot = new jsvgEllipse();
|
|
172
|
+
dot.setFillColor( "black" );
|
|
173
|
+
dot.setWidthAndHeight( dotSize,dotSize );
|
|
174
|
+
dot.setPosition( pX, pY );
|
|
175
|
+
this.addChild( dot );
|
|
176
|
+
pX += spacer;
|
|
177
|
+
if ( i != 0 && i%3 == 2 )
|
|
178
|
+
{
|
|
179
|
+
pX = spacer*5;
|
|
180
|
+
pY += spacer;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// make divider line
|
|
185
|
+
var L = new jsvgLine();
|
|
186
|
+
L.setEndpoints( spacer*4, spacer/2, spacer*4, H-spacer/2 );
|
|
187
|
+
this.addChild( L );
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
renderAsBar()
|
|
191
|
+
{
|
|
192
|
+
if ( this.size == 'large' )
|
|
193
|
+
{
|
|
194
|
+
var W = 240;
|
|
195
|
+
}
|
|
196
|
+
if ( this.size == 'medium' )
|
|
197
|
+
{
|
|
198
|
+
var W = 120;
|
|
199
|
+
}
|
|
200
|
+
if ( this.size == 'small' )
|
|
201
|
+
{
|
|
202
|
+
var W = 80;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
var p = this.valueA / ( this.valueA + this.valueB );
|
|
206
|
+
|
|
207
|
+
var B1 = new jsvgRect();
|
|
208
|
+
B1.setWidthAndHeight( W, 30 );
|
|
209
|
+
// B1.setCornerRadius(5);
|
|
210
|
+
B1.setFillColor( omdColor.mediumGray );
|
|
211
|
+
this.addChild( B1 );
|
|
212
|
+
|
|
213
|
+
var B2 = new jsvgRect();
|
|
214
|
+
// B2.setCornerRadius(5);
|
|
215
|
+
B2.setWidthAndHeight( p*W, 30 );
|
|
216
|
+
B2.setFillColor( "black" );
|
|
217
|
+
this.addChild( B2 );
|
|
218
|
+
|
|
219
|
+
var total = this.valueA + this.valueB;
|
|
220
|
+
var spacer = W / total;
|
|
221
|
+
for( var i=1; i<total; i++ )
|
|
222
|
+
{
|
|
223
|
+
var pX = i * spacer;
|
|
224
|
+
var L = new jsvgLine();
|
|
225
|
+
L.setStrokeColor("white");
|
|
226
|
+
L.setEndpoints( pX, 0, pX, 30 );
|
|
227
|
+
this.addChild( L );
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
|
|
2
|
+
import { omdColor } from "./omdColor.js";
|
|
3
|
+
import { omdMetaExpression } from "./omdMetaExpression.js"
|
|
4
|
+
import { omdExpression } from "./omdExpression.js"
|
|
5
|
+
import { omdNumber } from "./omdNumber.js"
|
|
6
|
+
import { omdVariable } from "./omdVariable.js"
|
|
7
|
+
import { omdTerm } from "./omdTerm.js"
|
|
8
|
+
|
|
9
|
+
export class omdRationalExpression extends omdMetaExpression
|
|
10
|
+
{
|
|
11
|
+
constructor()
|
|
12
|
+
{
|
|
13
|
+
// initialization
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this.type = "omdPowerExpression";
|
|
17
|
+
|
|
18
|
+
this.numeratorExpression = null;
|
|
19
|
+
this.denominatorExpression = null;
|
|
20
|
+
|
|
21
|
+
this.numeratorHolder = new jsvgGroup();
|
|
22
|
+
this.addChild( this.numeratorHolder );
|
|
23
|
+
|
|
24
|
+
this.denominatorHolder = new jsvgGroup();
|
|
25
|
+
this.addChild( this.denominatorHolder );
|
|
26
|
+
|
|
27
|
+
this.dividerLine = new jsvgLine();
|
|
28
|
+
this.setStrokeWidth( 2 );
|
|
29
|
+
this.setStrokeColor( "black" );
|
|
30
|
+
this.addChild( this.dividerLine );
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// make a power expression of (2x+2)^(3x+3)
|
|
34
|
+
|
|
35
|
+
loadFromJSON( data )
|
|
36
|
+
{
|
|
37
|
+
if ( typeof data.numeratorExpression != "undefined" )
|
|
38
|
+
{
|
|
39
|
+
// console.log("A");
|
|
40
|
+
// console.log( data.baseExpression );
|
|
41
|
+
if ( data.numeratorExpression.omdType == "expression" )
|
|
42
|
+
this.numeratorExpression = new omdExpression();
|
|
43
|
+
if ( data.numeratorExpression.omdType == "number" )
|
|
44
|
+
this.numeratorExpression = new omdNumber();
|
|
45
|
+
if ( data.numeratorExpression.omdType == "variable" )
|
|
46
|
+
this.numeratorExpression = new omdVariable();
|
|
47
|
+
if ( data.numeratorExpression.omdType == "term" )
|
|
48
|
+
this.numeratorExpression = new omdTerm();
|
|
49
|
+
this.numeratorExpression.loadFromJSON( data.numeratorExpression );
|
|
50
|
+
this.numeratorHolder.removeAllChildren();
|
|
51
|
+
this.numeratorHolder.addChild( this.numeratorExpression );
|
|
52
|
+
}
|
|
53
|
+
if ( typeof data.denominatorExpression != "undefined" )
|
|
54
|
+
{
|
|
55
|
+
// console.log("B");
|
|
56
|
+
// console.log( data.exponentExpression );
|
|
57
|
+
if ( data.denominatorExpression.omdType == "expression" )
|
|
58
|
+
this.denominatorExpression = new omdExpression();
|
|
59
|
+
if ( data.denominatorExpression.omdType == "number" )
|
|
60
|
+
this.denominatorExpression = new omdNumber();
|
|
61
|
+
if ( data.denominatorExpression.omdType == "variable" )
|
|
62
|
+
this.denominatorExpression = new omdVariable();
|
|
63
|
+
if ( data.denominatorExpression.omdType == "term" )
|
|
64
|
+
this.denominatorExpression = new omdTerm();
|
|
65
|
+
this.denominatorExpression.loadFromJSON( data.denominatorExpression );
|
|
66
|
+
this.denominatorHolder.removeAllChildren();
|
|
67
|
+
this.denominatorHolder.addChild( this.denominatorExpression );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.updateLayout();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
setNumeratorAndDenominator( numerator, denominator )
|
|
75
|
+
{
|
|
76
|
+
this.numeratorExpression = numerator;
|
|
77
|
+
this.numeratorHolder.removeAllChildren();
|
|
78
|
+
this.numeratorHolder.addChild( numerator );
|
|
79
|
+
|
|
80
|
+
this.denominatorExpression = denominator;
|
|
81
|
+
this.denominatorHolder.removeAllChildren();
|
|
82
|
+
this.denominatorHolder.addChild( denominator );
|
|
83
|
+
|
|
84
|
+
this.numeratorExpression.hideBackgroundByDefault();
|
|
85
|
+
this.denominatorExpression.hideBackgroundByDefault();
|
|
86
|
+
|
|
87
|
+
this.updateLayout();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
updateLayout()
|
|
91
|
+
{
|
|
92
|
+
this.numeratorHolder.setPosition(5, 0);
|
|
93
|
+
this.denominatorHolder.setPosition( 5, 30 );
|
|
94
|
+
|
|
95
|
+
// get max width
|
|
96
|
+
var W = this.numeratorExpression.width;
|
|
97
|
+
if ( this.denominatorExpression.width > W )
|
|
98
|
+
W = this.denominatorExpression.width;
|
|
99
|
+
|
|
100
|
+
// center numerator
|
|
101
|
+
var pX = W/2 - this.numeratorExpression.width/2 + 5;
|
|
102
|
+
this.numeratorHolder.setPosition( pX, 0 );
|
|
103
|
+
|
|
104
|
+
// center denominator
|
|
105
|
+
pX = W/2 - this.denominatorExpression.width/2 + 5;
|
|
106
|
+
this.denominatorHolder.setPosition( pX, 30 );
|
|
107
|
+
|
|
108
|
+
// update line width
|
|
109
|
+
this.dividerLine.setEndpoints( 10-5,30, W+5,30 );
|
|
110
|
+
|
|
111
|
+
// update back rect
|
|
112
|
+
this.backRect.setWidthAndHeight( W+10, 60 );
|
|
113
|
+
this.setWidthAndHeight( this.backRect.width, this.backRect.height );
|
|
114
|
+
}
|
|
115
|
+
}
|