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

Function fitText

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

Source from the content-addressed store, hash-verified

24const TEXTURE_STROKE_WIDTH = 8;
25
26function fitText(
27 ctx: CanvasRenderingContext2D,
28 text: string,
29 maxWidth: number,
30): string {
31 if (ctx.measureText(text).width <= maxWidth) return text;
32
33 let lo = 0;
34 let hi = text.length;
35 while (lo < hi) {
36 const mid = Math.ceil((lo + hi) / 2);
37 const candidate = `${text.slice(0, mid)}...`;
38 if (ctx.measureText(candidate).width <= maxWidth) lo = mid;
39 else hi = mid - 1;
40 }
41
42 return `${text.slice(0, Math.max(1, lo))}...`;
43}
44
45function createLabelTexture(name: string, color: string): LabelTexture | null {
46 const canvas = document.createElement("canvas");

Callers 1

createLabelTextureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected