search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Custom timeline not cut off correctly

Asked by AC
26 days ago.

We have a custom timeline with custom headers and custom cells. Using the zoom level properties timeline, timeHeaders and cellWidth.

We set the headers based on an 8 hour shift. If the scheduler view end date is at midnight, that means the last timeline in the array is from 2024-10-30T22:00:00, till 2024-10-31T00:00:00. But this entry is ignored and the header is stretched for the full shift period.

Probably it is best to describe this with some screenshots.

As we can see here, Wednesday is longer than Thursday, and the last 22 header should be narrower, since the duration is only till midnight.

If we set the timeline width to 2 hours, it looks like it is divisible by the header, and the width of the last header is as expected.

What we would like to achieve is having the cells like in the first image, and the headers like in the second.

Comment posted by AC
26 days ago.

To describe it better, hopefully, setting the cell width to 2 hours, it looks like it is able to set the last header end time at midnight, because the cell with doesn’t stretch it.

It looks like the cell width of the last column can not be smaller than the other cells.

Something like this would be ideal. This also reflects the times in the custom timeline array.

Answer posted by Dan Letecky [DayPilot]
26 days ago.

In the manual timeline mode, the Scheduler always uses the default cell width unless you specify it explicitly. The start and end of the last shift are correct (2 hours), but it is displayed at full width (40 pixels by default).

You need to modify your logic to apply a custom width for the last cell.

Something like this:

function createTimeline() {
    const timeline = [];
    const start = new DayPilot.Date("2025-03-01");

    const shiftDuration = 8; // Shift duration in hours
    const firstShiftStart = 6; // First shift starts at 6 AM
    const shiftsPerDay = 3; // Number of shifts per day

    const standardCellWidth = 40; // dp.cellWidth

    const daysInMonth = start.daysInMonth();

    for (let i = 0; i < daysInMonth; i++) {
        const currentDay = start.addDays(i);
        const isLastDay = i === daysInMonth - 1;
        for (let j = 0; j < shiftsPerDay; j++) {
            const isLastCell = isLastDay && j === shiftsPerDay - 1;
            const hour = {};
            hour.start = currentDay.addHours(firstShiftStart + j * shiftDuration);

            hour.end = hour.start.addHours(shiftDuration);
            hour.width = standardCellWidth;

            // Adjust for the last cell on the last day
            if (isLastCell) {
                const monthEnd = start.addMonths(1).getDatePart(); // Start of next month
                if (hour.end > monthEnd) {
                    hour.end = monthEnd;
                }
                // Recalculate duration and width
                const durationMs = hour.end.getTime() - hour.start.getTime();
                const durationHours = durationMs / (1000 * 60 * 60);

                hour.width = (durationHours / shiftDuration) * standardCellWidth;
            }

            timeline.push(hour);
        }
    }
    return timeline;
}
Comment posted by AC
26 days ago.

It’s working wonderfully. Thank you again for your great support.

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):