Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt, Versetzung, Befoerderung, Karenz, On- und Offboarding, Berichte, Massenimport und ein lueckenloser Nachweis jeder Aenderung. Next.js 16 mit React 19 und TypeScript, PostgreSQL 17 ueber Kysely, Anmeldung ueber Microsoft Entra ID. Die Fachlogik liegt in der Datenbank: rund dreissig PL/pgSQL-Funktionen fuehren eine Aenderung, ihren Historieneintrag und ihren Protokolleintrag in einer Transaktion aus. Die Zugriffsschranke ist Row Level Security, nicht die Oberflaeche. Betrieb auf Windows Server ohne Docker: ein fertiges Paket, ein Windows-Dienst, der IIS als HTTPS-Vorschaltung und zwei geplante Aufgaben. Siehe deploy/windows/README.md.
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import dagre from "@dagrejs/dagre";
|
|
import type { ChartNode, ChartNodeKind } from "./types";
|
|
|
|
// Must match what OrgChartNode actually renders: Dagre reserves exactly this
|
|
// much space per node, so a box that grows past it overlaps its neighbour.
|
|
export const NODE_DIMENSIONS: Record<ChartNodeKind, { width: number; height: number }> = {
|
|
person: { width: 268, height: 80 },
|
|
role: { width: 268, height: 80 },
|
|
group: { width: 244, height: 62 },
|
|
vacancy: { width: 244, height: 62 },
|
|
};
|
|
|
|
export type VisibleEdge = { id: string; source: string; target: string };
|
|
|
|
// Collapsing a node means excluding its descendants here, not CSS-hiding a
|
|
// layout computed for the full tree — Dagre only ever lays out what's
|
|
// actually visible, which is what keeps this usable at ~800 employees.
|
|
export function collectVisible(tree: ChartNode[], isExpanded: (id: string) => boolean): { visibleNodes: ChartNode[]; visibleEdges: VisibleEdge[] } {
|
|
const visibleNodes: ChartNode[] = [];
|
|
const visibleEdges: VisibleEdge[] = [];
|
|
|
|
function walk(n: ChartNode) {
|
|
visibleNodes.push(n);
|
|
if (n.children.length > 0 && isExpanded(n.id)) {
|
|
for (const c of n.children) {
|
|
visibleEdges.push({ id: `${n.id}->${c.id}`, source: n.id, target: c.id });
|
|
walk(c);
|
|
}
|
|
}
|
|
}
|
|
for (const root of tree) walk(root);
|
|
|
|
return { visibleNodes, visibleEdges };
|
|
}
|
|
|
|
// Dagre returns center points; React Flow positions nodes by their top-left
|
|
// corner, hence the width/height/2 offset below.
|
|
export function layoutWithDagre(visibleNodes: ChartNode[], visibleEdges: VisibleEdge[]): Map<string, { x: number; y: number }> {
|
|
const g = new dagre.graphlib.Graph();
|
|
// ranksep leaves room for the expand button that overhangs each node's
|
|
// bottom edge; nodesep keeps sibling cards from visually merging.
|
|
g.setGraph({ rankdir: "TB", nodesep: 40, ranksep: 88 });
|
|
g.setDefaultEdgeLabel(() => ({}));
|
|
|
|
for (const n of visibleNodes) {
|
|
const { width, height } = NODE_DIMENSIONS[n.kind];
|
|
g.setNode(n.id, { width, height });
|
|
}
|
|
for (const e of visibleEdges) g.setEdge(e.source, e.target);
|
|
|
|
dagre.layout(g);
|
|
|
|
const positions = new Map<string, { x: number; y: number }>();
|
|
for (const n of visibleNodes) {
|
|
const { width, height } = NODE_DIMENSIONS[n.kind];
|
|
const { x, y } = g.node(n.id);
|
|
positions.set(n.id, { x: x - width / 2, y: y - height / 2 });
|
|
}
|
|
return positions;
|
|
}
|