Skip to content

Commit b1429ff

Browse files
feat: x-axis padding prop
1 parent 3dc49f9 commit b1429ff

File tree

7 files changed

+26
-3
lines changed

7 files changed

+26
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
8080
rotateLabelX,
8181
tickGap = 5,
8282
xAxisLabel,
83+
xAxisPadding,
8384
yAxisLabel,
8485
...other
8586
} = props;
8687
const CustomTooltip = customTooltip;
87-
const paddingValue = (!showXAxis && !showYAxis) || (startEndOnly && !showYAxis) ? 0 : 20;
88+
const paddingValue =
89+
xAxisPadding ?? ((!showXAxis && !showYAxis) || (startEndOnly && !showYAxis) ? 0 : 20);
8890
const [legendHeight, setLegendHeight] = useState(60);
8991
const [activeDot, setActiveDot] = useState<ActiveDot | undefined>(undefined);
9092
const [activeLegend, setActiveLegend] = useState<string | undefined>(undefined);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
9696
barCategoryGap,
9797
tickGap = 5,
9898
xAxisLabel,
99+
xAxisPadding,
99100
yAxisLabel,
100101
className,
101102
...other
102103
} = props;
103104
const CustomTooltip = customTooltip;
104-
const paddingValue = !showXAxis && !showYAxis ? 0 : 20;
105+
const paddingValue = xAxisPadding ?? (!showXAxis && !showYAxis ? 0 : 20);
105106
const [legendHeight, setLegendHeight] = useState(60);
106107
const categoryColors = constructCategoryColors(categories, colors);
107108
const [activeBar, setActiveBar] = React.useState<any | undefined>(undefined);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
7676
tickGap = 5,
7777
xAxisLabel,
7878
yAxisLabel,
79+
xAxisPadding,
7980
...other
8081
} = props;
8182
const CustomTooltip = customTooltip;
82-
const paddingValue = !showXAxis && !showYAxis ? 0 : 20;
83+
const paddingValue = xAxisPadding ?? (!showXAxis && !showYAxis ? 0 : 20);
8384
const [legendHeight, setLegendHeight] = useState(60);
8485
const [activeDot, setActiveDot] = useState<ActiveDot | undefined>(undefined);
8586
const [activeLegend, setActiveLegend] = useState<string | undefined>(undefined);

src/components/chart-elements/common/BaseChartProps.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ interface BaseChartProps extends BaseAnimationTimingProps, React.HTMLAttributes<
4242
};
4343
tickGap?: number;
4444
xAxisLabel?: string;
45+
xAxisPadding?: number;
4546
yAxisLabel?: string;
4647
}
4748

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,9 @@ export const AxisLabels: Story = {
364364
yAxisLabel: "Amount (USD)",
365365
},
366366
};
367+
368+
export const xAxisNoPadding: Story = {
369+
args: {
370+
xAxisPadding: 0,
371+
},
372+
};

src/stories/chart-elements/BarChart.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,9 @@ export const AxisLabels: Story = {
387387
yAxisLabel: "Amount (USD)",
388388
},
389389
};
390+
391+
export const xAxisNoPadding: Story = {
392+
args: {
393+
xAxisPadding: 0,
394+
},
395+
};

src/stories/chart-elements/LineChart.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,9 @@ export const AxisLabels: Story = {
324324
yAxisLabel: "Amount (USD)",
325325
},
326326
};
327+
328+
export const xAxisNoPadding: Story = {
329+
args: {
330+
xAxisPadding: 0,
331+
},
332+
};

0 commit comments

Comments
 (0)