| 1 |
define([ |
| 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", |
| 14 |
"dijit/Menu", |
| 15 |
"dijit/MenuItem", |
| 16 |
"dijit/form/ComboButton", |
| 17 |
"dijit/form/Button", |
| 18 |
"dijit/form/TextBox" |
| 19 |
], function(declare, lang, win, domStyle, domConstruct, domGeometry, ready, Standard, calc, FloatingPane, template){ |
| 20 |
|
| 21 |
|
| 22 |
return declare( |
| 23 |
"dojox.calc.GraphPro", |
| 24 |
Standard, |
| 25 |
{ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
templateString: template, |
| 30 |
|
| 31 |
grapher:null, |
| 32 |
funcMaker:null, |
| 33 |
aFloatingPane: null, |
| 34 |
|
| 35 |
executorLoaded: function(){ |
| 36 |
|
| 37 |
|
| 38 |
this.inherited(arguments); |
| 39 |
ready(lang.hitch(this, function(){ |
| 40 |
if(this.writeStore == null && "functionMakerButton" in this){ |
| 41 |
domStyle.set(this.functionMakerButton.domNode, { visibility: "hidden" }); |
| 42 |
} |
| 43 |
})); |
| 44 |
}, |
| 45 |
makeFunctionWindow: function(){ |
| 46 |
|
| 47 |
|
| 48 |
var body = win.body(); |
| 49 |
|
| 50 |
var pane = domConstruct.create('div'); |
| 51 |
body.appendChild(pane); |
| 52 |
|
| 53 |
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); |
| 54 |
var that = this; |
| 55 |
var d = domConstruct.create("div"); |
| 56 |
this.funcMaker = new calc.FuncGen({ |
| 57 |
writeStore:that.writeStore, |
| 58 |
readStore:that.readStore, |
| 59 |
functions:that.functions, |
| 60 |
deleteFunction: that.executor.deleteFunction, |
| 61 |
onSaved:function(){ |
| 62 |
var name, |
| 63 |
body; |
| 64 |
if((name = this.combo.get("value")) == ""){ |
| 65 |
this.status.set("value", "The function needs a name"); |
| 66 |
}else if((body = this.textarea.get("value")) == ""){ |
| 67 |
|
| 68 |
this.status.set("value", "The function needs a body"); |
| 69 |
}else{ |
| 70 |
var args = this.args.get("value"); |
| 71 |
if(!(name in this.functions)){ |
| 72 |
this.combo.item = this.writeStore.put({name: name, args: args, body: body}); |
| 73 |
} |
| 74 |
this.saveFunction(name, args, body); |
| 75 |
this.status.set("value", "Function "+name+" was saved"); |
| 76 |
} |
| 77 |
}, |
| 78 |
saveFunction: lang.hitch(that, that.saveFunction) |
| 79 |
}, d); |
| 80 |
this.aFloatingPane.set('content', this.funcMaker); |
| 81 |
this.aFloatingPane.startup(); |
| 82 |
this.aFloatingPane.bringToTop(); |
| 83 |
}, |
| 84 |
makeGrapherWindow: function(){ |
| 85 |
|
| 86 |
|
| 87 |
var body = win.body(); |
| 88 |
|
| 89 |
var pane = domConstruct.create('div'); |
| 90 |
body.appendChild(pane); |
| 91 |
|
| 92 |
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); |
| 93 |
var that = this; |
| 94 |
|
| 95 |
var d = domConstruct.create("div"); |
| 96 |
this.grapher = new calc.Grapher({ |
| 97 |
myPane: this.aFloatingPane, |
| 98 |
drawOne: function(i){ |
| 99 |
this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value")); |
| 100 |
this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value'); |
| 101 |
if(this.array[i][this.expressionIndex].get("value")==""){ |
| 102 |
this.setStatus(i, "Error"); |
| 103 |
return; |
| 104 |
} |
| 105 |
var func; |
| 106 |
var yEquals = (this.array[i][this.functionMode]=="y="); |
| 107 |
if(this.array[i][this.expressionIndex].get("value")!=this.array[i][this.evaluatedExpression]){ |
| 108 |
var args = 'x'; |
| 109 |
if(!yEquals){ |
| 110 |
args = 'y'; |
| 111 |
} |
| 112 |
func = that.executor.Function('', args, "return "+this.array[i][this.expressionIndex].get('value')); |
| 113 |
this.array[i][this.evaluatedExpression] = this.array[i][this.expressionIndex].value; |
| 114 |
this.array[i][this.functionRef] = func; |
| 115 |
} |
| 116 |
else{ |
| 117 |
func = this.array[i][this.functionRef]; |
| 118 |
} |
| 119 |
var pickedColor = this.array[i][this.colorIndex].get("value"); |
| 120 |
if(!pickedColor){ |
| 121 |
pickedColor = 'black'; |
| 122 |
} |
| 123 |
calc.draw(this.array[i][this.chartIndex], func, {graphNumber:this.array[i][this.funcNumberIndex], fOfX:yEquals, color:{stroke:{color:pickedColor}}}); |
| 124 |
this.setStatus(i, "Drawn"); |
| 125 |
}, |
| 126 |
onDraw:function(){ |
| 127 |
for(var i = 0; i < this.rowCount; i++){ |
| 128 |
if((!this.dirty && this.array[i][this.checkboxIndex].get("checked")) || (this.dirty && this.array[i][this.statusIndex].innerHTML=="Drawn")){ |
| 129 |
this.drawOne(i); |
| 130 |
}else{ |
| 131 |
this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value")); |
| 132 |
this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value'); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
var bufferY = domGeometry.position(this.outerDiv).y-domGeometry.position(this.myPane.domNode).y; |
| 137 |
bufferY*=2; |
| 138 |
bufferY=Math.abs(bufferY); |
| 139 |
var height = "" + Math.max(parseInt(this.graphHeight.get('value'))+50, this.outerDiv.scrollHeight+bufferY); |
| 140 |
var width = "" + (parseInt(this.graphWidth.get('value')) + this.outerDiv.scrollWidth); |
| 141 |
this.myPane.resize({w:width, h:height}); |
| 142 |
} |
| 143 |
}, d); |
| 144 |
this.aFloatingPane.set('content', this.grapher); |
| 145 |
this.aFloatingPane.startup(); |
| 146 |
this.aFloatingPane.bringToTop(); |
| 147 |
} |
| 148 |
}); |
| 149 |
}); |