highcharts_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +106 -0
  9. data/Rakefile +6 -0
  10. data/highcharts_rails.gemspec +27 -0
  11. data/lib/highcharts_rails/version.rb +3 -0
  12. data/lib/highcharts_rails.rb +8 -0
  13. data/vendor/assets/javascripts/highcharts-3d.src.js +2139 -0
  14. data/vendor/assets/javascripts/highcharts-more.src.js +2982 -0
  15. data/vendor/assets/javascripts/highcharts.src.js +22947 -0
  16. data/vendor/assets/javascripts/js/highcharts-3d.src.js +2085 -0
  17. data/vendor/assets/javascripts/js/highcharts-more.src.js +2820 -0
  18. data/vendor/assets/javascripts/js/highcharts.src.js +20917 -0
  19. data/vendor/assets/javascripts/js/modules/accessibility.src.js +1072 -0
  20. data/vendor/assets/javascripts/js/modules/annotations.src.js +408 -0
  21. data/vendor/assets/javascripts/js/modules/boost.src.js +652 -0
  22. data/vendor/assets/javascripts/js/modules/broken-axis.src.js +338 -0
  23. data/vendor/assets/javascripts/js/modules/data.src.js +981 -0
  24. data/vendor/assets/javascripts/js/modules/drilldown.src.js +756 -0
  25. data/vendor/assets/javascripts/js/modules/exporting.src.js +953 -0
  26. data/vendor/assets/javascripts/js/modules/funnel.src.js +290 -0
  27. data/vendor/assets/javascripts/js/modules/gantt.src.js +791 -0
  28. data/vendor/assets/javascripts/js/modules/grid-axis.src.js +545 -0
  29. data/vendor/assets/javascripts/js/modules/heatmap.src.js +798 -0
  30. data/vendor/assets/javascripts/js/modules/no-data-to-display.src.js +150 -0
  31. data/vendor/assets/javascripts/js/modules/offline-exporting.src.js +492 -0
  32. data/vendor/assets/javascripts/js/modules/overlapping-datalabels.src.js +164 -0
  33. data/vendor/assets/javascripts/js/modules/series-label.src.js +606 -0
  34. data/vendor/assets/javascripts/js/modules/solid-gauge.src.js +305 -0
  35. data/vendor/assets/javascripts/js/modules/treemap.src.js +881 -0
  36. data/vendor/assets/javascripts/js/modules/xrange-series.src.js +254 -0
  37. data/vendor/assets/javascripts/js/themes/dark-blue.js +317 -0
  38. data/vendor/assets/javascripts/js/themes/dark-green.js +314 -0
  39. data/vendor/assets/javascripts/js/themes/dark-unica.js +243 -0
  40. data/vendor/assets/javascripts/js/themes/gray.js +326 -0
  41. data/vendor/assets/javascripts/js/themes/grid-light.js +99 -0
  42. data/vendor/assets/javascripts/js/themes/grid.js +131 -0
  43. data/vendor/assets/javascripts/js/themes/sand-signika.js +129 -0
  44. data/vendor/assets/javascripts/js/themes/skies.js +112 -0
  45. data/vendor/assets/javascripts/lib/canvg.src.js +3073 -0
  46. data/vendor/assets/javascripts/lib/jspdf.src.js +3031 -0
  47. data/vendor/assets/javascripts/lib/rgbcolor.src.js +299 -0
  48. data/vendor/assets/javascripts/lib/svg2pdf.src.js +1451 -0
  49. data/vendor/assets/javascripts/modules/accessibility.src.js +1072 -0
  50. data/vendor/assets/javascripts/modules/annotations.src.js +408 -0
  51. data/vendor/assets/javascripts/modules/boost.src.js +652 -0
  52. data/vendor/assets/javascripts/modules/broken-axis.src.js +338 -0
  53. data/vendor/assets/javascripts/modules/data.src.js +981 -0
  54. data/vendor/assets/javascripts/modules/drilldown.src.js +797 -0
  55. data/vendor/assets/javascripts/modules/exporting.src.js +882 -0
  56. data/vendor/assets/javascripts/modules/funnel.src.js +304 -0
  57. data/vendor/assets/javascripts/modules/gantt.src.js +815 -0
  58. data/vendor/assets/javascripts/modules/grid-axis.src.js +547 -0
  59. data/vendor/assets/javascripts/modules/heatmap.src.js +810 -0
  60. data/vendor/assets/javascripts/modules/no-data-to-display.src.js +161 -0
  61. data/vendor/assets/javascripts/modules/offline-exporting.src.js +492 -0
  62. data/vendor/assets/javascripts/modules/overlapping-datalabels.src.js +164 -0
  63. data/vendor/assets/javascripts/modules/series-label.src.js +606 -0
  64. data/vendor/assets/javascripts/modules/solid-gauge.src.js +316 -0
  65. data/vendor/assets/javascripts/modules/treemap.src.js +935 -0
  66. data/vendor/assets/javascripts/modules/xrange-series.src.js +276 -0
  67. data/vendor/assets/javascripts/themes/dark-blue.js +317 -0
  68. data/vendor/assets/javascripts/themes/dark-green.js +314 -0
  69. data/vendor/assets/javascripts/themes/dark-unica.js +243 -0
  70. data/vendor/assets/javascripts/themes/gray.js +326 -0
  71. data/vendor/assets/javascripts/themes/grid-light.js +99 -0
  72. data/vendor/assets/javascripts/themes/grid.js +131 -0
  73. data/vendor/assets/javascripts/themes/sand-signika.js +129 -0
  74. data/vendor/assets/javascripts/themes/skies.js +112 -0
  75. data/vendor/assets/stylesheets/highcharts.scss +610 -0
  76. metadata +161 -0
@@ -0,0 +1,1072 @@
1
+ /**
2
+ * @license Highcharts JS v5.0.6 (2016-12-07)
3
+ * Accessibility module
4
+ *
5
+ * (c) 2010-2016 Highsoft AS
6
+ * Author: Oystein Moseng
7
+ *
8
+ * License: www.highcharts.com/license
9
+ */
10
+ (function(factory) {
11
+ if (typeof module === 'object' && module.exports) {
12
+ module.exports = factory;
13
+ } else {
14
+ factory(Highcharts);
15
+ }
16
+ }(function(Highcharts) {
17
+ (function(H) {
18
+ /**
19
+ * Accessibility module
20
+ *
21
+ * (c) 2010-2016 Highsoft AS
22
+ * Author: Oystein Moseng
23
+ *
24
+ * License: www.highcharts.com/license
25
+ */
26
+ 'use strict';
27
+
28
+ var win = H.win,
29
+ doc = win.document,
30
+ each = H.each,
31
+ erase = H.erase,
32
+ addEvent = H.addEvent,
33
+ removeEvent = H.removeEvent,
34
+ fireEvent = H.fireEvent,
35
+ dateFormat = H.dateFormat,
36
+ merge = H.merge,
37
+ // Human readable description of series and each point in singular and plural
38
+ typeToSeriesMap = {
39
+ 'default': ['series', 'data point', 'data points'],
40
+ 'line': ['line', 'data point', 'data points'],
41
+ 'spline': ['line', 'data point', 'data points'],
42
+ 'area': ['line', 'data point', 'data points'],
43
+ 'areaspline': ['line', 'data point', 'data points'],
44
+ 'pie': ['pie', 'slice', 'slices'],
45
+ 'column': ['column series', 'column', 'columns'],
46
+ 'bar': ['bar series', 'bar', 'bars'],
47
+ 'scatter': ['scatter series', 'data point', 'data points'],
48
+ 'boxplot': ['boxplot series', 'box', 'boxes'],
49
+ 'arearange': ['arearange series', 'data point', 'data points'],
50
+ 'areasplinerange': ['areasplinerange series', 'data point', 'data points'],
51
+ 'bubble': ['bubble series', 'bubble', 'bubbles'],
52
+ 'columnrange': ['columnrange series', 'column', 'columns'],
53
+ 'errorbar': ['errorbar series', 'errorbar', 'errorbars'],
54
+ 'funnel': ['funnel', 'data point', 'data points'],
55
+ 'pyramid': ['pyramid', 'data point', 'data points'],
56
+ 'waterfall': ['waterfall series', 'column', 'columns'],
57
+ 'map': ['map', 'area', 'areas'],
58
+ 'mapline': ['line', 'data point', 'data points'],
59
+ 'mappoint': ['point series', 'data point', 'data points'],
60
+ 'mapbubble': ['bubble series', 'bubble', 'bubbles']
61
+ },
62
+ // Descriptions for exotic chart types
63
+ typeDescriptionMap = {
64
+ boxplot: ' Box plot charts are typically used to display groups of statistical data. ' +
65
+ 'Each data point in the chart can have up to 5 values: minimum, lower quartile, median, upper quartile and maximum. ',
66
+ arearange: ' Arearange charts are line charts displaying a range between a lower and higher value for each point. ',
67
+ areasplinerange: ' These charts are line charts displaying a range between a lower and higher value for each point. ',
68
+ bubble: ' Bubble charts are scatter charts where each data point also has a size value. ',
69
+ columnrange: ' Columnrange charts are column charts displaying a range between a lower and higher value for each point. ',
70
+ errorbar: ' Errorbar series are used to display the variability of the data. ',
71
+ funnel: ' Funnel charts are used to display reduction of data in stages. ',
72
+ pyramid: ' Pyramid charts consist of a single pyramid with item heights corresponding to each point value. ',
73
+ waterfall: ' A waterfall chart is a column chart where each column contributes towards a total end value. '
74
+ },
75
+ commonKeys = ['name', 'id', 'category', 'x', 'value', 'y'],
76
+ specialKeys = ['z', 'open', 'high', 'q3', 'median', 'q1', 'low', 'close']; // Tell user about all properties if points have one of these defined
77
+
78
+ // Default a11y options
79
+ H.setOptions({
80
+ accessibility: {
81
+ enabled: true,
82
+ pointDescriptionThreshold: 30, // set to false to disable
83
+ keyboardNavigation: {
84
+ enabled: true
85
+ // skipNullPoints: false
86
+ }
87
+ // describeSingleSeries: false
88
+ }
89
+ });
90
+
91
+ // Utility function. Reverses child nodes of a DOM element
92
+ function reverseChildNodes(node) {
93
+ var i = node.childNodes.length;
94
+ while (i--) {
95
+ node.appendChild(node.childNodes[i]);
96
+ }
97
+ }
98
+
99
+ // Utility function to attempt to fake a click event on an element
100
+ function fakeClickEvent(element) {
101
+ var fakeEvent;
102
+ if (element && element.onclick) {
103
+ fakeEvent = doc.createEvent('Events');
104
+ fakeEvent.initEvent('click', true, false);
105
+ element.onclick(fakeEvent);
106
+ }
107
+ }
108
+
109
+ // Whenever drawing series, put info on DOM elements
110
+ H.wrap(H.Series.prototype, 'render', function(proceed) {
111
+ proceed.apply(this, Array.prototype.slice.call(arguments, 1));
112
+ if (this.chart.options.accessibility.enabled) {
113
+ this.setA11yDescription();
114
+ }
115
+ });
116
+
117
+ // Put accessible info on series and points of a series
118
+ H.Series.prototype.setA11yDescription = function() {
119
+ var a11yOptions = this.chart.options.accessibility,
120
+ firstPointEl = this.points && this.points.length && this.points[0].graphic && this.points[0].graphic.element,
121
+ seriesEl = firstPointEl && firstPointEl.parentNode || this.graph && this.graph.element || this.group && this.group.element; // Could be tracker series depending on series type
122
+
123
+ if (seriesEl) {
124
+ // For some series types the order of elements do not match the order of points in series
125
+ // In that case we have to reverse them in order for AT to read them out in an understandable order
126
+ if (seriesEl.lastChild === firstPointEl) {
127
+ reverseChildNodes(seriesEl);
128
+ }
129
+ // Make individual point elements accessible if possible. Note: If markers are disabled there might not be any elements there to make accessible.
130
+ if (this.points && (this.points.length < a11yOptions.pointDescriptionThreshold || a11yOptions.pointDescriptionThreshold === false)) {
131
+ each(this.points, function(point) {
132
+ if (point.graphic) {
133
+ point.graphic.element.setAttribute('role', 'img');
134
+ point.graphic.element.setAttribute('tabindex', '-1');
135
+ point.graphic.element.setAttribute('aria-label', a11yOptions.pointDescriptionFormatter && a11yOptions.pointDescriptionFormatter(point) ||
136
+ point.buildPointInfoString());
137
+ }
138
+ });
139
+ }
140
+ // Make series element accessible
141
+ if (this.chart.series.length > 1 || a11yOptions.describeSingleSeries) {
142
+ seriesEl.setAttribute('role', 'region');
143
+ seriesEl.setAttribute('tabindex', '-1');
144
+ seriesEl.setAttribute('aria-label', a11yOptions.seriesDescriptionFormatter && a11yOptions.seriesDescriptionFormatter(this) ||
145
+ this.buildSeriesInfoString());
146
+ }
147
+ }
148
+ };
149
+
150
+ // Return string with information about series
151
+ H.Series.prototype.buildSeriesInfoString = function() {
152
+ var typeInfo = typeToSeriesMap[this.type] || typeToSeriesMap.default,
153
+ description = this.description || this.options.description;
154
+ return (this.name ? this.name + ', ' : '') +
155
+ (this.chart.types.length === 1 ? typeInfo[0] : 'series') + ' ' + (this.index + 1) + ' of ' + (this.chart.series.length) +
156
+ (this.chart.types.length === 1 ? ' with ' : '. ' + typeInfo[0] + ' with ') +
157
+ (this.points.length + ' ' + (this.points.length === 1 ? typeInfo[1] : typeInfo[2])) +
158
+ (description ? '. ' + description : '') +
159
+ (this.chart.yAxis.length > 1 && this.yAxis ? '. Y axis, ' + this.yAxis.getDescription() : '') +
160
+ (this.chart.xAxis.length > 1 && this.xAxis ? '. X axis, ' + this.xAxis.getDescription() : '');
161
+ };
162
+
163
+ // Return string with information about point
164
+ H.Point.prototype.buildPointInfoString = function() {
165
+ var point = this,
166
+ series = point.series,
167
+ a11yOptions = series.chart.options.accessibility,
168
+ infoString = '',
169
+ hasSpecialKey = false,
170
+ dateTimePoint = series.xAxis && series.xAxis.isDatetimeAxis,
171
+ timeDesc = dateTimePoint && dateFormat(a11yOptions.pointDateFormatter && a11yOptions.pointDateFormatter(point) || a11yOptions.pointDateFormat ||
172
+ H.Tooltip.prototype.getXDateFormat(point, series.chart.options.tooltip, series.xAxis), point.x);
173
+
174
+ each(specialKeys, function(key) {
175
+ if (point[key] !== undefined) {
176
+ hasSpecialKey = true;
177
+ }
178
+ });
179
+
180
+ // If the point has one of the less common properties defined, display all that are defined
181
+ if (hasSpecialKey) {
182
+ if (dateTimePoint) {
183
+ infoString = timeDesc;
184
+ }
185
+ each(commonKeys.concat(specialKeys), function(key) {
186
+ if (point[key] !== undefined && !(dateTimePoint && key === 'x')) {
187
+ infoString += (infoString ? '. ' : '') + key + ', ' + this[key];
188
+ }
189
+ });
190
+ } else {
191
+ // Pick and choose properties for a succint label
192
+ infoString = (this.name || timeDesc || this.category || this.id || 'x, ' + this.x) + ', ' +
193
+ (this.value !== undefined ? this.value : this.y);
194
+ }
195
+
196
+ return (this.index + 1) + '. ' + infoString + '.' + (this.description ? ' ' + this.description : '');
197
+ };
198
+
199
+ // Get descriptive label for axis
200
+ H.Axis.prototype.getDescription = function() {
201
+ return this.userOptions && this.userOptions.description || this.axisTitle && this.axisTitle.textStr ||
202
+ this.options.id || this.categories && 'categories' || 'values';
203
+ };
204
+
205
+ // Pan along axis in a direction (1 or -1), optionally with a defined granularity (number of steps it takes to walk across current view)
206
+ H.Axis.prototype.panStep = function(direction, granularity) {
207
+ var gran = granularity || 3,
208
+ extremes = this.getExtremes(),
209
+ step = (extremes.max - extremes.min) / gran * direction,
210
+ newMax = extremes.max + step,
211
+ newMin = extremes.min + step,
212
+ size = newMax - newMin;
213
+ if (direction < 0 && newMin < extremes.dataMin) {
214
+ newMin = extremes.dataMin;
215
+ newMax = newMin + size;
216
+ } else if (direction > 0 && newMax > extremes.dataMax) {
217
+ newMax = extremes.dataMax;
218
+ newMin = newMax - size;
219
+ }
220
+ this.setExtremes(newMin, newMax);
221
+ };
222
+
223
+ // Whenever adding or removing series, keep track of types present in chart
224
+ H.wrap(H.Series.prototype, 'init', function(proceed) {
225
+ proceed.apply(this, Array.prototype.slice.call(arguments, 1));
226
+ var chart = this.chart;
227
+ if (chart.options.accessibility.enabled) {
228
+ chart.types = chart.types || [];
229
+
230
+ // Add type to list if does not exist
231
+ if (chart.types.indexOf(this.type) < 0) {
232
+ chart.types.push(this.type);
233
+ }
234
+
235
+ addEvent(this, 'remove', function() {
236
+ var removedSeries = this,
237
+ hasType = false;
238
+
239
+ // Check if any of the other series have the same type as this one. Otherwise remove it from the list.
240
+ each(chart.series, function(s) {
241
+ if (s !== removedSeries && chart.types.indexOf(removedSeries.type) < 0) {
242
+ hasType = true;
243
+ }
244
+ });
245
+ if (!hasType) {
246
+ erase(chart.types, removedSeries.type);
247
+ }
248
+ });
249
+ }
250
+ });
251
+
252
+ // Return simplified description of chart type. Some types will not be familiar to most screen reader users, but we try.
253
+ H.Chart.prototype.getTypeDescription = function() {
254
+ var firstType = this.types && this.types[0],
255
+ mapTitle = this.series[0] && this.series[0].mapTitle;
256
+ if (!firstType) {
257
+ return 'Empty chart.';
258
+ } else if (firstType === 'map') {
259
+ return mapTitle ? 'Map of ' + mapTitle : 'Map of unspecified region.';
260
+ } else if (this.types.length > 1) {
261
+ return 'Combination chart.';
262
+ } else if (['spline', 'area', 'areaspline'].indexOf(firstType) > -1) {
263
+ return 'Line chart.';
264
+ }
265
+ return firstType + ' chart.' + (typeDescriptionMap[firstType] || '');
266
+ };
267
+
268
+ // Return object with text description of each of the chart's axes
269
+ H.Chart.prototype.getAxesDescription = function() {
270
+ var numXAxes = this.xAxis.length,
271
+ numYAxes = this.yAxis.length,
272
+ desc = {},
273
+ i;
274
+
275
+ if (numXAxes) {
276
+ desc.xAxis = 'The chart has ' + numXAxes + (numXAxes > 1 ? ' X axes' : ' X axis') + ' displaying ';
277
+ if (numXAxes < 2) {
278
+ desc.xAxis += this.xAxis[0].getDescription() + '.';
279
+ } else {
280
+ for (i = 0; i < numXAxes - 1; ++i) {
281
+ desc.xAxis += (i ? ', ' : '') + this.xAxis[i].getDescription();
282
+ }
283
+ desc.xAxis += ' and ' + this.xAxis[i].getDescription() + '.';
284
+ }
285
+ }
286
+
287
+ if (numYAxes) {
288
+ desc.yAxis = 'The chart has ' + numYAxes + (numYAxes > 1 ? ' Y axes' : ' Y axis') + ' displaying ';
289
+ if (numYAxes < 2) {
290
+ desc.yAxis += this.yAxis[0].getDescription() + '.';
291
+ } else {
292
+ for (i = 0; i < numYAxes - 1; ++i) {
293
+ desc.yAxis += (i ? ', ' : '') + this.yAxis[i].getDescription();
294
+ }
295
+ desc.yAxis += ' and ' + this.yAxis[i].getDescription() + '.';
296
+ }
297
+ }
298
+
299
+ return desc;
300
+ };
301
+
302
+ // Set a11y attribs on exporting menu
303
+ H.Chart.prototype.addAccessibleContextMenuAttribs = function() {
304
+ var exportList = this.exportDivElements;
305
+ if (exportList) {
306
+ // Set tabindex on the menu items to allow focusing by script
307
+ // Set role to give screen readers a chance to pick up the contents
308
+ each(exportList, function(item) {
309
+ if (item.tagName === 'DIV' &&
310
+ !(item.children && item.children.length)) {
311
+ item.setAttribute('role', 'menuitem');
312
+ item.setAttribute('tabindex', -1);
313
+ }
314
+ });
315
+ // Set accessibility properties on parent div
316
+ exportList[0].parentNode.setAttribute('role', 'menu');
317
+ exportList[0].parentNode.setAttribute('aria-label', 'Chart export');
318
+ }
319
+ };
320
+
321
+ // Highlight a point (show tooltip and display hover state). Returns the highlighted point.
322
+ H.Point.prototype.highlight = function() {
323
+ var chart = this.series.chart;
324
+ if (this.graphic && this.graphic.element.focus) {
325
+ this.graphic.element.focus();
326
+ }
327
+ if (!this.isNull) {
328
+ this.onMouseOver(); // Show the hover marker
329
+ chart.tooltip.refresh(chart.tooltip.shared ? [this] : this); // Show the tooltip
330
+ } else {
331
+ chart.tooltip.hide(0);
332
+ // Don't call blur on the element, as it messes up the chart div's focus
333
+ }
334
+ chart.highlightedPoint = this;
335
+ return this;
336
+ };
337
+
338
+ // Function to highlight next/previous point in chart
339
+ // Returns highlighted point on success, false on failure (no adjacent point to highlight in chosen direction)
340
+ H.Chart.prototype.highlightAdjacentPoint = function(next) {
341
+ var series = this.series,
342
+ curPoint = this.highlightedPoint,
343
+ curPointIndex = curPoint && curPoint.index || 0,
344
+ newSeries,
345
+ newPoint;
346
+
347
+ // If no points, return false
348
+ if (!series[0] || !series[0].points) {
349
+ return false;
350
+ }
351
+
352
+ // Use first point if none already highlighted
353
+ if (!curPoint) {
354
+ return series[0].points[0].highlight();
355
+ }
356
+
357
+ // Find index of current point in series.points array. Necessary for dataGrouping (and maybe zoom?)
358
+ if (curPoint.series.points[curPointIndex] !== curPoint) {
359
+ for (var i = 0; i < curPoint.series.points.length; ++i) {
360
+ if (curPoint.series.points[i] === curPoint) {
361
+ curPointIndex = i;
362
+ break;
363
+ }
364
+ }
365
+ }
366
+
367
+ // Try to grab next/prev point
368
+ newSeries = series[curPoint.series.index + (next ? 1 : -1)];
369
+ newPoint = curPoint.series.points[curPointIndex + (next ? 1 : -1)] || newSeries && newSeries.points[next ? 0 : newSeries.points.length - 1];
370
+
371
+ // If there is no adjacent point, we return false
372
+ if (newPoint === undefined) {
373
+ return false;
374
+ }
375
+
376
+ // Recursively skip null points
377
+ if (newPoint.isNull && this.options.accessibility.keyboardNavigation &&
378
+ this.options.accessibility.keyboardNavigation.skipNullPoints) {
379
+ this.highlightedPoint = newPoint;
380
+ return this.highlightAdjacentPoint(next);
381
+ }
382
+
383
+ // There is an adjacent point, highlight it
384
+ return newPoint.highlight();
385
+ };
386
+
387
+ // Show the export menu and focus the first item (if exists)
388
+ H.Chart.prototype.showExportMenu = function() {
389
+ if (this.exportSVGElements && this.exportSVGElements[0]) {
390
+ this.exportSVGElements[0].element.onclick();
391
+ this.highlightExportItem(0);
392
+ }
393
+ };
394
+
395
+ // Highlight export menu item by index
396
+ H.Chart.prototype.highlightExportItem = function(ix) {
397
+ var listItem = this.exportDivElements && this.exportDivElements[ix],
398
+ curHighlighted = this.exportDivElements && this.exportDivElements[this.highlightedExportItem];
399
+
400
+ if (listItem && listItem.tagName === 'DIV' && !(listItem.children && listItem.children.length)) {
401
+ if (listItem.focus) {
402
+ listItem.focus();
403
+ }
404
+ if (curHighlighted && curHighlighted.onmouseout) {
405
+ curHighlighted.onmouseout();
406
+ }
407
+ if (listItem.onmouseover) {
408
+ listItem.onmouseover();
409
+ }
410
+ this.highlightedExportItem = ix;
411
+ return true;
412
+ }
413
+ };
414
+
415
+ // Highlight range selector button by index
416
+ H.Chart.prototype.highlightRangeSelectorButton = function(ix) {
417
+ var buttons = this.rangeSelector.buttons;
418
+ // Deselect old
419
+ if (buttons[this.highlightedRangeSelectorItemIx]) {
420
+ buttons[this.highlightedRangeSelectorItemIx].setState(this.oldRangeSelectorItemState || 0);
421
+ }
422
+ // Select new
423
+ this.highlightedRangeSelectorItemIx = ix;
424
+ if (buttons[ix]) {
425
+ if (buttons[ix].element.focus) {
426
+ buttons[ix].element.focus();
427
+ }
428
+ this.oldRangeSelectorItemState = buttons[ix].state;
429
+ buttons[ix].setState(2);
430
+ return true;
431
+ }
432
+ return false;
433
+ };
434
+
435
+ // Highlight legend item by index
436
+ H.Chart.prototype.highlightLegendItem = function(ix) {
437
+ var items = this.legend.allItems;
438
+ if (items[this.highlightedLegendItemIx]) {
439
+ fireEvent(items[this.highlightedLegendItemIx].legendGroup.element, 'mouseout');
440
+ }
441
+ this.highlightedLegendItemIx = ix;
442
+ if (items[ix]) {
443
+ if (items[ix].legendGroup.element.focus) {
444
+ items[ix].legendGroup.element.focus();
445
+ }
446
+ fireEvent(items[ix].legendGroup.element, 'mouseover');
447
+ return true;
448
+ }
449
+ return false;
450
+ };
451
+
452
+ // Hide export menu
453
+ H.Chart.prototype.hideExportMenu = function() {
454
+ var exportList = this.exportDivElements;
455
+ if (exportList) {
456
+ each(exportList, function(el) {
457
+ fireEvent(el, 'mouseleave');
458
+ });
459
+ if (exportList[this.highlightedExportItem] && exportList[this.highlightedExportItem].onmouseout) {
460
+ exportList[this.highlightedExportItem].onmouseout();
461
+ }
462
+ this.highlightedExportItem = 0;
463
+ this.renderTo.focus();
464
+ }
465
+ };
466
+
467
+ // Add keyboard navigation handling to chart
468
+ H.Chart.prototype.addKeyboardNavEvents = function() {
469
+ var chart = this;
470
+
471
+ // Abstraction layer for keyboard navigation. Keep a map of keyCodes to handler functions, and a next/prev move handler for tab order.
472
+ // The module's keyCode handlers determine when to move to another module.
473
+ // Validate holds a function to determine if there are prerequisites for this module to run that are not met.
474
+ // Init holds a function to run once before any keyCodes are interpreted.
475
+ // transformTabs determines whether to transform tabs to left/right events or not. Defaults to true.
476
+ function KeyboardNavigationModule(options) {
477
+ this.keyCodeMap = options.keyCodeMap;
478
+ this.move = options.move;
479
+ this.validate = options.validate;
480
+ this.init = options.init;
481
+ this.transformTabs = options.transformTabs !== false;
482
+ }
483
+ KeyboardNavigationModule.prototype = {
484
+ // Find handler function(s) for key code in the keyCodeMap and run it.
485
+ run: function(e) {
486
+ var navModule = this,
487
+ keyCode = e.which || e.keyCode,
488
+ handled = false;
489
+ keyCode = this.transformTabs && keyCode === 9 ? (e.shiftKey ? 37 : 39) : keyCode; // Transform tabs
490
+ each(this.keyCodeMap, function(codeSet) {
491
+ if (codeSet[0].indexOf(keyCode) > -1) {
492
+ handled = codeSet[1].call(navModule, keyCode, e) === false ? false : true; // If explicitly returning false, we haven't handled it
493
+ }
494
+ });
495
+ return handled;
496
+ }
497
+ };
498
+ // Maintain abstraction between KeyboardNavigationModule and Highcharts
499
+ // The chart object keeps track of a list of KeyboardNavigationModules that we move through
500
+ function navModuleFactory(keyMap, options) {
501
+ return new KeyboardNavigationModule(merge({
502
+ keyCodeMap: keyMap,
503
+ // Move to next/prev valid module, or undefined if none, and init it.
504
+ // Returns true on success and false if there is no valid module to move to.
505
+ move: function(direction) {
506
+ chart.keyboardNavigationModuleIndex += direction;
507
+ var newModule = chart.keyboardNavigationModules[chart.keyboardNavigationModuleIndex];
508
+ if (newModule) {
509
+ if (newModule.validate && !newModule.validate()) {
510
+ return this.move(direction); // Invalid module
511
+ }
512
+ if (newModule.init) {
513
+ newModule.init(direction); // Valid module, init it
514
+ return true;
515
+ }
516
+ }
517
+ // No module
518
+ chart.keyboardNavigationModuleIndex = 0; // Reset counter
519
+ chart.slipNextTab = true; // Allow next tab to slip, as we will have focus on chart now
520
+ return false;
521
+ }
522
+ }, options));
523
+ }
524
+
525
+ // Route keydown events
526
+ function keydownHandler(ev) {
527
+ var e = ev || win.event,
528
+ keyCode = e.which || e.keyCode,
529
+ curNavModule = chart.keyboardNavigationModules[chart.keyboardNavigationModuleIndex];
530
+
531
+ // Handle tabbing
532
+ if (keyCode === 9) {
533
+ // If we reached end of chart, we need to let this tab slip through to allow users to tab further
534
+ if (chart.slipNextTab) {
535
+ chart.slipNextTab = false;
536
+ return;
537
+ }
538
+ }
539
+ // If key was not tab, don't slip the next tab
540
+ chart.slipNextTab = false;
541
+
542
+ // If there is a navigation module for the current index, run it. Otherwise, we are outside of the chart in some direction.
543
+ if (curNavModule) {
544
+ if (curNavModule.run(e)) {
545
+ e.preventDefault(); // If successfully handled, stop the event here.
546
+ }
547
+ }
548
+ }
549
+
550
+ // List of the different keyboard handling modes we use depending on where we are in the chart.
551
+ // Each mode has a set of handling functions mapped to key codes.
552
+ // Each mode determines when to move to the next/prev mode.
553
+ chart.keyboardNavigationModules = [
554
+ // Points
555
+ navModuleFactory([
556
+ // Left/Right
557
+ [
558
+ [37, 39],
559
+ function(keyCode) {
560
+ if (!chart.highlightAdjacentPoint(keyCode === 39)) { // Try to highlight adjacent point
561
+ return this.move(keyCode === 39 ? 1 : -1); // Failed. Move to next/prev module
562
+ }
563
+ }
564
+ ],
565
+ // Up/Down
566
+ [
567
+ [38, 40],
568
+ function(keyCode) {
569
+ var newSeries;
570
+ if (chart.highlightedPoint) {
571
+ newSeries = chart.series[chart.highlightedPoint.series.index + (keyCode === 38 ? -1 : 1)]; // Find prev/next series
572
+ if (newSeries && newSeries.points[0]) { // If series exists and has data, go for it
573
+ newSeries.points[0].highlight();
574
+ } else {
575
+ return this.move(keyCode === 40 ? 1 : -1); // Otherwise, attempt to move to next/prev module
576
+ }
577
+ }
578
+ }
579
+ ],
580
+ // Enter/Spacebar
581
+ [
582
+ [13, 32],
583
+ function() {
584
+ if (chart.highlightedPoint) {
585
+ chart.highlightedPoint.firePointEvent('click');
586
+ }
587
+ }
588
+ ]
589
+ ], {
590
+ // If coming back to points from other module, highlight last point
591
+ init: function(direction) {
592
+ var lastSeries = chart.series && chart.series[chart.series.length - 1],
593
+ lastPoint = lastSeries && lastSeries.points && lastSeries.points[lastSeries.points.length - 1];
594
+ if (direction < 0 && lastPoint) {
595
+ lastPoint.highlight();
596
+ }
597
+ }
598
+ }),
599
+
600
+ // Exporting
601
+ navModuleFactory([
602
+ // Left/Up
603
+ [
604
+ [37, 38],
605
+ function() {
606
+ var i = chart.highlightedExportItem || 0,
607
+ reachedEnd = true,
608
+ series = chart.series,
609
+ newSeries;
610
+ // Try to highlight prev item in list. Highlighting e.g. separators will fail.
611
+ while (i--) {
612
+ if (chart.highlightExportItem(i)) {
613
+ reachedEnd = false;
614
+ break;
615
+ }
616
+ }
617
+ if (reachedEnd) {
618
+ chart.hideExportMenu();
619
+ // Wrap to last point
620
+ if (series && series.length) {
621
+ newSeries = series[series.length - 1];
622
+ if (newSeries.points.length) {
623
+ newSeries.points[newSeries.points.length - 1].highlight();
624
+ }
625
+ }
626
+ // Try to move to prev module (should be points, since we wrapped to last point)
627
+ return this.move(-1);
628
+ }
629
+ }
630
+ ],
631
+ // Right/Down
632
+ [
633
+ [39, 40],
634
+ function() {
635
+ var highlightedExportItem = chart.highlightedExportItem || 0,
636
+ reachedEnd = true;
637
+ // Try to highlight next item in list. Highlighting e.g. separators will fail.
638
+ for (var i = highlightedExportItem + 1; i < chart.exportDivElements.length; ++i) {
639
+ if (chart.highlightExportItem(i)) {
640
+ reachedEnd = false;
641
+ break;
642
+ }
643
+ }
644
+ if (reachedEnd) {
645
+ chart.hideExportMenu();
646
+ return this.move(1); // Next module
647
+ }
648
+ }
649
+ ],
650
+ // Enter/Spacebar
651
+ [
652
+ [13, 32],
653
+ function() {
654
+ fakeClickEvent(chart.exportDivElements[chart.highlightedExportItem]);
655
+ }
656
+ ]
657
+ ], {
658
+ // Only run exporting navigation if exporting support exists and is enabled on chart
659
+ validate: function() {
660
+ return chart.exportChart && !(chart.options.exporting && chart.options.exporting.enabled === false);
661
+ },
662
+ // Show export menu
663
+ init: function(direction) {
664
+ chart.highlightedPoint = null;
665
+ chart.showExportMenu();
666
+ // If coming back to export menu from other module, try to highlight last item in menu
667
+ if (direction < 0 && chart.exportDivElements) {
668
+ for (var i = chart.exportDivElements.length; i > -1; --i) {
669
+ if (chart.highlightExportItem(i)) {
670
+ break;
671
+ }
672
+ }
673
+ }
674
+ }
675
+ }),
676
+
677
+ // Map zoom
678
+ navModuleFactory([
679
+ // Up/down/left/right
680
+ [
681
+ [38, 40, 37, 39],
682
+ function(keyCode) {
683
+ chart[keyCode === 38 || keyCode === 40 ? 'yAxis' : 'xAxis'][0].panStep(keyCode < 39 ? -1 : 1);
684
+ }
685
+ ],
686
+
687
+ // Tabs
688
+ [
689
+ [9],
690
+ function(keyCode, e) {
691
+ var button;
692
+ chart.mapNavButtons[chart.focusedMapNavButtonIx].setState(0); // Deselect old
693
+ if (e.shiftKey && !chart.focusedMapNavButtonIx || !e.shiftKey && chart.focusedMapNavButtonIx) { // trying to go somewhere we can't?
694
+ chart.mapZoom(); // Reset zoom
695
+ return this.move(e.shiftKey ? -1 : 1); // Nowhere to go, go to prev/next module
696
+ }
697
+ chart.focusedMapNavButtonIx += e.shiftKey ? -1 : 1;
698
+ button = chart.mapNavButtons[chart.focusedMapNavButtonIx];
699
+ if (button.element.focus) {
700
+ button.element.focus();
701
+ }
702
+ button.setState(2);
703
+ }
704
+ ],
705
+
706
+ // Enter/Spacebar
707
+ [
708
+ [13, 32],
709
+ function() {
710
+ fakeClickEvent(chart.mapNavButtons[chart.focusedMapNavButtonIx].element);
711
+ }
712
+ ]
713
+ ], {
714
+ // Only run this module if we have map zoom on the chart
715
+ validate: function() {
716
+ return chart.mapZoom && chart.mapNavButtons && chart.mapNavButtons.length === 2;
717
+ },
718
+
719
+ // Handle tabs separately
720
+ transformTabs: false,
721
+
722
+ // Make zoom buttons do their magic
723
+ init: function(direction) {
724
+ var zoomIn = chart.mapNavButtons[0],
725
+ zoomOut = chart.mapNavButtons[1],
726
+ initialButton = direction > 0 ? zoomIn : zoomOut;
727
+
728
+ each(chart.mapNavButtons, function(button, i) {
729
+ button.element.setAttribute('tabindex', -1);
730
+ button.element.setAttribute('role', 'button');
731
+ button.element.setAttribute('aria-label', 'Zoom ' + (i ? 'out' : '') + 'chart');
732
+ });
733
+
734
+ if (initialButton.element.focus) {
735
+ initialButton.element.focus();
736
+ }
737
+ initialButton.setState(2);
738
+ chart.focusedMapNavButtonIx = direction > 0 ? 0 : 1;
739
+ }
740
+ }),
741
+
742
+ // Highstock range selector (minus input boxes)
743
+ navModuleFactory([
744
+ // Left/Right/Up/Down
745
+ [
746
+ [37, 39, 38, 40],
747
+ function(keyCode) {
748
+ var direction = (keyCode === 37 || keyCode === 38) ? -1 : 1;
749
+ // Try to highlight next/prev button
750
+ if (!chart.highlightRangeSelectorButton(chart.highlightedRangeSelectorItemIx + direction)) {
751
+ return this.move(direction);
752
+ }
753
+ }
754
+ ],
755
+ // Enter/Spacebar
756
+ [
757
+ [13, 32],
758
+ function() {
759
+ if (chart.oldRangeSelectorItemState !== 3) { // Don't allow click if button used to be disabled
760
+ fakeClickEvent(chart.rangeSelector.buttons[chart.highlightedRangeSelectorItemIx].element);
761
+ }
762
+ }
763
+ ]
764
+ ], {
765
+ // Only run this module if we have range selector
766
+ validate: function() {
767
+ return chart.rangeSelector && chart.rangeSelector.buttons && chart.rangeSelector.buttons.length;
768
+ },
769
+
770
+ // Make elements focusable and accessible
771
+ init: function(direction) {
772
+ each(chart.rangeSelector.buttons, function(button) {
773
+ button.element.setAttribute('tabindex', '-1');
774
+ button.element.setAttribute('role', 'button');
775
+ button.element.setAttribute('aria-label', 'Select range ' + (button.text && button.text.textStr));
776
+ });
777
+ // Focus first/last button
778
+ chart.highlightRangeSelectorButton(direction > 0 ? 0 : chart.rangeSelector.buttons.length - 1);
779
+ }
780
+ }),
781
+
782
+ // Highstock range selector, input boxes
783
+ navModuleFactory([
784
+ // Tab/Up/Down
785
+ [
786
+ [9, 38, 40],
787
+ function(keyCode, e) {
788
+ var direction = (keyCode === 9 && e.shiftKey || keyCode === 38) ? -1 : 1,
789
+ newIx = chart.highlightedInputRangeIx = chart.highlightedInputRangeIx + direction;
790
+ // Try to highlight next/prev item in list.
791
+ if (newIx > 1 || newIx < 0) { // Out of range
792
+ return this.move(direction);
793
+ }
794
+ chart.rangeSelector[newIx ? 'maxInput' : 'minInput'].focus(); // Input boxes are HTML, and should have focus support in all browsers
795
+ }
796
+ ]
797
+ ], {
798
+ // Only run if we have range selector with input boxes
799
+ validate: function() {
800
+ var inputVisible = chart.rangeSelector && chart.rangeSelector.inputGroup && chart.rangeSelector.inputGroup.element.getAttribute('visibility') !== 'hidden';
801
+ return inputVisible && chart.options.rangeSelector.inputEnabled !== false && chart.rangeSelector.minInput && chart.rangeSelector.maxInput;
802
+ },
803
+
804
+ // Handle tabs different from left/right (because we don't want to catch left/right in a text area)
805
+ transformTabs: false,
806
+
807
+ // Highlight first/last input box
808
+ init: function(direction) {
809
+ chart.highlightedInputRangeIx = direction > 0 ? 0 : 1;
810
+ chart.rangeSelector[chart.highlightedInputRangeIx ? 'maxInput' : 'minInput'].focus();
811
+ }
812
+ }),
813
+
814
+ // Legend navigation
815
+ navModuleFactory([
816
+ // Left/Right/Up/Down
817
+ [
818
+ [37, 39, 38, 40],
819
+ function(keyCode) {
820
+ var direction = (keyCode === 37 || keyCode === 38) ? -1 : 1;
821
+ // Try to highlight next/prev legend item
822
+ if (!chart.highlightLegendItem(chart.highlightedLegendItemIx + direction)) {
823
+ return this.move(direction);
824
+ }
825
+ }
826
+ ],
827
+ // Enter/Spacebar
828
+ [
829
+ [13, 32],
830
+ function() {
831
+ fakeClickEvent(chart.legend.allItems[chart.highlightedLegendItemIx].legendItem.element.parentNode);
832
+ }
833
+ ]
834
+ ], {
835
+ // Only run this module if we have at least one legend - wait for it - item.
836
+ validate: function() {
837
+ return chart.legend && chart.legend.allItems && !chart.colorAxis;
838
+ },
839
+
840
+ // Make elements focusable and accessible
841
+ init: function(direction) {
842
+ each(chart.legend.allItems, function(item) {
843
+ item.legendGroup.element.setAttribute('tabindex', '-1');
844
+ item.legendGroup.element.setAttribute('role', 'button');
845
+ item.legendGroup.element.setAttribute('aria-label', 'Toggle visibility of series ' + item.name);
846
+ });
847
+ // Focus first/last item
848
+ chart.highlightLegendItem(direction > 0 ? 0 : chart.legend.allItems.length - 1);
849
+ }
850
+ })
851
+ ];
852
+
853
+ // Init nav module index. We start at the first module, and as the user navigates through the chart the index will increase to use different handler modules.
854
+ chart.keyboardNavigationModuleIndex = 0;
855
+
856
+ // Make chart reachable by tab
857
+ if (!chart.renderTo.tabIndex) {
858
+ chart.renderTo.setAttribute('tabindex', '0');
859
+ }
860
+
861
+ // Handle keyboard events
862
+ addEvent(chart.renderTo, 'keydown', keydownHandler);
863
+ addEvent(chart, 'destroy', function() {
864
+ removeEvent(chart.renderTo, 'keydown', keydownHandler);
865
+ });
866
+ };
867
+
868
+ // Add screen reader region to chart.
869
+ // tableId is the HTML id of the table to focus when clicking the table anchor in the screen reader region.
870
+ H.Chart.prototype.addScreenReaderRegion = function(tableId) {
871
+ var chart = this,
872
+ series = chart.series,
873
+ options = chart.options,
874
+ a11yOptions = options.accessibility,
875
+ hiddenSection = chart.screenReaderRegion = doc.createElement('div'),
876
+ tableShortcut = doc.createElement('h3'),
877
+ tableShortcutAnchor = doc.createElement('a'),
878
+ chartHeading = doc.createElement('h3'),
879
+ hiddenStyle = { // CSS style to hide element from visual users while still exposing it to screen readers
880
+ position: 'absolute',
881
+ left: '-9999px',
882
+ top: 'auto',
883
+ width: '1px',
884
+ height: '1px',
885
+ overflow: 'hidden'
886
+ },
887
+ chartTypes = chart.types || [],
888
+ // Build axis info - but not for pies and maps. Consider not adding for certain other types as well (funnel, pyramid?)
889
+ axesDesc = (chartTypes.length === 1 && chartTypes[0] === 'pie' || chartTypes[0] === 'map') && {} || chart.getAxesDescription(),
890
+ chartTypeInfo = series[0] && typeToSeriesMap[series[0].type] || typeToSeriesMap.default;
891
+
892
+ hiddenSection.setAttribute('role', 'region');
893
+ hiddenSection.setAttribute('aria-label', 'Chart screen reader information.');
894
+
895
+ hiddenSection.innerHTML = a11yOptions.screenReaderSectionFormatter && a11yOptions.screenReaderSectionFormatter(chart) ||
896
+ '<div tabindex="0">Use regions/landmarks to skip ahead to chart' +
897
+ (series.length > 1 ? ' and navigate between data series' : '') + '.</div><h3>Summary.</h3><div>' + (options.title.text || 'Chart') +
898
+ (options.subtitle && options.subtitle.text ? '. ' + options.subtitle.text : '') +
899
+ '</div><h3>Long description.</h3><div>' + (options.chart.description || 'No description available.') +
900
+ '</div><h3>Structure.</h3><div>Chart type: ' + (options.chart.typeDescription || chart.getTypeDescription()) + '</div>' +
901
+ (series.length === 1 ? '<div>' + chartTypeInfo[0] + ' with ' + series[0].points.length + ' ' +
902
+ (series[0].points.length === 1 ? chartTypeInfo[1] : chartTypeInfo[2]) + '.</div>' : '') +
903
+ (axesDesc.xAxis ? ('<div>' + axesDesc.xAxis + '</div>') : '') +
904
+ (axesDesc.yAxis ? ('<div>' + axesDesc.yAxis + '</div>') : '');
905
+
906
+ // Add shortcut to data table if export-csv is loaded
907
+ if (chart.getCSV) {
908
+ tableShortcutAnchor.innerHTML = 'View as data table.';
909
+ tableShortcutAnchor.href = '#' + tableId;
910
+ tableShortcutAnchor.setAttribute('tabindex', '-1'); // Make this unreachable by user tabbing
911
+ tableShortcutAnchor.onclick = a11yOptions.onTableAnchorClick || function() {
912
+ chart.viewData();
913
+ doc.getElementById(tableId).focus();
914
+ };
915
+ tableShortcut.appendChild(tableShortcutAnchor);
916
+
917
+ hiddenSection.appendChild(tableShortcut);
918
+ }
919
+
920
+ chartHeading.innerHTML = 'Chart graphic.';
921
+ chart.renderTo.insertBefore(chartHeading, chart.renderTo.firstChild);
922
+ chart.renderTo.insertBefore(hiddenSection, chart.renderTo.firstChild);
923
+
924
+ // Hide the section and the chart heading
925
+ merge(true, chartHeading.style, hiddenStyle);
926
+ merge(true, hiddenSection.style, hiddenStyle);
927
+ };
928
+
929
+
930
+ // Make chart container accessible, and wrap table functionality
931
+ H.Chart.prototype.callbacks.push(function(chart) {
932
+ var options = chart.options,
933
+ a11yOptions = options.accessibility;
934
+
935
+ if (!a11yOptions.enabled) {
936
+ return;
937
+ }
938
+
939
+ var titleElement = doc.createElementNS('http://www.w3.org/2000/svg', 'title'),
940
+ exportGroupElement = doc.createElementNS('http://www.w3.org/2000/svg', 'g'),
941
+ descElement = chart.container.getElementsByTagName('desc')[0],
942
+ textElements = chart.container.getElementsByTagName('text'),
943
+ titleId = 'highcharts-title-' + chart.index,
944
+ tableId = 'highcharts-data-table-' + chart.index,
945
+ chartTitle = options.title.text || 'Chart',
946
+ oldColumnHeaderFormatter = options.exporting && options.exporting.csv && options.exporting.csv.columnHeaderFormatter,
947
+ topLevelColumns = [];
948
+
949
+ // Add SVG title/desc tags
950
+ titleElement.textContent = chartTitle;
951
+ titleElement.id = titleId;
952
+ descElement.parentNode.insertBefore(titleElement, descElement);
953
+ chart.renderTo.setAttribute('role', 'region');
954
+ chart.renderTo.setAttribute('aria-label', chartTitle + '. Use up and down arrows to navigate.');
955
+
956
+ // Set screen reader properties on export menu
957
+ if (chart.exportSVGElements && chart.exportSVGElements[0] && chart.exportSVGElements[0].element) {
958
+ var oldExportCallback = chart.exportSVGElements[0].element.onclick,
959
+ parent = chart.exportSVGElements[0].element.parentNode;
960
+ chart.exportSVGElements[0].element.onclick = function() {
961
+ oldExportCallback.apply(this, Array.prototype.slice.call(arguments));
962
+ chart.addAccessibleContextMenuAttribs();
963
+ chart.highlightExportItem(0);
964
+ };
965
+ chart.exportSVGElements[0].element.setAttribute('role', 'button');
966
+ chart.exportSVGElements[0].element.setAttribute('aria-label', 'View export menu');
967
+ exportGroupElement.appendChild(chart.exportSVGElements[0].element);
968
+ exportGroupElement.setAttribute('role', 'region');
969
+ exportGroupElement.setAttribute('aria-label', 'Chart export menu');
970
+ parent.appendChild(exportGroupElement);
971
+ }
972
+
973
+ // Set screen reader properties on input boxes for range selector. We need to do this regardless of whether or not these are visible, as they are
974
+ // by default part of the page's tabindex unless we set them to -1.
975
+ if (chart.rangeSelector) {
976
+ each(['minInput', 'maxInput'], function(key, i) {
977
+ if (chart.rangeSelector[key]) {
978
+ chart.rangeSelector[key].setAttribute('tabindex', '-1');
979
+ chart.rangeSelector[key].setAttribute('role', 'textbox');
980
+ chart.rangeSelector[key].setAttribute('aria-label', 'Select ' + (i ? 'end' : 'start') + ' date.');
981
+ }
982
+ });
983
+ }
984
+
985
+ // Hide text elements from screen readers
986
+ each(textElements, function(el) {
987
+ el.setAttribute('aria-hidden', 'true');
988
+ });
989
+
990
+ // Add top-secret screen reader region
991
+ chart.addScreenReaderRegion(tableId);
992
+
993
+ // Enable keyboard navigation
994
+ if (a11yOptions.keyboardNavigation) {
995
+ chart.addKeyboardNavEvents();
996
+ }
997
+
998
+ /* Wrap table functionality from export-csv */
999
+
1000
+ // Keep track of columns
1001
+ merge(true, options.exporting, {
1002
+ csv: {
1003
+ columnHeaderFormatter: function(series, key, keyLength) {
1004
+ var prevCol = topLevelColumns[topLevelColumns.length - 1];
1005
+ if (keyLength > 1) {
1006
+ // We need multiple levels of column headers
1007
+ // Populate a list of column headers to add in addition to the ones added by export-csv
1008
+ if ((prevCol && prevCol.text) !== series.name) {
1009
+ topLevelColumns.push({
1010
+ text: series.name,
1011
+ span: keyLength
1012
+ });
1013
+ }
1014
+ }
1015
+ if (oldColumnHeaderFormatter) {
1016
+ return oldColumnHeaderFormatter.call(this, series, key, keyLength);
1017
+ }
1018
+ return keyLength > 1 ? key : series.name;
1019
+ }
1020
+ }
1021
+ });
1022
+
1023
+ // Add ID and title/caption to table HTML
1024
+ H.wrap(chart, 'getTable', function(proceed) {
1025
+ return proceed.apply(this, Array.prototype.slice.call(arguments, 1))
1026
+ .replace('<table>', '<table id="' + tableId + '" summary="Table representation of chart"><caption>' + chartTitle + '</caption>');
1027
+ });
1028
+
1029
+ // Add accessibility attributes and top level columns
1030
+ H.wrap(chart, 'viewData', function(proceed) {
1031
+ if (!this.insertedTable) {
1032
+ proceed.apply(this, Array.prototype.slice.call(arguments, 1));
1033
+
1034
+ var table = doc.getElementById(tableId),
1035
+ body = table.getElementsByTagName('tbody')[0],
1036
+ firstRow = body.firstChild.children,
1037
+ columnHeaderRow = '<tr><td></td>',
1038
+ cell,
1039
+ newCell;
1040
+
1041
+ // Make table focusable by script
1042
+ table.setAttribute('tabindex', '-1');
1043
+
1044
+ // Create row headers
1045
+ each(body.children, function(el) {
1046
+ cell = el.firstChild;
1047
+ newCell = doc.createElement('th');
1048
+ newCell.setAttribute('scope', 'row');
1049
+ newCell.innerHTML = cell.innerHTML;
1050
+ cell.parentNode.replaceChild(newCell, cell);
1051
+ });
1052
+
1053
+ // Set scope for column headers
1054
+ each(firstRow, function(el) {
1055
+ if (el.tagName === 'TH') {
1056
+ el.setAttribute('scope', 'col');
1057
+ }
1058
+ });
1059
+
1060
+ // Add top level columns
1061
+ if (topLevelColumns.length) {
1062
+ each(topLevelColumns, function(col) {
1063
+ columnHeaderRow += '<th scope="col" colspan="' + col.span + '">' + col.text + '</th>';
1064
+ });
1065
+ body.insertAdjacentHTML('afterbegin', columnHeaderRow);
1066
+ }
1067
+ }
1068
+ });
1069
+ });
1070
+
1071
+ }(Highcharts));
1072
+ }));