sonification.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* *
  2. *
  3. * (c) 2009-2020 Øystein Moseng
  4. *
  5. * Sonification module for Highcharts
  6. *
  7. * License: www.highcharts.com/license
  8. *
  9. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10. *
  11. * */
  12. 'use strict';
  13. import H from '../../Core/Globals.js';
  14. import O from '../../Core/Options.js';
  15. var defaultOptions = O.defaultOptions;
  16. import Point from '../../Core/Series/Point.js';
  17. import U from '../../Core/Utilities.js';
  18. var addEvent = U.addEvent, extend = U.extend, merge = U.merge;
  19. import Instrument from './Instrument.js';
  20. import instruments from './instrumentDefinitions.js';
  21. import Earcon from './Earcon.js';
  22. import pointSonifyFunctions from './pointSonify.js';
  23. import chartSonifyFunctions from './chartSonify.js';
  24. import utilities from './utilities.js';
  25. import TimelineClasses from './Timeline.js';
  26. import sonificationOptions from './options.js';
  27. import '../../Core/Series/Series.js';
  28. // Expose on the Highcharts object
  29. /**
  30. * Global classes and objects related to sonification.
  31. *
  32. * @requires module:modules/sonification
  33. *
  34. * @name Highcharts.sonification
  35. * @type {Highcharts.SonificationObject}
  36. */
  37. /**
  38. * Global classes and objects related to sonification.
  39. *
  40. * @requires module:modules/sonification
  41. *
  42. * @interface Highcharts.SonificationObject
  43. */ /**
  44. * Note fade-out-time in milliseconds. Most notes are faded out quickly by
  45. * default if there is time. This is to avoid abrupt stops which will cause
  46. * perceived clicks.
  47. * @name Highcharts.SonificationObject#fadeOutDuration
  48. * @type {number}
  49. */ /**
  50. * Utility functions.
  51. * @name Highcharts.SonificationObject#utilities
  52. * @private
  53. * @type {object}
  54. */ /**
  55. * The Instrument class.
  56. * @name Highcharts.SonificationObject#Instrument
  57. * @type {Function}
  58. */ /**
  59. * Predefined instruments, given as an object with a map between the instrument
  60. * name and the Highcharts.Instrument object.
  61. * @name Highcharts.SonificationObject#instruments
  62. * @type {Object}
  63. */ /**
  64. * The Earcon class.
  65. * @name Highcharts.SonificationObject#Earcon
  66. * @type {Function}
  67. */ /**
  68. * The TimelineEvent class.
  69. * @private
  70. * @name Highcharts.SonificationObject#TimelineEvent
  71. * @type {Function}
  72. */ /**
  73. * The TimelinePath class.
  74. * @private
  75. * @name Highcharts.SonificationObject#TimelinePath
  76. * @type {Function}
  77. */ /**
  78. * The Timeline class.
  79. * @private
  80. * @name Highcharts.SonificationObject#Timeline
  81. * @type {Function}
  82. */
  83. H.sonification = {
  84. fadeOutDuration: 20,
  85. // Classes and functions
  86. utilities: utilities,
  87. Instrument: Instrument,
  88. instruments: instruments,
  89. Earcon: Earcon,
  90. TimelineEvent: TimelineClasses.TimelineEvent,
  91. TimelinePath: TimelineClasses.TimelinePath,
  92. Timeline: TimelineClasses.Timeline
  93. };
  94. // Add default options
  95. merge(true, defaultOptions, sonificationOptions);
  96. // Chart specific
  97. Point.prototype.sonify = pointSonifyFunctions.pointSonify;
  98. Point.prototype.cancelSonify = pointSonifyFunctions.pointCancelSonify;
  99. H.Series.prototype.sonify = chartSonifyFunctions.seriesSonify;
  100. extend(H.Chart.prototype, {
  101. sonify: chartSonifyFunctions.chartSonify,
  102. pauseSonify: chartSonifyFunctions.pause,
  103. resumeSonify: chartSonifyFunctions.resume,
  104. rewindSonify: chartSonifyFunctions.rewind,
  105. cancelSonify: chartSonifyFunctions.cancel,
  106. getCurrentSonifyPoints: chartSonifyFunctions.getCurrentPoints,
  107. setSonifyCursor: chartSonifyFunctions.setCursor,
  108. resetSonifyCursor: chartSonifyFunctions.resetCursor,
  109. resetSonifyCursorEnd: chartSonifyFunctions.resetCursorEnd
  110. });
  111. /* eslint-disable no-invalid-this */
  112. // Prepare charts for sonification on init
  113. addEvent(H.Chart, 'init', function () {
  114. this.sonification = {};
  115. });
  116. // Update with chart/series/point updates
  117. addEvent(H.Chart, 'update', function (e) {
  118. var newOptions = e.options.sonification;
  119. if (newOptions) {
  120. merge(true, this.options.sonification, newOptions);
  121. }
  122. });