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

feat: New prop for x-axis label rotation #775

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/components/chart-elements/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
onValueChange,
enableLegendSlider = false,
customTooltip,
rotateLabelX,
...other
} = props;
const CustomTooltip = customTooltip;
Expand Down Expand Up @@ -182,6 +183,9 @@ const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>((props, ref)
tickLine={false}
axisLine={false}
minTickGap={5}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
height={rotateLabelX?.xAxisHeight}
/>
<YAxis
width={yAxisWidth}
Expand Down
7 changes: 7 additions & 0 deletions src/components/chart-elements/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
noDataText,
onValueChange,
customTooltip,
rotateLabelX,
className,
enableLegendSlider = false,
...other
Expand Down Expand Up @@ -177,6 +178,9 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
)}
tickLine={false}
axisLine={false}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
height={rotateLabelX?.xAxisHeight}
/>
) : (
<XAxis
Expand All @@ -199,6 +203,9 @@ const BarChart = React.forwardRef<HTMLDivElement, BarChartProps>((props, ref) =>
tickFormatter={valueFormatter}
minTickGap={5}
allowDecimals={allowDecimals}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
height={rotateLabelX?.xAxisHeight}
/>
)}
{layout !== "vertical" ? (
Expand Down
4 changes: 4 additions & 0 deletions src/components/chart-elements/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
onValueChange,
enableLegendSlider = false,
customTooltip,
rotateLabelX,
...other
} = props;
const CustomTooltip = customTooltip;
Expand Down Expand Up @@ -178,6 +179,9 @@ const LineChart = React.forwardRef<HTMLDivElement, LineChartProps>((props, ref)
tickLine={false}
axisLine={false}
minTickGap={5}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
height={rotateLabelX?.xAxisHeight}
/>
<YAxis
width={yAxisWidth}
Expand Down
9 changes: 9 additions & 0 deletions src/components/chart-elements/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export interface ScatterChartProps
enableLegendSlider?: boolean;
onValueChange?: (value: EventProps) => void;
customTooltip?: React.ComponentType<CustomTooltipType>;
rotateLabelX?: {
angle: number;
verticalShift: number;
xAxisHeight: number;
};
}

const renderShape = (props: any, activeNode: any | undefined, activeLegend: string | undefined) => {
Expand Down Expand Up @@ -130,6 +135,7 @@ const ScatterChart = React.forwardRef<HTMLDivElement, ScatterChartProps>((props,
noDataText,
onValueChange,
customTooltip,
rotateLabelX,
className,
enableLegendSlider = false,
...other
Expand Down Expand Up @@ -235,6 +241,9 @@ const ScatterChart = React.forwardRef<HTMLDivElement, ScatterChartProps>((props,
minTickGap={5}
domain={xAxisDomain as AxisDomain}
allowDataOverflow={true}
angle={rotateLabelX?.angle}
dy={rotateLabelX?.verticalShift}
height={rotateLabelX?.xAxisHeight}
/>
) : null}
{y ? (
Expand Down
5 changes: 5 additions & 0 deletions src/components/chart-elements/common/BaseChartProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ interface BaseChartProps extends BaseAnimationTimingProps, React.HTMLAttributes<
onValueChange?: (value: EventProps) => void;
enableLegendSlider?: boolean;
customTooltip?: React.ComponentType<CustomTooltipType>;
rotateLabelX?: {
angle: number;
verticalShift: number;
xAxisHeight: number;
};
}

export default BaseChartProps;
7 changes: 7 additions & 0 deletions src/stories/chart-elements/AreaChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ export const MultipleZeroValues: Story = {
},
};

export const RotateXLabels: Story = {
args: {
data: longBaseChartData,
rotateLabelX: { angle: -45, verticalShift: 15, xAxisHeight: 50 },
},
};

export const WithoutLegendScroll: Story = {
args: { enableLegendSlider: false },
};
Expand Down
15 changes: 15 additions & 0 deletions src/stories/chart-elements/BarChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ export const MultipleZeroValues: Story = {
},
};

export const RotateXLabelsHorizontal: Story = {
args: {
data: longBaseChartData,
rotateLabelX: { angle: -45, verticalShift: 15, xAxisHeight: 50 },
},
};

export const RotateXLabelVertical: Story = {
args: {
data: longBaseChartData,
rotateLabelX: { angle: -45, verticalShift: 15, xAxisHeight: 50 },
layout: "vertical",
},
};

//Custom tooltips
const customTooltipColors: Color[] = ["cyan"];
const customTooltipIndex = "month";
Expand Down
7 changes: 7 additions & 0 deletions src/stories/chart-elements/LineChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ export const LongIndexNameAndPreserveStartEnd: Story = {
args: { data: longIndexBaseChartData, intervalType: "preserveStartEnd" },
};

export const RotateXLabels: Story = {
args: {
data: longBaseChartData,
rotateLabelX: { angle: -45, verticalShift: 15, xAxisHeight: 50 },
},
};

//Custom tooltips
const customTooltipColors: Color[] = ["cyan"];
const customTooltipIndex = "month";
Expand Down
6 changes: 6 additions & 0 deletions src/stories/chart-elements/ScatterChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export const MultipleZeroValues: Story = {
},
};

export const RotateXLabel: Story = {
args: {
rotateLabelX: { angle: -45, verticalShift: 15, xAxisHeight: 50 },
},
};

//Custom tooltips
const customTooltipColors: Color[] = ["red", "green", "blue", "yellow"];
const customTooltipIndex = "location";
Expand Down
Loading