Skip to content

Commit a88fdab

Browse files
krisantrobusserifluousnkrantz
authored
Docs highcharts eng a11y (#4335)
* feat(docs): data viz base structure * feat(data-viz): wokring base chart * feat(data-viz): wip * feat(data-viz): wip * feat(data-viz): wip * feat(data-viz): wip * feat(data-viz): sitemap * feat(data-viz): docs exmapleds * feat(data-viz): ci checks * feat(data-viz): docs refinement * chore(cleanup): remove redundant story * chore(cleanup): changeset * fix(data-viz): fix urls * fix(data-viz): fix slugs * feat(data-vix): chart-provider in project.json * chore(data-vix): test chanpshots * chore(ci): fix supabase * chore(ci): fix supabase * chore(ci): ignore generated files for linting * chore(data-vix): typos * chore(data-vix): trigger rebuild * chore(data-vix): trigger rebuild * chore(data-vix): trigger rebuild * feat(data-visualization): add initial supported charts * feat(data-visualization): axis titles * feat(data-visualization): include area chart * feat(data-visualization): additional example * feat(data-visualization): tests * feat(data-visualization): refactor * chore(data-visualization): lci checks * feat(data-visualization): changesets * feat(data-visualization): animation boolean * feat(data-visualization): wip * feat(data-visualization): jsdoc and type cleanup * feat(data-visualization): cedits and column styles * feat(data-visualization): watermark on examples * feat(data-visualization): update chart types content * feat(data-visualization): adding typedocs * Update packages/paste-website/src/components/site-wrapper/sidebar/SidebarNavigation.tsx Co-authored-by: Sarah <sali@twilio.com> * feat(data-visualization): chart option docs * feat(data-visualization): cleanup chart options * feat(data-visualization): vrt * feat(data-visualization): pr cleanup * chore(typos): fix various typos * chore(typos): revert fix * chore(tests): add support for same title sidebar disclousres * feat(data-viz): update docs urls and release versioning * chore(data-viz): update urls * Apply suggestions from code review Co-authored-by: Sarah <sali@twilio.com> * chore(data-viz): addressed PR comments * fix(e2e): chage order of disclosure opening to account for multiple data-visualization * docs(data-viz): wip a11y * docs(data-viz): added a11y descriptions * docs(data-viz): enhanced descriptions * feat(data-viz): changeset * docs(data-viz): typos * Update packages/paste-website/src/pages/foundations/data-visualization/for-engineers/accessibility.mdx Co-authored-by: Nora Krantz <75342690+nkrantz@users.noreply.github.com> * docs(data-a11y): added external link * Apply suggestions from code review Co-authored-by: Sarah <sali@twilio.com> * docs(data-a11y): a11y fixes * docs(data-a11y): typo * Update packages/paste-website/src/pages/foundations/data-visualization/for-engineers/accessibility.mdx Co-authored-by: Sarah <sali@twilio.com> * docs(data-a11y): pr suggestion --------- Co-authored-by: Sarah <sali@twilio.com> Co-authored-by: Nora Krantz <75342690+nkrantz@users.noreply.github.com>
1 parent 098085f commit a88fdab

File tree

6 files changed

+212
-0
lines changed

6 files changed

+212
-0
lines changed

.changeset/dull-rockets-type.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@twilio-paste/core": minor
3+
"@twilio-paste/data-visualization-library": minor
4+
---
5+
6+
[Data Visualization Library] added the ability to set accessibility options

cypress/integration/sitemap-vrt/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export const SITEMAP = [
290290
"/foundations/data-visualization/",
291291
"/foundations/data-visualization/for-engineers/",
292292
"/foundations/data-visualization/for-engineers/chart-types/",
293+
"/foundations/data-visualization/for-engineers/accessibility/",
293294
"/foundations/spacing-and-layout/",
294295
"/foundations/typography/",
295296
"/inclusive-design/",

packages/paste-libraries/data-visualization/src/transformers/baseFormatter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ export const handleBaseChartOptionsFormatting = ({
1919
pointFormatter: userPointFormatter,
2020
enableCredits = false,
2121
isAnimated = true,
22+
accessibility,
2223
...rest
2324
}: BaseChartOptions): Highcharts.Options => {
2425
const context = React.useContext(ThemeContext) as ThemeShape;
2526

2627
return {
28+
accessibility: {
29+
enabled: true,
30+
...accessibility,
31+
},
2732
chart: {
2833
resetZoomButton: {
2934
theme: {

packages/paste-website/src/component-examples/data-visualization/ChartExamples.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,84 @@ const ColumnGroupedAxisExample = () => {
343343
344344
render(<ColumnGroupedAxisExample />);
345345
`.trim();
346+
347+
export const SimpleChartAccessibilityExample = `
348+
const SimpleChartAccessibilityExample = () => {
349+
const lineSeriesData = [
350+
{
351+
name: "Installation",
352+
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
353+
},
354+
{
355+
name: "Manufacturing",
356+
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
357+
},
358+
]
359+
360+
return (
361+
<ChartProvider options={{
362+
type: "line",
363+
series: lineSeriesData,
364+
title: {
365+
text: "Solar Employment Growth by Sector, 2010-2016",
366+
hide: true,
367+
},
368+
subtitle: {
369+
text: "Source: thesolarfoundation.com",
370+
hide: true,
371+
},
372+
accessibility: {
373+
description: "This is a line chart showing the solar employment growth by sector from 2010 to 2016.",
374+
point: {
375+
descriptionFormatter: function (point) {
376+
return "The point " + point.index + " has a value of " + point.y;
377+
},
378+
},
379+
series: {
380+
descriptionFormatter: function (series) {
381+
return "The series " + series.name + " has a total of " + series.points.length + " points";
382+
},
383+
},
384+
},
385+
}}>
386+
<BaseChart />
387+
</ChartProvider>
388+
);
389+
};
390+
391+
render(<SimpleChartAccessibilityExample />);
392+
`.trim();
393+
394+
export const SimpleChartAccessibilityDefaultExample = `
395+
const SimpleChartAccessibilityDefaultExample = () => {
396+
const lineSeriesData = [
397+
{
398+
name: "Installation",
399+
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175],
400+
},
401+
{
402+
name: "Manufacturing",
403+
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434],
404+
},
405+
]
406+
407+
return (
408+
<ChartProvider options={{
409+
type: "line",
410+
series: lineSeriesData,
411+
title: {
412+
text: "Solar Employment Growth by Sector, 2010-2016",
413+
hide: true,
414+
},
415+
subtitle: {
416+
text: "Source: thesolarfoundation.com",
417+
hide: true,
418+
}
419+
}}>
420+
<BaseChart />
421+
</ChartProvider>
422+
);
423+
};
424+
425+
render(<SimpleChartAccessibilityDefaultExample />);
426+
`.trim();

packages/paste-website/src/components/site-wrapper/sidebar/SidebarNavigation.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ const SiteSidebarNavigation = (): JSX.Element => {
144144
<SidebarAnchor href={`${SidebarCategoryRoutes.DATA_VISUALIZATION}/for-engineers`}>
145145
Getting started
146146
</SidebarAnchor>
147+
<SidebarAnchor href={`${SidebarCategoryRoutes.DATA_VISUALIZATION}/for-engineers/accessibility`}>
148+
Accessibility
149+
</SidebarAnchor>
147150
<SidebarAnchor href={`${SidebarCategoryRoutes.DATA_VISUALIZATION}/for-engineers/chart-types`}>
148151
Chart types
149152
</SidebarAnchor>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
export const meta = {
2+
title: "Accessibility",
3+
description: "Explanation of accessibility features provided by the Highcharts module and how to customize them.",
4+
slug: "/foundations/data-visualization/accessibility/",
5+
};
6+
7+
import Image from "next/image";
8+
import Highcharts from "highcharts";
9+
import HighchartsAccessibilityModule from "highcharts/modules/accessibility";
10+
import HighchartsReact from "highcharts-react-official";
11+
import { applyPasteHighchartsModules, usePasteHighchartsTheme } from "@twilio-paste/data-visualization-library";
12+
13+
import { Box } from "@twilio-paste/box";
14+
import { Heading } from "@twilio-paste/heading";
15+
import { Text } from "@twilio-paste/text";
16+
import { Callout, CalloutHeading, CalloutText } from "@twilio-paste/callout";
17+
import { ChartProvider } from "@twilio-paste/chart-provider";
18+
import { PageHeaderSeparator } from "@twilio-paste/page-header";
19+
import { Separator } from "@twilio-paste/separator";
20+
import { InlineCode } from "@twilio-paste/inline-code";
21+
import { Anchor} from "@twilio-paste/anchor";
22+
23+
import { SidebarCategoryRoutes } from "../../../../constants";
24+
import DefaultLayout from "../../../../layouts/DefaultLayout";
25+
import { getNavigationData } from "../../../../utils/api";
26+
import { ExamplesDataVizBaseChart as BaseChart } from "../../../../component-examples/data-visualization/BaseChart";
27+
import { SimpleChartAccessibilityExample, SimpleChartAccessibilityDefaultExample } from "../../../../component-examples/data-visualization/ChartExamples";
28+
29+
export default DefaultLayout;
30+
31+
export const getStaticProps = async () => {
32+
const navigationData = await getNavigationData();
33+
return {
34+
props: {
35+
navigationData,
36+
},
37+
};
38+
};
39+
40+
<GenericHeader name={meta.title} description={meta.description} categoryRoute={SidebarCategoryRoutes.FOUNDATIONS}>
41+
<PageHeaderSeparator>
42+
<Separator orientation="horizontal" />
43+
</PageHeaderSeparator>
44+
</GenericHeader>
45+
46+
<contentwrapper>
47+
48+
<PageAside data={mdxHeadings} />
49+
50+
<content>
51+
52+
## Introduction
53+
54+
<Box marginBottom="space60">
55+
<Callout variant="neutral">
56+
<CalloutHeading>In progress</CalloutHeading>
57+
<CalloutText>As our current data visualization offerings are in progress, these guidelines may change. We will update these pages when new features are supported. Please raise a <Anchor showExternal={true} href="https://github.com/twilio-labs/paste/discussions/new?category=general">GitHub discussion</Anchor> for any feedback or requests.</CalloutText>
58+
</Callout>
59+
</Box>
60+
61+
Highcharts offers an accessibility module which we recommend always enabling. If using our [BaseChart](/foundations/data-visualization/for-engineers#basechart) implementation, this is taken care of. It provides many useful features that help visually impaired users interact with and understand charts. More information on this module can be found on [Highcharts docs](https://www.highcharts.com/docs/accessibility/accessibility-module). Features that are offered are:
62+
- Announces chart metadata such as title, subtitle, and description.
63+
- Allows keyboard navigation of series, points, and legend items.
64+
- Describes series when focused.
65+
- Describes points when focused.
66+
- Announces the legend item when focused and describes whether the series is hidden or shown.
67+
- Toggles series visibility via keyboard.
68+
- When switching from a series to the legend, legend items announce that they are used to toggle series, along with the title of chart.
69+
70+
## Screen reader announcements
71+
72+
The accessibility module provides announcements by default for the series and point formatters. These can be overridden by passing additional props. See below for more details. Note that the default formats are in English only - any translations would need to be overridden.
73+
74+
- When switching points, announce the point index, _x_-axis, value, and series name. Example: "2, _x_ 3, 8105, Installation", which means it is the 2nd point in the series, with _x_-axis = 3, and a value of 8105 (_y_-axis) in the series "Installation".
75+
- When focusing on a series, announce the series name, series position of total, and how many points. Example: "Installation, line 1 of 2 with 8 data points."
76+
77+
### Customizing announcements
78+
79+
To override the default announcements you can set the `accessibility` attribute in the support options of the [Chart Provider](/components/chart-provider/api#charttypeoptions)
80+
81+
The point and series will be passed to the `descriptionFormatter` to retrieve the correct values, such as axis values and series names.
82+
83+
Below is an example where we have not overridden the default announcements to understand the base features.
84+
85+
<LivePreview
86+
scope={{ChartProvider, BaseChart}}
87+
language="jsx"
88+
noInline
89+
>
90+
{SimpleChartAccessibilityDefaultExample}
91+
</LivePreview>
92+
93+
94+
## Custom example
95+
96+
Below is an example of a chart with custom `descriptionFormatter` for the series and point. The title and sub title are both specified but hidden. They will still be included in the screen reader announcements to give context to visually impaired users but not be visible on the chart.
97+
98+
If you inspect the rendered chart element you will see that an aria-label is applied to both the series and the point with the correct formatting provided in the config.
99+
- `aria-label="The series Installation has a total of 8 points"` is applied to the series.
100+
- `aria-label="The point 0 has a value of 43934"` is applied to the point.
101+
102+
<LivePreview
103+
scope={{ChartProvider, BaseChart}}
104+
language="jsx"
105+
noInline
106+
>
107+
{SimpleChartAccessibilityExample}
108+
</LivePreview>
109+
110+
## Notes
111+
112+
- When focusing on points, the tooltip is not announced by screen readers. Instead the point description is read out. If you have key information in the tooltip, be sure to include it in the `point.descriptionFormatter`.
113+
114+
</content>
115+
116+
</contentwrapper>

0 commit comments

Comments
 (0)