기준선과 비교하기Compare the plan with the baseline
처음 계획(기준선)을 막대 아래 얇은 막대로 겹쳐 그려 일정이 얼마나 밀렸는지 한눈에 봐요.Draw the original plan as a thin bar under each bar to see how far the schedule has slipped.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="기준선" id="show">
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
</div>
<div id="grid" style="height: 480px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('show').addEventListener('change', (event) => actions.show(api, event.target.value));import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T = [
['1', null, '웹사이트 개편', '이준호', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', '기획', '박민지', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', '요구사항 수집', '박민지', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', '경쟁 서비스 조사', '이준호', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', '범위 확정', '박민지', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', '디자인', '최하은', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', '와이어프레임', '최하은', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', '화면 디자인', '최하은', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', '아이콘 세트', '한지우', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', '디자인 검토', '최하은', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', '프런트엔드', '한지우', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', '백엔드', '김도윤', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', '검색 기능', '이준호', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', '결제 기능', '김도윤', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', '콘텐츠 입력', '박민지', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', '통합', '김도윤', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', '출시', '이준호', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', '품질 점검', '한지우', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', '출시일', '이준호', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', '인수인계', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', '운영 교육', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', '문서화', '한지우', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
// 처음 계획(기준선). 적히지 않은 작업은 기준선이 없어요.
const BASELINE = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id) => BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// 호스트(서버)가 계산한 주공정 작업 id예요. 요약 작업은 넣지 않아요.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline, critical) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// 연결을 풀고 표를 원래 자리로 돌려놔요.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
let view = null;
let gantt = null;
export function setup(api, log) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// 행을 고르면 기준선과 계획이 며칠 차이 나는지 알려 줘요 (양수 = 늦어짐).
const off = gantt.on('row-select', (e) => {
const raw = e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null)
return;
log(v === null
? { ko: `작업 ${e.taskId}: 기준선이 없어요`, en: `Task ${e.taskId}: no baseline` }
: {
ko: `작업 ${e.taskId}: 시작 ${v.startDays}일, 종료 ${v.endDays}일 차이`,
en: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
});
});
log({
ko: '막대 아래 얇은 막대가 처음 계획(기준선)이에요',
en: 'The thin bar under each bar is the baseline',
});
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// 기준선 보이기/숨기기. 기준선 날짜가 없으면 그 층은 그려지지 않아요.
show: (_api, value) => {
gantt?.setData(makeData(value !== 'off', false));
},
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>기준선과 비교하기</title>
</head>
<body>
<div class="toolbar">
<select aria-label="기준선" id="show">
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
</div>
<div id="grid" style="height: 480px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<link rel="stylesheet" href="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.css" />
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.min.js"></script>
<script>
const { baselineVariance } = MaxGridGantt;
const { createGantt, createSplitView } = MaxGridGantt;
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T = [
['1', null, '웹사이트 개편', '이준호', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', '기획', '박민지', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', '요구사항 수집', '박민지', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', '경쟁 서비스 조사', '이준호', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', '범위 확정', '박민지', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', '디자인', '최하은', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', '와이어프레임', '최하은', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', '화면 디자인', '최하은', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', '아이콘 세트', '한지우', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', '디자인 검토', '최하은', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', '프런트엔드', '한지우', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', '백엔드', '김도윤', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', '검색 기능', '이준호', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', '결제 기능', '김도윤', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', '콘텐츠 입력', '박민지', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', '통합', '김도윤', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', '출시', '이준호', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', '품질 점검', '한지우', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', '출시일', '이준호', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', '인수인계', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', '운영 교육', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', '문서화', '한지우', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
// 처음 계획(기준선). 적히지 않은 작업은 기준선이 없어요.
const BASELINE = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id) => BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// 호스트(서버)가 계산한 주공정 작업 id예요. 요약 작업은 넣지 않아요.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline, critical) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// 연결을 풀고 표를 원래 자리로 돌려놔요.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
let view = null;
let gantt = null;
function setup(api, log) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// 행을 고르면 기준선과 계획이 며칠 차이 나는지 알려 줘요 (양수 = 늦어짐).
const off = gantt.on('row-select', (e) => {
const raw = e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null)
return;
log(v === null
? { ko: `작업 ${e.taskId}: 기준선이 없어요`, en: `Task ${e.taskId}: no baseline` }
: {
ko: `작업 ${e.taskId}: 시작 ${v.startDays}일, 종료 ${v.endDays}일 차이`,
en: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
});
});
log({
ko: '막대 아래 얇은 막대가 처음 계획(기준선)이에요',
en: 'The thin bar under each bar is the baseline',
});
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
const actions = {
// 기준선 보이기/숨기기. 기준선 날짜가 없으면 그 층은 그려지지 않아요.
show: (_api, value) => {
gantt?.setData(makeData(value !== 'off', false));
},
};
options.ariaLabel = "기준선과 비교하기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('show').addEventListener('change', (event) => actions.show(api, event.target.value));
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="기준선"
disabled={!api}
onChange={(event) => api && actions.show(api, event.target.value)}
>
<option value="on">보이기</option>
<option value="off">숨기기</option>
</select>
</div>
<Grid style={{ height: 480 }} ref={gridRef} options={options} />
</>
);
}import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, '웹사이트 개편', '이준호', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', '기획', '박민지', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', '요구사항 수집', '박민지', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', '경쟁 서비스 조사', '이준호', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', '범위 확정', '박민지', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', '디자인', '최하은', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', '와이어프레임', '최하은', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', '화면 디자인', '최하은', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', '아이콘 세트', '한지우', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', '디자인 검토', '최하은', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', '프런트엔드', '한지우', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', '백엔드', '김도윤', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', '검색 기능', '이준호', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', '결제 기능', '김도윤', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', '콘텐츠 입력', '박민지', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', '통합', '김도윤', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', '출시', '이준호', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', '품질 점검', '한지우', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', '출시일', '이준호', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', '인수인계', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', '운영 교육', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', '문서화', '한지우', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
// 처음 계획(기준선). 적히지 않은 작업은 기준선이 없어요.
const BASELINE: Record<string, [string, string]> = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id: string) =>
BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// 호스트(서버)가 계산한 주공정 작업 id예요. 요약 작업은 넣지 않아요.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline: boolean, critical: boolean) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// 연결을 풀고 표를 원래 자리로 돌려놔요.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
type Gantt = ReturnType<typeof createGantt>;
let view: ReturnType<typeof mountGantt> | null = null;
let gantt: Gantt | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// 행을 고르면 기준선과 계획이 며칠 차이 나는지 알려 줘요 (양수 = 늦어짐).
const off = gantt.on('row-select', (e) => {
const raw =
e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null) return;
log(
v === null
? { ko: `작업 ${e.taskId}: 기준선이 없어요`, en: `Task ${e.taskId}: no baseline` }
: {
ko: `작업 ${e.taskId}: 시작 ${v.startDays}일, 종료 ${v.endDays}일 차이`,
en: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
},
);
});
log({
ko: '막대 아래 얇은 막대가 처음 계획(기준선)이에요',
en: 'The thin bar under each bar is the baseline',
});
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// 기준선 보이기/숨기기. 기준선 날짜가 없으면 그 층은 그려지지 않아요.
show: (_api: GridApi<Row>, value?: string) => {
gantt?.setData(makeData(value !== 'off', false));
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/vue @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="기준선"
:disabled="!api"
@change="api && actions.show(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
</div>
<Grid style="height: 480px" :options="options" @ready="onReady" />
</template>import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, '웹사이트 개편', '이준호', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', '기획', '박민지', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', '요구사항 수집', '박민지', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', '경쟁 서비스 조사', '이준호', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', '범위 확정', '박민지', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', '디자인', '최하은', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', '와이어프레임', '최하은', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', '화면 디자인', '최하은', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', '아이콘 세트', '한지우', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', '디자인 검토', '최하은', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', '프런트엔드', '한지우', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', '백엔드', '김도윤', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', '검색 기능', '이준호', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', '결제 기능', '김도윤', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', '콘텐츠 입력', '박민지', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', '통합', '김도윤', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', '출시', '이준호', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', '품질 점검', '한지우', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', '출시일', '이준호', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', '인수인계', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', '운영 교육', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', '문서화', '한지우', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
// 처음 계획(기준선). 적히지 않은 작업은 기준선이 없어요.
const BASELINE: Record<string, [string, string]> = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id: string) =>
BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// 호스트(서버)가 계산한 주공정 작업 id예요. 요약 작업은 넣지 않아요.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline: boolean, critical: boolean) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// 연결을 풀고 표를 원래 자리로 돌려놔요.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
type Gantt = ReturnType<typeof createGantt>;
let view: ReturnType<typeof mountGantt> | null = null;
let gantt: Gantt | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// 행을 고르면 기준선과 계획이 며칠 차이 나는지 알려 줘요 (양수 = 늦어짐).
const off = gantt.on('row-select', (e) => {
const raw =
e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null) return;
log(
v === null
? { ko: `작업 ${e.taskId}: 기준선이 없어요`, en: `Task ${e.taskId}: no baseline` }
: {
ko: `작업 ${e.taskId}: 시작 ${v.startDays}일, 종료 ${v.endDays}일 차이`,
en: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
},
);
});
log({
ko: '막대 아래 얇은 막대가 처음 계획(기준선)이에요',
en: 'The thin bar under each bar is the baseline',
});
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// 기준선 보이기/숨기기. 기준선 날짜가 없으면 그 층은 그려지지 않아요.
show: (_api: GridApi<Row>, value?: string) => {
gantt?.setData(makeData(value !== 'off', false));
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/angular @maxgrid/gantt @maxgrid/gantt-core로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="기준선"
[disabled]="!api"
(change)="api && actions.show(api, $any($event.target).value)"
>
<option value="on" selected>보이기</option>
<option value="off">숨기기</option>
</select>
</div>
<mx-grid style="height: 480px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE';
// [id, 부모, 작업, 담당자, 시작, 종료, 진행률, 상태]. 날짜가 비면 일정 없음, 시작=종료면 마일스톤이에요.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, '웹사이트 개편', '이준호', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', '기획', '박민지', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', '요구사항 수집', '박민지', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', '경쟁 서비스 조사', '이준호', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', '범위 확정', '박민지', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', '디자인', '최하은', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', '와이어프레임', '최하은', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', '화면 디자인', '최하은', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', '아이콘 세트', '한지우', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', '디자인 검토', '최하은', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', '개발', '김도윤', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', '프런트엔드', '한지우', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', '백엔드', '김도윤', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', '검색 기능', '이준호', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', '결제 기능', '김도윤', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', '콘텐츠 입력', '박민지', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', '통합', '김도윤', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', '출시', '이준호', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', '품질 점검', '한지우', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', '출시일', '이준호', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', '인수인계', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', '운영 교육', '박민지', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', '문서화', '한지우', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [앞 작업, 뒤 작업, 종류, 지연(작업일)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// 같은 부모 안의 순서(sortNo)와 WBS 번호는 배열 순서에서 계산해요.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// 표에 넣을 평평한 행(부모 id만 알면 트리가 돼요).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// 간트 차트에 넣을 데이터. 날짜 계산은 하지 않고 받은 값을 그대로 그려요.
// 처음 계획(기준선). 적히지 않은 작업은 기준선이 없어요.
const BASELINE: Record<string, [string, string]> = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id: string) =>
BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// 호스트(서버)가 계산한 주공정 작업 id예요. 요약 작업은 넣지 않아요.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline: boolean, critical: boolean) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: '표준 달력(월-금)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: '작업', width: 220 },
{ id: 'assignee', title: '담당자', width: 110 },
{ id: 'start', title: '시작', width: 100 },
{ id: 'end', title: '종료', width: 100 },
{ id: 'progress', title: '진행률(%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// 간트와 줄을 맞추려면 행·머리글 높이를 같게 맞춰야 해요(머리글 48, 행 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// 표 옆에 간트 차트를 붙여요: 표 요소를 왼쪽 칸으로 옮기고 createSplitView로 묶어요.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'ko',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// 연결을 풀고 표를 원래 자리로 돌려놔요.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
type Gantt = ReturnType<typeof createGantt>;
let view: ReturnType<typeof mountGantt> | null = null;
let gantt: Gantt | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// 행을 고르면 기준선과 계획이 며칠 차이 나는지 알려 줘요 (양수 = 늦어짐).
const off = gantt.on('row-select', (e) => {
const raw =
e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null) return;
log(
v === null
? { ko: `작업 ${e.taskId}: 기준선이 없어요`, en: `Task ${e.taskId}: no baseline` }
: {
ko: `작업 ${e.taskId}: 시작 ${v.startDays}일, 종료 ${v.endDays}일 차이`,
en: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
},
);
});
log({
ko: '막대 아래 얇은 막대가 처음 계획(기준선)이에요',
en: 'The thin bar under each bar is the baseline',
});
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// 기준선 보이기/숨기기. 기준선 날짜가 없으면 그 층은 그려지지 않아요.
show: (_api: GridApi<Row>, value?: string) => {
gantt?.setData(makeData(value !== 'off', false));
},
}; This example needs an extra package. To run it locally, install with npm i maxgrid @maxgrid/gantt @maxgrid/gantt-core.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Baseline" id="show">
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
</div>
<div id="grid" style="height: 480px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('show').addEventListener('change', (event) => actions.show(api, event.target.value));import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
// [id, parent, task, assignee, start, end, progress, status]. No dates means unscheduled; start = end means a milestone.
const T = [
['1', null, 'Website renewal', 'Liam Carter', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', 'Planning', 'Emma Stone', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', 'Requirements', 'Emma Stone', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', 'Competitor review', 'Liam Carter', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', 'Scope sign-off', 'Emma Stone', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', 'Design', 'Noah Reed', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', 'Wireframes', 'Noah Reed', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', 'Visual design', 'Noah Reed', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', 'Icon set', 'Olivia Park', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', 'Design review', 'Noah Reed', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', 'Build', 'Ethan Cole', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', 'Front end', 'Olivia Park', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', 'Back end', 'Ethan Cole', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', 'Search feature', 'Liam Carter', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', 'Payments', 'Ethan Cole', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', 'Content entry', 'Emma Stone', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', 'Integration', 'Ethan Cole', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', 'Launch', 'Liam Carter', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', 'QA', 'Olivia Park', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', 'Go-live', 'Liam Carter', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', 'Handover', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', 'Training', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', 'Docs', 'Olivia Park', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// The order inside a parent (sortNo) and the WBS number come from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (a parent id is enough to make a tree).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the values as given and does no date math.
// The original plan (baseline). A task that is not listed has no baseline.
const BASELINE = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id) => BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// Task ids on the critical path, computed by the host. Summary tasks are not listed.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline, critical) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: 'Standard calendar (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Keep row and header heights equal to the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// Detach and put the grid back where it was.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
let view = null;
let gantt = null;
export function setup(api, log) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// Selecting a row logs how many days the plan differs from the baseline (positive = later).
const off = gantt.on('row-select', (e) => {
const raw = e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null)
return;
log(v === null
? `Task ${e.taskId}: no baseline`
: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`);
});
log('The thin bar under each bar is the baseline');
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// Show or hide the baseline. Without baseline dates the layer is not drawn at all.
show: (_api, value) => {
gantt?.setData(makeData(value !== 'off', false));
},
};This HTML also loads an extra bundle (the extra script tag above) and uses it as a global. No install is needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Compare the plan with the baseline</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Baseline" id="show">
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
</div>
<div id="grid" style="height: 480px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<link rel="stylesheet" href="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.css" />
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.gantt.min.js"></script>
<script>
const { baselineVariance } = MaxGridGantt;
const { createGantt, createSplitView } = MaxGridGantt;
// [id, parent, task, assignee, start, end, progress, status]. No dates means unscheduled; start = end means a milestone.
const T = [
['1', null, 'Website renewal', 'Liam Carter', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', 'Planning', 'Emma Stone', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', 'Requirements', 'Emma Stone', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', 'Competitor review', 'Liam Carter', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', 'Scope sign-off', 'Emma Stone', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', 'Design', 'Noah Reed', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', 'Wireframes', 'Noah Reed', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', 'Visual design', 'Noah Reed', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', 'Icon set', 'Olivia Park', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', 'Design review', 'Noah Reed', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', 'Build', 'Ethan Cole', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', 'Front end', 'Olivia Park', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', 'Back end', 'Ethan Cole', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', 'Search feature', 'Liam Carter', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', 'Payments', 'Ethan Cole', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', 'Content entry', 'Emma Stone', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', 'Integration', 'Ethan Cole', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', 'Launch', 'Liam Carter', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', 'QA', 'Olivia Park', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', 'Go-live', 'Liam Carter', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', 'Handover', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', 'Training', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', 'Docs', 'Olivia Park', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// The order inside a parent (sortNo) and the WBS number come from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map();
const wbsOf = new Map();
const sortOf = new Map();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (a parent id is enough to make a tree).
const rows = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id),
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the values as given and does no date math.
// The original plan (baseline). A task that is not listed has no baseline.
const BASELINE = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id) => BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// Task ids on the critical path, computed by the host. Summary tasks are not listed.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline, critical) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id),
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: 'Standard calendar (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
const options = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Keep row and header heights equal to the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api, ganttOptions = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// Detach and put the grid back where it was.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
let view = null;
let gantt = null;
function setup(api, log) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// Selecting a row logs how many days the plan differs from the baseline (positive = later).
const off = gantt.on('row-select', (e) => {
const raw = e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null)
return;
log(v === null
? `Task ${e.taskId}: no baseline`
: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`);
});
log('The thin bar under each bar is the baseline');
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
const actions = {
// Show or hide the baseline. Without baseline dates the layer is not drawn at all.
show: (_api, value) => {
gantt?.setData(makeData(value !== 'off', false));
},
};
options.ariaLabel = "Compare the plan with the baseline";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('show').addEventListener('change', (event) => actions.show(api, event.target.value));
</script>
</body>
</html> This example needs an extra package. To run it locally, install with npm i @maxgrid/react @maxgrid/gantt @maxgrid/gantt-core.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Baseline"
disabled={!api}
onChange={(event) => api && actions.show(api, event.target.value)}
>
<option value="on">Show</option>
<option value="off">Hide</option>
</select>
</div>
<Grid style={{ height: 480 }} ref={gridRef} options={options} />
</>
);
}import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE';
// [id, parent, task, assignee, start, end, progress, status]. No dates means unscheduled; start = end means a milestone.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, 'Website renewal', 'Liam Carter', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', 'Planning', 'Emma Stone', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', 'Requirements', 'Emma Stone', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', 'Competitor review', 'Liam Carter', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', 'Scope sign-off', 'Emma Stone', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', 'Design', 'Noah Reed', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', 'Wireframes', 'Noah Reed', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', 'Visual design', 'Noah Reed', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', 'Icon set', 'Olivia Park', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', 'Design review', 'Noah Reed', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', 'Build', 'Ethan Cole', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', 'Front end', 'Olivia Park', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', 'Back end', 'Ethan Cole', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', 'Search feature', 'Liam Carter', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', 'Payments', 'Ethan Cole', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', 'Content entry', 'Emma Stone', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', 'Integration', 'Ethan Cole', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', 'Launch', 'Liam Carter', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', 'QA', 'Olivia Park', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', 'Go-live', 'Liam Carter', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', 'Handover', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', 'Training', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', 'Docs', 'Olivia Park', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// The order inside a parent (sortNo) and the WBS number come from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (a parent id is enough to make a tree).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the values as given and does no date math.
// The original plan (baseline). A task that is not listed has no baseline.
const BASELINE: Record<string, [string, string]> = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id: string) =>
BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// Task ids on the critical path, computed by the host. Summary tasks are not listed.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline: boolean, critical: boolean) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: 'Standard calendar (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Keep row and header heights equal to the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// Detach and put the grid back where it was.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
type Gantt = ReturnType<typeof createGantt>;
let view: ReturnType<typeof mountGantt> | null = null;
let gantt: Gantt | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// Selecting a row logs how many days the plan differs from the baseline (positive = later).
const off = gantt.on('row-select', (e) => {
const raw =
e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null) return;
log(
v === null
? `Task ${e.taskId}: no baseline`
: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
);
});
log('The thin bar under each bar is the baseline');
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// Show or hide the baseline. Without baseline dates the layer is not drawn at all.
show: (_api: GridApi<Row>, value?: string) => {
gantt?.setData(makeData(value !== 'off', false));
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/vue @maxgrid/gantt @maxgrid/gantt-core.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Baseline"
:disabled="!api"
@change="api && actions.show(api, ($event.target as HTMLSelectElement).value)"
>
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
</div>
<Grid style="height: 480px" :options="options" @ready="onReady" />
</template>import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE';
// [id, parent, task, assignee, start, end, progress, status]. No dates means unscheduled; start = end means a milestone.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, 'Website renewal', 'Liam Carter', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', 'Planning', 'Emma Stone', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', 'Requirements', 'Emma Stone', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', 'Competitor review', 'Liam Carter', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', 'Scope sign-off', 'Emma Stone', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', 'Design', 'Noah Reed', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', 'Wireframes', 'Noah Reed', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', 'Visual design', 'Noah Reed', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', 'Icon set', 'Olivia Park', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', 'Design review', 'Noah Reed', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', 'Build', 'Ethan Cole', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', 'Front end', 'Olivia Park', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', 'Back end', 'Ethan Cole', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', 'Search feature', 'Liam Carter', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', 'Payments', 'Ethan Cole', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', 'Content entry', 'Emma Stone', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', 'Integration', 'Ethan Cole', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', 'Launch', 'Liam Carter', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', 'QA', 'Olivia Park', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', 'Go-live', 'Liam Carter', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', 'Handover', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', 'Training', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', 'Docs', 'Olivia Park', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// The order inside a parent (sortNo) and the WBS number come from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (a parent id is enough to make a tree).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the values as given and does no date math.
// The original plan (baseline). A task that is not listed has no baseline.
const BASELINE: Record<string, [string, string]> = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id: string) =>
BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// Task ids on the critical path, computed by the host. Summary tasks are not listed.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline: boolean, critical: boolean) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: 'Standard calendar (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Keep row and header heights equal to the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// Detach and put the grid back where it was.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
type Gantt = ReturnType<typeof createGantt>;
let view: ReturnType<typeof mountGantt> | null = null;
let gantt: Gantt | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// Selecting a row logs how many days the plan differs from the baseline (positive = later).
const off = gantt.on('row-select', (e) => {
const raw =
e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null) return;
log(
v === null
? `Task ${e.taskId}: no baseline`
: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
);
});
log('The thin bar under each bar is the baseline');
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// Show or hide the baseline. Without baseline dates the layer is not drawn at all.
show: (_api: GridApi<Row>, value?: string) => {
gantt?.setData(makeData(value !== 'off', false));
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/angular @maxgrid/gantt @maxgrid/gantt-core.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Baseline"
[disabled]="!api"
(change)="api && actions.show(api, $any($event.target).value)"
>
<option value="on" selected>Show</option>
<option value="off">Hide</option>
</select>
</div>
<mx-grid style="height: 480px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { baselineVariance } from '@maxgrid/gantt-core';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: string;
parentId: string | null;
wbs: string;
name: string;
assignee: string;
start: string;
end: string;
progress: number;
}
type Status = 'TODO' | 'IN_PROGRESS' | 'DONE';
// [id, parent, task, assignee, start, end, progress, status]. No dates means unscheduled; start = end means a milestone.
const T: Array<[string, string | null, string, string, string, string, number, Status]> = [
['1', null, 'Website renewal', 'Liam Carter', '2026-12-01', '2027-03-05', 0, 'TODO'],
['2', '1', 'Planning', 'Emma Stone', '2026-12-01', '2026-12-11', 0, 'TODO'],
['3', '2', 'Requirements', 'Emma Stone', '2026-12-01', '2026-12-08', 60, 'IN_PROGRESS'],
['4', '2', 'Competitor review', 'Liam Carter', '2026-12-03', '2026-12-10', 30, 'IN_PROGRESS'],
['5', '2', 'Scope sign-off', 'Emma Stone', '2026-12-11', '2026-12-11', 0, 'TODO'],
['6', '1', 'Design', 'Noah Reed', '2026-12-14', '2027-01-13', 0, 'TODO'],
['7', '6', 'Wireframes', 'Noah Reed', '2026-12-14', '2026-12-23', 40, 'IN_PROGRESS'],
['8', '6', 'Visual design', 'Noah Reed', '2026-12-21', '2027-01-08', 10, 'IN_PROGRESS'],
['9', '6', 'Icon set', 'Olivia Park', '2026-12-28', '2027-01-08', 0, 'TODO'],
['10', '6', 'Design review', 'Noah Reed', '2027-01-11', '2027-01-13', 0, 'TODO'],
['11', '1', 'Build', 'Ethan Cole', '2027-01-11', '2027-02-19', 0, 'TODO'],
['12', '11', 'Front end', 'Olivia Park', '2027-01-11', '2027-02-05', 0, 'TODO'],
['13', '11', 'Back end', 'Ethan Cole', '2027-01-11', '2027-02-12', 0, 'TODO'],
['14', '11', 'Search feature', 'Liam Carter', '2027-01-25', '2027-02-12', 0, 'TODO'],
['15', '11', 'Payments', 'Ethan Cole', '2027-01-25', '2027-02-19', 0, 'TODO'],
['16', '11', 'Content entry', 'Emma Stone', '2027-01-18', '2027-02-12', 0, 'TODO'],
['17', '11', 'Integration', 'Ethan Cole', '2027-02-08', '2027-02-19', 0, 'TODO'],
['18', '1', 'Launch', 'Liam Carter', '2027-02-15', '2027-03-01', 0, 'TODO'],
['19', '18', 'QA', 'Olivia Park', '2027-02-15', '2027-02-26', 0, 'TODO'],
['20', '18', 'Go-live', 'Liam Carter', '2027-03-01', '2027-03-01', 0, 'TODO'],
['21', '1', 'Handover', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['22', '21', 'Training', 'Emma Stone', '2027-02-22', '2027-03-05', 0, 'TODO'],
['23', '21', 'Docs', 'Olivia Park', '2027-02-22', '2027-03-03', 0, 'TODO'],
];
// [predecessor, successor, type, lag (working days)]
const D: Array<[string, string, 'FS' | 'SS' | 'FF' | 'SF', number]> = [
['3', '5', 'FS', 0],
['4', '5', 'FS', 0],
['5', '7', 'FS', 0],
['7', '8', 'SS', 3],
['8', '10', 'FF', 0],
['10', '12', 'FS', 0],
['10', '13', 'FS', 0],
['12', '17', 'FF', 0],
['13', '17', 'FS', 0],
['17', '19', 'FS', 0],
['19', '20', 'FS', 0],
];
// The order inside a parent (sortNo) and the WBS number come from the array order.
const parents = new Set(T.map((r) => r[1]));
const counts = new Map<string | null, number>();
const wbsOf = new Map<string, string>();
const sortOf = new Map<string, number>();
for (const [id, parent] of T) {
const n = (counts.get(parent) ?? 0) + 1;
counts.set(parent, n);
sortOf.set(id, n);
wbsOf.set(id, parent === null ? String(n) : wbsOf.get(parent) + '.' + n);
}
// Flat grid rows (a parent id is enough to make a tree).
const rows: Row[] = T.map(([id, parentId, name, assignee, start, end, progress]) => ({
id,
parentId,
wbs: wbsOf.get(id) as string,
name,
assignee,
start,
end,
progress,
}));
// Data for the Gantt chart. It draws the values as given and does no date math.
// The original plan (baseline). A task that is not listed has no baseline.
const BASELINE: Record<string, [string, string]> = {
'3': ['2026-12-01', '2026-12-04'],
'4': ['2026-12-03', '2026-12-09'],
'5': ['2026-12-08', '2026-12-08'],
'7': ['2026-12-09', '2026-12-18'],
'8': ['2026-12-14', '2026-12-31'],
'10': ['2027-01-04', '2027-01-06'],
'12': ['2027-01-04', '2027-01-29'],
'13': ['2027-01-04', '2027-02-05'],
'17': ['2027-02-01', '2027-02-12'],
'19': ['2027-02-08', '2027-02-19'],
'20': ['2027-02-22', '2027-02-22'],
};
const baselineOf = (id: string) =>
BASELINE[id] ? { baselineStart: BASELINE[id][0], baselineEnd: BASELINE[id][1] } : {};
// Task ids on the critical path, computed by the host. Summary tasks are not listed.
const CRITICAL = ['3', '5', '7', '8', '10', '13', '17', '19', '20'];
function makeData(withBaseline: boolean, critical: boolean) {
return {
tasks: T.map(([id, parentId, name, assignee, start, end, progressPct, status]) => ({
id,
parentId,
sortNo: sortOf.get(id) as number,
name,
status,
plannedStart: start || null,
plannedEnd: end || null,
progressPct,
isMilestone: start !== '' && start === end,
hasChildren: parents.has(id),
calendarId: null,
wbsCode: wbsOf.get(id),
assigneeName: assignee,
version: 1,
...(withBaseline ? baselineOf(id) : {}),
})),
dependencies: D.map(([predecessorId, successorId, depType, lagDays], n) => ({
id: 'd' + (n + 1),
predecessorId,
successorId,
depType,
lagDays,
})),
...(critical ? { criticalIds: CRITICAL } : {}),
calendars: [
{
id: 'std',
name: 'Standard calendar (Mon-Fri)',
workDays: 31,
isDefault: true,
exceptions: [],
},
],
};
}
export const options: GridOptions<Row> = {
columns: [
{ id: 'wbs', title: 'WBS', width: 70 },
{ id: 'name', title: 'Task', width: 220 },
{ id: 'assignee', title: 'Assignee', width: 110 },
{ id: 'start', title: 'Start', width: 100 },
{ id: 'end', title: 'End', width: 100 },
{ id: 'progress', title: 'Progress (%)', kind: 'number', width: 90, align: 'end' },
],
rows,
rowKey: 'id',
// Keep row and header heights equal to the chart so the lines line up (header 48, row 32).
rowHeight: 32,
headerHeight: 48,
verticalScroll: 'external',
selection: 'single',
tree: { parentKey: 'parentId', column: 'name', expandDepth: 'all' },
};
// Put the Gantt chart next to the grid: move the grid element into the left pane and join both with createSplitView.
function mountGantt(api: GridApi<Row>, ganttOptions: Parameters<typeof createGantt>[1] = {}) {
const gridEl = api.getGridElement();
const host = gridEl.parentElement as HTMLElement;
const box = document.createElement('div');
const left = document.createElement('div');
const right = document.createElement('div');
box.style.cssText = 'position: relative; width: 100%; height: 100%;';
box.append(left, right);
host.append(box);
left.append(gridEl);
const split = createSplitView({
left,
right,
container: box,
initial: 0.45,
min: box.clientWidth < 600 ? 110 : 240,
});
const gantt = createGantt(right, {
rowHeight: 32,
locale: 'en',
verticalScroll: 'external',
...ganttOptions,
});
return {
gantt,
destroy() {
// Detach and put the grid back where it was.
gantt.destroy();
split.destroy();
host.append(gridEl);
box.remove();
},
};
}
type Gantt = ReturnType<typeof createGantt>;
let view: ReturnType<typeof mountGantt> | null = null;
let gantt: Gantt | null = null;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
view = mountGantt(api, {});
gantt = view.gantt;
gantt.setData(makeData(true, false));
const unlink = gantt.attachGrid(api);
// Selecting a row logs how many days the plan differs from the baseline (positive = later).
const off = gantt.on('row-select', (e) => {
const raw =
e.taskId === null ? undefined : makeData(true, false).tasks.find((t) => t.id === e.taskId);
const v = raw ? baselineVariance(raw) : null;
if (e.taskId === null) return;
log(
v === null
? `Task ${e.taskId}: no baseline`
: `Task ${e.taskId}: start ${v.startDays} d, end ${v.endDays} d from baseline`,
);
});
log('The thin bar under each bar is the baseline');
return () => {
off();
unlink();
view?.destroy();
view = null;
gantt = null;
};
}
export const actions = {
// Show or hide the baseline. Without baseline dates the layer is not drawn at all.
show: (_api: GridApi<Row>, value?: string) => {
gantt?.setData(makeData(value !== 'off', false));
},
};