Commit 1ffb0911 by Valera Rozuvan Committed by Alexander Kryklia

GST work in progress.

parent 3eb3d7db
...@@ -22,6 +22,10 @@ define('Graph', ['logme'], function (logme) { ...@@ -22,6 +22,10 @@ define('Graph', ['logme'], function (logme) {
plotDiv.width(300); plotDiv.width(300);
} }
// Sometimes, when height is not explicitly set via CSS (or by some
// other means), it is 0 pixels by default. When Flot will try to plot
// a graph in this DIV with 0 height, then it will raise an error. To
// prevent this, we will set it to be equal to the width.
if (plotDiv.height() === 0) { if (plotDiv.height() === 0) {
plotDiv.height(plotDiv.width()); plotDiv.height(plotDiv.width());
} }
...@@ -84,7 +88,7 @@ define('Graph', ['logme'], function (logme) { ...@@ -84,7 +88,7 @@ define('Graph', ['logme'], function (logme) {
return; return;
function processTicks(ticksStr, ticksObj, unitsType) { function processTicks(ticksStr, ticksObj, unitsType) {
var ticksBlobs, tempFloat; var ticksBlobs, tempFloat, tempTicks, c1, c2;
// The 'ticks' setting is a string containing 3 floating-point // The 'ticks' setting is a string containing 3 floating-point
// numbers. // numbers.
...@@ -137,13 +141,83 @@ define('Graph', ['logme'], function (logme) { ...@@ -137,13 +141,83 @@ define('Graph', ['logme'], function (logme) {
// units: change last tick to units // units: change last tick to units
if (typeof config.plot[unitsType] === 'string') { if (typeof config.plot[unitsType] === 'string') {
var ticks = _.map(_.range(ticksObj.min, tempTicks = [];
ticksObj.max + ticksObj.tickSize, ticksObj.tickSize),
function(x){ return [x, for (c1 = ticksObj.min; c1 <= ticksObj.max; c1 += ticksObj.tickSize) {
x > ticksObj.max - ticksObj.tickSize ? config.plot[unitsType] : x]; c2 = roundToPrec(c1, ticksObj.tickSize);
}); tempTicks.push([c2, c2]);
}
tempTicks.pop();
tempTicks.push([
roundToPrec(ticksObj.max, ticksObj.tickSize),
config.plot[unitsType]
]);
ticksObj.tickSize = null; ticksObj.tickSize = null;
ticksObj.ticks = ticks; ticksObj.ticks = tempTicks;
}
return;
function roundToPrec(num, prec) {
var c1, tn1, tn2, digitsBefore, digitsAfter;
tn1 = Math.abs(num);
tn2 = Math.abs(prec);
// Find out number of digits BEFORE the decimal point.
c1 = 0;
tn1 = Math.abs(num);
while (tn1 >= 1) {
c1 += 1;
tn1 /= 10;
}
digitsBefore = c1;
// Find out number of digits AFTER the decimal point.
c1 = 0;
tn1 = Math.abs(num);
while (Math.round(tn1) !== tn1) {
c1 += 1;
tn1 *= 10;
}
digitsAfter = c1;
// For precision, find out number of digits AFTER the
// decimal point.
c1 = 0;
while (Math.round(tn2) !== tn2) {
c1 += 1;
tn2 *= 10;
}
// If precision is more than 1 (no digits after decimal
// points).
if (c1 === 0) {
return num;
}
// If the precision contains digits after the decimal
// point, we apply special rules.
else {
tn1 = Math.abs(num);
if (digitsAfter > c1) {
tn1 = tn1.toPrecision(digitsBefore + c1);
} else {
tn1 = tn1.toPrecision(digitsBefore + digitsAfter);
}
}
if (num < 0) {
return -tn1;
}
return tn1;
} }
} }
} }
...@@ -190,21 +264,22 @@ define('Graph', ['logme'], function (logme) { ...@@ -190,21 +264,22 @@ define('Graph', ['logme'], function (logme) {
try { try {
xrange.max = Function.apply(null, allParamNames); xrange.max = Function.apply(null, allParamNames);
} catch (err) { } catch (err) {
logme('ERROR: could not create a function from the string "' + config.plot.xrange.min + '" for xrange.min.'); logme('ERROR: could not create a function from the string "' + config.plot.xrange.max + '" for xrange.max.');
return false; return false;
} }
allParamNames.pop(); allParamNames.pop();
logme('xrange = ', xrange); if (typeof config.plot.num_points !== 'string') {
logme('ERROR: config.plot.num_points is not a string.');
logme('config.plot.num_points = ', config.plot.num_points);
return false;
}
// The user can specify the number of points. However, internally
// we will use it to generate a 'step' - i.e. the distance (on
// x-axis) between two adjacent points.
if (typeof config.plot.num_points === 'string') {
tempNum = parseInt(config.plot.num_points, 10); tempNum = parseInt(config.plot.num_points, 10);
if (isNaN(tempNum) === true) { if (isFinite(tempNum) === false) {
logme('ERROR: Could not parse the number of points.'); logme('ERROR: Expected config.plot.num_points to be a a valid integer. It is not.');
logme('config.plot.num_points = ', config.plot.num_points); logme('config.plot.num_points = ', config.plot.num_points);
return false; return false;
...@@ -221,14 +296,6 @@ define('Graph', ['logme'], function (logme) { ...@@ -221,14 +296,6 @@ define('Graph', ['logme'], function (logme) {
} }
numPoints = tempNum; numPoints = tempNum;
} else {
logme('MESSAGE: config.plot.num_points is not a string.');
logme('Will set number of points to {width of graph} / 10.');
numPoints = plotDiv.width() / 10.0;
logme('numPoints = ' + numPoints);
}
return true; return true;
} }
...@@ -311,8 +378,6 @@ define('Graph', ['logme'], function (logme) { ...@@ -311,8 +378,6 @@ define('Graph', ['logme'], function (logme) {
// will break. // will break.
funcString = $('<div>').html(funcString).text(); funcString = $('<div>').html(funcString).text();
logme('funcString = ' + funcString);
// Some defaults. If no options are set for the graph, we will // Some defaults. If no options are set for the graph, we will
// make sure that at least a line is drawn for a function. // make sure that at least a line is drawn for a function.
newFunctionObject = { newFunctionObject = {
...@@ -324,8 +389,6 @@ define('Graph', ['logme'], function (logme) { ...@@ -324,8 +389,6 @@ define('Graph', ['logme'], function (logme) {
// XML. // XML.
paramNames = state.getAllParameterNames(); paramNames = state.getAllParameterNames();
logme('allParamNames = ', paramNames);
// The 'x' is always one of the function parameters. // The 'x' is always one of the function parameters.
paramNames.push('x'); paramNames.push('x');
...@@ -333,8 +396,6 @@ define('Graph', ['logme'], function (logme) { ...@@ -333,8 +396,6 @@ define('Graph', ['logme'], function (logme) {
// the Function constructor. // the Function constructor.
paramNames.push(funcString); paramNames.push(funcString);
console.log('paramNames = ', paramNames);
// Create the function from the function string, and all of the // Create the function from the function string, and all of the
// available parameters AND the 'x' variable as it's parameters. // available parameters AND the 'x' variable as it's parameters.
// For this we will use the built-in Function object // For this we will use the built-in Function object
...@@ -431,8 +492,6 @@ define('Graph', ['logme'], function (logme) { ...@@ -431,8 +492,6 @@ define('Graph', ['logme'], function (logme) {
end = xrange.max.apply(window, paramValues); end = xrange.max.apply(window, paramValues);
step = (end - start) / (numPoints - 1); step = (end - start) / (numPoints - 1);
logme('start = ' + start + ', end = ' + end + ', step = ' + step);
// Generate the data points. // Generate the data points.
for (x = start; x <= end; x += step) { for (x = start; x <= end; x += step) {
......
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