sonification.js 3.7 KB

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