]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Linear scale is reversible 1215/head
authorEvert Timberg <evert.timberg@gmail.com>
Mon, 15 Jun 2015 21:31:29 +0000 (17:31 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Mon, 15 Jun 2015 21:31:29 +0000 (17:31 -0400)
src/scales/scale.linear.js

index 60caae477347ac46e4d47d389a27814162cfe419..a122886065e15907942cc3403220fc0fd3972861 100644 (file)
@@ -22,6 +22,7 @@
                },
 
                // scale numbers
+               reverse: false,
                beginAtZero: false,
                override: null,
 
                        // 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
                        // 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;