-
Notifications
You must be signed in to change notification settings - Fork 121
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(a11y): improve chart figure #1104
Changes from 5 commits
3558657
6560602
7e499b9
81926ae
36cacf7
d091a14
e7d1230
5ef8ace
01a46af
947b29f
9e036d3
a03433f
bf0e013
5935818
9b11e85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { common } from '../page_objects/common'; | ||
|
||
describe('Accessibility tree', () => { | ||
it('should include the series types if one type of series', async () => { | ||
const tree = await common.testAccessibilityTree( | ||
'http://localhost:9001/iframe.html?id=annotations-lines--x-continuous-domain', | ||
'.echCanvasRenderer', | ||
); | ||
// the legend has bars and lines as value.descriptions not value.name | ||
const hasTextOfChartTypes = tree.children.filter((value) => { | ||
return value.name === 'bars'; | ||
}); | ||
expect(hasTextOfChartTypes.length).toBe(1); | ||
}); | ||
it('should include the series types if multiple types of series', async () => { | ||
const tree = await common.testAccessibilityTree( | ||
'http://localhost:9001/iframe.html?id=mixed-charts--bars-and-lines', | ||
'.echCanvasRenderer', | ||
); | ||
// the legend has bars and lines as value.descriptions not value.name | ||
const hasTextOfChartTypes = tree.children.filter((value) => { | ||
return value.name === 'bars' || value.name === 'lines'; | ||
}); | ||
expect(hasTextOfChartTypes.length).toBe(2); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -152,27 +152,50 @@ class XYChartComponent extends React.Component<XYChartProps> { | |||||||||
initialized, | ||||||||||
isChartEmpty, | ||||||||||
chartContainerDimensions: { width, height }, | ||||||||||
geometries, | ||||||||||
} = this.props; | ||||||||||
|
||||||||||
if (!initialized || isChartEmpty) { | ||||||||||
this.ctx = null; | ||||||||||
return null; | ||||||||||
} | ||||||||||
|
||||||||||
const seriesTypes: string[] = []; | ||||||||||
Object.entries(geometries).forEach((value) => { | ||||||||||
if (value[1].length > 0) { | ||||||||||
seriesTypes.push(value[0]); | ||||||||||
} | ||||||||||
}); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not base our text on internal object keys. We should be able to get that information in a better/cleaner way. We should not think about text changes if we refactor our internal code structure. Also remember that we need to add i18n, and having a stronger enum instead of internal object keys can improve the robustness of the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you recommend getting this data if not using the object keys? On the i18n front, I don't think it's fair to expect a PR that improves a11y to also solve Charts' i18n in one fell swoop. Without an existing i18n solution in place (correct me if I'm wrong as I'm only loosely familiar with the codebase), building with a hypothetical solution in mind brings a lot of overhead with little gain imo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored in e7d1230 thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm referring to the fact that we are extracting the chart type "strings" from an object This refactoring increase also the current issue: if the
The concept of chart type is already built into each A selector that picks the actual series types and creates a Set of unique There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok thanks please see 9e036d3 |
||||||||||
|
||||||||||
return ( | ||||||||||
<canvas | ||||||||||
ref={forwardStageRef} | ||||||||||
className="echCanvasRenderer" | ||||||||||
width={width * this.devicePixelRatio} | ||||||||||
height={height * this.devicePixelRatio} | ||||||||||
style={{ | ||||||||||
width, | ||||||||||
height, | ||||||||||
}} | ||||||||||
aria-label="Chart" | ||||||||||
// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role | ||||||||||
role="img" | ||||||||||
/> | ||||||||||
<figure> | ||||||||||
<canvas | ||||||||||
ref={forwardStageRef} | ||||||||||
className="echCanvasRenderer" | ||||||||||
width={width * this.devicePixelRatio} | ||||||||||
height={height * this.devicePixelRatio} | ||||||||||
style={{ | ||||||||||
width, | ||||||||||
height, | ||||||||||
}} | ||||||||||
aria-label="Chart" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As stated in the issue, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see e7d1230 thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In e7d1230 I ended up removing the aria-label because it's not read by VoiceOver and this PR adds more information. I was leaning towards not having the aria-label since it's not providing more information on the |
||||||||||
// eslint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role | ||||||||||
role="presentation" | ||||||||||
> | ||||||||||
<dl className="screen-reader"> | ||||||||||
{seriesTypes.length > 0 ? ( | ||||||||||
<dt> | ||||||||||
Chart type(s) | ||||||||||
{seriesTypes.map((value, index) => { | ||||||||||
return <dd key={`${index}`}>{value}</dd>; | ||||||||||
})} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplified...
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you fixed in e7d1230 |
||||||||||
</dt> | ||||||||||
) : ( | ||||||||||
<dt>No series in chart</dt> | ||||||||||
)} | ||||||||||
</dl> | ||||||||||
</canvas> | ||||||||||
</figure> | ||||||||||
markov00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
); | ||||||||||
} | ||||||||||
} | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import 'highlighter'; | ||
@import 'crosshair'; | ||
@import 'screen_reader'; | ||
@import 'annotations/index'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.screen-reader { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always prefix classes with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call thank you - fixed in e7d1230 |
||
position: absolute; | ||
left: -10000px; | ||
top: auto; | ||
width: 1px; | ||
height: 1px; | ||
myasonik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍