MCPcopy Create free account
hub / github.com/Rello/analytics / drawLabel

Function drawLabel

js/3rdParty/chartjs-plugin-annotation.min.js:92–123  ·  view source on GitHub ↗
(ctx, x1, y1, x2, y2, label)

Source from the content-addressed store, hash-verified

90 },
91
92 drawLabel(ctx, x1, y1, x2, y2, label) {
93 const content = label.content;
94 const fontSize = label.font?.size || 12;
95 const fontFamily = label.font?.family || 'Arial';
96 const color = label.color || '#333';
97 const backgroundColor = label.backgroundColor || 'rgba(255, 255, 255, 0.8)';
98 const padding = label.padding || 4;
99
100 ctx.font = `${fontSize}px ${fontFamily}`;
101 const textWidth = ctx.measureText(content).width;
102 const textHeight = fontSize;
103
104 // Position label
105 let labelX, labelY;
106 if (x1 === x2) {
107 // Vertical line
108 labelX = x1 + 5;
109 labelY = y1 + 20;
110 } else {
111 // Horizontal line
112 labelX = x1 + 5;
113 labelY = y1 - 5;
114 }
115
116 // Draw background
117 ctx.fillStyle = backgroundColor;
118 ctx.fillRect(labelX - padding, labelY - textHeight - padding, textWidth + 2 * padding, textHeight + 2 * padding);
119
120 // Draw text
121 ctx.fillStyle = color;
122 ctx.fillText(content, labelX, labelY);
123 }
124};
125
126// Register the plugin if Chart is available

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected