Timeline · Loading events
Long axis
Three months of hour columns — about 2,200 — across 200 rows. Columns are virtualized like rows: only those in view are drawn.
Live demo
Scroll far to the right · Drag an event
Fullscreenimport { useMemo } from "react"
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { bigTimeline } from "./data/generate"
import { useEvents } from "./kit"
export function LongAxisDemo() {
// Three months of hour columns (≈2,200) across 200 rows: only the columns
// and rows in view are rendered.
const data = useMemo(() => {
const now = new Date()
const months = [0, 1, 2].map((m) => bigTimeline(200, 10, new Date(now.getFullYear(), now.getMonth() + m, 1)))
return {
resources: months[0].resources,
events: months.flatMap((month, m) => month.events.map((e) => ({ ...e, id: `${e.id}-${m}` }))),
}
}, [])
const { events, handlers } = useEvents(data.events)
return (
<ProScheduler
data={events}
resources={data.resources}
view={{ timeline: { type: "month", size: 3, resolutionHorizontal: "hour" } }}
styleConfig={{ unitWidthPx: 32, fitToWidth: false }}
height={560}
{...handlers}
/>
)
}// data/generate.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { monthStart } from "./studio"
/** Mulberry32: a tiny seeded PRNG, good enough for demo data. */
function random(seed: number) {
let a = seed >>> 0
return () => {
a = (a + 0x6d2b79f5) >>> 0
let t = a
t = Math.imul(t ^ (t >>> 15), t | 1)
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
}
const palette = ["#2563eb", "#059669", "#d97706", "#7c3aed", "#db2777", "#0891b2", "#dc2626", "#65a30d"]
const words = ["Install", "Audit", "Repair", "Survey", "Upgrade", "Inspect", "Deliver", "Train", "Review", "Plan"]
/** `resourceCount` rows with `perResource` multi-hour to multi-day events
* each, spread across the current month. */
export function bigTimeline(resourceCount = 500, perResource = 12, base = monthStart()) {
const next = random(42)
const resources: SchedulerResource[] = Array.from({ length: resourceCount }, (_, i) => ({
id: `res-${i + 1}`,
name: `Resource ${String(i + 1).padStart(3, "0")}`,
color: palette[i % palette.length],
}))
const events: SchedulerEvent[] = []
for (const resource of resources) {
for (let n = 0; n < perResource; n++) {
const day = Math.floor(next() * 28)
const hour = 6 + Math.floor(next() * 12)
const start = new Date(base.getFullYear(), base.getMonth(), base.getDate() + day, hour)
const hours = 2 + Math.floor(next() * 60)
events.push({
id: `${resource.id}-${n}`,
title: `${words[Math.floor(next() * words.length)]} ${n + 1}`,
start,
end: new Date(start.getTime() + hours * 3_600_000),
resource: resource.id,
})
}
}
return { resources, events }
}About this demo
Three months of hour columns — about 2,200 — across 200 rows. Columns are virtualized like rows: only those in view are drawn.
Things to try
- Scroll far to the right
- Drag an event
The props behind it are explained in Scales, ranges and zoom.