]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Horizontal Log Scale
authorTanner Linsley <tannerlinsley@gmail.com>
Thu, 24 Sep 2015 18:59:03 +0000 (12:59 -0600)
committerTanner Linsley <tannerlinsley@gmail.com>
Thu, 24 Sep 2015 18:59:03 +0000 (12:59 -0600)
src/scales/scale.linear.js
src/scales/scale.logarithmic.js

index 662c69e6068310baa957b4f3c028b006ca0760c1..27cdff3ddcc43e84e5dc9fb1ae4dacc7eb5cdc95 100644 (file)
                        var range = this.end - this.start;
 
                        if (this.isHorizontal()) {
+
                                var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
                                pixel = this.left + (innerWidth / range * (this.getRightValue(value) - this.start));
                                return Math.round(pixel + this.paddingLeft);
index dbe896d3cd836549e38a62f70e31eea6a7366462..3bc3d02d4776f788323cf58652fbeac0c6817b4e 100644 (file)
 
                                this.ticks.push(label); // empty string will not render so we're good
                        }, this);
-
-                       console.log(this.tickValues, this.ticks);
                },
                // Get the correct value. If the value type is object get the x or y based on whether we are horizontal or not
                getRightValue: function(rawValue) {
                        return typeof rawValue === "object" ? (this.isHorizontal() ? rawValue.x : rawValue.y) : rawValue;
                },
                getPixelForTick: function(index, includeOffset) {
-                       return this.getPixelForValue(this.tickValues[index], includeOffset);
+                       return this.getPixelForValue(this.tickValues[index], null, null, includeOffset);
                },
-               getPixelForValue: function(value) {
-                       // This must be called after fit has been run so that 
-                       //      this.left, this.top, this.right, and this.bottom have been defined
+               getPixelForValue: function(value, index, datasetIndex, includeOffset) {
                        var pixel;
+
+                       var newVal = this.getRightValue(value);
                        var range = helpers.log10(this.end) - helpers.log10(this.start);
 
                        if (this.isHorizontal()) {
-                               if (value === 0) {
+
+                               if (newVal === 0) {
                                        pixel = this.left + this.paddingLeft;
                                } else {
                                        var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
-                                       pixel = this.left + (innerWidth / range * (helpers.log10(value) - helpers.log10(this.start)));
-                                       pixel += this.paddingLeft;
+                                       pixel = this.left + (innerWidth / range * (helpers.log10(newVal) - helpers.log10(this.start)));
+                                       return pixel + this.paddingLeft;
                                }
                        } else {
                                // Bottom - top since pixels increase downard on a screen
-                               if (value === 0) {
+                               if (newVal === 0) {
                                        pixel = this.top + this.paddingTop;
                                } else {
                                        var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
-                                       pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (helpers.log10(value) - helpers.log10(this.start)));
+                                       return (this.bottom - this.paddingBottom) - (innerHeight / range * (helpers.log10(newVal) - helpers.log10(this.start)));
                                }
                        }
 
-                       return pixel;
                },
 
        });