DeprecatedOptions.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* *
  2. *
  3. * (c) 2009-2021 Øystein Moseng
  4. *
  5. * Default options for accessibility.
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. /* eslint-disable max-len */
  13. /*
  14. * List of deprecated options:
  15. *
  16. * chart.description -> accessibility.description
  17. * chart.typeDescription -> accessibility.typeDescription
  18. * series.description -> series.accessibility.description
  19. * series.exposeElementToA11y -> series.accessibility.exposeAsGroupOnly
  20. * series.pointDescriptionFormatter ->
  21. * series.accessibility.pointDescriptionFormatter
  22. * series.skipKeyboardNavigation ->
  23. * series.accessibility.keyboardNavigation.enabled
  24. * point.description -> point.accessibility.description !!!! WARNING: No longer deprecated and handled, removed for HC8.
  25. * axis.description -> axis.accessibility.description
  26. *
  27. * accessibility.pointDateFormat -> accessibility.point.dateFormat
  28. * accessibility.addTableShortcut -> Handled by screenReaderSection.beforeChartFormat
  29. * accessibility.pointDateFormatter -> accessibility.point.dateFormatter
  30. * accessibility.pointDescriptionFormatter -> accessibility.point.descriptionFormatter
  31. * accessibility.pointDescriptionThreshold -> accessibility.series.pointDescriptionEnabledThreshold
  32. * accessibility.pointNavigationThreshold -> accessibility.keyboardNavigation.seriesNavigation.pointNavigationEnabledThreshold
  33. * accessibility.pointValueDecimals -> accessibility.point.valueDecimals
  34. * accessibility.pointValuePrefix -> accessibility.point.valuePrefix
  35. * accessibility.pointValueSuffix -> accessibility.point.valueSuffix
  36. * accessibility.screenReaderSectionFormatter -> accessibility.screenReaderSection.beforeChartFormatter
  37. * accessibility.describeSingleSeries -> accessibility.series.describeSingleSeries
  38. * accessibility.seriesDescriptionFormatter -> accessibility.series.descriptionFormatter
  39. * accessibility.onTableAnchorClick -> accessibility.screenReaderSection.onViewDataTableClick
  40. * accessibility.axisRangeDateFormat -> accessibility.screenReaderSection.axisRangeDateFormat
  41. * accessibility.keyboardNavigation.skipNullPoints -> accessibility.keyboardNavigation.seriesNavigation.skipNullPoints
  42. * accessibility.keyboardNavigation.mode -> accessibility.keyboardNavigation.seriesNavigation.mode
  43. *
  44. * lang.accessibility.chartHeading -> no longer used, remove
  45. * lang.accessibility.legendItem -> lang.accessibility.legend.legendItem
  46. * lang.accessibility.legendLabel -> lang.accessibility.legend.legendLabel
  47. * lang.accessibility.mapZoomIn -> lang.accessibility.zoom.mapZoomIn
  48. * lang.accessibility.mapZoomOut -> lang.accessibility.zoom.mapZoomOut
  49. * lang.accessibility.resetZoomButton -> lang.accessibility.zoom.resetZoomButton
  50. * lang.accessibility.screenReaderRegionLabel -> lang.accessibility.screenReaderSection.beforeRegionLabel
  51. * lang.accessibility.rangeSelectorButton -> lang.accessibility.rangeSelector.buttonText
  52. * lang.accessibility.rangeSelectorMaxInput -> lang.accessibility.rangeSelector.maxInputLabel
  53. * lang.accessibility.rangeSelectorMinInput -> lang.accessibility.rangeSelector.minInputLabel
  54. * lang.accessibility.svgContainerEnd -> lang.accessibility.screenReaderSection.endOfChartMarker
  55. * lang.accessibility.viewAsDataTable -> lang.accessibility.table.viewAsDataTableButtonText
  56. * lang.accessibility.tableSummary -> lang.accessibility.table.tableSummary
  57. *
  58. */
  59. /* eslint-enable max-len */
  60. 'use strict';
  61. import U from '../../Core/Utilities.js';
  62. var error = U.error, pick = U.pick;
  63. /* eslint-disable valid-jsdoc */
  64. /**
  65. * Set a new option on a root prop, where the option is defined as an array of
  66. * suboptions.
  67. * @private
  68. * @param root
  69. * @param {Array<string>} optionAsArray
  70. * @param {*} val
  71. * @return {void}
  72. */
  73. function traverseSetOption(root, optionAsArray, val) {
  74. var opt = root, prop, i = 0;
  75. for (; i < optionAsArray.length - 1; ++i) {
  76. prop = optionAsArray[i];
  77. opt = opt[prop] = pick(opt[prop], {});
  78. }
  79. opt[optionAsArray[optionAsArray.length - 1]] = val;
  80. }
  81. /**
  82. * If we have a clear root option node for old and new options and a mapping
  83. * between, we can use this generic function for the copy and warn logic.
  84. */
  85. function deprecateFromOptionsMap(chart, rootOldAsArray, rootNewAsArray, mapToNewOptions) {
  86. /**
  87. * @private
  88. */
  89. function getChildProp(root, propAsArray) {
  90. return propAsArray.reduce(function (acc, cur) {
  91. return acc[cur];
  92. }, root);
  93. }
  94. var rootOld = getChildProp(chart.options, rootOldAsArray), rootNew = getChildProp(chart.options, rootNewAsArray);
  95. Object.keys(mapToNewOptions).forEach(function (oldOptionKey) {
  96. var _a;
  97. var val = rootOld[oldOptionKey];
  98. if (typeof val !== 'undefined') {
  99. traverseSetOption(rootNew, mapToNewOptions[oldOptionKey], val);
  100. error(32, false, chart, (_a = {},
  101. _a[rootOldAsArray.join('.') + "." + oldOptionKey] = rootNewAsArray.join('.') + "." + mapToNewOptions[oldOptionKey].join('.'),
  102. _a));
  103. }
  104. });
  105. }
  106. /**
  107. * @private
  108. */
  109. function copyDeprecatedChartOptions(chart) {
  110. var chartOptions = chart.options.chart || {}, a11yOptions = chart.options.accessibility || {};
  111. ['description', 'typeDescription'].forEach(function (prop) {
  112. var _a;
  113. if (chartOptions[prop]) {
  114. a11yOptions[prop] = chartOptions[prop];
  115. error(32, false, chart, (_a = {}, _a["chart." + prop] = "use accessibility." + prop, _a));
  116. }
  117. });
  118. }
  119. /**
  120. * @private
  121. */
  122. function copyDeprecatedAxisOptions(chart) {
  123. chart.axes.forEach(function (axis) {
  124. var opts = axis.options;
  125. if (opts && opts.description) {
  126. opts.accessibility = opts.accessibility || {};
  127. opts.accessibility.description = opts.description;
  128. error(32, false, chart, { 'axis.description': 'use axis.accessibility.description' });
  129. }
  130. });
  131. }
  132. /**
  133. * @private
  134. */
  135. function copyDeprecatedSeriesOptions(chart) {
  136. // Map of deprecated series options. New options are defined as
  137. // arrays of paths under series.options.
  138. var oldToNewSeriesOptions = {
  139. description: ['accessibility', 'description'],
  140. exposeElementToA11y: ['accessibility', 'exposeAsGroupOnly'],
  141. pointDescriptionFormatter: [
  142. 'accessibility', 'pointDescriptionFormatter'
  143. ],
  144. skipKeyboardNavigation: [
  145. 'accessibility', 'keyboardNavigation', 'enabled'
  146. ]
  147. };
  148. chart.series.forEach(function (series) {
  149. // Handle series wide options
  150. Object.keys(oldToNewSeriesOptions).forEach(function (oldOption) {
  151. var _a;
  152. var optionVal = series.options[oldOption];
  153. if (typeof optionVal !== 'undefined') {
  154. // Set the new option
  155. traverseSetOption(series.options, oldToNewSeriesOptions[oldOption],
  156. // Note that skipKeyboardNavigation has inverted option
  157. // value, since we set enabled rather than disabled
  158. oldOption === 'skipKeyboardNavigation' ?
  159. !optionVal : optionVal);
  160. error(32, false, chart, (_a = {}, _a["series." + oldOption] = "series." + oldToNewSeriesOptions[oldOption].join('.'), _a));
  161. }
  162. });
  163. });
  164. }
  165. /**
  166. * @private
  167. */
  168. function copyDeprecatedTopLevelAccessibilityOptions(chart) {
  169. deprecateFromOptionsMap(chart, ['accessibility'], ['accessibility'], {
  170. pointDateFormat: ['point', 'dateFormat'],
  171. pointDateFormatter: ['point', 'dateFormatter'],
  172. pointDescriptionFormatter: ['point', 'descriptionFormatter'],
  173. pointDescriptionThreshold: ['series',
  174. 'pointDescriptionEnabledThreshold'],
  175. pointNavigationThreshold: ['keyboardNavigation', 'seriesNavigation',
  176. 'pointNavigationEnabledThreshold'],
  177. pointValueDecimals: ['point', 'valueDecimals'],
  178. pointValuePrefix: ['point', 'valuePrefix'],
  179. pointValueSuffix: ['point', 'valueSuffix'],
  180. screenReaderSectionFormatter: ['screenReaderSection',
  181. 'beforeChartFormatter'],
  182. describeSingleSeries: ['series', 'describeSingleSeries'],
  183. seriesDescriptionFormatter: ['series', 'descriptionFormatter'],
  184. onTableAnchorClick: ['screenReaderSection', 'onViewDataTableClick'],
  185. axisRangeDateFormat: ['screenReaderSection', 'axisRangeDateFormat']
  186. });
  187. }
  188. /**
  189. * @private
  190. */
  191. function copyDeprecatedKeyboardNavigationOptions(chart) {
  192. deprecateFromOptionsMap(chart, ['accessibility', 'keyboardNavigation'], ['accessibility', 'keyboardNavigation', 'seriesNavigation'], {
  193. skipNullPoints: ['skipNullPoints'],
  194. mode: ['mode']
  195. });
  196. }
  197. /**
  198. * @private
  199. */
  200. function copyDeprecatedLangOptions(chart) {
  201. deprecateFromOptionsMap(chart, ['lang', 'accessibility'], ['lang', 'accessibility'], {
  202. legendItem: ['legend', 'legendItem'],
  203. legendLabel: ['legend', 'legendLabel'],
  204. mapZoomIn: ['zoom', 'mapZoomIn'],
  205. mapZoomOut: ['zoom', 'mapZoomOut'],
  206. resetZoomButton: ['zoom', 'resetZoomButton'],
  207. screenReaderRegionLabel: ['screenReaderSection',
  208. 'beforeRegionLabel'],
  209. rangeSelectorButton: ['rangeSelector', 'buttonText'],
  210. rangeSelectorMaxInput: ['rangeSelector', 'maxInputLabel'],
  211. rangeSelectorMinInput: ['rangeSelector', 'minInputLabel'],
  212. svgContainerEnd: ['screenReaderSection', 'endOfChartMarker'],
  213. viewAsDataTable: ['table', 'viewAsDataTableButtonText'],
  214. tableSummary: ['table', 'tableSummary']
  215. });
  216. }
  217. /**
  218. * Copy options that are deprecated over to new options. Logs warnings to
  219. * console if deprecated options are used.
  220. *
  221. * @private
  222. */
  223. function copyDeprecatedOptions(chart) {
  224. copyDeprecatedChartOptions(chart);
  225. copyDeprecatedAxisOptions(chart);
  226. if (chart.series) {
  227. copyDeprecatedSeriesOptions(chart);
  228. }
  229. copyDeprecatedTopLevelAccessibilityOptions(chart);
  230. copyDeprecatedKeyboardNavigationOptions(chart);
  231. copyDeprecatedLangOptions(chart);
  232. }
  233. export default copyDeprecatedOptions;