Skip to content

Commit

Permalink
Ensure deprecated unitStepSize property of time scale is repsected + …
Browse files Browse the repository at this point in the history
…add tests
  • Loading branch information
etimberg committed Jun 22, 2017
1 parent de0ea5c commit 3dcdc96
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/scales/scale.time.js
Expand Up @@ -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.getValueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
var stepSize = optionStepSize || timeHelpers.determineStepSize(minTimestamp || dataMin, maxTimestamp || dataMax, unit, maxTicks);
me.ticks = timeHelpers.generateTicks({
maxTicks: maxTicks,
min: minTimestamp,
Expand Down
34 changes: 34 additions & 0 deletions test/specs/scale.time.tests.js
Expand Up @@ -282,6 +282,40 @@ 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']);
});

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.unitStepSize = 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'],
Expand Down

0 comments on commit 3dcdc96

Please sign in to comment.