From cdb1831ceb1405ed1fdcc7b47a4a2cd54138938d Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 24 Sep 2018 21:19:18 -0700 Subject: [PATCH] Add a11y features to the line-chart component - Treat it as an image - Add a title and a description - Hide the axes, just in case --- ui/app/components/line-chart.js | 19 +++++++++++++++++++ ui/app/templates/components/line-chart.hbs | 15 ++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ui/app/components/line-chart.js b/ui/app/components/line-chart.js index e8846026d..52c5de964 100644 --- a/ui/app/components/line-chart.js +++ b/ui/app/components/line-chart.js @@ -37,6 +37,9 @@ export default Component.extend(WindowResizable, { timeseries: false, chartClass: 'is-primary', + title: 'Line Chart', + description: null, + // Private Properties width: 0, @@ -96,6 +99,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]) || 1; diff --git a/ui/app/templates/components/line-chart.hbs b/ui/app/templates/components/line-chart.hbs index eb993918d..77861245b 100644 --- a/ui/app/templates/components/line-chart.hbs +++ b/ui/app/templates/components/line-chart.hbs @@ -1,4 +1,13 @@ - + + {{title}} + + {{#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}} + @@ -14,8 +23,8 @@ - - + +