From 6e99181b330d62a964b382ec33659a47ea88aaf4 Mon Sep 17 00:00:00 2001 From: "olau@iola.dk" Date: Fri, 11 Mar 2011 21:14:58 +0000 Subject: [PATCH] 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 --- NEWS.txt | 2 ++ jquery.flot.js | 44 ++++++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 76e46d1..beedf00 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -136,6 +136,8 @@ Bug fixes: - Fix bug with backwards compatibility for shadowSize = 0 (report and suggested fix by aspinak). - 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 diff --git a/jquery.flot.js b/jquery.flot.js index 51a4509..3e4e84f 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -771,36 +771,28 @@ var s, m, t = axis.options.transform || identity, it = axis.options.inverseTransform; + // precompute how much the axis is scaling a point + // in canvas space if (axis.direction == "x") { - // precompute how much the axis is scaling a point - // in canvas space - 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); }; + s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min)); + m = Math.min(t(axis.max), t(axis.min)); } else { - s = axis.scale = plotHeight / (t(axis.max) - t(axis.min)); - m = t(axis.max); - - 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); }; + s = axis.scale = plotHeight / Math.abs(t(axis.max) - t(axis.min)); + s = -s; + m = Math.max(t(axis.max), 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); }; } function measureTickLabels(axis) {