maidr 3.43.0 → 3.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/maidr.js CHANGED
@@ -304,7 +304,7 @@ You might need to use a local HTTP server (instead of file://): https://react.de
304
304
  Use arrow keys to navigate subplots and press 'ENTER'.`;case"subplot":return`This is a maidr plot containing ${n.size} layers, and
305
305
  this is layer 1 of ${n.size}: ${n.trace.traceType} plot. ${i}
306
306
  Use Arrows to navigate data points. Toggle B for Braille, T for Text,
307
- S for Sonification, and R for Review mode.`;case"trace":{let o=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(o="single line");const s=o==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${o}${s}. ${i} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}class N3{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[5],16)}}const i=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return i?{r:Number.parseInt(i[1],10),g:Number.parseInt(i[2],10),b:Number.parseInt(i[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const i=this.calculateLuminance(t),o=this.calculateLuminance(n);return(Math.max(i,o)+.05)/(Math.min(i,o)+.05)}static calculateLuminance(t){const[n,i,o]=[t.r,t.g,t.b].map(s=>{const f=s/255;return f<=.03928?f/12.92:((f+.055)/1.055)**2.4});return .2126*n+.7152*i+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}static isEqual(t,n){const i=this.parse(t),o=this.parse(n);return!i||!o?!1:i.r===o.r&&i.g===o.g&&i.b===o.b}}class Ht{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,s=await new Promise((h,y)=>{const S=new Image;S.onload=()=>h(S),S.onerror=()=>y(new Error("Failed to load SVG image")),S.src=o}),f=document.createElement("canvas");[f.width,f.height]=[s.naturalWidth,s.naturalHeight];const d=f.getContext("2d");return d?(d.drawImage(s,0,0),f.toDataURL("image/jpeg",.92)):(console.error("Error converting SVG to Base 64: Canvas context unavailable"),"")}catch(n){return console.error("Error converting SVG to Base 64:",n instanceof Error?n.message:n),""}}static selectAllElements(t,n=!0){return Array.from(document.querySelectorAll(t)).map(i=>{if(!n)return i;const o=i.cloneNode(!0);return o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i.insertAdjacentElement(ge.AFTER_END,o),o})}static selectElement(t,n=!0){const i=document.querySelector(t);if(!n)return i;const o=i==null?void 0:i.cloneNode(!0);return o==null||o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i==null||i.insertAdjacentElement(ge.AFTER_END,o),o}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(ge.FILL,ge.TRANSPARENT),n.setAttribute(ge.STROKE,ge.TRANSPARENT),n.setAttribute(ge.VISIBILITY,ge.HIDDEN),n}static createCircleElement(t,n,i){var y;const o=window.getComputedStyle(i),s=o.stroke||o.fill,f=o.strokeWidth||"2",d=Number.parseFloat(f)*2,h=document.createElementNS(this.SVG_NAMESPACE,ge.CIRCLE);return h.setAttribute(ge.CIRCLE_X,String(t)),h.setAttribute(ge.CIRCLE_Y,String(n)),h.setAttribute(ge.RADIUS,String(d)),h.setAttribute(ge.FILL,s),h.setAttribute(ge.STROKE,s),h.setAttribute(ge.STROKE_WIDTH,f),h.setAttribute(ge.VISIBILITY,ge.HIDDEN),(y=i.parentElement)==null||y.insertAdjacentElement(ge.AFTER_END,h),h}static createLineElement(t,n){const o=t.getBBox();let s,f,d,h;switch(n){case"top":[s,f,d,h]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[s,f,d,h]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[s,f,d,h]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[s,f,d,h]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const y=window.getComputedStyle(t),S=document.createElementNS(this.SVG_NAMESPACE,ge.LINE);return S.setAttribute(ge.X1,String(s)),S.setAttribute(ge.Y1,String(f)),S.setAttribute(ge.X2,String(d)),S.setAttribute(ge.Y2,String(h)),S.setAttribute(ge.STROKE,y.stroke),S.setAttribute(ge.STROKE_WIDTH,y.strokeWidth||"2"),S.setAttribute(ge.VISIBILITY,ge.HIDDEN),t.insertAdjacentElement(ge.AFTER_END,S),S}static getAdjustedOpacity(t,n){const i=t?Number.parseFloat(t):Number.NaN;return!Number.isNaN(i)&&i>n?i.toString():"1"}static createHighlightElement(t,n){const i=t.cloneNode(!0),o=t.tagName.toLowerCase(),s=o===ge.POLYLINE||o===ge.LINE,f=window.getComputedStyle(t),d=s?f.getPropertyValue(ge.STROKE):f.getPropertyValue(ge.FILL),h=this.getHighlightColor(d,n),y=f.getPropertyValue("fill-opacity"),S=f.getPropertyValue("stroke-opacity");if(i.style.fillOpacity=this.getAdjustedOpacity(y,this.MIN_VISIBLE_FILL_OPACITY),i.style.strokeOpacity=this.getAdjustedOpacity(S,this.MIN_VISIBLE_STROKE_OPACITY),i.setAttribute(ge.VISIBILITY,ge.VISIBLE),i.setAttribute(ge.STROKE,h),i.setAttribute(ge.FILL,h),i.style.fill=h,i.style.stroke=h,s){const E=window.getComputedStyle(i).getPropertyValue(ge.STROKE_WIDTH),T=E.match(/^([0-9.]+)([a-z%]*)$/i);if(T){const w=Number.parseFloat(T[1]),C=T[2]||"";i.setAttribute(ge.STROKE_WIDTH,`${w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE}${C}`)}else{const w=Number.parseFloat(E),C=Number.isNaN(w)?this.STROKE_WIDTH_HIGHLIGHT_INCREASE:w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE;i.setAttribute(ge.STROKE_WIDTH,`${C}`)}}return t.insertAdjacentElement(ge.AFTER_END,i),i}static getHighlightColor(t,n){const i=N3.parse(t);if(!i||!(N3.getContrastRatio(i,ge.HIGHLIGHT_BASE_COLOR)<ge.HIGHLIGHT_CONTRAST_RATIO))return n;const f={...i};return i.r===i.g&&i.g===i.b?(f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)),f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)),f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO))):i.r>=i.g&&i.r>=i.b?f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)):i.g>=i.r&&i.g>=i.b?f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)):f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO)),N3.rgbToString(f)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",i=N3.parse(n);return i?(.2126*i.r+.7152*i.g+.0722*i.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,n){t.style.outline=`4px solid ${n}`,t.style.outlineOffset="3px",t.style.borderRadius="3px",t.style.overflow="visible"}static removeSubplotHighlightCss(t){t.style.removeProperty("outline"),t.style.removeProperty("outline-offset"),t.style.removeProperty("border-radius"),t.style.removeProperty("overflow")}static setSubplotHighlightSvgWithAdaptiveColor(t,n,i){const o=t.querySelector("rect, path");let s="";if(o){s=window.getComputedStyle(o).getPropertyValue("fill"),(!s||s==="none"||s==="transparent"||s==="rgba(0, 0, 0, 0)")&&(i?s=window.getComputedStyle(i).getPropertyValue("fill"):s=n);const f=this.getHighlightColor(s,n);o.setAttribute("stroke",f),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}q(Ht,"SVG_NAMESPACE","http://www.w3.org/2000/svg"),q(Ht,"MIN_VISIBLE_FILL_OPACITY",.01),q(Ht,"MIN_VISIBLE_STROKE_OPACITY",.01),q(Ht,"STROKE_WIDTH_HIGHLIGHT_INCREASE",2);const AB="unavailable",CB="X",OB="Y",MB="unavailable";class C7{constructor(){q(this,"observers");q(this,"isWarning");this.observers=new Array,this.isWarning=!1}dispose(){this.observers.length=0}notifyRotorBounds(){this.isWarning=!0,this.notifyStateUpdate(),this.isWarning=!1}get isInitialEntry(){return this.movable.isInitialEntry}set isInitialEntry(t){this.movable.isInitialEntry=t}get isOutOfBounds(){return this.movable.isOutOfBounds}set isOutOfBounds(t){this.movable.isOutOfBounds=t}get row(){return this.movable.row}get col(){return this.movable.col}set row(t){this.movable.row=t}set col(t){this.movable.col=t}getSafeIndices(){const t=this.row>=0&&this.row<this.dimension.rows?this.row:0,n=this.col>=0&&this.col<this.dimension.cols?this.col:0;return{row:t,col:n}}addObserver(t){this.observers.push(t)}removeObserver(t){const n=this.observers.indexOf(t);n!==-1&&this.observers.splice(n,1)}notifyStateUpdate(){const t=this.state;this.observers.forEach(n=>n.update(t))}notifyOutOfBounds(){const t=this.outOfBoundsState;this.observers.forEach(n=>n.update(t))}moveOnce(t){const n=this.movable.moveOnce(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToExtreme(t){const n=this.movable.moveToExtreme(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToIndex(t,n){const i=this.movable.moveToIndex(t,n);return i?this.notifyStateUpdate():this.notifyOutOfBounds(),i}isMovable(t){return this.movable.isMovable(t)}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}moveToNextCompareValue(t,n){return this.notifyRotorBounds(),!1}compare(t,n,i){return i==="lower"?t<n:i==="higher"?t>n:!1}moveUpRotor(t){throw new Error("Move up function is not defined for this trace")}moveDownRotor(t){throw new Error("Move down function is not defined for this trace")}moveLeftRotor(t){throw new Error("Move left function is not defined for this trace")}moveRightRotor(t){throw new Error("Move right function is not defined for this trace")}moveToPoint(t,n){}}class Pl extends C7{constructor(n){var i,o,s;super();q(this,"id");q(this,"type");q(this,"title");q(this,"xAxis");q(this,"yAxis");q(this,"fill");q(this,"navigationService");q(this,"layer");this.layer=n,this.navigationService=new S7,this.id=n.id,this.type=n.type,this.title=n.title??AB,this.xAxis=((i=n.axes)==null?void 0:i.x)??CB,this.yAxis=((o=n.axes)==null?void 0:o.y)??OB,this.fill=((s=n.axes)==null?void 0:s.fill)??MB}dispose(){this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(i=>{(Array.isArray(i)?i:[i]).forEach(s=>s.remove())})),this.highlightValues.length=0),super.dispose()}get state(){var n;return this.isWarning?{empty:!0,type:"trace",traceType:this.type,audio:{size:((n=this.values[this.row])==null?void 0:n.length)||0,index:this.col},warning:!0}:{empty:!1,type:"trace",traceType:this.type,plotType:this.type,title:this.title,xAxis:this.xAxis,yAxis:this.yAxis,fill:this.fill,hasMultiPoints:this.hasMultiPoints,audio:this.audio,braille:this.braille,text:this.text,autoplay:this.autoplay,highlight:this.highlight}}get outOfBoundsState(){return{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols}}}get highlight(){return this.highlightValues===null||this.isInitialEntry?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}get autoplay(){return{UPWARD:this.dimension.rows,DOWNWARD:this.dimension.rows,FORWARD:this.dimension.cols,BACKWARD:this.dimension.cols}}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}get hasMultiPoints(){return!1}getExtremaTargets(){return[]}navigateToExtrema(n){if(this.supportsExtrema)throw new Error("Extrema navigation not implemented by this plot type")}finalizeExtremaNavigation(){this.isInitialEntry&&(this.isInitialEntry=!1),this.updateVisualPointPosition(),this.notifyStateUpdate()}updateVisualPointPosition(){}supportsExtremaNavigation(){return this.supportsExtrema}getCurrentXValue(){if(this.hasPointsArray()){const n=this.getPointsArray();if(this.isValidPointsArray(n))return this.navigationService.extractXValueFromPoints(n,this.row,this.col)}if(this.hasValuesArray()){const n=this.values;if(this.isValidValuesArray(n))return this.navigationService.extractXValueFromValues(n,this.row,this.col)}return null}moveToXValue(n){if(this.hasPointsArray()){const i=this.getPointsArray();if(this.isValidPointsArray(i))return this.navigationService.moveToXValueInPoints(i,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const i=this.values;if(this.isValidValuesArray(i))return this.navigationService.moveToXValueInValues(i,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}getId(){return this.id}moveToPoint(n,i){const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}isPointInBounds(n,i,{element:o,row:s,col:f}){const d=o.getBoundingClientRect();let h=12;return(this.type===ar.HEATMAP||this.type===ar.BAR||this.type===ar.STACKED||this.type===ar.HISTOGRAM)&&(h=0),n>=d.x-h&&n<=d.x+d.width+h&&i>=d.y-h&&i<=d.y+d.height+h}}class Na{constructor(){}static safeMin(t){return t.length===0?1/0:Math.min(...t)}static safeMax(t){return t.length===0?-1/0:Math.max(...t)}static minFrom2D(t){const n=t.flat();return this.safeMin(n)}static maxFrom2D(t){const n=t.flat();return this.safeMax(n)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let n=t[0],i=t[0];for(let o=1;o<t.length;o++){const s=t[o];s<n&&(n=s),s>i&&(i=s)}return{min:n,max:i}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class O7{constructor(t){q(this,"isInitialEntry");q(this,"isOutOfBounds");q(this,"row");q(this,"col");this.isInitialEntry=(t==null?void 0:t.isInitialEntry)??!0,this.isOutOfBounds=!1,this.row=(t==null?void 0:t.row)??0,this.col=(t==null?void 0:t.col)??0}moveToIndex(t,n){return this.isMovable([t,n])?(this.row=t,this.col=n,this.isInitialEntry=!1,!0):!1}}class Im extends O7{constructor(n,i){super(i);q(this,"elements");this.elements=n}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}return!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":this.row=this.elements.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.col=this.elements[this.row].length-1;break;case"BACKWARD":this.col=0;break}return!0}moveToIndex(n,i){return this.isMovable([n,i])?(this.row=n,this.col=i,this.isInitialEntry=!1,!0):!1}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.elements.length&&o>=0&&o<this.elements[this.row].length}switch(n){case"UPWARD":return this.row<this.elements.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.elements[this.row].length-1;case"BACKWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.elements.length-1)),this.col=Math.max(0,Math.min(this.col,this.elements[this.row].length-1))}}class RB extends O7{constructor(n,i){super(i);q(this,"graph");this.graph=n}moveOnce(n){var s;if(this.isInitialEntry)return this.handleInitialEntry(),!0;const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.up;break;case"DOWNWARD":o=i.down;break;case"FORWARD":o=i.right;break;case"BACKWARD":o=i.left;break}return o?(this.row=o.row,this.col=o.col,!0):!1}moveToExtreme(n){var s;this.isInitialEntry&&this.handleInitialEntry();const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.top;break;case"DOWNWARD":o=i.bottom;break;case"FORWARD":o=i.end;break;case"BACKWARD":o=i.start;break}return o?(this.row=o.row,this.col=o.col,!0):!1}isMovable(n){var o,s,f;if(Array.isArray(n)){const[d,h]=n;return((o=this.graph[d])==null?void 0:o[h])!==null&&((s=this.graph[d])==null?void 0:s[h])!==void 0}const i=(f=this.graph[this.row])==null?void 0:f[this.col];if(!i)return!1;switch(n){case"UPWARD":return i.up!==null;case"DOWNWARD":return i.down!==null;case"FORWARD":return i.right!==null;case"BACKWARD":return i.left!==null}}handleInitialEntry(){this.isInitialEntry=!1,this.isMovable([0,0])?(this.row=0,this.col=0):(this.row=-1,this.col=-1)}}class _B extends O7{constructor(n,i){super();q(this,"mode");q(this,"xPoints");q(this,"yPoints");q(this,"xValues");q(this,"yValues");this.mode="col",this.xPoints=n,this.yPoints=i,this.xValues=n.map(o=>o.x),this.yValues=i.map(o=>o.y)}dispose(){this.xValues.length=0,this.yValues.length=0}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;if(this.mode==="col")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}return!0}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="col")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}return!0}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="col")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}toggleNavigation(){if(this.mode==="col"){const n=this.xPoints[this.col],i=n.y[Math.floor(n.y.length/2)];this.row=this.yValues.indexOf(i),this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)];this.col=this.xValues.indexOf(i),this.mode="col"}}handleInitialEntry(){this.isInitialEntry=!1,this.mode==="col"?(this.col=Math.max(0,Math.min(this.col,this.xPoints.length-1)),this.row=Math.max(0,Math.min(this.row,this.xPoints[this.col].y.length-1))):(this.row=Math.max(0,Math.min(this.row,this.yPoints.length-1)),this.col=Math.max(0,Math.min(this.col,this.yPoints[this.row].x.length-1)))}}class M7 extends Pl{constructor(n,i){super(n);q(this,"movable");q(this,"points");q(this,"barValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"orientation");q(this,"min");q(this,"max");q(this,"supportsExtrema",!0);this.points=i,this.orientation=n.orientation??An.VERTICAL,this.barValues=i.map(o=>o.map(s=>this.orientation===An.VERTICAL?Number(s.y):Number(s.x))),this.min=this.barValues.map(o=>Na.safeMin(o)),this.max=this.barValues.map(o=>Na.safeMax(o)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Im(this.points)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get audio(){const n=this.orientation===An.VERTICAL,i=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{freq:{min:Na.safeMin(this.min),max:Na.safeMax(this.max),raw:i},panning:{x:n?this.col:this.row,y:n?this.row:this.col,rows:n?this.barValues.length:this.barValues[this.col].length,cols:n?this.barValues[this.row].length:this.barValues.length},group:n?this.row:this.col}}get braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){const n=this.orientation===An.VERTICAL,i=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,s=n?i.x:i.y,f=n?this.yAxis:this.xAxis,d=n?i.y:i.x;return{main:{label:o,value:s},cross:{label:f,value:d}}}get dimension(){return{rows:this.barValues.length,cols:this.barValues[this.row].length}}get values(){return this.barValues}mapToSvgElements(n){if(!n)return null;const i=[Ht.selectAllElements(n)];if(i.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(i[o].length!==this.points[o].length)return null;return i}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();d&&i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}return i}findNearestPoint(n,i){if(!this.highlightValues)return null;for(let o=0;o<this.highlightValues.length;o++)for(let s=0;s<this.highlightValues[o].length;s++){const f=this.highlightValues[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();if(n>=h.x&&n<=h.x+h.width&&i>=h.y&&i<=h.y+h.height)return{element:d,row:o,col:s}}return null}}class DB extends M7{isPointInBounds(t,n,{element:i,row:o,col:s}){const f=i.getBoundingClientRect();return t>=f.x&&t<=f.x+f.width&&n>=f.y&&n<=f.y+f.height}constructor(t){super(t,[t.data])}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.barValues[n];if(!i||i.length===0)return t;const o=this.min[n],s=this.max[n],f=i.indexOf(s),d=i.indexOf(o);return t.push({label:`Max Bar at ${this.getPointLabel(f)}`,value:s,pointIndex:f,segment:"bar",type:"max",navigationType:"point"}),t.push({label:`Min Bar at ${this.getPointLabel(d)}`,value:o,pointIndex:d,segment:"bar",type:"min",navigationType:"point"}),t}navigateToExtrema(t){this.col=t.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(t){if(this.points[this.row]&&this.points[this.row][t]){const n=this.points[this.row][t];return this.orientation===An.VERTICAL?`${n.x}`:`${n.y}`}return`Point ${t}`}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const Js={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class kB extends Pl{constructor(n,i=!1){var f;super(n);q(this,"supportsExtrema",!1);q(this,"movable");q(this,"points");q(this,"boxValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"orientation");q(this,"sections");q(this,"min");q(this,"max");q(this,"isViolinBoxPlot");this.isViolinBoxPlot=i&&n.type===ar.BOX,this.points=n.data,this.orientation=n.orientation??An.VERTICAL,this.orientation===An.HORIZONTAL?this.points=[...n.data].reverse():this.points=n.data,this.sections=[Js.LOWER_OUTLIER,Js.MIN,Js.Q1,Js.Q2,Js.Q3,Js.MAX,Js.UPPER_OUTLIER];const o=[d=>d.lowerOutliers,d=>d.min,d=>d.q1,d=>d.q2,d=>d.q3,d=>d.max,d=>d.upperOutliers];this.orientation===An.HORIZONTAL?this.boxValues=this.points.map(d=>o.map(h=>h(d))):this.boxValues=o.map(d=>this.points.map(h=>d(h)));const s=this.boxValues.map(d=>d.flatMap(h=>Array.isArray(h)?h:[h]));this.min=Na.minFrom2D(s),this.max=Na.maxFrom2D(s),this.highlightValues=this.mapToSvgElements(n.selectors),this.orientation===An.HORIZONTAL&&((f=this.highlightValues)==null||f.reverse()),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Im(this.boxValues,{row:0})}isViolin(){return this.isViolinBoxPlot}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,i){return super.moveToIndex(n,i)}handleInitialEntry(){var n;this.isInitialEntry=!1,this.orientation===An.VERTICAL?(this.row=Math.min(1,this.boxValues.length-1),this.col=0):(this.row=0,this.col=Math.min(1,((n=this.boxValues[0])==null?void 0:n.length)??1))}moveOnce(n){if(!this.isViolin())return super.moveOnce(n);if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.orientation===An.VERTICAL)if(n==="FORWARD")this.col+=1,this.row=1;else if(n==="BACKWARD")this.col-=1,this.row=1;else return super.moveOnce(n);else if(n==="UPWARD")this.row+=1,this.col=1;else if(n==="DOWNWARD")this.row-=1,this.col=1;else return super.moveOnce(n);return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}get values(){return this.boxValues}get audio(){const n=this.orientation===An.HORIZONTAL,i=this.boxValues[this.row][this.col],o=n?this.col:this.row,s=Array.isArray(i)?i.length===0?o:i[i.length-1]-this.min:Number.isNaN(i)?o:i-this.min;return{freq:{min:this.min,max:this.max,raw:this.boxValues[this.row][this.col]},panning:{x:n?s:this.row,y:n?this.row:s,rows:n?this.boxValues.length:this.max-this.min,cols:n?this.max-this.min:this.boxValues.length}}}get braille(){const n=this.orientation===An.HORIZONTAL,i=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:i,col:o}}get text(){const n=this.orientation===An.HORIZONTAL,i=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,s=n?this.sections[this.col]:this.sections[this.row],f=n?this.xAxis:this.yAxis,d=this.boxValues[this.row][this.col];return{main:{label:o,value:i.fill},cross:{label:f,value:d},section:s}}get dimension(){const n=this.orientation===An.HORIZONTAL;return{rows:n?this.boxValues.length:this.boxValues[this.row].length,cols:n?this.boxValues[this.row].length:this.boxValues.length}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const i=this.orientation===An.VERTICAL,o=new Array;if(i)for(let f=0;f<this.sections.length;f++)o.push(Array.from({length:n.length}));const s=[];return n.forEach(f=>{var w,C;const d=((w=f.lowerOutliers)==null?void 0:w.flatMap(R=>Ht.selectAllElements(R,!1)))??[],h=((C=f.upperOutliers)==null?void 0:C.flatMap(R=>Ht.selectAllElements(R,!1)))??[],y=Ht.selectElement(f.min,!1),S=Ht.selectElement(f.max,!1),E=Ht.selectElement(f.iq,!1),T=Ht.selectElement(f.q2,!1);s.push({lowerOutliers:d,upperOutliers:h,min:y,max:S,iq:E,q2:T})}),s.forEach((f,d)=>{var N;const h=f.lowerOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),y=f.upperOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),S=this.cloneElementOrEmpty(f.min),E=this.cloneElementOrEmpty(f.max),T=this.cloneElementOrEmpty(f.q2),w=((N=this.layer.domMapping)==null?void 0:N.iqrDirection)==="reverse",[C,R]=f.iq?i?w?[Ht.createLineElement(f.iq,"top"),Ht.createLineElement(f.iq,"bottom")]:[Ht.createLineElement(f.iq,"bottom"),Ht.createLineElement(f.iq,"top")]:[Ht.createLineElement(f.iq,"left"),Ht.createLineElement(f.iq,"right")]:[Ht.createEmptyElement("line"),Ht.createEmptyElement("line")],D=[h,S,C,T,R,E,y];i?D.forEach((z,B)=>{o[B][d]=z}):o.push(D)}),o}cloneElementOrEmpty(n){if(!n)return Ht.createEmptyElement();const i=n.cloneNode(!0);return i.setAttribute(ge.VISIBILITY,ge.HIDDEN),n.insertAdjacentElement(ge.AFTER_END,i),i}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.boxValues.length)return!1;let s=[],f=0;if(n==="left"||n==="right"?(s=this.boxValues[this.row],f=this.col):(s=this.boxValues.map(y=>y[this.col]),f=this.row),s.length<=0)return!1;const d=n==="right"||n==="up"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){const y=s[f],S=s[h];if(Array.isArray(S)||Array.isArray(y))return!0;if(this.compare(S,y,i))return this.set_point(n,h),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}set_point(n,i){n==="left"||n==="right"?this.col=i:this.row=i}moveUpRotor(n){return this.orientation===An.VERTICAL?(this.moveOnce("UPWARD"),!0):this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.orientation===An.VERTICAL?(this.moveOnce("DOWNWARD"),!0):this.moveToNextCompareValue("down",n)}moveLeftRotor(n){return this.orientation===An.HORIZONTAL?(this.moveOnce("BACKWARD"),!0):this.moveToNextCompareValue("left",n)}moveRightRotor(n){return this.orientation===An.HORIZONTAL?(this.moveOnce("FORWARD"),!0):this.moveToNextCompareValue("right",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){}getCurrentXValue(){return this.isViolin()?this.orientation===An.VERTICAL?this.col>=0?this.col:null:this.row>=0?this.row:null:super.getCurrentXValue()}moveToXValue(n){if(!this.isViolin())return super.moveToXValue(n);if(this.isInitialEntry&&this.handleInitialEntry(),typeof n!="number")return!1;const i=Math.floor(n),o=this.values;if(this.orientation===An.VERTICAL){const s=o.length>0?o[0].length:0;if(i<0||i>=s)return!1;const f=this.col;return this.col=i,i!==f&&(this.row=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(i<0||i>=o.length)return!1;const s=this.row;return this.row=i,i!==s&&(this.col=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}getCurrentYValue(){if(!this.isViolin())return null;const n=this.values;if(this.orientation===An.VERTICAL){if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}}else if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}return null}moveToXAndYValue(n,i){if(!this.isViolin()||typeof n!="number")return!1;const o=Math.floor(n),s=this.values;if(this.orientation===An.VERTICAL){const f=s.length>0?s[0].length:0;if(o<0||o>=f)return!1;this.col=o;let d=1,h=1/0;for(let y=0;y<s.length;y++){const S=s[y];if(Array.isArray(S)&&o<S.length){const E=S[o];if(Array.isArray(E)){for(const T of E)if(typeof T=="number"){const w=Math.abs(T-i);w<h&&(h=w,d=y)}}else if(typeof E=="number"){const T=Math.abs(E-i);T<h&&(h=T,d=y)}}}return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(o<0||o>=s.length)return!1;this.row=o;let f=1,d=1/0;const h=s[o];if(Array.isArray(h))for(let y=0;y<h.length;y++){const S=h[y];if(Array.isArray(S)){for(const E of S)if(typeof E=="number"){const T=Math.abs(E-i);T<d&&(d=T,f=y)}}else if(typeof S=="number"){const E=Math.abs(S-i);E<d&&(d=E,f=y)}}return this.col=f,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}onSwitchFrom(n){var d;if(!this.isViolin())return!1;const i=n;if(!((i.type||((d=i.state)==null?void 0:d.traceType))==="smooth"))return!1;const f=n.getCurrentXValue();if(n.getCurrentYValue){const h=n.getCurrentYValue();if(h!==null&&f!==null&&this.moveToXAndYValue){const y=this.moveToXAndYValue(f,h);return y&&(this.isInitialEntry=!1),y}}if(f!==null){const h=this.moveToXValue(f);return h&&(this.isInitialEntry=!1),h}return!1}}const NB="trend",fA=100,zB=["volatility","open","high","low","close"];class LB extends Pl{constructor(n){super(n);q(this,"supportsExtrema",!0);q(this,"movable");q(this,"candles");q(this,"candleValues");q(this,"orientation");q(this,"currentSegmentType","open");q(this,"currentPointIndex",0);q(this,"sortedSegmentsByPoint");q(this,"segmentPositionMaps");q(this,"sections");q(this,"min");q(this,"max");q(this,"highlightValues");q(this,"highlightCenters");q(this,"navigationService");this.navigationService=new S7;const i=n.data;this.candles=i.map(s=>({...s,volatility:Math.round((s.high-s.low)*fA)/fA,trend:s.close>s.open?"Bull":s.close<s.open?"Bear":"Neutral"})),this.orientation=n.orientation??An.VERTICAL,this.sections=zB,this.candleValues=this.sections.map(s=>this.candles.map(f=>f[s]));const o=this.orientation===An.HORIZONTAL?{col:this.sections.length-1}:{row:this.sections.length-1};this.movable=new Im(this.candleValues,o),this.min=Na.minFrom2D(this.candleValues),this.max=Na.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===An.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters()}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(s=>[s,n[s]]).sort((s,f)=>s[1]-f[1]).map(s=>s[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const i=new Map;return n.forEach((o,s)=>{i.set(o,s)}),i})}getSegmentPositionInSortedOrder(n,i){return this.segmentPositionMaps[n].get(i)??0}getSegmentTypeAtSortedPosition(n,i){return this.sortedSegmentsByPoint[n][i]??"open"}updateVisualSegmentPosition(){const i=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===An.HORIZONTAL?this.col=i:this.row=i}updateVisualPointPosition(){this.orientation===An.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex,this.updateVisualSegmentPosition()}handleInitialEntry(){this.isInitialEntry=!1,this.currentPointIndex=Math.max(0,Math.min(this.currentPointIndex,this.candles.length-1)),this.currentSegmentType="close",this.updateVisualSegmentPosition()}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open");if(o===-1)return this.notifyOutOfBounds(),!1;const s=n==="UPWARD"?o+1:o-1;if(s>=0&&s<i.length)this.currentSegmentType=i[s],this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(i>=0&&i<this.candles.length)this.currentPointIndex=i,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}}return this.notifyStateUpdate(),!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[i.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[0],this.updateVisualSegmentPosition();break}case"FORWARD":{this.currentPointIndex=this.candles.length-1,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}case"BACKWARD":{this.currentPointIndex=0,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}}return this.notifyStateUpdate(),!0}moveToIndex(n,i){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:o,segmentType:s}=this.navigationService.computeIndexAndSegment(n,i,this.orientation,this.sections);return this.currentPointIndex=o,this.currentSegmentType=s,this.row=n,this.col=i,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open"),s=n==="UPWARD"?o+1:o-1;return s>=0&&s<i.length}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return i>=0&&i<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}get audio(){let n;const i=this.orientation===An.HORIZONTAL;return this.currentSegmentType==="volatility"?n=this.candles[this.currentPointIndex].volatility:this.currentSegmentType?n=this.candles[this.currentPointIndex][this.currentSegmentType]:n=this.candles[this.currentPointIndex].open,{freq:{min:this.min,max:this.max,raw:n},panning:{x:i?this.row:this.col,y:i?this.col:this.row,rows:i?this.candleValues.length:this.candleValues[this.row].length,cols:i?this.candleValues[this.row].length:this.candleValues.length},trend:this.candles[this.currentPointIndex].trend}}get braille(){const n=this.candles.map(f=>f.trend),i=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=i;const o=this.candleValues.map(f=>Math.min(...f)),s=this.candleValues.map(f=>Math.max(...f));return{empty:!1,id:this.id,values:this.candleValues,min:o,max:s,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const i=Array.isArray(n)?n:[n],o=[];for(const s of i)o.push(...Ht.selectAllElements(s));return o}getElementAt(n,i){return i<n.length?n[i]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const C=Array.isArray(n)?n[0]||"":n,R=Ht.selectAllElements(C),D=[];for(let N=0;N<this.sections.length;N++){D[N]=[];for(let z=0;z<this.candles.length;z++){const B=z<R.length?z:0;D[N][z]=R[B]}}return D}const i=n,o=this.candles.length,s=this.collectElements(i.body);let f=this.collectElements(i.wickHigh),d=this.collectElements(i.wickLow);if(f.length===0||d.length===0){const C=this.collectElements(i.wick);C.length>0&&(f.length===0&&(f=C),d.length===0&&(d=C))}const h=this.collectElements(i.open),y=this.collectElements(i.close),S=Array.from({length:o},()=>Ht.createEmptyElement()),E=Array.from({length:o},()=>Ht.createEmptyElement()),T=Array.from({length:o},()=>Ht.createEmptyElement());for(let C=0;C<o;C++){let R=this.getElementAt(h,C);if(!R){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"bottom":B<z?"top":"bottom";R=Ht.createLineElement(N,V)}else R=Ht.createEmptyElement()}S[C]=R;let D=this.getElementAt(y,C);if(!D){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"top":B<z?"bottom":"top";D=Ht.createLineElement(N,V)}else D=Ht.createEmptyElement()}E[C]=D,T[C]=Ht.createEmptyElement()}const w=Array.from({length:this.sections.length},()=>Array.from({length:o},()=>Ht.createEmptyElement()));for(let C=0;C<o;C++){const R=this.sortedSegmentsByPoint[C];for(let D=0;D<R.length;D++){const N=R[D];let z;switch(N){case"volatility":{const B=[],V=this.getElementAt(s,C),L=this.getElementAt(f,C)??V,P=this.getElementAt(d,C)??V;L&&B.push(L),V&&B.push(V),P&&B.push(P);const X=Array.from(new Set(B));z=X.length>0?X:[Ht.createEmptyElement()]}break;case"open":z=S[C];break;case"close":z=E[C];break;case"high":z=this.getElementAt(f,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;case"low":z=this.getElementAt(d,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;default:z=Ht.createEmptyElement()}w[D][C]=z}}return w}get text(){const n=this.candles[this.currentPointIndex];let i;return this.currentSegmentType==="volatility"?i=n.volatility:this.currentSegmentType?i=n[this.currentSegmentType]:i=n.open,{main:{label:this.orientation===An.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===An.HORIZONTAL?this.xAxis:this.yAxis,value:i},section:this.currentSegmentType??"open",fill:{label:NB,value:n.trend}}}getCurrentTrend(){return this.candles[this.currentPointIndex].trend}getCurrentXValue(){return this.currentPointIndex>=0&&this.currentPointIndex<this.candles.length?this.candles[this.currentPointIndex].value:null}moveToXValue(n){const i=this.candles.findIndex(o=>o.value===n);return i!==-1?(this.currentPointIndex=i,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getAvailableXValues(){return this.candles.map(n=>n.value)}getExtremaTargets(){const n=[],i=this.currentSegmentType??"open";if(i==="volatility"){const o=this.candles.map((y,S)=>({value:y.volatility,index:S})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,S)=>{const E=this.candles[y];n.push({label:`Max Volatility at ${E.value}`,value:E.volatility,pointIndex:y,segment:"volatility",type:"max",navigationType:"point"})}),h.forEach((y,S)=>{const E=this.candles[y];n.push({label:`Min Volatility at ${E.value}`,value:E.volatility,pointIndex:y,segment:"volatility",type:"min",navigationType:"point"})})}else{const o=this.candles.map((y,S)=>({value:y[i],index:S,xValue:y.value})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,S)=>{const E=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Max ${T} at ${E.value}`,value:E[i],pointIndex:y,segment:i,type:"max",navigationType:"point"})}),h.forEach((y,S)=>{const E=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Min ${T} at ${E.value}`,value:E[i],pointIndex:y,segment:i,type:"min",navigationType:"point"})})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.finalizeExtremaNavigation()}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.candles.length)return!1;const s=this.currentSegmentType??"open",f=this.candles.map((S,E)=>({value:S[s],index:E,xValue:S.value})),d=this.col,h=n==="right"?1:-1;let y=d+h;for(;y>=0&&y<f.length;){if(this.compare(f[y].value,f[d].value,i))return this.col=y,this.currentPointIndex=y,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;y+=h}return this.notifyRotorBounds(),!1}moveUpRotor(){return this.moveOnce("UPWARD"),!0}moveDownRotor(){return this.moveOnce("DOWNWARD"),!0}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}get dimension(){const n=this.orientation===An.HORIZONTAL;return{rows:n?this.candleValues.length:this.candleValues[this.row].length,cols:n?this.candleValues[this.row].length:this.candleValues.length}}}class IB extends Pl{constructor(n){super(n);q(this,"supportsExtrema",!1);q(this,"movable");q(this,"heatmapValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"x");q(this,"y");q(this,"min");q(this,"max");const i=n.data;this.x=i.x,this.y=[...i.y].reverse(),this.heatmapValues=[...i.points].reverse();const{min:o,max:s}=Na.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=s,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Im(this.heatmapValues)}get values(){return this.heatmapValues}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get audio(){return{freq:{min:this.min,max:this.max,raw:this.heatmapValues[this.row][this.col]},panning:{x:this.col,y:this.row,rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}}get braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){return{main:{label:this.xAxis,value:this.x[this.col]},cross:{label:this.yAxis,value:this.y[this.row]},fill:{label:this.fill,value:String(this.heatmapValues[this.row][this.col])}}}get dimension(){return{rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}mapToSvgElements(n){var d;if(!n)return null;const i=this.heatmapValues.length,o=this.heatmapValues[0].length,s=Ht.selectAllElements(n);if(s.length===0||s.length!==i*o)return null;const f=new Array;if(s[0]instanceof SVGPathElement)for(let h=0;h<i;h++){const y=i-1-h,S=new Array;for(let E=0;E<o;E++){const T=y*o+E;S.push(s[T])}f.push(S)}else if(s[0]instanceof SVGRectElement)if(((d=this.layer.domMapping)==null?void 0:d.order)==="row")for(let h=0;h<i;h++){const y=new Array;for(let S=0;S<o;S++){const E=h*o+S;y.push(s[E])}f.push(y)}else for(let h=0;h<i;h++){const y=new Array;for(let S=0;S<o;S++){const E=S*i+h;y.push(s[E])}f.push(y)}return f}updateVisualPointPosition(){const{row:n,col:i}=this.getSafeIndices();this.row=n,this.col=i}moveToNextCompareValue(n,i){switch(n){case"left":case"right":return this.search_in_row(n,i);case"up":case"down":return this.search_in_col(n,i);default:return this.notifyRotorBounds(),!1}}search_in_row(n,i){const o=this.y.length,s=this.col,f=n==="left"?-1:1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[this.row][d],this.heatmapValues[this.row][s],i))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}search_in_col(n,i){const o=this.x.length,s=this.row,f=n==="up"?1:-1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[d][this.col],this.heatmapValues[s][this.col],i))return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return!1}moveUpRotor(n){return this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.moveToNextCompareValue("down",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}}class BB extends M7{constructor(t){super(t,[t.data])}get text(){const t=this.orientation===An.VERTICAL,n=this.points[this.row][this.col],i=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text,range:{min:i,max:o}}}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const dA="Group",R7=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class hA extends Pl{constructor(n){super(n);q(this,"supportsExtrema",!0);q(this,"rotorSupport",!0);q(this,"movable");q(this,"points");q(this,"lineValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"min");q(this,"max");q(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(i=>i.map(o=>Number(o.y))),this.min=this.lineValues.map(i=>Na.safeMin(i)),this.max=this.lineValues.map(i=>Na.safeMax(i)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new RB(this.buildGraph())}get values(){return this.lineValues}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}buildGraph(){const n=this.points.length;if(n===0)return new Array;const i=Math.max(0,...this.points.map(s=>s.length)),o=this.points.map(s=>s.map(()=>({up:null,down:null,left:null,right:null,top:null,bottom:null,start:null,end:null})));for(let s=0;s<i;s++){const f=this.points.map((S,E)=>{var T;return{y:(T=S[s])==null?void 0:T.y,row:E}}).filter(S=>S.y!==void 0);if(f.length===0)continue;const d=[...f].sort((S,E)=>S.y-E.y),h={row:d[0].row,col:s},y={row:d[d.length-1].row,col:s};for(let S=0;S<d.length;S++){const{row:E}=d[S],T=o[E][s];T&&(S>0&&(T.down={row:d[S-1].row,col:s}),S<d.length-1&&(T.up={row:d[S+1].row,col:s}),T.bottom=h,T.top=y)}}for(let s=0;s<n;s++){const f=this.points[s].length>0?{row:s,col:0}:null,d=this.points[s].length>0?{row:s,col:this.points[s].length-1}:null;for(let h=0;h<this.points[s].length;h++){const y=o[s][h];y&&(h>0&&(y.left={row:s,col:h-1}),h<this.points[s].length-1&&(y.right={row:s,col:h+1}),y.start=f,y.end=d)}}return o}get audio(){return{freq:{min:this.min[this.row],max:this.max[this.row],raw:this.lineValues[this.row][this.col]},panning:{x:this.row,y:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:this.row}}get braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){var s;const n=this.points[this.row][this.col],i=this.findIntersections();let o={};if(i.length>1){let f=i.map(d=>{var y;const h=d.group;return((y=this.points[h][0])==null?void 0:y.fill)||`l${h+1}`});if(this.previousRow!==null){const d=((s=this.points[this.previousRow][0])==null?void 0:s.fill)||`l${this.previousRow+1}`;f.includes(d)&&(f=[d,...f.filter(h=>h!==d)])}o={fill:{label:dA,value:`intersection at (${f.join(", ")})`}}}else o=n.fill?{fill:{label:dA,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...o}}get dimension(){return{rows:this.lineValues.length,cols:this.lineValues[this.row].length}}moveOnce(n){if(this.isInitialEntry)return this.movable.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const o=this.findLineByXAndYDirection(n),s=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const f=this.findColumnByXValue(o,s);if(f!==-1){this.row=o,this.col=f;const d=this.findIntersections();if(d.length>1){const y={...super.state,intersections:d};for(const S of this.observers)S.update(y)}else this.notifyStateUpdate();return!0}else return this.notifyOutOfBounds(),!1}else return this.notifyOutOfBounds(),!1}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const i=this.findIntersections();if(i.length>1){const s={...super.state,intersections:i};for(const f of this.observers)f.update(s)}else this.notifyStateUpdate();return!0}findIntersections(){const n=this.points[this.row][this.col].x,i=this.points[this.row][this.col].y,o=[];for(let s=0;s<this.points.length;s++){const f=this.points[s].findIndex(d=>d.x===n&&d.y===i);f!==-1&&o.push({freq:{min:this.min[s],max:this.max[f],raw:i},panning:{x:this.row,y:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:s})}return o}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.values.length&&o>=0&&o<this.values[i].length}switch(n){case"UPWARD":case"DOWNWARD":{const i=this.findLineByXAndYDirection(n);if(i===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(i,o)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const i=this.points[this.row][this.col].x;let o=null,s=Number.POSITIVE_INFINITY;for(let f=0;f<this.points.length;f++){if(f===this.row)continue;const d=this.points[f].findIndex(E=>E.x===i);if(d===-1)continue;const h=this.points[f][d].y,y=n==="UPWARD"?h>this.points[this.row][this.col].y:h<this.points[this.row][this.col].y,S=Math.abs(h-this.points[this.row][this.col].y);y&&S<s&&(s=S,o=f)}return o}findColumnByXValue(n,i){return this.points[n].findIndex(o=>o.x===i)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const i=[];let o=!0;for(let s=0;s<n.length;s++){const f=Ht.selectElement(n[s],!1);if(!f){i.push([]);continue}const d=[];if(f instanceof SVGPathElement){const S=f.getAttribute(ge.D)||ge.EMPTY;R7.lastIndex=0;let E=R7.exec(S);for(;E!==null;)d.push({x:Number.parseFloat(E[1]),y:Number.parseFloat(E[2])}),E=R7.exec(S)}else if(f instanceof SVGPolylineElement){const E=(f.getAttribute(ge.POINTS)||ge.EMPTY).split(/\s+/).filter(Boolean);for(const T of E){const[w,C]=T.split(ge.COMMA);d.push({x:Number.parseFloat(w),y:Number.parseFloat(C)})}}if(d.length!==this.lineValues[s].length)if(d.length<this.lineValues[s].length)for(;d.length<this.lineValues[s].length;)d.push({x:Number.NaN,y:Number.NaN});else d.length>this.lineValues[s].length&&(d.length=this.lineValues[s].length);const h=[];let y=!1;for(const S of d){if(Number.isNaN(S.x)||Number.isNaN(S.y)){y=!0;break}h.push(Ht.createCircleElement(S.x,S.y,f))}if(y){i.push([]);continue}h.length>0&&(o=!1),i.push(h)}return o?null:i}get state(){const n=super.state;if(n.empty)return n;const i=this.points.length>1,o={...n,plotType:i?"multiline":"single line",...i&&{groupCount:this.points.length}},s=this.findIntersections();return s.length>1?{...o,intersections:s}:o}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}getExtremaTargets(){const n=[],i=this.row;if(i<0||i>=this.lineValues.length)return n;const o=this.lineValues[i];if(!o||o.length===0)return n;const s=this.min[i],f=this.max[i],d=[],h=[];for(let y=0;y<o.length;y++){const S=o[y];S===f&&d.push(y),S===s&&h.push(y)}for(const y of d)n.push({label:`Max point at ${this.getPointLabel(y)}`,value:f,pointIndex:y,segment:"line",type:"max",navigationType:"point"});for(const y of h)n.push({label:`Min point at ${this.getPointLabel(y)}`,value:s,pointIndex:y,segment:"line",type:"min",navigationType:"point"});return n}navigateToExtrema(n){this.col=n.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(n){return this.points[this.row]&&this.points[this.row][n]?`${this.points[this.row][n].x}`:`Point ${n}`}updateVisualPointPosition(){const{row:n,col:i}=this.getSafeIndices();this.row=n,this.col=i}getAvailableXValues(){return this.points[this.row].map(n=>n.x)}moveToXValue(n){return this.isInitialEntry&&this.movable.handleInitialEntry(),super.moveToXValue(n)}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.lineValues.length)return!1;const s=this.lineValues[o];if(!s||s.length===0)return!1;const f=this.col,d=n==="right"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){if(this.compare(s[h],s[f],i))return this.col=h,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}compare(n,i,o){return o==="lower"?n<i:o==="higher"?n>i:!1}moveUpRotor(n){return this.moveOnce("UPWARD"),!0}moveDownRotor(n){return this.moveOnce("DOWNWARD"),!0}}class VB extends Pl{constructor(n){super(n);q(this,"mode");q(this,"movable");q(this,"supportsExtrema",!1);q(this,"xPoints");q(this,"yPoints");q(this,"xValues");q(this,"yValues");q(this,"highlightXValues");q(this,"highlightYValues");q(this,"highlightCenters");q(this,"minX");q(this,"maxX");q(this,"minY");q(this,"maxY");this.mode="column";const i=n.data,o=[...i].sort((h,y)=>h.x-y.x||h.y-y.y);this.xPoints=new Array;let s=null;for(const h of o)(!s||s.x!==h.x)&&(s={x:h.x,y:[]},this.xPoints.push(s)),s.y.push(h.y);const f=[...i].sort((h,y)=>h.y-y.y||h.x-y.x);this.yPoints=new Array;let d=null;for(const h of f)(!d||d.y!==h.y)&&(d={y:h.y,x:[]},this.yPoints.push(d)),d.x.push(h.x);this.xValues=this.xPoints.map(h=>h.x),this.yValues=this.yPoints.map(h=>h.y),this.minX=Na.safeMin(this.xValues),this.maxX=Na.safeMax(this.xValues),this.minY=Na.safeMin(this.yValues),this.maxY=Na.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new _B(this.xPoints,this.yPoints)}dispose(){this.movable.dispose(),this.xPoints.length=0,this.yPoints.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightYValues.length=0),super.dispose()}get highlightValues(){return this.movable.mode==="col"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}get values(){const n=[this.xValues,this.yValues];return this.mode==="column"?this.row!==0&&(this.row=0):(this.row<0||this.row>=this.yPoints.length)&&(this.row=0),n}get braille(){return{empty:!1,id:this.id,values:this.values,min:0,max:0,row:this.row,col:this.col}}get audio(){if(this.movable.mode==="col"){const n=this.xPoints[this.col];return{freq:{raw:n.y,min:this.minY,max:this.maxY},panning:{y:this.row,x:this.col,rows:n.y.length,cols:this.xPoints.length}}}else{const n=this.yPoints[this.row];return{freq:{raw:n.x,min:this.minX,max:this.maxX},panning:{y:this.row,x:this.col,rows:this.yPoints.length,cols:n.x.length}}}}get text(){if(this.movable.mode==="col"){const n=this.xPoints[this.col];return{main:{label:this.xAxis,value:n.x},cross:{label:this.yAxis,value:n.y}}}else{const n=this.yPoints[this.row];return{main:{label:this.yAxis,value:n.y},cross:{label:this.xAxis,value:n.x}}}}get dimension(){return{rows:this.yPoints.length,cols:this.xPoints.length}}get highlight(){if(this.highlightValues===null)return this.outOfBoundsState;const n=this.movable.mode==="col"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return n?{empty:!1,elements:n}:this.outOfBoundsState}get hasMultiPoints(){return!0}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0,this.mode="column"}toggleNavigation(){if(this.mode==="column"){const n=this.xPoints[this.col],i=n.y[Math.floor(n.y.length/2)],o=this.yValues.indexOf(i);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(i);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}return this.notifyStateUpdate(),!0}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}return this.notifyStateUpdate(),!0}moveToIndex(n,i){return this.mode==="column"?n>=0&&n<this.xPoints.length?(this.col=n,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):i>=0&&i<this.yPoints.length?(this.col=i,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const i=Ht.selectAllElements(n);if(i.length===0)return[null,null];const o=new Map,s=new Map;i.forEach(h=>{const y=Number.parseFloat(h.getAttribute("x")||""),S=Number.parseFloat(h.getAttribute("y")||"");Number.isNaN(y)||(o.has(y)||o.set(y,[]),o.get(y).push(h)),Number.isNaN(S)||(s.has(S)||s.set(S,[]),s.get(S).push(h))});const f=Array.from(o.entries()).sort(([h],[y])=>h-y).map(([h,y])=>y),d=Array.from(s.entries()).sort(([h],[y])=>y-h).map(([h,y])=>y);return[f,d]}mapSvgElementsToCenters(){const n=this.highlightXValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){this.mode="column";const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}}const pA="Sum",UB="Level",PB="undefined";class jB extends M7{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let s=0;s<this.barValues[0].length;s++){const f=this.barValues.reduce((h,y)=>h+y[s],0);t.push(f);const d=this.orientation===An.VERTICAL?{x:this.points[0][s].x,y:f,fill:pA}:{x:f,y:this.points[0][s].y,fill:pA};n.push(d)}this.points.push(n),this.barValues.push(t);const{min:i,max:o}=Na.minMax(t);this.min.push(i),this.max.push(o)}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.min[n],o=this.max[n],s=this.barValues[n];if(!s||s.length===0)return t;const f=s.indexOf(o),d=s.indexOf(i),h=this.getGroupLabel(n),y=this.getCategoryLabel(f),S=this.getCategoryLabel(d);return t.push({label:`Max ${h} at ${y}`,value:o,pointIndex:f,segment:h,type:"max",groupIndex:n,categoryIndex:f,navigationType:"group"}),t.push({label:`Min ${h} at ${S}`,value:i,pointIndex:d,segment:h,type:"min",groupIndex:n,categoryIndex:d,navigationType:"group"}),t}navigateToExtrema(t){t.groupIndex!==void 0&&t.categoryIndex!==void 0?(this.row=t.groupIndex,this.col=t.categoryIndex):this.col=t.pointIndex,this.finalizeExtremaNavigation()}getGroupLabel(t){if(this.points[t]&&this.points[t].length>0){const n=this.points[t][0];if(t===this.barValues.length-1)return"Total";if(n.fill)return`${this.getFillAxisLabel()}: '${n.fill}'`}return`Group ${t}`}getCategoryLabel(t){if(this.points[0]&&this.points[0][t]){const n=this.points[0][t];return this.orientation===An.VERTICAL?`${n.x}`:`${n.y}`}return`Category ${t}`}getFillAxisLabel(){return"Category"}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}get text(){return{...super.text,fill:{label:UB,value:this.points[this.row][this.col].fill??PB}}}get highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}mapToSvgElements(t){var o;if(!t)return new Array;const n=Ht.selectAllElements(t);if(n.length===0)return new Array;const i=new Array;if(n[0]instanceof SVGPathElement)for(let s=0,f=0;s<this.barValues.length;s++){const d=new Array;for(let h=0;h<this.barValues[s].length;h++){if(f>=n.length)return new Array;this.barValues[s][h]===0?d.push(Ht.createEmptyElement()):d.push(n[f++])}i.push(d)}else if(n[0]instanceof SVGRectElement){for(let f=0;f<this.barValues.length;f++)i.push(new Array);const s=((o=this.layer.domMapping)==null?void 0:o.groupDirection)==="forward";for(let f=0,d=0;f<this.barValues[0].length;f++)if(s)for(let h=0;h<this.barValues.length;h++){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}else for(let h=this.barValues.length-1;h>=0;h--){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}}return i}}class _7 extends hA{constructor(t){super(t)}get state(){const t=super.state;return t.empty?t:{...t,plotType:"smooth"}}get audio(){const t=this.lineValues[this.row],n=f=>t[Math.max(0,Math.min(f,t.length-1))],i=n(this.col-1),o=n(this.col),s=n(this.col+1);return{freq:{min:this.min[this.row],max:this.max[this.row],raw:[i,o,s]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0}}}class $B extends _7{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let i=!0;for(let s=0;s<t.length;s++){const f=Ht.selectElement(t[s],!1);if(!f){n.push([]);continue}const d=(o=this.points)==null?void 0:o[s],h=[];for(const y of d)typeof y.svg_x=="number"&&typeof y.svg_y=="number"&&h.push(Ht.createCircleElement(y.svg_x,y.svg_y,f));h.length>0&&(i=!1),n.push(h)}return i?null:n}}const D7=.001;class HB extends _7{constructor(t){super(t)}isMovable(t){var n;if(Array.isArray(t)){const[i,o]=t;return i>=0&&i<this.points.length&&o>=0&&o<(((n=this.points[i])==null?void 0:n.length)||0)}switch(t){case"FORWARD":return this.row<this.points.length-1;case"BACKWARD":return this.row>0;case"UPWARD":return this.col<this.points[this.row].length-1;case"DOWNWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0}moveOnce(t){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(t))return this.notifyOutOfBounds(),!1;switch(t){case"FORWARD":if(this.row<this.points.length-1){const n=this.row+1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"BACKWARD":if(this.row>0){const n=this.row-1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"UPWARD":case"DOWNWARD":return t==="UPWARD"?this.col<this.points[this.row].length-1?(this.col+=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):this.col>0?(this.col-=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}}mapToSvgElements(t){if(!t||t.length===0)return null;const n=[];let i=!0;const o=t.length===this.points.length;for(let s=0;s<this.points.length;s++){const f=[],d=this.points[s];let h;if(o?h=t[s]:h=t[0],!h){n.push([]);continue}const y=Ht.selectAllElements(h,!1);let S=null;if(y.length>0){const E=y.filter(C=>C instanceof SVGUseElement),T=y.filter(C=>C instanceof SVGPathElement),w=E.length>0?E:T;w.length>0&&(S=w[o?0:s<w.length?s:0])}if(S&&d){for(const E of d){let T,w;const C=E;if(typeof C.svg_x=="number"&&typeof C.svg_y=="number")T=C.svg_x,w=C.svg_y;else if(typeof E.x=="number"&&typeof E.y=="number")T=E.x,w=E.y;else continue;!Number.isNaN(T)&&!Number.isNaN(w)&&f.push(Ht.createCircleElement(T,w,S))}f.length>0&&(i=!1)}n.push(f)}return i?null:n}get text(){const t=this.points[this.row][this.col],n=t.x,i=Number(t.y),o=this.points[this.row],s=t;let f;if(typeof s.width=="number"&&!Number.isNaN(s.width))f=s.width;else{const w=typeof s.svg_y=="number"?s.svg_y:null,C=[];for(const R of o){const D=R,N=Number(R.y),z=typeof D.svg_y=="number"?D.svg_y:null;let B=!1;w!==null&&z!==null?B=Math.abs(z-w)<=1:B=Math.abs(N-i)<=.01,B&&typeof D.svg_x=="number"&&!Number.isNaN(D.svg_x)&&C.push(D.svg_x)}if(C.length>=2){const R=Math.min(...C),D=Math.max(...C);f=Math.abs(D-R)}}const d=T=>Math.round(T*1e4)/1e4,h=d(i),y=f!==void 0&&f>0?d(f):void 0;let S;if(typeof n=="string")S=n;else{const T=o[0];T&&typeof T.x=="string"?S=T.x:S=`Category ${this.row}`}const E={main:{label:this.xAxis,value:S},cross:{label:this.yAxis,value:h}};return y!==void 0&&(E.fill={label:"volume",value:String(y)}),E}get audio(){const n=this.points[0];if(!n||n.length===0)return super.audio;const i=n.map(z=>z.density??z.width??0),o=i.filter(z=>z>0);if(o.length===0)return super.audio;const s=Math.min(...o),f=i.length>0?Math.max(...i):0,d=s===f?Math.max(0,s-D7):s,h=s===f?f+D7:f,y=Math.min(this.col,i.length-1),S=z=>i[Math.max(0,Math.min(z,i.length-1))],E=y>0?S(y-1):S(y),T=S(y),w=y<i.length-1?S(y+1):S(y),C=this.points[this.row],R=C?Math.min(this.col,C.length-1):0,D=C==null?void 0:C[R];let N=1;if(D){const z=D.density??D.width??0,B=C.map(X=>X.density??X.width??0),V=B.filter(X=>X>0),L=V.length>0?Math.min(...V):0,P=B.length>0?Math.max(...B):0;if(P>0&&typeof z=="number"&&z>0){const X=L===P?P+D7:P;N=z/X}}return{freq:{min:d,max:h,raw:[E,T,w]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0,volumeScale:N}}getCurrentXValue(){return this.row>=0&&this.row<this.points.length?this.row:null}moveToXValue(t){var s;this.isInitialEntry&&this.handleInitialEntry();const n=this.points;if(!n||!n.length)return!1;const i=Math.floor(t);if(i<0||i>=n.length)return!1;const o=this.row;if(this.row=i,i!==o)this.col=0;else{const f=(s=n[i])!=null&&s.length?n[i].length-1:0;this.col=Math.min(this.col,f)}return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}getCurrentYValue(){const t=this.lineValues[this.row];if(!t||t.length===0)return null;if(this.col>=0&&this.col<t.length){const n=t[this.col];return typeof n=="number"?n:null}return null}moveToXAndYValue(t,n){if(typeof t!="number")return!1;const i=Math.floor(t);if(i<0||i>=this.lineValues.length)return!1;this.row=i;const o=this.lineValues[this.row];if(!o||o.length===0)return this.col=0,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;let s=0,f=Math.abs(o[0]-n);for(let d=1;d<o.length;d++){const h=Math.abs(o[d]-n);h<f&&(f=h,s=d)}return this.col=s,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}onSwitchFrom(t){var f;const n=t;if(!((n.type||((f=n.state)==null?void 0:f.traceType))==="box"))return!1;const s=t.getCurrentXValue();if(t.getCurrentYValue){const d=t.getCurrentYValue();if(d!==null&&s!==null&&this.moveToXAndYValue){const h=this.moveToXAndYValue(s,d);return h&&(this.isInitialEntry=!1),h}}if(s!==null){const d=this.moveToXValue(s);return d&&(this.isInitialEntry=!1),d}return!1}}function qB(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function GB(e,t=!1){return t&&e.type===ar.SMOOTH?new HB(e):Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&qB(e.data[0][0])?new $B(e):new _7(e)}class FB{static create(t,n){const i=(n==null?void 0:n.isViolinPlot)===!0;switch(t.type){case ar.BAR:return new DB(t);case ar.BOX:return new kB(t,i);case ar.CANDLESTICK:return new LB(t);case ar.HEATMAP:return new IB(t);case ar.HISTOGRAM:return new BB(t);case ar.LINE:return new hA(t);case ar.SCATTER:return new VB(t);case ar.SMOOTH:return GB(t,i);case ar.DODGED:case ar.NORMALIZED:case ar.STACKED:return new jB(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const YB="MAIDR Plot",XB="unavailable",WB="unavailable";class QB extends C7{constructor(n){super();q(this,"id");q(this,"movable");q(this,"title");q(this,"subtitle");q(this,"caption");q(this,"subplots");q(this,"size");this.id=n.id,this.title=n.title??YB,this.subtitle=n.subtitle??XB,this.caption=n.caption??WB;const i=n.subplots;this.subplots=i.map(o=>o.map(s=>new KB(s))),this.size=this.subplots.reduce((o,s)=>o+s.length,0),this.movable=new Im(this.subplots,{row:this.subplots.length-1})}get dimension(){return{rows:this.subplots.length,cols:this.subplots[this.row].length}}dispose(){this.subplots.forEach(n=>n.forEach(i=>i.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((o,s)=>o+s.length,0),i=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:i.getStateWithFigurePosition(this.row,this.col),traceTypes:i.traceTypes,highlight:this.highlight}}get highlight(){var i;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}};try{const o=((i=this.subplots[0])==null?void 0:i.length)||1,s=this.row*o+this.col+1,f=`g[id="axes_${s}"]`,d=document.querySelector(f);if(d)return{empty:!1,elements:d};const h=document.querySelectorAll('g[id^="axes_"]');if(h.length>0&&s-1<h.length)return{empty:!1,elements:h[s-1]}}catch{return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}moveToPoint(n,i){this.notifyStateUpdate()}get outOfBoundsState(){return{empty:!0,type:"figure"}}}class KB extends C7{constructor(n){super();q(this,"movable");q(this,"traces");q(this,"traceTypes");q(this,"size");q(this,"highlightValue");q(this,"isViolinPlot");const i=n.layers;this.size=i.length;const o=i.map(h=>h.type),s=o.includes(ar.BOX),f=o.includes(ar.SMOOTH),d=s&&f;this.isViolinPlot=d,this.traces=i.map(h=>[FB.create(h,{isViolinPlot:d})]),this.traceTypes=this.traces.flat().map(h=>{const y=h.state;return y.empty?ge.EMPTY:y.traceType}),this.highlightValue=this.mapToSvgElement(n.selector),this.movable=new Im(this.traces)}get dimension(){return{rows:this.values.length,cols:this.values[this.row].length}}dispose(){this.traces.forEach(n=>n.forEach(i=>i.dispose())),this.traces.length=0,super.dispose()}getRow(){return this.row}getSize(){return this.size}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}moveOnce(n){return this.isViolinPlot?(this.isInitialEntry&&(this.isInitialEntry=!1),super.moveOnce(n)):super.moveOnce(n)}get state(){return{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight}}get outOfBoundsState(){return{empty:!0,type:"subplot"}}get highlight(){return this.highlightValue===null?{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.values.length,cols:this.values[this.row].length}}:{empty:!1,elements:this.highlightValue}}moveToPoint(n,i){this.notifyStateUpdate()}getStateWithFigurePosition(n,i){return this.state}mapToSvgElement(n){return n?Ht.selectElement(n)??null:null}}const ZB={SINE_BASIC:0},JB=100,eV=440,tV=880,mA=180,gA=.2,nV=.1,yA=.3,vA=ZB.SINE_BASIC;class rV{constructor(t,n,i){q(this,"notification");q(this,"isCombinedAudio");q(this,"mode");q(this,"activeAudioIds");q(this,"volume");q(this,"minFrequency");q(this,"maxFrequency");q(this,"audioContext");q(this,"compressor");this.notification=t,this.isCombinedAudio=!1,this.mode="on",this.updateMode(i),this.activeAudioIds=new Map,this.volume=this.normalizeVolume(n.get("general.volume")),this.minFrequency=n.get("general.minFrequency"),this.maxFrequency=n.get("general.maxFrequency"),n.onChange(o=>{o.affectsSetting("general.volume")&&(this.volume=this.normalizeVolume(o.get("general.volume"))),o.affectsSetting("general.minFrequency")&&(this.minFrequency=o.get("general.minFrequency")),o.affectsSetting("general.maxFrequency")&&(this.maxFrequency=o.get("general.maxFrequency"))}),this.audioContext=new AudioContext,this.compressor=this.initCompressor()}dispose(){this.stopAll(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close())}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const n=this.audioContext.createGain();return n.gain.value=.5,t.connect(n),n.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;n.empty||n.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=n.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}update(t){if(this.updateMode(t),this.mode==="off")return;if(t.empty){t.warning?this.playWarningTone():this.playEmptyTone({x:0,y:0,rows:0,cols:0});return}if(t.type!=="trace")return;const n=t.audio;if(n.isContinuous)this.playSmooth(n.freq,n.panning,"sine",n.volumeMultiplier,n.volumeScale);else if(Array.isArray(n.freq.raw)){const i=n.freq.raw;if(i.length===0){this.playZeroTone(n.panning);return}let o=0;const s=this.mode==="on"?50:0,f=new Array,d=()=>{o<i.length?(this.playTone({min:n.freq.min,max:n.freq.max,raw:i[o++]},{x:n.panning.x,y:n.panning.y,rows:n.panning.rows,cols:n.panning.cols},n.group),f.push(setTimeout(d,s))):this.stop(f)};d()}else n.freq.raw===0?this.playZeroTone(n.panning):this.playTone(n.freq,n.panning,n.group)}playTone(t,n,i=0){const o={min:t.min,max:t.max},s={min:this.minFrequency,max:this.maxFrequency},f=this.interpolate(t.raw,o,s),d=this.clamp(this.interpolate(n.x,{min:0,max:n.cols},{min:-1,max:1}),-1,1),h=this.clamp(this.interpolate(n.y,{min:0,max:n.rows},{min:-1,max:1}),-1,1);return this.playOscillator(f,{x:d,y:h},i)}getHarmony(t){const n={type:"sine",gain:1,multiplier:1};if(t===0)return[n];const i=[{type:"triangle",gain:.8,multiplier:2},{type:"sine",gain:.6,multiplier:1.5},{type:"triangle",gain:.4,multiplier:3},{type:"sine",gain:.3,multiplier:4}],o=[n];let s=n.gain,f=t;for(let d=0;d<i.length&&f>0;d++)(f&1)===1&&(o.push(i[d]),s+=i[d].gain),f>>=1;for(const d of o)d.gain/=s;return o}playOscillator(t,n={x:0,y:0},i=0){const o=yA,s=this.audioContext.currentTime,f=[],d=this.audioContext.createGain(),h=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"linear",positionX:n.x,positionY:n.y,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});d.connect(h),h.connect(this.compressor);const y=[.5*this.volume,this.volume,.5*this.volume,.5*this.volume,.5*this.volume,.1*this.volume,1e-4*this.volume];d.gain.setValueCurveAtTime(y,s,o);const S=this.getHarmony(i);for(const w of S){const C=this.audioContext.createOscillator();C.type=w.type,C.frequency.value=t*w.multiplier;const R=this.audioContext.createGain();R.gain.value=w.gain,C.connect(R),R.connect(d),C.start(s),f.push(C)}const E=w=>{h.disconnect(),d.disconnect(),f.forEach(C=>{C.stop(),C.disconnect()}),this.activeAudioIds.delete(w)},T=setTimeout(()=>E(T),o*1e3*2);return this.activeAudioIds.set(T,f),this.activeAudioIds.set(T,f),T}playSmooth(t,n,i="sine",o,s){const f=this.audioContext,d=f.currentTime,h=yA,y=t.raw.map(B=>this.interpolate(B,{min:t.min,max:t.max},{min:this.minFrequency,max:this.maxFrequency})),S=this.volume;let E;s!==void 0?E=S*Math.max(0,s):E=S*(o??1),y.length<2&&y.push(y[0]);const T=this.clamp(this.interpolate(n.x,{min:0,max:n.cols-1},{min:-1,max:1}),-1,1),w=this.clamp(this.interpolate(n.y,{min:0,max:n.rows-1},{min:-1,max:1}),-1,1),C=f.createOscillator();C.type=i,C.frequency.setValueCurveAtTime(y,d,h);const R=f.createGain(),D=[1e-4*E,.5*E,1e-4*E];R.gain.setValueCurveAtTime(D,d,h);const N=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"linear",positionX:T,positionY:w,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1});C.connect(R),R.connect(N),N.connect(this.compressor),C.start(d),C.stop(d+h);const z=setTimeout(()=>{C.disconnect(),R.disconnect(),N.disconnect(),this.activeAudioIds.delete(z)},h*1e3*2);this.activeAudioIds.set(z,C)}playEmptyTone(t){const n=this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),i=this.interpolate(t.y,{min:0,max:t.rows-1},{min:-1,max:1}),o=this.audioContext,s=o.currentTime,f=.2,d=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"inverse",positionX:n,positionY:i,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1}),h=[500,1e3,1500,2100,2700],y=[1,.6,.4,.2,.1],S=o.createGain();S.gain.setValueAtTime(.3*this.volume,s),S.gain.exponentialRampToValueAtTime(.01*this.volume,s+f),S.connect(d),d.connect(this.compressor);const E=[];for(let C=0;C<h.length;C++){const R=o.createOscillator(),D=o.createGain(),N=this.audioContext.createStereoPanner(),z=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});R.frequency.value=h[C],R.type="sine",D.gain.setValueAtTime(y[C]*this.volume,s),D.gain.exponentialRampToValueAtTime(.001*this.volume,s+f),R.connect(D),D.connect(N),N.connect(z),z.connect(S),R.start(s),R.stop(s+f),E.push(R)}const T=C=>{d.disconnect(),S.disconnect(),E.forEach(R=>{R.disconnect()}),this.activeAudioIds.delete(C)},w=setTimeout(()=>T(w),f*1e3*2);return this.activeAudioIds.set(w,E),w}playOneWarningBeep(t,n){const i=this.audioContext.createOscillator(),o=this.audioContext.createGain();i.type="sine",i.frequency.value=t;let s=1;i.type!=="sine"&&(s=.5),o.gain.setValueAtTime(s,n),o.gain.exponentialRampToValueAtTime(.001,n+gA),i.connect(o),o.connect(this.audioContext.destination),i.start(n),i.stop(n+gA)}playWarningTone(){const t=this.audioContext.currentTime;this.playOneWarningBeep(mA,t),this.playOneWarningBeep(mA/2**(1/12),t+nV)}playZeroTone(t){const n=this.clamp(this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),-1,1),i=this.clamp(this.interpolate(t.y,{min:0,max:t.rows-1},{min:-1,max:1}),-1,1);return this.playOscillator(JB,{x:n,y:i})}playWaitingTone(){return setInterval(()=>this.playOscillator(eV,{x:0,y:0},vA),1e3)}playCompleteTone(){return this.playOscillator(tV,{x:0,y:0},vA)}interpolate(t,n,i){return n.min===n.max?i.min:(t-n.min)/(n.max-n.min)*(i.max-i.min)+i.min}clamp(t,n,i){return Math.max(n,Math.min(t,i))}toggle(){switch(this.mode){case"off":this.mode=this.isCombinedAudio?"combined":"on";break;case"on":this.mode="off";break;case"combined":this.mode="on";break}const n=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(n)}stop(t){(Array.isArray(t)?t:[t]).forEach(i=>{const o=this.activeAudioIds.get(i);if(!o){clearInterval(i);return}(Array.isArray(o)?o:[o]).forEach(f=>{f==null||f.disconnect(),f==null||f.stop()}),clearTimeout(i),this.activeAudioIds.delete(i)})}stopAll(){this.activeAudioIds.forEach((t,n)=>{clearTimeout(n),(Array.isArray(t)?t:[t]).forEach(o=>{o.disconnect(),o.stop()})}),this.activeAudioIds.clear()}normalizeVolume(t){return t/100*(t/100)}}const iV=250,aV=50,oV=500,bA=20;class lV{constructor(t,n,i){q(this,"context");q(this,"notification");q(this,"settings");q(this,"autoplayId");q(this,"currentDirection");q(this,"userSpeed");q(this,"defaultSpeed");q(this,"minSpeed");q(this,"maxSpeed");q(this,"autoplayRate");q(this,"interval");q(this,"totalDuration");q(this,"onChangeEmitter");q(this,"onChange");this.notification=n,this.context=t,this.settings=i,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=iV,this.minSpeed=aV,this.maxSpeed=oV,this.interval=bA,this.autoplayRate=this.defaultSpeed,this.interval=bA,this.totalDuration=i.get("general.autoplayDuration"),i.onChange(o=>{o.affectsSetting("general.autoplayDuration")&&(this.totalDuration=o.get("general.autoplayDuration"),this.restart())}),this.onChangeEmitter=new Ad,this.onChange=this.onChangeEmitter.event}dispose(){this.stop(),this.onChangeEmitter.dispose()}start(t,n){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,n),this.currentDirection=t,this.autoplayId=setInterval(()=>{this.context.isMovable(t)?this.context.moveOnce(t):this.stop()},this.autoplayRate)}stop(){this.autoplayId&&clearInterval(this.autoplayId),this.autoplayId=null,this.currentDirection=null,this.onChangeEmitter.fire({type:"stop"})}restart(){this.autoplayId&&clearInterval(this.autoplayId),this.currentDirection&&this.start(this.currentDirection)}speedUp(){const t=this.userSpeed??this.autoplayRate;t-this.interval>this.minSpeed?(this.userSpeed=t-this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed up")):this.notification.notify("Max speed")}speedDown(){const t=this.userSpeed??this.autoplayRate;t+this.interval<=this.maxSpeed?(this.userSpeed=t+this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed down")):this.notification.notify("Min speed")}resetSpeed(){this.userSpeed=null,this.autoplayRate=this.defaultSpeed,this.restart(),this.notification.notify("Reset speed")}getAutoplayRate(t,n){if(this.userSpeed!==null)return this.userSpeed;if(n&&!n.empty){const i=Math.ceil(this.totalDuration/n.autoplay[t]);return this.defaultSpeed=i,this.minSpeed=Math.min(this.minSpeed,i),i}return this.defaultSpeed}}const SA=32;class cv{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const f=(t.max[s]-t.min[s])/4,d=t.min[s]+f,h=d+f,y=h+f;for(let S=0;S<t.values[s].length;S++)t.values[s][S]===0?n.push(" "):t.values[s][S]<=d||t.values[s][S]<=h?n.push("⠤"):t.values[s][S]<=y?n.push("⠒"):n.push("⠉"),i[s].push(o.length),o.push({row:s,col:S});n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class sV{constructor(){q(this,"GLOBAL_MIN","globalMin");q(this,"GLOBAL_MAX","globalMax");q(this,"BLANK","blank");q(this,"LOWER_OUTLIER","lowerOutlier");q(this,"UPPER_OUTLIER","upperOutlier");q(this,"MIN","min");q(this,"MAX","max");q(this,"Q1","q1");q(this,"Q2","q2");q(this,"Q3","q3")}encode(t,n=SA){const i=new Array,o=new Array,s=new Array;for(let f=0;f<t.values.length;f++){const d=t.values[f],h=[{type:this.GLOBAL_MIN,value:t.min},...d.lowerOutliers.map(X=>({type:this.LOWER_OUTLIER,value:X})),{type:this.MIN,value:d.min},{type:this.Q1,value:d.q1},{type:this.Q2,value:d.q2},{type:this.Q3,value:d.q3},{type:this.MAX,value:d.max},...d.upperOutliers.map(X=>({type:this.UPPER_OUTLIER,value:X})),{type:this.GLOBAL_MAX,value:t.max}],y=new Array;let S=!0;for(let X=0;X<h.length-1;X++){const le=h[X],ue=h[X+1],re=Math.abs(S?ue.value-le.value:le.value-h[X-1].value);le.type===this.LOWER_OUTLIER||le.type===this.UPPER_OUTLIER?(y.push({type:le.type,length:0,numChars:1}),y.push({type:this.BLANK,length:re,numChars:0})):le.type===this.Q2?(S=!1,y.push({type:this.Q2,length:0,numChars:2})):le.type===this.GLOBAL_MIN||le.type===this.GLOBAL_MAX?y.push({type:this.BLANK,length:re,numChars:0}):y.push({type:le.type,length:re,numChars:1})}let E=y.reduce((X,le)=>X+(le.numChars>0?le.numChars:0),0),[T,w,C,R]=[-1,-1,-1,-1];for(let X=0;X<y.length;X++)y[X].type===this.MIN&&y[X].length>0&&(T=X),y[X].type===this.MAX&&y[X].length>0&&(w=X),y[X].type===this.Q1&&(C=X),y[X].type===this.Q3&&(R=X);T!==-1&&w!==-1&&y[T].length!==y[w].length&&(y[T].length>y[w].length?(y[T].numChars++,E++):(y[w].numChars++,E++)),C!==-1&&R!==-1&&y[C].length!==y[R].length&&(y[C].length>y[R].length?(y[C].numChars++,E++):(y[R].numChars++,E++));const D=Math.max(0,n-E),N=y.reduce((X,le)=>X+(le.type!==this.Q2&&le.length>0?le.length:0),0);for(const X of y)if(X.type!==this.Q2&&X.length>0){const le=Math.round(X.length/N*D);X.numChars+=le}const z=y.reduce((X,le)=>X+le.numChars,0);let B=n-z,V=0;for(;B!==0;){const X=y[V%y.length];X.type!==this.BLANK&&X.type!==this.Q2&&X.length>0&&(X.numChars+=B>0?1:-1,B+=B>0?-1:1),V++}let L=-1;const P=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];s.push(Array.from({length:P.length}).fill(-1));for(const X of y){X.type!==this.BLANK&&X.type!==this.GLOBAL_MIN&&X.type!==this.GLOBAL_MAX&&(L=P.indexOf(X.type),s[f][L]=i.length);for(let le=0;le<X.numChars;le++){let ue="⠀";X.type===this.MIN||X.type===this.MAX?ue="⠒":X.type===this.Q1||X.type===this.Q3?ue="⠿":X.type===this.Q2?ue=le===0?"⠸":"⠇":X.type===this.LOWER_OUTLIER||X.type===this.UPPER_OUTLIER?ue="⠂":X.type===this.BLANK&&(ue="⠀"),i.push(ue),o.push({row:f,col:L})}}for(let X=0;X<3;X++)if(s[f][X]===-1){for(let le=X+1;le<=3;le++)if(s[f][le]!==-1){s[f][X]=s[f][le];break}}for(let X=6;X>3;X--)if(s[f][X]===-1){for(let le=X-1;le>=3;le--)if(s[f][le]!==-1){s[f][X]=s[f][le];break}}i.push(ge.NEW_LINE),o.push({row:f,col:L})}return{value:i.join(ge.EMPTY),cellToIndex:s,indexToCell:o}}}class uV{encode(t){const n=new Array,i=new Array,o=new Array,s=(t.max-t.min)/3,f=t.min+s,d=f+s;for(let h=0;h<t.values.length;h++){i.push(new Array);for(let y=0;y<t.values[h].length;y++)t.values[h][y]===0?n.push(" "):t.values[h][y]<=f?n.push("⠤"):t.values[h][y]<=d?n.push("⠒"):n.push("⠉"),i[h].push(o.length),o.push({row:h,col:y});n.push(ge.NEW_LINE),i[h].push(o.length),o.push({row:h,col:t.values[h].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class xA{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const{low:f,medium:d,mediumHigh:h,high:y}=this.getThresholds(s,t);for(let S=0;S<t.values[s].length;S++){const E=t.values[s][S],T=S>0?t.values[s][S-1]:null,w=this.getBrailleChar(E,T,f,d,y,h);n.push(w),i[s].push(o.length),o.push({row:s,col:S})}n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}getBrailleChar(t,n,i,o,s,f){return f===void 0&&(f=s),t<=i&&n!==null&&n>i?n<=o?"⢄":n<=f?"⢆":"⢇":t<=i?"⣀":n!==null&&n<=i?t<=o?"⡠":t<=f?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=f?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=f?"⠔":"⠜":t<=f&&n!==null&&n>f?"⠑":t<=f?"⠒":n!==null&&n<=f?"⠊":t<=s?"⠉":""}getBraille6Char(t,n,i,o,s){const f=E=>E<=i?"low":E<=o?"medium":(E<=s,"high"),d=f(t),h=n!==null?f(n):null,y={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},S=`${d},${h}`;return y[S]||""}addDot8(t){if(!t||t.length===0)return"⢀";const o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class cV extends xA{getThresholds(t,n){const i=Array.isArray(n.min)?n.min[t]:n.min,o=Array.isArray(n.max)?n.max[t]:n.max,s=(o-i)/3,f=i+s,d=f+s;return{low:f,medium:d,high:o}}encode(t){var s;const n=new Array,i=new Array,o=new Array;for(let f=0;f<t.values.length;f++){i.push(new Array);const{low:d,medium:h,high:y}=this.getThresholds(f,t);for(let S=0;S<t.values[f].length;S++){const E=t.values[f][S],T=S>0?t.values[f][S-1]:null;let w=this.getBraille6Char(E,T,d,h,y);((s=t.custom)==null?void 0:s[S])==="Bear"&&(w=this.addDot8(w)),n.push(w),i[f].push(o.length),o.push({row:f,col:S})}n.push(ge.NEW_LINE),i[f].push(o.length),o.push({row:f,col:t.values[f].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class EA extends xA{getThresholds(t,n){const i=(n.max[t]-n.min[t])/4,o=n.min[t]+i,s=o+i,f=s+i,d=n.max[t];return{low:o,medium:s,mediumHigh:f,high:d}}}class fV{constructor(t,n,i){q(this,"context");q(this,"notification");q(this,"display");q(this,"enabled");q(this,"cacheId");q(this,"cache");q(this,"encoders");q(this,"onChangeEmitter");q(this,"onChange");this.context=t,this.notification=n,this.display=i,this.enabled=!1,this.cacheId=ge.EMPTY,this.cache=null,this.encoders=new Map([[ar.BAR,new cv],[ar.BOX,new sV],[ar.CANDLESTICK,new cV],[ar.DODGED,new cv],[ar.HEATMAP,new uV],[ar.HISTOGRAM,new cv],[ar.LINE,new EA],[ar.NORMALIZED,new cv],[ar.SMOOTH,new EA],[ar.STACKED,new cv]]),this.onChangeEmitter=new Ad,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const n=t.type==="subplot"?t.trace:t;if(n.empty||n.braille.empty||!this.encoders.has(n.traceType))return;const i=n.braille;if(this.cache===null||this.cacheId!==i.id){const o=this.encoders.get(n.traceType);this.cache=o.encode(i,SA),this.cacheId=i.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[i.row][i.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:i}=this.cache.indexToCell[t];this.context.moveToIndex(n,i)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const i=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(i);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(Cn.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var wA=(e=>(e[e.OK=200]="OK",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.SERVER_ERROR=500]="SERVER_ERROR",e))(wA||{});class TA{constructor(){}static async post(t,n,i){const o={...this.DEFAULT_HEADERS,...i};return this.request(t,"POST",o,n)}static async request(t,n,i,o){try{const s=await fetch(t,{method:n,headers:i,body:o});return s.ok?{success:!0,data:await s.json()}:{success:!1,error:{statusCode:s.status,message:`API Error: ${s.status} - ${s.statusText}`}}}catch(s){return console.error(`Error in API ${n} request to ${t}:`,s),{success:!1,error:{statusCode:wA.SERVER_ERROR,message:s instanceof Error?s.message:"Unknown error occurred"}}}}}q(TA,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const dV=`You are a helpful assistant that answers questions about statistical visualizations. Your role is to:
307
+ S for Sonification, and R for Review mode.`;case"trace":{let o=n.plotType;n.plotType==="multiline"&&n.groupCount===1&&(o="single line");const s=o==="multiline"&&n.groupCount?` with ${n.groupCount} groups`:"";return`This is a maidr plot of type: ${o}${s}. ${i} Use Arrows to navigate data points. Toggle B for Braille, T for Text, S for Sonification, and R for Review mode.`}}}}class N3{constructor(){}static parse(t){const n=t.replace(/\s/g,"").toLowerCase();if(/^#(?:[a-f0-9]{3}){1,2}$/.test(n)){let o=n.substring(1).split("");return o.length===3&&(o=[o[0],o[0],o[1],o[1],o[2],o[2]]),{r:Number.parseInt(o[0]+o[1],16),g:Number.parseInt(o[2]+o[3],16),b:Number.parseInt(o[4]+o[5],16)}}const i=n.match(/^rgba?\((\d+),(\d+),(\d+)(?:,\d*(?:\.\d*)?)?\)$/);return i?{r:Number.parseInt(i[1],10),g:Number.parseInt(i[2],10),b:Number.parseInt(i[3],10)}:null}static invert(t){return{r:255-t.r,g:255-t.g,b:255-t.b}}static getContrastRatio(t,n){const i=this.calculateLuminance(t),o=this.calculateLuminance(n);return(Math.max(i,o)+.05)/(Math.min(i,o)+.05)}static calculateLuminance(t){const[n,i,o]=[t.r,t.g,t.b].map(s=>{const f=s/255;return f<=.03928?f/12.92:((f+.055)/1.055)**2.4});return .2126*n+.7152*i+.0722*o}static rgbToString(t){return`rgb(${t.r}, ${t.g}, ${t.b})`}static isEqual(t,n){const i=this.parse(t),o=this.parse(n);return!i||!o?!1:i.r===o.r&&i.g===o.g&&i.b===o.b}}class Ht{constructor(){}static async toBase64(t){try{const n=new XMLSerializer().serializeToString(t).replace(/>\s+</g,"> <").replace(/\s{2,}/g," ").trim(),o=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n).replace(/'/g,"%27").replace(/"/g,"%22")}`,s=await new Promise((h,y)=>{const S=new Image;S.onload=()=>h(S),S.onerror=()=>y(new Error("Failed to load SVG image")),S.src=o}),f=document.createElement("canvas");[f.width,f.height]=[s.naturalWidth,s.naturalHeight];const d=f.getContext("2d");return d?(d.drawImage(s,0,0),f.toDataURL("image/jpeg",.92)):(console.error("Error converting SVG to Base 64: Canvas context unavailable"),"")}catch(n){return console.error("Error converting SVG to Base 64:",n instanceof Error?n.message:n),""}}static selectAllElements(t,n=!0){return Array.from(document.querySelectorAll(t)).map(i=>{if(!n)return i;const o=i.cloneNode(!0);return o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i.insertAdjacentElement(ge.AFTER_END,o),o})}static selectElement(t,n=!0){const i=document.querySelector(t);if(!n)return i;const o=i==null?void 0:i.cloneNode(!0);return o==null||o.setAttribute(ge.VISIBILITY,ge.HIDDEN),i==null||i.insertAdjacentElement(ge.AFTER_END,o),o}static createEmptyElement(t="rect"){const n=document.createElementNS(this.SVG_NAMESPACE,t);return n.setAttribute(ge.FILL,ge.TRANSPARENT),n.setAttribute(ge.STROKE,ge.TRANSPARENT),n.setAttribute(ge.VISIBILITY,ge.HIDDEN),n}static createCircleElement(t,n,i){var y;const o=window.getComputedStyle(i),s=o.stroke||o.fill,f=o.strokeWidth||"2",d=Number.parseFloat(f)*2,h=document.createElementNS(this.SVG_NAMESPACE,ge.CIRCLE);return h.setAttribute(ge.CIRCLE_X,String(t)),h.setAttribute(ge.CIRCLE_Y,String(n)),h.setAttribute(ge.RADIUS,String(d)),h.setAttribute(ge.FILL,s),h.setAttribute(ge.STROKE,s),h.setAttribute(ge.STROKE_WIDTH,f),h.setAttribute(ge.VISIBILITY,ge.HIDDEN),(y=i.parentElement)==null||y.insertAdjacentElement(ge.AFTER_END,h),h}static createLineElement(t,n){const o=t.getBBox();let s,f,d,h;switch(n){case"top":[s,f,d,h]=[o.x,o.y,o.x+o.width,o.y];break;case"bottom":[s,f,d,h]=[o.x,o.y+o.height,o.x+o.width,o.y+o.height];break;case"left":[s,f,d,h]=[o.x,o.y,o.x,o.y+o.height];break;case"right":[s,f,d,h]=[o.x+o.width,o.y,o.x+o.width,o.y+o.height];break}const y=window.getComputedStyle(t),S=document.createElementNS(this.SVG_NAMESPACE,ge.LINE);return S.setAttribute(ge.X1,String(s)),S.setAttribute(ge.Y1,String(f)),S.setAttribute(ge.X2,String(d)),S.setAttribute(ge.Y2,String(h)),S.setAttribute(ge.STROKE,y.stroke),S.setAttribute(ge.STROKE_WIDTH,y.strokeWidth||"2"),S.setAttribute(ge.VISIBILITY,ge.HIDDEN),t.insertAdjacentElement(ge.AFTER_END,S),S}static getAdjustedOpacity(t,n){const i=t?Number.parseFloat(t):Number.NaN;return!Number.isNaN(i)&&i>n?i.toString():"1"}static createHighlightElement(t,n){const i=t.cloneNode(!0),o=t.tagName.toLowerCase(),s=o===ge.POLYLINE||o===ge.LINE,f=window.getComputedStyle(t),d=s?f.getPropertyValue(ge.STROKE):f.getPropertyValue(ge.FILL),h=this.getHighlightColor(d,n),y=f.getPropertyValue("fill-opacity"),S=f.getPropertyValue("stroke-opacity");if(i.style.fillOpacity=this.getAdjustedOpacity(y,this.MIN_VISIBLE_FILL_OPACITY),i.style.strokeOpacity=this.getAdjustedOpacity(S,this.MIN_VISIBLE_STROKE_OPACITY),i.setAttribute(ge.VISIBILITY,ge.VISIBLE),i.setAttribute(ge.STROKE,h),i.setAttribute(ge.FILL,h),i.style.fill=h,i.style.stroke=h,s){const E=window.getComputedStyle(i).getPropertyValue(ge.STROKE_WIDTH),T=E.match(/^([0-9.]+)([a-z%]*)$/i);if(T){const w=Number.parseFloat(T[1]),C=T[2]||"";i.setAttribute(ge.STROKE_WIDTH,`${w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE}${C}`)}else{const w=Number.parseFloat(E),C=Number.isNaN(w)?this.STROKE_WIDTH_HIGHLIGHT_INCREASE:w+this.STROKE_WIDTH_HIGHLIGHT_INCREASE;i.setAttribute(ge.STROKE_WIDTH,`${C}`)}}return t.insertAdjacentElement(ge.AFTER_END,i),i}static getHighlightColor(t,n){const i=N3.parse(t);if(!i||!(N3.getContrastRatio(i,ge.HIGHLIGHT_BASE_COLOR)<ge.HIGHLIGHT_CONTRAST_RATIO))return n;const f={...i};return i.r===i.g&&i.g===i.b?(f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)),f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)),f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO))):i.r>=i.g&&i.r>=i.b?f.r=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.r*ge.HIGHLIGHT_COLOR_RATIO)):i.g>=i.r&&i.g>=i.b?f.g=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.g*ge.HIGHLIGHT_COLOR_RATIO)):f.b=Math.min(ge.HIGHLIGHT_MAX_COLOR,Math.floor(i.b*ge.HIGHLIGHT_COLOR_RATIO)),N3.rgbToString(f)}static getContrastingColorForElement(t){const n=window.getComputedStyle(t).fill||"rgb(255,255,255)",i=N3.parse(n);return i?(.2126*i.r+.7152*i.g+.0722*i.b)/255>.5?"#000":"#fff":"#000"}static setSubplotHighlightCss(t,n){t.style.outline=`4px solid ${n}`,t.style.outlineOffset="3px",t.style.borderRadius="3px",t.style.overflow="visible"}static removeSubplotHighlightCss(t){t.style.removeProperty("outline"),t.style.removeProperty("outline-offset"),t.style.removeProperty("border-radius"),t.style.removeProperty("overflow")}static setSubplotHighlightSvgWithAdaptiveColor(t,n,i){const o=t.querySelector("rect, path");let s="";if(o){s=window.getComputedStyle(o).getPropertyValue("fill"),(!s||s==="none"||s==="transparent"||s==="rgba(0, 0, 0, 0)")&&(i?s=window.getComputedStyle(i).getPropertyValue("fill"):s=n);const f=this.getHighlightColor(s,n);o.setAttribute("stroke",f),o.setAttribute("stroke-width","4")}}static removeSubplotHighlightSvg(t){const n=t.querySelector("rect, path");n&&(n.removeAttribute("stroke"),n.removeAttribute("stroke-width"))}}q(Ht,"SVG_NAMESPACE","http://www.w3.org/2000/svg"),q(Ht,"MIN_VISIBLE_FILL_OPACITY",.01),q(Ht,"MIN_VISIBLE_STROKE_OPACITY",.01),q(Ht,"STROKE_WIDTH_HIGHLIGHT_INCREASE",2);const AB="unavailable",CB="X",OB="Y",MB="unavailable";class C7{constructor(){q(this,"observers");q(this,"isWarning");this.observers=new Array,this.isWarning=!1}dispose(){this.observers.length=0}notifyRotorBounds(){this.isWarning=!0,this.notifyStateUpdate(),this.isWarning=!1}get isInitialEntry(){return this.movable.isInitialEntry}set isInitialEntry(t){this.movable.isInitialEntry=t}get isOutOfBounds(){return this.movable.isOutOfBounds}set isOutOfBounds(t){this.movable.isOutOfBounds=t}get row(){return this.movable.row}get col(){return this.movable.col}set row(t){this.movable.row=t}set col(t){this.movable.col=t}getSafeIndices(){const t=this.row>=0&&this.row<this.dimension.rows?this.row:0,n=this.col>=0&&this.col<this.dimension.cols?this.col:0;return{row:t,col:n}}addObserver(t){this.observers.push(t)}removeObserver(t){const n=this.observers.indexOf(t);n!==-1&&this.observers.splice(n,1)}notifyStateUpdate(){const t=this.state;this.observers.forEach(n=>n.update(t))}notifyOutOfBounds(){const t=this.outOfBoundsState;this.observers.forEach(n=>n.update(t))}moveOnce(t){const n=this.movable.moveOnce(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToExtreme(t){const n=this.movable.moveToExtreme(t);return n?this.notifyStateUpdate():this.notifyOutOfBounds(),n}moveToIndex(t,n){const i=this.movable.moveToIndex(t,n);return i?this.notifyStateUpdate():this.notifyOutOfBounds(),i}isMovable(t){return this.movable.isMovable(t)}notifyObserversWithState(t){for(const n of this.observers)n.update(t)}moveToNextCompareValue(t,n){return this.notifyRotorBounds(),!1}compare(t,n,i){return i==="lower"?t<n:i==="higher"?t>n:!1}moveUpRotor(t){throw new Error("Move up function is not defined for this trace")}moveDownRotor(t){throw new Error("Move down function is not defined for this trace")}moveLeftRotor(t){throw new Error("Move left function is not defined for this trace")}moveRightRotor(t){throw new Error("Move right function is not defined for this trace")}moveToPoint(t,n){}}class Pl extends C7{constructor(n){var i,o,s;super();q(this,"id");q(this,"type");q(this,"title");q(this,"xAxis");q(this,"yAxis");q(this,"fill");q(this,"navigationService");q(this,"layer");this.layer=n,this.navigationService=new S7,this.id=n.id,this.type=n.type,this.title=n.title??AB,this.xAxis=((i=n.axes)==null?void 0:i.x)??CB,this.yAxis=((o=n.axes)==null?void 0:o.y)??OB,this.fill=((s=n.axes)==null?void 0:s.fill)??MB}dispose(){this.highlightValues&&(this.highlightValues.forEach(n=>n.forEach(i=>{(Array.isArray(i)?i:[i]).forEach(s=>s.remove())})),this.highlightValues.length=0),super.dispose()}get state(){return this.isWarning?{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols},warning:!0}:{empty:!1,type:"trace",traceType:this.type,plotType:this.type,title:this.title,xAxis:this.xAxis,yAxis:this.yAxis,fill:this.fill,hasMultiPoints:this.hasMultiPoints,audio:this.audio,braille:this.braille,text:this.text,autoplay:this.autoplay,highlight:this.highlight}}get outOfBoundsState(){return{empty:!0,type:"trace",traceType:this.type,audio:{y:this.row,x:this.col,rows:this.dimension.rows,cols:this.dimension.cols}}}get highlight(){return this.highlightValues===null||this.isInitialEntry?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}get autoplay(){return{UPWARD:this.dimension.rows,DOWNWARD:this.dimension.rows,FORWARD:this.dimension.cols,BACKWARD:this.dimension.cols}}resetToInitialEntry(){this.isInitialEntry=!0,this.row=0,this.col=0}get hasMultiPoints(){return!1}getExtremaTargets(){return[]}navigateToExtrema(n){if(this.supportsExtrema)throw new Error("Extrema navigation not implemented by this plot type")}finalizeExtremaNavigation(){this.isInitialEntry&&(this.isInitialEntry=!1),this.updateVisualPointPosition(),this.notifyStateUpdate()}updateVisualPointPosition(){}supportsExtremaNavigation(){return this.supportsExtrema}getCurrentXValue(){if(this.hasPointsArray()){const n=this.getPointsArray();if(this.isValidPointsArray(n))return this.navigationService.extractXValueFromPoints(n,this.row,this.col)}if(this.hasValuesArray()){const n=this.values;if(this.isValidValuesArray(n))return this.navigationService.extractXValueFromValues(n,this.row,this.col)}return null}moveToXValue(n){if(this.hasPointsArray()){const i=this.getPointsArray();if(this.isValidPointsArray(i))return this.navigationService.moveToXValueInPoints(i,n,this.moveToIndex.bind(this))}if(this.hasValuesArray()){const i=this.values;if(this.isValidValuesArray(i))return this.navigationService.moveToXValueInValues(i,n,this.moveToIndex.bind(this))}return!1}hasPointsArray(){return"points"in this&&this.points!==void 0}hasValuesArray(){return"values"in this&&this.values!==void 0}getPointsArray(){return this.points}isValidPointsArray(n){return Array.isArray(n)&&n.length>0}isValidValuesArray(n){return Array.isArray(n)&&n.length>0}getId(){return this.id}moveToPoint(n,i){const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}isPointInBounds(n,i,{element:o,row:s,col:f}){const d=o.getBoundingClientRect();let h=12;return(this.type===ar.HEATMAP||this.type===ar.BAR||this.type===ar.STACKED||this.type===ar.HISTOGRAM)&&(h=0),n>=d.x-h&&n<=d.x+d.width+h&&i>=d.y-h&&i<=d.y+d.height+h}}class Na{constructor(){}static safeMin(t){return t.length===0?1/0:Math.min(...t)}static safeMax(t){return t.length===0?-1/0:Math.max(...t)}static minFrom2D(t){const n=t.flat();return this.safeMin(n)}static maxFrom2D(t){const n=t.flat();return this.safeMax(n)}static minMax(t){if(t.length===0)return{min:1/0,max:-1/0};let n=t[0],i=t[0];for(let o=1;o<t.length;o++){const s=t[o];s<n&&(n=s),s>i&&(i=s)}return{min:n,max:i}}static minMaxFrom2D(t){const n=t.flat();return this.minMax(n)}}class O7{constructor(t){q(this,"isInitialEntry");q(this,"isOutOfBounds");q(this,"row");q(this,"col");this.isInitialEntry=(t==null?void 0:t.isInitialEntry)??!0,this.isOutOfBounds=!1,this.row=(t==null?void 0:t.row)??0,this.col=(t==null?void 0:t.col)??0}moveToIndex(t,n){return this.isMovable([t,n])?(this.row=t,this.col=n,this.isInitialEntry=!1,!0):!1}}class Im extends O7{constructor(n,i){super(i);q(this,"elements");this.elements=n}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;switch(n){case"UPWARD":this.row+=1;break;case"DOWNWARD":this.row-=1;break;case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}return!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":this.row=this.elements.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.col=this.elements[this.row].length-1;break;case"BACKWARD":this.col=0;break}return!0}moveToIndex(n,i){return this.isMovable([n,i])?(this.row=n,this.col=i,this.isInitialEntry=!1,!0):!1}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.elements.length&&o>=0&&o<this.elements[this.row].length}switch(n){case"UPWARD":return this.row<this.elements.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":return this.col<this.elements[this.row].length-1;case"BACKWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=Math.max(0,Math.min(this.row,this.elements.length-1)),this.col=Math.max(0,Math.min(this.col,this.elements[this.row].length-1))}}class RB extends O7{constructor(n,i){super(i);q(this,"graph");this.graph=n}moveOnce(n){var s;if(this.isInitialEntry)return this.handleInitialEntry(),!0;const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.up;break;case"DOWNWARD":o=i.down;break;case"FORWARD":o=i.right;break;case"BACKWARD":o=i.left;break}return o?(this.row=o.row,this.col=o.col,!0):!1}moveToExtreme(n){var s;this.isInitialEntry&&this.handleInitialEntry();const i=(s=this.graph[this.row])==null?void 0:s[this.col];if(!i)return!1;let o=null;switch(n){case"UPWARD":o=i.top;break;case"DOWNWARD":o=i.bottom;break;case"FORWARD":o=i.end;break;case"BACKWARD":o=i.start;break}return o?(this.row=o.row,this.col=o.col,!0):!1}isMovable(n){var o,s,f;if(Array.isArray(n)){const[d,h]=n;return((o=this.graph[d])==null?void 0:o[h])!==null&&((s=this.graph[d])==null?void 0:s[h])!==void 0}const i=(f=this.graph[this.row])==null?void 0:f[this.col];if(!i)return!1;switch(n){case"UPWARD":return i.up!==null;case"DOWNWARD":return i.down!==null;case"FORWARD":return i.right!==null;case"BACKWARD":return i.left!==null}}handleInitialEntry(){this.isInitialEntry=!1,this.isMovable([0,0])?(this.row=0,this.col=0):(this.row=-1,this.col=-1)}}class _B extends O7{constructor(n,i){super();q(this,"mode");q(this,"xPoints");q(this,"yPoints");q(this,"xValues");q(this,"yValues");this.mode="col",this.xPoints=n,this.yPoints=i,this.xValues=n.map(o=>o.x),this.yValues=i.map(o=>o.y)}dispose(){this.xValues.length=0,this.yValues.length=0}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),!0;if(!this.isMovable(n))return!1;if(this.mode==="col")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}return!0}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="col")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}return!0}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="col")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}toggleNavigation(){if(this.mode==="col"){const n=this.xPoints[this.col],i=n.y[Math.floor(n.y.length/2)];this.row=this.yValues.indexOf(i),this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)];this.col=this.xValues.indexOf(i),this.mode="col"}}handleInitialEntry(){this.isInitialEntry=!1,this.mode==="col"?(this.col=Math.max(0,Math.min(this.col,this.xPoints.length-1)),this.row=Math.max(0,Math.min(this.row,this.xPoints[this.col].y.length-1))):(this.row=Math.max(0,Math.min(this.row,this.yPoints.length-1)),this.col=Math.max(0,Math.min(this.col,this.yPoints[this.row].x.length-1)))}}class M7 extends Pl{constructor(n,i){super(n);q(this,"movable");q(this,"points");q(this,"barValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"orientation");q(this,"min");q(this,"max");q(this,"supportsExtrema",!0);this.points=i,this.orientation=n.orientation??An.VERTICAL,this.barValues=i.map(o=>o.map(s=>this.orientation===An.VERTICAL?Number(s.y):Number(s.x))),this.min=this.barValues.map(o=>Na.safeMin(o)),this.max=this.barValues.map(o=>Na.safeMax(o)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Im(this.points)}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}get audio(){const n=this.orientation===An.VERTICAL,i=n?this.barValues[this.row][this.col]:this.barValues[this.col][this.row];return{freq:{min:Na.safeMin(this.min),max:Na.safeMax(this.max),raw:i},panning:{x:n?this.col:this.row,y:n?this.row:this.col,rows:n?this.barValues.length:this.barValues[this.col].length,cols:n?this.barValues[this.row].length:this.barValues.length},group:n?this.row:this.col}}get braille(){return{empty:!1,id:this.id,values:this.barValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){const n=this.orientation===An.VERTICAL,i=this.points[this.row][this.col],o=n?this.xAxis:this.yAxis,s=n?i.x:i.y,f=n?this.yAxis:this.xAxis,d=n?i.y:i.x;return{main:{label:o,value:s},cross:{label:f,value:d}}}get dimension(){return{rows:this.barValues.length,cols:this.barValues[this.row].length}}get values(){return this.barValues}mapToSvgElements(n){if(!n)return null;const i=[Ht.selectAllElements(n)];if(i.length!==this.points.length)return null;for(let o=0;o<this.points.length;o++)if(i[o].length!==this.points[o].length)return null;return i}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();d&&i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}return i}findNearestPoint(n,i){if(!this.highlightValues)return null;for(let o=0;o<this.highlightValues.length;o++)for(let s=0;s<this.highlightValues[o].length;s++){const f=this.highlightValues[o][s],d=Array.isArray(f)?f[0]:f,h=d.getBoundingClientRect();if(n>=h.x&&n<=h.x+h.width&&i>=h.y&&i<=h.y+h.height)return{element:d,row:o,col:s}}return null}}class DB extends M7{isPointInBounds(t,n,{element:i,row:o,col:s}){const f=i.getBoundingClientRect();return t>=f.x&&t<=f.x+f.width&&n>=f.y&&n<=f.y+f.height}constructor(t){super(t,[t.data])}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.barValues[n];if(!i||i.length===0)return t;const o=this.min[n],s=this.max[n],f=i.indexOf(s),d=i.indexOf(o);return t.push({label:`Max Bar at ${this.getPointLabel(f)}`,value:s,pointIndex:f,segment:"bar",type:"max",navigationType:"point"}),t.push({label:`Min Bar at ${this.getPointLabel(d)}`,value:o,pointIndex:d,segment:"bar",type:"min",navigationType:"point"}),t}navigateToExtrema(t){this.col=t.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(t){if(this.points[this.row]&&this.points[this.row][t]){const n=this.points[this.row][t];return this.orientation===An.VERTICAL?`${n.x}`:`${n.y}`}return`Point ${t}`}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const Js={LOWER_OUTLIER:"Lower outlier(s)",MIN:"Minimum",Q1:"25%",Q2:"50%",Q3:"75%",MAX:"Maximum",UPPER_OUTLIER:"Upper outlier(s)"};class kB extends Pl{constructor(n,i=!1){var f;super(n);q(this,"supportsExtrema",!1);q(this,"movable");q(this,"points");q(this,"boxValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"orientation");q(this,"sections");q(this,"min");q(this,"max");q(this,"isViolinBoxPlot");this.isViolinBoxPlot=i&&n.type===ar.BOX,this.points=n.data,this.orientation=n.orientation??An.VERTICAL,this.orientation===An.HORIZONTAL?this.points=[...n.data].reverse():this.points=n.data,this.sections=[Js.LOWER_OUTLIER,Js.MIN,Js.Q1,Js.Q2,Js.Q3,Js.MAX,Js.UPPER_OUTLIER];const o=[d=>d.lowerOutliers,d=>d.min,d=>d.q1,d=>d.q2,d=>d.q3,d=>d.max,d=>d.upperOutliers];this.orientation===An.HORIZONTAL?this.boxValues=this.points.map(d=>o.map(h=>h(d))):this.boxValues=o.map(d=>this.points.map(h=>d(h)));const s=this.boxValues.map(d=>d.flatMap(h=>Array.isArray(h)?h:[h]));this.min=Na.minFrom2D(s),this.max=Na.maxFrom2D(s),this.highlightValues=this.mapToSvgElements(n.selectors),this.orientation===An.HORIZONTAL&&((f=this.highlightValues)==null||f.reverse()),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Im(this.boxValues,{row:0})}isViolin(){return this.isViolinBoxPlot}dispose(){this.points.length=0,this.sections.length=0,super.dispose()}moveToIndex(n,i){return super.moveToIndex(n,i)}handleInitialEntry(){var n;this.isInitialEntry=!1,this.orientation===An.VERTICAL?(this.row=Math.min(1,this.boxValues.length-1),this.col=0):(this.row=0,this.col=Math.min(1,((n=this.boxValues[0])==null?void 0:n.length)??1))}moveOnce(n){if(!this.isViolin())return super.moveOnce(n);if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.orientation===An.VERTICAL)if(n==="FORWARD")this.col+=1,this.row=1;else if(n==="BACKWARD")this.col-=1,this.row=1;else return super.moveOnce(n);else if(n==="UPWARD")this.row+=1,this.col=1;else if(n==="DOWNWARD")this.row-=1,this.col=1;else return super.moveOnce(n);return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}get values(){return this.boxValues}get audio(){const n=this.orientation===An.HORIZONTAL,i=this.boxValues[this.row][this.col],o=n?this.col:this.row,s=Array.isArray(i)?i.length===0?o:i[i.length-1]-this.min:Number.isNaN(i)?o:i-this.min;return{freq:{min:this.min,max:this.max,raw:this.boxValues[this.row][this.col]},panning:{x:n?s:this.row,y:n?this.row:s,rows:n?this.boxValues.length:this.max-this.min,cols:n?this.max-this.min:this.boxValues.length}}}get braille(){const n=this.orientation===An.HORIZONTAL,i=n?this.row:this.col,o=n?this.col:this.row;return{empty:!1,id:this.id,values:this.points,min:this.min,max:this.max,row:i,col:o}}get text(){const n=this.orientation===An.HORIZONTAL,i=n?this.points[this.row]:this.points[this.col],o=n?this.yAxis:this.xAxis,s=n?this.sections[this.col]:this.sections[this.row],f=n?this.xAxis:this.yAxis,d=this.boxValues[this.row][this.col];return{main:{label:o,value:i.fill},cross:{label:f,value:d},section:s}}get dimension(){const n=this.orientation===An.HORIZONTAL;return{rows:n?this.boxValues.length:this.boxValues[this.row].length,cols:n?this.boxValues[this.row].length:this.boxValues.length}}mapToSvgElements(n){if(!n||n.length!==this.points.length)return null;const i=this.orientation===An.VERTICAL,o=new Array;if(i)for(let f=0;f<this.sections.length;f++)o.push(Array.from({length:n.length}));const s=[];return n.forEach(f=>{var w,C;const d=((w=f.lowerOutliers)==null?void 0:w.flatMap(R=>Ht.selectAllElements(R,!1)))??[],h=((C=f.upperOutliers)==null?void 0:C.flatMap(R=>Ht.selectAllElements(R,!1)))??[],y=Ht.selectElement(f.min,!1),S=Ht.selectElement(f.max,!1),E=Ht.selectElement(f.iq,!1),T=Ht.selectElement(f.q2,!1);s.push({lowerOutliers:d,upperOutliers:h,min:y,max:S,iq:E,q2:T})}),s.forEach((f,d)=>{var N;const h=f.lowerOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),y=f.upperOutliers.map(z=>{const B=z.cloneNode(!0);return B.setAttribute(ge.VISIBILITY,ge.HIDDEN),z.insertAdjacentElement(ge.AFTER_END,B),B}),S=this.cloneElementOrEmpty(f.min),E=this.cloneElementOrEmpty(f.max),T=this.cloneElementOrEmpty(f.q2),w=((N=this.layer.domMapping)==null?void 0:N.iqrDirection)==="reverse",[C,R]=f.iq?i?w?[Ht.createLineElement(f.iq,"top"),Ht.createLineElement(f.iq,"bottom")]:[Ht.createLineElement(f.iq,"bottom"),Ht.createLineElement(f.iq,"top")]:[Ht.createLineElement(f.iq,"left"),Ht.createLineElement(f.iq,"right")]:[Ht.createEmptyElement("line"),Ht.createEmptyElement("line")],D=[h,S,C,T,R,E,y];i?D.forEach((z,B)=>{o[B][d]=z}):o.push(D)}),o}cloneElementOrEmpty(n){if(!n)return Ht.createEmptyElement();const i=n.cloneNode(!0);return i.setAttribute(ge.VISIBILITY,ge.HIDDEN),n.insertAdjacentElement(ge.AFTER_END,i),i}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.boxValues.length)return!1;let s=[],f=0;if(n==="left"||n==="right"?(s=this.boxValues[this.row],f=this.col):(s=this.boxValues.map(y=>y[this.col]),f=this.row),s.length<=0)return!1;const d=n==="right"||n==="up"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){const y=s[f],S=s[h];if(Array.isArray(S)||Array.isArray(y))return!0;if(this.compare(S,y,i))return this.set_point(n,h),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}set_point(n,i){n==="left"||n==="right"?this.col=i:this.row=i}moveUpRotor(n){return this.orientation===An.VERTICAL?(this.moveOnce("UPWARD"),!0):this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.orientation===An.VERTICAL?(this.moveOnce("DOWNWARD"),!0):this.moveToNextCompareValue("down",n)}moveLeftRotor(n){return this.orientation===An.HORIZONTAL?(this.moveOnce("BACKWARD"),!0):this.moveToNextCompareValue("left",n)}moveRightRotor(n){return this.orientation===An.HORIZONTAL?(this.moveOnce("FORWARD"),!0):this.moveToNextCompareValue("right",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){}getCurrentXValue(){return this.isViolin()?this.orientation===An.VERTICAL?this.col>=0?this.col:null:this.row>=0?this.row:null:super.getCurrentXValue()}moveToXValue(n){if(!this.isViolin())return super.moveToXValue(n);if(this.isInitialEntry&&this.handleInitialEntry(),typeof n!="number")return!1;const i=Math.floor(n),o=this.values;if(this.orientation===An.VERTICAL){const s=o.length>0?o[0].length:0;if(i<0||i>=s)return!1;const f=this.col;return this.col=i,i!==f&&(this.row=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(i<0||i>=o.length)return!1;const s=this.row;return this.row=i,i!==s&&(this.col=1),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}getCurrentYValue(){if(!this.isViolin())return null;const n=this.values;if(this.orientation===An.VERTICAL){if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}}else if(this.row>=0&&this.row<n.length&&this.col>=0){const i=n[this.row];if(Array.isArray(i)&&this.col<i.length){const o=i[this.col];return Array.isArray(o)?o.length>0?o[0]:null:typeof o=="number"?o:null}}return null}moveToXAndYValue(n,i){if(!this.isViolin()||typeof n!="number")return!1;const o=Math.floor(n),s=this.values;if(this.orientation===An.VERTICAL){const f=s.length>0?s[0].length:0;if(o<0||o>=f)return!1;this.col=o;let d=1,h=1/0;for(let y=0;y<s.length;y++){const S=s[y];if(Array.isArray(S)&&o<S.length){const E=S[o];if(Array.isArray(E)){for(const T of E)if(typeof T=="number"){const w=Math.abs(T-i);w<h&&(h=w,d=y)}}else if(typeof E=="number"){const T=Math.abs(E-i);T<h&&(h=T,d=y)}}}return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}else{if(o<0||o>=s.length)return!1;this.row=o;let f=1,d=1/0;const h=s[o];if(Array.isArray(h))for(let y=0;y<h.length;y++){const S=h[y];if(Array.isArray(S)){for(const E of S)if(typeof E=="number"){const T=Math.abs(E-i);T<d&&(d=T,f=y)}}else if(typeof S=="number"){const E=Math.abs(S-i);E<d&&(d=E,f=y)}}return this.col=f,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}}onSwitchFrom(n){var d;if(!this.isViolin())return!1;const i=n;if(!((i.type||((d=i.state)==null?void 0:d.traceType))==="smooth"))return!1;const f=n.getCurrentXValue();if(n.getCurrentYValue){const h=n.getCurrentYValue();if(h!==null&&f!==null&&this.moveToXAndYValue){const y=this.moveToXAndYValue(f,h);return y&&(this.isInitialEntry=!1),y}}if(f!==null){const h=this.moveToXValue(f);return h&&(this.isInitialEntry=!1),h}return!1}}const NB="trend",fA=100,zB=["volatility","open","high","low","close"];class LB extends Pl{constructor(n){super(n);q(this,"supportsExtrema",!0);q(this,"movable");q(this,"candles");q(this,"candleValues");q(this,"orientation");q(this,"currentSegmentType","open");q(this,"currentPointIndex",0);q(this,"sortedSegmentsByPoint");q(this,"segmentPositionMaps");q(this,"sections");q(this,"min");q(this,"max");q(this,"highlightValues");q(this,"highlightCenters");q(this,"navigationService");this.navigationService=new S7;const i=n.data;this.candles=i.map(s=>({...s,volatility:Math.round((s.high-s.low)*fA)/fA,trend:s.close>s.open?"Bull":s.close<s.open?"Bear":"Neutral"})),this.orientation=n.orientation??An.VERTICAL,this.sections=zB,this.candleValues=this.sections.map(s=>this.candles.map(f=>f[s]));const o=this.orientation===An.HORIZONTAL?{col:this.sections.length-1}:{row:this.sections.length-1};this.movable=new Im(this.candleValues,o),this.min=Na.minFrom2D(this.candleValues),this.max=Na.maxFrom2D(this.candleValues),this.sortedSegmentsByPoint=this.precomputeSortedSegments(),this.segmentPositionMaps=this.precomputePositionMaps(),this.currentPointIndex=0,this.currentSegmentType="close",this.orientation===An.HORIZONTAL?this.col=0:this.row=0,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters()}precomputeSortedSegments(){return this.candles.map(n=>["volatility",...["low","open","close","high"].map(s=>[s,n[s]]).sort((s,f)=>s[1]-f[1]).map(s=>s[0])])}precomputePositionMaps(){return this.sortedSegmentsByPoint.map(n=>{const i=new Map;return n.forEach((o,s)=>{i.set(o,s)}),i})}getSegmentPositionInSortedOrder(n,i){return this.segmentPositionMaps[n].get(i)??0}getSegmentTypeAtSortedPosition(n,i){return this.sortedSegmentsByPoint[n][i]??"open"}updateVisualSegmentPosition(){const i=this.sortedSegmentsByPoint[this.currentPointIndex].indexOf(this.currentSegmentType??"open");this.orientation===An.HORIZONTAL?this.col=i:this.row=i}updateVisualPointPosition(){this.orientation===An.HORIZONTAL?this.row=this.currentPointIndex:this.col=this.currentPointIndex,this.updateVisualSegmentPosition()}handleInitialEntry(){this.isInitialEntry=!1,this.currentPointIndex=Math.max(0,Math.min(this.currentPointIndex,this.candles.length-1)),this.currentSegmentType="close",this.updateVisualSegmentPosition()}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open");if(o===-1)return this.notifyOutOfBounds(),!1;const s=n==="UPWARD"?o+1:o-1;if(s>=0&&s<i.length)this.currentSegmentType=i[s],this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;if(i>=0&&i<this.candles.length)this.currentPointIndex=i,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();else return this.notifyOutOfBounds(),!1;break}}return this.notifyStateUpdate(),!0}moveToExtreme(n){switch(this.isInitialEntry&&this.handleInitialEntry(),n){case"UPWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[i.length-1],this.updateVisualSegmentPosition();break}case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex];this.currentSegmentType=i[0],this.updateVisualSegmentPosition();break}case"FORWARD":{this.currentPointIndex=this.candles.length-1,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}case"BACKWARD":{this.currentPointIndex=0,this.updateVisualPointPosition(),this.updateVisualSegmentPosition();break}}return this.notifyStateUpdate(),!0}moveToIndex(n,i){this.isInitialEntry&&this.handleInitialEntry();const{pointIndex:o,segmentType:s}=this.navigationService.computeIndexAndSegment(n,i,this.orientation,this.sections);return this.currentPointIndex=o,this.currentSegmentType=s,this.row=n,this.col=i,this.updateVisualSegmentPosition(),this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}isMovable(n){if(Array.isArray(n))return super.isMovable(n);if(this.isInitialEntry)return!0;switch(n){case"UPWARD":case"DOWNWARD":{const i=this.sortedSegmentsByPoint[this.currentPointIndex],o=i.indexOf(this.currentSegmentType??"open"),s=n==="UPWARD"?o+1:o-1;return s>=0&&s<i.length}case"FORWARD":case"BACKWARD":{const i=n==="FORWARD"?this.currentPointIndex+1:this.currentPointIndex-1;return i>=0&&i<this.candles.length}}}dispose(){this.navigationService.dispose(),this.candles.length=0,super.dispose()}get values(){return this.candleValues}get audio(){let n;const i=this.orientation===An.HORIZONTAL;return this.currentSegmentType==="volatility"?n=this.candles[this.currentPointIndex].volatility:this.currentSegmentType?n=this.candles[this.currentPointIndex][this.currentSegmentType]:n=this.candles[this.currentPointIndex].open,{freq:{min:this.min,max:this.max,raw:n},panning:{x:i?this.row:this.col,y:i?this.col:this.row,rows:i?this.candleValues.length:this.candleValues[this.row].length,cols:i?this.candleValues[this.row].length:this.candleValues.length},trend:this.candles[this.currentPointIndex].trend}}get braille(){const n=this.candles.map(f=>f.trend),i=this.getSegmentPositionInSortedOrder(this.currentPointIndex,this.currentSegmentType??this.sections[0]);this.row=i;const o=this.candleValues.map(f=>Math.min(...f)),s=this.candleValues.map(f=>Math.max(...f));return{empty:!1,id:this.id,values:this.candleValues,min:o,max:s,row:this.row,col:this.col,custom:n}}collectElements(n){if(!n)return[];const i=Array.isArray(n)?n:[n],o=[];for(const s of i)o.push(...Ht.selectAllElements(s));return o}getElementAt(n,i){return i<n.length?n[i]:null}mapToSvgElements(n){if(!n)return null;if(typeof n=="string"||Array.isArray(n)){const C=Array.isArray(n)?n[0]||"":n,R=Ht.selectAllElements(C),D=[];for(let N=0;N<this.sections.length;N++){D[N]=[];for(let z=0;z<this.candles.length;z++){const B=z<R.length?z:0;D[N][z]=R[B]}}return D}const i=n,o=this.candles.length,s=this.collectElements(i.body);let f=this.collectElements(i.wickHigh),d=this.collectElements(i.wickLow);if(f.length===0||d.length===0){const C=this.collectElements(i.wick);C.length>0&&(f.length===0&&(f=C),d.length===0&&(d=C))}const h=this.collectElements(i.open),y=this.collectElements(i.close),S=Array.from({length:o},()=>Ht.createEmptyElement()),E=Array.from({length:o},()=>Ht.createEmptyElement()),T=Array.from({length:o},()=>Ht.createEmptyElement());for(let C=0;C<o;C++){let R=this.getElementAt(h,C);if(!R){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"bottom":B<z?"top":"bottom";R=Ht.createLineElement(N,V)}else R=Ht.createEmptyElement()}S[C]=R;let D=this.getElementAt(y,C);if(!D){const N=this.getElementAt(s,C);if(N){const{open:z,close:B}=this.candles[C],V=B>z?"top":B<z?"bottom":"top";D=Ht.createLineElement(N,V)}else D=Ht.createEmptyElement()}E[C]=D,T[C]=Ht.createEmptyElement()}const w=Array.from({length:this.sections.length},()=>Array.from({length:o},()=>Ht.createEmptyElement()));for(let C=0;C<o;C++){const R=this.sortedSegmentsByPoint[C];for(let D=0;D<R.length;D++){const N=R[D];let z;switch(N){case"volatility":{const B=[],V=this.getElementAt(s,C),L=this.getElementAt(f,C)??V,P=this.getElementAt(d,C)??V;L&&B.push(L),V&&B.push(V),P&&B.push(P);const X=Array.from(new Set(B));z=X.length>0?X:[Ht.createEmptyElement()]}break;case"open":z=S[C];break;case"close":z=E[C];break;case"high":z=this.getElementAt(f,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;case"low":z=this.getElementAt(d,C)??this.getElementAt(s,C)??Ht.createEmptyElement();break;default:z=Ht.createEmptyElement()}w[D][C]=z}}return w}get text(){const n=this.candles[this.currentPointIndex];let i;return this.currentSegmentType==="volatility"?i=n.volatility:this.currentSegmentType?i=n[this.currentSegmentType]:i=n.open,{main:{label:this.orientation===An.HORIZONTAL?this.yAxis:this.xAxis,value:n.value},cross:{label:this.orientation===An.HORIZONTAL?this.xAxis:this.yAxis,value:i},section:this.currentSegmentType??"open",fill:{label:NB,value:n.trend}}}getCurrentTrend(){return this.candles[this.currentPointIndex].trend}getCurrentXValue(){return this.currentPointIndex>=0&&this.currentPointIndex<this.candles.length?this.candles[this.currentPointIndex].value:null}moveToXValue(n){const i=this.candles.findIndex(o=>o.value===n);return i!==-1?(this.currentPointIndex=i,this.currentSegmentType="close",this.updateVisualPointPosition(),this.updateVisualSegmentPosition(),this.notifyStateUpdate(),!0):!1}getAvailableXValues(){return this.candles.map(n=>n.value)}getExtremaTargets(){const n=[],i=this.currentSegmentType??"open";if(i==="volatility"){const o=this.candles.map((y,S)=>({value:y.volatility,index:S})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,S)=>{const E=this.candles[y];n.push({label:`Max Volatility at ${E.value}`,value:E.volatility,pointIndex:y,segment:"volatility",type:"max",navigationType:"point"})}),h.forEach((y,S)=>{const E=this.candles[y];n.push({label:`Min Volatility at ${E.value}`,value:E.volatility,pointIndex:y,segment:"volatility",type:"min",navigationType:"point"})})}else{const o=this.candles.map((y,S)=>({value:y[i],index:S,xValue:y.value})),s=Math.max(...o.map(y=>y.value)),f=o.filter(y=>y.value===s).map(y=>y.index),d=Math.min(...o.map(y=>y.value)),h=o.filter(y=>y.value===d).map(y=>y.index);f.forEach((y,S)=>{const E=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Max ${T} at ${E.value}`,value:E[i],pointIndex:y,segment:i,type:"max",navigationType:"point"})}),h.forEach((y,S)=>{const E=this.candles[y],T=i.charAt(0).toUpperCase()+i.slice(1);n.push({label:`Min ${T} at ${E.value}`,value:E[i],pointIndex:y,segment:i,type:"min",navigationType:"point"})})}return n}navigateToExtrema(n){this.currentPointIndex=n.pointIndex,this.currentSegmentType=n.segment,this.finalizeExtremaNavigation()}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.candles.length)return!1;const s=this.currentSegmentType??"open",f=this.candles.map((S,E)=>({value:S[s],index:E,xValue:S.value})),d=this.col,h=n==="right"?1:-1;let y=d+h;for(;y>=0&&y<f.length;){if(this.compare(f[y].value,f[d].value,i))return this.col=y,this.currentPointIndex=y,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;y+=h}return this.notifyRotorBounds(),!1}moveUpRotor(){return this.moveOnce("UPWARD"),!0}moveDownRotor(){return this.moveOnce("DOWNWARD"),!0}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}get dimension(){const n=this.orientation===An.HORIZONTAL;return{rows:n?this.candleValues.length:this.candleValues[this.row].length,cols:n?this.candleValues[this.row].length:this.candleValues.length}}}class IB extends Pl{constructor(n){super(n);q(this,"supportsExtrema",!1);q(this,"movable");q(this,"heatmapValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"x");q(this,"y");q(this,"min");q(this,"max");const i=n.data;this.x=i.x,this.y=[...i.y].reverse(),this.heatmapValues=[...i.points].reverse();const{min:o,max:s}=Na.minMaxFrom2D(this.heatmapValues);this.min=o,this.max=s,this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new Im(this.heatmapValues)}get values(){return this.heatmapValues}dispose(){this.heatmapValues.length=0,this.x.length=0,this.y.length=0,super.dispose()}get audio(){return{freq:{min:this.min,max:this.max,raw:this.heatmapValues[this.row][this.col]},panning:{x:this.col,y:this.row,rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}}get braille(){return{empty:!1,id:this.id,values:this.heatmapValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){return{main:{label:this.xAxis,value:this.x[this.col]},cross:{label:this.yAxis,value:this.y[this.row]},fill:{label:this.fill,value:String(this.heatmapValues[this.row][this.col])}}}get dimension(){return{rows:this.heatmapValues.length,cols:this.heatmapValues[this.row].length}}mapToSvgElements(n){var d;if(!n)return null;const i=this.heatmapValues.length,o=this.heatmapValues[0].length,s=Ht.selectAllElements(n);if(s.length===0||s.length!==i*o)return null;const f=new Array;if(s[0]instanceof SVGPathElement)for(let h=0;h<i;h++){const y=i-1-h,S=new Array;for(let E=0;E<o;E++){const T=y*o+E;S.push(s[T])}f.push(S)}else if(s[0]instanceof SVGRectElement)if(((d=this.layer.domMapping)==null?void 0:d.order)==="row")for(let h=0;h<i;h++){const y=new Array;for(let S=0;S<o;S++){const E=h*o+S;y.push(s[E])}f.push(y)}else for(let h=0;h<i;h++){const y=new Array;for(let S=0;S<o;S++){const E=S*i+h;y.push(s[E])}f.push(y)}return f}updateVisualPointPosition(){const{row:n,col:i}=this.getSafeIndices();this.row=n,this.col=i}moveToNextCompareValue(n,i){switch(n){case"left":case"right":return this.search_in_row(n,i);case"up":case"down":return this.search_in_col(n,i);default:return this.notifyRotorBounds(),!1}}search_in_row(n,i){const o=this.y.length,s=this.col,f=n==="left"?-1:1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[this.row][d],this.heatmapValues[this.row][s],i))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}search_in_col(n,i){const o=this.x.length,s=this.row,f=n==="up"?1:-1;let d=s+f;for(;d>=0&&d<o;){if(this.compare(this.heatmapValues[d][this.col],this.heatmapValues[s][this.col],i))return this.row=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return!1}moveUpRotor(n){return this.moveToNextCompareValue("up",n)}moveDownRotor(n){return this.moveToNextCompareValue("down",n)}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}}class BB extends M7{constructor(t){super(t,[t.data])}get text(){const t=this.orientation===An.VERTICAL,n=this.points[this.row][this.col],i=t?n.xMin:n.yMin,o=t?n.xMax:n.yMax;return{...super.text,range:{min:i,max:o}}}moveToNextCompareValue(t,n){const i=this.row;if(i<0||i>=this.barValues.length)return!1;const o=this.barValues[i];if(!o||o.length===0)return!1;const s=this.col,f=t==="right"?1:-1;let d=s+f;for(;d>=0&&d<o.length;){if(this.compare(o[d],o[s],n))return this.col=d,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;d+=f}return this.notifyRotorBounds(),!1}}const dA="Group",R7=/[ML]\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)/g;class hA extends Pl{constructor(n){super(n);q(this,"supportsExtrema",!0);q(this,"rotorSupport",!0);q(this,"movable");q(this,"points");q(this,"lineValues");q(this,"highlightValues");q(this,"highlightCenters");q(this,"min");q(this,"max");q(this,"previousRow",null);this.points=n.data,this.lineValues=this.points.map(i=>i.map(o=>Number(o.y))),this.min=this.lineValues.map(i=>Na.safeMin(i)),this.max=this.lineValues.map(i=>Na.safeMax(i)),this.highlightValues=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new RB(this.buildGraph())}get values(){return this.lineValues}dispose(){this.points.length=0,this.min.length=0,this.max.length=0,super.dispose()}buildGraph(){const n=this.points.length;if(n===0)return new Array;const i=Math.max(0,...this.points.map(s=>s.length)),o=this.points.map(s=>s.map(()=>({up:null,down:null,left:null,right:null,top:null,bottom:null,start:null,end:null})));for(let s=0;s<i;s++){const f=this.points.map((S,E)=>{var T;return{y:(T=S[s])==null?void 0:T.y,row:E}}).filter(S=>S.y!==void 0);if(f.length===0)continue;const d=[...f].sort((S,E)=>S.y-E.y),h={row:d[0].row,col:s},y={row:d[d.length-1].row,col:s};for(let S=0;S<d.length;S++){const{row:E}=d[S],T=o[E][s];T&&(S>0&&(T.down={row:d[S-1].row,col:s}),S<d.length-1&&(T.up={row:d[S+1].row,col:s}),T.bottom=h,T.top=y)}}for(let s=0;s<n;s++){const f=this.points[s].length>0?{row:s,col:0}:null,d=this.points[s].length>0?{row:s,col:this.points[s].length-1}:null;for(let h=0;h<this.points[s].length;h++){const y=o[s][h];y&&(h>0&&(y.left={row:s,col:h-1}),h<this.points[s].length-1&&(y.right={row:s,col:h+1}),y.start=f,y.end=d)}}return o}get audio(){return{freq:{min:this.min[this.row],max:this.max[this.row],raw:this.lineValues[this.row][this.col]},panning:{x:this.row,y:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:this.row}}get braille(){return{empty:!1,id:this.id,values:this.lineValues,min:this.min,max:this.max,row:this.row,col:this.col}}get text(){var s;const n=this.points[this.row][this.col],i=this.findIntersections();let o={};if(i.length>1){let f=i.map(d=>{var y;const h=d.group;return((y=this.points[h][0])==null?void 0:y.fill)||`l${h+1}`});if(this.previousRow!==null){const d=((s=this.points[this.previousRow][0])==null?void 0:s.fill)||`l${this.previousRow+1}`;f.includes(d)&&(f=[d,...f.filter(h=>h!==d)])}o={fill:{label:dA,value:`intersection at (${f.join(", ")})`}}}else o=n.fill?{fill:{label:dA,value:n.fill}}:{};return{main:{label:this.xAxis,value:this.points[this.row][this.col].x},cross:{label:this.yAxis,value:this.points[this.row][this.col].y},...o}}get dimension(){return{rows:this.lineValues.length,cols:this.lineValues[this.row].length}}moveOnce(n){if(this.isInitialEntry)return this.movable.handleInitialEntry(),this.previousRow=null,this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.previousRow=this.row,n==="UPWARD"||n==="DOWNWARD"){const o=this.findLineByXAndYDirection(n),s=this.points[this.row][this.col].x;if(o!==null&&o!==this.row){const f=this.findColumnByXValue(o,s);if(f!==-1){this.row=o,this.col=f;const d=this.findIntersections();if(d.length>1){const y={...super.state,intersections:d};for(const S of this.observers)S.update(y)}else this.notifyStateUpdate();return!0}else return this.notifyOutOfBounds(),!1}else return this.notifyOutOfBounds(),!1}switch(n){case"FORWARD":this.col+=1;break;case"BACKWARD":this.col-=1;break}const i=this.findIntersections();if(i.length>1){const s={...super.state,intersections:i};for(const f of this.observers)f.update(s)}else this.notifyStateUpdate();return!0}findIntersections(){const n=this.points[this.row][this.col].x,i=this.points[this.row][this.col].y,o=[];for(let s=0;s<this.points.length;s++){const f=this.points[s].findIndex(d=>d.x===n&&d.y===i);f!==-1&&o.push({freq:{min:this.min[s],max:this.max[f],raw:i},panning:{x:this.row,y:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},group:s})}return o}isMovable(n){if(Array.isArray(n)){const[i,o]=n;return i>=0&&i<this.values.length&&o>=0&&o<this.values[i].length}switch(n){case"UPWARD":case"DOWNWARD":{const i=this.findLineByXAndYDirection(n);if(i===null)return!1;const o=this.points[this.row][this.col].x;return this.findColumnByXValue(i,o)!==-1}case"FORWARD":return this.col<this.values[this.row].length-1;case"BACKWARD":return this.col>0}}findLineByXAndYDirection(n){const i=this.points[this.row][this.col].x;let o=null,s=Number.POSITIVE_INFINITY;for(let f=0;f<this.points.length;f++){if(f===this.row)continue;const d=this.points[f].findIndex(E=>E.x===i);if(d===-1)continue;const h=this.points[f][d].y,y=n==="UPWARD"?h>this.points[this.row][this.col].y:h<this.points[this.row][this.col].y,S=Math.abs(h-this.points[this.row][this.col].y);y&&S<s&&(s=S,o=f)}return o}findColumnByXValue(n,i){return this.points[n].findIndex(o=>o.x===i)}mapToSvgElements(n){if(!n||n.length!==this.lineValues.length)return null;const i=[];let o=!0;for(let s=0;s<n.length;s++){const f=Ht.selectElement(n[s],!1);if(!f){i.push([]);continue}const d=[];if(f instanceof SVGPathElement){const S=f.getAttribute(ge.D)||ge.EMPTY;R7.lastIndex=0;let E=R7.exec(S);for(;E!==null;)d.push({x:Number.parseFloat(E[1]),y:Number.parseFloat(E[2])}),E=R7.exec(S)}else if(f instanceof SVGPolylineElement){const E=(f.getAttribute(ge.POINTS)||ge.EMPTY).split(/\s+/).filter(Boolean);for(const T of E){const[w,C]=T.split(ge.COMMA);d.push({x:Number.parseFloat(w),y:Number.parseFloat(C)})}}if(d.length!==this.lineValues[s].length)if(d.length<this.lineValues[s].length)for(;d.length<this.lineValues[s].length;)d.push({x:Number.NaN,y:Number.NaN});else d.length>this.lineValues[s].length&&(d.length=this.lineValues[s].length);const h=[];let y=!1;for(const S of d){if(Number.isNaN(S.x)||Number.isNaN(S.y)){y=!0;break}h.push(Ht.createCircleElement(S.x,S.y,f))}if(y){i.push([]);continue}h.length>0&&(o=!1),i.push(h)}return o?null:i}get state(){const n=super.state;if(n.empty)return n;const i=this.points.length>1,o={...n,plotType:i?"multiline":"single line",...i&&{groupCount:this.points.length}},s=this.findIntersections();return s.length>1?{...o,intersections:s}:o}mapSvgElementsToCenters(){const n=this.highlightValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}getExtremaTargets(){const n=[],i=this.row;if(i<0||i>=this.lineValues.length)return n;const o=this.lineValues[i];if(!o||o.length===0)return n;const s=this.min[i],f=this.max[i],d=[],h=[];for(let y=0;y<o.length;y++){const S=o[y];S===f&&d.push(y),S===s&&h.push(y)}for(const y of d)n.push({label:`Max point at ${this.getPointLabel(y)}`,value:f,pointIndex:y,segment:"line",type:"max",navigationType:"point"});for(const y of h)n.push({label:`Min point at ${this.getPointLabel(y)}`,value:s,pointIndex:y,segment:"line",type:"min",navigationType:"point"});return n}navigateToExtrema(n){this.col=n.pointIndex,this.finalizeExtremaNavigation()}getPointLabel(n){return this.points[this.row]&&this.points[this.row][n]?`${this.points[this.row][n].x}`:`Point ${n}`}updateVisualPointPosition(){const{row:n,col:i}=this.getSafeIndices();this.row=n,this.col=i}getAvailableXValues(){return this.points[this.row].map(n=>n.x)}moveToXValue(n){return this.isInitialEntry&&this.movable.handleInitialEntry(),super.moveToXValue(n)}moveToNextCompareValue(n,i){const o=this.row;if(o<0||o>=this.lineValues.length)return!1;const s=this.lineValues[o];if(!s||s.length===0)return!1;const f=this.col,d=n==="right"?1:-1;let h=f+d;for(;h>=0&&h<s.length;){if(this.compare(s[h],s[f],i))return this.col=h,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;h+=d}return this.notifyRotorBounds(),!1}compare(n,i,o){return o==="lower"?n<i:o==="higher"?n>i:!1}moveUpRotor(n){return this.moveOnce("UPWARD"),!0}moveDownRotor(n){return this.moveOnce("DOWNWARD"),!0}}class VB extends Pl{constructor(n){super(n);q(this,"mode");q(this,"movable");q(this,"supportsExtrema",!1);q(this,"xPoints");q(this,"yPoints");q(this,"xValues");q(this,"yValues");q(this,"highlightXValues");q(this,"highlightYValues");q(this,"highlightCenters");q(this,"minX");q(this,"maxX");q(this,"minY");q(this,"maxY");this.mode="column";const i=n.data,o=[...i].sort((h,y)=>h.x-y.x||h.y-y.y);this.xPoints=new Array;let s=null;for(const h of o)(!s||s.x!==h.x)&&(s={x:h.x,y:[]},this.xPoints.push(s)),s.y.push(h.y);const f=[...i].sort((h,y)=>h.y-y.y||h.x-y.x);this.yPoints=new Array;let d=null;for(const h of f)(!d||d.y!==h.y)&&(d={y:h.y,x:[]},this.yPoints.push(d)),d.x.push(h.x);this.xValues=this.xPoints.map(h=>h.x),this.yValues=this.yPoints.map(h=>h.y),this.minX=Na.safeMin(this.xValues),this.maxX=Na.safeMax(this.xValues),this.minY=Na.safeMin(this.yValues),this.maxY=Na.safeMax(this.yValues),[this.highlightXValues,this.highlightYValues]=this.mapToSvgElements(n.selectors),this.highlightCenters=this.mapSvgElementsToCenters(),this.movable=new _B(this.xPoints,this.yPoints)}dispose(){this.movable.dispose(),this.xPoints.length=0,this.yPoints.length=0,this.highlightXValues&&(this.highlightXValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightXValues.length=0),this.highlightYValues&&(this.highlightYValues.forEach(n=>n.forEach(i=>i.remove())),this.highlightYValues.length=0),super.dispose()}get highlightValues(){return this.movable.mode==="col"?this.highlightXValues:this.highlightYValues}getAudioGroupIndex(){return{}}get values(){const n=[this.xValues,this.yValues];return this.mode==="column"?this.row!==0&&(this.row=0):(this.row<0||this.row>=this.yPoints.length)&&(this.row=0),n}get braille(){return{empty:!1,id:this.id,values:this.values,min:0,max:0,row:this.row,col:this.col}}get audio(){if(this.movable.mode==="col"){const n=this.xPoints[this.col];return{freq:{raw:n.y,min:this.minY,max:this.maxY},panning:{y:this.row,x:this.col,rows:n.y.length,cols:this.xPoints.length}}}else{const n=this.yPoints[this.row];return{freq:{raw:n.x,min:this.minX,max:this.maxX},panning:{y:this.row,x:this.col,rows:this.yPoints.length,cols:n.x.length}}}}get text(){if(this.movable.mode==="col"){const n=this.xPoints[this.col];return{main:{label:this.xAxis,value:n.x},cross:{label:this.yAxis,value:n.y}}}else{const n=this.yPoints[this.row];return{main:{label:this.yAxis,value:n.y},cross:{label:this.xAxis,value:n.x}}}}get dimension(){return{rows:this.yPoints.length,cols:this.xPoints.length}}get highlight(){if(this.highlightValues===null)return this.outOfBoundsState;const n=this.movable.mode==="col"?this.col<this.highlightValues.length?this.highlightValues[this.col]:null:this.row<this.highlightValues.length?this.highlightValues[this.row]:null;return n?{empty:!1,elements:n}:this.outOfBoundsState}get hasMultiPoints(){return!0}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0,this.mode="column"}toggleNavigation(){if(this.mode==="column"){const n=this.xPoints[this.col],i=n.y[Math.floor(n.y.length/2)],o=this.yValues.indexOf(i);o===-1||o>=this.yPoints.length?this.row=0:this.row=o,this.mode="row"}else{const n=this.yPoints[this.row],i=n.x[Math.floor(n.x.length/2)],o=this.xValues.indexOf(i);o===-1||o>=this.xPoints.length?this.col=0:this.col=o,this.mode="column",this.row=0}}moveOnce(n){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(n))return this.notifyOutOfBounds(),!1;if(this.mode==="column")switch(n){case"FORWARD":this.col++;break;case"BACKWARD":this.col--;break;case"UPWARD":case"DOWNWARD":{this.toggleNavigation();break}}else switch(n){case"UPWARD":this.row++;break;case"DOWNWARD":this.row--;break;case"FORWARD":case"BACKWARD":{this.toggleNavigation();break}}return this.notifyStateUpdate(),!0}moveToExtreme(n){if(this.isInitialEntry&&this.handleInitialEntry(),this.mode==="column")switch(n){case"UPWARD":this.toggleNavigation(),this.row=this.yPoints.length-1;break;case"DOWNWARD":this.toggleNavigation(),this.row=0;break;case"FORWARD":this.col=this.xPoints.length-1;break;case"BACKWARD":this.col=0;break}else switch(n){case"UPWARD":this.row=this.yPoints.length-1;break;case"DOWNWARD":this.row=0;break;case"FORWARD":this.toggleNavigation(),this.col=this.xPoints.length-1;break;case"BACKWARD":this.toggleNavigation(),this.col=0;break}return this.notifyStateUpdate(),!0}moveToIndex(n,i){return this.mode==="column"?n>=0&&n<this.xPoints.length?(this.col=n,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):i>=0&&i<this.yPoints.length?(this.col=i,this.row=0,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}isMovable(n){if(Array.isArray(n))return!1;if(this.mode==="column")switch(n){case"FORWARD":return this.col<this.xPoints.length-1;case"BACKWARD":return this.col>0;case"UPWARD":case"DOWNWARD":return!0}else switch(n){case"UPWARD":return this.row<this.yPoints.length-1;case"DOWNWARD":return this.row>0;case"FORWARD":case"BACKWARD":return!0}}mapToSvgElements(n){if(!n)return[null,null];const i=Ht.selectAllElements(n);if(i.length===0)return[null,null];const o=new Map,s=new Map;i.forEach(h=>{const y=Number.parseFloat(h.getAttribute("x")||""),S=Number.parseFloat(h.getAttribute("y")||"");Number.isNaN(y)||(o.has(y)||o.set(y,[]),o.get(y).push(h)),Number.isNaN(S)||(s.has(S)||s.set(S,[]),s.get(S).push(h))});const f=Array.from(o.entries()).sort(([h],[y])=>h-y).map(([h,y])=>y),d=Array.from(s.entries()).sort(([h],[y])=>y-h).map(([h,y])=>y);return[f,d]}mapSvgElementsToCenters(){const n=this.highlightXValues;if(!n)return null;const i=[];for(let o=0;o<n.length;o++)for(let s=0;s<n[o].length;s++){const f=n[o][s],d=Array.isArray(f)?f[0]:f;if(d){const h=d.getBoundingClientRect();i.push({x:h.x+h.width/2,y:h.y+h.height/2,row:o,col:s,element:d})}}return i}findNearestPoint(n,i){if(!this.highlightCenters)return null;let o=1/0,s=-1;for(let f=0;f<this.highlightCenters.length;f++){const d=this.highlightCenters[f],h=Math.hypot(d.x-n,d.y-i);h<o&&(o=h,s=f)}return s===-1?null:{element:this.highlightCenters[s].element,row:this.highlightCenters[s].row,col:this.highlightCenters[s].col}}moveToPoint(n,i){this.mode="column";const o=this.findNearestPoint(n,i);if(o&&this.isPointInBounds(n,i,o)){if(this.row===o.row&&this.col===o.col)return;this.moveToIndex(o.row,o.col)}}}const pA="Sum",UB="Level",PB="undefined";class jB extends M7{constructor(t){super(t,t.data),this.createSummaryLevel()}createSummaryLevel(){const t=new Array,n=new Array;for(let s=0;s<this.barValues[0].length;s++){const f=this.barValues.reduce((h,y)=>h+y[s],0);t.push(f);const d=this.orientation===An.VERTICAL?{x:this.points[0][s].x,y:f,fill:pA}:{x:f,y:this.points[0][s].y,fill:pA};n.push(d)}this.points.push(n),this.barValues.push(t);const{min:i,max:o}=Na.minMax(t);this.min.push(i),this.max.push(o)}getExtremaTargets(){const t=[],n=this.row;if(n<0||n>=this.barValues.length)return t;const i=this.min[n],o=this.max[n],s=this.barValues[n];if(!s||s.length===0)return t;const f=s.indexOf(o),d=s.indexOf(i),h=this.getGroupLabel(n),y=this.getCategoryLabel(f),S=this.getCategoryLabel(d);return t.push({label:`Max ${h} at ${y}`,value:o,pointIndex:f,segment:h,type:"max",groupIndex:n,categoryIndex:f,navigationType:"group"}),t.push({label:`Min ${h} at ${S}`,value:i,pointIndex:d,segment:h,type:"min",groupIndex:n,categoryIndex:d,navigationType:"group"}),t}navigateToExtrema(t){t.groupIndex!==void 0&&t.categoryIndex!==void 0?(this.row=t.groupIndex,this.col=t.categoryIndex):this.col=t.pointIndex,this.finalizeExtremaNavigation()}getGroupLabel(t){if(this.points[t]&&this.points[t].length>0){const n=this.points[t][0];if(t===this.barValues.length-1)return"Total";if(n.fill)return`${this.getFillAxisLabel()}: '${n.fill}'`}return`Group ${t}`}getCategoryLabel(t){if(this.points[0]&&this.points[0][t]){const n=this.points[0][t];return this.orientation===An.VERTICAL?`${n.x}`:`${n.y}`}return`Category ${t}`}getFillAxisLabel(){return"Category"}updateVisualPointPosition(){const{row:t,col:n}=this.getSafeIndices();this.row=t,this.col=n}get text(){return{...super.text,fill:{label:UB,value:this.points[this.row][this.col].fill??PB}}}get highlight(){return this.highlightValues===null||this.row===this.barValues.length-1?this.outOfBoundsState:{empty:!1,elements:this.highlightValues[this.row][this.col]}}mapToSvgElements(t){var o;if(!t)return new Array;const n=Ht.selectAllElements(t);if(n.length===0)return new Array;const i=new Array;if(n[0]instanceof SVGPathElement)for(let s=0,f=0;s<this.barValues.length;s++){const d=new Array;for(let h=0;h<this.barValues[s].length;h++){if(f>=n.length)return new Array;this.barValues[s][h]===0?d.push(Ht.createEmptyElement()):d.push(n[f++])}i.push(d)}else if(n[0]instanceof SVGRectElement){for(let f=0;f<this.barValues.length;f++)i.push(new Array);const s=((o=this.layer.domMapping)==null?void 0:o.groupDirection)==="forward";for(let f=0,d=0;f<this.barValues[0].length;f++)if(s)for(let h=0;h<this.barValues.length;h++){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}else for(let h=this.barValues.length-1;h>=0;h--){if(d>=n.length)return new Array;this.barValues[h][f]===0?i[h].push(Ht.createEmptyElement()):i[h].push(n[d++])}}return i}}class _7 extends hA{constructor(t){super(t)}get state(){const t=super.state;return t.empty?t:{...t,plotType:"smooth"}}get audio(){const t=this.lineValues[this.row],n=f=>t[Math.max(0,Math.min(f,t.length-1))],i=n(this.col-1),o=n(this.col),s=n(this.col+1);return{freq:{min:this.min[this.row],max:this.max[this.row],raw:[i,o,s]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0}}}class $B extends _7{constructor(t){super(t)}mapToSvgElements(t){var o;if(!t||t.length!==this.lineValues.length)return null;const n=[];let i=!0;for(let s=0;s<t.length;s++){const f=Ht.selectElement(t[s],!1);if(!f){n.push([]);continue}const d=(o=this.points)==null?void 0:o[s],h=[];for(const y of d)typeof y.svg_x=="number"&&typeof y.svg_y=="number"&&h.push(Ht.createCircleElement(y.svg_x,y.svg_y,f));h.length>0&&(i=!1),n.push(h)}return i?null:n}}const D7=.001;class HB extends _7{constructor(t){super(t)}isMovable(t){var n;if(Array.isArray(t)){const[i,o]=t;return i>=0&&i<this.points.length&&o>=0&&o<(((n=this.points[i])==null?void 0:n.length)||0)}switch(t){case"FORWARD":return this.row<this.points.length-1;case"BACKWARD":return this.row>0;case"UPWARD":return this.col<this.points[this.row].length-1;case"DOWNWARD":return this.col>0}}handleInitialEntry(){this.isInitialEntry=!1,this.row=0,this.col=0}moveOnce(t){if(this.isInitialEntry)return this.handleInitialEntry(),this.notifyStateUpdate(),!0;if(!this.isMovable(t))return this.notifyOutOfBounds(),!1;switch(t){case"FORWARD":if(this.row<this.points.length-1){const n=this.row+1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"BACKWARD":if(this.row>0){const n=this.row-1;return this.row=n,this.col=0,this.notifyStateUpdate(),!0}return this.notifyOutOfBounds(),!1;case"UPWARD":case"DOWNWARD":return t==="UPWARD"?this.col<this.points[this.row].length-1?(this.col+=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1):this.col>0?(this.col-=1,this.notifyStateUpdate(),!0):(this.notifyOutOfBounds(),!1)}}mapToSvgElements(t){if(!t||t.length===0)return null;const n=[];let i=!0;const o=t.length===this.points.length;for(let s=0;s<this.points.length;s++){const f=[],d=this.points[s];let h;if(o?h=t[s]:h=t[0],!h){n.push([]);continue}const y=Ht.selectAllElements(h,!1);let S=null;if(y.length>0){const E=y.filter(C=>C instanceof SVGUseElement),T=y.filter(C=>C instanceof SVGPathElement),w=E.length>0?E:T;w.length>0&&(S=w[o?0:s<w.length?s:0])}if(S&&d){for(const E of d){let T,w;const C=E;if(typeof C.svg_x=="number"&&typeof C.svg_y=="number")T=C.svg_x,w=C.svg_y;else if(typeof E.x=="number"&&typeof E.y=="number")T=E.x,w=E.y;else continue;!Number.isNaN(T)&&!Number.isNaN(w)&&f.push(Ht.createCircleElement(T,w,S))}f.length>0&&(i=!1)}n.push(f)}return i?null:n}get text(){const t=this.points[this.row][this.col],n=t.x,i=Number(t.y),o=this.points[this.row],s=t;let f;if(typeof s.width=="number"&&!Number.isNaN(s.width))f=s.width;else{const w=typeof s.svg_y=="number"?s.svg_y:null,C=[];for(const R of o){const D=R,N=Number(R.y),z=typeof D.svg_y=="number"?D.svg_y:null;let B=!1;w!==null&&z!==null?B=Math.abs(z-w)<=1:B=Math.abs(N-i)<=.01,B&&typeof D.svg_x=="number"&&!Number.isNaN(D.svg_x)&&C.push(D.svg_x)}if(C.length>=2){const R=Math.min(...C),D=Math.max(...C);f=Math.abs(D-R)}}const d=T=>Math.round(T*1e4)/1e4,h=d(i),y=f!==void 0&&f>0?d(f):void 0;let S;if(typeof n=="string")S=n;else{const T=o[0];T&&typeof T.x=="string"?S=T.x:S=`Category ${this.row}`}const E={main:{label:this.xAxis,value:S},cross:{label:this.yAxis,value:h}};return y!==void 0&&(E.fill={label:"volume",value:String(y)}),E}get audio(){const n=this.points[0];if(!n||n.length===0)return super.audio;const i=n.map(z=>z.density??z.width??0),o=i.filter(z=>z>0);if(o.length===0)return super.audio;const s=Math.min(...o),f=i.length>0?Math.max(...i):0,d=s===f?Math.max(0,s-D7):s,h=s===f?f+D7:f,y=Math.min(this.col,i.length-1),S=z=>i[Math.max(0,Math.min(z,i.length-1))],E=y>0?S(y-1):S(y),T=S(y),w=y<i.length-1?S(y+1):S(y),C=this.points[this.row],R=C?Math.min(this.col,C.length-1):0,D=C==null?void 0:C[R];let N=1;if(D){const z=D.density??D.width??0,B=C.map(X=>X.density??X.width??0),V=B.filter(X=>X>0),L=V.length>0?Math.min(...V):0,P=B.length>0?Math.max(...B):0;if(P>0&&typeof z=="number"&&z>0){const X=L===P?P+D7:P;N=z/X}}return{freq:{min:d,max:h,raw:[E,T,w]},panning:{y:this.row,x:this.col,rows:this.lineValues.length,cols:this.lineValues[this.row].length},isContinuous:!0,volumeScale:N}}getCurrentXValue(){return this.row>=0&&this.row<this.points.length?this.row:null}moveToXValue(t){var s;this.isInitialEntry&&this.handleInitialEntry();const n=this.points;if(!n||!n.length)return!1;const i=Math.floor(t);if(i<0||i>=n.length)return!1;const o=this.row;if(this.row=i,i!==o)this.col=0;else{const f=(s=n[i])!=null&&s.length?n[i].length-1:0;this.col=Math.min(this.col,f)}return this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}getCurrentYValue(){const t=this.lineValues[this.row];if(!t||t.length===0)return null;if(this.col>=0&&this.col<t.length){const n=t[this.col];return typeof n=="number"?n:null}return null}moveToXAndYValue(t,n){if(typeof t!="number")return!1;const i=Math.floor(t);if(i<0||i>=this.lineValues.length)return!1;this.row=i;const o=this.lineValues[this.row];if(!o||o.length===0)return this.col=0,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0;let s=0,f=Math.abs(o[0]-n);for(let d=1;d<o.length;d++){const h=Math.abs(o[d]-n);h<f&&(f=h,s=d)}return this.col=s,this.updateVisualPointPosition(),this.notifyStateUpdate(),!0}onSwitchFrom(t){var f;const n=t;if(!((n.type||((f=n.state)==null?void 0:f.traceType))==="box"))return!1;const s=t.getCurrentXValue();if(t.getCurrentYValue){const d=t.getCurrentYValue();if(d!==null&&s!==null&&this.moveToXAndYValue){const h=this.moveToXAndYValue(s,d);return h&&(this.isInitialEntry=!1),h}}if(s!==null){const d=this.moveToXValue(s);return d&&(this.isInitialEntry=!1),d}return!1}}function qB(e){return typeof(e==null?void 0:e.svg_x)=="number"&&typeof(e==null?void 0:e.svg_y)=="number"}function GB(e,t=!1){return t&&e.type===ar.SMOOTH?new HB(e):Array.isArray(e.data)&&e.data.length>0&&Array.isArray(e.data[0])&&qB(e.data[0][0])?new $B(e):new _7(e)}class FB{static create(t,n){const i=(n==null?void 0:n.isViolinPlot)===!0;switch(t.type){case ar.BAR:return new DB(t);case ar.BOX:return new kB(t,i);case ar.CANDLESTICK:return new LB(t);case ar.HEATMAP:return new IB(t);case ar.HISTOGRAM:return new BB(t);case ar.LINE:return new hA(t);case ar.SCATTER:return new VB(t);case ar.SMOOTH:return GB(t,i);case ar.DODGED:case ar.NORMALIZED:case ar.STACKED:return new jB(t);default:throw new Error(`Invalid trace type: ${t.type}`)}}}const YB="MAIDR Plot",XB="unavailable",WB="unavailable";class QB extends C7{constructor(n){super();q(this,"id");q(this,"movable");q(this,"title");q(this,"subtitle");q(this,"caption");q(this,"subplots");q(this,"size");this.id=n.id,this.title=n.title??YB,this.subtitle=n.subtitle??XB,this.caption=n.caption??WB;const i=n.subplots;this.subplots=i.map(o=>o.map(s=>new KB(s))),this.size=this.subplots.reduce((o,s)=>o+s.length,0),this.movable=new Im(this.subplots,{row:this.subplots.length-1})}get dimension(){return{rows:this.subplots.length,cols:this.subplots[this.row].length}}dispose(){this.subplots.forEach(n=>n.forEach(i=>i.dispose())),this.subplots.length=0,super.dispose()}get values(){return this.subplots}get activeSubplot(){return this.subplots[this.row][this.col]}get state(){if(this.isOutOfBounds)return{empty:!0,type:"figure"};const n=this.col+1+this.subplots.slice(0,this.row).reduce((o,s)=>o+s.length,0),i=this.activeSubplot;return{empty:!1,type:"figure",title:this.title,subtitle:this.subtitle,caption:this.caption,size:this.size,index:n,subplot:i.getStateWithFigurePosition(this.row,this.col),traceTypes:i.traceTypes,highlight:this.highlight}}get highlight(){var i;if(document.querySelectorAll('g[id^="axes_"]').length<=1)return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}};try{const o=((i=this.subplots[0])==null?void 0:i.length)||1,s=this.row*o+this.col+1,f=`g[id="axes_${s}"]`,d=document.querySelector(f);if(d)return{empty:!1,elements:d};const h=document.querySelectorAll('g[id^="axes_"]');if(h.length>0&&s-1<h.length)return{empty:!1,elements:h[s-1]}}catch{return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}return{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.subplots.length,cols:this.subplots[this.row].length}}}moveToPoint(n,i){this.notifyStateUpdate()}get outOfBoundsState(){return{empty:!0,type:"figure"}}}class KB extends C7{constructor(n){super();q(this,"movable");q(this,"traces");q(this,"traceTypes");q(this,"size");q(this,"highlightValue");q(this,"isViolinPlot");const i=n.layers;this.size=i.length;const o=i.map(h=>h.type),s=o.includes(ar.BOX),f=o.includes(ar.SMOOTH),d=s&&f;this.isViolinPlot=d,this.traces=i.map(h=>[FB.create(h,{isViolinPlot:d})]),this.traceTypes=this.traces.flat().map(h=>{const y=h.state;return y.empty?ge.EMPTY:y.traceType}),this.highlightValue=this.mapToSvgElement(n.selector),this.movable=new Im(this.traces)}get dimension(){return{rows:this.values.length,cols:this.values[this.row].length}}dispose(){this.traces.forEach(n=>n.forEach(i=>i.dispose())),this.traces.length=0,super.dispose()}getRow(){return this.row}getSize(){return this.size}get values(){return this.traces}get activeTrace(){return this.traces[this.row][this.col]}moveOnce(n){return this.isViolinPlot?(this.isInitialEntry&&(this.isInitialEntry=!1),super.moveOnce(n)):super.moveOnce(n)}get state(){return{empty:!1,type:"subplot",size:this.size,index:this.row+1,trace:this.activeTrace.state,highlight:this.highlight}}get outOfBoundsState(){return{empty:!0,type:"subplot"}}get highlight(){return this.highlightValue===null?{empty:!0,type:"trace",audio:{y:this.row,x:this.col,rows:this.values.length,cols:this.values[this.row].length}}:{empty:!1,elements:this.highlightValue}}moveToPoint(n,i){this.notifyStateUpdate()}getStateWithFigurePosition(n,i){return this.state}mapToSvgElement(n){return n?Ht.selectElement(n)??null:null}}const ZB={SINE_BASIC:0},JB=100,eV=440,tV=880,mA=180,gA=.2,nV=.1,yA=.3,vA=ZB.SINE_BASIC;class rV{constructor(t,n,i){q(this,"notification");q(this,"isCombinedAudio");q(this,"mode");q(this,"activeAudioIds");q(this,"volume");q(this,"minFrequency");q(this,"maxFrequency");q(this,"audioContext");q(this,"compressor");this.notification=t,this.isCombinedAudio=!1,this.mode="on",this.updateMode(i),this.activeAudioIds=new Map,this.volume=this.normalizeVolume(n.get("general.volume")),this.minFrequency=n.get("general.minFrequency"),this.maxFrequency=n.get("general.maxFrequency"),n.onChange(o=>{o.affectsSetting("general.volume")&&(this.volume=this.normalizeVolume(o.get("general.volume"))),o.affectsSetting("general.minFrequency")&&(this.minFrequency=o.get("general.minFrequency")),o.affectsSetting("general.maxFrequency")&&(this.maxFrequency=o.get("general.maxFrequency"))}),this.audioContext=new AudioContext,this.compressor=this.initCompressor()}dispose(){this.stopAll(),this.audioContext.state!=="closed"&&(this.compressor.disconnect(),this.audioContext.close())}initCompressor(){const t=this.audioContext.createDynamicsCompressor();t.threshold.value=-50,t.knee.value=40,t.ratio.value=12,t.attack.value=0,t.release.value=.25;const n=this.audioContext.createGain();return n.gain.value=.5,t.connect(n),n.connect(this.audioContext.destination),t}updateMode(t){if(t.empty||t.type==="figure")return;const n=t.type==="subplot"?t.trace:t;n.empty||n.hasMultiPoints===this.isCombinedAudio||(this.isCombinedAudio=n.hasMultiPoints,this.mode!=="off"&&(this.isCombinedAudio?this.mode="combined":this.mode="on"))}update(t){if(this.updateMode(t),this.mode==="off")return;if(t.empty){t.warning?this.playWarningTone():this.playEmptyTone({x:0,y:0,rows:0,cols:0});return}if(t.type!=="trace")return;const n=t.audio;if(n.isContinuous)this.playSmooth(n.freq,n.panning,"sine",n.volumeMultiplier,n.volumeScale);else if(Array.isArray(n.freq.raw)){const i=n.freq.raw;if(i.length===0){this.playZeroTone(n.panning);return}let o=0;const s=this.mode==="on"?50:0,f=new Array,d=()=>{o<i.length?(this.playTone({min:n.freq.min,max:n.freq.max,raw:i[o++]},{x:n.panning.x,y:n.panning.y,rows:n.panning.rows,cols:n.panning.cols},n.group),f.push(setTimeout(d,s))):this.stop(f)};d()}else n.freq.raw===0?this.playZeroTone(n.panning):this.playTone(n.freq,n.panning,n.group)}playTone(t,n,i=0){const o={min:t.min,max:t.max},s={min:this.minFrequency,max:this.maxFrequency},f=this.interpolate(t.raw,o,s),d=this.clamp(this.interpolate(n.x,{min:0,max:n.cols},{min:-1,max:1}),-1,1),h=this.clamp(this.interpolate(n.y,{min:0,max:n.rows},{min:-1,max:1}),-1,1);return this.playOscillator(f,{x:d,y:h},i)}getHarmony(t){const n={type:"sine",gain:1,multiplier:1};if(t===0)return[n];const i=[{type:"triangle",gain:.8,multiplier:2},{type:"sine",gain:.6,multiplier:1.5},{type:"triangle",gain:.4,multiplier:3},{type:"sine",gain:.3,multiplier:4}],o=[n];let s=n.gain,f=t;for(let d=0;d<i.length&&f>0;d++)(f&1)===1&&(o.push(i[d]),s+=i[d].gain),f>>=1;for(const d of o)d.gain/=s;return o}playOscillator(t,n={x:0,y:0},i=0){const o=yA,s=this.audioContext.currentTime,f=[],d=this.audioContext.createGain(),h=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"linear",positionX:n.x,positionY:n.y,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});d.connect(h),h.connect(this.compressor);const y=[.5*this.volume,this.volume,.5*this.volume,.5*this.volume,.5*this.volume,.1*this.volume,1e-4*this.volume];d.gain.setValueCurveAtTime(y,s,o);const S=this.getHarmony(i);for(const w of S){const C=this.audioContext.createOscillator();C.type=w.type,C.frequency.value=t*w.multiplier;const R=this.audioContext.createGain();R.gain.value=w.gain,C.connect(R),R.connect(d),C.start(s),f.push(C)}const E=w=>{h.disconnect(),d.disconnect(),f.forEach(C=>{C.stop(),C.disconnect()}),this.activeAudioIds.delete(w)},T=setTimeout(()=>E(T),o*1e3*2);return this.activeAudioIds.set(T,f),this.activeAudioIds.set(T,f),T}playSmooth(t,n,i="sine",o,s){const f=this.audioContext,d=f.currentTime,h=yA,y=t.raw.map(B=>this.interpolate(B,{min:t.min,max:t.max},{min:this.minFrequency,max:this.maxFrequency})),S=this.volume;let E;s!==void 0?E=S*Math.max(0,s):E=S*(o??1),y.length<2&&y.push(y[0]);const T=this.clamp(this.interpolate(n.x,{min:0,max:n.cols-1},{min:-1,max:1}),-1,1),w=this.clamp(this.interpolate(n.y,{min:0,max:n.rows-1},{min:-1,max:1}),-1,1),C=f.createOscillator();C.type=i,C.frequency.setValueCurveAtTime(y,d,h);const R=f.createGain(),D=[1e-4*E,.5*E,1e-4*E];R.gain.setValueCurveAtTime(D,d,h);const N=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"linear",positionX:T,positionY:w,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1});C.connect(R),R.connect(N),N.connect(this.compressor),C.start(d),C.stop(d+h);const z=setTimeout(()=>{C.disconnect(),R.disconnect(),N.disconnect(),this.activeAudioIds.delete(z)},h*1e3*2);this.activeAudioIds.set(z,C)}playEmptyTone(t){const n=this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),i=this.interpolate(t.y,{min:0,max:t.rows-1},{min:-1,max:1}),o=this.audioContext,s=o.currentTime,f=.2,d=new PannerNode(this.audioContext,{panningModel:"HRTF",distanceModel:"inverse",positionX:n,positionY:i,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1}),h=[500,1e3,1500,2100,2700],y=[1,.6,.4,.2,.1],S=o.createGain();S.gain.setValueAtTime(.3*this.volume,s),S.gain.exponentialRampToValueAtTime(.01*this.volume,s+f),S.connect(d),d.connect(this.compressor);const E=[];for(let C=0;C<h.length;C++){const R=o.createOscillator(),D=o.createGain(),N=this.audioContext.createStereoPanner(),z=new PannerNode(this.audioContext,{distanceModel:"linear",positionX:0,positionY:0,positionZ:0,orientationX:0,orientationY:0,orientationZ:-1,refDistance:1,maxDistance:1e4,rolloffFactor:10,coneInnerAngle:40,coneOuterAngle:50,coneOuterGain:.4});R.frequency.value=h[C],R.type="sine",D.gain.setValueAtTime(y[C]*this.volume,s),D.gain.exponentialRampToValueAtTime(.001*this.volume,s+f),R.connect(D),D.connect(N),N.connect(z),z.connect(S),R.start(s),R.stop(s+f),E.push(R)}const T=C=>{d.disconnect(),S.disconnect(),E.forEach(R=>{R.disconnect()}),this.activeAudioIds.delete(C)},w=setTimeout(()=>T(w),f*1e3*2);return this.activeAudioIds.set(w,E),w}playOneWarningBeep(t,n){const i=this.audioContext.createOscillator(),o=this.audioContext.createGain();i.type="sine",i.frequency.value=t;let s=1;i.type!=="sine"&&(s=.5),o.gain.setValueAtTime(s,n),o.gain.exponentialRampToValueAtTime(.001,n+gA),i.connect(o),o.connect(this.audioContext.destination),i.start(n),i.stop(n+gA)}playWarningTone(){const t=this.audioContext.currentTime;this.playOneWarningBeep(mA,t),this.playOneWarningBeep(mA/2**(1/12),t+nV)}playZeroTone(t){const n=this.clamp(this.interpolate(t.x,{min:0,max:t.cols-1},{min:-1,max:1}),-1,1),i=this.clamp(this.interpolate(t.y,{min:0,max:t.rows-1},{min:-1,max:1}),-1,1);return this.playOscillator(JB,{x:n,y:i})}playWaitingTone(){return setInterval(()=>this.playOscillator(eV,{x:0,y:0},vA),1e3)}playCompleteTone(){return this.playOscillator(tV,{x:0,y:0},vA)}interpolate(t,n,i){return n.min===n.max?i.min:(t-n.min)/(n.max-n.min)*(i.max-i.min)+i.min}clamp(t,n,i){return Math.max(n,Math.min(t,i))}toggle(){switch(this.mode){case"off":this.mode=this.isCombinedAudio?"combined":"on";break;case"on":this.mode="off";break;case"combined":this.mode="on";break}const n=`Sound is ${this.isCombinedAudio&&this.mode==="on"?"separate":this.mode}`;this.notification.notify(n)}stop(t){(Array.isArray(t)?t:[t]).forEach(i=>{const o=this.activeAudioIds.get(i);if(!o){clearInterval(i);return}(Array.isArray(o)?o:[o]).forEach(f=>{f==null||f.disconnect(),f==null||f.stop()}),clearTimeout(i),this.activeAudioIds.delete(i)})}stopAll(){this.activeAudioIds.forEach((t,n)=>{clearTimeout(n),(Array.isArray(t)?t:[t]).forEach(o=>{o.disconnect(),o.stop()})}),this.activeAudioIds.clear()}normalizeVolume(t){return t/100*(t/100)}}const iV=250,aV=50,oV=500,bA=20;class lV{constructor(t,n,i){q(this,"context");q(this,"notification");q(this,"settings");q(this,"autoplayId");q(this,"currentDirection");q(this,"userSpeed");q(this,"defaultSpeed");q(this,"minSpeed");q(this,"maxSpeed");q(this,"autoplayRate");q(this,"interval");q(this,"totalDuration");q(this,"onChangeEmitter");q(this,"onChange");this.notification=n,this.context=t,this.settings=i,this.autoplayId=null,this.currentDirection=null,this.userSpeed=null,this.defaultSpeed=iV,this.minSpeed=aV,this.maxSpeed=oV,this.interval=bA,this.autoplayRate=this.defaultSpeed,this.interval=bA,this.totalDuration=i.get("general.autoplayDuration"),i.onChange(o=>{o.affectsSetting("general.autoplayDuration")&&(this.totalDuration=o.get("general.autoplayDuration"),this.restart())}),this.onChangeEmitter=new Ad,this.onChange=this.onChangeEmitter.event}dispose(){this.stop(),this.onChangeEmitter.dispose()}start(t,n){this.stop(),this.onChangeEmitter.fire({type:"start"}),this.autoplayRate=this.getAutoplayRate(t,n),this.currentDirection=t,this.autoplayId=setInterval(()=>{this.context.isMovable(t)?this.context.moveOnce(t):this.stop()},this.autoplayRate)}stop(){this.autoplayId&&clearInterval(this.autoplayId),this.autoplayId=null,this.currentDirection=null,this.onChangeEmitter.fire({type:"stop"})}restart(){this.autoplayId&&clearInterval(this.autoplayId),this.currentDirection&&this.start(this.currentDirection)}speedUp(){const t=this.userSpeed??this.autoplayRate;t-this.interval>this.minSpeed?(this.userSpeed=t-this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed up")):this.notification.notify("Max speed")}speedDown(){const t=this.userSpeed??this.autoplayRate;t+this.interval<=this.maxSpeed?(this.userSpeed=t+this.interval,this.autoplayRate=this.userSpeed,this.restart(),this.notification.notify("Speed down")):this.notification.notify("Min speed")}resetSpeed(){this.userSpeed=null,this.autoplayRate=this.defaultSpeed,this.restart(),this.notification.notify("Reset speed")}getAutoplayRate(t,n){if(this.userSpeed!==null)return this.userSpeed;if(n&&!n.empty){const i=Math.ceil(this.totalDuration/n.autoplay[t]);return this.defaultSpeed=i,this.minSpeed=Math.min(this.minSpeed,i),i}return this.defaultSpeed}}const SA=32;class cv{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const f=(t.max[s]-t.min[s])/4,d=t.min[s]+f,h=d+f,y=h+f;for(let S=0;S<t.values[s].length;S++)t.values[s][S]===0?n.push(" "):t.values[s][S]<=d||t.values[s][S]<=h?n.push("⠤"):t.values[s][S]<=y?n.push("⠒"):n.push("⠉"),i[s].push(o.length),o.push({row:s,col:S});n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class sV{constructor(){q(this,"GLOBAL_MIN","globalMin");q(this,"GLOBAL_MAX","globalMax");q(this,"BLANK","blank");q(this,"LOWER_OUTLIER","lowerOutlier");q(this,"UPPER_OUTLIER","upperOutlier");q(this,"MIN","min");q(this,"MAX","max");q(this,"Q1","q1");q(this,"Q2","q2");q(this,"Q3","q3")}encode(t,n=SA){const i=new Array,o=new Array,s=new Array;for(let f=0;f<t.values.length;f++){const d=t.values[f],h=[{type:this.GLOBAL_MIN,value:t.min},...d.lowerOutliers.map(X=>({type:this.LOWER_OUTLIER,value:X})),{type:this.MIN,value:d.min},{type:this.Q1,value:d.q1},{type:this.Q2,value:d.q2},{type:this.Q3,value:d.q3},{type:this.MAX,value:d.max},...d.upperOutliers.map(X=>({type:this.UPPER_OUTLIER,value:X})),{type:this.GLOBAL_MAX,value:t.max}],y=new Array;let S=!0;for(let X=0;X<h.length-1;X++){const le=h[X],ue=h[X+1],re=Math.abs(S?ue.value-le.value:le.value-h[X-1].value);le.type===this.LOWER_OUTLIER||le.type===this.UPPER_OUTLIER?(y.push({type:le.type,length:0,numChars:1}),y.push({type:this.BLANK,length:re,numChars:0})):le.type===this.Q2?(S=!1,y.push({type:this.Q2,length:0,numChars:2})):le.type===this.GLOBAL_MIN||le.type===this.GLOBAL_MAX?y.push({type:this.BLANK,length:re,numChars:0}):y.push({type:le.type,length:re,numChars:1})}let E=y.reduce((X,le)=>X+(le.numChars>0?le.numChars:0),0),[T,w,C,R]=[-1,-1,-1,-1];for(let X=0;X<y.length;X++)y[X].type===this.MIN&&y[X].length>0&&(T=X),y[X].type===this.MAX&&y[X].length>0&&(w=X),y[X].type===this.Q1&&(C=X),y[X].type===this.Q3&&(R=X);T!==-1&&w!==-1&&y[T].length!==y[w].length&&(y[T].length>y[w].length?(y[T].numChars++,E++):(y[w].numChars++,E++)),C!==-1&&R!==-1&&y[C].length!==y[R].length&&(y[C].length>y[R].length?(y[C].numChars++,E++):(y[R].numChars++,E++));const D=Math.max(0,n-E),N=y.reduce((X,le)=>X+(le.type!==this.Q2&&le.length>0?le.length:0),0);for(const X of y)if(X.type!==this.Q2&&X.length>0){const le=Math.round(X.length/N*D);X.numChars+=le}const z=y.reduce((X,le)=>X+le.numChars,0);let B=n-z,V=0;for(;B!==0;){const X=y[V%y.length];X.type!==this.BLANK&&X.type!==this.Q2&&X.length>0&&(X.numChars+=B>0?1:-1,B+=B>0?-1:1),V++}let L=-1;const P=[this.LOWER_OUTLIER,this.MIN,this.Q1,this.Q2,this.Q3,this.MAX,this.UPPER_OUTLIER];s.push(Array.from({length:P.length}).fill(-1));for(const X of y){X.type!==this.BLANK&&X.type!==this.GLOBAL_MIN&&X.type!==this.GLOBAL_MAX&&(L=P.indexOf(X.type),s[f][L]=i.length);for(let le=0;le<X.numChars;le++){let ue="⠀";X.type===this.MIN||X.type===this.MAX?ue="⠒":X.type===this.Q1||X.type===this.Q3?ue="⠿":X.type===this.Q2?ue=le===0?"⠸":"⠇":X.type===this.LOWER_OUTLIER||X.type===this.UPPER_OUTLIER?ue="⠂":X.type===this.BLANK&&(ue="⠀"),i.push(ue),o.push({row:f,col:L})}}for(let X=0;X<3;X++)if(s[f][X]===-1){for(let le=X+1;le<=3;le++)if(s[f][le]!==-1){s[f][X]=s[f][le];break}}for(let X=6;X>3;X--)if(s[f][X]===-1){for(let le=X-1;le>=3;le--)if(s[f][le]!==-1){s[f][X]=s[f][le];break}}i.push(ge.NEW_LINE),o.push({row:f,col:L})}return{value:i.join(ge.EMPTY),cellToIndex:s,indexToCell:o}}}class uV{encode(t){const n=new Array,i=new Array,o=new Array,s=(t.max-t.min)/3,f=t.min+s,d=f+s;for(let h=0;h<t.values.length;h++){i.push(new Array);for(let y=0;y<t.values[h].length;y++)t.values[h][y]===0?n.push(" "):t.values[h][y]<=f?n.push("⠤"):t.values[h][y]<=d?n.push("⠒"):n.push("⠉"),i[h].push(o.length),o.push({row:h,col:y});n.push(ge.NEW_LINE),i[h].push(o.length),o.push({row:h,col:t.values[h].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class xA{encode(t){const n=new Array,i=new Array,o=new Array;for(let s=0;s<t.values.length;s++){i.push(new Array);const{low:f,medium:d,mediumHigh:h,high:y}=this.getThresholds(s,t);for(let S=0;S<t.values[s].length;S++){const E=t.values[s][S],T=S>0?t.values[s][S-1]:null,w=this.getBrailleChar(E,T,f,d,y,h);n.push(w),i[s].push(o.length),o.push({row:s,col:S})}n.push(ge.NEW_LINE),i[s].push(o.length),o.push({row:s,col:t.values[s].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}getBrailleChar(t,n,i,o,s,f){return f===void 0&&(f=s),t<=i&&n!==null&&n>i?n<=o?"⢄":n<=f?"⢆":"⢇":t<=i?"⣀":n!==null&&n<=i?t<=o?"⡠":t<=f?"⡰":"⡸":t<=o&&n!==null&&n>o?n<=f?"⠢":"⠣":t<=o?"⠤":n!==null&&n<=o?t<=f?"⠔":"⠜":t<=f&&n!==null&&n>f?"⠑":t<=f?"⠒":n!==null&&n<=f?"⠊":t<=s?"⠉":""}getBraille6Char(t,n,i,o,s){const f=E=>E<=i?"low":E<=o?"medium":(E<=s,"high"),d=f(t),h=n!==null?f(n):null,y={"low,medium":"⠢","low,high":"⠣","low,null":"⠤","low,low":"⠤","medium,low":"⠔","medium,high":"⠑","medium,null":"⠒","medium,medium":"⠒","high,low":"⠜","high,medium":"⠊","high,null":"⠉","high,high":"⠉"},S=`${d},${h}`;return y[S]||""}addDot8(t){if(!t||t.length===0)return"⢀";const o=t.charCodeAt(0)-10240|128;return String.fromCharCode(10240+o)}}class cV extends xA{getThresholds(t,n){const i=Array.isArray(n.min)?n.min[t]:n.min,o=Array.isArray(n.max)?n.max[t]:n.max,s=(o-i)/3,f=i+s,d=f+s;return{low:f,medium:d,high:o}}encode(t){var s;const n=new Array,i=new Array,o=new Array;for(let f=0;f<t.values.length;f++){i.push(new Array);const{low:d,medium:h,high:y}=this.getThresholds(f,t);for(let S=0;S<t.values[f].length;S++){const E=t.values[f][S],T=S>0?t.values[f][S-1]:null;let w=this.getBraille6Char(E,T,d,h,y);((s=t.custom)==null?void 0:s[S])==="Bear"&&(w=this.addDot8(w)),n.push(w),i[f].push(o.length),o.push({row:f,col:S})}n.push(ge.NEW_LINE),i[f].push(o.length),o.push({row:f,col:t.values[f].length})}return{value:n.join(ge.EMPTY),cellToIndex:i,indexToCell:o}}}class EA extends xA{getThresholds(t,n){const i=(n.max[t]-n.min[t])/4,o=n.min[t]+i,s=o+i,f=s+i,d=n.max[t];return{low:o,medium:s,mediumHigh:f,high:d}}}class fV{constructor(t,n,i){q(this,"context");q(this,"notification");q(this,"display");q(this,"enabled");q(this,"cacheId");q(this,"cache");q(this,"encoders");q(this,"onChangeEmitter");q(this,"onChange");this.context=t,this.notification=n,this.display=i,this.enabled=!1,this.cacheId=ge.EMPTY,this.cache=null,this.encoders=new Map([[ar.BAR,new cv],[ar.BOX,new sV],[ar.CANDLESTICK,new cV],[ar.DODGED,new cv],[ar.HEATMAP,new uV],[ar.HISTOGRAM,new cv],[ar.LINE,new EA],[ar.NORMALIZED,new cv],[ar.SMOOTH,new EA],[ar.STACKED,new cv]]),this.onChangeEmitter=new Ad,this.onChange=this.onChangeEmitter.event}dispose(){this.onChangeEmitter.dispose(),this.cache=null,this.encoders.clear()}update(t){if(!this.enabled||t.empty)return;const n=t.type==="subplot"?t.trace:t;if(n.empty||n.braille.empty||!this.encoders.has(n.traceType))return;const i=n.braille;if(this.cache===null||this.cacheId!==i.id){const o=this.encoders.get(n.traceType);this.cache=o.encode(i,SA),this.cacheId=i.id}this.onChangeEmitter.fire({value:this.cache.value.trim(),index:this.cache.cellToIndex[i.row][i.col]})}moveToIndex(t){if(!this.enabled||this.cache===null||t<0||t>=this.cache.indexToCell.length)return;const{row:n,col:i}=this.cache.indexToCell[t];this.context.moveToIndex(n,i)}toggle(t){if(t.empty){this.notification.notify("No info for braille");return}if(t.braille.empty){const i=`Braille is not supported for plot type: ${t.braille.traceType}`;this.notification.notify(i);return}this.enabled=!this.enabled,this.update(t),this.display.toggleFocus(Cn.BRAILLE);const n=`Braille is ${this.enabled?"on":"off"}`;this.notification.notify(n)}}var wA=(e=>(e[e.OK=200]="OK",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.SERVER_ERROR=500]="SERVER_ERROR",e))(wA||{});class TA{constructor(){}static async post(t,n,i){const o={...this.DEFAULT_HEADERS,...i};return this.request(t,"POST",o,n)}static async request(t,n,i,o){try{const s=await fetch(t,{method:n,headers:i,body:o});return s.ok?{success:!0,data:await s.json()}:{success:!1,error:{statusCode:s.status,message:`API Error: ${s.status} - ${s.statusText}`}}}catch(s){return console.error(`Error in API ${n} request to ${t}:`,s),{success:!1,error:{statusCode:wA.SERVER_ERROR,message:s instanceof Error?s.message:"Unknown error occurred"}}}}}q(TA,"DEFAULT_HEADERS",{"Content-Type":"application/json"});const dV=`You are a helpful assistant that answers questions about statistical visualizations. Your role is to:
308
308
  1. Answer the user's specific question directly and clearly
309
309
  2. Use simple, everyday language with minimal statistical terms
310
310
  3. Provide relevant information from the data when needed