Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure deprecated unitStepSize property of time scale is respected #4401

Merged
merged 1 commit into from Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.valueOrDefault(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
29 changes: 29 additions & 0 deletions test/specs/global.deprecations.tests.js
Expand Up @@ -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() {
Expand Down
18 changes: 18 additions & 0 deletions test/specs/scale.time.tests.js
Expand Up @@ -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'],
Expand Down