Permalink
Browse files

Refactor sampleFunction

  • Loading branch information...
1 parent f629e11 commit 3cfaca7c05d424ac4e7615ea738be52b302ac877 @leto committed Dec 23, 2008
Showing with 15 additions and 14 deletions.
  1. +14 −1 js/hypatia.js
  2. +1 −13 tmpl/index.tmpl
View
@@ -5,4 +5,17 @@
debug( 'ERROR: errorThrown=' + errorThrown );
}
this; // the options for this ajax request
- }
+ };
+
+ function sampleFunction(x1,x2,points,func,legend_label) {
+ debug('sampling data for ' + x1 + ' to ' + x2 );
+ var d = [];
+ var step = (x2 - x1)/points;
+ for (var i = x1; i < x2; i += step ) {
+ d.push([i, func( i )]);
+ }
+
+ return [
+ { label: legend_label , data: d }
+ ];
+ };
View
@@ -92,18 +92,6 @@ $( function() {
return false;
});
// setup plot
- function sampleFunction(x1,x2,func) {
- debug('sampling data for ' + x1 + ' to ' + x2 );
- var d = [];
- var step = (x2 - x1)/300;
- for (var i = x1; i < x2; i += step ) {
- d.push([i, func( i )]);
- }
-
- return [
- { label: "sin(x^2)", data: d }
- ];
- }
var options = {
crosshair: { mode: "xy", color: "#ff0000" },
@@ -116,7 +104,7 @@ $( function() {
grid: { hoverable: true, clickable: true , color: "#999"}
};
- var startData = sampleFunction( -2*Math.PI , 2*Math.PI, function (x) { return Math.sin(x*x) } );
+ var startData = sampleFunction( -2*Math.PI , 2*Math.PI, 300, function (x) { return Math.sin(x*x) }, 'sin(x^2)' );
debug( 'got startdata' );
var plot = $.plot($("#plot1"), startData, options);

0 comments on commit 3cfaca7

Please sign in to comment.