Skip to content

Commit

Permalink
Add legend left padding
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt committed May 27, 2024
1 parent bc7fb44 commit e63ee2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ const ChartLegend = (
onClick?: (category: string, color: string) => void,
enableLegendSlider?: boolean,
legendPosition?: "left" | "center" | "right",
yAxisWidth?: number,
) => {
const legendRef = React.useRef<HTMLDivElement>(null)

Expand All @@ -330,9 +331,13 @@ const ChartLegend = (

const filteredPayload = payload.filter((item: any) => item.type !== "none")

const paddingLeft =
legendPosition === "left" && yAxisWidth ? yAxisWidth - 8 : 0

return (
<div
ref={legendRef}
style={{ paddingLeft: paddingLeft }}
className={cx(
"flex items-center",
{ "justify-center": legendPosition === "center" },
Expand Down Expand Up @@ -736,6 +741,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>(
: undefined,
enableLegendSlider,
legendPosition,
yAxisWidth,
)
}
/>
Expand Down
6 changes: 6 additions & 0 deletions src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ const ChartLegend = (
onClick?: (category: string, color: string) => void,
enableLegendSlider?: boolean,
legendPosition?: "left" | "center" | "right",
yAxisWidth?: number,
) => {
const legendRef = React.useRef<HTMLDivElement>(null)

Expand All @@ -329,9 +330,13 @@ const ChartLegend = (

const filteredPayload = payload.filter((item: any) => item.type !== "none")

const paddingLeft =
legendPosition === "left" && yAxisWidth ? yAxisWidth - 8 : 0

return (
<div
ref={legendRef}
style={{ paddingLeft: paddingLeft }}
className={cx(
"flex items-center",
{ "justify-center": legendPosition === "center" },
Expand Down Expand Up @@ -726,6 +731,7 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>(
: undefined,
enableLegendSlider,
legendPosition,
yAxisWidth,
)
}
/>
Expand Down

0 comments on commit e63ee2e

Please sign in to comment.