accessibility.src.js
99.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
/**
* @license Highcharts JS v6.2.0 (2018-10-17)
* Accessibility module
*
* (c) 2010-2017 Highsoft AS
* Author: Oystein Moseng
*
* License: www.highcharts.com/license
*/
'use strict';
(function (factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory;
} else if (typeof define === 'function' && define.amd) {
define(function () {
return factory;
});
} else {
factory(Highcharts);
}
}(function (Highcharts) {
(function (H) {
/**
* Accessibility module - internationalization support
*
* (c) 2010-2018 Highsoft AS
* Author: Øystein Moseng
*
* License: www.highcharts.com/license
*/
var each = H.each,
pick = H.pick;
/**
* String trim that works for IE6-8 as well.
* @param {string} str The input string
* @return {string} The trimmed string
*/
function stringTrim(str) {
return str.trim && str.trim() || str.replace(/^\s+|\s+$/g, '');
}
/**
* i18n utility function. Format a single array or plural statement in a format
* string. If the statement is not an array or plural statement, returns the
* statement within brackets. Invalid array statements return an empty string.
*/
function formatExtendedStatement(statement, ctx) {
var eachStart = statement.indexOf('#each('),
pluralStart = statement.indexOf('#plural('),
indexStart = statement.indexOf('['),
indexEnd = statement.indexOf(']'),
arr,
result;
// Dealing with an each-function?
if (eachStart > -1) {
var eachEnd = statement.slice(eachStart).indexOf(')') + eachStart,
preEach = statement.substring(0, eachStart),
postEach = statement.substring(eachEnd + 1),
eachStatement = statement.substring(eachStart + 6, eachEnd),
eachArguments = eachStatement.split(','),
lenArg = Number(eachArguments[1]),
len;
result = '';
arr = ctx[eachArguments[0]];
if (arr) {
lenArg = isNaN(lenArg) ? arr.length : lenArg;
len = lenArg < 0 ?
arr.length + lenArg :
Math.min(lenArg, arr.length); // Overshoot
// Run through the array for the specified length
for (var i = 0; i < len; ++i) {
result += preEach + arr[i] + postEach;
}
}
return result.length ? result : '';
}
// Dealing with a plural-function?
if (pluralStart > -1) {
var pluralEnd = statement.slice(pluralStart).indexOf(')') + pluralStart,
pluralStatement = statement.substring(pluralStart + 8, pluralEnd),
pluralArguments = pluralStatement.split(','),
num = Number(ctx[pluralArguments[0]]);
switch (num) {
case 0:
result = pick(pluralArguments[4], pluralArguments[1]);
break;
case 1:
result = pick(pluralArguments[2], pluralArguments[1]);
break;
case 2:
result = pick(pluralArguments[3], pluralArguments[1]);
break;
default:
result = pluralArguments[1];
}
return result ? stringTrim(result) : '';
}
// Array index
if (indexStart > -1) {
var arrayName = statement.substring(0, indexStart),
ix = Number(statement.substring(indexStart + 1, indexEnd)),
val;
arr = ctx[arrayName];
if (!isNaN(ix) && arr) {
if (ix < 0) {
val = arr[arr.length + ix];
// Handle negative overshoot
if (val === undefined) {
val = arr[0];
}
} else {
val = arr[ix];
// Handle positive overshoot
if (val === undefined) {
val = arr[arr.length - 1];
}
}
}
return val !== undefined ? val : '';
}
// Standard substitution, delegate to H.format or similar
return '{' + statement + '}';
}
/**
* i18n formatting function. Extends H.format() functionality by also handling
* arrays and plural conditionals. Arrays can be indexed as follows:
*
* Format: 'This is the first index: {myArray[0]}. The last: {myArray[-1]}.'
* Context: { myArray: [0, 1, 2, 3, 4, 5] }
* Result: 'This is the first index: 0. The last: 5.'
*
* They can also be iterated using the #each() function. This will repeat the
* contents of the bracket expression for each element. Example:
*
* Format: 'List contains: {#each(myArray)cm }'
* Context: { myArray: [0, 1, 2] }
* Result: 'List contains: 0cm 1cm 2cm '
*
* The #each() function optionally takes a length parameter. If positive, this
* parameter specifies the max number of elements to iterate through. If
* negative, the function will subtract the number from the length of the array.
* Use this to stop iterating before the array ends. Example:
*
* Format: 'List contains: {#each(myArray, -1) }and {myArray[-1]}.'
* Context: { myArray: [0, 1, 2, 3] }
* Result: 'List contains: 0, 1, 2, and 3.'
*
* Use the #plural() function to pick a string depending on whether or not a
* context object is 1. Arguments are #plural(obj, plural, singular). Example:
*
* Format: 'Has {numPoints} {#plural(numPoints, points, point}.'
* Context: { numPoints: 5 }
* Result: 'Has 5 points.'
*
* Optionally there are additional parameters for dual and none:
* #plural(obj,plural,singular,dual,none)
* Example:
*
* Format: 'Has {#plural(numPoints, many points, one point, two points, none}.'
* Context: { numPoints: 2 }
* Result: 'Has two points.'
*
* The dual or none parameters will take precedence if they are supplied.
*
* @param {string} formatString The string to format.
* @param {object} context Context to apply to the format string.
* @param {Time} time A `Time` instance for date formatting, passed on to
* H.format().
* @return {string} The formatted string.
*/
H.i18nFormat = function (formatString, context, time) {
var getFirstBracketStatement = function (sourceStr, offset) {
var str = sourceStr.slice(offset || 0),
startBracket = str.indexOf('{'),
endBracket = str.indexOf('}');
if (startBracket > -1 && endBracket > startBracket) {
return {
statement: str.substring(startBracket + 1, endBracket),
begin: offset + startBracket + 1,
end: offset + endBracket
};
}
},
tokens = [],
bracketRes,
constRes,
cursor = 0;
// Tokenize format string into bracket statements and constants
do {
bracketRes = getFirstBracketStatement(formatString, cursor);
constRes = formatString.substring(
cursor,
bracketRes && bracketRes.begin - 1
);
// If we have constant content before this bracket statement, add it
if (constRes.length) {
tokens.push({
value: constRes,
type: 'constant'
});
}
// Add the bracket statement
if (bracketRes) {
tokens.push({
value: bracketRes.statement,
type: 'statement'
});
}
cursor = bracketRes && bracketRes.end + 1;
} while (bracketRes);
// Perform the formatting. The formatArrayStatement function returns the
// statement in brackets if it is not an array statement, which means it
// gets picked up by H.format below.
each(tokens, function (token) {
if (token.type === 'statement') {
token.value = formatExtendedStatement(token.value, context);
}
});
// Join string back together and pass to H.format to pick up non-array
// statements.
return H.format(H.reduce(tokens, function (acc, cur) {
return acc + cur.value;
}, ''), context, time);
};
/**
* Apply context to a format string from lang options of the chart.
* @param {string} langKey Key (using dot notation) into lang option structure
* @param {object} context Context to apply to the format string
* @return {string} The formatted string
*/
H.Chart.prototype.langFormat = function (langKey, context, time) {
var keys = langKey.split('.'),
formatString = this.options.lang,
i = 0;
for (; i < keys.length; ++i) {
formatString = formatString && formatString[keys[i]];
}
return typeof formatString === 'string' && H.i18nFormat(
formatString, context, time
);
};
H.setOptions({
lang: {
/**
* Configure the accessibility strings in the chart. Requires the
* [accessibility module](//code.highcharts.com/modules/accessibility.
* js) to be loaded. For a description of the module and information
* on its features, see [Highcharts Accessibility](http://www.highcharts.
* com/docs/chart-concepts/accessibility).
*
* For more dynamic control over the accessibility functionality, see
* [accessibility.pointDescriptionFormatter](
* accessibility.pointDescriptionFormatter),
* [accessibility.seriesDescriptionFormatter](
* accessibility.seriesDescriptionFormatter), and
* [accessibility.screenReaderSectionFormatter](
* accessibility.screenReaderSectionFormatter).
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility
*/
accessibility: {
/* eslint-disable max-len */
screenReaderRegionLabel: 'Chart screen reader information.',
navigationHint: 'Use regions/landmarks to skip ahead to chart {#plural(numSeries, and navigate between data series,)}',
defaultChartTitle: 'Chart',
longDescriptionHeading: 'Long description.',
noDescription: 'No description available.',
structureHeading: 'Structure.',
viewAsDataTable: 'View as data table.',
chartHeading: 'Chart graphic.',
chartContainerLabel: 'Interactive chart. {title}. Use up and down arrows to navigate with most screen readers.',
rangeSelectorMinInput: 'Select start date.',
rangeSelectorMaxInput: 'Select end date.',
tableSummary: 'Table representation of chart.',
mapZoomIn: 'Zoom chart',
mapZoomOut: 'Zoom out chart',
rangeSelectorButton: 'Select range {buttonText}',
legendItem: 'Toggle visibility of series {itemName}',
/**
* Title element text for the chart SVG element. Leave this
* empty to disable adding the title element. Browsers will display
* this content when hovering over elements in the chart. Assistive
* technology may use this element to label the chart.
*
* @since 6.0.8
*/
svgContainerTitle: '{chartTitle}',
/**
* Descriptions of lesser known series types. The relevant
* description is added to the screen reader information region
* when these series types are used.
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility.seriesTypeDescriptions
*/
seriesTypeDescriptions: {
boxplot: 'Box plot charts are typically used to display ' +
'groups of statistical data. Each data point in the ' +
'chart can have up to 5 values: minimum, lower quartile, ' +
'median, upper quartile, and maximum.',
arearange: 'Arearange charts are line charts displaying a ' +
'range between a lower and higher value for each point.',
areasplinerange: 'These charts are line charts displaying a ' +
'range between a lower and higher value for each point.',
bubble: 'Bubble charts are scatter charts where each data ' +
'point also has a size value.',
columnrange: 'Columnrange charts are column charts ' +
'displaying a range between a lower and higher value for ' +
'each point.',
errorbar: 'Errorbar series are used to display the ' +
'variability of the data.',
funnel: 'Funnel charts are used to display reduction of data ' +
'in stages.',
pyramid: 'Pyramid charts consist of a single pyramid with ' +
'item heights corresponding to each point value.',
waterfall: 'A waterfall chart is a column chart where each ' +
'column contributes towards a total end value.'
},
/**
* Chart type description strings. This is added to the chart
* information region.
*
* If there is only a single series type used in the chart, we use
* the format string for the series type, or default if missing.
* There is one format string for cases where there is only a single
* series in the chart, and one for multiple series of the same
* type.
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility.chartTypes
*/
chartTypes: {
emptyChart: 'Empty chart',
mapTypeDescription: 'Map of {mapTitle} with {numSeries} data series.',
unknownMap: 'Map of unspecified region with {numSeries} data series.',
combinationChart: 'Combination chart with {numSeries} data series.',
defaultSingle: 'Chart with {numPoints} data {#plural(numPoints, points, point)}.',
defaultMultiple: 'Chart with {numSeries} data series.',
splineSingle: 'Line chart with {numPoints} data {#plural(numPoints, points, point)}.',
splineMultiple: 'Line chart with {numSeries} lines.',
lineSingle: 'Line chart with {numPoints} data {#plural(numPoints, points, point)}.',
lineMultiple: 'Line chart with {numSeries} lines.',
columnSingle: 'Bar chart with {numPoints} {#plural(numPoints, bars, bar)}.',
columnMultiple: 'Bar chart with {numSeries} data series.',
barSingle: 'Bar chart with {numPoints} {#plural(numPoints, bars, bar)}.',
barMultiple: 'Bar chart with {numSeries} data series.',
pieSingle: 'Pie chart with {numPoints} {#plural(numPoints, slices, slice)}.',
pieMultiple: 'Pie chart with {numSeries} pies.',
scatterSingle: 'Scatter chart with {numPoints} {#plural(numPoints, points, point)}.',
scatterMultiple: 'Scatter chart with {numSeries} data series.',
boxplotSingle: 'Boxplot with {numPoints} {#plural(numPoints, boxes, box)}.',
boxplotMultiple: 'Boxplot with {numSeries} data series.',
bubbleSingle: 'Bubble chart with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
bubbleMultiple: 'Bubble chart with {numSeries} data series.'
},
/**
* Axis description format strings.
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility.axis
*/
axis: {
xAxisDescriptionSingular: 'The chart has 1 X axis displaying {names[0]}.',
xAxisDescriptionPlural: 'The chart has {numAxes} X axes displaying {#each(names, -1) }and {names[-1]}',
yAxisDescriptionSingular: 'The chart has 1 Y axis displaying {names[0]}.',
yAxisDescriptionPlural: 'The chart has {numAxes} Y axes displaying {#each(names, -1) }and {names[-1]}'
},
/**
* Exporting menu format strings for accessibility module.
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility.exporting
*/
exporting: {
chartMenuLabel: 'Chart export',
menuButtonLabel: 'View export menu',
exportRegionLabel: 'Chart export menu'
},
/**
* Lang configuration for different series types. For more dynamic
* control over the series element descriptions, see
* [accessibility.seriesDescriptionFormatter](
* accessibility.seriesDescriptionFormatter).
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility.series
*/
series: {
/**
* Lang configuration for the series main summary. Each series
* type has two modes:
* 1. This series type is the only series type used in the
* chart
* 2. This is a combination chart with multiple series types
*
* If a definition does not exist for the specific series type
* and mode, the 'default' lang definitions are used.
*
* @since 6.0.6
* @type {Object}
* @optionparent lang.accessibility.series.summary
*/
summary: {
default: '{name}, series {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
defaultCombination: '{name}, series {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
line: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
lineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
spline: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
splineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
column: '{name}, bar series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bars, bar)}.',
columnCombination: '{name}, series {ix} of {numSeries}. Bar series with {numPoints} {#plural(numPoints, bars, bar)}.',
bar: '{name}, bar series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bars, bar)}.',
barCombination: '{name}, series {ix} of {numSeries}. Bar series with {numPoints} {#plural(numPoints, bars, bar)}.',
pie: '{name}, pie {ix} of {numSeries} with {numPoints} {#plural(numPoints, slices, slice)}.',
pieCombination: '{name}, series {ix} of {numSeries}. Pie with {numPoints} {#plural(numPoints, slices, slice)}.',
scatter: '{name}, scatter plot {ix} of {numSeries} with {numPoints} {#plural(numPoints, points, point)}.',
scatterCombination: '{name}, series {ix} of {numSeries}, scatter plot with {numPoints} {#plural(numPoints, points, point)}.',
boxplot: '{name}, boxplot {ix} of {numSeries} with {numPoints} {#plural(numPoints, boxes, box)}.',
boxplotCombination: '{name}, series {ix} of {numSeries}. Boxplot with {numPoints} {#plural(numPoints, boxes, box)}.',
bubble: '{name}, bubble series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
bubbleCombination: '{name}, series {ix} of {numSeries}. Bubble series with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
map: '{name}, map {ix} of {numSeries} with {numPoints} {#plural(numPoints, areas, area)}.',
mapCombination: '{name}, series {ix} of {numSeries}. Map with {numPoints} {#plural(numPoints, areas, area)}.',
mapline: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
maplineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
mapbubble: '{name}, bubble series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
mapbubbleCombination: '{name}, series {ix} of {numSeries}. Bubble series with {numPoints} {#plural(numPoints, bubbles, bubble)}.'
},
/* eslint-enable max-len */
/**
* User supplied description text. This is added after the main
* summary if present.
*
* @type {String}
* @since 6.0.6
*/
description: '{description}',
/**
* xAxis description for series if there are multiple xAxes in
* the chart.
*
* @type {String}
* @since 6.0.6
*/
xAxisDescription: 'X axis, {name}',
/**
* yAxis description for series if there are multiple yAxes in
* the chart.
*
* @type {String}
* @since 6.0.6
*/
yAxisDescription: 'Y axis, {name}'
}
}
}
});
}(Highcharts));
(function (H) {
/**
* Accessibility module - Screen Reader support
*
* (c) 2010-2017 Highsoft AS
* Author: Oystein Moseng
*
* License: www.highcharts.com/license
*/
var win = H.win,
doc = win.document,
each = H.each,
map = H.map,
erase = H.erase,
addEvent = H.addEvent,
merge = H.merge,
// CSS style to hide element from visual users while still exposing it to
// screen readers
hiddenStyle = {
position: 'absolute',
left: '-9999px',
top: 'auto',
width: '1px',
height: '1px',
overflow: 'hidden'
};
// If a point has one of the special keys defined, we expose all keys to the
// screen reader.
H.Series.prototype.commonKeys = ['name', 'id', 'category', 'x', 'value', 'y'];
H.Series.prototype.specialKeys = [
'z', 'open', 'high', 'q3', 'median', 'q1', 'low', 'close'
];
if (H.seriesTypes.pie) {
// A pie is always simple. Don't quote me on that.
H.seriesTypes.pie.prototype.specialKeys = [];
}
/**
* HTML encode some characters vulnerable for XSS.
* @param {string} html The input string
* @return {string} The excaped string
*/
function htmlencode(html) {
return html
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/\//g, '/');
}
/**
* Strip HTML tags away from a string. Used for aria-label attributes, painting
* on a canvas will fail if the text contains tags.
* @param {String} s The input string
* @return {String} The filtered string
*/
function stripTags(s) {
return typeof s === 'string' ? s.replace(/<\/?[^>]+(>|$)/g, '') : s;
}
/**
* Accessibility options
*/
H.setOptions({
/**
* Options for configuring accessibility for the chart. Requires the
* [accessibility module](//code.highcharts.com/modules/accessibility.
* js) to be loaded. For a description of the module and information
* on its features, see [Highcharts Accessibility](http://www.highcharts.
* com/docs/chart-concepts/accessibility).
*
* @since 5.0.0
* @type {Object}
* @optionparent accessibility
*/
accessibility: {
/**
* Whether or not to add series descriptions to charts with a single
* series.
*
* @type {Boolean}
* @default false
* @since 5.0.0
* @apioption accessibility.describeSingleSeries
*/
/**
* Function to run upon clicking the "View as Data Table" link in the
* screen reader region.
*
* By default Highcharts will insert and set focus to a data table
* representation of the chart.
*
* @type {Function}
* @since 5.0.0
* @apioption accessibility.onTableAnchorClick
*/
/**
* Date format to use for points on datetime axes when describing them
* to screen reader users.
*
* Defaults to the same format as in tooltip.
*
* For an overview of the replacement codes, see
* [dateFormat](/class-reference/Highcharts#dateFormat).
*
* @type {String}
* @see [pointDateFormatter](#accessibility.pointDateFormatter)
* @since 5.0.0
* @apioption accessibility.pointDateFormat
*/
/**
* Formatter function to determine the date/time format used with
* points on datetime axes when describing them to screen reader users.
* Receives one argument, `point`, referring to the point to describe.
* Should return a date format string compatible with
* [dateFormat](/class-reference/Highcharts#dateFormat).
*
* @type {Function}
* @see [pointDateFormat](#accessibility.pointDateFormat)
* @since 5.0.0
* @apioption accessibility.pointDateFormatter
*/
/**
* Formatter function to use instead of the default for point
* descriptions.
* Receives one argument, `point`, referring to the point to describe.
* Should return a String with the description of the point for a screen
* reader user.
*
* @type {Function}
* @see [point.description](#series.line.data.description)
* @since 5.0.0
* @apioption accessibility.pointDescriptionFormatter
*/
/**
* Formatter function to use instead of the default for series
* descriptions. Receives one argument, `series`, referring to the
* series to describe. Should return a String with the description of
* the series for a screen reader user.
*
* @type {Function}
* @see [series.description](#plotOptions.series.description)
* @since 5.0.0
* @apioption accessibility.seriesDescriptionFormatter
*/
/**
* Enable accessibility features for the chart.
*
* @type {Boolean}
* @default true
* @since 5.0.0
*/
enabled: true,
/**
* When a series contains more points than this, we no longer expose
* information about individual points to screen readers.
*
* Set to `false` to disable.
*
* @type {Number|Boolean}
* @since 5.0.0
*/
pointDescriptionThreshold: false, // set to false to disable
/**
* A formatter function to create the HTML contents of the hidden screen
* reader information region. Receives one argument, `chart`, referring
* to the chart object. Should return a String with the HTML content
* of the region.
*
* The link to view the chart as a data table will be added
* automatically after the custom HTML content.
*
* @type {Function}
* @default undefined
* @since 5.0.0
*/
screenReaderSectionFormatter: function (chart) {
var options = chart.options,
chartTypes = chart.types || [],
formatContext = {
chart: chart,
numSeries: chart.series && chart.series.length
},
// Build axis info - but not for pies and maps. Consider not
// adding for certain other types as well (funnel, pyramid?)
axesDesc = (
chartTypes.length === 1 && chartTypes[0] === 'pie' ||
chartTypes[0] === 'map'
) && {} || chart.getAxesDescription();
return '<div>' + chart.langFormat(
'accessibility.navigationHint', formatContext
) + '</div><h3>' +
(
options.title.text ?
htmlencode(options.title.text) :
chart.langFormat(
'accessibility.defaultChartTitle', formatContext
)
) +
(
options.subtitle && options.subtitle.text ?
'. ' + htmlencode(options.subtitle.text) :
''
) +
'</h3><h4>' + chart.langFormat(
'accessibility.longDescriptionHeading', formatContext
) + '</h4><div>' +
(
options.chart.description || chart.langFormat(
'accessibility.noDescription', formatContext
)
) +
'</div><h4>' + chart.langFormat(
'accessibility.structureHeading', formatContext
) + '</h4><div>' +
(
options.chart.typeDescription ||
chart.getTypeDescription()
) + '</div>' +
(axesDesc.xAxis ? (
'<div>' + axesDesc.xAxis + '</div>'
) : '') +
(axesDesc.yAxis ? (
'<div>' + axesDesc.yAxis + '</div>'
) : '');
}
}
});
/**
* A text description of the chart.
*
* If the Accessibility module is loaded, this is included by default
* as a long description of the chart and its contents in the hidden
* screen reader information region.
*
* @type {String}
* @see [typeDescription](#chart.typeDescription)
* @default undefined
* @since 5.0.0
* @apioption chart.description
*/
/**
* A text description of the chart type.
*
* If the Accessibility module is loaded, this will be included in the
* description of the chart in the screen reader information region.
*
*
* Highcharts will by default attempt to guess the chart type, but for
* more complex charts it is recommended to specify this property for
* clarity.
*
* @type {String}
* @default undefined
* @since 5.0.0
* @apioption chart.typeDescription
*/
// Utility function. Reverses child nodes of a DOM element
function reverseChildNodes(node) {
var i = node.childNodes.length;
while (i--) {
node.appendChild(node.childNodes[i]);
}
}
// Whenever drawing series, put info on DOM elements
H.addEvent(H.Series, 'afterRender', function () {
if (this.chart.options.accessibility.enabled) {
this.setA11yDescription();
}
});
// Put accessible info on series and points of a series
H.Series.prototype.setA11yDescription = function () {
var a11yOptions = this.chart.options.accessibility,
firstPointEl = (
this.points &&
this.points.length &&
this.points[0].graphic &&
this.points[0].graphic.element
),
seriesEl = (
firstPointEl &&
firstPointEl.parentNode || this.graph &&
this.graph.element || this.group &&
this.group.element
); // Could be tracker series depending on series type
if (seriesEl) {
// For some series types the order of elements do not match the order of
// points in series. In that case we have to reverse them in order for
// AT to read them out in an understandable order
if (seriesEl.lastChild === firstPointEl) {
reverseChildNodes(seriesEl);
}
// Make individual point elements accessible if possible. Note: If
// markers are disabled there might not be any elements there to make
// accessible.
if (
this.points && (
this.points.length < a11yOptions.pointDescriptionThreshold ||
a11yOptions.pointDescriptionThreshold === false
)
) {
each(this.points, function (point) {
if (point.graphic) {
point.graphic.element.setAttribute('role', 'img');
point.graphic.element.setAttribute('tabindex', '-1');
point.graphic.element.setAttribute('aria-label', stripTags(
point.series.options.pointDescriptionFormatter &&
point.series.options.pointDescriptionFormatter(point) ||
a11yOptions.pointDescriptionFormatter &&
a11yOptions.pointDescriptionFormatter(point) ||
point.buildPointInfoString()
));
}
});
}
// Make series element accessible
if (this.chart.series.length > 1 || a11yOptions.describeSingleSeries) {
seriesEl.setAttribute(
'role',
this.options.exposeElementToA11y ? 'img' : 'region'
);
seriesEl.setAttribute('tabindex', '-1');
seriesEl.setAttribute(
'aria-label',
stripTags(
a11yOptions.seriesDescriptionFormatter &&
a11yOptions.seriesDescriptionFormatter(this) ||
this.buildSeriesInfoString()
)
);
}
}
};
// Return string with information about series
H.Series.prototype.buildSeriesInfoString = function () {
var chart = this.chart,
desc = this.description || this.options.description,
description = desc && chart.langFormat(
'accessibility.series.description', {
description: desc,
series: this
}
),
xAxisInfo = chart.langFormat(
'accessibility.series.xAxisDescription',
{
name: this.xAxis && this.xAxis.getDescription(),
series: this
}
),
yAxisInfo = chart.langFormat(
'accessibility.series.yAxisDescription',
{
name: this.yAxis && this.yAxis.getDescription(),
series: this
}
),
summaryContext = {
name: this.name || '',
ix: this.index + 1,
numSeries: chart.series.length,
numPoints: this.points.length,
series: this
},
combination = chart.types.length === 1 ? '' : 'Combination',
summary = chart.langFormat(
'accessibility.series.summary.' + this.type + combination,
summaryContext
) || chart.langFormat(
'accessibility.series.summary.default' + combination,
summaryContext
);
return summary + (description ? ' ' + description : '') + (
chart.yAxis.length > 1 && this.yAxis ?
' ' + yAxisInfo : ''
) + (
chart.xAxis.length > 1 && this.xAxis ?
' ' + xAxisInfo : ''
);
};
// Return string with information about point
H.Point.prototype.buildPointInfoString = function () {
var point = this,
series = point.series,
a11yOptions = series.chart.options.accessibility,
infoString = '',
dateTimePoint = series.xAxis && series.xAxis.isDatetimeAxis,
timeDesc =
dateTimePoint &&
series.chart.time.dateFormat(
a11yOptions.pointDateFormatter &&
a11yOptions.pointDateFormatter(point) ||
a11yOptions.pointDateFormat ||
H.Tooltip.prototype.getXDateFormat.call(
{
getDateFormat: H.Tooltip.prototype.getDateFormat,
chart: series.chart
},
point,
series.chart.options.tooltip,
series.xAxis
),
point.x
),
hasSpecialKey = H.find(series.specialKeys, function (key) {
return point[key] !== undefined;
});
// If the point has one of the less common properties defined, display all
// that are defined
if (hasSpecialKey) {
if (dateTimePoint) {
infoString = timeDesc;
}
each(series.commonKeys.concat(series.specialKeys), function (key) {
if (point[key] !== undefined && !(dateTimePoint && key === 'x')) {
infoString += (infoString ? '. ' : '') +
key + ', ' +
point[key];
}
});
} else {
// Pick and choose properties for a succint label
infoString =
(
this.name ||
timeDesc ||
this.category ||
this.id ||
'x, ' + this.x
) + ', ' +
(this.value !== undefined ? this.value : this.y);
}
return (this.index + 1) + '. ' + infoString + '.' +
(this.description ? ' ' + this.description : '');
};
// Get descriptive label for axis
H.Axis.prototype.getDescription = function () {
return (
this.userOptions && this.userOptions.description ||
this.axisTitle && this.axisTitle.textStr ||
this.options.id ||
this.categories && 'categories' ||
this.isDatetimeAxis && 'Time' ||
'values'
);
};
// Whenever adding or removing series, keep track of types present in chart
addEvent(H.Series, 'afterInit', function () {
var chart = this.chart;
if (chart.options.accessibility.enabled) {
chart.types = chart.types || [];
// Add type to list if does not exist
if (chart.types.indexOf(this.type) < 0) {
chart.types.push(this.type);
}
}
});
addEvent(H.Series, 'remove', function () {
var chart = this.chart,
removedSeries = this,
hasType = false;
// Check if any of the other series have the same type as this one.
// Otherwise remove it from the list.
each(chart.series, function (s) {
if (
s !== removedSeries &&
chart.types.indexOf(removedSeries.type) < 0
) {
hasType = true;
}
});
if (!hasType) {
erase(chart.types, removedSeries.type);
}
});
// Return simplified description of chart type. Some types will not be familiar
// to most screen reader users, but in those cases we try to add a description
// of the type.
H.Chart.prototype.getTypeDescription = function () {
var firstType = this.types && this.types[0],
firstSeries = this.series && this.series[0] || {},
mapTitle = firstSeries.mapTitle,
typeDesc = this.langFormat(
'accessibility.seriesTypeDescriptions.' + firstType,
{ chart: this }
),
formatContext = {
numSeries: this.series.length,
numPoints: firstSeries.points && firstSeries.points.length,
chart: this,
mapTitle: mapTitle
},
multi = this.series && this.series.length === 1 ? 'Single' : 'Multiple';
if (!firstType) {
return this.langFormat(
'accessibility.chartTypes.emptyChart', formatContext
);
} else if (firstType === 'map') {
return mapTitle ?
this.langFormat(
'accessibility.chartTypes.mapTypeDescription',
formatContext
) :
this.langFormat(
'accessibility.chartTypes.unknownMap',
formatContext
);
} else if (this.types.length > 1) {
return this.langFormat(
'accessibility.chartTypes.combinationChart', formatContext
);
}
return (
this.langFormat(
'accessibility.chartTypes.' + firstType + multi,
formatContext
) ||
this.langFormat(
'accessibility.chartTypes.default' + multi,
formatContext
)
) +
(typeDesc ? ' ' + typeDesc : '');
};
// Return object with text description of each of the chart's axes
H.Chart.prototype.getAxesDescription = function () {
var numXAxes = this.xAxis.length,
numYAxes = this.yAxis.length,
desc = {};
if (numXAxes) {
desc.xAxis = this.langFormat(
'accessibility.axis.xAxisDescription' + (
numXAxes > 1 ? 'Plural' : 'Singular'
),
{
chart: this,
names: map(this.xAxis, function (axis) {
return axis.getDescription();
}),
numAxes: numXAxes
}
);
}
if (numYAxes) {
desc.yAxis = this.langFormat(
'accessibility.axis.yAxisDescription' + (
numYAxes > 1 ? 'Plural' : 'Singular'
),
{
chart: this,
names: map(this.yAxis, function (axis) {
return axis.getDescription();
}),
numAxes: numYAxes
}
);
}
return desc;
};
// Set a11y attribs on exporting menu
H.Chart.prototype.addAccessibleContextMenuAttribs = function () {
var exportList = this.exportDivElements;
if (exportList) {
// Set tabindex on the menu items to allow focusing by script
// Set role to give screen readers a chance to pick up the contents
each(exportList, function (item) {
if (item.tagName === 'DIV' &&
!(item.children && item.children.length)) {
item.setAttribute('role', 'menuitem');
item.setAttribute('tabindex', -1);
}
});
// Set accessibility properties on parent div
exportList[0].parentNode.setAttribute('role', 'menu');
exportList[0].parentNode.setAttribute('aria-label',
this.langFormat(
'accessibility.exporting.chartMenuLabel', { chart: this }
)
);
}
};
// Add screen reader region to chart.
// tableId is the HTML id of the table to focus when clicking the table anchor
// in the screen reader region.
H.Chart.prototype.addScreenReaderRegion = function (id, tableId) {
var chart = this,
hiddenSection = chart.screenReaderRegion = doc.createElement('div'),
tableShortcut = doc.createElement('h4'),
tableShortcutAnchor = doc.createElement('a'),
chartHeading = doc.createElement('h4');
hiddenSection.setAttribute('id', id);
hiddenSection.setAttribute('role', 'region');
hiddenSection.setAttribute(
'aria-label',
chart.langFormat(
'accessibility.screenReaderRegionLabel', { chart: this }
)
);
hiddenSection.innerHTML = chart.options.accessibility
.screenReaderSectionFormatter(chart);
// Add shortcut to data table if export-data is loaded
if (chart.getCSV) {
tableShortcutAnchor.innerHTML = chart.langFormat(
'accessibility.viewAsDataTable', { chart: chart }
);
tableShortcutAnchor.href = '#' + tableId;
// Make this unreachable by user tabbing
tableShortcutAnchor.setAttribute('tabindex', '-1');
tableShortcutAnchor.onclick =
chart.options.accessibility.onTableAnchorClick || function () {
chart.viewData();
doc.getElementById(tableId).focus();
};
tableShortcut.appendChild(tableShortcutAnchor);
hiddenSection.appendChild(tableShortcut);
}
// Note: JAWS seems to refuse to read aria-label on the container, so add an
// h4 element as title for the chart.
chartHeading.innerHTML = chart.langFormat(
'accessibility.chartHeading', { chart: chart }
);
chart.renderTo.insertBefore(chartHeading, chart.renderTo.firstChild);
chart.renderTo.insertBefore(hiddenSection, chart.renderTo.firstChild);
// Hide the section and the chart heading
merge(true, chartHeading.style, hiddenStyle);
merge(true, hiddenSection.style, hiddenStyle);
};
// Make chart container accessible, and wrap table functionality
H.Chart.prototype.callbacks.push(function (chart) {
var options = chart.options,
a11yOptions = options.accessibility;
if (!a11yOptions.enabled) {
return;
}
var titleElement,
descElement = chart.container.getElementsByTagName('desc')[0],
textElements = chart.container.getElementsByTagName('text'),
titleId = 'highcharts-title-' + chart.index,
tableId = 'highcharts-data-table-' + chart.index,
hiddenSectionId = 'highcharts-information-region-' + chart.index,
chartTitle = options.title.text || chart.langFormat(
'accessibility.defaultChartTitle', { chart: chart }
),
svgContainerTitle = stripTags(chart.langFormat(
'accessibility.svgContainerTitle', {
chartTitle: chartTitle
}
));
// Add SVG title tag if it is set
if (svgContainerTitle.length) {
titleElement = doc.createElementNS(
'http://www.w3.org/2000/svg',
'title'
);
titleElement.textContent = svgContainerTitle;
titleElement.id = titleId;
descElement.parentNode.insertBefore(titleElement, descElement);
}
chart.renderTo.setAttribute('role', 'region');
chart.renderTo.setAttribute(
'aria-label',
chart.langFormat(
'accessibility.chartContainerLabel',
{
title: stripTags(chartTitle),
chart: chart
}
)
);
// Set screen reader properties on export menu
if (
chart.exportSVGElements &&
chart.exportSVGElements[0] &&
chart.exportSVGElements[0].element
) {
// Set event handler on button
var button = chart.exportSVGElements[0].element,
oldExportCallback = button.onclick;
button.onclick = function () {
oldExportCallback.apply(
this,
Array.prototype.slice.call(arguments)
);
chart.addAccessibleContextMenuAttribs();
chart.highlightExportItem(0);
};
// Set props on button
button.setAttribute('role', 'button');
button.setAttribute(
'aria-label',
chart.langFormat(
'accessibility.exporting.menuButtonLabel', { chart: chart }
)
);
// Set props on group
chart.exportingGroup.element.setAttribute('role', 'region');
chart.exportingGroup.element.setAttribute('aria-label',
chart.langFormat(
'accessibility.exporting.exportRegionLabel', { chart: chart }
)
);
}
// 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
// by default part of the page's tabindex unless we set them to -1.
if (chart.rangeSelector) {
each(['minInput', 'maxInput'], function (key, i) {
if (chart.rangeSelector[key]) {
chart.rangeSelector[key].setAttribute('tabindex', '-1');
chart.rangeSelector[key].setAttribute('role', 'textbox');
chart.rangeSelector[key].setAttribute(
'aria-label',
chart.langFormat(
'accessibility.rangeSelector' +
(i ? 'MaxInput' : 'MinInput'), { chart: chart }
)
);
}
});
}
// Hide text elements from screen readers
each(textElements, function (el) {
el.setAttribute('aria-hidden', 'true');
});
// Add top-secret screen reader region
chart.addScreenReaderRegion(hiddenSectionId, tableId);
// Add ID and summary attr to table HTML
H.wrap(chart, 'getTable', function (proceed) {
return proceed.apply(this, Array.prototype.slice.call(arguments, 1))
.replace(
'<table>',
'<table id="' + tableId + '" summary="' + chart.langFormat(
'accessibility.tableSummary', { chart: chart }
) + '">'
);
});
});
}(Highcharts));
(function (H) {
/**
* Accessibility module - Keyboard navigation
*
* (c) 2010-2017 Highsoft AS
* Author: Oystein Moseng
*
* License: www.highcharts.com/license
*/
var win = H.win,
doc = win.document,
each = H.each,
addEvent = H.addEvent,
fireEvent = H.fireEvent,
merge = H.merge,
pick = H.pick,
hasSVGFocusSupport;
// Add focus border functionality to SVGElements.
// Draws a new rect on top of element around its bounding box.
H.extend(H.SVGElement.prototype, {
addFocusBorder: function (margin, style) {
// Allow updating by just adding new border
if (this.focusBorder) {
this.removeFocusBorder();
}
// Add the border rect
var bb = this.getBBox(),
pad = pick(margin, 3);
this.focusBorder = this.renderer.rect(
bb.x - pad,
bb.y - pad,
bb.width + 2 * pad,
bb.height + 2 * pad,
style && style.borderRadius
)
.addClass('highcharts-focus-border')
.attr({
stroke: style && style.stroke,
'stroke-width': style && style.strokeWidth
})
.attr({
zIndex: 99
})
.add(this.parentGroup);
},
removeFocusBorder: function () {
if (this.focusBorder) {
this.focusBorder.destroy();
delete this.focusBorder;
}
}
});
// Set for which series types it makes sense to move to the closest point with
// up/down arrows, and which series types should just move to next series.
H.Series.prototype.keyboardMoveVertical = true;
each(['column', 'pie'], function (type) {
if (H.seriesTypes[type]) {
H.seriesTypes[type].prototype.keyboardMoveVertical = false;
}
});
/**
* Strip HTML tags away from a string. Used for aria-label attributes, painting
* on a canvas will fail if the text contains tags.
* @param {String} s The input string
* @return {String} The filtered string
*/
function stripTags(s) {
return typeof s === 'string' ? s.replace(/<\/?[^>]+(>|$)/g, '') : s;
}
/**
* Get the index of a point in a series. This is needed when using e.g. data
* grouping.
*
* @param {Point} point The point to find index of.
* @return {number} The index in the series.points array of the point.
*/
function getPointIndex(point) {
var index = point.index,
points = point.series.points,
i = points.length;
if (points[index] !== point) {
while (i--) {
if (points[i] === point) {
return i;
}
}
} else {
return index;
}
}
/**
* Set default keyboard navigation options
*/
H.setOptions({
accessibility: {
/**
* Options for keyboard navigation.
*
* @type {Object}
* @since 5.0.0
* @apioption accessibility.keyboardNavigation
*/
keyboardNavigation: {
/**
* Enable keyboard navigation for the chart.
*
* @type {Boolean}
* @default true
* @since 5.0.0
* @apioption accessibility.keyboardNavigation.enabled
*/
enabled: true,
/**
* Options for the focus border drawn around elements while
* navigating through them.
*
* @type {Object}
* @sample highcharts/accessibility/custom-focus
* Custom focus ring
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder
*/
focusBorder: {
/**
* Enable/disable focus border for chart.
*
* @type {Boolean}
* @default true
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder.enabled
*/
enabled: true,
/**
* Hide the browser's default focus indicator.
*
* @type {Boolean}
* @default true
* @since 6.0.4
* @apioption accessibility.keyboardNavigation.focusBorder.hideBrowserFocusOutline
*/
hideBrowserFocusOutline: true,
/**
* Style options for the focus border drawn around elements
* while navigating through them. Note that some browsers in
* addition draw their own borders for focused elements. These
* automatic borders can not be styled by Highcharts.
*
* In styled mode, the border is given the
* `.highcharts-focus-border` class.
*
* @type {Object}
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder.style
*/
style: {
/**
* Color of the focus border.
*
* @type {Color}
* @default #000000
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder.style.color
*/
color: '#335cad',
/**
* Line width of the focus border.
*
* @type {Number}
* @default 2
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder.style.lineWidth
*/
lineWidth: 2,
/**
* Border radius of the focus border.
*
* @type {Number}
* @default 3
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder.style.borderRadius
*/
borderRadius: 3
},
/**
* Focus border margin around the elements.
*
* @type {Number}
* @default 2
* @since 6.0.3
* @apioption accessibility.keyboardNavigation.focusBorder.margin
*/
margin: 2
},
/**
* Set the keyboard navigation mode for the chart. Can be "normal"
* or "serialize". In normal mode, left/right arrow keys move
* between points in a series, while up/down arrow keys move between
* series. Up/down navigation acts intelligently to figure out which
* series makes sense to move to from any given point.
*
* In "serialize" mode, points are instead navigated as a single
* list. Left/right behaves as in "normal" mode. Up/down arrow keys
* will behave like left/right. This is useful for unifying
* navigation behavior with/without screen readers enabled.
*
* @type {String}
* @validvalue ["normal", "serialize"]
* @default normal
* @since 6.0.4
* @apioption accessibility.keyboardNavigation.mode
*/
/**
* Skip null points when navigating through points with the
* keyboard.
*
* @type {Boolean}
* @default true
* @since 5.0.0
* @apioption accessibility.keyboardNavigation.skipNullPoints
*/
skipNullPoints: true
}
}
});
/**
* Keyboard navigation for the legend. Requires the Accessibility module.
* @since 5.0.14
* @apioption legend.keyboardNavigation
*/
/**
* Enable/disable keyboard navigation for the legend. Requires the Accessibility
* module.
*
* @type {Boolean}
* @see [accessibility.keyboardNavigation](
* #accessibility.keyboardNavigation.enabled)
* @default true
* @since 5.0.13
* @apioption legend.keyboardNavigation.enabled
*/
// Abstraction layer for keyboard navigation. Keep a map of keyCodes to
// handler functions, and a next/prev move handler for tab order. The
// module's keyCode handlers determine when to move to another module.
// Validate holds a function to determine if there are prerequisites for
// this module to run that are not met. Init holds a function to run once
// before any keyCodes are interpreted. Terminate holds a function to run
// once before moving to next/prev module.
// The chart object keeps track of a list of KeyboardNavigationModules.
function KeyboardNavigationModule(chart, options) {
this.chart = chart;
this.id = options.id;
this.keyCodeMap = options.keyCodeMap;
this.validate = options.validate;
this.init = options.init;
this.terminate = options.terminate;
}
KeyboardNavigationModule.prototype = {
// Find handler function(s) for key code in the keyCodeMap and run it.
run: function (e) {
var navModule = this,
keyCode = e.which || e.keyCode,
found = false,
handled = false;
each(this.keyCodeMap, function (codeSet) {
if (codeSet[0].indexOf(keyCode) > -1) {
found = true;
handled = codeSet[1].call(navModule, keyCode, e) === false ?
// If explicitly returning false, we haven't handled it
false :
true;
}
});
// Default tab handler, move to next/prev module
if (!found && keyCode === 9) {
handled = this.move(e.shiftKey ? -1 : 1);
}
return handled;
},
// Move to next/prev valid module, or undefined if none, and init
// it. Returns true on success and false if there is no valid module
// to move to.
move: function (direction) {
var chart = this.chart;
if (this.terminate) {
this.terminate(direction);
}
chart.keyboardNavigationModuleIndex += direction;
var newModule = chart.keyboardNavigationModules[
chart.keyboardNavigationModuleIndex
];
// Remove existing focus border if any
if (chart.focusElement) {
chart.focusElement.removeFocusBorder();
}
// Verify new module
if (newModule) {
if (newModule.validate && !newModule.validate()) {
return this.move(direction); // Invalid module, recurse
}
if (newModule.init) {
newModule.init(direction); // Valid module, init it
return true;
}
}
// No module
chart.keyboardNavigationModuleIndex = 0; // Reset counter
// Set focus to chart or exit anchor depending on direction
if (direction > 0) {
this.chart.exiting = true;
this.chart.tabExitAnchor.focus();
} else {
this.chart.renderTo.focus();
}
return false;
}
};
// Utility function to attempt to fake a click event on an element
function fakeClickEvent(element) {
var fakeEvent;
if (element && element.onclick && doc.createEvent) {
fakeEvent = doc.createEvent('Events');
fakeEvent.initEvent('click', true, false);
element.onclick(fakeEvent);
}
}
// Determine if a series should be skipped
function isSkipSeries(series) {
var a11yOptions = series.chart.options.accessibility;
return series.options.skipKeyboardNavigation ||
series.options.enableMouseTracking === false || // #8440
!series.visible ||
// Skip all points in a series where pointDescriptionThreshold is
// reached
(a11yOptions.pointDescriptionThreshold &&
a11yOptions.pointDescriptionThreshold <= series.points.length);
}
// Determine if a point should be skipped
function isSkipPoint(point) {
var a11yOptions = point.series.chart.options.accessibility;
return point.isNull && a11yOptions.keyboardNavigation.skipNullPoints ||
point.visible === false ||
isSkipSeries(point.series);
}
// Get the point in a series that is closest (in distance) to a reference point
// Optionally supply weight factors for x and y directions
function getClosestPoint(point, series, xWeight, yWeight) {
var minDistance = Infinity,
dPoint,
minIx,
distance,
i = series.points.length;
if (point.plotX === undefined || point.plotY === undefined) {
return;
}
while (i--) {
dPoint = series.points[i];
if (dPoint.plotX === undefined || dPoint.plotY === undefined) {
continue;
}
distance = (point.plotX - dPoint.plotX) *
(point.plotX - dPoint.plotX) * (xWeight || 1) +
(point.plotY - dPoint.plotY) *
(point.plotY - dPoint.plotY) * (yWeight || 1);
if (distance < minDistance) {
minDistance = distance;
minIx = i;
}
}
return minIx !== undefined && series.points[minIx];
}
// Pan along axis in a direction (1 or -1), optionally with a defined
// granularity (number of steps it takes to walk across current view)
H.Axis.prototype.panStep = function (direction, granularity) {
var gran = granularity || 3,
extremes = this.getExtremes(),
step = (extremes.max - extremes.min) / gran * direction,
newMax = extremes.max + step,
newMin = extremes.min + step,
size = newMax - newMin;
if (direction < 0 && newMin < extremes.dataMin) {
newMin = extremes.dataMin;
newMax = newMin + size;
} else if (direction > 0 && newMax > extremes.dataMax) {
newMax = extremes.dataMax;
newMin = newMax - size;
}
this.setExtremes(newMin, newMax);
};
// Set chart's focus to an SVGElement. Calls focus() on it, and draws the focus
// border. If the focusElement argument is supplied, it draws the border around
// svgElement and sets the focus to focusElement.
H.Chart.prototype.setFocusToElement = function (svgElement, focusElement) {
var focusBorderOptions = this.options.accessibility
.keyboardNavigation.focusBorder,
browserFocusElement = focusElement || svgElement;
// Set browser focus if possible
if (
browserFocusElement.element &&
browserFocusElement.element.focus
) {
browserFocusElement.element.focus();
// Hide default focus ring
if (focusBorderOptions.hideBrowserFocusOutline) {
browserFocusElement.css({ outline: 'none' });
}
}
if (focusBorderOptions.enabled) {
// Remove old focus border
if (this.focusElement) {
this.focusElement.removeFocusBorder();
}
// Draw focus border (since some browsers don't do it automatically)
svgElement.addFocusBorder(focusBorderOptions.margin, {
stroke: focusBorderOptions.style.color,
strokeWidth: focusBorderOptions.style.lineWidth,
borderRadius: focusBorderOptions.style.borderRadius
});
this.focusElement = svgElement;
}
};
// Highlight a point (show tooltip and display hover state). Returns the
// highlighted point.
H.Point.prototype.highlight = function () {
var chart = this.series.chart;
if (!this.isNull) {
this.onMouseOver(); // Show the hover marker and tooltip
} else {
if (chart.tooltip) {
chart.tooltip.hide(0);
}
// Don't call blur on the element, as it messes up the chart div's focus
}
// We focus only after calling onMouseOver because the state change can
// change z-index and mess up the element.
if (this.graphic) {
chart.setFocusToElement(this.graphic);
}
chart.highlightedPoint = this;
return this;
};
// Function to highlight next/previous point in chart
// Returns highlighted point on success, false on failure (no adjacent point to
// highlight in chosen direction)
H.Chart.prototype.highlightAdjacentPoint = function (next) {
var chart = this,
series = chart.series,
curPoint = chart.highlightedPoint,
curPointIndex = curPoint && getPointIndex(curPoint) || 0,
curPoints = curPoint && curPoint.series.points,
lastSeries = chart.series && chart.series[chart.series.length - 1],
lastPoint = lastSeries && lastSeries.points &&
lastSeries.points[lastSeries.points.length - 1],
newSeries,
newPoint;
// If no points, return false
if (!series[0] || !series[0].points) {
return false;
}
if (!curPoint) {
// No point is highlighted yet. Try first/last point depending on move
// direction
newPoint = next ? series[0].points[0] : lastPoint;
} else {
// We have a highlighted point.
// Grab next/prev point & series
newSeries = series[curPoint.series.index + (next ? 1 : -1)];
newPoint = curPoints[curPointIndex + (next ? 1 : -1)];
if (!newPoint && newSeries) {
// Done with this series, try next one
newPoint = newSeries.points[next ? 0 : newSeries.points.length - 1];
}
// If there is no adjacent point, we return false
if (!newPoint) {
return false;
}
}
// Recursively skip points
if (isSkipPoint(newPoint)) {
// If we skip this whole series, move to the end of the series before we
// recurse, just to optimize
newSeries = newPoint.series;
if (isSkipSeries(newSeries)) {
chart.highlightedPoint = next ?
newSeries.points[newSeries.points.length - 1] :
newSeries.points[0];
} else {
// Otherwise, just move one point
chart.highlightedPoint = newPoint;
}
// Retry
return chart.highlightAdjacentPoint(next);
}
// There is an adjacent point, highlight it
return newPoint.highlight();
};
// Highlight first valid point in a series. Returns the point if successfully
// highlighted, otherwise false. If there is a highlighted point in the series,
// use that as starting point.
H.Series.prototype.highlightFirstValidPoint = function () {
var curPoint = this.chart.highlightedPoint,
start = (curPoint && curPoint.series) === this ?
getPointIndex(curPoint) :
0,
points = this.points;
if (points) {
for (var i = start, len = points.length; i < len; ++i) {
if (!isSkipPoint(points[i])) {
return points[i].highlight();
}
}
for (var j = start; j >= 0; --j) {
if (!isSkipPoint(points[j])) {
return points[j].highlight();
}
}
}
return false;
};
// Highlight next/previous series in chart. Returns false if no adjacent series
// in the direction, otherwise returns new highlighted point.
H.Chart.prototype.highlightAdjacentSeries = function (down) {
var chart = this,
newSeries,
newPoint,
adjacentNewPoint,
curPoint = chart.highlightedPoint,
lastSeries = chart.series && chart.series[chart.series.length - 1],
lastPoint = lastSeries && lastSeries.points &&
lastSeries.points[lastSeries.points.length - 1];
// If no point is highlighted, highlight the first/last point
if (!chart.highlightedPoint) {
newSeries = down ? (chart.series && chart.series[0]) : lastSeries;
newPoint = down ?
(newSeries && newSeries.points && newSeries.points[0]) : lastPoint;
return newPoint ? newPoint.highlight() : false;
}
newSeries = chart.series[curPoint.series.index + (down ? -1 : 1)];
if (!newSeries) {
return false;
}
// We have a new series in this direction, find the right point
// Weigh xDistance as counting much higher than Y distance
newPoint = getClosestPoint(curPoint, newSeries, 4);
if (!newPoint) {
return false;
}
// New series and point exists, but we might want to skip it
if (isSkipSeries(newSeries)) {
// Skip the series
newPoint.highlight();
adjacentNewPoint = chart.highlightAdjacentSeries(down); // Try recurse
if (!adjacentNewPoint) {
// Recurse failed
curPoint.highlight();
return false;
}
// Recurse succeeded
return adjacentNewPoint;
}
// Highlight the new point or any first valid point back or forwards from it
newPoint.highlight();
return newPoint.series.highlightFirstValidPoint();
};
// Highlight the closest point vertically
H.Chart.prototype.highlightAdjacentPointVertical = function (down) {
var curPoint = this.highlightedPoint,
minDistance = Infinity,
bestPoint;
if (curPoint.plotX === undefined || curPoint.plotY === undefined) {
return false;
}
each(this.series, function (series) {
if (isSkipSeries(series)) {
return;
}
each(series.points, function (point) {
if (point.plotY === undefined || point.plotX === undefined ||
point === curPoint) {
return;
}
var yDistance = point.plotY - curPoint.plotY,
width = Math.abs(point.plotX - curPoint.plotX),
distance = Math.abs(yDistance) * Math.abs(yDistance) +
width * width * 4; // Weigh horizontal distance highly
// Reverse distance number if axis is reversed
if (series.yAxis.reversed) {
yDistance *= -1;
}
if (
yDistance < 0 && down || yDistance > 0 && !down || // Wrong dir
distance < 5 || // Points in same spot => infinite loop
isSkipPoint(point)
) {
return;
}
if (distance < minDistance) {
minDistance = distance;
bestPoint = point;
}
});
});
return bestPoint ? bestPoint.highlight() : false;
};
// Show the export menu and focus the first item (if exists)
H.Chart.prototype.showExportMenu = function () {
if (this.exportSVGElements && this.exportSVGElements[0]) {
this.exportSVGElements[0].element.onclick();
this.highlightExportItem(0);
}
};
// Hide export menu
H.Chart.prototype.hideExportMenu = function () {
var chart = this,
exportList = chart.exportDivElements;
if (exportList && chart.exportContextMenu) {
// Reset hover states etc.
each(exportList, function (el) {
if (el.className === 'highcharts-menu-item' && el.onmouseout) {
el.onmouseout();
}
});
chart.highlightedExportItem = 0;
// Hide the menu div
chart.exportContextMenu.hideMenu();
// Make sure the chart has focus and can capture keyboard events
chart.container.focus();
}
};
// Highlight export menu item by index
H.Chart.prototype.highlightExportItem = function (ix) {
var listItem = this.exportDivElements && this.exportDivElements[ix],
curHighlighted =
this.exportDivElements &&
this.exportDivElements[this.highlightedExportItem];
if (
listItem &&
listItem.tagName === 'DIV' &&
!(listItem.children && listItem.children.length)
) {
if (listItem.focus && hasSVGFocusSupport) {
// Only focus if we can set focus back to the elements after
// destroying the menu (#7422)
listItem.focus();
}
if (curHighlighted && curHighlighted.onmouseout) {
curHighlighted.onmouseout();
}
if (listItem.onmouseover) {
listItem.onmouseover();
}
this.highlightedExportItem = ix;
return true;
}
};
// Try to highlight the last valid export menu item
H.Chart.prototype.highlightLastExportItem = function () {
var chart = this,
i;
if (chart.exportDivElements) {
i = chart.exportDivElements.length;
while (i--) {
if (chart.highlightExportItem(i)) {
break;
}
}
}
};
// Highlight range selector button by index
H.Chart.prototype.highlightRangeSelectorButton = function (ix) {
var buttons = this.rangeSelector.buttons;
// Deselect old
if (buttons[this.highlightedRangeSelectorItemIx]) {
buttons[this.highlightedRangeSelectorItemIx].setState(
this.oldRangeSelectorItemState || 0
);
}
// Select new
this.highlightedRangeSelectorItemIx = ix;
if (buttons[ix]) {
this.setFocusToElement(buttons[ix].box, buttons[ix]);
this.oldRangeSelectorItemState = buttons[ix].state;
buttons[ix].setState(2);
return true;
}
return false;
};
// Highlight legend item by index
H.Chart.prototype.highlightLegendItem = function (ix) {
var items = this.legend.allItems,
oldIx = this.highlightedLegendItemIx;
if (items[ix]) {
if (items[oldIx]) {
fireEvent(
items[oldIx].legendGroup.element,
'mouseout'
);
}
// Scroll if we have to
if (items[ix].pageIx !== undefined &&
items[ix].pageIx + 1 !== this.legend.currentPage) {
this.legend.scroll(1 + items[ix].pageIx - this.legend.currentPage);
}
// Focus
this.highlightedLegendItemIx = ix;
this.setFocusToElement(items[ix].legendItem, items[ix].legendGroup);
fireEvent(items[ix].legendGroup.element, 'mouseover');
return true;
}
return false;
};
// Add keyboard navigation handling modules to chart
H.Chart.prototype.addKeyboardNavigationModules = function () {
var chart = this;
function navModuleFactory(id, keyMap, options) {
return new KeyboardNavigationModule(chart, merge({
keyCodeMap: keyMap
}, { id: id }, options));
}
// List of the different keyboard handling modes we use depending on where
// we are in the chart. Each mode has a set of handling functions mapped to
// key codes. Each mode determines when to move to the next/prev mode.
chart.keyboardNavigationModules = [
// Entry point catching the first tab, allowing users to tab into points
// more intuitively.
navModuleFactory('entry', []),
// Points
navModuleFactory('points', [
// Left/Right
[[37, 39], function (keyCode) {
var right = keyCode === 39;
if (!chart.highlightAdjacentPoint(right)) {
// Failed to highlight next, wrap to last/first
return this.init(right ? 1 : -1);
}
return true;
}],
// Up/Down
[[38, 40], function (keyCode) {
var down = keyCode !== 38,
navOptions = chart.options.accessibility.keyboardNavigation;
if (navOptions.mode && navOptions.mode === 'serialize') {
// Act like left/right
if (!chart.highlightAdjacentPoint(down)) {
return this.init(down ? 1 : -1);
}
return true;
}
// Normal mode, move between series
var highlightMethod = chart.highlightedPoint &&
chart.highlightedPoint.series.keyboardMoveVertical ?
'highlightAdjacentPointVertical' :
'highlightAdjacentSeries';
chart[highlightMethod](down);
return true;
}],
// Enter/Spacebar
[[13, 32], function () {
if (chart.highlightedPoint) {
chart.highlightedPoint.firePointEvent('click');
}
}]
], {
// Always start highlighting from scratch when entering this module
init: function (dir) {
var numSeries = chart.series.length,
i = dir > 0 ? 0 : numSeries,
res;
if (dir > 0) {
delete chart.highlightedPoint;
// Find first valid point to highlight
while (i < numSeries) {
res = chart.series[i].highlightFirstValidPoint();
if (res) {
return res;
}
++i;
}
} else {
// Find last valid point to highlight
while (i--) {
chart.highlightedPoint = chart.series[i].points[
chart.series[i].points.length - 1
];
// Highlight first valid point in the series will also
// look backwards. It always starts from currently
// highlighted point.
res = chart.series[i].highlightFirstValidPoint();
if (res) {
return res;
}
}
}
},
// If leaving points, don't show tooltip anymore
terminate: function () {
if (chart.tooltip) {
chart.tooltip.hide(0);
}
delete chart.highlightedPoint;
}
}),
// Exporting
navModuleFactory('exporting', [
// Left/Up
[[37, 38], function () {
var i = chart.highlightedExportItem || 0,
reachedEnd = true;
// Try to highlight prev item in list. Highlighting e.g.
// separators will fail.
while (i--) {
if (chart.highlightExportItem(i)) {
reachedEnd = false;
break;
}
}
if (reachedEnd) {
chart.highlightLastExportItem();
return true;
}
}],
// Right/Down
[[39, 40], function () {
var highlightedExportItem = chart.highlightedExportItem || 0,
reachedEnd = true;
// Try to highlight next item in list. Highlighting e.g.
// separators will fail.
for (
var i = highlightedExportItem + 1;
i < chart.exportDivElements.length;
++i
) {
if (chart.highlightExportItem(i)) {
reachedEnd = false;
break;
}
}
if (reachedEnd) {
chart.highlightExportItem(0);
return true;
}
}],
// Enter/Spacebar
[[13, 32], function () {
fakeClickEvent(
chart.exportDivElements[chart.highlightedExportItem]
);
}]
], {
// Only run exporting navigation if exporting support exists and is
// enabled on chart
validate: function () {
return (
chart.exportChart &&
!(
chart.options.exporting &&
chart.options.exporting.enabled === false
)
);
},
// Show export menu
init: function (direction) {
chart.highlightedPoint = null;
chart.showExportMenu();
// If coming back to export menu from other module, try to
// highlight last item in menu
if (direction < 0) {
chart.highlightLastExportItem();
}
},
// Hide the menu
terminate: function () {
chart.hideExportMenu();
}
}),
// Map zoom
navModuleFactory('mapZoom', [
// Up/down/left/right
[[38, 40, 37, 39], function (keyCode) {
chart[keyCode === 38 || keyCode === 40 ? 'yAxis' : 'xAxis'][0]
.panStep(keyCode < 39 ? -1 : 1);
}],
// Tabs
[[9], function (keyCode, e) {
var button;
// Deselect old
chart.mapNavButtons[chart.focusedMapNavButtonIx].setState(0);
if (
e.shiftKey && !chart.focusedMapNavButtonIx ||
!e.shiftKey && chart.focusedMapNavButtonIx
) { // trying to go somewhere we can't?
chart.mapZoom(); // Reset zoom
// Nowhere to go, go to prev/next module
return this.move(e.shiftKey ? -1 : 1);
}
chart.focusedMapNavButtonIx += e.shiftKey ? -1 : 1;
button = chart.mapNavButtons[chart.focusedMapNavButtonIx];
chart.setFocusToElement(button.box, button);
button.setState(2);
}],
// Enter/Spacebar
[[13, 32], function () {
fakeClickEvent(
chart.mapNavButtons[chart.focusedMapNavButtonIx].element
);
}]
], {
// Only run this module if we have map zoom on the chart
validate: function () {
return (
chart.mapZoom &&
chart.mapNavButtons &&
chart.mapNavButtons.length === 2
);
},
// Make zoom buttons do their magic
init: function (direction) {
var zoomIn = chart.mapNavButtons[0],
zoomOut = chart.mapNavButtons[1],
initialButton = direction > 0 ? zoomIn : zoomOut;
each(chart.mapNavButtons, function (button, i) {
button.element.setAttribute('tabindex', -1);
button.element.setAttribute('role', 'button');
button.element.setAttribute(
'aria-label',
chart.langFormat(
'accessibility.mapZoom' + (i ? 'Out' : 'In'),
{ chart: chart }
)
);
});
chart.setFocusToElement(initialButton.box, initialButton);
initialButton.setState(2);
chart.focusedMapNavButtonIx = direction > 0 ? 0 : 1;
}
}),
// Highstock range selector (minus input boxes)
navModuleFactory('rangeSelector', [
// Left/Right/Up/Down
[[37, 39, 38, 40], function (keyCode) {
var direction = (keyCode === 37 || keyCode === 38) ? -1 : 1;
// Try to highlight next/prev button
if (
!chart.highlightRangeSelectorButton(
chart.highlightedRangeSelectorItemIx + direction
)
) {
return this.move(direction);
}
}],
// Enter/Spacebar
[[13, 32], function () {
// Don't allow click if button used to be disabled
if (chart.oldRangeSelectorItemState !== 3) {
fakeClickEvent(
chart.rangeSelector.buttons[
chart.highlightedRangeSelectorItemIx
].element
);
}
}]
], {
// Only run this module if we have range selector
validate: function () {
return (
chart.rangeSelector &&
chart.rangeSelector.buttons &&
chart.rangeSelector.buttons.length
);
},
// Make elements focusable and accessible
init: function (direction) {
each(chart.rangeSelector.buttons, function (button) {
button.element.setAttribute('tabindex', '-1');
button.element.setAttribute('role', 'button');
button.element.setAttribute(
'aria-label',
chart.langFormat(
'accessibility.rangeSelectorButton',
{
chart: chart,
buttonText: button.text && button.text.textStr
}
)
);
});
// Focus first/last button
chart.highlightRangeSelectorButton(
direction > 0 ? 0 : chart.rangeSelector.buttons.length - 1
);
}
}),
// Highstock range selector, input boxes
navModuleFactory('rangeSelectorInput', [
// Tab/Up/Down
[[9, 38, 40], function (keyCode, e) {
var direction =
(keyCode === 9 && e.shiftKey || keyCode === 38) ? -1 : 1,
newIx = chart.highlightedInputRangeIx =
chart.highlightedInputRangeIx + direction;
// Try to highlight next/prev item in list.
if (newIx > 1 || newIx < 0) { // Out of range
return this.move(direction);
}
chart.rangeSelector[newIx ? 'maxInput' : 'minInput'].focus();
}]
], {
// Only run if we have range selector with input boxes
validate: function () {
var inputVisible = (
chart.rangeSelector &&
chart.rangeSelector.inputGroup &&
chart.rangeSelector.inputGroup.element
.getAttribute('visibility') !== 'hidden'
);
return (
inputVisible &&
chart.options.rangeSelector.inputEnabled !== false &&
chart.rangeSelector.minInput &&
chart.rangeSelector.maxInput
);
},
// Highlight first/last input box
init: function (direction) {
chart.highlightedInputRangeIx = direction > 0 ? 0 : 1;
chart.rangeSelector[
chart.highlightedInputRangeIx ? 'maxInput' : 'minInput'
].focus();
}
}),
// Legend navigation
navModuleFactory('legend', [
// Left/Right/Up/Down
[[37, 39, 38, 40], function (keyCode) {
var direction = (keyCode === 37 || keyCode === 38) ? -1 : 1;
// Try to highlight next/prev legend item
if (!chart.highlightLegendItem(
chart.highlightedLegendItemIx + direction
) && chart.legend.allItems.length > 1) {
// Wrap around if more than 1 item
this.init(direction);
}
}],
// Enter/Spacebar
[[13, 32], function () {
var legendElement = chart.legend.allItems[
chart.highlightedLegendItemIx
].legendItem.element;
fakeClickEvent(
!chart.legend.options.useHTML ? // #8561
legendElement.parentNode : legendElement
);
}]
], {
// Only run this module if we have at least one legend - wait for
// it - item. Don't run if the legend is populated by a colorAxis.
// Don't run if legend navigation is disabled.
validate: function () {
return chart.legend && chart.legend.allItems &&
chart.legend.display &&
!(chart.colorAxis && chart.colorAxis.length) &&
(chart.options.legend &&
chart.options.legend.keyboardNavigation &&
chart.options.legend.keyboardNavigation.enabled) !== false;
},
// Make elements focusable and accessible
init: function (direction) {
each(chart.legend.allItems, function (item) {
item.legendGroup.element.setAttribute('tabindex', '-1');
item.legendGroup.element.setAttribute('role', 'button');
item.legendGroup.element.setAttribute(
'aria-label',
chart.langFormat(
'accessibility.legendItem',
{
chart: chart,
itemName: stripTags(item.name)
}
)
);
});
// Focus first/last item
chart.highlightLegendItem(
direction > 0 ? 0 : chart.legend.allItems.length - 1
);
}
})
];
};
// Add exit anchor to the chart
// We use this to move focus out of chart whenever we want, by setting focus
// to this div and not preventing the default tab action.
// We also use this when users come back into the chart by tabbing back, in
// order to navigate from the end of the chart.
// Function returns the unbind function for the exit anchor's event handler.
H.Chart.prototype.addExitAnchor = function () {
var chart = this;
chart.tabExitAnchor = doc.createElement('div');
chart.tabExitAnchor.setAttribute('tabindex', '0');
// Hide exit anchor
merge(true, chart.tabExitAnchor.style, {
position: 'absolute',
left: '-9999px',
top: 'auto',
width: '1px',
height: '1px',
overflow: 'hidden'
});
chart.renderTo.appendChild(chart.tabExitAnchor);
return addEvent(chart.tabExitAnchor, 'focus',
function (ev) {
var e = ev || win.event,
curModule;
// If focusing and we are exiting, do nothing once.
if (!chart.exiting) {
// Not exiting, means we are coming in backwards
chart.renderTo.focus();
e.preventDefault();
// Move to last valid keyboard nav module
// Note the we don't run it, just set the index
chart.keyboardNavigationModuleIndex =
chart.keyboardNavigationModules.length - 1;
curModule = chart.keyboardNavigationModules[
chart.keyboardNavigationModuleIndex
];
// Validate the module
if (curModule.validate && !curModule.validate()) {
// Invalid.
// Move inits next valid module in direction
curModule.move(-1);
} else {
// We have a valid module, init it
curModule.init(-1);
}
} else {
// Don't skip the next focus, we only skip once.
chart.exiting = false;
}
}
);
};
// Clear the chart and reset the navigation state
H.Chart.prototype.resetKeyboardNavigation = function () {
var chart = this,
curMod = (
chart.keyboardNavigationModules &&
chart.keyboardNavigationModules[
chart.keyboardNavigationModuleIndex || 0
]
);
if (curMod && curMod.terminate) {
curMod.terminate();
}
if (chart.focusElement) {
chart.focusElement.removeFocusBorder();
}
chart.keyboardNavigationModuleIndex = 0;
chart.keyboardReset = true;
};
/**
* On destroy, we need to clean up the focus border and the state
*/
H.addEvent(H.Series, 'destroy', function () {
var chart = this.chart;
if (chart.highlightedPoint && chart.highlightedPoint.series === this) {
delete chart.highlightedPoint;
if (chart.focusElement) {
chart.focusElement.removeFocusBorder();
}
}
});
// Add keyboard navigation events on chart load
H.Chart.prototype.callbacks.push(function (chart) {
var a11yOptions = chart.options.accessibility;
if (a11yOptions.enabled && a11yOptions.keyboardNavigation.enabled) {
// Test if we have focus support for SVG elements
hasSVGFocusSupport = !!chart.renderTo
.getElementsByTagName('g')[0].focus;
// Init nav modules. We start at the first module, and as the user
// navigates through the chart the index will increase to use different
// handler modules.
chart.addKeyboardNavigationModules();
chart.keyboardNavigationModuleIndex = 0;
// Make chart container reachable by tab
if (
chart.container.hasAttribute &&
!chart.container.hasAttribute('tabIndex')
) {
chart.container.setAttribute('tabindex', '0');
}
// Add tab exit anchor
if (!chart.tabExitAnchor) {
chart.unbindExitAnchorFocus = chart.addExitAnchor();
}
// Handle keyboard events by routing them to active keyboard nav module
chart.unbindKeydownHandler = addEvent(chart.renderTo, 'keydown',
function (ev) {
var e = ev || win.event,
curNavModule = chart.keyboardNavigationModules[
chart.keyboardNavigationModuleIndex
];
chart.keyboardReset = false;
// If there is a nav module for the current index, run it.
// Otherwise, we are outside of the chart in some direction.
if (curNavModule) {
if (curNavModule.run(e)) {
// Successfully handled this key event, stop default
e.preventDefault();
}
}
});
// Reset chart navigation state if we click outside the chart and it's
// not already reset
chart.unbindBlurHandler = addEvent(doc, 'mouseup', function () {
if (
!chart.keyboardReset &&
!(chart.pointer && chart.pointer.chartPosition)
) {
chart.resetKeyboardNavigation();
}
});
// Add cleanup handlers
addEvent(chart, 'destroy', function () {
chart.resetKeyboardNavigation();
if (chart.unbindExitAnchorFocus && chart.tabExitAnchor) {
chart.unbindExitAnchorFocus();
}
if (chart.unbindKeydownHandler && chart.renderTo) {
chart.unbindKeydownHandler();
}
if (chart.unbindBlurHandler) {
chart.unbindBlurHandler();
}
});
}
});
}(Highcharts));
return (function () {
}());
}));