Skip to content

Commit d6a3a8f

Browse files
authored
fix(Pie- & DonutChart): improve label and legend text contrast (#8521)
Fixes #8395
1 parent 48e636b commit d6a3a8f

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

packages/charts/src/components/PieChart/PieChart.module.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
outline: none;
55
}
66

7+
:global(.recharts-legend-item-text) {
8+
color: var(--sapTextColor) !important;
9+
}
10+
711
[data-active-legend] {
812
background: color-mix(in srgb, var(--sapSelectedColor), transparent 87%);
9-
:global(.recharts-legend-item-text) {
10-
color: var(--sapTextColor) !important;
11-
}
1213
}
1314
}

packages/charts/src/components/PieChart/index.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,15 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
154154
}
155155

156156
return (
157-
<RechartsText {...props} alignmentBaseline="middle" className="recharts-pie-label-text">
157+
<RechartsText
158+
{...props}
159+
alignmentBaseline="middle"
160+
className="recharts-pie-label-text"
161+
style={{ paintOrder: 'stroke fill' }}
162+
stroke="var(--sapTextColor)"
163+
strokeWidth={0.5}
164+
strokeLinejoin="round"
165+
>
158166
{measure.formatter(props.value)}
159167
</RechartsText>
160168
);
@@ -237,10 +245,29 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
237245
<>
238246
<path d={`M${sx},${sy}L${mx},${my}L${ex},${ey}`} stroke={fill} fill="none" />
239247
<circle cx={ex} cy={ey} r={2} fill={fill} stroke="none" />
240-
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey} textAnchor={textAnchor} fill={fill}>
248+
<text
249+
x={ex + (cos >= 0 ? 1 : -1) * 12}
250+
y={ey}
251+
textAnchor={textAnchor}
252+
fill={fill}
253+
style={{ paintOrder: 'stroke fill' }}
254+
stroke="var(--sapTextColor)"
255+
strokeWidth={0.5}
256+
strokeLinejoin="round"
257+
>
241258
{measure.formatter(value)}
242259
</text>
243-
<text x={ex + (cos >= 0 ? 1 : -1) * 12} y={ey} dy={18} textAnchor={textAnchor} fill={fill}>
260+
<text
261+
x={ex + (cos >= 0 ? 1 : -1) * 12}
262+
y={ey}
263+
dy={18}
264+
textAnchor={textAnchor}
265+
fill={fill}
266+
style={{ paintOrder: 'stroke fill' }}
267+
stroke="var(--sapTextColor)"
268+
strokeWidth={0.5}
269+
strokeLinejoin="round"
270+
>
244271
{`(${(percent * 100).toFixed(2)}%)`}
245272
</text>
246273
</>
@@ -317,7 +344,11 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
317344
activeShape={chartConfig.activeSegment != null && renderActiveShape}
318345
rootTabIndex={-1}
319346
>
320-
{centerLabel && <RechartsLabel position="center">{centerLabel}</RechartsLabel>}
347+
{centerLabel && (
348+
<RechartsLabel position="center" fill="var(--sapTextColor)">
349+
{centerLabel}
350+
</RechartsLabel>
351+
)}
321352
{dataset &&
322353
dataset.map((data, index) => (
323354
<Cell

0 commit comments

Comments
 (0)