You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.1 KiB
59 lines
2.1 KiB
2 years ago
|
function Graph(fullDescription) {
|
||
|
var d = fullDescription;
|
||
|
|
||
|
this.name = d.substring(0, d.indexOf("("));
|
||
|
|
||
|
this.reference = d.charAt(d.indexOf("(") + 1);
|
||
|
|
||
|
this.displayFunction = d.substring(d.indexOf("=") + 1, d.length);
|
||
|
|
||
|
|
||
|
this.color = "#000000";
|
||
|
this.thickness = 2;
|
||
|
this.points = [];
|
||
|
this.visible = true;
|
||
|
|
||
|
this.getFullDescription = function(){
|
||
|
return (this.name + "(" + this.reference + ") = " + this.displayFunction).replace(/\s+/g, " ");
|
||
|
}
|
||
|
|
||
|
this.getDisplayFunction = function(){return this.displayFunction;}
|
||
|
this.setDisplayFunction = function(displayFunction){
|
||
|
this.displayFunction = displayFunction.replace(/\s+/g, " ");
|
||
|
this.convertToExecuteableFunction();
|
||
|
}
|
||
|
|
||
|
this.getExecuteFunction = function(){return this.executeFunction;}
|
||
|
|
||
|
this.getReference = function(){return this.reference;}
|
||
|
|
||
|
this.getName = function(){return this.name;}
|
||
|
|
||
|
this.getColor = function(){return this.color;}
|
||
|
this.setColor = function(color){this.color = color;}
|
||
|
|
||
|
this.getThickness = function(){return this.thickness;}
|
||
|
this.setThickness = function(thickness){this.thickness = thickness;}
|
||
|
|
||
|
this.getPoints = function(){return this.points;}
|
||
|
this.setPoints = function(points){this.points = points;}
|
||
|
|
||
|
this.convertToExecuteableFunction = function(){
|
||
|
var f = this.displayFunction;
|
||
|
f = f.substr(0, f.length);
|
||
|
f = f.replace(/,/g, ".");
|
||
|
f = f.replace(/(\d+\.?\d*)\s*([a-z])/g, "$1*$2");
|
||
|
f = f.replace(/([a-z])\s*(\d+\.?\d*)/g, "$2*$1");
|
||
|
f = f.replace(/\-([a-z])/g, "-1*$1");
|
||
|
f = f.replace(new RegExp("([a-z])" + this.reference, "g"), "$1*" + this.reference);
|
||
|
f = f.replace(new RegExp(this.reference + "([a-z])", "g"), "$1*" + this.reference);
|
||
|
variables.forEach(function(v){f = f.replace(new RegExp(v.getName(), "g"), v.getValue());});
|
||
|
var powCount = f.split("^").length - 1;
|
||
|
for (var i = 0; i < powCount; i++){f = f.replace(/(\(.*(\(.*\))*.*\)|[a-z]?(\d+\.?\d*)?)\^(\(.*(\(.*\))*.*\)|[a-z]?(\d+\.?\d*)?)/, "pow($1, $4)");}
|
||
|
f = f.replace(/\|(.+)\|/g, "abs($1)");
|
||
|
f = f.replace(/e/g, "Math.E");
|
||
|
//console.log(f);
|
||
|
this.executeFunction = f;
|
||
|
}
|
||
|
this.convertToExecuteableFunction();
|
||
|
}
|