/** * Highcharts JS v11.2.0 (2023-10-30) * * Sonification module * * (c) 2010-2022 Highsoft AS * Author: Øystein Moseng * * License: www.highcharts.com/license */!function(e){"object"==typeof module&&module.exports?(e.default=e,module.exports=e):"function"==typeof define&&define.amd?define("highcharts/modules/sonification",["highcharts"],function(t){return e(t),e.Highcharts=t,e}):e("undefined"!=typeof Highcharts?Highcharts:void 0)}(function(e){"use strict";var t=e?e._modules:{};function i(e,t,i,n){e.hasOwnProperty(t)||(e[t]=n.apply(null,i),"function"==typeof CustomEvent&&window.dispatchEvent(new CustomEvent("HighchartsModuleLoaded",{detail:{path:t,module:e[t]}})))}i(t,"Extensions/Sonification/Options.js",[],function(){return{sonification:{enabled:!0,duration:6e3,afterSeriesWait:700,updateInterval:200,masterVolume:.7,order:"sequential",showTooltip:!0,showCrosshair:!0,pointGrouping:{enabled:!0,groupTimespan:15,algorithm:"minmax",prop:"y"},defaultInstrumentOptions:{roundToMusicalNotes:!0,instrument:"piano",mapping:{time:"x",pan:"x",noteDuration:200,pitch:{mapTo:"y",min:"c2",max:"c6",within:"yAxis"},gapBetweenNotes:100}},defaultSpeechOptions:{language:"en-US",mapping:{time:"x",rate:1.3,volume:.4},pointGrouping:{algorithm:"last"}}},exporting:{menuItemDefinitions:{downloadMIDI:{textKey:"downloadMIDI",onclick:function(){this.sonification&&this.sonification.downloadMIDI()}},playAsSound:{textKey:"playAsSound",onclick:function(){var e=this.sonification;e&&e.isPlaying()?e.cancel():this.sonify()}}}},lang:{downloadMIDI:"Download MIDI",playAsSound:"Play as sound"}}}),i(t,"Extensions/Sonification/SynthPatch.js",[t["Core/Utilities.js"]],function(e){var t=this&&this.__assign||function(){return(t=Object.assign||function(e){for(var t,i=1,n=arguments.length;i1&&e.unshift({t:0,vol:s?0:1}),e.forEach(function(t,n){var s=e[n-1],a=s?(t.t-s.t)/1e3:0,l=i+(s?s.t/1e3+u.stopRampTime:0);r.setTargetAtTime(t.vol*o,l,Math.max(a,u.stopRampTime)/2)})}var l=function(){function e(e,t){this.pulseWidth=Math.min(Math.max(0,t.pulseWidth||.5));var i=function(){return new OscillatorNode(e,{type:"sawtooth",detune:t.detune,frequency:Math.max(1,t.frequency||350)})};this.sawOscA=i(),this.sawOscB=i(),this.phaseInverter=new GainNode(e,{gain:-1}),this.masterGain=new GainNode(e),this.delayNode=new DelayNode(e,{delayTime:this.pulseWidth/this.sawOscA.frequency.value}),this.sawOscA.connect(this.masterGain),this.sawOscB.connect(this.phaseInverter),this.phaseInverter.connect(this.delayNode),this.delayNode.connect(this.masterGain)}return e.prototype.connect=function(e){this.masterGain.connect(e)},e.prototype.getFrequencyFacade=function(){var e=this;return{cancelScheduledValues:function(t){return e.sawOscA.frequency.cancelScheduledValues(t),e.sawOscB.frequency.cancelScheduledValues(t),e.delayNode.delayTime.cancelScheduledValues(t),e.sawOscA.frequency},setValueAtTime:function(t,i){return this.cancelScheduledValues(i),e.sawOscA.frequency.setValueAtTime(t,i),e.sawOscB.frequency.setValueAtTime(t,i),e.delayNode.delayTime.setValueAtTime(Math.round(1e4*e.pulseWidth/t)/1e4,i),e.sawOscA.frequency},setTargetAtTime:function(t,i,n){return this.cancelScheduledValues(i),e.sawOscA.frequency.setTargetAtTime(t,i,n),e.sawOscB.frequency.setTargetAtTime(t,i,n),e.delayNode.delayTime.setTargetAtTime(Math.round(1e4*e.pulseWidth/t)/1e4,i,n),e.sawOscA.frequency}}},e.prototype.getPWMTarget=function(){return this.delayNode.delayTime},e.prototype.start=function(){this.sawOscA.start(),this.sawOscB.start()},e.prototype.stop=function(e){this.sawOscA.stop(e),this.sawOscB.stop(e)},e}(),c=function(){function e(e,t,i){this.audioContext=e,this.options=t,this.fmOscillatorIx=t.fmOscillator,this.vmOscillatorIx=t.vmOscillator,this.createSoundSource(),this.createGain(),this.createFilters(),this.createVolTracking(),i&&this.connect(i)}return e.prototype.connect=function(e){[this.lowpassNode,this.highpassNode,this.volTrackingNode,this.vmNode,this.gainNode,this.whiteNoise,this.pulseNode,this.oscNode].reduce(function(e,t){return t?(t.connect(e),t):e},e)},e.prototype.start=function(){this.oscNode&&this.oscNode.start(),this.whiteNoise&&this.whiteNoise.start(),this.pulseNode&&this.pulseNode.start()},e.prototype.stopAtTime=function(e){this.oscNode&&this.oscNode.stop(e),this.whiteNoise&&this.whiteNoise.stop(e),this.pulseNode&&this.pulseNode.stop(e)},e.prototype.setFreqAtTime=function(e,t,n){void 0===n&&(n=0);var s=this.options,a=i(o(s.fixedFrequency,t)*(s.freqMultiplier||1),0,21e3),r=this.getOscTarget(),l=n/5e3;r&&(r.cancelScheduledValues(e),n&&e-(this.lastUpdateTime||-1)>.01?(r.setTargetAtTime(a,e,l),r.setValueAtTime(a,e+l)):r.setValueAtTime(a,e)),this.scheduleVolTrackingChange(a,e,n),this.scheduleFilterTrackingChange(a,e,n),this.lastUpdateTime=e},e.prototype.getFMTarget=function(){return this.oscNode&&this.oscNode.detune||this.whiteNoise&&this.whiteNoise.detune||this.pulseNode&&this.pulseNode.getPWMTarget()},e.prototype.getVMTarget=function(){return this.vmNode&&this.vmNode.gain},e.prototype.runEnvelopeAtTime=function(e,t){this.gainNode&&r(("attack"===e?this.options.attackEnvelope:this.options.releaseEnvelope)||[],e,t,this.gainNode,this.options.volume)},e.prototype.cancelScheduled=function(){this.gainNode&&this.gainNode.gain.cancelScheduledValues(this.audioContext.currentTime);var e=this.getOscTarget();e&&e.cancelScheduledValues(0),this.lowpassNode&&this.lowpassNode.frequency.cancelScheduledValues(0),this.highpassNode&&this.highpassNode.frequency.cancelScheduledValues(0),this.volTrackingNode&&this.volTrackingNode.gain.cancelScheduledValues(0)},e.prototype.scheduleVolTrackingChange=function(e,t,i){if(this.volTrackingNode){var n=s(this.options.volumePitchTrackingMultiplier||1,e),o=i?i/1e3:u.stopRampTime;this.volTrackingNode.gain.cancelScheduledValues(t),this.volTrackingNode.gain.setTargetAtTime(n,t,o/5),this.volTrackingNode.gain.setValueAtTime(n,t+o)}},e.prototype.scheduleFilterTrackingChange=function(e,t,n){var o=this.options,a=n?n/1e3:u.stopRampTime,r=function(n,o){var r=s(o.frequencyPitchTrackingMultiplier||1,e),l=i((o.frequency||1e3)*r,0,21e3);n.frequency.cancelScheduledValues(t),n.frequency.setTargetAtTime(l,t,a/5),n.frequency.setValueAtTime(l,t+a)};this.lowpassNode&&o.lowpass&&r(this.lowpassNode,o.lowpass),this.highpassNode&&o.highpass&&r(this.highpassNode,o.highpass)},e.prototype.createGain=function(){var e=this.options;(n(e.volume)||e.attackEnvelope&&e.attackEnvelope.length||e.releaseEnvelope&&e.releaseEnvelope.length)&&(this.gainNode=new GainNode(this.audioContext,{gain:o(e.volume,1)})),this.vmNode=new GainNode(this.audioContext)},e.prototype.createSoundSource=function(){var e=this.options,t=this.audioContext,i=(e.fixedFrequency||0)*(e.freqMultiplier||1);if("whitenoise"===e.type){for(var n=2*t.sampleRate,o=t.createBuffer(1,n,t.sampleRate),s=o.getChannelData(0),a=0;ae.time;);this.events.splice(i+1,0,e)}else this.events.push(e);return e},e.prototype.mute=function(){this.muted=!0},e.prototype.unmute=function(){this.muted=!1},e.prototype.cancel=function(){this.engine.cancel()},e.prototype.destroy=function(){this.engine.destroy()},e}()}),i(t,"Extensions/Sonification/MIDI.js",[t["Extensions/Sonification/SonificationInstrument.js"],t["Core/Utilities.js"]],function(e,t){var i=t.pick,n=function(e,t){return t>>>8*e&255},o=[0,255,81,3,7,161,32],s=function(e){for(var t=127&e,i=[];e>>=7;)t<<=8,t|=127&e|128;for(;;)if(i.push(255&t),128&t)t>>=8;else break;return i},a=function(t){var n,o,s=[],a=function(e){for(var t=s.length;t--&&s[t].timeMS>e.timeMS;);s.splice(t+1,0,e)};return t.forEach(function(t){var s=t.instrumentEventOptions||{},r=t.time,l=o=i(s.noteDuration,o),c=l&&t.time+l,u=[{valMap:function(e){return 64+63*e&127},data:{10:s.pan,92:s.tremoloDepth,93:s.tremoloSpeed}},{valMap:function(e){return 127*e/2e4&127},data:{74:s.lowpassFreq,75:s.highpassFreq}},{valMap:function(e){return 63*Math.min(18,Math.max(-18,e))/18+63&127},data:{71:s.lowpassResonance,76:s.highpassResonance}}],h=n=void 0===s.volume?i(n,127):127*s.volume&127,p=s.frequency,m=s.note||0,f=12+(p?Math.round(12*Math.log(p)/Math.LN2-48.37632):"string"==typeof m?e.noteStringToC0Distance(m):m)&127;u.forEach(function(e){return Object.keys(e.data).forEach(function(t){var i=e.data[t];void 0!==i&&a({timeMS:r,type:"CTRL_CHG",data:[176,parseInt(t,10),e.valMap(i)]})})}),c&&(a({timeMS:r,type:"NON",data:[144,f,h]}),a({timeMS:c,type:"NOF",data:[128,f,h]}))}),s},r=function(e,t){var i=[];if(t&&i.push(0,192,127&t),e){for(var n=[],o=0;o1;return new Uint8Array([77,84,104,100,0,0,0,6,0,(t=s?o+1:o)>1?1:0,n(1,t),n(0,t),1,244].concat(s?l([],!0):[],i.reduce(function(e,t){var i=t.engine;return e.concat(l(t.events,!s,i.midiTrackName,i.midiInstrument))},[])))}}),i(t,"Extensions/DownloadURL.js",[t["Core/Globals.js"]],function(e){var t=e.isSafari,i=e.win,n=e.win.document,o=i.URL||i.webkitURL||i;function s(e){var t=e.replace(/filename=.*;/,"").match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/);if(t&&t.length>3&&i.atob&&i.ArrayBuffer&&i.Uint8Array&&i.Blob&&o.createObjectURL){for(var n=i.atob(t[3]),s=new i.ArrayBuffer(n.length),a=new i.Uint8Array(s),r=0;r2e6)&&!(e=s(e)||""))throw Error("Failed to convert to blob");if(void 0!==r.download)r.href=e,r.download=o,n.body.appendChild(r),r.click(),n.body.removeChild(r);else try{if(!i.open(e,"chart"))throw Error("Failed to open window")}catch(t){i.location.href=e}}}}),i(t,"Extensions/Sonification/SonificationTimeline.js",[t["Extensions/Sonification/TimelineChannel.js"],t["Extensions/Sonification/MIDI.js"],t["Extensions/DownloadURL.js"],t["Core/Utilities.js"]],function(e,t,i,n){var o=i.downloadURL,s=n.defined,a=n.find,r=n.merge;return function(){function i(e,t){this.chart=t,this.isPaused=!1,this.isPlaying=!1,this.channels=[],this.scheduledCallbacks=[],this.playTimestamp=0,this.resumeFromTime=0,this.options=e||{}}return i.prototype.addChannel=function(t,i,n,o){if(void 0===n&&(n=!1),"instrument"===t&&!i.scheduleEventAtTime||"speech"===t&&!i.sayAtTime)throw Error("Highcharts Sonification: Invalid channel engine.");var s=new e(t,i,n,o);return this.channels.push(s),s},i.prototype.play=function(t,i,n,o){var s,l,c=this;void 0===i&&(i=!0),void 0===n&&(n=!0),this.isPlaying?this.cancel():this.clearScheduledCallbacks(),this.onEndArgument=o,this.playTimestamp=Date.now(),this.resumeFromTime=0,this.isPaused=!1,this.isPlaying=!0;var u=this.options.skipThreshold||2,h=this.options.onPlay,p=this.options.showTooltip,m=this.options.showCrosshair,f=t?(l=(s=(this.playingChannels||this.channels).map(function(e){return e.cancel(),{channel:e,filteredEvents:e.muted?[]:e.events.filter(t)}})).reduce(function(e,t){return Math.min(e,t.filteredEvents.length?t.filteredEvents[0].time:1/0)},1/0),s.map(function(t){return new e(t.channel.type,t.channel.engine,t.channel.showPlayMarker,t.filteredEvents.map(function(e){return r(e,{time:e.time-l})}),t.channel.muted)})):this.channels,d=[];i&&(this.playingChannels=f),h&&h({chart:this.chart,timeline:this});var y=0;f.forEach(function(e){if(!e.muted){var t=e.events.length,i=-1/0,n=-1/0,o="";y=Math.max(e.events[t-1]&&e.events[t-1].time||0,y);for(var s=0;s50||s===t-1);h&&d.push(h),y&&(c.scheduledCallbacks.push(setTimeout(function(){if(r.callback&&r.callback(),h){if(m){var e=h.series;e&&e.xAxis&&e.xAxis.crosshair&&e.xAxis.drawCrosshair(void 0,h),e&&e.yAxis&&e.yAxis.crosshair&&e.yAxis.drawCrosshair(void 0,h)}p&&!(f&&f.hoverPoints&&f.hoverPoints.length>1&&a(f.hoverPoints,function(e){return e===h})&&h.onMouseOver)&&h.onMouseOver()}},r.time)),i=r.time)}}(s)}});var v=this.options.onEnd,g=this.options.onStop;this.scheduledCallbacks.push(setTimeout(function(){var e=c.chart,t={chart:e,timeline:c,pointsPlayed:d};c.isPlaying=!1,n&&c.resetPlayState(),g&&g(t),v&&v(t),o&&o(t),e&&(e.tooltip&&e.tooltip.hide(0),e.hoverSeries&&e.hoverSeries.onMouseOut(),e.axes.forEach(function(e){return e.hideCrosshair()}))},y+250)),this.resumeFromTime=i?y:this.getLength()},i.prototype.pause=function(){return this.isPaused=!0,this.cancel(),this.resumeFromTime=Date.now()-this.playTimestamp-10,this.resumeFromTime},i.prototype.getCurrentTime=function(){return this.isPlaying?Date.now()-this.playTimestamp:this.resumeFromTime},i.prototype.getLength=function(){return this.channels.reduce(function(e,t){var i=t.events[t.events.length-1];return i?Math.max(i.time,e):e},0)},i.prototype.resume=function(){if(this.playingChannels){var e=this.resumeFromTime-50;this.play(function(t){return t.time>e},!1,!1,this.onEndArgument),this.playTimestamp-=e}else this.play(void 0,!1,!1,this.onEndArgument)},i.prototype.anchorPlayMoment=function(e,t){this.isPlaying&&this.pause();var i=0;this.play(function(t,n,o){var s=e(t,n,o);return s&&t.time>i&&(i=t.time),s},!1,!1,t),this.playingChannels=this.playingChannels||this.channels,this.isPaused=!0,this.isPlaying=!1,this.resumeFromTime=i},i.prototype.playAdjacent=function(e,t,i,n){this.isPlaying&&this.pause();var o=this.resumeFromTime,s=this.channels.reduce(function(t,i){for(var s=n?i.events.filter(n):i.events,a=0,r=s.length,l=t;a>1,u=s[c].time,h=u-o;h>0?(e&&ul&&(l=u),a=c+1):e?a=c+1:r=c}return l},e?1/0:-1/0);if(s===1/0||s===-1/0){i&&i({chart:this.chart,timeline:this,attemptedNext:e});return}this.anchorPlayMoment(function(t,i,a){var r=e?t.time>o&&t.time<=s+.02:t.time=s-.02;return n?r&&n(t,i,a):r},t)},i.prototype.playClosestToPropValue=function(e,t,i,n,o){var a=1/0,r=null;(this.playingChannels||this.channels).forEach(function(i){for(var n=i.events,l=n.length;l--;)if(c=n[l],u=l,o?!!o(c,u,n)&&!!c.relatedPoint:!!c.relatedPoint){var c,u,h=n[l].relatedPoint[e],p=s(h)&&Math.abs(t-h);!1!==p&&pr.time-1&&e.relatedPoint===r.relatedPoint)},!1,!1,i),this.playingChannels=this.playingChannels||this.channels,this.isPaused=!0,this.isPlaying=!1,this.resumeFromTime=r.time):n&&n({chart:this.chart,timeline:this})},i.prototype.getEventsForPoint=function(e){return this.channels.reduce(function(t,i){var n=i.events.filter(function(t){return t.relatedPoint===e});return t.concat(n)},[])},i.prototype.playSegment=function(e,t){var i={first:1/0,last:-1/0};if(this.channels.forEach(function(e){e.events.length&&(i.first=Math.min(e.events[0].time,i.first),i.last=Math.max(e.events[e.events.length-1].time,i.last))}),i.first<1/0){var n=(i.last-i.first)/100,o=i.first+e*n,s=o+n;if(!this.channels.some(function(e){for(var t=e.events,i=0,n=t.length;i>1,r=t[a].time;if(rs))return!0;n=a}}return!1}))return;this.play(function(e){return e.time>=o&&e.time<=s},!1,!1,t),this.playingChannels=this.playingChannels||this.channels,this.isPaused=!0,this.isPlaying=!1,this.resumeFromTime=s}},i.prototype.getLastPlayedPoint=function(e){var t=this.getCurrentTime(),i=this.playingChannels||this.channels,n=1/0,o=null;return i.forEach(function(i){var s=i.events.filter(function(i,n,o){return!!(i.relatedPoint&&i.time<=t&&(!e||e(i,n,o)))}),a=s[s.length-1];if(a){var r=Math.abs(a.time-t);r0?function(e){return Math.log(e)/Math.LOG10E}:function(e){var t=Math.abs(e);t<10&&(t+=(10-t)/10);var i=Math.log(t)/Math.LN10;return e<0?-i:i},u=c(t.min);l=r*(c(e)-u)/(c(t.max)-u)}return a(n?i.max-l:i.min+l,i.min,i.max)}function y(e,t,i,n,o,s,a){return h(function(e,t,i,n,o,s){if("number"==typeof o)return o;if("function"==typeof o)return o(l({time:0},e));var a,u=o,p=n.mapFunction,m=n.min,f=n.max,y=n.within;if("object"==typeof o&&(u=o.mapTo,p=o.mapFunction||p,m=h(o.min,m),f=h(o.max,f),y=o.within||n.within,a=o.scale),!u)return null;var v="-"===u.charAt(0);v&&(u=u.slice(1));var g=e.value,q="value"===u&&void 0!==g&&s;if(!q){var T=o.value;if(void 0!==T)g=T;else{if(!e.point)return null;g=e.point[u]}void 0===g&&(g=c(u,e.point))}if("number"!=typeof g||null===g)return null;var w=null;if(e.point){if("xAxis"===y||"yAxis"===y){var x=e.point.series[y];x&&r(x.dataMin)&&r(x.dataMax)&&(w={min:x.dataMin,max:x.dataMax})}else("series"===y||i)&&e.point.series&&(w=t.seriesExtremes[e.point.series.index][q?s:u])}if(w||(w=t.globalExtremes[q?s:u]),a){for(var E=[],S=Math.floor(m/12),N=Math.ceil(f/12)+1,P=a.length,k=S;k=m&&b<=f&&E.push(b)}var C=d(g,w,{min:0,max:E.length-1},v,"logarithmic"===p);return E[Math.round(C)]}return d(g,w,{min:m,max:f},v,"logarithmic"===p)}(e,t,i,l({min:0,max:1,mapTo:"y",mapFunction:"linear",within:"chart"},s||{}),n,a),o)}function v(e,n,o,s){var a=s.mapping||{},r="speech"===s.type?new i({language:s.language,name:s.preferredVoice}):new t(n,o,{capabilities:{pan:!!a.pan,tremolo:!!a.tremolo,filters:!!(a.highpass||a.lowpass)},synthPatch:s.instrument,midiTrackName:s.midiName});return e.addChannel(s.type||"instrument",r,h(s.showPlayMarker,!0))}function g(e,i,n,o,s,a){var r=function(t,i,s,r){return y(e,o,!1,(r||n)[t],i,s,a)},c=[],u={noteDuration:r("noteDuration",200,{min:40,max:1e3}),pan:r("pan",0,{min:-1,max:1}),volume:r("volume",1,{min:.1,max:1})};n.frequency&&(u.frequency=r("frequency",440,{min:50,max:6e3})),n.lowpass&&(u.lowpassFreq=r("frequency",2e4,{min:0,max:2e4},n.lowpass),u.lowpassResonance=r("resonance",0,{min:-6,max:12},n.lowpass)),n.highpass&&(u.highpassFreq=r("frequency",2e4,{min:0,max:2e4},n.highpass),u.highpassResonance=r("resonance",0,{min:-6,max:12},n.highpass)),n.tremolo&&(u.tremoloDepth=r("depth",0,{min:0,max:.8},n.tremolo),u.tremoloSpeed=r("speed",0,{min:0,max:.8},n.tremolo));var h=r("gapBetweenNotes",150,{min:50,max:1e3}),p=r("playDelay",0,{max:200}),f=function(n,r){void 0===r&&(r=0);var f=n;n.mapTo?("string"==typeof n.min&&(f.min=t.noteStringToC0Distance(n.min)),"string"==typeof n.max&&(f.max=t.noteStringToC0Distance(n.max))):"string"==typeof n&&m(n)&&(f=t.noteStringToC0Distance(n)),u.note=y(e,o,!1,f,-1,{min:0,max:107},a),u.note>-1&&(s&&(u.note=Math.round(u.note)),c.push(i.addEvent({time:e.time+p+h*r,relatedPoint:e.point,instrumentEventOptions:void 0!==r?l({},u):u})))};return n.pitch&&n.pitch.constructor===Array?n.pitch.forEach(f):n.pitch?f(n.pitch):n.frequency&&c.push(i.addEvent({time:e.time+p,relatedPoint:e.point,instrumentEventOptions:u})),c}function q(e,t,i,n,o){var s,a=function(t,s,a){return y(e,n,!1,i[t],s,a,o)},r=a("playDelay",0,{max:200}),l=a("pitch",1,{min:.3,max:2}),c=a("rate",1,{min:.4,max:4}),u=a("volume",1,{min:.1}),h=p("function"==typeof(s=i.text)?s(e):s,e,e.point&&e.point.series.chart);if(h)return t.addEvent({time:e.time+r,relatedPoint:e.point,speechOptions:{pitch:l,rate:c,volume:u},message:h})}function T(e,t,i){if("function"==typeof t)return t(e);if("object"==typeof t){var n=t.prop,o=h(e.value,e.point&&f(e.point,n));if("number"!=typeof o)return!1;var s=!0,a=t.crossingUp,r=t.crossingDown,l="number"==typeof i;s=a&&r?l&&(i=a||i>r&&o<=r):(void 0===a||l&&i=a)&&(void 0===r||l&&i>r&&o<=r);var c=h(t.max,1/0),u=h(t.min,-1/0);return o<=c&&o>=u&&s}return!0}return function(t,i,n){var o,a,r,p,w,x,E,S,N,P,k,M,b=n.options.sonification||{},C=b.defaultInstrumentOptions,A=b.defaultSpeechOptions,O=u({enabled:!0,groupTimespan:15,algorithm:"minmax",prop:"y"},b.pointGrouping),I=b.globalTracks||[],V=b.globalContextTracks||[],j="sequential"===b.order,F=Math.max(50,b.duration-300),D=b.afterSeriesWait,Q=b.events||{},R=(a=((o=n.options.sonification||{}).defaultInstrumentOptions||{}).mapping||{time:"x",pitch:"y"},r=o.defaultSpeechOptions&&o.defaultSpeechOptions.mapping||{},p=[],w={},x=function(e,t){null!==t?(p[t]=p[t]||{},p[t][e]=!0):w[e]=!0},E={},S={},N=function(e,t,i){var n=function(e){return"-"===e.charAt(0)?e.slice(1):e};if("string"==typeof t&&"text"!==e){if("pitch"===e&&m(t))return;"time"===e&&(S[t]=!0,x(t,i)),E[n(t)]=!0;return}if(t&&t.mapTo&&"string"==typeof t.mapTo){var o=n(t.mapTo);"time"===e&&x(o,i),("time"===e||"series"===t.within)&&(S[o]=!0),E[o]=!0;return}["tremolo","lowpass","highpass"].indexOf(e)>-1&&"object"==typeof t&&Object.keys(t).forEach(function(e){return N(e,t[e],i)})},P=function(e,t){Object.keys(e).forEach(function(i){return N(i,e[i],t)})},k=function(e){return e.forEach(function(e){E[e.valueProp||"x"]=S[e.valueProp||"x"]=!0})},P(a,null),P(r,null),k(o.globalContextTracks||[]),M=Object.keys(w).length,n.series.forEach(function(e){var t=e.options.sonification;if(e.visible&&!(t&&!1===t.enabled)&&(M&&(p[e.index]=u(w)),t)){var i=(t.defaultInstrumentOptions||{}).mapping,n=(t.defaultSpeechOptions||{}).mapping;i&&P(i,e.index),n&&P(n,e.index),k(t.contextTracks||[]),(t.tracks||[]).concat(t.contextTracks||[]).forEach(function(t){t.mapping&&P(t.mapping,e.index)})}}),s({seriesTimeProps:p},function(e,t,i){for(var n=e.series,o=t.length,s=i.length,a=function(e){return e.reduce(function(e,t){return e[t]={min:1/0,max:-1/0},e},{})},r=function(e,t,i){var n=t[i];void 0===n&&(n=c(i,t)),"number"==typeof n&&(e[i].min=Math.min(e[i].min,n),e[i].max=Math.max(e[i].max,n))},l=a(t),u=n.length,h=Array(u);u--;){var p=a(i),m=n[u].options;if(n[u].visible&&(!m||!m.sonification||!1!==m.sonification.enabled)){for(var f=n[u].points||[],d=f.length;d--;){for(var y=o;y--;)r(l,f[d],t[y]);for(y=s;y--;)r(p,f[d],i[y])}h[u]=p}}return{globalExtremes:l,seriesExtremes:h}}(n,Object.keys(E),Object.keys(S)))),U=new e({onPlay:Q.onPlay,onEnd:Q.onEnd,onStop:Q.onStop,showCrosshair:b.showCrosshair,showTooltip:b.showTooltip},n);n.sonification&&(n.sonification.propMetrics=R);var G=0;return n.series.forEach(function(e,n){var o=e.options.sonification||{};if(e.visible&&!1!==o.enabled){var s,a=j?function(e,t,i,n){var o,s,a=t-(e.chart.series.length-1)*n;if(i.seriesTimeProps.every(function(e){var t=Object.keys(e);return!(t.length>1)&&(o||(o=t[0]),o===t[0])})){var r=i.seriesExtremes[e.index][o];s=Math.round((r.max-r.min)/i.seriesExtremes.reduce(function(e,t){return t[o]?e+t[o].max-t[o].min:e},0)*a)}else{var l=e.chart.series.reduce(function(e,t){return e+t.points.length},0);s=Math.round((e.points||[]).length/l*a)}return Math.max(50,s)}(e,F,R,D):F,r=u(C,o.defaultInstrumentOptions),c=u(A,o.defaultSpeechOptions),p=u(O,o.pointGrouping),m=(o.tracks||[r]).concat(I),w=U.channels.length&&!j?o.contextTracks||[]:(o.contextTracks||[]).concat(V),x=[];m.forEach(function(n){var o=u({pointGrouping:p,midiName:n.midiName||e.name},"speech"===n.type?c:r,n),l=o.pointGrouping,m=o.activeWhen,d=function(e){"object"==typeof m&&m.prop&&(s=f(e,m.prop))},w=v(U,t,i,o),E=function(e){return x.push.apply(x,function(e,t,i,n){var o=[];if("speech"===i.type&&i.mapping){var s=q(e,t,i.mapping,n);s&&(o=[s])}else i.mapping&&(o=g(e,t,i.mapping,n,h(i.roundToMusicalNotes,!0)));return o}(e,w,o,R))},S=[],N=0,P=function(e){if(1===S.length)E({point:S[0].point,time:N+e/2});else{var t=function(e,t){var i=e.algorithm||"minmax",n=function(e){return t[e]?[t[e].point]:[]};if("first"===i)return n(0);if("last"===i)return n(t.length-1);if("middle"===i)return n(t.length>>1);if("firstlast"===i)return n(0).concat(n(t.length-1));if("minmax"===i){var o,s,a,r,l=e.prop||"y";if(t.forEach(function(e){var t=f(e.point,l);void 0!==t&&((!o||tr)&&(s=e,r=t))}),o&&s)return o.point===s.point?[o.point]:o.time>s.time?[s.point,o.point]:[o.point,s.point]}return[]}(l,S),i=e/t.length;t.forEach(function(e,t){return E({point:e,time:N+i/2+i*t})})}S=[]};(e.points||[]).forEach(function(t,i){var n,r=i===e.points.length-1,c=(n=G,y({point:t,time:0},R,j,o.mapping&&o.mapping.time||0,0,{min:0,max:a,mapTo:"x"})+n),u={point:t,time:c};if(!o.mapping||!T(u,m,s)){d(t),r&&S.length&&P(S[S.length-1].time-S[0].time);return}if(d(t),l.enabled){var h=c-N,p=l.groupTimespan,f=r&&h<=p?h:p;r||h>p?(h<=p&&S.push(u),P(f),N=Math.floor(c/p)*p,r&&h>p?E({point:u.point,time:N+f/2}):S=[u]):S.push(u)}else E(u)})});var E=x.reduce(function(e,t){return t.timee.time?t:e},{time:-1/0});E.callback=Q.onSeriesStart?Q.onSeriesStart.bind(null,{series:e,timeline:U}):void 0,S.callback=Q.onSeriesEnd?Q.onSeriesEnd.bind(null,{series:e,timeline:U}):void 0,w.forEach(function(e){var o="speech"===e.type?u(A,e):u(C,{mapping:{pitch:{mapTo:"value"}}},e),r=v(U,t,i,o);s=void 0;var c=o.timeInterval,p=o.valueInterval,m=o.valueProp||"x",f=o.activeWhen,y=R.seriesExtremes[n][m],w=function(e,t){if(!o.mapping||!T({time:e,value:t},"object"==typeof f?l({prop:m},f):f,s)){s=t;return}s=t,"speech"===o.type?q({time:e,value:t},r,o.mapping,R,m):g({time:e,value:t},r,o.mapping,R,h(o.roundToMusicalNotes,!0),m)};if(c)for(var x=0;x<=a;){var E=d(x,{min:0,max:a},y);w(x+G,E),x+=c}if(p)for(var E=y.min;E<=y.max;){var x=d(E,y,{min:0,max:a},!1,"logarithmic"===o.valueMapFunction);w(x+G,E),E+=p}}),j&&(G+=a+D)}}),U}}),i(t,"Extensions/Sonification/Sonification.js",[t["Core/Defaults.js"],t["Core/Utilities.js"],t["Core/Globals.js"],t["Extensions/Sonification/Options.js"],t["Extensions/Sonification/SonificationInstrument.js"],t["Extensions/Sonification/SonificationSpeaker.js"],t["Extensions/Sonification/SynthPatch.js"],t["Extensions/Sonification/InstrumentPresets.js"],t["Extensions/Sonification/TimelineFromChart.js"]],function(e,t,i,n,o,s,a,r,l){var c=e.defaultOptions,u=e.getOptions,h=t.addEvent,p=t.extend,m=t.fireEvent,f=t.merge,d=t.pick,y=i.doc,v=i.win,g=function(){function e(e){this.chart=e,this.retryContextCounter=0,this.lastUpdate=0,this.unbindKeydown=h(y,"keydown",function(t){e&&e.sonification&&("Esc"===t.key||"Escape"===t.key)&&e.sonification.cancel()});try{this.audioContext=new v.AudioContext,this.audioContext.suspend(),this.audioDestination=this.audioContext.destination}catch(e){}}return e.prototype.setAudioDestination=function(e){this.audioDestination=e,this.update()},e.prototype.isPlaying=function(){return!!this.timeline&&this.timeline.isPlaying},e.prototype.playSegment=function(e,t){this.ready(this.playSegment.bind(this,e,t))&&this.timeline&&this.timeline.playSegment(e,t)},e.prototype.playAdjacent=function(e,t,i){var n=this;if(this.ready(this.playAdjacent.bind(this,e,t,i))&&this.timeline){var o=this.chart.options.sonification,s=o&&o.events&&o.events.onBoundaryHit;s||this.initBoundaryInstrument(),this.timeline.playAdjacent(e,t,s||function(){n.defaultBoundaryHit()},i)}},e.prototype.playAdjacentSeries=function(e,t,i){void 0===t&&(t="x");var n=this.getLastPlayedPoint();if(n){var o=n.series.index+(e?1:-1);return this.playClosestToProp(t,n[t],function(e){return!!e.relatedPoint&&e.relatedPoint.series.index===o},i),this.chart.series[o]||null}return null},e.prototype.playClosestToProp=function(e,t,i,n){var o=this;if(this.ready(this.playClosestToProp.bind(this,e,t,i,n))&&this.timeline){var s=this.chart.options.sonification,a=s&&s.events&&s.events.onBoundaryHit;a||this.initBoundaryInstrument(),this.timeline.playClosestToPropValue(e,t,n,a||function(){return o.defaultBoundaryHit()},i)}},e.prototype.getLastPlayedPoint=function(){return this.timeline?this.timeline.getLastPlayedPoint():null},e.prototype.playNote=function(e,t,i){if(void 0===i&&(i=0),this.ready(this.playNote.bind(this,e,t))){var n=t.noteDuration=t.noteDuration||500,s=new o(this.audioContext,this.audioDestination,{synthPatch:e,capabilities:{filters:!0,tremolo:!0,pan:!0}});s.scheduleEventAtTime(i/1e3,t),setTimeout(function(){return s&&s.destroy()},i+n+500)}},e.prototype.speak=function(e,t,i){void 0===i&&(i=0),new s(f({language:"en-US",rate:1.5,volume:.4},t||{})).sayAtTime(i,e)},e.prototype.cancel=function(){this.timeline&&this.timeline.cancel(),m(this,"cancel")},e.prototype.downloadMIDI=function(){this.ready(this.downloadMIDI.bind(this))&&this.timeline&&(this.timeline.reset(),this.timeline.downloadMIDI())},e.prototype.sonifyChart=function(e,t){this.ready(this.sonifyChart.bind(this,e,t))&&this.timeline&&(this.timeline.reset(),this.beforePlay(),this.timeline.play(void 0,void 0,e,t))},e.prototype.sonifySeries=function(e,t,i){this.ready(this.sonifySeries.bind(this,e,t,i))&&this.timeline&&(this.timeline.reset(),this.beforePlay(),this.timeline.play(function(t){return!!t.relatedPoint&&t.relatedPoint.series===e},void 0,t,i))},e.prototype.sonifyPoint=function(e,t){this.ready(this.sonifyPoint.bind(this,e,t))&&this.timeline&&(this.timeline.reset(),this.beforePlay(),this.timeline.anchorPlayMoment(function(t){return t.relatedPoint===e},t))},e.prototype.setMasterVolume=function(e){this.timeline&&this.timeline.setMasterVolume(e)},e.prototype.destroy=function(){this.unbindKeydown(),this.timeline&&(this.timeline.destroy(),delete this.timeline),this.boundaryInstrument&&this.boundaryInstrument.stop(),this.audioContext&&(this.audioContext.close(),delete this.audioContext)},e.prototype.update=function(){var e=this.chart.options&&this.chart.options.sonification;if(this.ready(this.update.bind(this))&&e){var t=Date.now(),i=e.updateInterval;if(t-this.lastUpdate