sangltdn / flot

Automatically exported from code.google.com/p/flot
MIT License
0 stars 0 forks source link

Bug in certain types of transform + related feature suggestion #263

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Transforms designed to reverse a graph around an axis don't work -- for
example, f(x) = axis.max - x. The resulting graph is identical to what the
graph would be without the transform. 

This is probably because the computation of the scaling factor and origin
in setupGrid gets confused when axis.max < axis.min. In fact, changing the
code there to:

s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min));

and then
m = Math.min(t(axis.min),t(axis.max)); // for the x axes
and
m = Math.max(t(axis.min),t(axis.max)); // for the y axes

...should fix it.

It would also be very nice to have an option 'reverseAxis' that would
create the transformation automatically, so users wouldn't have to iterate
over their data to find the max value. This could possibly be done by
changing the code that sets up the transform in setupGrid to:

var s, m, tPrime = o.transform || identity, itPrime = o.inverseTransform;

var t = (o.reverseAxis) ? function(x) {return tPrime(axis.max - x); } : tPrime;
var it = (o.reverseAxis) ? function(x) {return itPrime(axis.max - x); } :
itPrime;

Thanks!
Mike

Original issue reported on code.google.com by van...@gmail.com on 19 Nov 2009 at 3:11

GoogleCodeExporter commented 9 years ago
Sorry for the bad response time. I've just fixed this now, worked just like you 
said. Can't believe I haven't looked at this before. Many thanks!

I understand your rationale for the reverse axis stuff, but I'm not too 
comfortable with it. I'd rather see a plugin do that kind of thing - it's not 
complicated per se, it's just a bit difficult to explain to people, and I think 
the core is currently full of too much of the difficult-to-explain stuff. I 
think it would make more sense to put an interface to the data parser if you 
are interested in working on that - actually coming to think of it, I think you 
can add a hook to solve this problem.

Original comment by olau%iol...@gtempaccount.com on 11 Mar 2011 at 9:12

GoogleCodeExporter commented 9 years ago
Excellent, thanks for the fix!

Original comment by van...@gmail.com on 11 Mar 2011 at 9:49