]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Unify cartesian scale tick order (#8062)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 16 Nov 2020 19:59:53 +0000 (21:59 +0200)
committerGitHub <noreply@github.com>
Mon, 16 Nov 2020 19:59:53 +0000 (14:59 -0500)
src/scales/scale.logarithmic.js
test/specs/core.ticks.tests.js
test/specs/scale.logarithmic.tests.js

index 849084f06a3ef2815b1b74ab06bf38fc9e99ee52..40983febde7819e68357283c834c85b0d7e56bc8 100644 (file)
@@ -123,23 +123,21 @@ export default class LogarithmicScale extends Scale {
                        max: me._userMax
                };
                const ticks = generateTicks(generationOptions, me);
-               let reverse = !me.isHorizontal();
 
                // At this point, we need to update our max and min given the tick values since we have expanded the
                // range of the scale
                _setMinAndMaxByKey(ticks, me, 'value');
 
                if (opts.reverse) {
-                       reverse = !reverse;
+                       ticks.reverse();
+
                        me.start = me.max;
                        me.end = me.min;
                } else {
                        me.start = me.min;
                        me.end = me.max;
                }
-               if (reverse) {
-                       ticks.reverse();
-               }
+
                return ticks;
        }
 
index d03f71ff5ccd80a15a38182252988669159c672f..ec080afadfd25cb2500066c2385539d768369b65 100644 (file)
@@ -94,6 +94,6 @@ describe('Test tick generators', function() {
                var yLabels = getLabels(chart.scales.y);
 
                expect(xLabels).toEqual(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
-               expect(yLabels).toEqual(['1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1']);
+               expect(yLabels).toEqual(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
        });
 });
index 905f756771dcada420abd728d24693a5aac40ce4..c6a4b960b83002f7f8b80c08e7e23b9b151c210c 100644 (file)
@@ -448,8 +448,8 @@ describe('Logarithmic Scale tests', function() {
                var tickCount = yScale.ticks.length;
                expect(yScale.min).toBe(10);
                expect(yScale.max).toBe(1010);
-               expect(yScale.ticks[0].value).toBe(1010);
-               expect(yScale.ticks[tickCount - 1].value).toBe(10);
+               expect(yScale.ticks[0].value).toBe(10);
+               expect(yScale.ticks[tickCount - 1].value).toBe(1010);
        });
 
        it('should ignore negative min and max options', function() {
@@ -535,9 +535,8 @@ describe('Logarithmic Scale tests', function() {
                        }
                });
 
-               // Counts down because the lines are drawn top to bottom
                var scale = chart.scales.y;
-               expect(getLabels(scale)).toEqual([80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
+               expect(getLabels(scale)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80]);
                expect(scale.start).toEqual(1);
                expect(scale.end).toEqual(80);
        });
@@ -567,7 +566,7 @@ describe('Logarithmic Scale tests', function() {
 
                var scale = chart.scales.y;
                // Counts down because the lines are drawn top to bottom
-               expect(getLabels(scale)).toEqual([30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1]);
+               expect(getLabels(scale)).toEqual([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30]);
                expect(scale.start).toEqual(0.1);
                expect(scale.end).toEqual(30);
        });
@@ -598,7 +597,7 @@ describe('Logarithmic Scale tests', function() {
                });
 
                var scale = chart.scales.y;
-               expect(getLabels(scale)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80]);
+               expect(getLabels(scale)).toEqual([80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
                expect(scale.start).toEqual(80);
                expect(scale.end).toEqual(1);
        });
@@ -628,7 +627,7 @@ describe('Logarithmic Scale tests', function() {
                });
 
                var scale = chart.scales.y;
-               expect(getLabels(scale)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30]);
+               expect(getLabels(scale)).toEqual([30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
                expect(scale.start).toEqual(30);
                expect(scale.end).toEqual(1);
        });
@@ -651,7 +650,7 @@ describe('Logarithmic Scale tests', function() {
                        }
                });
 
-               expect(getLabels(chart.scales.y)).toEqual(['', '', '', '50', '', '', '20', '10', '', '', '', '', '5', '', '', '2', '1']);
+               expect(getLabels(chart.scales.y)).toEqual(['1', '2', '', '', '5', '', '', '', '', '10', '20', '', '', '50', '', '', '']);
        });
 
        it('should build labels using the user supplied callback', function() {