( overlay: TextOverlay, xLabels: readonly AxisLabel[], yLabels: readonly AxisLabel[], theme: AxisLabelThemeConfig )
| 47 | * Adds axis labels to a text overlay with consistent styling. |
| 48 | */ |
| 49 | export function addAxisLabelsToOverlay( |
| 50 | overlay: TextOverlay, |
| 51 | xLabels: readonly AxisLabel[], |
| 52 | yLabels: readonly AxisLabel[], |
| 53 | theme: AxisLabelThemeConfig |
| 54 | ): void { |
| 55 | // Clear existing labels |
| 56 | overlay.clear(); |
| 57 | |
| 58 | const axisNameFontSize = getAxisTitleFontSize(theme.fontSize); |
| 59 | |
| 60 | // Add X-axis labels |
| 61 | for (const label of xLabels) { |
| 62 | const span = overlay.addLabel(label.text, label.x, label.y, { |
| 63 | fontSize: label.isTitle ? axisNameFontSize : theme.fontSize, |
| 64 | color: theme.textColor, |
| 65 | anchor: label.anchor ?? 'middle', |
| 66 | rotation: label.rotation, |
| 67 | }); |
| 68 | styleAxisLabelSpan(span, label, theme); |
| 69 | } |
| 70 | |
| 71 | // Add Y-axis labels |
| 72 | for (const label of yLabels) { |
| 73 | const span = overlay.addLabel(label.text, label.x, label.y, { |
| 74 | fontSize: label.isTitle ? axisNameFontSize : theme.fontSize, |
| 75 | color: theme.textColor, |
| 76 | anchor: label.anchor ?? 'end', |
| 77 | rotation: label.rotation, |
| 78 | }); |
| 79 | styleAxisLabelSpan(span, label, theme); |
| 80 | } |
| 81 | } |
no test coverage detected