diff --git a/src/components/chart-elements/AreaChart/AreaChart.tsx b/src/components/chart-elements/AreaChart/AreaChart.tsx index 53d166437..18c721edc 100644 --- a/src/components/chart-elements/AreaChart/AreaChart.tsx +++ b/src/components/chart-elements/AreaChart/AreaChart.tsx @@ -76,6 +76,7 @@ const AreaChart = React.forwardRef((props, ref) onValueChange, enableLegendSlider = false, customTooltip, + rotateLabelX, ...other } = props; const CustomTooltip = customTooltip; @@ -182,6 +183,9 @@ const AreaChart = React.forwardRef((props, ref) tickLine={false} axisLine={false} minTickGap={5} + angle={rotateLabelX?.angle} + dy={rotateLabelX?.verticalShift} + height={rotateLabelX?.xAxisHeight} /> ((props, ref) => noDataText, onValueChange, customTooltip, + rotateLabelX, className, enableLegendSlider = false, ...other @@ -177,6 +178,9 @@ const BarChart = React.forwardRef((props, ref) => )} tickLine={false} axisLine={false} + angle={rotateLabelX?.angle} + dy={rotateLabelX?.verticalShift} + height={rotateLabelX?.xAxisHeight} /> ) : ( ((props, ref) => tickFormatter={valueFormatter} minTickGap={5} allowDecimals={allowDecimals} + angle={rotateLabelX?.angle} + dy={rotateLabelX?.verticalShift} + height={rotateLabelX?.xAxisHeight} /> )} {layout !== "vertical" ? ( diff --git a/src/components/chart-elements/LineChart/LineChart.tsx b/src/components/chart-elements/LineChart/LineChart.tsx index 359f9c753..21f9d9faa 100644 --- a/src/components/chart-elements/LineChart/LineChart.tsx +++ b/src/components/chart-elements/LineChart/LineChart.tsx @@ -71,6 +71,7 @@ const LineChart = React.forwardRef((props, ref) onValueChange, enableLegendSlider = false, customTooltip, + rotateLabelX, ...other } = props; const CustomTooltip = customTooltip; @@ -178,6 +179,9 @@ const LineChart = React.forwardRef((props, ref) tickLine={false} axisLine={false} minTickGap={5} + angle={rotateLabelX?.angle} + dy={rotateLabelX?.verticalShift} + height={rotateLabelX?.xAxisHeight} /> void; customTooltip?: React.ComponentType; + rotateLabelX?: { + angle: number; + verticalShift: number; + xAxisHeight: number; + }; } const renderShape = (props: any, activeNode: any | undefined, activeLegend: string | undefined) => { @@ -130,6 +135,7 @@ const ScatterChart = React.forwardRef((props, noDataText, onValueChange, customTooltip, + rotateLabelX, className, enableLegendSlider = false, ...other @@ -235,6 +241,9 @@ const ScatterChart = React.forwardRef((props, minTickGap={5} domain={xAxisDomain as AxisDomain} allowDataOverflow={true} + angle={rotateLabelX?.angle} + dy={rotateLabelX?.verticalShift} + height={rotateLabelX?.xAxisHeight} /> ) : null} {y ? ( diff --git a/src/components/chart-elements/common/BaseChartProps.tsx b/src/components/chart-elements/common/BaseChartProps.tsx index 4dca0306f..b4d6ce2e0 100644 --- a/src/components/chart-elements/common/BaseChartProps.tsx +++ b/src/components/chart-elements/common/BaseChartProps.tsx @@ -35,6 +35,11 @@ interface BaseChartProps extends BaseAnimationTimingProps, React.HTMLAttributes< onValueChange?: (value: EventProps) => void; enableLegendSlider?: boolean; customTooltip?: React.ComponentType; + rotateLabelX?: { + angle: number; + verticalShift: number; + xAxisHeight: number; + }; } export default BaseChartProps; diff --git a/src/stories/chart-elements/AreaChart.stories.tsx b/src/stories/chart-elements/AreaChart.stories.tsx index fbfdb83b5..22cb71d66 100644 --- a/src/stories/chart-elements/AreaChart.stories.tsx +++ b/src/stories/chart-elements/AreaChart.stories.tsx @@ -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 }, }; diff --git a/src/stories/chart-elements/BarChart.stories.tsx b/src/stories/chart-elements/BarChart.stories.tsx index 12ae02870..3895c0c3d 100644 --- a/src/stories/chart-elements/BarChart.stories.tsx +++ b/src/stories/chart-elements/BarChart.stories.tsx @@ -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"; diff --git a/src/stories/chart-elements/LineChart.stories.tsx b/src/stories/chart-elements/LineChart.stories.tsx index e03c64bf7..98ef6753a 100644 --- a/src/stories/chart-elements/LineChart.stories.tsx +++ b/src/stories/chart-elements/LineChart.stories.tsx @@ -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"; diff --git a/src/stories/chart-elements/ScatterChart.stories.tsx b/src/stories/chart-elements/ScatterChart.stories.tsx index 0af9a4f1e..4358f805c 100644 --- a/src/stories/chart-elements/ScatterChart.stories.tsx +++ b/src/stories/chart-elements/ScatterChart.stories.tsx @@ -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";