Arjunsos / simile-widgets

Automatically exported from code.google.com/p/simile-widgets
0 stars 0 forks source link

TIMEPLOT: Fix for Logarithmic grid geometry when maxValue < 1 #73

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When using the Logarithmic geometry, if the max data value in the chart is
< 1 (say, a dataset that ranges from 0.00001 to 0.001), no grid labels are
drawn on the value-axis at all, leaving one to wonder how to interpret the
lines drawn. I've made a small patch to timeplot to correct this. It may
not be the optimal solution, but it's better than nothing.

In plot.js, I've changed the _logarthmicCalculateGrid function to be:

(The relevant change is the new comments/stanza sandwiched inbetween the
existing declarations of "v" and "y")

----------------------------

      Timeplot.LogarithmicValueGeometry.prototype._logarithmicCalculateGrid
= function() {
          var grid = [];

          if (!this._canvas || this._valueRange == 0) return grid;

          var v = 1;
          // if max < 1, start "v" at the power
          // of 10 just below the max, so that
          // we don't get a blank vertical grid
          if(this._maxValue < 1) {
v = Math.pow(10,Math.floor(Math.log(this._maxValue)/Math.LN10));
}
          var y = this.toScreen(v);
          while (y < this._canvas.height || isNaN(y)) {
              if (y > 0) {
                  grid.push({ y: y, label: v });
              }
              v *= 10;
              y = this.toScreen(v);
          }

          return grid;
      };

Actually, it's an improvement to instead do the v = function as:

v = Math.pow(10,Math.floor(Math.log(this._maxValue)/Math.LN10)-1);

Which gives two grid values below the max data value for reference, instead
of just a single grid value. 

Original issue reported on code.google.com by stefano.mazzocchi@gmail.com on 25 Mar 2009 at 5:26

GoogleCodeExporter commented 9 years ago

Original comment by stefano.mazzocchi@gmail.com on 25 Mar 2009 at 6:42

GoogleCodeExporter commented 9 years ago
would you tell me how I can get Plot.js to use it as a local file ?

Original comment by ranjeet2...@gmail.com on 14 Apr 2009 at 11:57