Premium support for our pure JavaScript UI components


Post by a.petrov@sis-it.pro »

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?


Post by Maxim Gorkovsky »

Hello.
It does sound like a bug, so I opened a ticket here: https://github.com/bryntum/support/issues/3245

You can try to override getAdjustedDates method to take increment into account:

new Scheduler({
  timeAxis : {
    getAdjustedDates(startDate, endDate, forceAdjust = false) {
            const me = this;
            if (endDate && startDate - endDate === 0) {
                endDate = null;
            }

            startDate = startDate || me.startDate;
            endDate = endDate || DateHelper.add(startDate, me.defaultSpan, me.mainUnit);

            return me.autoAdjust || forceAdjust ? {
                startDate : me.floorDate(startDate, false, me.autoAdjust ? me.mainUnit : me.unit, me.increment), // <- patched
                endDate   : me.ceilDate(endDate, false, me.autoAdjust ? me.mainUnit : me.unit, me.increment) // <- patched
            } : {
                startDate : startDate,
                endDate   : endDate
            };
        }
  }
});

Post by a.petrov@sis-it.pro »

Thanks, that works. Will this issue be fixed in the library, and if it will, when can we expect the fix?


Post by alex.l »

it was not prioritized yet, you can subscribe on ticket updates to be notified when it will be scheduled. All I can say now - I don't think we can expect it to be released in a nearest month.

All the best,
Alex


Post Reply