Timeline · Loading events
Large dataset
Up to a thousand rows and twelve thousand events. Rows are virtualized, so only the ones in view are drawn.
Live demo
Switch to 1000 resources · Scroll to the bottom
Fullscreenimport { useMemo, useState } from "react"
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { bigTimeline } from "./data/generate"
import { Choice, Toolbar, useEvents, when } from "./kit"
export function LargeDatasetDemo() {
const [size, setSize] = useState(500)
const dataset = useMemo(() => bigTimeline(size, 12), [size])
const { events, setEvents, handlers } = useEvents(dataset.events)
const [shownFor, setShownFor] = useState(dataset)
// Swap the data when the size changes (state adjusted during render).
if (shownFor !== dataset) {
setShownFor(dataset)
setEvents(dataset.events)
}
return (
<div className="docs-demo__stack">
<Toolbar label="Dataset">
{[100, 500, 1000].map((n) => (
<Choice key={n} active={size === n} onClick={() => setSize(n)}>
{n} resources
</Choice>
))}
<span className="demo-muted">{events.length.toLocaleString()} events</span>
</Toolbar>
<ProScheduler
data={events}
resources={dataset.resources}
view={{ timeline: { type: "month" } }}
styleConfig={{ laneHeight: 22, laneGap: 2, rowPadding: 4, minRowHeight: 30, resourceColWidth: 150 }}
height={560}
{...handlers}
/>
</div>
)
}// 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
Up to a thousand rows and twelve thousand events. Rows are virtualized, so only the ones in view are drawn.
Things to try
- Switch to 1000 resources
- Scroll to the bottom
The props behind it are explained in Views.