sonification.js 3.2 KB

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