Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: <AreaChart /> Doesn't Display Gradient in Firefox Bug #1132

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 84 additions & 80 deletions src/components/chart-elements/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
/>
) : null}
{categories.map((category) => {
const gradientId = (categoryColors.get(category) ?? BaseColors.Gray).replace("#", "");
return (
<defs key={category}>
{showGradient ? (
Expand All @@ -302,7 +303,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
colorPalette.text,
).textColor
}
id={categoryColors.get(category)}
id={gradientId}
x1="0"
y1="0"
x2="0"
Expand All @@ -325,7 +326,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
colorPalette.text,
).textColor
}
id={categoryColors.get(category)}
id={gradientId}
x1="0"
y1="0"
x2="0"
Expand All @@ -342,68 +343,22 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
</defs>
);
})}
{categories.map((category) => (
<Area
className={
getColorClassNames(
categoryColors.get(category) ?? BaseColors.Gray,
colorPalette.text,
).strokeColor
}
strokeOpacity={activeDot || (activeLegend && activeLegend !== category) ? 0.3 : 1}
activeDot={(props: any) => {
const { cx, cy, stroke, strokeLinecap, strokeLinejoin, strokeWidth, dataKey } =
props;
return (
<Dot
className={tremorTwMerge(
"stroke-tremor-background dark:stroke-dark-tremor-background",
onValueChange ? "cursor-pointer" : "",
getColorClassNames(
categoryColors.get(dataKey) ?? BaseColors.Gray,
colorPalette.text,
).fillColor,
)}
cx={cx}
cy={cy}
r={5}
fill=""
stroke={stroke}
strokeLinecap={strokeLinecap}
strokeLinejoin={strokeLinejoin}
strokeWidth={strokeWidth}
onClick={(dotProps: any, event) => onDotClick(props, event)}
/>
);
}}
dot={(props: any) => {
const {
stroke,
strokeLinecap,
strokeLinejoin,
strokeWidth,
cx,
cy,
dataKey,
index,
} = props;

if (
(hasOnlyOneValueForThisKey(data, category) &&
!(activeDot || (activeLegend && activeLegend !== category))) ||
(activeDot?.index === index && activeDot?.dataKey === category)
) {
{categories.map((category) => {
const gradientId = (categoryColors.get(category) ?? BaseColors.Gray).replace("#", "");
return (
<Area
className={
getColorClassNames(
categoryColors.get(category) ?? BaseColors.Gray,
colorPalette.text,
).strokeColor
}
strokeOpacity={activeDot || (activeLegend && activeLegend !== category) ? 0.3 : 1}
activeDot={(props: any) => {
const { cx, cy, stroke, strokeLinecap, strokeLinejoin, strokeWidth, dataKey } =
props;
return (
<Dot
key={index}
cx={cx}
cy={cy}
r={5}
stroke={stroke}
fill=""
strokeLinecap={strokeLinecap}
strokeLinejoin={strokeLinejoin}
strokeWidth={strokeWidth}
className={tremorTwMerge(
"stroke-tremor-background dark:stroke-dark-tremor-background",
onValueChange ? "cursor-pointer" : "",
Expand All @@ -412,26 +367,75 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
colorPalette.text,
).fillColor,
)}
cx={cx}
cy={cy}
r={5}
fill=""
stroke={stroke}
strokeLinecap={strokeLinecap}
strokeLinejoin={strokeLinejoin}
strokeWidth={strokeWidth}
onClick={(dotProps: any, event) => onDotClick(props, event)}
/>
);
}
return <Fragment key={index}></Fragment>;
}}
key={category}
name={category}
type={curveType}
dataKey={category}
stroke=""
fill={`url(#${categoryColors.get(category)})`}
strokeWidth={2}
strokeLinejoin="round"
strokeLinecap="round"
isAnimationActive={showAnimation}
animationDuration={animationDuration}
stackId={stack ? "a" : undefined}
connectNulls={connectNulls}
/>
))}
}}
dot={(props: any) => {
const {
stroke,
strokeLinecap,
strokeLinejoin,
strokeWidth,
cx,
cy,
dataKey,
index,
} = props;

if (
(hasOnlyOneValueForThisKey(data, category) &&
!(activeDot || (activeLegend && activeLegend !== category))) ||
(activeDot?.index === index && activeDot?.dataKey === category)
) {
return (
<Dot
key={index}
cx={cx}
cy={cy}
r={5}
stroke={stroke}
fill=""
strokeLinecap={strokeLinecap}
strokeLinejoin={strokeLinejoin}
strokeWidth={strokeWidth}
className={tremorTwMerge(
"stroke-tremor-background dark:stroke-dark-tremor-background",
onValueChange ? "cursor-pointer" : "",
getColorClassNames(
categoryColors.get(dataKey) ?? BaseColors.Gray,
colorPalette.text,
).fillColor,
)}
/>
);
}
return <Fragment key={index}></Fragment>;
}}
key={category}
name={category}
type={curveType}
dataKey={category}
stroke=""
fill={`url(#${gradientId})`}
strokeWidth={2}
strokeLinejoin="round"
strokeLinecap="round"
isAnimationActive={showAnimation}
animationDuration={animationDuration}
stackId={stack ? "a" : undefined}
connectNulls={connectNulls}
/>
);
})}
{onValueChange
? categories.map((category) => (
<Line
Expand Down
Loading