FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Charts: provide an accessible title and description by dlabrecq · Pull Request #2500 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (7) .scss  (2) .snap  (9) .tsx  (6) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • Chart.tsx
        • Chart.test.tsx.snap
      • ChartArea.md
        • ChartBar.test.tsx.snap
        • ChartBar.md
        • chart-bar.scss
      • ChartDonut.tsx
        • ChartDonut.md
      • ChartGroup.tsx
        • ChartLine.md
        • chart-line.scss
      • ChartPie.tsx
        • ChartPie.test.tsx.snap
        • ChartPie.md
        • ChartStack.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
VictoryStyleInterface,
VictoryZoomContainer,
} from 'victory';
import { ChartContainer } from '../ChartContainer';
import {
ChartLegend,
ChartLegendOrientation,
Expand Down Expand Up @@ -49,6 +50,20 @@ export interface ChartProps extends VictoryChartProps {
* {duration: 500, onExit: () => {}, onEnter: {duration: 500, before: () => ({y: 0})})}
*/
animate?: AnimatePropTypeInterface;
/**
* The ariaDesc prop specifies the description of the chart/SVG to assist with
* accessibility for screen readers.
*
* Note: Overridden by the desc prop of containerComponent
*/
ariaDesc?: string;
/**
* The ariaTitle prop specifies the title to be applied to the SVG to assist
* accessibility for screen readers.
*
* Note: Overridden by the title prop of containerComponent
*/
ariaTitle?: string;
/**
* The children to render with the chart
*/
Expand Down Expand Up @@ -338,8 +353,11 @@ export interface ChartProps extends VictoryChartProps {

export const Chart: React.FunctionComponent<ChartProps> = ({
allowZoom = false,
ariaDesc,
ariaTitle,
children,
containerComponent = allowZoom ? <VictoryZoomContainer /> : undefined,
containerComponent = allowZoom ? <VictoryZoomContainer /> : <ChartContainer />,
legendComponent = <ChartLegend />,
legendData,
legendPosition = ChartCommonStyles.legend.position as ChartLegendPosition,
padding,
Expand All @@ -350,7 +368,6 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
// destructure last
theme = getTheme(themeColor, themeVariant),
legendOrientation = theme.legend.orientation as ChartLegendOrientation,
legendComponent = <ChartLegend data={legendData} orientation={legendOrientation} theme={theme} />,
height = theme.chart.height,
width = theme.chart.width,
...rest
Expand All @@ -368,19 +385,23 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
width: Math.abs(width - (defaultPadding.left + defaultPadding.right))
};

const getLegendComponent = () => {
const legendProps = legendComponent.props ? legendComponent.props : {};
return React.cloneElement(legendComponent as React.ReactElement<any>, {
data: legendData,
orientation: legendOrientation,
theme,
...legendProps
});
};
const container = React.cloneElement(containerComponent as React.ReactElement<any>, {
desc: ariaDesc,
title: ariaTitle,
theme,
...containerComponent.props
});

const legend = React.cloneElement(legendComponent as React.ReactElement<any>, {
data: legendData,
orientation: legendOrientation,
theme,
...legendComponent.props
});

// Returns a legend
const getLegend = () => {
if (!legendComponent.props.data) {
// Returns a wrapped legend
const getWrappedLegend = () => {
if (!legend.props.data) {
return null;
}
let dx = 0;
Expand All @@ -406,22 +427,22 @@ export const Chart: React.FunctionComponent<ChartProps> = ({
svgWidth={width}
theme={theme}
>
{getLegendComponent()}
{legend}
</ChartLegendWrapper>
);
};

return (
<VictoryChart
containerComponent={containerComponent}
containerComponent={container}
height={height}
padding={defaultPadding}
theme={theme}
width={width}
{...rest}
>
{children}
{getLegend()}
{getWrappedLegend()}
</VictoryChart>
);
};
Expand Down
Loading

Back | FazBrowse Home | New Git URL