Skip to content

Commit

Permalink
feat: x-axis padding prop
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbalonperin committed Jun 8, 2024
1 parent 3dc49f9 commit b1429ff
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/chart-elements/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
rotateLabelX,
tickGap = 5,
xAxisLabel,
xAxisPadding,
yAxisLabel,
...other
} = props;
const CustomTooltip = customTooltip;
const paddingValue = (!showXAxis && !showYAxis) || (startEndOnly && !showYAxis) ? 0 : 20;
const paddingValue =
xAxisPadding ?? ((!showXAxis && !showYAxis) || (startEndOnly && !showYAxis) ? 0 : 20);
const [legendHeight, setLegendHeight] = useState(60);
const [activeDot, setActiveDot] = useState<ActiveDot | undefined>(undefined);
const [activeLegend, setActiveLegend] = useState<string | undefined>(undefined);
Expand Down
3 changes: 2 additions & 1 deletion src/components/chart-elements/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
barCategoryGap,
tickGap = 5,
xAxisLabel,
xAxisPadding,
yAxisLabel,
className,
...other
} = props;
const CustomTooltip = customTooltip;
const paddingValue = !showXAxis && !showYAxis ? 0 : 20;
const paddingValue = xAxisPadding ?? (!showXAxis && !showYAxis ? 0 : 20);
const [legendHeight, setLegendHeight] = useState(60);
const categoryColors = constructCategoryColors(categories, colors);
const [activeBar, setActiveBar] = React.useState<any | undefined>(undefined);
Expand Down
3 changes: 2 additions & 1 deletion src/components/chart-elements/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
tickGap = 5,
xAxisLabel,
yAxisLabel,
xAxisPadding,
...other
} = props;
const CustomTooltip = customTooltip;
const paddingValue = !showXAxis && !showYAxis ? 0 : 20;
const paddingValue = xAxisPadding ?? (!showXAxis && !showYAxis ? 0 : 20);
const [legendHeight, setLegendHeight] = useState(60);
const [activeDot, setActiveDot] = useState<ActiveDot | undefined>(undefined);
const [activeLegend, setActiveLegend] = useState<string | undefined>(undefined);
Expand Down
1 change: 1 addition & 0 deletions src/components/chart-elements/common/BaseChartProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface BaseChartProps extends BaseAnimationTimingProps, React.HTMLAttributes<
};
tickGap?: number;
xAxisLabel?: string;
xAxisPadding?: number;
yAxisLabel?: string;
}

Expand Down
6 changes: 6 additions & 0 deletions src/stories/chart-elements/AreaChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const xAxisNoPadding: Story = {
args: {
xAxisPadding: 0,
},
};
6 changes: 6 additions & 0 deletions src/stories/chart-elements/BarChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const xAxisNoPadding: Story = {
args: {
xAxisPadding: 0,
},
};
6 changes: 6 additions & 0 deletions src/stories/chart-elements/LineChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,9 @@ export const AxisLabels: Story = {
yAxisLabel: "Amount (USD)",
},
};

export const xAxisNoPadding: Story = {
args: {
xAxisPadding: 0,
},
};

0 comments on commit b1429ff

Please sign in to comment.