Hello.
I have faced issue with custom view preset for half year.
Preset config:
{
id: 'half-year',
tickWidth: 40,
timeResolution: { unit: 'day', increment: 1 },
headers: [
{ unit: 'year', increment: 1, dateFormat: 'YYYY' },
{
unit: 'month',
increment: 6,
renderer(startDate: Date): string {
return startDate.getMonth() < 6 ? 'Half 1' : 'Half 2';
},
},
],
}
Also I modified TimeAxis.generateTicks for support of half-year:
function generateTicks(start: Date, end: Date) {
if (this.viewPreset.id === 'half-year') {
const dates = this['getAdjustedDates'](start, end);
start = dates.startDate;
end = dates.endDate;
const ticks = [];
this['tickCache'] = {};
while (start < end) {
let endDate: Date;
endDate = start.getMonth() < 6 ? new Date(start.getFullYear(), 5, 30) : new Date(start.getFullYear(), 11, 31);
if (endDate > end) {
endDate = end;
}
ticks.push({ id: ticks.length + 1, startDate: start, endDate });
this['tickCache'][start.getTime()] = ticks.length - 1;
start = new Date(endDate.getTime());
start.setDate(start.getDate() + 1);
}
return ticks;
} else {
return originalGenerateTicks.call(this, ...arguments);
}
}
Also should note that we set auto adjust of time axis to false.
If project has startDate=2020-12-01 and endDate=2022-31-01 first tick (half 2 of 2020) has width of full size tick instead of 1/6 of full-size tick. I have tried to figure out why this is happening and have found that visibleTickStart in TimeAxis.internalOnReconfigure calculates to 0. I think this is because of getAdjustedDates is using base unit (month) with increment 1 which gives us startDate (2020-12-01). As result in calculation of visibleTickStart tick has size of one month and is fully visible.
How can I fix this issue?