Skip to content

Commit 891a619

Browse files
fix: <AreaChart /> Doesn't Display Gradient in Firefox Bug (#1132)
* fix: area chart linting and firefox id issue --------- Co-authored-by: severinlandolt <[email protected]>
1 parent c7df68f commit 891a619

File tree

1 file changed

+84
-80
lines changed

1 file changed

+84
-80
lines changed

src/components/chart-elements/AreaChart/AreaChart.tsx

Lines changed: 84 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
292292
/>
293293
) : null}
294294
{categories.map((category) => {
295+
const gradientId = (categoryColors.get(category) ?? BaseColors.Gray).replace("#", "");
295296
return (
296297
<defs key={category}>
297298
{showGradient ? (
@@ -302,7 +303,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
302303
colorPalette.text,
303304
).textColor
304305
}
305-
id={categoryColors.get(category)}
306+
id={gradientId}
306307
x1="0"
307308
y1="0"
308309
x2="0"
@@ -325,7 +326,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
325326
colorPalette.text,
326327
).textColor
327328
}
328-
id={categoryColors.get(category)}
329+
id={gradientId}
329330
x1="0"
330331
y1="0"
331332
x2="0"
@@ -342,68 +343,22 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
342343
</defs>
343344
);
344345
})}
345-
{categories.map((category) => (
346-
<Area
347-
className={
348-
getColorClassNames(
349-
categoryColors.get(category) ?? BaseColors.Gray,
350-
colorPalette.text,
351-
).strokeColor
352-
}
353-
strokeOpacity={activeDot || (activeLegend && activeLegend !== category) ? 0.3 : 1}
354-
activeDot={(props: any) => {
355-
const { cx, cy, stroke, strokeLinecap, strokeLinejoin, strokeWidth, dataKey } =
356-
props;
357-
return (
358-
<Dot
359-
className={tremorTwMerge(
360-
"stroke-tremor-background dark:stroke-dark-tremor-background",
361-
onValueChange ? "cursor-pointer" : "",
362-
getColorClassNames(
363-
categoryColors.get(dataKey) ?? BaseColors.Gray,
364-
colorPalette.text,
365-
).fillColor,
366-
)}
367-
cx={cx}
368-
cy={cy}
369-
r={5}
370-
fill=""
371-
stroke={stroke}
372-
strokeLinecap={strokeLinecap}
373-
strokeLinejoin={strokeLinejoin}
374-
strokeWidth={strokeWidth}
375-
onClick={(dotProps: any, event) => onDotClick(props, event)}
376-
/>
377-
);
378-
}}
379-
dot={(props: any) => {
380-
const {
381-
stroke,
382-
strokeLinecap,
383-
strokeLinejoin,
384-
strokeWidth,
385-
cx,
386-
cy,
387-
dataKey,
388-
index,
389-
} = props;
390-
391-
if (
392-
(hasOnlyOneValueForThisKey(data, category) &&
393-
!(activeDot || (activeLegend && activeLegend !== category))) ||
394-
(activeDot?.index === index && activeDot?.dataKey === category)
395-
) {
346+
{categories.map((category) => {
347+
const gradientId = (categoryColors.get(category) ?? BaseColors.Gray).replace("#", "");
348+
return (
349+
<Area
350+
className={
351+
getColorClassNames(
352+
categoryColors.get(category) ?? BaseColors.Gray,
353+
colorPalette.text,
354+
).strokeColor
355+
}
356+
strokeOpacity={activeDot || (activeLegend && activeLegend !== category) ? 0.3 : 1}
357+
activeDot={(props: any) => {
358+
const { cx, cy, stroke, strokeLinecap, strokeLinejoin, strokeWidth, dataKey } =
359+
props;
396360
return (
397361
<Dot
398-
key={index}
399-
cx={cx}
400-
cy={cy}
401-
r={5}
402-
stroke={stroke}
403-
fill=""
404-
strokeLinecap={strokeLinecap}
405-
strokeLinejoin={strokeLinejoin}
406-
strokeWidth={strokeWidth}
407362
className={tremorTwMerge(
408363
"stroke-tremor-background dark:stroke-dark-tremor-background",
409364
onValueChange ? "cursor-pointer" : "",
@@ -412,26 +367,75 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
412367
colorPalette.text,
413368
).fillColor,
414369
)}
370+
cx={cx}
371+
cy={cy}
372+
r={5}
373+
fill=""
374+
stroke={stroke}
375+
strokeLinecap={strokeLinecap}
376+
strokeLinejoin={strokeLinejoin}
377+
strokeWidth={strokeWidth}
378+
onClick={(dotProps: any, event) => onDotClick(props, event)}
415379
/>
416380
);
417-
}
418-
return <Fragment key={index}></Fragment>;
419-
}}
420-
key={category}
421-
name={category}
422-
type={curveType}
423-
dataKey={category}
424-
stroke=""
425-
fill={`url(#${categoryColors.get(category)})`}
426-
strokeWidth={2}
427-
strokeLinejoin="round"
428-
strokeLinecap="round"
429-
isAnimationActive={showAnimation}
430-
animationDuration={animationDuration}
431-
stackId={stack ? "a" : undefined}
432-
connectNulls={connectNulls}
433-
/>
434-
))}
381+
}}
382+
dot={(props: any) => {
383+
const {
384+
stroke,
385+
strokeLinecap,
386+
strokeLinejoin,
387+
strokeWidth,
388+
cx,
389+
cy,
390+
dataKey,
391+
index,
392+
} = props;
393+
394+
if (
395+
(hasOnlyOneValueForThisKey(data, category) &&
396+
!(activeDot || (activeLegend && activeLegend !== category))) ||
397+
(activeDot?.index === index && activeDot?.dataKey === category)
398+
) {
399+
return (
400+
<Dot
401+
key={index}
402+
cx={cx}
403+
cy={cy}
404+
r={5}
405+
stroke={stroke}
406+
fill=""
407+
strokeLinecap={strokeLinecap}
408+
strokeLinejoin={strokeLinejoin}
409+
strokeWidth={strokeWidth}
410+
className={tremorTwMerge(
411+
"stroke-tremor-background dark:stroke-dark-tremor-background",
412+
onValueChange ? "cursor-pointer" : "",
413+
getColorClassNames(
414+
categoryColors.get(dataKey) ?? BaseColors.Gray,
415+
colorPalette.text,
416+
).fillColor,
417+
)}
418+
/>
419+
);
420+
}
421+
return <Fragment key={index}></Fragment>;
422+
}}
423+
key={category}
424+
name={category}
425+
type={curveType}
426+
dataKey={category}
427+
stroke=""
428+
fill={`url(#${gradientId})`}
429+
strokeWidth={2}
430+
strokeLinejoin="round"
431+
strokeLinecap="round"
432+
isAnimationActive={showAnimation}
433+
animationDuration={animationDuration}
434+
stackId={stack ? "a" : undefined}
435+
connectNulls={connectNulls}
436+
/>
437+
);
438+
})}
435439
{onValueChange
436440
? categories.map((category) => (
437441
<Line

0 commit comments

Comments
 (0)