A header tick can be drawn by the consumer
Context
A consumer app needs a header that shows a weekday letter above a day number, a week-start label, off-day shading and a highlight on today. A preset format returns a string. It cannot return two lines or a flag.
Decision
gantt.headerTickRenderer = (ctx: HeaderTickContext) => HeaderTickPaint | undefined;
interface HeaderTickContext { band: number; tick: Tick; time: ZonedTime; locale: Intl.LocalesArgument; rangeStart: ZonedTime }
interface HeaderTickPaint { content?: ElementDescription; flags?: readonly string[] }
{ unit: 'month', format: { month: 'long' }, heightPx: 30 }
undefinedmeans the library text.flagsbecomedata-flagtokens on the tick. A consumer addsofffrom its own calendar. The library never assumes Saturday and Sunday.- The core stamps
todayitself, because the library owns the clock. For the week unit, the tick that holds today. heightPxon a header band wins over--fg-band-height, which wins over the default.HeaderFormatalso receivesrangeStart, so a label can show a year only when the year changes.
Options rejected
- A richer
formatstring. It cannot carry a flag or a second line. - A consumer flag for
today. The consumer would need the library's clock and zone.
Consequences
- With no renderer, the header draws as before.
Addendum: a band can align its cells to a finer unit
A month band and a week band drift apart where a week crosses a month end. A consumer wants one month cell to cover whole weeks.
ViewPresetHeader.alignTo?: TimeUnitmakes the band's cells start and end on boundaries of that finer unit.- A month band with
alignTo: 'week'owns the weeks whose first day falls in that month. alignTomust be strictly finer than the band'sunit.resolvePresetthrowsInvalidPresetErrorwith rule'header-align'otherwise.- The cells come from the same tick walk as every other band.
tickFloorandnextTickfind the calendar boundary, and the firstalignToboundary at or after it starts the cell. - The name is
alignTobecausesnapmeans drag snapping. - A header tick renderer and a
rangeStartyear label see the aligned cell as a normal tick.