feat(org-chart): add core cards and fixed-layout integration

This commit is contained in:
shkim4 committed 2026-10-12 17:58:30 +09:00
1 parent d18e3c3380
commit 61c6f8d1f1
161 files changed
+13044 -1

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
import type { Employee, NormalizedOrgChartDataset, OrganizationTreeNode, OrgChartDataset } from './types.js';
/** Pure derivation for validated datasets. Multiple roots remain a forest. */
export function normalizeOrgChartDataset(data: OrgChartDataset): NormalizedOrgChartDataset {
const organizationsById = new Map(data.organizations.map(org => [org.id, org]));
const employeesByOrganization = new Map<string, Employee[]>(data.organizations.map(org => [org.id, []]));
for (const employee of data.employees) employeesByOrganization.get(employee.organizationId)?.push(employee);
const nodes = new Map<string, OrganizationTreeNode>(data.organizations.map(org => [org.id, { organization: org, children: [] }]));
const roots: OrganizationTreeNode[] = [];
for (const node of nodes.values()) {
if (node.organization.parentId === null) roots.push(node);
else nodes.get(node.organization.parentId)?.children.push(node);
}
const order = new Map((data.presentation?.organizationOrder ?? []).map((id, index) => [id, index]));
const compare = (a: OrganizationTreeNode, b: OrganizationTreeNode) => {
const aOrder = order.get(a.organization.id) ?? Infinity;
const bOrder = order.get(b.organization.id) ?? Infinity;
if (aOrder !== bOrder) return aOrder < bOrder ? -1 : 1;
const difference = a.organization.displayOrder - b.organization.displayOrder;
if (difference) return difference;
// Code-unit order is deterministic across environments and independent of locale.
return a.organization.id < b.organization.id ? -1 : a.organization.id > b.organization.id ? 1 : 0;
};
roots.sort(compare);
for (const node of nodes.values()) node.children.sort(compare);
return { roots, organizationsById, employeesByOrganization };
}