source: Dev/branches/rest-dojo-ui/client/dojox/calc/GraphPro.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 5.4 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/lang",
4        "dojo/_base/window",
5        "dojo/dom-style",
6        "dojo/dom-construct",
7        "dojo/dom-geometry",
8        "dojo/ready",
9        "dojox/calc/Standard",
10        "dojox/calc/Grapher",
11        "dojox/layout/FloatingPane",
12        "dojo/text!./templates/GraphPro.html",
13        "dojox/calc/_Executor", // template
14        "dijit/Menu", // template
15        "dijit/MenuItem", // template
16        "dijit/form/ComboButton", // template
17        "dijit/form/Button", // template
18        "dijit/form/TextBox" // template
19], function(declare, lang, win, domStyle, domConstruct, domGeometry, ready, Standard, calc, FloatingPane, template){
20
21        /*=====
22                Standard = dojox.calc.Standard;
23        =====*/
24        return declare(
25                "dojox.calc.GraphPro",
26                Standard,
27        {
28                // summary:
29                //              The dialog widget for a graphing, scientific calculator
30                //
31                templateString: template,
32
33                grapher:null,
34                funcMaker:null,
35                aFloatingPane: null,
36
37                executorLoaded: function(){
38                        // summary
39                        //      when executor loads check to see if the writestore is there
40                        this.inherited(arguments);
41                        ready(lang.hitch(this, function(){
42                                if(this.writeStore == null && "functionMakerButton" in this){
43                                        domStyle.set(this.functionMakerButton.domNode, { visibility: "hidden" });
44                                }
45                        }));
46                },
47                makeFunctionWindow: function(){
48                        // summary
49                        //      use this function to create a function window (with the button on the layout)
50                        var body = win.body();
51
52                        var pane = domConstruct.create('div');
53                        body.appendChild(pane);
54
55                        this.aFloatingPane = new dojox.layout.FloatingPane({resizable:false, dockable:true, maxable:false, closable:true, duration:300, title:"Function Window", style:"position:absolute;left:10em;top:10em;width:50em;"}, pane);
56                        var that = this;
57                        var d = domConstruct.create("div");
58                        this.funcMaker = new calc.FuncGen({
59                                writeStore:that.writeStore,
60                                readStore:that.readStore,
61                                functions:that.functions,
62                                deleteFunction: that.executor.deleteFunction,
63                                onSaved:function(){
64                                        var     name,
65                                                body;
66                                        if((name = this.combo.get("value")) == ""){
67                                                this.status.set("value", "The function needs a name");
68                                        }else if((body = this.textarea.get("value")) == ""){
69                                                // i don't think users need empty functions for math
70                                                this.status.set("value", "The function needs a body");
71                                        }else{
72                                                var args = this.args.get("value");
73                                                if(!(name in this.functions)){
74                                                        this.combo.item = this.writeStore.put({name: name, args: args, body: body});
75                                                }
76                                                this.saveFunction(name, args, body);
77                                                this.status.set("value", "Function "+name+" was saved");
78                                        }
79                                },
80                                saveFunction: lang.hitch(that, that.saveFunction)
81                        }, d);
82                        this.aFloatingPane.set('content', this.funcMaker);
83                        this.aFloatingPane.startup();
84                        this.aFloatingPane.bringToTop();
85                },
86                makeGrapherWindow: function(){
87                        // summary
88                        //      use this to make a Grapher window appear with a button
89                        var body = win.body();
90
91                        var pane = domConstruct.create('div');
92                        body.appendChild(pane);
93
94                        this.aFloatingPane = new dojox.layout.FloatingPane({resizable:false, dockable:true, maxable:false, closable:true, duration:300, title:"Graph Window", style:"position:absolute;left:10em;top:5em;width:50em;"}, pane);
95                        var that = this;
96
97                        var d = domConstruct.create("div");
98                        this.grapher = new calc.Grapher({
99                                myPane: this.aFloatingPane,
100                                drawOne: function(i){
101                                        this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));
102                                        this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');
103                                        if(this.array[i][this.expressionIndex].get("value")==""){
104                                                this.setStatus(i, "Error");
105                                                return;
106                                        }
107                                        var func;
108                                        var yEquals = (this.array[i][this.functionMode]=="y=");
109                                        if(this.array[i][this.expressionIndex].get("value")!=this.array[i][this.evaluatedExpression]){
110                                                var args = 'x';
111                                                if(!yEquals){
112                                                        args = 'y';
113                                                }
114                                                func = that.executor.Function('', args, "return "+this.array[i][this.expressionIndex].get('value'));
115                                                this.array[i][this.evaluatedExpression] = this.array[i][this.expressionIndex].value;
116                                                this.array[i][this.functionRef] = func;
117                                        }
118                                        else{
119                                                func = this.array[i][this.functionRef];
120                                        }
121                                        var pickedColor = this.array[i][this.colorIndex].get("value");
122                                        if(!pickedColor){
123                                                pickedColor = 'black';
124                                        }
125                                        calc.draw(this.array[i][this.chartIndex], func, {graphNumber:this.array[i][this.funcNumberIndex], fOfX:yEquals, color:{stroke:{color:pickedColor}}});
126                                        this.setStatus(i, "Drawn");
127                                },
128                                onDraw:function(){
129                                        for(var i = 0; i < this.rowCount; i++){
130                                                if((!this.dirty && this.array[i][this.checkboxIndex].get("checked")) || (this.dirty && this.array[i][this.statusIndex].innerHTML=="Drawn")){
131                                                        this.drawOne(i);
132                                                }else{
133                                                        this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));
134                                                        this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');
135                                                }
136                                        }
137
138                                        var bufferY = domGeometry.position(this.outerDiv).y-domGeometry.position(this.myPane.domNode).y;
139                                        bufferY*=2;
140                                        bufferY=Math.abs(bufferY);
141                                        var height = "" + Math.max(parseInt(this.graphHeight.get('value'))+50, this.outerDiv.scrollHeight+bufferY);
142                                        var width = "" + (parseInt(this.graphWidth.get('value')) + this.outerDiv.scrollWidth);
143                                        this.myPane.resize({w:width, h:height});
144                                }
145                        }, d);
146                        this.aFloatingPane.set('content', this.grapher);
147                        this.aFloatingPane.startup();
148                        this.aFloatingPane.bringToTop();
149                }
150        });
151});
Note: See TracBrowser for help on using the repository browser.