Commit 6e99181b authored by olau@iola.dk's avatar olau@iola.dk

Simplify transformation helper function slightly and fix issue 263

that prevented inverse transforms from working correctly.


git-svn-id: https://flot.googlecode.com/svn/trunk@303 1e0a6537-2640-0410-bfb7-f154510ff394
parent 47821c71
...@@ -136,6 +136,8 @@ Bug fixes: ...@@ -136,6 +136,8 @@ Bug fixes:
- Fix bug with backwards compatibility for shadowSize = 0 (report and - Fix bug with backwards compatibility for shadowSize = 0 (report and
suggested fix by aspinak). suggested fix by aspinak).
- Adapt examples to skip loading excanvas (fix by Ryley Breiddal). - Adapt examples to skip loading excanvas (fix by Ryley Breiddal).
- Fix bug that prevent a simple f(x) = -x transform from working
correctly (fix by Mike, issue 263).
Flot 0.6 Flot 0.6
......
...@@ -771,36 +771,28 @@ ...@@ -771,36 +771,28 @@
var s, m, t = axis.options.transform || identity, var s, m, t = axis.options.transform || identity,
it = axis.options.inverseTransform; it = axis.options.inverseTransform;
// precompute how much the axis is scaling a point
// in canvas space
if (axis.direction == "x") { if (axis.direction == "x") {
// precompute how much the axis is scaling a point s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min));
// in canvas space m = Math.min(t(axis.max), t(axis.min));
s = axis.scale = plotWidth / (t(axis.max) - t(axis.min));
m = t(axis.min);
// data point to canvas coordinate
if (t == identity) // slight optimization
axis.p2c = function (p) { return (p - m) * s; };
else
axis.p2c = function (p) { return (t(p) - m) * s; };
// canvas coordinate to data point
if (!it)
axis.c2p = function (c) { return m + c / s; };
else
axis.c2p = function (c) { return it(m + c / s); };
} }
else { else {
s = axis.scale = plotHeight / (t(axis.max) - t(axis.min)); s = axis.scale = plotHeight / Math.abs(t(axis.max) - t(axis.min));
m = t(axis.max); s = -s;
m = Math.max(t(axis.max), t(axis.min));
if (t == identity)
axis.p2c = function (p) { return (m - p) * s; };
else
axis.p2c = function (p) { return (m - t(p)) * s; };
if (!it)
axis.c2p = function (c) { return m - c / s; };
else
axis.c2p = function (c) { return it(m - c / s); };
} }
// data point to canvas coordinate
if (t == identity) // slight optimization
axis.p2c = function (p) { return (p - m) * s; };
else
axis.p2c = function (p) { return (t(p) - m) * s; };
// canvas coordinate to data point
if (!it)
axis.c2p = function (c) { return m + c / s; };
else
axis.c2p = function (c) { return it(m + c / s); };
} }
function measureTickLabels(axis) { function measureTickLabels(axis) {
......
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