mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Support isoWeekday when rounding (#7269)
This commit is contained in:
parent
1228981e4f
commit
32de1b6ebf
@ -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;
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user