Skip to content

Commit

Permalink
Add a11y features to the line-chart component
Browse files Browse the repository at this point in the history
- Treat it as an image
- Add a title and a description
- Hide the axes, just in case
  • Loading branch information
DingoEatingFuzz committed Sep 25, 2018
1 parent a8d485f commit c8c0777
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
19 changes: 19 additions & 0 deletions ui/app/components/line-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default Component.extend(WindowResizable, {
timeseries: false,
chartClass: 'is-primary',

title: 'Line Chart',
description: null,

// Private Properties

width: 0,
Expand Down Expand Up @@ -95,6 +98,22 @@ export default Component.extend(WindowResizable, {
return scale;
}),

xRange: computed('data.[]', 'xFormat', 'xProp', 'timeseries', function() {
const { xProp, timeseries, data } = this.getProperties('xProp', 'timeseries', 'data');
const range = d3Array.extent(data, d => d[xProp]);
const formatter = this.xFormat(timeseries);

return range.map(formatter);
}),

yRange: computed('data.[]', 'yFormat', 'yProp', function() {
const yProp = this.get('yProp');
const range = d3Array.extent(this.get('data'), d => d[yProp]);
const formatter = this.yFormat();

return range.map(formatter);
}),

yScale: computed('data.[]', 'yProp', 'xAxisOffset', function() {
const yProp = this.get('yProp');
let max = d3Array.max(this.get('data'), d => d[yProp]);
Expand Down
15 changes: 12 additions & 3 deletions ui/app/templates/components/line-chart.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<svg>
<svg role="img" aria-labelledby="{{concat "title-" elementId}} {{concat "desc-" elementId}}">
<title id="{{concat "title-" elementId}}">{{title}}</title>
<description id="{{concat "desc-" elementId}}">
{{#if description}}
{{description}}
{{else}}
X-axis values range from {{xRange.firstObject}} to {{xRange.lastObject}},
and Y-axis values range from {{yRange.firstObject}} to {{yRange.lastObject}}.
{{/if}}
</description>
<defs>
<linearGradient x1="0" x2="0" y1="0" y2="1" class="{{chartClass}}" id="{{fillId}}">
<stop class="start" offset="0%" />
Expand All @@ -14,8 +23,8 @@
<rect class="area" x="0" y="0" width="{{yAxisOffset}}" height="{{xAxisOffset}}" fill="url(#{{fillId}})" clip-path="url(#{{maskId}})" />
<rect class="hover-target" x="0" y="0" width="{{yAxisOffset}}" height="{{xAxisOffset}}" />
</g>
<g class="x-axis axis" transform="translate(0, {{xAxisOffset}})"></g>
<g class="y-axis axis" transform="translate({{yAxisOffset}}, 0)"></g>
<g aria-hidden="true" class="x-axis axis" transform="translate(0, {{xAxisOffset}})"></g>
<g aria-hidden="true" class="y-axis axis" transform="translate({{yAxisOffset}}, 0)"></g>
</svg>
<div class="chart-tooltip is-snappy {{if isActive "active" "inactive"}}" style={{tooltipStyle}}>
<p>
Expand Down

0 comments on commit c8c0777

Please sign in to comment.