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

Function fitText

graph-ui/src/galaxy/NodeLabels.tsx:92–109  ·  view source on GitHub ↗
(
    ctx: CanvasRenderingContext2D,
    text: string,
    maxWidth: number,
)

Source from the content-addressed store, hash-verified

90const TEXTURE_STROKE_WIDTH = 8;
91
92function fitText(
93 ctx: CanvasRenderingContext2D,
94 text: string,
95 maxWidth: number,
96): string {
97 if (ctx.measureText(text).width <= maxWidth) return text;
98
99 let lo = 0;
100 let hi = text.length;
101 while (lo < hi) {
102 const mid = Math.ceil((lo + hi) / 2);
103 const candidate = `${text.slice(0, mid)}...`;
104 if (ctx.measureText(candidate).width <= maxWidth) lo = mid;
105 else hi = mid - 1;
106 }
107
108 return `${text.slice(0, Math.max(1, lo))}...`;
109}
110
111function createLabelTexture(
112 name: string,

Callers 1

createLabelTextureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected