Skip to content

feat(charts): allow rechart's accessibilityLayer prop #6459

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

Merged
merged 1 commit into from
Oct 8, 2024
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
1 change: 1 addition & 0 deletions packages/charts/src/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* @param measure {IChartMeasure} Current measure object
* @param dataElement {object} Current data element
*/
highlightColor?: (value: number, measure: MeasureConfig, dataElement: Record<string, any>) => CSSProperties['color'];

Check warning on line 79 in packages/charts/src/components/BarChart/BarChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}

interface DimensionConfig extends IChartDimension {
Expand Down Expand Up @@ -186,7 +186,7 @@
? dataKeys.findIndex((key) => key === chartConfig.secondYAxis?.dataKey)
: 0;

const [componentRef, chartRef] = useSyncRef<any>(ref);

Check warning on line 189 in packages/charts/src/components/BarChart/BarChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

const onItemLegendClick = useLegendItemClick(onLegendClick);
const labelFormatter = useLabelFormatter(primaryDimension);
Expand Down Expand Up @@ -246,6 +246,7 @@
layout="vertical"
data={dataset}
barGap={chartConfig.barGap}
accessibilityLayer={chartConfig.accessibilityLayer}
className={
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* @param measure {IChartMeasure} Current measure object
* @param dataElement {object} Current data element
*/
highlightColor?: (value: number, measure: MeasureConfig, dataElement: Record<string, any>) => CSSProperties['color'];

Check warning on line 69 in packages/charts/src/components/BulletChart/BulletChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}

interface DimensionConfig extends IChartDimension {
Expand Down Expand Up @@ -146,7 +146,7 @@
...rest
} = props;

const [componentRef, chartRef] = useSyncRef<any>(ref);

Check warning on line 149 in packages/charts/src/components/BulletChart/BulletChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

const chartConfig: BulletChartProps['chartConfig'] = {
yAxisVisible: false,
Expand Down Expand Up @@ -225,7 +225,7 @@
);
} else {
onDataPointClick(
enrichEventWithDetails({} as any, {

Check warning on line 228 in packages/charts/src/components/BulletChart/BulletChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
value: eventOrIndex.value,
dataKey: eventOrIndex.dataKey,
dataIndex: eventOrIndex.index,
Expand Down Expand Up @@ -290,6 +290,7 @@
margin={marginChart}
data={dataset}
layout={layout}
accessibilityLayer={chartConfig.accessibilityLayer}
className={
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
}
Expand All @@ -302,7 +303,7 @@
{chartConfig.xAxisVisible &&
dimensions.map((dimension, index) => {
let AxisComponent;
const axisProps: any = {

Check warning on line 306 in packages/charts/src/components/BulletChart/BulletChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
dataKey: dimension.accessor,
interval: dimension?.interval ?? (isBigDataSet ? 'preserveStartEnd' : 0),
tickLine: index < 1,
Expand Down Expand Up @@ -442,7 +443,7 @@
/>
)}
{sortedMeasures?.map((element, index) => {
const chartElementProps: any = {

Check warning on line 446 in packages/charts/src/components/BulletChart/BulletChart.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
isAnimationActive: !noAnimation
};
let labelPosition = 'top';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ const ColumnChart = forwardRef<HTMLDivElement, ColumnChartProps>((props, ref) =>
margin={marginChart}
data={dataset}
barGap={chartConfig.barGap}
accessibilityLayer={chartConfig.accessibilityLayer}
className={
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ const ColumnChartWithTrend = forwardRef<HTMLDivElement, ColumnChartWithTrendProp
yAxisTicksVisible: false,
gridHorizontal: false,
yAxisLabelsVisible: false,
yAxisWidth
yAxisWidth,
accessibilityLayer: chartConfig.accessibilityLayer
}}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions packages/charts/src/components/ComposedChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ const ComposedChart = forwardRef<HTMLDivElement, ComposedChartProps>((props, ref
margin={marginChart}
data={dataset}
layout={layout}
accessibilityLayer={chartConfig.accessibilityLayer}
className={
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined
}
Expand Down
1 change: 1 addition & 0 deletions packages/charts/src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
margin={marginChart}
data={dataset}
onClick={onDataPointClickInternal}
accessibilityLayer={chartConfig.accessibilityLayer}
className={typeof onDataPointClick === 'function' ? 'has-click-handler' : undefined}
>
<CartesianGrid
Expand Down
1 change: 1 addition & 0 deletions packages/charts/src/components/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
<PieChartLib
onClick={onClickInternal}
margin={chartConfig.margin}
accessibilityLayer={chartConfig.accessibilityLayer}
className={clsx(
typeof onDataPointClick === 'function' || typeof onClick === 'function' ? 'has-click-handler' : undefined,
classNames.piechart
Expand Down
1 change: 1 addition & 0 deletions packages/charts/src/components/RadarChart/RadarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const RadarChart = forwardRef<HTMLDivElement, RadarChartProps>((props, ref) => {
onClick={onClickInternal}
data={dataset}
margin={chartConfig.margin}
accessibilityLayer={chartConfig.accessibilityLayer}
className={typeof onDataPointClick === 'function' ? 'has-click-handler' : undefined}
>
<PolarGrid gridType={chartConfig.polarGridType} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const ScatterChart = forwardRef<HTMLDivElement, ScatterChartProps>((props, ref)
<ScatterChartLib
onClick={onClickInternal}
margin={marginChart}
accessibilityLayer={chartConfig.accessibilityLayer}
className={typeof onDataPointClick === 'function' ? 'has-click-handler' : undefined}
>
<CartesianGrid
Expand Down
12 changes: 12 additions & 0 deletions packages/charts/src/interfaces/IChartBaseProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface IChartBaseProps<T = ICartesianChartConfig> extends Omit<CommonP
* - `legendPosition`: Vertical position of the legend. Can be one of the following: `"top"`,`"middle"`, `"bottom"` (`"middle"` is not supported for: ColumnChartWithTrend, DonutChart, PieChart)
* - `legendHorizontalAlign`: Alignment of the legend. Can be one of the following: `"left"`, `"center"`, `"right"`
* - `resizeDebounce`: Number that sets the amount of delay time the chart waits when resizing.
* - `accessibilityLayer`: Experimental property to improve accessibility. Not supported by all charts and configurations!
*
* Please note that depending on the chart type, the `chartConfig` prop may accept more properties.
*/
Expand All @@ -93,6 +94,17 @@ export interface IChartBaseProps<T = ICartesianChartConfig> extends Omit<CommonP
* Number that sets the amount of delay time the chart waits when resizing.
*/
resizeDebounce?: number;
/**
* __Experimental!__
*
* Apply an accessibility layer on the chart, i.a. allowing users to focus and navigate the chart via the arrow keys.
*
* __Note:__ Currently, this feature only supports categorical and horizontal charts with tooltips!
* For more details, please refer to the [Recharts documentation](https://recharts.org/en-US/storybook) under the "Accessibility" section.
*
* @experimental
*/
accessibilityLayer?: boolean;
};
/**
* Defines the configuration object for the internally used `recharts` Tooltip popover that is displayed when hovering over data points.
Expand Down
Loading