]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Ensure deprecated unitStepSize property of time scale is respected (#4401)
authorEvert Timberg <evert.timberg+github@gmail.com>
Sun, 25 Jun 2017 12:37:38 +0000 (08:37 -0400)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Sun, 25 Jun 2017 12:37:38 +0000 (14:37 +0200)
src/scales/scale.time.js
test/specs/global.deprecations.tests.js
test/specs/scale.time.tests.js

index 7d45602c1aed2eb76fa4da2abfb529e7acbda737..14621ba7a8b0ba76f0f10f4e8e6865d282fecc43 100644 (file)
@@ -146,7 +146,8 @@ module.exports = function(Chart) {
                        me.unit = unit;
                        me.majorUnit = majorUnit;
 
-                       var stepSize = timeOpts.stepSize || timeHelpers.determineStepSize(minTimestamp || dataMin, maxTimestamp || dataMax, unit, maxTicks);
+                       var optionStepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
+                       var stepSize = optionStepSize || timeHelpers.determineStepSize(minTimestamp || dataMin, maxTimestamp || dataMax, unit, maxTicks);
                        me.ticks = timeHelpers.generateTicks({
                                maxTicks: maxTicks,
                                min: minTimestamp,
index 5eeded72580d9fe6bd90bda8a4521fb0aff84fa3..253c49bf8a51864fb2d8e0f6aa232e6ab1a11636 100644 (file)
@@ -218,6 +218,35 @@ describe('Deprecations', function() {
                                expect(Chart.helpers.callCallback).toBe(Chart.helpers.callback);
                        });
                });
+
+               describe('Time Axis: unitStepSize option', function() {
+                       it('should use the stepSize property', function() {
+                               var chart = window.acquireChart({
+                                       type: 'line',
+                                       data: {
+                                               labels: ['2015-01-01T20:00:00', '2015-01-01T21:00:00'],
+                                       },
+                                       options: {
+                                               scales: {
+                                                       xAxes: [{
+                                                               id: 'time',
+                                                               type: 'time',
+                                                               time: {
+                                                                       unit: 'hour',
+                                                                       unitStepSize: 2
+                                                               }
+                                                       }]
+                                               }
+                                       }
+                               });
+
+                               var ticks = chart.scales.time.ticks.map(function(tick) {
+                                       return tick.value;
+                               });
+
+                               expect(ticks).toEqual(['8PM', '10PM']);
+                       });
+               });
        });
 
        describe('Version 2.5.0', function() {
index 86e0216e3300f56e5b7b5ba8ea8d05a5d821575f..2b8c50ed9694d60fb46b5a37e5271463e6ef9360 100755 (executable)
@@ -282,6 +282,24 @@ describe('Time scale tests', function() {
                expect(ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015', 'Jan 18, 2015', 'Jan 25, 2015', 'Feb 2015', 'Feb 8, 2015', 'Feb 15, 2015']);
        });
 
+       describe('config step size', function() {
+               it('should use the stepSize property', function() {
+                       var mockData = {
+                               labels: ['2015-01-01T20:00:00', '2015-01-01T21:00:00'],
+                       };
+
+                       var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('time'));
+                       config.time.unit = 'hour';
+                       config.time.stepSize = 2;
+
+                       var scale = createScale(mockData, config);
+                       scale.update(2500, 200);
+                       var ticks = getTicksValues(scale.ticks);
+
+                       expect(ticks).toEqual(['8PM', '10PM']);
+               });
+       });
+
        describe('when specifying limits', function() {
                var mockData = {
                        labels: ['2015-01-01T20:00:00', '2015-01-02T20:00:00', '2015-01-03T20:00:00'],