/* Highcharts JS v9.1.1 (2021-06-03) Sonification module (c) 2012-2021 ystein Moseng License: www.highcharts.com/license */ 'use strict';(function(b){"object"===typeof module&&module.exports?(b["default"]=b,module.exports=b):"function"===typeof define&&define.amd?define("highcharts/modules/sonification",["highcharts"],function(m){b(m);b.Highcharts=m;return b}):b("undefined"!==typeof Highcharts?Highcharts:void 0)})(function(b){function m(d,b,g,p){d.hasOwnProperty(b)||(d[b]=p.apply(null,g))}b=b?b._modules:{};m(b,"Extensions/Sonification/Instrument.js",[b["Core/Globals.js"],b["Core/Utilities.js"]],function(d,b){function g(c){this.init(c)} var p=b.error,l=b.merge,k=b.pick,A=b.uniqueKey,n={type:"oscillator",playCallbackInterval:20,masterVolume:1,oscillator:{waveformShape:"sine"}};g.prototype.init=function(c){if(this.initAudioContext()){this.options=l(n,c);this.id=this.options.id=c&&c.id||A();this.masterVolume=this.options.masterVolume||0;c=d.audioContext;var a=this.destinationNode||c.destination;this.gainNode=c.createGain();this.setGain(0);(this.panNode=c.createStereoPanner&&c.createStereoPanner())?(this.setPan(0),this.gainNode.connect(this.panNode), this.panNode.connect(a)):this.gainNode.connect(a);"oscillator"===this.options.type&&this.initOscillator(this.options.oscillator);this.playCallbackTimers=[]}else p(29)};g.prototype.copy=function(c){return new g(l(this.options,{id:null},c))};g.prototype.initAudioContext=function(){var c=d.win.AudioContext||d.win.webkitAudioContext,a=!!d.audioContext;return c?(d.audioContext=d.audioContext||new c,!a&&d.audioContext&&"running"===d.audioContext.state&&d.audioContext.suspend(),!!(d.audioContext&&d.audioContext.createOscillator&& d.audioContext.createGain)):!1};g.prototype.initOscillator=function(c){this.oscillator=d.audioContext.createOscillator();this.oscillator.type=c.waveformShape;this.oscillator.connect(this.gainNode);this.oscillatorStarted=!1};g.prototype.setPan=function(c){this.panNode&&this.panNode.pan.setValueAtTime(c,d.audioContext.currentTime)};g.prototype.setGain=function(c,a){var e=this.gainNode;c*=this.masterVolume;e&&(1.2d?e:a},Infinity):c};g.prototype.clearPlayCallbackTimers=function(){this.playCallbackTimers.forEach(function(c){clearInterval(c)});this.playCallbackTimers=[]};g.prototype.setFrequency=function(c,a){a=a||{};c=this.getValidFrequency(c,a.min,a.max);"oscillator"===this.options.type&&this.oscillatorPlay(c)};g.prototype.oscillatorPlay=function(c){this.oscillatorStarted||(this.oscillator.start(),this.oscillatorStarted=!0);this.oscillator.frequency.setValueAtTime(c, d.audioContext.currentTime)};g.prototype.preparePlay=function(){this.setGain(.001);"suspended"===d.audioContext.state&&d.audioContext.resume();this.oscillator&&!this.oscillatorStarted&&(this.oscillator.start(),this.oscillatorStarted=!0)};g.prototype.play=function(c){var a=this,e=c.duration||0,f=function(e,f,b){var d=c.duration,g=0,k=a.options.playCallbackInterval;if("function"===typeof e){var l=setInterval(function(){g++;var c=g*k/d;if(1<=c)a[f](e(1),b),clearInterval(l);else a[f](e(c),b)},k);a.playCallbackTimers.push(l)}else a[f](e, b)};if(a.id)if("suspended"===d.audioContext.state||this.oscillator&&!this.oscillatorStarted)a.preparePlay(),setTimeout(function(){a.play(c)},10);else{a.playCallbackTimers.length&&a.clearPlayCallbackTimers();a.cancelGainRamp();a.stopOscillatorTimeout&&(clearTimeout(a.stopOscillatorTimeout),delete a.stopOscillatorTimeout);a.stopTimeout&&(clearTimeout(a.stopTimeout),delete a.stopTimeout,a.stopCallback&&(a._play=a.play,a.play=function(){},a.stopCallback("cancelled"),a.play=a._play));var b=e=c.max||d.push(new b.sonification.TimelineEvent({time:c.max})); d.length&&a.addTimelineEvents(d)})}function w(a){return a.reduce(function(a,b){return a+v(b).reduce(function(a,b){return(b=b.series&&b.seriesOptions&&b.seriesOptions.timeExtremes)?Math.max(a,b.max-b.min):a},0)},0)}function F(a,c){var e=Math.max(c-E(a),0),d=w(a);return a.reduce(function(a,c){c=v(c).reduce(function(a,c){c instanceof b.sonification.TimelinePath?a.push(c):c.series&&(c.seriesOptions.duration=c.seriesOptions.duration||p.virtualAxisTranslate(c.seriesOptions.timeExtremes.max-c.seriesOptions.timeExtremes.min, {min:0,max:d},{min:0,max:e}),a.push(f(c.series,c.seriesOptions)));return a},[]);a.push(c);return a},[])}function G(a,b){if(b&&b.instruments)return b.instruments;var c=a.chart.options.sonification&&a.chart.options.sonification.defaultInstrumentOptions||{},e=function(a){L(a,function(b,c){null===b&&delete a[c]})};return(a.options.sonification&&a.options.sonification.instruments||[{}]).map(function(a){e(a.mapping||{});e(a);return{instrument:a.instrument||c.instrument,instrumentOptions:u(c,a,{mapping:void 0, instrument:void 0}),instrumentMapping:u(c.mapping,a.mapping)}})}function C(a){var b=a.options.sonification||{},c=a.chart.options.sonification||{},e=c.events||{},f=b.events||{};return{onEnd:f.onSeriesEnd||e.onSeriesEnd,onStart:f.onSeriesStart||e.onSeriesStart,onPointEnd:f.onPointEnd||e.onPointEnd,onPointStart:f.onPointStart||e.onPointStart,pointPlayTime:c.defaultInstrumentOptions&&c.defaultInstrumentOptions.mapping&&c.defaultInstrumentOptions.mapping.pointPlayTime,masterVolume:c.masterVolume,instruments:G(a), earcons:b.earcons||c.earcons}}function H(a,b){a=a.options.sonification||{};return u({duration:a.duration,afterSeriesWait:a.afterSeriesWait,pointPlayTime:a.defaultInstrumentOptions&&a.defaultInstrumentOptions.mapping&&a.defaultInstrumentOptions.mapping.pointPlayTime,order:a.order,onSeriesStart:a.events&&a.events.onSeriesStart,onSeriesEnd:a.events&&a.events.onSeriesEnd,onEnd:a.events&&a.events.onEnd},b)}"";var K=g.find,J=g.isArray,u=g.merge,x=g.pick,v=g.splat,L=g.objectEach;return{chartSonify:function(a){var c= H(this,a);this.sonification.timeline&&this.sonification.timeline.pause();this.sonification.duration=c.duration;var e=m(this,c.instruments,c.dataExtremes);a=y(c.order,this,function(a){return r(a,e,c)});a=t(a,c.afterSeriesWait||0);a=F(a,c.duration);a.forEach(function(a){z(a)});this.sonification.timeline=new b.sonification.Timeline({paths:a,onEnd:c.onEnd});this.sonification.timeline.play()},seriesSonify:function(a){var c=this.chart.options.sonification,e=this.options.sonification;a=u({duration:e&&e.duration|| c&&c.duration},C(this),a);c=f(this,a);e=this.chart.sonification;e.timeline&&e.timeline.pause();e.duration=a.duration;e.timeline=new b.sonification.Timeline({paths:[c]});e.timeline.play()},pause:function(a){this.sonification.timeline?this.sonification.timeline.pause(x(a,!0)):this.sonification.currentlyPlayingPoint&&this.sonification.currentlyPlayingPoint.cancelSonify(a)},resume:function(a){this.sonification.timeline&&this.sonification.timeline.play(a)},rewind:function(a){this.sonification.timeline&& this.sonification.timeline.rewind(a)},cancel:function(a){this.pauseSonify(a);this.resetSonifyCursor()},getCurrentPoints:function(){if(this.sonification.timeline){var a=this.sonification.timeline.getCursor();return Object.keys(a).map(function(b){return a[b].eventObject}).filter(function(a){return a instanceof h})}return[]},setCursor:function(a){var b=this.sonification.timeline;b&&v(a).forEach(function(a){b.setCursor(a.id)})},resetCursor:function(){this.sonification.timeline&&this.sonification.timeline.resetCursor()}, resetCursorEnd:function(){this.sonification.timeline&&this.sonification.timeline.resetCursorEnd()}}});m(b,"Extensions/Sonification/Timeline.js",[b["Core/Globals.js"],b["Core/Utilities.js"],b["Extensions/Sonification/Utilities.js"]],function(b,h,g){function d(a){this.init(a||{})}function l(a){this.init(a)}function k(a){this.init(a||{})}var m=h.merge,n=h.splat,c=h.uniqueKey;d.prototype.init=function(a){this.options=a;this.time=a.time||0;this.id=this.options.id=a.id||c()};d.prototype.play=function(a){var b= this.options.eventObject,c=this.options.onEnd,d=a&&a.onEnd,g=this.options.playOptions&&this.options.playOptions.onEnd;a=m(this.options.playOptions,a);b&&b.sonify?(a.onEnd=c||d||g?function(){var a=arguments;[c,d,g].forEach(function(b){b&&b.apply(this,a)})}:void 0,b.sonify(a)):(d&&d(),c&&c())};d.prototype.cancel=function(a){this.options.eventObject.cancelSonify(a)};l.prototype.init=function(a){this.options=a;this.id=this.options.id=a.id||c();this.cursor=0;this.eventsPlaying={};this.events=a.silentWait? [new d({time:0}),new d({time:a.silentWait})]:this.options.events;this.targetDuration=a.targetDuration||a.silentWait;this.sortEvents();this.updateEventIdMap();this.signalHandler=new g.SignalHandler(["playOnEnd","masterOnEnd","onStart","onEventStart","onEventEnd"]);this.signalHandler.registerSignalCallbacks(m(a,{masterOnEnd:a.onEnd}))};l.prototype.sortEvents=function(){this.events=this.events.sort(function(a,b){return a.time-b.time})};l.prototype.updateEventIdMap=function(){this.eventIdMap=this.events.reduce(function(a, b,c){a[b.id]=c;return a},{})};l.prototype.addTimelineEvents=function(a){this.events=this.events.concat(a);this.sortEvents();this.updateEventIdMap()};l.prototype.getCursor=function(){return this.events[this.cursor]};l.prototype.setCursor=function(a){a=this.eventIdMap[a];return"undefined"!==typeof a?(this.cursor=a,!0):!1};l.prototype.play=function(a){this.pause();this.signalHandler.emitSignal("onStart");this.signalHandler.clearSignalCallbacks(["playOnEnd"]);this.signalHandler.registerSignalCallbacks({playOnEnd:a}); this.playEvents(1)};l.prototype.rewind=function(a){this.pause();this.signalHandler.emitSignal("onStart");this.signalHandler.clearSignalCallbacks(["playOnEnd"]);this.signalHandler.registerSignalCallbacks({playOnEnd:a});this.playEvents(-1)};l.prototype.resetCursor=function(){this.cursor=0};l.prototype.resetCursorEnd=function(){this.cursor=this.events.length-1};l.prototype.pause=function(a){var b=this;clearTimeout(b.nextScheduledPlay);Object.keys(b.eventsPlaying).forEach(function(c){b.eventsPlaying[c]&& b.eventsPlaying[c].cancel(a)});b.eventsPlaying={}};l.prototype.playEvents=function(a){var b=this,c=b.events[this.cursor],d=b.events[this.cursor+a],g=function(a){b.signalHandler.emitSignal("masterOnEnd",a);b.signalHandler.emitSignal("playOnEnd",a)};c.timelinePath=b;if(!1===b.signalHandler.emitSignal("onEventStart",c))g({event:c,cancelled:!0});else if(b.eventsPlaying[c.id]=c,c.play({onEnd:function(a){a={event:c,cancelled:!!a};delete b.eventsPlaying[c.id];b.signalHandler.emitSignal("onEventEnd",a);d|| g(a)}}),d){var h=Math.abs(d.time-c.time);1>h?(b.cursor+=a,b.playEvents(a)):this.nextScheduledPlay=setTimeout(function(){b.cursor+=a;b.playEvents(a)},h)}};k.prototype.init=function(a){this.options=a;this.cursor=0;this.paths=a.paths||[];this.pathsPlaying={};this.signalHandler=new g.SignalHandler(["playOnEnd","masterOnEnd","onPathStart","onPathEnd"]);this.signalHandler.registerSignalCallbacks(m(a,{masterOnEnd:a.onEnd}))};k.prototype.play=function(a){this.pause();this.signalHandler.clearSignalCallbacks(["playOnEnd"]); this.signalHandler.registerSignalCallbacks({playOnEnd:a});this.playPaths(1)};k.prototype.rewind=function(a){this.pause();this.signalHandler.clearSignalCallbacks(["playOnEnd"]);this.signalHandler.registerSignalCallbacks({playOnEnd:a});this.playPaths(-1)};k.prototype.playPaths=function(a){var c=this,d=c.signalHandler;if(c.paths.length){var g=n(this.paths[this.cursor]),h=this.paths[this.cursor+a],k=0,l=function(b){d.emitSignal("onPathStart",b);c.pathsPlaying[b.id]=b;b[0=g.length&&(h&&!e?(c.cursor+=a,n(h).forEach(function(b){b[0