Commit 46de7b2c by Valera Rozuvan Committed by Alexander Kryklia

Added config options for number of points and xrange - start, end, step.

parent 4265bf17
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
// define() functions from Require JS available inside the anonymous function. // define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) { (function (requirejs, require, define) {
define('Graph', ['logme'], function (logme) { define('Graph', [], function () {
return Graph; return Graph;
function Graph(gstId, config, state) { function Graph(gstId, config, state) {
var plotDiv, dataSeries, functions, xaxis, yaxis; var plotDiv, dataSeries, functions, xaxis, yaxis, xrange;
logme('config:', config);
plotDiv = $('#' + gstId + '_plot'); plotDiv = $('#' + gstId + '_plot');
...@@ -19,6 +17,7 @@ define('Graph', ['logme'], function (logme) { ...@@ -19,6 +17,7 @@ define('Graph', ['logme'], function (logme) {
setGraphDimensions(); setGraphDimensions();
setGraphAxes(); setGraphAxes();
setGraphXRange();
state.bindUpdatePlotEvent(plotDiv, onUpdatePlot); state.bindUpdatePlotEvent(plotDiv, onUpdatePlot);
...@@ -30,27 +29,25 @@ define('Graph', ['logme'], function (logme) { ...@@ -30,27 +29,25 @@ define('Graph', ['logme'], function (logme) {
return; return;
function setGraphDimensions() { function setGraphDimensions() {
var dimObj, width, height; var dimObj, width, height, tempInt;
// If no dimensions are specified by the user, the graph have // If no dimensions are specified by the user, the graph have
// predefined dimensions. // predefined dimensions.
width = 300; width = 100;
height = 300; height = 100;
// Get the user specified dimensions, if any. // Get the user specified dimensions, if any.
if ($.isPlainObject(config.plot['dimensions']) === true) { if ($.isPlainObject(config.plot['dimensions']) === true) {
dimObj = config.plot['dimensions']; dimObj = config.plot['dimensions'];
if (dimObj.hasOwnProperty('@width') === true) { tempInt = parseInt(dimObj['@width'], 10);
if (isNaN(parseInt(dimObj['@width'], 10)) === false) { if (isNaN(tempInt) === false) {
width = parseInt(dimObj['@width'], 10); width = tempInt;
}
} }
if (dimObj.hasOwnProperty('@height') === true) { tempInt = parseInt(dimObj['@height'], 10);
if (isNaN(parseInt(dimObj['@height'], 10)) === false) { if (isNaN(tempInt) === false) {
height = parseInt(dimObj['@height'], 10); height = tempInt;
}
} }
} }
...@@ -84,9 +81,6 @@ define('Graph', ['logme'], function (logme) { ...@@ -84,9 +81,6 @@ define('Graph', ['logme'], function (logme) {
function processTicks(ticksStr, ticksObj) { function processTicks(ticksStr, ticksObj) {
var ticksBlobs, min, tickSize, max; var ticksBlobs, min, tickSize, max;
logme('Processing ticks. Ticks string is: [' + ticksStr + ']');
logme('Original ticks object:', ticksObj);
ticksBlobs = ticksStr.split(','); ticksBlobs = ticksStr.split(',');
if (ticksBlobs.length !== 3) { if (ticksBlobs.length !== 3) {
...@@ -116,8 +110,42 @@ define('Graph', ['logme'], function (logme) { ...@@ -116,8 +110,42 @@ define('Graph', ['logme'], function (logme) {
if (ticksObj.tickSize * 2 >= ticksObj.max - ticksObj.min) { if (ticksObj.tickSize * 2 >= ticksObj.max - ticksObj.min) {
ticksObj.tickSize = (ticksObj.max - ticksObj.min) / 10.0; ticksObj.tickSize = (ticksObj.max - ticksObj.min) / 10.0;
} }
}
}
function setGraphXRange() {
var xRangeStr, xRangeBlobs, tempNum;
xrange = {
'start': 0,
'end': 30,
'step': 0.1
};
if (typeof config.plot['xrange'] === 'string') {
xRangeStr = config.plot['xrange'];
xRangeBlobs = xRangeStr.split(',');
logme('Modified ticks object:', ticksObj); if (xRangeBlobs.length === 2) {
tempNum = parseFloat(xRangeBlobs[0]);
if (isNaN(tempNum) === false) {
xrange.start = tempNum;
}
tempNum = parseFloat(xRangeBlobs[1]);
if (isNaN(tempNum) === false) {
xrange.end = tempNum;
}
}
}
if (typeof config.plot['num_points'] === 'string') {
tempNum = parseInt(config.plot['num_points'], 10);
if (isNaN(tempNum) === false) {
xrange.step = (xrange.end - xrange.start) / tempNum;
}
} }
} }
...@@ -242,7 +270,7 @@ define('Graph', ['logme'], function (logme) { ...@@ -242,7 +270,7 @@ define('Graph', ['logme'], function (logme) {
} }
function generateData() { function generateData() {
var c0, c1, functionObj, seriesObj, dataPoints, constValues, x, y; var c0, functionObj, seriesObj, dataPoints, constValues, x, y;
constValues = state.getAllConstantValues(); constValues = state.getAllConstantValues();
...@@ -254,8 +282,7 @@ define('Graph', ['logme'], function (logme) { ...@@ -254,8 +282,7 @@ define('Graph', ['logme'], function (logme) {
seriesObj = {}; seriesObj = {};
dataPoints = []; dataPoints = [];
for (c1 = 0; c1 < 30; c1 += 1) { for (x = xrange.start; x <= xrange.end; x += xrange.step) {
x = c1;
// Push the 'x' variable to the end of the parameter array. // Push the 'x' variable to the end of the parameter array.
constValues.push(x); constValues.push(x);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment