本文へ移動

ショーケース

建設工程表

オフィスビルの全体工程表です。クリティカルパス、ベースライン、作業班の平準化、アーンドバリュー、遅延の試算を表示し、すべての日付をコアのスケジューラーで計算します。

ライブデモGitHub で見る ↗

Harbour Point · 9階建てオフィスビル

建設工程表

休日を含む現場カレンダーでコアのスケジューラーが計算した全体工程表です。クリティカルパス、余裕、ベースライン、報告済み進捗のある基準日、平準化付きの作業班負荷、アーンドバリュー、鉄骨遅延の試算を表示します。

引き渡しの予測2027年3月23日ベースライン比 +4 稼働日契約期限 3月31日 まで余裕 6 稼働日
SPI0.91SV −$1.5M
CPI0.96CV −$0.6M
EAC$40.9MBAC $39.4M · VAC −$1.5M
完了率39%計画 43%
過負荷33能力超過の班・日数
  • クリティカルパス
  • 余裕あり
  • 完了
  • ベースライン
  • 基準日
  • 過負荷
100%
作業分解
終了
余裕
差異
週 1週 9週 17週 25週 33週 41週 49週 57
Q1
2026年 Q2
2026年 Q3
2026年 Q4
2027年 Q1
Q2
3月
4月
5月
6月
7月
8月
9月
10月
11月
12月
1月
2月
3月
4月
5月
契約
1Site preparation
4月2日
0日
0日
2Substructure
7月16日
0日
+6日
3Superstructure
11月30日
0日
+1日
3.1Concrete core (jump form)
8月20日
完了
+6日
3.2Steel package A · fab & deliver
7月28日
完了
+4日
3.3Steel package B · fab & deliver
9月29日
0日
+1日
3.4Level 1 frame & deck
8月10日
完了
+4日
3.5Level 2 frame & deck
8月20日
完了
+4日
3.6Level 3 frame & deck
9月17日
0日
+15日
3.7Level 4 frame & deck
9月29日
0日
+15日
3.8Level 5 frame & deck
10月9日
3日
+1日
3.9Level 6 frame & deck
10月21日
3日
+1日
Civil & groundworks1 班 · ピーク 1
Concrete gang1 班 · ピーク 1
矢印キーで移動、Shift で終了を、Alt で開始を伸縮します。Escape で取り消します。

アーンドバリュー · S カーブ

  • 計画 (PV)
  • 出来高 (EV)
  • 実コスト (AC)
  • 予測
累積コストの S カーブ計画価値は 2027年3月17日 に $39.4M に達します。基準日の PV は $17.0M、EV は $15.5M、AC は $16.1M で、予測は 2027年3月23日 に $40.9M に達します。$0.0M$10.0M$20.0M$30.0M$40.0M$50.0M26年4月26年7月26年10月27年1月27年4月基準日

主要マイルストーン

マイルストーンベースライン予測差異
Substructure complete7月9日7月17日+6 稼働日
Topping out11月26日12月1日+1 稼働日
Building watertight1月6日1月12日+4 稼働日
Practical completion3月17日3月23日+4 稼働日

クリティカルパス上の次の作業

  1. Steel package B · fab & deliver8月3日 – 9月29日
  2. Level 3 frame & deck8月21日 – 9月17日
  3. Lift installation8月21日 – 10月21日
  4. MEP rough-in L1–L28月24日 – 9月30日
  5. Level 4 frame & deck9月18日 – 9月29日
書き出し

基準日は 2026年9月14日です。未着手のバーをドラッグするか矢印キーで動かすと、計画を再計算します。

デモの右下の角をドラッグすると高さを変えられます。

ソースコード

vue
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, shallowRef, useId } from 'vue'
import {
  GanttChart, buildWorkPeriods, calculateResourceLoad, comparePlans, computeEarnedValue, invertWorkPeriods, levelResources,
  planBaselines, rescheduleFromStatusDate, scheduleTasks, scheduledBarFields, timelineConstraints, timelineCsvTable, toCsv,
  toMsProjectXml, type ScheduleInput, type ScheduleSuccess, type ScheduleTask, type ScheduledTask, type TimelineBand,
  type TimelineBar, type TimelineColumn, type TimelineEdit, type TimelineRow, type TimeRange,
} from '../../src'
import { download } from '../download'
import {
  assignments, baselineDurations, contractCompletion, crewLabel, crews, day, dependencies, holidays, on, phases, range,
  reportedProgress, scheduleTasksOf, statusDate, steelDeliveryId, tasks as program,
} from './constructionData'
import { useDemoLocale } from '../i18n'

// An executive master schedule for an office tower. Every date comes from the core scheduler: a weekday calendar with
// holidays, FS and SS links with lags, requested starts, a status date with reported progress, and resource leveling.
// The chart is controlled: an accepted bar edit becomes a requested start or a duration and the plan is recalculated.
interface RowData { kind: 'phase' | 'task' | 'milestone'; wbs: string }
interface ProgramRow extends TimelineRow<RowData> { data: RowData }

// Task, phase and crew names are data and stay in English; the interface follows the page language.
const { t, labels, isJapanese } = useDemoLocale()

const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
const formatTime = (time: number) => {
  const date = new Date(time)
  return isJapanese.value ? `${date.getUTCMonth() + 1}月${date.getUTCDate()}日` : `${date.getUTCDate()} ${months[date.getUTCMonth()]}`
}
const formatDate = (time: number) => isJapanese.value ? `${new Date(time).getUTCFullYear()}年${formatTime(time)}` : `${formatTime(time)} ${new Date(time).getUTCFullYear()}`
/** Working days: "wd" in English. */
const wd = t({ en: 'wd', ja: '稼働日' })
const doneText = t({ en: 'done', ja: '完了' })
const money = (thousands: number | undefined) => thousands === undefined ? 'n/a' : `$${(thousands / 1000).toFixed(1)}M`
const signedMoney = (thousands: number) => (thousands < 0 ? '−' : '+') + money(Math.abs(thousands))
const ratio = (value: number | undefined) => value === undefined ? 'n/a' : value.toFixed(2)
const signedDays = (days: number) => days === 0 ? `±0 ${wd}` : `${days > 0 ? '+' : '−'}${Math.abs(days)} ${wd}`

// ---- calendar: weekdays, with holidays and the winter shutdown closed ----
const exceptions = Object.fromEntries(holidays.map(date => [date, []]))
const allDay = (weekday: number) => ({ weekday, startMinute: 0, endMinute: 1440 })
const periods = buildWorkPeriods(range, { weekly: [1, 2, 3, 4, 5].map(allDay), exceptions })
const calendars = [{ id: 'site', periods }]
// Only holidays and the shutdown are shaded; weekends would stripe the whole chart at this zoom.
const closures = invertWorkPeriods(buildWorkPeriods(range, { weekly: [0, 1, 2, 3, 4, 5, 6].map(allDay), exceptions }), range)
/** Working time in [from, to), in elapsed units. */
const workIn = (from: number, to: number) =>
  periods.reduce((sum, period) => sum + Math.max(0, Math.min(to, period.end) - Math.max(from, period.start)), 0)
/** Signed working days from a to b. */
const workDaysBetween = (a: number, b: number) => Math.round((b >= a ? workIn(a, b) : -workIn(b, a)) / day)
const input = (list: readonly ScheduleTask[]): ScheduleInput => ({ range, quantum: day, calendars, defaultCalendarId: 'site', tasks: list, dependencies })
const resources = crews.map(crew => ({ id: crew.id, capacity: crew.capacity, periods }))
const programById = new Map(program.map(task => [task.id, task]))
const labelOf = (id: string) => programById.get(id)?.label ?? phases.find(phase => phase.id === id)?.label ?? id
const started = (id: string) => (reportedProgress.get(id) ?? 0) > 0

function mustSchedule(result: ReturnType<typeof scheduleTasks>): ScheduleSuccess {
  if (!result.ok) throw new Error('The construction program must be feasible')
  return result
}
// The signed-off baseline: the same logic before ground conditions lengthened piling and excavation.
const baselinePlan = mustSchedule(scheduleTasks(input(scheduleTasksOf(program.map(task => ({ ...task, days: baselineDurations.get(task.id) ?? task.days }))))))
const baselines = planBaselines(baselinePlan, 'baseline')
const baselineById = new Map(baselinePlan.tasks.map(task => [task.id, task]))

/**
 * The plan at the status date. rescheduleFromStatusDate keeps the reported work in place and moves the rest after the
 * status date; the result is then pinned (fixed starts and pauses for started tasks, the status date as earliest start
 * for the others), so that scheduleTasks and levelResources both plan from the same progress. The what-if scenario
 * adds ten working days to the remaining steel delivery.
 */
function statusTasks(list: readonly ScheduleTask[], steelDelay: boolean): ScheduleTask[] {
  const progressed = rescheduleFromStatusDate(input(list), statusDate, reportedProgress)
  if (!progressed.ok) throw new Error('The reported progress must fit the program')
  const placed = new Map(progressed.tasks.map(task => [task.id, task]))
  return list.map(task => {
    if (task.parentId === undefined) return task
    let next: ScheduleTask
    if (started(task.id)) {
      const { work, start } = placed.get(task.id)!
      const { startNoEarlierThan: _requested, ...rest } = task
      const pauses = work.slice(1).map((piece, index) => ({ start: work[index]!.end, end: piece.start }))
      next = { ...rest, fixedStart: start, ...(pauses.length ? { pauses } : {}) }
    } else next = { ...task, startNoEarlierThan: Math.max(task.startNoEarlierThan ?? range.start, statusDate) }
    return steelDelay && task.id === steelDeliveryId ? { ...next, duration: next.duration + 10 * day } : next
  })
}

const initialTasks = scheduleTasksOf(program)
const planTasks = shallowRef<ScheduleTask[]>(initialTasks)
const whatIf = ref(false)
const showAllLinks = ref(false)
const leveled = ref(false)
const status = ref(t({
  en: 'Status date 14 Sep 2026. Drag or use the arrow keys on an unstarted bar to reschedule it; the plan is recalculated.',
  ja: '基準日は 2026年9月14日です。未着手のバーをドラッグするか矢印キーで動かすと、計画を再計算します。',
}))
const scenario = (steelDelay: boolean) => {
  const list = statusTasks(planTasks.value, steelDelay)
  return { tasks: list, plan: mustSchedule(scheduleTasks(input(list))) }
}
const current = computed(() => scenario(false))
const delayed = computed(() => whatIf.value ? scenario(true) : undefined)
const shown = computed(() => delayed.value ?? current.value)
const plan = computed(() => shown.value.plan)
const byId = computed(() => new Map(plan.value.tasks.map(task => [task.id, task])))
const handover = computed(() => byId.value.get('handover')!.start)
// comparePlans measures the what-if against the current plan: the finish shift and every task it moves.
const comparison = computed(() => delayed.value && comparePlans(
  { input: input(current.value.tasks), result: current.value.plan },
  { input: input(delayed.value.tasks), result: delayed.value.plan },
))
const whatIfSlip = computed(() => comparison.value ? workDaysBetween(current.value.plan.finish, delayed.value!.plan.finish) : 0)
const baselineSlip = computed(() => workDaysBetween(baselineById.get('handover')!.start, handover.value))
const contractMargin = computed(() => workDaysBetween(handover.value, contractCompletion))
const load = computed(() => calculateResourceLoad(range, plan.value.tasks, resources, assignments))
// The histogram draws each task's work across weekends and holidays it spans, so crews read as solid blocks; the
// over-allocation figure above counts working days only.
const loadView = computed(() => calculateResourceLoad(range, plan.value.tasks.map(task => ({
  ...task, work: task.work.length ? splitWork(task) ?? [{ start: task.start, end: task.end }] : [],
})), crews.map(({ id, capacity }) => ({ id, capacity })), assignments))
const overCrewDays = computed(() => load.value.reduce((sum, segment) => sum + segment.overload * workIn(segment.start, segment.end) / day, 0))
/** The next unfinished critical tasks, in date order: what the site team must protect. */
const criticalAhead = computed(() => plan.value.tasks
  .filter(task => task.critical && !task.summary && task.end > task.start && (reportedProgress.get(task.id) ?? 0) < 1)
  .sort((a, b) => a.start - b.start).slice(0, 5))
const criticalLinks = computed(() => new Set(plan.value.criticalDependencyIds))

// ---- earned value: baseline dates, reported progress, cost rates, and weekly history from the work done ----
const progressedPlan = mustSchedule(scheduleTasks(input(statusTasks(initialTasks, false))))
const workDone = (task: ScheduledTask, time: number) => task.work.reduce((sum, piece) => sum + Math.max(0, Math.min(time, piece.end) - piece.start), 0)
const earned = computeEarnedValue(program.filter(task => task.budget > 0).map(task => {
  const progress = reportedProgress.get(task.id) ?? 0
  const done = progressedPlan.tasks.find(item => item.id === task.id)!
  const doneAtStatus = workDone(done, statusDate)
  const at = (time: number) => doneAtStatus ? progress * workDone(done, time) / doneAtStatus : 0
  const history = []
  for (let time = range.start; time < statusDate; time += 7 * day) {
    history.push({ time, progress: at(time), actualCost: Math.round(at(time) * task.budget * (task.costRate ?? 1)) })
  }
  const { start, end } = baselineById.get(task.id)!
  return { id: task.id, budget: task.budget, start, end, calendarId: 'site', progress, actualCost: Math.round(progress * task.budget * (task.costRate ?? 1)), history }
}), { statusDate, calendars, series: { step: 7 * day, start: range.start, end: baselinePlan.finish } })
const totals = earned.totals

// ---- S-curve ----
const curve = { width: 560, height: 230, left: 52, right: 14, top: 14, bottom: 26 }
const yMax = Math.ceil(Math.max(totals.bac, totals.eac ?? 0) / 10_000) * 10_000
const cx = (time: number) => curve.left + (time - range.start) / (range.end - range.start) * (curve.width - curve.left - curve.right)
const cy = (value: number) => curve.height - curve.bottom - value / yMax * (curve.height - curve.top - curve.bottom)
const line = (points: readonly (readonly [number, number | undefined])[]) => points.filter(([, value]) => value !== undefined)
  .map(([time, value], index) => `${index ? 'L' : 'M'}${cx(time).toFixed(1)},${cy(value!).toFixed(1)}`).join('')
const pvLine = line(earned.series.map(point => [point.time, point.pv]))
const pvArea = `${pvLine}L${cx(baselinePlan.finish).toFixed(1)},${cy(0)}L${cx(range.start).toFixed(1)},${cy(0)}Z`
const evLine = line(earned.series.map(point => [point.time, point.ev]))
const acLine = line(earned.series.map(point => [point.time, point.ac]))
const forecastEv = computed(() => line([[statusDate, totals.ev], [plan.value.finish, totals.bac]]))
const forecastAc = computed(() => line([[statusDate, totals.ac], [plan.value.finish, totals.eac]]))
const yTicks = Array.from({ length: yMax / 10_000 + 1 }, (_, index) => index * 10_000)
const xTicks = [on(2026, 4, 1), on(2026, 7, 1), on(2026, 10, 1), on(2027, 1, 1), on(2027, 4, 1)]
const curveId = useId()
const curveSummary = computed(() => t({
  en: `Planned value reaches ${money(totals.bac)} on ${formatDate(baselinePlan.finish)}. At the status date PV is `
    + `${money(totals.pv)}, EV ${money(totals.ev)} and AC ${money(totals.ac)}; the forecast reaches ${money(totals.eac)} on ${formatDate(plan.value.finish)}.`,
  ja: `計画価値は ${formatDate(baselinePlan.finish)} に ${money(totals.bac)} に達します。基準日の PV は ${money(totals.pv)}、EV は ${money(totals.ev)}、`
    + `AC は ${money(totals.ac)} で、予測は ${formatDate(plan.value.finish)} に ${money(totals.eac)} に達します。`,
}))

// ---- chart ----
const wbs = new Map<string, string>()
phases.forEach((phase, index) => {
  wbs.set(phase.id, String(index + 1))
  program.filter(task => task.phase === phase.id).forEach((task, child) => wbs.set(task.id, `${index + 1}.${child + 1}`))
})
const rows: ProgramRow[] = phases.flatMap(phase => [
  { id: phase.id, label: phase.label, data: { kind: 'phase' as const, wbs: wbs.get(phase.id)! } },
  ...program.filter(task => task.phase === phase.id).map(task => ({
    id: task.id, parentId: phase.id, label: task.label, data: { kind: task.days ? 'task' as const : 'milestone' as const, wbs: wbs.get(task.id)! },
  })),
])
const collapsed = ref<ReadonlySet<string>>(new Set(['site', 'sub']))
// The chart is as tall as its content, so the crew load rows stay in view below the tasks.
const rowHeight = 25, loadRowHeight = 32
const chartHeight = computed(() => 40 + 2 * 26 + rows.filter(row => !row.parentId || !collapsed.value.has(row.parentId)).length * rowHeight
  + crews.length * loadRowHeight + 16)
const quarters: TimelineBand[] = []
for (let year = 2026, quarter = 0; on(year, quarter * 3 + 1, 1) < range.end; quarter === 3 ? (year++, quarter = 0) : quarter++) {
  const start = Math.max(range.start, on(year, quarter * 3 + 1, 1)), end = Math.min(range.end, on(year, quarter * 3 + 4, 1))
  if (end > start) quarters.push({ start, end, label: end - start > 40 * day ? t({ en: `Q${quarter + 1} ${year}`, ja: `${year}年 Q${quarter + 1}` }) : `Q${quarter + 1}` })
}
const monthBands: TimelineBand[] = []
for (let time = range.start; time < range.end;) {
  const date = new Date(time), next = Math.min(range.end, on(date.getUTCFullYear(), date.getUTCMonth() + 2, 1))
  monthBands.push({ start: time, end: next, label: t({ en: months[date.getUTCMonth()]!, ja: `${date.getUTCMonth() + 1}月` }) })
  time = next
}
const markers = [{ id: 'contract', time: contractCompletion, label: t({ en: 'Contract', ja: '契約' }) }]
/** Work pieces split by more than calendar time off: the reported work and its resumption after the status date. */
function splitWork(task: ScheduledTask): TimeRange[] | undefined {
  const pieces: TimeRange[] = []
  for (const piece of task.work) {
    const last = pieces[pieces.length - 1]
    if (last && workIn(last.end, piece.start) === 0) pieces[pieces.length - 1] = { start: last.start, end: piece.end }
    else pieces.push({ ...piece })
  }
  return pieces.length > 1 ? pieces : undefined
}
const bars = computed<TimelineBar[]>(() => program.map(task => {
  const scheduled = byId.value.get(task.id)!
  const { segments: _segments, critical, latestEnd, ...dates } = scheduledBarFields(scheduled)
  const progress = reportedProgress.get(task.id) ?? 0
  const done = progress >= 1
  const requested = planTasks.value.find(item => item.id === task.id)?.startNoEarlierThan
  return {
    id: task.id, rowId: task.id, label: task.label, ...dates, progress: task.days ? progress : undefined,
    segments: splitWork(scheduled), baselines: [baselines.get(task.id)!],
    tone: done ? 'teal' : critical ? 'amber' : 'blue', critical: critical && !done,
    ...(done || critical || !task.days ? {} : { latestEnd }),
    ...(task.id === 'handover' ? { deadline: contractCompletion } : {}),
    ...(started(task.id) || requested === undefined ? {} : { constraints: timelineConstraints({ startNoEarlierThan: requested }) }),
    editable: !done && task.days > 0,
    description: crewLabel(task.id) ?? (task.days ? t({ en: 'Subcontract package', ja: '下請け工事' }) : t({ en: 'Milestone', ja: 'マイルストーン' })),
  }
}))
const chartLinks = computed(() => showAllLinks.value ? dependencies : dependencies.filter(link => criticalLinks.value.has(link.id)))
const loadRows = crews.map(crew => ({ id: crew.id, label: crew.label, detail: t({ en: `${crew.capacity} ${crew.capacity === 1 ? 'crew' : 'crews'}`, ja: `${crew.capacity} 班` }) }))
/** The last working day of a task or summary (its end is the exclusive midnight after it); a milestone's own day. */
function lastWorkDay(task: TimeRange) {
  if (task.end === task.start) return task.start
  let last = task.start
  for (const period of periods) if (period.start < task.end) last = Math.min(period.end, task.end) - day
  return last
}
const columns: TimelineColumn<ProgramRow>[] = [
  { id: 'finish', label: t({ en: 'Finish', ja: '終了' }), width: 58, value: row => formatTime(lastWorkDay(byId.value.get(row.id)!)) },
  { id: 'float', label: t({ en: 'Float', ja: '余裕' }), width: 46, value: row => {
    const task = byId.value.get(row.id)!
    return reportedProgress.get(row.id) === 1 ? doneText : `${Math.round(task.workFloat / day)}${t({ en: 'd', ja: '日' })}`
  } },
  { id: 'variance', label: t({ en: 'Var', ja: '差異' }), width: 48, value: row => {
    const task = byId.value.get(row.id)!, base = baselineById.get(row.id)!
    const days = workDaysBetween(lastWorkDay(base), lastWorkDay(task))
    const unit = t({ en: 'd', ja: '日' })
    return days ? (days > 0 ? '+' : '−') + Math.abs(days) + unit : '0' + unit
  } },
]
const milestones = ['sub-done', 'topping', 'watertight', 'handover'].map(id => ({ id, label: labelOf(id) }))

// ---- edits, leveling and scenarios ----
const animating = ref(false)
let animationTimer: ReturnType<typeof setTimeout> | undefined
function animate() {
  animating.value = true
  clearTimeout(animationTimer)
  animationTimer = setTimeout(() => { animating.value = false }, 900)
}
onBeforeUnmount(() => clearTimeout(animationTimer))
function handoverNote(before: number) {
  const shift = workDaysBetween(before, handover.value)
  return t({
    en: `Practical completion ${formatDate(handover.value)} (${shift ? signedDays(shift) : 'no change'}).`,
    ja: `実質的完成は ${formatDate(handover.value)}(${shift ? signedDays(shift) : '変更なし'})。`,
  })
}
function validateEdit(change: TimelineEdit) {
  if (started(change.id)) return t({ en: `${labelOf(change.id)} has started; report progress instead of moving it.`, ja: `${labelOf(change.id)} は着手済みです。移動せずに進捗を報告してください。` })
  if (change.mode === 'start') return t({ en: 'Drag the bar to move it, or its right edge to change its duration.', ja: 'バーをドラッグして移動するか、右端をドラッグして期間を変えてください。' })
}
function onEdit(change: TimelineEdit) {
  const before = handover.value
  const next = planTasks.value.map(task => task.id !== change.id ? task : change.mode === 'move'
    ? { ...task, startNoEarlierThan: change.after.start }
    : { ...task, duration: Math.max(day, workIn(change.before.start, change.after.end)) })
  try {
    statusTasks(next, whatIf.value)
    mustSchedule(scheduleTasks(input(statusTasks(next, whatIf.value))))
  } catch {
    status.value = t({
      en: `${labelOf(change.id)} cannot go there: the program would run past ${formatDate(range.end)}.`,
      ja: `${labelOf(change.id)} はそこへ動かせません。工程が ${formatDate(range.end)} を超えてしまいます。`,
    })
    return
  }
  planTasks.value = next
  const task = byId.value.get(change.id)!
  const held = change.mode === 'move' && task.start > change.after.start
  status.value = (change.mode === 'move'
    ? t({
      en: `${labelOf(change.id)} starts ${formatTime(task.start)}${held ? ', held by its predecessors' : ''}. `,
      ja: `${labelOf(change.id)} は ${formatTime(task.start)} に開始します${held ? '(先行作業の制約による)' : ''}。`,
    })
    : t({
      en: `${labelOf(change.id)} now takes ${task.work.reduce((sum, piece) => sum + piece.end - piece.start, 0) / day} working days. `,
      ja: `${labelOf(change.id)} の期間は ${task.work.reduce((sum, piece) => sum + piece.end - piece.start, 0) / day} 稼働日になりました。`,
    })) + handoverNote(before)
}
function onRejected(_change: TimelineEdit, reason: string) {
  status.value = reason
}
function toggleWhatIf() {
  const before = handover.value
  whatIf.value = !whatIf.value
  animate()
  status.value = whatIf.value
    ? t({
      en: `What-if: steel package B arrives 10 working days late; ${comparison.value?.result.consequenceTaskIds.length ?? 0} tasks move. ${handoverNote(before)}`,
      ja: `試算: 鉄骨パッケージ B が 10 稼働日遅れて到着し、${comparison.value?.result.consequenceTaskIds.length ?? 0} 件の作業が動きます。${handoverNote(before)}`,
    })
    : t({ en: `Steel delivery back on its forecast. ${handoverNote(before)}`, ja: `鉄骨の納入を予測どおりに戻しました。${handoverNote(before)}` })
}
function level() {
  const before = handover.value
  const result = levelResources({ ...input(shown.value.tasks), resources, assignments })
  if (!result.ok) return
  // Persist each capacity delay as a requested start; successors follow through their links.
  const delays = new Map(result.delays.filter(delay => delay.cause === 'capacity').map(delay => [delay.taskId, delay.after.start]))
  planTasks.value = planTasks.value.map(task => delays.has(task.id) ? { ...task, startNoEarlierThan: delays.get(task.id)! } : task)
  leveled.value = true
  animate()
  const names = [...delays.keys()].map(labelOf).join(t({ en: ' and ', ja: '、' }))
  status.value = delays.size
    ? t({ en: `Levelled: ${names} wait for free crews. ${handoverNote(before)}`, ja: `平準化しました: ${names} は空いた作業班を待ちます。${handoverNote(before)}` })
    : t({ en: 'No crew is over-allocated.', ja: '能力を超えた作業班はありません。' })
}
function reset() {
  planTasks.value = initialTasks
  whatIf.value = false
  leveled.value = false
  animate()
  status.value = t({ en: 'Plan reset to the reported status.', ja: '計画を報告時点の状態に戻しました。' })
}

// ---- exports ----
const chart = ref<InstanceType<typeof GanttChart>>()
function exportMsProject() {
  const tasks = rows.map(row => {
    const task = byId.value.get(row.id)!, base = baselineById.get(row.id)!
    const requested = planTasks.value.find(item => item.id === row.id)?.startNoEarlierThan
    return {
      id: row.id, name: row.label, start: task.start, end: task.end, outlineLevel: row.parentId ? 2 : 1,
      percentComplete: Math.round((reportedProgress.get(row.id) ?? 0) * 100), baselines: [{ number: 0, start: base.start, end: base.end }],
      ...(row.parentId && !started(row.id) && requested !== undefined ? { constraints: { startNoEarlierThan: requested } } : {}),
    }
  })
  const xml = toMsProjectXml({
    name: 'Office tower master schedule', tasks,
    dependencies: dependencies.map(link => ({ from: link.from, to: link.to, type: link.type, lag: link.lag })),
    resources: crews.map(crew => ({ id: crew.id, name: crew.label, maxUnits: crew.capacity })), assignments,
  })
  download(new Blob([xml], { type: 'application/xml' }), 'office-tower.xml')
  status.value = t({
    en: `Exported Microsoft Project XML with ${tasks.length} tasks and ${dependencies.length} links.`,
    ja: `${tasks.length} 件の作業と ${dependencies.length} 件の依存関係を Microsoft Project XML に書き出しました。`,
  })
}
function exportCsv() {
  const csv = toCsv(timelineCsvTable(rows, bars.value, { formatTime: time => new Date(time).toISOString().slice(0, 10) }))
  download(new Blob([csv], { type: 'text/csv' }), 'office-tower.csv')
  status.value = t({ en: `Exported CSV with ${bars.value.length} work packages.`, ja: `${bars.value.length} 件の作業パッケージを CSV に書き出しました。` })
}
function exportSvg() {
  const svg = chart.value?.exportSvg({
    title: t({ en: 'Office tower · master schedule', ja: 'オフィスビル · 全体工程表' }), rowHeading: t({ en: 'Work breakdown', ja: '作業分解' }),
  })
  if (!svg) return
  download(svg, 'office-tower.svg')
  status.value = t({ en: 'Exported the schedule as SVG.', ja: '工程表を SVG に書き出しました。' })
}
</script>

<template>
  <section class="sc-build" :class="{ 'sc-build-animating': animating }" :aria-label="t({ en: 'Construction program', ja: '建設工程表' })">
    <div class="sc-build-head">
      <div>
        <p class="sc-build-eyebrow">{{ t({ en: 'Harbour Point · 9-storey office tower', ja: 'Harbour Point · 9階建てオフィスビル' }) }}</p>
        <h2>{{ t({ en: 'Construction program', ja: '建設工程表' }) }}</h2>
        <p class="sc-build-intro">{{ t({
          en: 'A master schedule computed by the core scheduler on a site calendar with holidays: critical path, float, baseline strips, the status date with reported progress, crew load with leveling, earned value and a steel-delay what-if.',
          ja: '休日を含む現場カレンダーでコアのスケジューラーが計算した全体工程表です。クリティカルパス、余裕、ベースライン、報告済み進捗のある基準日、平準化付きの作業班負荷、アーンドバリュー、鉄骨遅延の試算を表示します。',
        }) }}</p>
      </div>
      <div class="sc-build-actions">
        <label class="sc-build-switch"><input type="checkbox" :checked="whatIf" @change="toggleWhatIf"><span aria-hidden="true"></span>{{ t({ en: 'What-if: delay steel delivery +10 working days', ja: '試算: 鉄骨の納入を 10 稼働日遅らせる' }) }}</label>
        <button type="button" class="sc-build-primary" :disabled="overCrewDays === 0" @click="level">{{ overCrewDays === 0 && leveled ? t({ en: 'Resources levelled', ja: '平準化済み' }) : t({ en: 'Level resources', ja: '資源を平準化' }) }}</button>
        <button type="button" @click="reset">{{ t({ en: 'Reset', ja: 'リセット' }) }}</button>
      </div>
    </div>

    <div class="sc-build-kpis" :aria-label="t({ en: 'Key indicators', ja: '主要指標' })">
      <div class="sc-build-kpi sc-build-kpi-hero" role="group" :aria-label="t({ en: 'Forecast handover', ja: '引き渡しの予測' })" :class="{ 'sc-build-late': contractMargin < 0 }">
        <span class="sc-build-kpi-label">{{ t({ en: 'Forecast handover', ja: '引き渡しの予測' }) }}</span>
        <strong>{{ formatDate(handover) }}</strong>
        <span class="sc-build-badges">
          <span class="sc-build-badge" :class="baselineSlip > 0 ? 'sc-build-badge-warn' : 'sc-build-badge-ok'">{{ t({ en: `${signedDays(baselineSlip)} vs baseline`, ja: `ベースライン比 ${signedDays(baselineSlip)}` }) }}</span>
          <span v-if="whatIf" class="sc-build-badge sc-build-badge-bad">{{ t({ en: 'what-if', ja: '試算' }) }} {{ signedDays(whatIfSlip) }}</span>
        </span>
        <small>{{ contractMargin >= 0
          ? t({ en: `${contractMargin} wd margin to contract ${formatTime(contractCompletion)}`, ja: `契約期限 ${formatTime(contractCompletion)} まで余裕 ${contractMargin} 稼働日` })
          : t({ en: `${-contractMargin} wd past contract ${formatTime(contractCompletion)}`, ja: `契約期限 ${formatTime(contractCompletion)} を ${-contractMargin} 稼働日超過` }) }}</small>
      </div>
      <div class="sc-build-kpi" role="group" :aria-label="t({ en: 'Schedule performance', ja: 'スケジュール効率' })">
        <span class="sc-build-kpi-label">SPI</span><strong :class="{ 'sc-build-neg': (totals.spi ?? 1) < 1 }">{{ ratio(totals.spi) }}</strong>
        <small>SV {{ signedMoney(totals.sv) }}</small>
      </div>
      <div class="sc-build-kpi" role="group" :aria-label="t({ en: 'Cost performance', ja: 'コスト効率' })">
        <span class="sc-build-kpi-label">CPI</span><strong :class="{ 'sc-build-neg': (totals.cpi ?? 1) < 1 }">{{ ratio(totals.cpi) }}</strong>
        <small>CV {{ signedMoney(totals.cv) }}</small>
      </div>
      <div class="sc-build-kpi" role="group" :aria-label="t({ en: 'Estimate at completion', ja: '完成時総コスト見積もり' })">
        <span class="sc-build-kpi-label">EAC</span><strong>{{ money(totals.eac) }}</strong>
        <small>BAC {{ money(totals.bac) }} · VAC {{ signedMoney(totals.vac ?? 0) }}</small>
      </div>
      <div class="sc-build-kpi" role="group" :aria-label="t({ en: 'Percent complete', ja: '完了率' })">
        <span class="sc-build-kpi-label">{{ t({ en: 'Complete', ja: '完了率' }) }}</span><strong>{{ Math.round(totals.ev / totals.bac * 100) }}%</strong>
        <span class="sc-build-meter" aria-hidden="true"><span :style="{ width: totals.ev / totals.bac * 100 + '%' }"></span><i :style="{ left: totals.pv / totals.bac * 100 + '%' }"></i></span>
        <small>{{ t({ en: 'planned', ja: '計画' }) }} {{ Math.round(totals.pv / totals.bac * 100) }}%</small>
      </div>
      <div class="sc-build-kpi" role="group" :aria-label="t({ en: 'Crew over-allocation', ja: '作業班の過負荷' })">
        <span class="sc-build-kpi-label">{{ t({ en: 'Over-allocation', ja: '過負荷' }) }}</span><strong :class="{ 'sc-build-neg': overCrewDays > 0 }">{{ overCrewDays }}</strong>
        <small>{{ t({ en: 'crew-days over capacity', ja: '能力超過の班・日数' }) }}</small>
      </div>
    </div>

    <GanttChart
      ref="chart" :rows="rows" :bars="bars" :dependencies="chartLinks" :range="range" :pixels-per-unit="2.05 / day"
      :tick-steps="[28 * day, 56 * day]" :snap="day" :min-duration="day" :format-time="formatTime" :header-bands="[quarters, monthBands]"
      :non-working-periods="closures" :row-height="rowHeight" :height="chartHeight" :columns="columns" show-summaries :collapsed-ids="collapsed"
      :highlighted-dependency-ids="criticalLinks" :status-date="statusDate" show-progress-line :markers="markers"
      :load-rows="loadRows" :load-segments="loadView" :load-row-height="loadRowHeight" :baseline-ids="['baseline']" :baseline-label="() => t({ en: 'Baseline', ja: 'ベースライン' })"
      :format-variance="value => `${value >= 0 ? '+' : '−'}${Math.abs(Math.round(value / day))} ${t({ en: 'd', ja: '日' })}`" :format-lag="value => `+${value / day} ${t({ en: 'd', ja: '日' })}`"
      :validate-edit="validateEdit" dependency-style="rounded" sticky-band-labels
      :labels="{
        ...labels.gantt, region: t({ en: 'Construction master schedule', ja: '建設の全体工程表' }), rows: t({ en: 'Work breakdown', ja: '作業分解' }),
        statusDate: t({ en: 'Status', ja: '基準日' }), loadRegion: t({ en: 'Crew load', ja: '作業班の負荷' }), critical: t({ en: 'Critical path', ja: 'クリティカルパス' }),
        deadline: t({ en: 'Contract completion', ja: '契約上の完成' }), late: t({ en: 'Late against contract', ja: '契約に対して遅延' }),
      }"
      @update:collapsed-ids="collapsed = $event" @edit="onEdit" @edit-rejected="onRejected"
    >
      <template #legend>
        <ul class="sc-build-legend" :aria-label="t({ en: 'Legend', ja: '凡例' })">
          <li><span class="sc-build-key sc-build-key-critical"></span>{{ t({ en: 'Critical path', ja: 'クリティカルパス' }) }}</li>
          <li><span class="sc-build-key sc-build-key-normal"></span>{{ t({ en: 'Float', ja: '余裕あり' }) }}</li>
          <li><span class="sc-build-key sc-build-key-done"></span>{{ t({ en: 'Complete', ja: '完了' }) }}</li>
          <li><span class="sc-build-key sc-build-key-baseline"></span>{{ t({ en: 'Baseline', ja: 'ベースライン' }) }}</li>
          <li><span class="sc-build-key sc-build-key-status"></span>{{ t({ en: 'Status date', ja: '基準日' }) }}</li>
          <li><span class="sc-build-key sc-build-key-over"></span>{{ t({ en: 'Over-allocated', ja: '過負荷' }) }}</li>
          <li><label><input v-model="showAllLinks" type="checkbox"> {{ t({ en: 'Show all links', ja: 'すべての依存関係を表示' }) }}</label></li>
        </ul>
      </template>
      <template #row="{ row }">
        <span class="sc-build-row" :class="`sc-build-row-${row.data.kind}`">
          <span class="sc-build-wbs">{{ row.data.wbs }}</span>
          <span v-if="row.data.kind === 'milestone'" class="sc-build-diamond" aria-hidden="true"></span>
          <span class="sc-build-name">{{ row.label }}</span>
        </span>
      </template>
      <template #cell="{ row, column, value }">
        <span class="sc-build-cell" :class="{
          'sc-build-cell-phase': row.data.kind === 'phase', 'sc-build-cell-zero': column.id === 'float' && value === '0' + t({ en: 'd', ja: '日' }),
          'sc-build-cell-late': column.id === 'variance' && String(value).startsWith('+'), 'sc-build-cell-done': value === doneText }">{{ value }}</span>
      </template>
      <template #tick="{ time }"><span class="sc-build-tick">{{ t({ en: 'Wk', ja: '週' }) }} {{ Math.round((time - range.start) / (7 * day)) + 1 }}</span></template>
      <template #bar="{ bar }">
        <span v-if="bar.start === bar.end" class="sc-build-milestone" :class="{ 'sc-build-milestone-end': bar.start > range.end - 60 * day }">{{ bar.label }} · {{ formatTime(bar.start) }}</span>
        <span v-else class="sc-build-bar"></span>
      </template>
      <template #load-row="{ row, peak }">
        <span class="sc-build-crew"><span>{{ row.label }}</span><small>{{ row.detail }} · {{ t({ en: 'peak', ja: 'ピーク' }) }} {{ peak }}</small></span>
      </template>
    </GanttChart>

    <div class="sc-build-panels">
      <figure class="sc-build-panel sc-build-curve">
        <figcaption>
          <h3>{{ t({ en: 'Earned value · S-curve', ja: 'アーンドバリュー · S カーブ' }) }}</h3>
          <ul class="sc-build-legend" :aria-label="t({ en: 'S-curve legend', ja: 'S カーブの凡例' })">
            <li><span class="sc-build-line sc-build-pv"></span>{{ t({ en: 'Planned (PV)', ja: '計画 (PV)' }) }}</li>
            <li><span class="sc-build-line sc-build-ev"></span>{{ t({ en: 'Earned (EV)', ja: '出来高 (EV)' }) }}</li>
            <li><span class="sc-build-line sc-build-ac"></span>{{ t({ en: 'Actual cost (AC)', ja: '実コスト (AC)' }) }}</li>
            <li><span class="sc-build-line sc-build-fc"></span>{{ t({ en: 'Forecast', ja: '予測' }) }}</li>
          </ul>
        </figcaption>
        <svg :viewBox="`0 0 ${curve.width} ${curve.height}`" role="img" :aria-labelledby="curveId + '-title'" :aria-describedby="curveId + '-desc'">
          <title :id="curveId + '-title'">{{ t({ en: 'Cumulative cost S-curve', ja: '累積コストの S カーブ' }) }}</title>
          <desc :id="curveId + '-desc'">{{ curveSummary }}</desc>
          <defs>
            <linearGradient :id="curveId + '-fill'" x1="0" x2="0" y1="0" y2="1">
              <stop offset="0" stop-color="#7aa7d9" stop-opacity=".28" /><stop offset="1" stop-color="#7aa7d9" stop-opacity="0" />
            </linearGradient>
          </defs>
          <g class="sc-build-grid">
            <g v-for="tick in yTicks" :key="tick">
              <line :x1="curve.left" :x2="curve.width - curve.right" :y1="cy(tick)" :y2="cy(tick)" />
              <text :x="curve.left - 8" :y="cy(tick)" text-anchor="end" dominant-baseline="middle">{{ money(tick) }}</text>
            </g>
            <text v-for="tick in xTicks" :key="tick" :x="cx(tick)" :y="curve.height - 6" text-anchor="middle">{{ t({ en: `${months[new Date(tick).getUTCMonth()]} ${String(new Date(tick).getUTCFullYear()).slice(2)}`, ja: `${String(new Date(tick).getUTCFullYear()).slice(2)}年${new Date(tick).getUTCMonth() + 1}月` }) }}</text>
          </g>
          <path :d="pvArea" :fill="`url(#${curveId}-fill)`" />
          <line class="sc-build-curve-status" :x1="cx(statusDate)" :x2="cx(statusDate)" :y1="curve.top" :y2="curve.height - curve.bottom" />
          <text class="sc-build-curve-tag" :x="cx(statusDate) + 5" :y="curve.top + 8">{{ t({ en: 'Status', ja: '基準日' }) }}</text>
          <path class="sc-build-path sc-build-pv" :d="pvLine" />
          <path class="sc-build-path sc-build-fc sc-build-fc-ev" :d="forecastEv" />
          <path class="sc-build-path sc-build-fc" :d="forecastAc" />
          <path class="sc-build-path sc-build-ac" :d="acLine" />
          <path class="sc-build-path sc-build-ev" :d="evLine" />
          <circle class="sc-build-dot sc-build-ev" :cx="cx(statusDate)" :cy="cy(totals.ev)" r="3.5" />
          <circle class="sc-build-dot sc-build-ac" :cx="cx(statusDate)" :cy="cy(totals.ac)" r="3.5" />
        </svg>
      </figure>
      <section class="sc-build-panel sc-build-milestones" :aria-label="t({ en: 'Key milestones', ja: '主要マイルストーン' })">
        <h3>{{ t({ en: 'Key milestones', ja: '主要マイルストーン' }) }}</h3>
        <table>
          <thead>
            <tr>
              <th scope="col">{{ t({ en: 'Milestone', ja: 'マイルストーン' }) }}</th><th scope="col">{{ t({ en: 'Baseline', ja: 'ベースライン' }) }}</th>
              <th scope="col">{{ t({ en: 'Forecast', ja: '予測' }) }}</th><th scope="col">{{ t({ en: 'Var', ja: '差異' }) }}</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in milestones" :key="item.id">
              <th scope="row">{{ item.label }}</th>
              <td>{{ formatTime(baselineById.get(item.id)!.start) }}</td>
              <td>{{ formatTime(byId.get(item.id)!.start) }}</td>
              <td><span class="sc-build-badge" :class="workDaysBetween(baselineById.get(item.id)!.start, byId.get(item.id)!.start) > 0 ? 'sc-build-badge-warn' : 'sc-build-badge-ok'">{{ signedDays(workDaysBetween(baselineById.get(item.id)!.start, byId.get(item.id)!.start)) }}</span></td>
            </tr>
          </tbody>
        </table>
        <h3>{{ t({ en: 'Next on the critical path', ja: 'クリティカルパス上の次の作業' }) }}</h3>
        <ol class="sc-build-ahead">
          <li v-for="task in criticalAhead" :key="task.id">
            <span>{{ labelOf(task.id) }}</span><small>{{ formatTime(task.start) }} – {{ formatTime(lastWorkDay(task)) }}</small>
          </li>
        </ol>
        <div class="sc-build-exports" role="group" :aria-label="t({ en: 'Export', ja: '書き出し' })">
          <span>{{ t({ en: 'Export', ja: '書き出し' }) }}</span>
          <button type="button" @click="exportMsProject">MS Project XML</button>
          <button type="button" @click="exportCsv">CSV</button>
          <button type="button" @click="exportSvg">SVG</button>
        </div>
      </section>
    </div>
    <p class="sc-build-status" role="status">{{ status }}</p>
  </section>
</template>

<style>
.sc-build {
  color-scheme: dark;
  --vw-surface: #131a22; --vw-surface-muted: #18212b; --vw-surface-hover: #1d2834;
  --vw-text: #e6edf3; --vw-muted: #8b9aab; --vw-border: #263343; --vw-grid: #1c2632; --vw-edge: #4b5d72;
  --vw-accent: #5fb4ff; --vw-on-solid: #fff; --vw-now: #ff7a59; --vw-marker: #f2c14e; --vw-marker-ink: #1a1405;
  --vw-non-working: rgb(255 255 255 / 4%); --vw-status: #3fd0c9; --vw-baseline: #64748b; --vw-float: #6f8296;
  --vw-critical: #ff7a3d; --vw-dependency-highlight: #ff8a4c; --vw-deadline: #f2c14e; --vw-constraint: #c58cff;
  --vw-load: #3d7fc4; --vw-load-overload: #ff4d5e; --vw-load-capacity: #b7c4d3;
  --vw-blue-solid: #3c6e9f; --vw-blue-pale: #1d3147; --vw-blue-ink: #d6e6f7; --vw-blue-line: #5a8cc0;
  --vw-amber-solid: #e8642c; --vw-amber-pale: #3a2216; --vw-amber-ink: #ffe3d4; --vw-amber-line: #ff8a4c;
  --vw-teal-solid: #2b6a5e; --vw-teal-pale: #163029; --vw-teal-ink: #cdeee6; --vw-teal-line: #3f8f80;
  padding: 26px 26px 18px;
  border: 1px solid #1f2a36;
  border-radius: 14px;
  background: radial-gradient(1200px 300px at 0 0, #17283a 0, transparent 60%), #0e141b;
  color: var(--vw-text);
  box-shadow: 0 10px 30px -12px rgb(0 0 0 / 55%);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.sc-build h2 { margin: 0 0 6px; color: #fff; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.sc-build h3 { margin: 0; color: #dfe7ef; font-size: 13px; font-weight: 650; letter-spacing: .01em; }
.sc-build-head { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.sc-build-eyebrow { margin: 0 0 4px; color: #f2c14e; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.sc-build-intro { max-width: 720px; margin: 0; color: var(--vw-muted); font-size: 13px; line-height: 1.55; }
.sc-build-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sc-build :where(.sc-build-actions, .sc-build-exports) button { height: 32px; padding: 0 14px; border: 1px solid #2d3c4e; border-radius: 8px; background: #17212c; color: #dbe5ef; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.sc-build :where(.sc-build-actions, .sc-build-exports) button:hover:not(:disabled) { border-color: #41566e; background: #1d2a38; }
.sc-build :where(.sc-build-actions, .sc-build-exports) button:focus-visible, .sc-build input:focus-visible + span { outline: 2px solid var(--vw-accent); outline-offset: 2px; }
.sc-build :where(.sc-build-actions, .sc-build-exports) button:disabled { opacity: .55; cursor: default; }
.sc-build .sc-build-primary { border-color: #2f7fd0; background: linear-gradient(#3a8ee0, #2b72bd); color: #fff; }
.sc-build .sc-build-primary:hover:not(:disabled) { border-color: #5aa6f0; background: linear-gradient(#4a9cec, #327dcb); }
.sc-build-switch { position: relative; display: inline-flex; align-items: center; gap: 9px; padding: 0 12px; height: 32px; border: 1px solid #3b2e1c; border-radius: 8px; background: #1d1810; color: #f6d9a8; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.sc-build-switch input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.sc-build-switch span { position: relative; width: 28px; height: 16px; border-radius: 8px; background: #4a3d29; transition: background .2s; }
.sc-build-switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: #f6d9a8; transition: transform .2s; }
.sc-build-switch input:checked + span { background: #e8642c; }
.sc-build-switch input:checked + span::after { transform: translateX(12px); background: #fff; }

/* KPI tiles */
.sc-build-kpis { display: grid; grid-template-columns: 1.35fr repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.sc-build-kpi { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 12px 14px; border: 1px solid #222e3b; border-radius: 10px; background: linear-gradient(#151e28, #121922); }
.sc-build-kpi-label { color: #8b9aab; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sc-build-kpi strong { color: #f3f7fb; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.sc-build-kpi small { overflow: hidden; color: #7f8fa1; font-size: 11.5px; text-overflow: ellipsis; white-space: nowrap; }
.sc-build-kpi-hero { border-color: #26405a; background: linear-gradient(135deg, #17314a, #121b25 70%); }
.sc-build-kpi-hero strong { font-size: 26px; }
.sc-build-kpi-hero.sc-build-late { border-color: #6a2630; background: linear-gradient(135deg, #3a1820, #121b25 70%); }
.sc-build-kpi .sc-build-neg { color: #ff8a6b; }
.sc-build-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.sc-build-badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sc-build-badge-ok { background: rgb(63 208 160 / 14%); color: #6fe0b8; }
.sc-build-badge-warn { background: rgb(242 193 78 / 15%); color: #f5cf6e; }
.sc-build-badge-bad { background: rgb(255 77 94 / 18%); color: #ff8f99; animation: sc-build-pop .5s ease-out; }
.sc-build-meter { position: relative; height: 6px; margin: 6px 0 2px; border-radius: 3px; background: #223040; }
.sc-build-meter span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: linear-gradient(90deg, #2bb3a3, #3fd0c9); }
.sc-build-meter i { position: absolute; top: -3px; width: 2px; height: 12px; border-radius: 1px; background: #e6edf3; }
@keyframes sc-build-pop { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }

/* Chart frame and header */
.sc-build .vw-gantt { --vw-row-label-width: 236px; font-size: 12px; }
.sc-build .vw-gantt-toolbar { min-height: 0; padding: 0 0 10px; }
.sc-build .vw-gantt-zoom { border-color: #2b394a; border-radius: 7px; background: #141c25; }
.sc-build .vw-gantt-zoom button { height: 26px; min-width: 26px; padding: 0; border: 0; border-radius: 0; background: transparent; }
.sc-build .vw-gantt-scroll { border: 1px solid #222e3b; border-radius: 10px; background: #111820; scrollbar-color: #2e3d4f transparent; }
.sc-build .vw-gantt-head, .sc-build .vw-gantt-corner { background: #141c25; }
.sc-build .vw-gantt-corner { color: #8b9aab; font-size: 11px; font-weight: 650; }
.sc-build .vw-gantt-band { border-color: #212c39; color: #b9c6d4; font-size: 11px; font-weight: 650; }
.sc-build .vw-gantt-tick { top: 13px; }
.sc-build-tick { color: #6f8195; font-size: 10.5px; font-weight: 600; }
.sc-build .vw-gantt-grid-line { background: #18212b; }
.sc-build .vw-gantt-row { border-bottom: 1px solid #17202a; }
.sc-build .vw-gantt-row:has(.sc-build-row-phase) { background: rgb(255 255 255 / 1.8%); }
.sc-build .vw-gantt-row-label { background: #121921; border-right: 1px solid #222e3b; }
.sc-build .vw-gantt-row-label:has(.sc-build-row-phase) { background: #151e28; }
.sc-build .vw-column-group > .vw-tree-row { padding-left: calc(4px + var(--vw-row-depth) * 14px); }
.sc-build .vw-row-toggle { color: #8b9aab; }
.sc-build .vw-extra-column { justify-content: flex-end; padding: 0 9px 0 4px; border-left: 1px solid #1a242f; }
.sc-build-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.sc-build-wbs { flex: none; min-width: 24px; color: #5f7186; font-size: 10.5px; font-variant-numeric: tabular-nums; }
.sc-build-name { overflow: hidden; color: #c9d4df; text-overflow: ellipsis; white-space: nowrap; }
.sc-build-row-phase .sc-build-name { color: #fff; font-weight: 650; }
.sc-build-row-phase .sc-build-wbs { color: #f2c14e; font-weight: 700; }
.sc-build-diamond { flex: none; width: 7px; height: 7px; background: #f2c14e; transform: rotate(45deg); }
.sc-build-cell { color: #9fb0c2; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sc-build-cell-phase { color: #e6edf3; font-weight: 650; }
.sc-build-cell-zero { color: #ff8a4c; font-weight: 700; }
.sc-build-cell-late { color: #f5cf6e; }
.sc-build-cell-done { color: #4fa893; }
.sc-build-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 0; padding: 4px 0 0; list-style: none; color: #9fb0c2; font-size: 11.5px; }
.sc-build-legend li, .sc-build-legend label { display: inline-flex; align-items: center; gap: 6px; }
.sc-build-key { width: 16px; height: 8px; border-radius: 2px; }
.sc-build-key-critical { background: var(--vw-amber-solid); box-shadow: 0 0 0 1px var(--vw-critical); }
.sc-build-key-normal { background: var(--vw-blue-solid); }
.sc-build-key-done { background: var(--vw-teal-solid); }
.sc-build-key-baseline { height: 3px; background: var(--vw-baseline); }
.sc-build-key-status { width: 2px; height: 12px; background: var(--vw-status); }
.sc-build-key-over { background: var(--vw-load-overload); }

/* Bars, baselines, links and markers */
.sc-build .vw-gantt-bar { border-radius: 3px; box-shadow: 0 1px 2px rgb(0 0 0 / 40%); }
.sc-build .vw-gantt-bar.vw-critical { box-shadow: 0 0 0 1px var(--vw-critical), 0 0 10px -2px rgb(255 122 61 / 55%); }
.sc-build .vw-gantt-bar.vw-is-selected { box-shadow: 0 0 0 2px #0e141b, 0 0 0 4px var(--vw-accent); }
.sc-build .vw-bar-progress { background: rgb(255 255 255 / 22%); }
.sc-build .vw-gantt-baseline { opacity: .9; }
.sc-build .vw-gantt-summary { height: 6px; top: calc(50% - 3px); border: 0; border-radius: 1px; background: #8094aa; overflow: visible; }
.sc-build .vw-gantt-summary span { background: #3fd0c9; opacity: 1; }
.sc-build .vw-gantt-summary::before, .sc-build .vw-gantt-summary::after { content: ''; position: absolute; top: 100%; border-top: 5px solid #8094aa; }
.sc-build .vw-gantt-summary::before { left: 0; border-right: 5px solid transparent; }
.sc-build .vw-gantt-summary::after { right: 0; border-left: 5px solid transparent; }
.sc-build .vw-gantt-links path { stroke: #3d4e62; stroke-width: 1.1px; }
.sc-build .vw-gantt-links path.vw-is-highlighted, .sc-build .vw-gantt-links .vw-is-highlighted path { stroke: var(--vw-dependency-highlight); stroke-width: 1.5px; }
.sc-build .vw-gantt-bar.vw-is-milestone.vw-has-slot { overflow: visible; }
.sc-build .vw-gantt-bar.vw-is-milestone.vw-has-slot::before { background: #f2c14e; }
.sc-build .vw-gantt-bar.vw-is-milestone.vw-critical.vw-has-slot::before { background: var(--vw-critical); }
.sc-build-milestone { position: absolute; left: calc(100% + 6px); top: 50%; translate: 0 -50%; color: #f3d48a; font-size: 11px; font-weight: 650; white-space: nowrap; pointer-events: none; }
.sc-build-milestone-end { right: calc(100% + 6px); left: auto; }
.sc-build .vw-gantt-status-date span, .sc-build .vw-gantt-marker span { border-radius: 0 0 4px 4px; font-size: 10px; font-weight: 700; }
.sc-build .vw-gantt-status-date span { background: var(--vw-status); color: #052523; }
.sc-build .vw-gantt-progress-line { stroke: var(--vw-status); }
.sc-build .vw-gantt-non-working { background: repeating-linear-gradient(135deg, rgb(255 255 255 / 5%) 0 2px, transparent 2px 5px); }

/* Crew load rows */
.sc-build .vw-gantt-load-row { background: #101820; border-color: #1c2632; }
.sc-build .vw-gantt-load-segment { border-right-color: #101820; }
.sc-build .vw-load-fill { border-radius: 2px 2px 0 0; background: linear-gradient(#4b8fd6, #2f6aa8); }
.sc-build .vw-load-capacity { border-top-width: 1px; opacity: .7; }
.sc-build .vw-gantt-load-segment.vw-is-idle .vw-load-capacity { opacity: .25; }
.sc-build .vw-gantt-load-segment.vw-is-overloaded .vw-load-over { box-shadow: 0 0 8px rgb(255 77 94 / 60%); }
.sc-build-crew { display: flex; flex-direction: column; line-height: 1.2; }
.sc-build-crew span { color: #c9d4df; font-weight: 600; }
.sc-build-crew small { color: #6f8195; font-size: 10.5px; }

/* Leveling and what-if transitions */
.sc-build-animating .vw-gantt-bar, .sc-build-animating .vw-gantt-float, .sc-build-animating .vw-gantt-summary {
  transition: left .75s cubic-bezier(.2, .8, .2, 1), width .75s cubic-bezier(.2, .8, .2, 1);
}
.sc-build-animating .vw-gantt-load-segment { animation: sc-build-rise .75s cubic-bezier(.2, .8, .2, 1); transform-origin: bottom; }
@keyframes sc-build-rise { from { opacity: .2; transform: scaleY(.3); } to { opacity: 1; transform: none; } }

/* Panels */
.sc-build-panels { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 12px; margin-top: 14px; }
.sc-build-panel { margin: 0; padding: 14px 16px; border: 1px solid #222e3b; border-radius: 10px; background: #121922; }
.sc-build-curve figcaption { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; margin-bottom: 6px; }
.sc-build-curve svg { display: block; width: 100%; height: auto; }
.sc-build-grid line { stroke: #1e2833; }
.sc-build-grid text, .sc-build-curve-tag { fill: #6f8195; font-size: 10px; font-variant-numeric: tabular-nums; }
.sc-build-curve-tag { fill: #3fd0c9; font-weight: 700; }
.sc-build-curve-status { stroke: #3fd0c9; stroke-dasharray: 3 3; }
.sc-build-path { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: d .6s ease; }
.sc-build-pv { stroke: #7aa7d9; }
.sc-build-ev { stroke: #3fd0c9; fill: #3fd0c9; }
.sc-build-ac { stroke: #ff8a4c; fill: #ff8a4c; }
.sc-build-path.sc-build-ev, .sc-build-path.sc-build-ac { fill: none; }
.sc-build-fc { stroke: #ff8a4c; stroke-dasharray: 4 4; stroke-width: 1.6; opacity: .8; }
.sc-build-fc-ev { stroke: #3fd0c9; }
.sc-build-dot { stroke: #121922; stroke-width: 2; }
.sc-build-line { width: 18px; border-top: 2px solid; }
.sc-build-line.sc-build-fc { border-top-style: dashed; border-color: #ff8a4c; }
.sc-build-line.sc-build-pv { border-color: #7aa7d9; }
.sc-build-line.sc-build-ev { border-color: #3fd0c9; }
.sc-build-line.sc-build-ac { border-color: #ff8a4c; }
.sc-build-milestones { display: flex; flex-direction: column; gap: 10px; }
.sc-build-milestones table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.sc-build-milestones th, .sc-build-milestones td { padding: 8px 6px; border-bottom: 1px solid #1c2632; text-align: left; white-space: nowrap; }
.sc-build-milestones thead th { color: #6f8195; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sc-build-milestones tbody th { color: #dfe7ef; font-weight: 600; white-space: normal; }
.sc-build-milestones td { color: #9fb0c2; }
.sc-build-milestones td:last-child, .sc-build-milestones th:last-child { text-align: right; }
.sc-build-ahead { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; counter-reset: ahead; }
.sc-build-ahead li { display: flex; align-items: center; gap: 8px; font-size: 12px; counter-increment: ahead; }
.sc-build-ahead li::before { content: counter(ahead); display: grid; place-items: center; flex: none; width: 18px; height: 18px; border-radius: 50%; background: rgb(255 122 61 / 16%); color: #ff9a66; font-size: 10.5px; font-weight: 700; }
.sc-build-ahead span { min-width: 0; overflow: hidden; color: #dfe7ef; text-overflow: ellipsis; white-space: nowrap; }
.sc-build-ahead small { margin-left: auto; color: #8b9aab; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sc-build-exports { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; }
.sc-build-exports > span { margin-right: 4px; color: #6f8195; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sc-build-exports button { height: 28px; padding: 0 11px; font-size: 12px; }
.sc-build-status { min-height: 18px; margin: 12px 2px 0; color: #9fb0c2; font-size: 12.5px; }

@media (max-width: 1100px) {
  .sc-build-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sc-build-panels { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .sc-build { padding: 18px 12px 14px; }
  .sc-build-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sc-build .vw-gantt { --vw-row-label-width: 170px; }
  .sc-build-milestones th, .sc-build-milestones td { padding: 8px 4px; }
  .sc-build-milestones thead th { letter-spacing: 0; white-space: normal; }
  .sc-build-milestones td { white-space: normal; }
  .sc-build-ahead li { flex-wrap: wrap; row-gap: 2px; }
  .sc-build-ahead span { flex: 1 1 0; }
  .sc-build-ahead small { flex-basis: 100%; padding-left: 26px; margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sc-build-animating .vw-gantt-bar, .sc-build-animating .vw-gantt-float, .sc-build-animating .vw-gantt-summary { transition: none; }
  .sc-build-animating .vw-gantt-load-segment, .sc-build-badge-bad { animation: none; }
}
</style>
ts
import type { ResourceAssignment, ScheduleLink, ScheduleTask } from '../../src'

// Deterministic data of the construction program showcase: a nine-storey steel-frame office tower on a weekday
// calendar with public holidays and a winter shutdown. Times are midnight UTC in epoch milliseconds; durations are
// working days and lags elapsed days. Nothing here reads the clock.

export const day = 86_400_000
/** Midnight UTC of a calendar date. */
export const on = (year: number, month: number, date: number) => Date.UTC(year, month - 1, date)

export const range = { start: on(2026, 3, 2), end: on(2027, 5, 3) }
/** The status (data) date of the progress report: Monday 14 September 2026. */
export const statusDate = on(2026, 9, 14)
/** The contractual completion date, drawn as the handover deadline. */
export const contractCompletion = on(2027, 3, 31)

/** Closed civil dates: public holidays and the winter shutdown. */
export const holidays = [
  '2026-04-03', '2026-05-25', '2026-06-19', '2026-07-03', '2026-09-07', '2026-11-26', '2026-11-27',
  '2026-12-24', '2026-12-25', '2026-12-28', '2026-12-29', '2026-12-30', '2026-12-31', '2027-01-01',
  '2027-01-18', '2027-02-15', '2027-05-31',
]

export type Phase = 'site' | 'sub' | 'super' | 'env' | 'mep' | 'fit' | 'comm'
export interface PhaseInfo { id: Phase; label: string; tone: 'teal' | 'blue' | 'violet' | 'amber' }
export const phases: PhaseInfo[] = [
  { id: 'site', label: 'Site preparation', tone: 'teal' },
  { id: 'sub', label: 'Substructure', tone: 'teal' },
  { id: 'super', label: 'Superstructure', tone: 'blue' },
  { id: 'env', label: 'Building envelope', tone: 'violet' },
  { id: 'mep', label: 'MEP services', tone: 'violet' },
  { id: 'fit', label: 'Fit-out', tone: 'blue' },
  { id: 'comm', label: 'Commissioning & handover', tone: 'amber' },
]

export interface ProgramTask {
  id: string
  phase: Phase
  label: string
  /** Working days; 0 is a milestone. */
  days: number
  /** Budget at completion in thousands of dollars. */
  budget: number
  /** Actual cost per unit of earned value: above 1 is over budget. */
  costRate?: number
  /** Requested start (Start No Earlier Than), for supplier slots and utility appointments. */
  notBefore?: number
  /** Leveling priority: lower values give way first when crews are short. */
  priority?: number
}

export const tasks: ProgramTask[] = [
  { id: 'ntp', phase: 'site', label: 'Notice to proceed', days: 0, budget: 0 },
  { id: 'mobilise', phase: 'site', label: 'Mobilise & hoarding', days: 10, budget: 420, costRate: 1.02 },
  { id: 'demolition', phase: 'site', label: 'Demolition & clearance', days: 14, budget: 680, costRate: 1.06 },
  { id: 'piling', phase: 'sub', label: 'Secant piling', days: 28, budget: 1900, costRate: 1.14 },
  { id: 'excavation', phase: 'sub', label: 'Bulk excavation', days: 22, budget: 1250, costRate: 1.09 },
  { id: 'caps', phase: 'sub', label: 'Pile caps & ground beams', days: 16, budget: 980, costRate: 1.05 },
  { id: 'slab', phase: 'sub', label: 'Basement slab & walls', days: 18, budget: 1340, costRate: 1.03 },
  { id: 'sub-done', phase: 'sub', label: 'Substructure complete', days: 0, budget: 0 },
  { id: 'core', phase: 'super', label: 'Concrete core (jump form)', days: 34, budget: 2100, costRate: 1.01 },
  { id: 'steel-1', phase: 'super', label: 'Steel package A · fab & deliver', days: 30, budget: 2600, costRate: 1, notBefore: on(2026, 6, 15) },
  { id: 'steel-2', phase: 'super', label: 'Steel package B · fab & deliver', days: 40, budget: 2900, notBefore: on(2026, 8, 3) },
  { id: 'l1', phase: 'super', label: 'Level 1 frame & deck', days: 9, budget: 520, costRate: 1.04 },
  { id: 'l2', phase: 'super', label: 'Level 2 frame & deck', days: 8, budget: 480, costRate: 1.03 },
  { id: 'l3', phase: 'super', label: 'Level 3 frame & deck', days: 8, budget: 480, costRate: 1.05 },
  { id: 'l4', phase: 'super', label: 'Level 4 frame & deck', days: 8, budget: 480, costRate: 1.02 },
  { id: 'l5', phase: 'super', label: 'Level 5 frame & deck', days: 8, budget: 480 },
  { id: 'l6', phase: 'super', label: 'Level 6 frame & deck', days: 8, budget: 480 },
  { id: 'l7', phase: 'super', label: 'Level 7 frame & deck', days: 8, budget: 480 },
  { id: 'l8', phase: 'super', label: 'Level 8 frame & deck', days: 8, budget: 480 },
  { id: 'roof', phase: 'super', label: 'Roof & plant deck', days: 10, budget: 640 },
  { id: 'topping', phase: 'super', label: 'Topping out', days: 0, budget: 0 },
  { id: 'facade-low', phase: 'env', label: 'Curtain wall L1–L4', days: 30, budget: 2400 },
  { id: 'facade-high', phase: 'env', label: 'Curtain wall L5–Roof', days: 30, budget: 2400 },
  { id: 'roofing', phase: 'env', label: 'Roofing & waterproofing', days: 14, budget: 560 },
  { id: 'watertight', phase: 'env', label: 'Building watertight', days: 0, budget: 0 },
  { id: 'power', phase: 'mep', label: 'Utility power connection', days: 6, budget: 310, notBefore: on(2027, 1, 11) },
  { id: 'mep-12', phase: 'mep', label: 'MEP rough-in L1–L2', days: 22, budget: 1150, costRate: 1.02 },
  { id: 'mep-34', phase: 'mep', label: 'MEP rough-in L3–L4', days: 22, budget: 1150 },
  { id: 'mep-56', phase: 'mep', label: 'MEP rough-in L5–L6', days: 22, budget: 1150 },
  { id: 'mep-78', phase: 'mep', label: 'MEP rough-in L7–L8', days: 22, budget: 1150 },
  { id: 'plant', phase: 'mep', label: 'Rooftop plant & risers', days: 24, budget: 1700 },
  { id: 'lifts', phase: 'mep', label: 'Lift installation', days: 40, budget: 1450 },
  { id: 'fit-12', phase: 'fit', label: 'Fit-out L1–L2', days: 24, budget: 1300 },
  { id: 'fit-34', phase: 'fit', label: 'Fit-out L3–L4', days: 24, budget: 1300 },
  { id: 'fit-56', phase: 'fit', label: 'Fit-out L5–L6', days: 24, budget: 1300 },
  { id: 'fit-78', phase: 'fit', label: 'Fit-out L7–L8', days: 24, budget: 1300 },
  { id: 'lobby', phase: 'fit', label: 'Lobby & public realm', days: 20, budget: 900, priority: -1 },
  { id: 'tc', phase: 'comm', label: 'Testing & commissioning', days: 18, budget: 820 },
  { id: 'fire', phase: 'comm', label: 'Fire & life-safety sign-off', days: 6, budget: 140 },
  { id: 'snag', phase: 'comm', label: 'Snagging & close-out', days: 10, budget: 260 },
  { id: 'handover', phase: 'comm', label: 'Practical completion', days: 0, budget: 0 },
]

/** The steel package whose delivery the what-if scenario delays. */
export const steelDeliveryId = 'steel-2'

const fs = (from: string, to: string, lagDays = 0): ScheduleLink =>
  ({ id: `${from}>${to}`, from, to, type: 'FS', ...(lagDays ? { lag: lagDays * day } : {}) })
const ss = (from: string, to: string, lagDays: number): ScheduleLink =>
  ({ id: `${from}>${to}`, from, to, type: 'SS', lag: lagDays * day })

export const dependencies: ScheduleLink[] = [
  fs('ntp', 'mobilise'), fs('mobilise', 'demolition'), fs('demolition', 'piling'),
  ss('piling', 'excavation', 21), fs('piling', 'caps'), fs('excavation', 'caps'), fs('caps', 'slab'), fs('slab', 'sub-done'),
  ss('slab', 'core', 14),
  fs('sub-done', 'l1'), fs('steel-1', 'l1'), ss('core', 'l1', 21),
  fs('l1', 'l2'), fs('l2', 'l3'), fs('l3', 'l4'), fs('l4', 'l5'), fs('steel-2', 'l5'),
  fs('l5', 'l6'), fs('l6', 'l7'), fs('l7', 'l8'), fs('l8', 'roof'), fs('roof', 'topping'),
  fs('l4', 'facade-low', 7), fs('facade-low', 'facade-high'), fs('l8', 'facade-high'), fs('roof', 'roofing'),
  fs('facade-high', 'watertight'), fs('roofing', 'watertight'),
  fs('l2', 'mep-12', 3), fs('l4', 'mep-34', 3), fs('l6', 'mep-56', 3), fs('l8', 'mep-78', 3),
  fs('roof', 'plant'), fs('core', 'lifts'),
  fs('mep-12', 'fit-12'), fs('facade-low', 'fit-12'), fs('mep-34', 'fit-34'), fs('facade-low', 'fit-34'),
  fs('mep-56', 'fit-56'), fs('mep-78', 'fit-78'), fs('watertight', 'fit-56'), fs('watertight', 'fit-78'),
  fs('watertight', 'lobby'),
  fs('power', 'tc'), fs('plant', 'tc'), fs('lifts', 'tc'), fs('fit-78', 'tc'), fs('fit-56', 'tc'), fs('fit-34', 'tc'), fs('fit-12', 'tc'),
  fs('tc', 'fire'), ss('tc', 'snag', 14), fs('lobby', 'snag'), fs('fire', 'handover'), fs('snag', 'handover'),
]

/** Progress reported at the status date, as a share of each task's work. Tasks not listed have not started. */
export const reportedProgress = new Map<string, number>([
  ['ntp', 1], ['mobilise', 1], ['demolition', 1], ['piling', 1], ['excavation', 1], ['caps', 1], ['slab', 1], ['sub-done', 1],
  ['core', 1], ['steel-1', 1], ['l1', 1], ['l2', 1], ['l3', 0.6], ['steel-2', 0.7], ['mep-12', 0.45], ['lifts', 0.3],
])

export type CrewId = 'civil' | 'concrete' | 'steel' | 'facade' | 'mep' | 'fitout'
export const crews: { id: CrewId; label: string; capacity: number }[] = [
  { id: 'civil', label: 'Civil & groundworks', capacity: 1 },
  { id: 'concrete', label: 'Concrete gang', capacity: 1 },
  { id: 'steel', label: 'Steel erectors', capacity: 1 },
  { id: 'facade', label: 'Facade installers', capacity: 1 },
  { id: 'mep', label: 'MEP trades', capacity: 2 },
  { id: 'fitout', label: 'Fit-out crews', capacity: 2 },
]
const crewOf: Record<string, CrewId> = {
  mobilise: 'civil', demolition: 'civil', excavation: 'civil', caps: 'concrete', slab: 'concrete',
  l1: 'steel', l2: 'steel', l3: 'steel', l4: 'steel', l5: 'steel', l6: 'steel', l7: 'steel', l8: 'steel', roof: 'steel',
  'facade-low': 'facade', 'facade-high': 'facade',
  'mep-12': 'mep', 'mep-34': 'mep', 'mep-56': 'mep', 'mep-78': 'mep', plant: 'mep',
  'fit-12': 'fitout', 'fit-34': 'fitout', 'fit-56': 'fitout', 'fit-78': 'fitout', lobby: 'fitout',
}
export const crewLabel = (id: string) => crews.find(crew => crew.id === crewOf[id])?.label
// The rooftop plant needs both MEP gangs at once.
export const assignments: ResourceAssignment[] = Object.entries(crewOf)
  .map(([taskId, resourceId]) => ({ resourceId, taskId, ...(taskId === 'plant' ? { units: 2 } : {}) }))

/** Scheduler tasks: one summary per phase and its subtasks, durations in working days. */
export function scheduleTasksOf(source: readonly ProgramTask[]): ScheduleTask[] {
  return [
    ...phases.map(phase => ({ id: phase.id, duration: 0 })),
    ...source.map(task => ({
      id: task.id, parentId: task.phase, duration: task.days * day,
      ...(task.notBefore === undefined ? {} : { startNoEarlierThan: task.notBefore }),
      ...(task.priority === undefined ? {} : { priority: task.priority }),
    })),
  ]
}

/** The baseline the owner signed off: the same logic before ground conditions slowed the piling and excavation. */
export const baselineDurations = new Map([['piling', 22], ['excavation', 18], ['steel-1', 26], ['caps', 14]])

MIT ライセンスで公開しています。