g.raphael icon indicating copy to clipboard operation
g.raphael copied to clipboard

Logarithmic scale for linechart

Open baryluk opened this issue 14 years ago • 3 comments

This library is really nice, i found it very usefull. Thanks.

I would like to have support for logarihmic scales in linechart.

I'm currnlty just calculating logarithms for x and/or x by hand outside of the raphael, but then labels under x and y axis are wrong.

I would like to have something like:

r.g.linechart(
  30, 15, 760, 320,
  x, [y1, y2, y3], {
    nostroke: false, axis: "0 1 1 1", width: 2,
    logscale_x: 4, logscale_y: 10,
});

Which will use Math.log(x[i])/Math.log(4.0) for each x point before ploting, and Math.log(y[ii][i])/Math.log(10) for y values. (1.0/Math.log(4.0) should be computed before any loop as it is constant. Also transformation should be performed only once and remembered, becuase datapoints are used in multiple places).

This needs some adjustments in the find of range of points in g.line.js, and of course when plotting.

I doesn't care that stright line, after logarithmic transformation is usually not a stright line. We are actually interested in points, and line should still be line as it only is for connecting visual point, not data points actually (and any way all other software does so).

I doesn't care about handling of negative values (they will produce NaN from log), anyone should before hand know what he/she sends to the raphael.

This should be few minutes of coding probably, but unfortunetly, i have no idea how to add this feature nicely and still make axis behave correctly.

Axis drawing and mouse over handlers will need slight adjustments.

Thanks.

baryluk avatar May 04 '10 18:05 baryluk

I have preliminary patch, but it will need review and probably small fix for axis. It doesn't break existing usage.

baryluk avatar May 04 '10 19:05 baryluk

for the time being you can replace the labels on the chart outside of g.raphael

glebm avatar May 06 '10 00:05 glebm

I need this too please

benzmuircroft avatar Aug 31 '14 17:08 benzmuircroft