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

[BUG] Use time.unit option to create default min/max for empty chart #5045

Merged
Merged
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/scales/scale.time.js
Expand Up @@ -504,6 +504,7 @@ module.exports = function(Chart) {
var me = this;
var chart = me.chart;
var timeOpts = me.options.time;
var unit = timeOpts.unit || 'day';
var min = MAX_INTEGER;
var max = MIN_INTEGER;
var timestamps = [];
Expand Down Expand Up @@ -555,9 +556,9 @@ module.exports = function(Chart) {
min = parse(timeOpts.min, me) || min;
max = parse(timeOpts.max, me) || max;

// In case there is no valid min/max, let's use today limits
min = min === MAX_INTEGER ? +moment().startOf('day') : min;
max = max === MIN_INTEGER ? +moment().endOf('day') + 1 : max;
// In case there is no valid min/max, set limits based on unit time option
min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;

// Make sure that max is strictly higher than min (required by the lookup table)
me.min = Math.min(min, max);
Expand Down