Support isoWeekday when rounding (#7269)

This commit is contained in:
Jukka Kurkela 2020-04-14 02:34:18 +03:00 committed by GitHub
parent 1228981e4f
commit 32de1b6ebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 3 deletions

View File

@ -70,7 +70,7 @@ function parse(scale, input) {
const adapter = scale._adapter;
const options = scale.options.time;
const parser = options.parser;
const {parser, round, isoWeekday} = options;
let value = input;
if (typeof parser === 'function') {
@ -88,8 +88,10 @@ function parse(scale, input) {
return value;
}
if (options.round) {
value = scale._adapter.startOf(value, options.round);
if (round) {
value = round === 'week' && isoWeekday
? scale._adapter.startOf(value, 'isoWeek', isoWeekday)
: scale._adapter.startOf(value, round);
}
return +value;

View File

@ -486,6 +486,37 @@ describe('Time scale tests', function() {
expect(xScale.getLabelForValue(value)).toBe('Jan 1, 2015, 8:00:00 pm');
});
it('should round to isoWeekday', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [{x: '2020-04-12T20:00:00', y: 1}, {x: '2020-04-13T20:00:00', y: 2}]
}]
},
options: {
scales: {
x: {
type: 'time',
ticks: {
source: 'data'
},
time: {
unit: 'week',
round: 'week',
isoWeekday: 1,
displayFormats: {
week: 'WW'
}
}
},
}
}
});
expect(getLabels(chart.scales.x)).toEqual(['15', '16']);
});
it('should get the correct label for a timestamp', function() {
var chart = window.acquireChart({
type: 'line',