]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Better conversion to ticks to make it easier to use callbacks 2144/head
authoretimberg <evert.timberg@gmail.com>
Wed, 16 Mar 2016 23:39:09 +0000 (19:39 -0400)
committeretimberg <evert.timberg@gmail.com>
Wed, 16 Mar 2016 23:39:09 +0000 (19:39 -0400)
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
test/scale.linear.tests.js

index 338fc3d35cdd404e05bf5c1ffd6f3f39de73c58b..9c6f1aeba97cd873efa2343171e4f08855a1a0b0 100644 (file)
@@ -221,13 +221,16 @@ module.exports = function(Chart) {
                                this.start = this.min;
                                this.end = this.max;
                        }
-
-                       this.ticksAsNumbers = this.ticks.slice(); // do after we potentially reverse the ticks
-                       this.zeroLineIndex = this.ticks.indexOf(0);
                },
                getLabelForIndex: function(index, datasetIndex) {
                        return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
                },
+               convertTicksToLabels: function() {
+                       this.ticksAsNumbers = this.ticks.slice();
+                       this.zeroLineIndex = this.ticks.indexOf(0);
+
+                       Chart.Scale.prototype.convertTicksToLabels.call(this);
+               },
                // Utils
                getPixelForValue: function(value, index, datasetIndex, includeOffset) {
                        // This must be called after fit has been run so that
index 8f138193b863f4a3c6c6f4d29f3026bce92077c2..070a08d61ff0fd94836e39a98608632c1ef5db28 100644 (file)
@@ -103,7 +103,7 @@ module.exports = function(Chart) {
                buildTicks: function() {
                        // Reset the ticks array. Later on, we will draw a grid line at these positions
                        // The array simply contains the numerical value of the spots where ticks will be
-                       this.tickValues = [];
+                       this.ticks = [];
 
                        // Figure out what the max number of ticks we can support it is based on the size of
                        // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
@@ -113,7 +113,7 @@ module.exports = function(Chart) {
                        var tickVal = this.options.ticks.min !== undefined ? this.options.ticks.min : Math.pow(10, Math.floor(helpers.log10(this.min)));
 
                        while (tickVal < this.max) {
-                               this.tickValues.push(tickVal);
+                               this.ticks.push(tickVal);
 
                                var exp = Math.floor(helpers.log10(tickVal));
                                var significand = Math.floor(tickVal / Math.pow(10, exp)) + 1;
@@ -127,20 +127,20 @@ module.exports = function(Chart) {
                        }
 
                        var lastTick = this.options.ticks.max !== undefined ? this.options.ticks.max : tickVal;
-                       this.tickValues.push(lastTick);
+                       this.ticks.push(lastTick);
 
                        if (this.options.position === "left" || this.options.position === "right") {
                                // We are in a vertical orientation. The top value is the highest. So reverse the array
-                               this.tickValues.reverse();
+                               this.ticks.reverse();
                        }
 
                        // At this point, we need to update our max and min given the tick values since we have expanded the
                        // range of the scale
-                       this.max = helpers.max(this.tickValues);
-                       this.min = helpers.min(this.tickValues);
+                       this.max = helpers.max(this.ticks);
+                       this.min = helpers.min(this.ticks);
 
                        if (this.options.ticks.reverse) {
-                               this.tickValues.reverse();
+                               this.ticks.reverse();
 
                                this.start = this.max;
                                this.end = this.min;
@@ -148,8 +148,11 @@ module.exports = function(Chart) {
                                this.start = this.min;
                                this.end = this.max;
                        }
+               },
+               convertTicksToLabels: function() {
+                       this.tickValues = this.ticks.slice();
 
-                       this.ticks = this.tickValues.slice();
+                       Chart.Scale.prototype.convertTicksToLabels.call(this);
                },
                // Get the correct tooltip label
                getLabelForIndex: function(index, datasetIndex) {
index be6c803d231bd726d0cfec58a0b3c11fd9a7724d..85d076bf68e7d8127a361cfd0eed3aa0cdbec267 100644 (file)
@@ -650,7 +650,6 @@ describe('Linear Scale', function() {
 
                // Reverse mode makes this count up
                expect(scale.ticks).toEqual([0, 10, 20, 30, 40, 50, 60, 70, 80]);
-               expect(scale.ticksAsNumbers).toEqual([0, 10, 20, 30, 40, 50, 60, 70, 80]);
                expect(scale.start).toBe(80);
                expect(scale.end).toBe(0);
        });