Skip to content

Commit

Permalink
Fixes #11184. Initial commit of dojox/calc project contributed by jas…
Browse files Browse the repository at this point in the history
…on_hays22 (CLA on file) through GSoC.

git-svn-id: http://svn.dojotoolkit.org/src/dojox/trunk@22729 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
Douglas Hays committed Aug 16, 2010
1 parent a99536e commit 02fbfeb
Show file tree
Hide file tree
Showing 18 changed files with 3,186 additions and 0 deletions.
143 changes: 143 additions & 0 deletions calc/FuncGen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
dojo.provide("dojox.calc.FuncGen");
dojo.experimental("dojox.calc.FuncGen");

dojo.require("dijit._Templated");
dojo.require("dojox.math._base");
dojo.require("dijit.dijit");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.SimpleTextarea");
dojo.require("dijit.form.Button");
dojo.require("dojo.data.ItemFileWriteStore");


dojo.declare(
"dojox.calc.FuncGen",
[dijit._Widget, dijit._Templated],
{
// summary:
// The dialog layout for making functions
//
templateString: dojo.cache("dojox.calc", "templates/FuncGen.html"),

widgetsInTemplate:true,

onSelect: function(){
// summary
// if they select something in the name combobox, then change the body and arguments to correspond to the function they selected
this.reset();
},
onClear: function(){
// summary
// the clear button in the template calls this
// clear the name, arguments, and body if the user says yes
var answer = confirm("Do you want to clear the name, argument, and body text?");
if(answer){
this.clear();
}
},
saveFunction: function(name, args, body){
// override me
},
onSaved: function(){
// this on save needs to be overriden if you want Executor parsing support
console.log("Save was pressed");
},
clear: function(){
// summary
// clear the name, arguments, and body
this.textarea.set("value", "");
this.args.set("value", "");
this.combo.set("value", "");
},
reset: function(){
// summary
// set the arguments and body to match a function selected if it exists in the function list
if(this.combo.get("value") in this.functions){
this.textarea.set("value", this.functions[this.combo.get("value")].body);
this.args.set("value", this.functions[this.combo.get("value")].args);
}
},
onReset: function(){
// summary
// (Reset button on click event) reset the arguments and body to their previously saved state if the user says yes
console.log("Reset was pressed");
if(this.combo.get("value") in this.functions){
var answer = confirm("Do you want to reset this function?");
if(answer){
this.reset();
this.status.set("value", "The function has been reset to its last save point.");
}
}
},
deleteThing: function(item){
// summary
// delete an item in the writestore
if (this.writeStore.isItem(item)){
// delete it
console.log("Found item "+item);
this.writeStore.deleteItem(item);
this.writeStore.save();
}else{
console.log("Unable to locate the item");
}
},
deleteFunction: function(name){
// override me
},
onDelete: function(){
// summary
// (Delete button on click event) delete a function if the user clicks yes

//console.log("Delete was pressed");

var name;
if((name = this.combo.get("value")) in this.functions){
var answer = confirm("Do you want to delete this function?");
if(answer){
var item = this.combo.item;

//this.writeStore.fetchItemByIdentity({identity:name, onItem: this.deleteThing, onError:null});

this.writeStore.deleteItem(item);
this.writeStore.save();

this.deleteFunction(name);
delete this.functions[name];
this.clear();
}
}else{
this.status.set("value", "Function cannot be deleted, it isn't saved.");
}
},
readyStatus: function(){
// summary
// set the status in the template to ready
this.status.set("value", "Ready");
},
writeStore:null, //the user can save functions to the writestore
readStore:null, // users cannot edit the read store contents, but they can use them
functions:null, // use the names to get to the function

/*postCreate: function(){
this.functions = []; // use the names to get to the function
this.writeStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'name', items:[]}});
this.combo.set("store", this.writeStore);
},*/

startup: function(){
// summary
// make sure the parent has a close button if it needs to be able to close
// link the write store too
this.combo.set("store", this.writeStore);

this.inherited(arguments);// this is super class startup
// close is only valid if the parent is a widget with a close function
var parent = dijit.getEnclosingWidget(this.domNode.parentNode);
if(parent && typeof parent.close == "function"){
this.closeButton.set("onClick", dojo.hitch(parent, 'close'));
}else{
dojo.style(this.closeButton.domNode, "display", "none"); // hide the button
}
}
});
143 changes: 143 additions & 0 deletions calc/GraphPro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
dojo.provide("dojox.calc.GraphPro");
dojo.experimental("dojox.calc.GraphPro");

dojo.require("dojox.calc.Standard");
dojo.require("dijit.dijit");
dojo.require("dijit.form.ComboBox");
dojo.require("dijit.form.Select");
dojo.require("dijit.form.CheckBox");
dojo.require("dijit.ColorPalette");
dojo.require("dojox.charting.Chart2D");
dojo.require("dojox.calc.Grapher");
dojo.require("dojox.layout.FloatingPane");
dojo.require("dojox.charting.themes.Tufte");
dojo.require("dojo.colors");

dojo.declare(
"dojox.calc.GraphPro",
dojox.calc.Standard,
{
// summary:
// The dialog widget for a graphing, scientific calculator
//
templateString: dojo.cache("dojox.calc", "templates/GraphPro.html"),

grapher:null,
funcMaker:null,
aFloatingPane: null,

executorLoaded: function(){
// summary
// when executor loads check to see if the writestore is there
this.inherited(arguments);
dojo.addOnLoad(dojo.hitch(this, function(){
if(this.writeStore == null && "functionMakerButton" in this){
dojo.style(this.functionMakerButton.domNode, { visibility: "hidden" });
}
}));
},
makeFunctionWindow: function(){
// summary
// use this function to create a function window (with the button on the layout)
var body = dojo.body();

var pane = dojo.create('div');
body.appendChild(pane);

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);
var that = this;
var d = dojo.create("div");
this.funcMaker = new dojox.calc.FuncGen({
writeStore:that.writeStore,
readStore:that.readStore,
functions:that.functions,
deleteFunction: that.executor.deleteFunction,
onSaved:function(){
var name,
body;
if((name = this.combo.get("value")) == ""){
this.status.set("value", "The function needs a name");
}else if ((body = this.textarea.get("value")) == ""){
// i don't think users need empty functions for math
this.status.set("value", "The function needs a body");
}else{
var args = this.args.get("value");
if(!(name in this.functions)){
this.combo.item = this.writeStore.newItem({name: name, args: args, body: body});
this.writeStore.save();
}
this.saveFunction(name, args, body);
this.status.set("value", "Function "+name+" was saved");
}
},
saveFunction: dojo.hitch(that, that.saveFunction)
}, d);
this.aFloatingPane.set('content', this.funcMaker);
this.aFloatingPane.startup();
this.aFloatingPane.bringToTop();
},
makeGrapherWindow: function(){
// summary
// use this to make a Grapher window appear with a button
var body = dojo.body();

var pane = dojo.create('div');
body.appendChild(pane);

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);
var that = this;

var d = dojo.create("div");
this.grapher = new dojox.calc.Grapher({
myPane: this.aFloatingPane,
drawOne: function(i){
this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));
this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');
if(this.array[i][this.expressionIndex].get("value")==""){
this.setStatus(i, "Error");
return;
}
var func;
var yEquals = (this.array[i][this.functionMode]=="y=");
if(this.array[i][this.expressionIndex].get("value")!=this.array[i][this.evaluatedExpression]){
var args = 'x';
if(!yEquals){
args = 'y';
}
func = that.executor.Function('', args, "return "+this.array[i][this.expressionIndex].get('value'));
this.array[i][this.evaluatedExpression] = this.array[i][this.expressionIndex].value;
this.array[i][this.functionRef] = func;
}
else{
func = this.array[i][this.functionRef];
}
var pickedColor = this.array[i][this.colorIndex].get("value");
if(!pickedColor){
pickedColor = 'black';
}
dojox.calc.Grapher.draw(this.array[i][this.chartIndex], func, {graphNumber:this.array[i][this.funcNumberIndex], fOfX:yEquals, color:{stroke:{color:pickedColor}}});
this.setStatus(i, "Drawn");
},
onDraw:function(){
for(var i = 0; i < this.rowCount; i++){
if((!this.dirty && this.array[i][this.checkboxIndex].get("checked")) || (this.dirty && this.array[i][this.statusIndex].innerHTML=="Drawn")){
this.drawOne(i);
}else{
this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));
this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');
}
}

var bufferY = dojo.position(this.outerDiv).y-dojo.position(this.myPane.domNode).y;
bufferY*=2;
bufferY=Math.abs(bufferY);
var height = "" + Math.max(parseInt(this.graphHeight.get('value'))+50, this.outerDiv.scrollHeight+bufferY);
var width = "" + (parseInt(this.graphWidth.get('value')) + this.outerDiv.scrollWidth);
this.myPane.resize({w:width, h:height});
}
}, d);
this.aFloatingPane.set('content', this.grapher);
this.aFloatingPane.startup();
this.aFloatingPane.bringToTop();
}
});
Loading

0 comments on commit 02fbfeb

Please sign in to comment.