MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / SceneLabels

Function SceneLabels

graph-ui/src/architecture/ArchitectureScene.tsx:211–266  ·  view source on GitHub ↗

* Screen-space label density changes with zoom; source positions never do. * Label boxes are measured once per model, so culling follows the CSS of the * map that shows them (the compact Overview labels are far smaller than the * service map's); the estimate only covers a label not laid out yet.

({ model, priorityId, selectedId, cull, onVisible, onFolders }: {
    model: RenderGraph; priorityId?: string; selectedId?: string; cull: boolean;
    onVisible: (ids: Set<string>) => void; onFolders: (spots: Map<string, number>) => void;
})

Source from the content-addressed store, hash-verified

209 * name takes a free corner of its platform or hides.
210 */
211function SceneLabels({ model, priorityId, selectedId, cull, onVisible, onFolders }: {
212 model: RenderGraph; priorityId?: string; selectedId?: string; cull: boolean;
213 onVisible: (ids: Set<string>) => void; onFolders: (spots: Map<string, number>) => void;
214}) {
215 const { camera, size, gl, events, invalidate } = useThree();
216 // Html labels mount where drei puts them: the event source, else the canvas parent.
217 const labelHost = (events.connected as HTMLElement | undefined) ?? gl.domElement.parentElement;
218 const previous = useRef('');
219 const previousFolders = useRef('');
220 const boxes = useRef(new Map<string, LabelBox>());
221 const folderBoxes = useRef(new Map<string, { width: number; height: number }>());
222 const attempts = useRef(0);
223 useEffect(() => { boxes.current.clear(); folderBoxes.current.clear(); attempts.current = 0; }, [model]);
224 useFrame(() => {
225 const platforms = model.platforms ?? [];
226 const unmeasured = () => model.nodes.some(node => !boxes.current.has(node.id)) || platforms.some(platform => !folderBoxes.current.has(platform.id));
227 if (unmeasured()) {
228 labelHost?.querySelectorAll<HTMLElement>('.architecture-node-label[data-node-id]').forEach(label => {
229 // A selected label carries extra rows; it is the priority label and keeps its reserve below.
230 if (!label.offsetWidth || label.classList.contains('is-selected')) return;
231 const [edgeX, edgeY] = labelEdges(getComputedStyle(label));
232 boxes.current.set(label.dataset.nodeId!, { width: label.offsetWidth, height: label.offsetHeight, edgeX, edgeY });
233 });
234 labelHost?.querySelectorAll<HTMLElement>('.architecture-folder-label[data-folder-id]').forEach(label => {
235 if (label.offsetWidth) folderBoxes.current.set(label.dataset.folderId!, { width: label.offsetWidth, height: label.offsetHeight });
236 });
237 }
238 // A measured label may overlap a neighbour by its padding, never by its text.
239 const inset = labelInset(boxes.current.values());
240 // Hotspot wells, then larger parts, claim their label space first.
241 const chips: SceneChip[] = [...model.nodes].sort((a, b) => (b.gravity ?? 0) - (a.gravity ?? 0) || b.count - a.count).map(node => {
242 const point = new Vector3(...node.position).add(new Vector3(0, dimensions(node)[1] + 7, 0)).project(camera);
243 const box = boxes.current.get(node.id);
244 return { id: node.id, x: (point.x + 1) * size.width / 2, y: (1 - point.y) * size.height / 2,
245 width: box?.width ?? Math.min(178, Math.max(78, (node.shortLabel ?? node.label).length * 7 + (node.gravityPercent === undefined ? 26 : 68))),
246 height: box?.height ?? 38, measured: Boolean(box) };
247 });
248 const names: SecondaryLabel[] = [...platforms].sort(folderPriority).map(platform => {
249 const measured = folderBoxes.current.get(platform.id);
250 const text = platform.path ? platform.path.split('/').at(-1) ?? '' : platform.label;
251 return { id: platform.id, width: measured?.width ?? Math.min(150, text.length * 6.5 + 4), height: measured?.height ?? 14,
252 spots: folderSpots(platform).map(({ local, align }) => {
253 const point = new Vector3(...platform.position).add(new Vector3(...local)).project(camera);
254 return { x: (point.x + 1) * size.width / 2, y: (1 - point.y) * size.height / 2, align };
255 }) };
256 });
257 const { visible: ids, folders: spots } = placeSceneLabels(chips, names, { priorityId, selectedId, cull, width: size.width, height: size.height, inset });
258 const key = [...ids].sort().join('|');
259 if (previous.current !== key) { previous.current = key; onVisible(ids); }
260 const folderKey = [...spots].map(([id, spot]) => `${id}:${spot}`).join('|');
261 if (previousFolders.current !== folderKey) { previousFolders.current = folderKey; onFolders(spots); }
262 // Labels mount a moment after the scene; a few extra frames pick up their real size.
263 if (unmeasured() && attempts.current++ < 8) invalidate();
264 });
265 return null;
266}
267
268function FitArchitecture({ model, planar, resetKey, controls, active }: {

Callers

nothing calls this directly

Calls 8

labelEdgesFunction · 0.90
labelInsetFunction · 0.90
placeSceneLabelsFunction · 0.90
unmeasuredFunction · 0.85
folderSpotsFunction · 0.85
invalidateFunction · 0.85
dimensionsFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected