From 76d2a782fc966a1e697e07dfa92687ef4d810ac6 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Mon, 15 Jun 2015 17:31:29 -0400 Subject: [PATCH] Linear scale is reversible --- src/scales/scale.linear.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 60caae477..a12288606 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -22,6 +22,7 @@ }, // scale numbers + reverse: false, beginAtZero: false, override: null, @@ -122,6 +123,16 @@ // range of the scale this.max = helpers.max(this.ticks); this.min = helpers.min(this.ticks); + + if (this.options.reverse) { + this.ticks.reverse(); + + this.start = this.max; + this.end = this.min; + } else { + this.start = this.min; + this.end = this.max; + } }, buildLabels: function() { // We assume that this has been run after ticks have been generated. We try to figure out @@ -152,13 +163,13 @@ // This must be called after fit has been run so that // this.left, this.top, this.right, and this.bottom have been defined var pixel; - var range = this.max - this.min; + var range = this.end - this.start; if (this.isHorizontal()) { - pixel = this.left + (this.width / range * (value - this.min)); + pixel = this.left + (this.width / range * (value - this.start)); } else { // Bottom - top since pixels increase downard on a screen - pixel = this.bottom - (this.height / range * (value - this.min)); + pixel = this.bottom - (this.height / range * (value - this.start)); } return pixel;