diff --git a/demos/lib/hermes.iife.js b/demos/lib/hermes.iife.js index bc80842..3e59541 100644 --- a/demos/lib/hermes.iife.js +++ b/demos/lib/hermes.iife.js @@ -1 +1 @@ -var Hermes=function(t){"use strict";const e={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},i={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},s={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},a={Horizontal:"horizontal",Vertical:"vertical"},n={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},l={After:"after",Before:"before"},o={Bezier:"bezier",Straight:"straight"},r=Number.NaN,h={x:Number.NaN,y:Number.NaN},c={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},d={dimIndex:-1,p0:h,p1:h,type:e.None},u="normal 12px san-serif",f="butt",p="round",y=10,g="black",x={debug:!1,direction:a.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:l.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:o.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:l.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:i.AxisEvenlySpaced},padding:[32,64]}},m={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},v=.01,b={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:m,key:void 0},shared:{action:d,focus:void 0}},S=t=>"number"==typeof t,N=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!k(t),k=t=>t instanceof Set,I=t=>"string"==typeof t,M=t=>JSON.parse(JSON.stringify(t)),L=(t,e)=>Math.min(e[1],Math.max(e[0],t)),B=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{N(t[i])&&N(e[i])?t[i]=B(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),E=(t,e)=>t.reduce(((t,i)=>(S(i)&&!isNaN(i)&&((t=>e===s.Logarithmic?isFinite(Math.log(t)):isFinite(t))(i)&&(it.finite[1]&&(t.finite[1]=i)),it.actual[1]&&(t.actual[1]=i)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),D=(t,e)=>t[e%t.length],w=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},P=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],z=(t,e,i={})=>{if(null!=i.includeNaN){const t=L(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},F=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},C=t=>I(t)?t:t.toString();class A{constructor(t,e,i,s={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=s.dataOnEdge&&(this.dataOnEdge=s.dataOnEdge),this.reverse=t===a.Horizontal?null!=s.reverse&&s.reverse:null==s.reverse||!s.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class T extends A{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>C(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const V=t=>e=>Math.log(e)/Math.log(t);class H extends A{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=V(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!S(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=V(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=O(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const $=(t,e)=>t.x*e.x+t.y*e.y,W=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=$(a,a),r=$(a,n),h=$(a,l),c=$(n,n),d=$(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},J=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle||g,t.beginPath(),t.moveTo(e[0].x,e[0].y);const l=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle||g,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(tt(e),tt(i)),t.lineTo(tt(s),tt(a)),t.stroke(),t.restore()},U=(t,e,i,s,a,n={})=>{t.save();const l=tt(e),o=tt(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(G(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(G(t,l,o,s,a,r),t.stroke())),t.restore()},G=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},X=(t,e,i,s,a,n={})=>{const l=Z(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),et(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},Y=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Z(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},K=(t,e,i=u)=>{et(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},Q=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Z=t=>(t+2*Math.PI)%(2*Math.PI),tt=t=>Math.round(t-.5)+.5,et=(t,e=u)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},it=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(st(t[a]),st(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},st=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},at=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},nt=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},lt=(t,i,s)=>{const a=i.shared.action,n=a.type===e.LabelMove&&a.dimIndex===t,l=i.dimension.bound||c,o=i.dimension.boundOffset||{x:0,y:0};return n?(h=o,{h:(r=l).h,w:r.w,x:r.x+h.x,y:r.y+h.y}):s;var r,h},ot=t=>isNaN(t.p0)&&isNaN(t.p1),rt=(t,e)=>{const i=M(m);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},ht={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ct=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:s.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:s.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:s.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:s.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:s.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:s.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:s.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:s.Linear}],dt=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:s.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:s.Logarithmic}];var ut=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:ht,dimensionSamples:ct,metricDimensionSamples:dt,generateData:(t,e,i=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===s.Categorical){if(n.categories)return i?P(n.categories):D(n.categories,l)}else if(n.type===s.Linear){const t=ht[n.key];if(t)return i?z(t[1],t[0],a):w(t[1],t[0],e,l,a)}else if(n.type===s.Logarithmic){const t=ht[n.key];if(t&&n.logBase)return i?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=z(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**w(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return r})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?P(ct):D(ct,i))),s=e?P(dt):D(dt,0);return i.push(s),i}});class ft{constructor(t,e,i,s){this.config=x,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=M(b),this._=void 0;const a=(t=>I(t)?document.querySelector(t):t)(t);if(!a)throw new R("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new R("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new R("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):nt((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return B(...t)}static getTester(){return ut}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const i=ft.validateDimensions(t);if(!i.valid)throw new R(i.message);const n=this.config.direction===a.Horizontal?a.Vertical:a.Horizontal;this.dimensionsOriginal=t,this.dimensions=M(t).map((t=>{const e=t.key,i=this.data[e]||[],a={...t,labelTruncated:F(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new _(n,0,100,0,100)};if(t.type===s.Linear||t.type===s.Logarithmic){const e=E(i,t.type);t.type===s.Linear?a.scale=new _(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===s.Logarithmic&&(a.scale=new H(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===s.Categorical&&(a.scale=new T(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,this.size,n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=M(b),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):nt((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,e;const s={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:Q(this.config.style.padding)}},{h:n,w:o}=this.size,r=s.layout,h=s.dims.shared.axes,c=s.dims.shared.label,d=s.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===a.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===l.Before,S=null!=p.angle,N=x.placement===l.Before;if(r.drawRect={h:n-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(e=p.angle)&&void 0!==e?e:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=K(this.ctx,t.labelTruncated,p.font),a=s.dims.list[e].label;a.w=i.w,a.h=i.h,a.lengthCos=S?i.w*c.cos:i.w,a.lengthSin=S?i.w*c.sin:i.h,Math.abs(a.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=a.lengthCos),Math.abs(a.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=a.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=n-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=n-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=s.dims.list[e].axes,a=s.dims.list[e].label,l=s.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=K(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(l.spaceBefore=f?a.lengthCos<0?-a.lengthCos:0:a.lengthSin>0?a.lengthSin:0,l.spaceAfter=f?a.lengthCos>0?a.lengthCos:0:a.lengthSin<0?-a.lengthSin:0):(l.spaceBefore=(f?a.lengthCos:a.lengthSin)/2,l.spaceAfter=(f?a.lengthCos:a.lengthSin)/2),N?l.spaceBefore=Math.max(l.spaceBefore,i.maxLength):l.spaceAfter=Math.max(l.spaceAfter,i.maxLength),f?(l.bound={h:n-r.padding[0]-r.padding[2],w:l.spaceBefore+l.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=l.bound.w):(l.bound={h:l.spaceBefore+l.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=l.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const a=((null==r?void 0:r.type)===n.Filter||(null==r?void 0:r.type)===n.FilterResize)&&(null==r?void 0:r.dimIndex)===t&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!a,h=a&&void 0===o.filterIndex,c=o.dimIndex===t&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===a.Horizontal?"y":"x",s=this._.dims.shared.axes.length;for(let a=0;ac>=t.p0&&c<=t.p1));let u=n.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?n.FilterResize:n.Filter}return{dimIndex:a,filterIndex:d,type:u}}}}updateActiveLabel(){var t,i;if(!this._||this.ix.shared.action.type!==e.LabelMove)return;const s=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===a.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(t,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[t]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[t][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=e.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=e.FilterResizeAfter:n.type=e.FilterMove):(n.type=e.FilterCreate,l.active={...m,p0:i,p1:i},s[t]=s[t]||[],s[t].push(l.active),n.filterIndex=s[t].length-1)}updateActiveFilter(t){var i,s,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,x=this.ix,v=x.filters,b=x.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===a.Horizontal?"y":"x";if(!(b.type===e.FilterCreate||b.type===e.FilterMove||b.type===e.FilterResizeAfter||b.type===e.FilterResizeBefore)||!v.key)return;const I=this.dimensions[b.dimIndex].key,M=y[b.dimIndex].layout.bound,B=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===e.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(s=v.active.startP1)&&void 0!==s?s:0,a=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=a):v.active.p1>=1&&(v.active.p0=1-a,v.active.p1=1)}else b.type===e.FilterResizeBefore?(v.active.p0=(b.p1[k]-M[k]-B)/g.length,v.active.p0=L(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-M[k]-B)/g.length,v.active.p1=L(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===t.type){if(E=b.p0,D=b.p1,Math.sqrt((D.x-E.x)**2+(D.y-E.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=t[i];null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[I]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...m};else for(let a=t+1;a!ot(t)))}))}updateCursor(){const t=this.ix,i=t.shared.action,s=t.shared.focus,l=this.config.direction===a.Horizontal;let o="default";i.type!==e.None?i.type===e.FilterMove||i.type===e.LabelMove?o="grabbing":i.type===e.FilterResizeAfter||i.type===e.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===e.FilterCreate&&(o="crosshair"):void 0!==s&&(s.type===n.DimensionLabel?o="grab":s.type===n.DimensionAxis?o="crosshair":s.type===n.Filter?o="grab":s.type===n.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,s=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===a.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===l.Before,x=f.label.placement===l.Before;for(let s=0;s{var f,y,g,x,m,v;const b=t.key,N=i[e].layout,k=lt(e,h,N.bound),I=this.data[b][s],M=S(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let P=k.x,z=k.y;if(L)P+=u?N.axisDataStart.x:N.axisBoundaryStart.x,z+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?N.axisInfinityStop.y:N.axisInfinityStart.y;P+=u?N.axisDataStart.x:t,z+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;P+=N.axisDataStart.x+(u?0:e),z+=N.axisDataStart.y+(u?e:0)}if(b===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=it(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[b]&&0!==d[b].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:P,y:z}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),j(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=lt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};X(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const b=null==f.label.angle&&u,N={textAlign:b?void 0:"center",textBaseline:b?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const a=this.dimensions[e].key,l=lt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[a]||[];if(q(this.ctx,l.x+m.x,l.y+m.y,l.x+v.x,l.y+v.y,r[e].axis),this.dataInfo.hasInfinity){q(this.ctx,l.x+y.x,l.y+y.y,l.x+m.x,l.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),q(this.ctx,l.x+v.x,l.y+v.y,l.x+g.x,l.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=l.x+y.x,s=l.y+y.y,a=t+M,n=s+L;q(this.ctx,t,s,a,n,r[e].tick);const o=l.x+g.x,h=l.y+g.y,c=o+M,d=h+L;q(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:n+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";X(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";X(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=l.x+(u?p.x:o.x),i=l.y+(u?p.y:o.y),s=t+M,a=i+L;q(this.ctx,t,i,s,a,r[e].tick);const n=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;X(this.ctx,"NaN",n,h,c,I)}for(let t=0;t{const a=t.p0*s.length,n=t.p1*s.length,h=r[e].filters[i].width,c=h/2,d=l.x+o.x+(u?-c:a),f=l.y+o.y+(u?a:-c),p=u?h:n-a,y=u?n-a:h;U(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,s=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===a.Horizontal,o={strokeStyle:"#dddddd"};q(this.ctx,0,i.padding[0],e,i.padding[0],o),q(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),q(this.ctx,i.padding[3],0,i.padding[3],t,o),q(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},u={strokeStyle:"#ffcc00"};s.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;U(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),U(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),J(this.ctx,g,u),J(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=M(b),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(t){var i,s;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===a.Horizontal,u=d?"x":"y",f=d?"y":"x",p=at(t,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const t=l.focus.dimIndex,a=this._.dims.list[t].layout,d=a.bound,p=a.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===n.DimensionLabel)o.type=e.LabelMove,o.dimIndex=t,r.axis=d[u]+p[u],r.bound=d;else if([n.DimensionAxis,n.Filter,n.FilterResize].includes(null===(s=l.focus)||void 0===s?void 0:s.type)){o.type=e.FilterCreate,o.dimIndex=t,h.key=this.dimensions[t].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,t)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=M(b),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}return t.ActionType=e,t.DimensionLayout=i,t.DimensionType=s,t.Direction=a,t.FocusType=n,t.LabelPlacement=l,t.PathType=o,t.default=ft,t}({}); +var Hermes=function(t){"use strict";const e={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},i={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},s={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},a={Horizontal:"horizontal",Vertical:"vertical"},n={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},l={After:"after",Before:"before"},o={Bezier:"bezier",Straight:"straight"},r=Number.NaN,h={x:Number.NaN,y:Number.NaN},c={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},d={dimIndex:-1,p0:h,p1:h,type:e.None},u="normal 12px san-serif",f="butt",p="round",y=10,g="black",x={debug:!1,direction:a.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:l.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:o.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:l.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:i.AxisEvenlySpaced},padding:[32,64]}},m={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},v=.01,b={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:m,key:void 0},shared:{action:d,focus:void 0}},S=t=>"number"==typeof t,N=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!k(t),k=t=>t instanceof Set,I=t=>"string"==typeof t,M=t=>JSON.parse(JSON.stringify(t)),L=(t,e)=>Math.min(e[1],Math.max(e[0],t)),B=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{N(t[i])&&N(e[i])?t[i]=B(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),E=(t,e)=>t.reduce(((t,i)=>(S(i)&&!isNaN(i)&&((t=>e===s.Logarithmic?isFinite(Math.log(t)):isFinite(t))(i)&&(it.finite[1]&&(t.finite[1]=i)),it.actual[1]&&(t.actual[1]=i)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),D=(t,e)=>t[e%t.length],w=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},P=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],z=(t,e,i={})=>{if(null!=i.includeNaN){const t=L(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},F=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},C=t=>I(t)?t:t.toString();class A{constructor(t,e,i,s={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=s.dataOnEdge&&(this.dataOnEdge=s.dataOnEdge),this.reverse=t===a.Horizontal?null!=s.reverse&&s.reverse:null==s.reverse||!s.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class T extends A{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>C(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const V=t=>e=>Math.log(e)/Math.log(t);class H extends A{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=V(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!S(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=V(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=O(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const $=(t,e)=>t.x*e.x+t.y*e.y,W=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=$(a,a),r=$(a,n),h=$(a,l),c=$(n,n),d=$(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},J=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle||g,t.beginPath(),t.moveTo(e[0].x,e[0].y);const l=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle||g,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(tt(e),tt(i)),t.lineTo(tt(s),tt(a)),t.stroke(),t.restore()},U=(t,e,i,s,a,n={})=>{t.save();const l=tt(e),o=tt(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(G(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(G(t,l,o,s,a,r),t.stroke())),t.restore()},G=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},X=(t,e,i,s,a,n={})=>{const l=Z(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),et(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},Y=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Z(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},K=(t,e,i=u)=>{et(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},Q=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Z=t=>(t+2*Math.PI)%(2*Math.PI),tt=t=>Math.round(t-.5)+.5,et=(t,e=u)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},it=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(st(t[a]),st(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},st=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},at=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},nt=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},lt=(t,i,s)=>{const a=i.shared.action,n=a.type===e.LabelMove&&a.dimIndex===t,l=i.dimension.bound||c,o=i.dimension.boundOffset||{x:0,y:0};return n?(h=o,{h:(r=l).h,w:r.w,x:r.x+h.x,y:r.y+h.y}):s;var r,h},ot=t=>isNaN(t.p0)&&isNaN(t.p1),rt=(t,e)=>{const i=M(m);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},ht={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ct=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:s.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:s.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:s.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:s.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:s.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:s.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:s.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:s.Linear}],dt=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:s.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:s.Logarithmic}];var ut=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:ht,dimensionSamples:ct,metricDimensionSamples:dt,generateData:(t,e,i=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===s.Categorical){if(n.categories)return i?P(n.categories):D(n.categories,l)}else if(n.type===s.Linear){const t=ht[n.key];if(t)return i?z(t[1],t[0],a):w(t[1],t[0],e,l,a)}else if(n.type===s.Logarithmic){const t=ht[n.key];if(t&&n.logBase)return i?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=z(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**w(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return r})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?P(ct):D(ct,i))),s=e?P(dt):D(dt,0);return i.push(s),i}});class ft{constructor(t,e,i,s){this.config=x,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=M(b),this._=void 0;const a=(t=>I(t)?document.querySelector(t):t)(t);if(!a)throw new R("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new R("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new R("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):nt((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return B(...t)}static getTester(){return ut}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const i=ft.validateDimensions(t);if(!i.valid)throw new R(i.message);const n=this.config.direction===a.Horizontal?a.Vertical:a.Horizontal;this.dimensionsOriginal=t,this.dimensions=M(t).map((t=>{const e=t.key,i=this.data[e]||[],a={...t,labelTruncated:F(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new _(n,0,100,0,100)};if(t.type===s.Linear||t.type===s.Logarithmic){const e=E(i,t.type);t.type===s.Linear?a.scale=new _(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===s.Logarithmic&&(a.scale=new H(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===s.Categorical&&(a.scale=new T(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,M(this.size),n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=M(b),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):nt((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,e;const s={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:Q(this.config.style.padding)}},{h:n,w:o}=this.size,r=s.layout,h=s.dims.shared.axes,c=s.dims.shared.label,d=s.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===a.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===l.Before,S=null!=p.angle,N=x.placement===l.Before;if(r.drawRect={h:n-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(e=p.angle)&&void 0!==e?e:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=K(this.ctx,t.labelTruncated,p.font),a=s.dims.list[e].label;a.w=i.w,a.h=i.h,a.lengthCos=S?i.w*c.cos:i.w,a.lengthSin=S?i.w*c.sin:i.h,Math.abs(a.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=a.lengthCos),Math.abs(a.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=a.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=n-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=n-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=s.dims.list[e].axes,a=s.dims.list[e].label,l=s.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=K(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(l.spaceBefore=f?a.lengthCos<0?-a.lengthCos:0:a.lengthSin>0?a.lengthSin:0,l.spaceAfter=f?a.lengthCos>0?a.lengthCos:0:a.lengthSin<0?-a.lengthSin:0):(l.spaceBefore=(f?a.lengthCos:a.lengthSin)/2,l.spaceAfter=(f?a.lengthCos:a.lengthSin)/2),N?l.spaceBefore=Math.max(l.spaceBefore,i.maxLength):l.spaceAfter=Math.max(l.spaceAfter,i.maxLength),f?(l.bound={h:n-r.padding[0]-r.padding[2],w:l.spaceBefore+l.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=l.bound.w):(l.bound={h:l.spaceBefore+l.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=l.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const a=((null==r?void 0:r.type)===n.Filter||(null==r?void 0:r.type)===n.FilterResize)&&(null==r?void 0:r.dimIndex)===t&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!a,h=a&&void 0===o.filterIndex,c=o.dimIndex===t&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===a.Horizontal?"y":"x",s=this._.dims.shared.axes.length;for(let a=0;ac>=t.p0&&c<=t.p1));let u=n.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?n.FilterResize:n.Filter}return{dimIndex:a,filterIndex:d,type:u}}}}updateActiveLabel(){var t,i;if(!this._||this.ix.shared.action.type!==e.LabelMove)return;const s=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===a.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(t,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[t]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[t][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=e.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=e.FilterResizeAfter:n.type=e.FilterMove):(n.type=e.FilterCreate,l.active={...m,p0:i,p1:i},s[t]=s[t]||[],s[t].push(l.active),n.filterIndex=s[t].length-1)}updateActiveFilter(t){var i,s,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,x=this.ix,v=x.filters,b=x.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===a.Horizontal?"y":"x";if(!(b.type===e.FilterCreate||b.type===e.FilterMove||b.type===e.FilterResizeAfter||b.type===e.FilterResizeBefore)||!v.key)return;const I=this.dimensions[b.dimIndex].key,B=y[b.dimIndex].layout.bound,E=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===e.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(s=v.active.startP1)&&void 0!==s?s:0,a=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=a):v.active.p1>=1&&(v.active.p0=1-a,v.active.p1=1)}else b.type===e.FilterResizeBefore?(v.active.p0=(b.p1[k]-B[k]-E)/g.length,v.active.p0=L(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-B[k]-E)/g.length,v.active.p1=L(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===t.type){if(D=b.p0,w=b.p1,Math.sqrt((w.x-D.x)**2+(w.y-D.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=M(t[i]);null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[I]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...m};else for(let a=t+1;a!ot(t)))}))}updateCursor(){const t=this.ix,i=t.shared.action,s=t.shared.focus,l=this.config.direction===a.Horizontal;let o="default";i.type!==e.None?i.type===e.FilterMove||i.type===e.LabelMove?o="grabbing":i.type===e.FilterResizeAfter||i.type===e.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===e.FilterCreate&&(o="crosshair"):void 0!==s&&(s.type===n.DimensionLabel?o="grab":s.type===n.DimensionAxis?o="crosshair":s.type===n.Filter?o="grab":s.type===n.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,s=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===a.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===l.Before,x=f.label.placement===l.Before;for(let s=0;s{var f,y,g,x,m,v;const b=t.key,N=i[e].layout,k=lt(e,h,N.bound),I=this.data[b][s],M=S(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let P=k.x,z=k.y;if(L)P+=u?N.axisDataStart.x:N.axisBoundaryStart.x,z+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?u?N.axisInfinityStop.x:N.axisInfinityStart.x:u?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?u?N.axisInfinityStart.y:N.axisInfinityStop.y:u?N.axisInfinityStop.y:N.axisInfinityStart.y;P+=u?N.axisDataStart.x:t,z+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;P+=N.axisDataStart.x+(u?0:e),z+=N.axisDataStart.y+(u?e:0)}if(b===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=it(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[b]&&0!==d[b].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:P,y:z}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),j(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=lt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};X(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const b=null==f.label.angle&&u,N={textAlign:b?void 0:"center",textBaseline:b?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const a=this.dimensions[e].key,l=lt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[a]||[];if(q(this.ctx,l.x+m.x,l.y+m.y,l.x+v.x,l.y+v.y,r[e].axis),this.dataInfo.hasInfinity){q(this.ctx,l.x+y.x,l.y+y.y,l.x+m.x,l.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),q(this.ctx,l.x+v.x,l.y+v.y,l.x+g.x,l.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=l.x+y.x,s=l.y+y.y,a=t+M,n=s+L;q(this.ctx,t,s,a,n,r[e].tick);const o=l.x+g.x,h=l.y+g.y,c=o+M,d=h+L;q(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:n+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";X(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";X(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=l.x+(u?p.x:o.x),i=l.y+(u?p.y:o.y),s=t+M,a=i+L;q(this.ctx,t,i,s,a,r[e].tick);const n=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;X(this.ctx,"NaN",n,h,c,I)}for(let t=0;t{const a=t.p0*s.length,n=t.p1*s.length,h=r[e].filters[i].width,c=h/2,d=l.x+o.x+(u?-c:a),f=l.y+o.y+(u?a:-c),p=u?h:n-a,y=u?n-a:h;U(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,s=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===a.Horizontal,o={strokeStyle:"#dddddd"};q(this.ctx,0,i.padding[0],e,i.padding[0],o),q(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),q(this.ctx,i.padding[3],0,i.padding[3],t,o),q(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},u={strokeStyle:"#ffcc00"};s.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;U(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),U(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),J(this.ctx,g,u),J(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=M(b),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(t){var i,s;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===a.Horizontal,u=d?"x":"y",f=d?"y":"x",p=at(t,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const t=l.focus.dimIndex,a=this._.dims.list[t].layout,d=a.bound,p=a.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===n.DimensionLabel)o.type=e.LabelMove,o.dimIndex=t,r.axis=d[u]+p[u],r.bound=d;else if([n.DimensionAxis,n.Filter,n.FilterResize].includes(null===(s=l.focus)||void 0===s?void 0:s.type)){o.type=e.FilterCreate,o.dimIndex=t,h.key=this.dimensions[t].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,t)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=M(b),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}return t.ActionType=e,t.DimensionLayout=i,t.DimensionType=s,t.Direction=a,t.FocusType=n,t.LabelPlacement=l,t.PathType=o,t.default=ft,t}({}); diff --git a/dist/hermes.cjs.js b/dist/hermes.cjs.js index 4365cb5..62c5dbc 100644 --- a/dist/hermes.cjs.js +++ b/dist/hermes.cjs.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},e={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},i={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},s={Horizontal:"horizontal",Vertical:"vertical"},a={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},n={After:"after",Before:"before"},l={Bezier:"bezier",Straight:"straight"},o=Number.NaN,r={x:Number.NaN,y:Number.NaN},h={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},c={dimIndex:-1,p0:r,p1:r,type:t.None},d="normal 12px san-serif",u="butt",f="round",p=10,y="black",g={debug:!1,direction:s.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:n.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:l.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:n.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:e.AxisEvenlySpaced},padding:[32,64]}},x={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},m=.01,v={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:x,key:void 0},shared:{action:c,focus:void 0}},b=t=>"number"==typeof t,S=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!N(t),N=t=>t instanceof Set,k=t=>"string"==typeof t,I=t=>JSON.parse(JSON.stringify(t)),M=(t,e)=>Math.min(e[1],Math.max(e[0],t)),L=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{S(t[i])&&S(e[i])?t[i]=L(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),B=(t,e)=>t.reduce(((t,s)=>(b(s)&&!isNaN(s)&&((t=>e===i.Logarithmic?isFinite(Math.log(t)):isFinite(t))(s)&&(st.finite[1]&&(t.finite[1]=s)),st.actual[1]&&(t.actual[1]=s)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),E=(t,e)=>t[e%t.length],D=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},w=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],P=(t,e,i={})=>{if(null!=i.includeNaN){const t=M(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},O=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},F=t=>k(t)?t:t.toString();class C{constructor(t,e,i,a={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=a.dataOnEdge&&(this.dataOnEdge=a.dataOnEdge),this.reverse=t===s.Horizontal?null!=a.reverse&&a.reverse:null==a.reverse||!a.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class A extends C{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>F(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const _=t=>e=>Math.log(e)/Math.log(t);class V extends C{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=_(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!b(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=_(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=z(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const H=(t,e)=>t.x*e.x+t.y*e.y,$=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=H(a,a),r=H(a,n),h=H(a,l),c=H(n,n),d=H(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},W=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle||y,t.beginPath(),t.moveTo(e[0].x,e[0].y);const o=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle||y,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(Z(e),Z(i)),t.lineTo(Z(s),Z(a)),t.stroke(),t.restore()},q=(t,e,i,s,a,n={})=>{t.save();const l=Z(e),o=Z(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(U(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(U(t,l,o,s,a,r),t.stroke())),t.restore()},U=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},G=(t,e,i,s,a,n={})=>{const l=Q(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),tt(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},X=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Q(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},Y=(t,e,i=d)=>{tt(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},K=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Q=t=>(t+2*Math.PI)%(2*Math.PI),Z=t=>Math.round(t-.5)+.5,tt=(t,e=d)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},et=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(it(t[a]),it(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},it=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},st=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},at=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},nt=(e,i,s)=>{const a=i.shared.action,n=a.type===t.LabelMove&&a.dimIndex===e,l=i.dimension.bound||h,o=i.dimension.boundOffset||{x:0,y:0};return n?(c=o,{h:(r=l).h,w:r.w,x:r.x+c.x,y:r.y+c.y}):s;var r,c},lt=t=>isNaN(t.p0)&&isNaN(t.p1),ot=(t,e)=>{const i=I(x);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},rt={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ht=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:i.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:i.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:i.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:i.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:i.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:i.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:i.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:i.Linear}],ct=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:i.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:i.Logarithmic}];var dt=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:rt,dimensionSamples:ht,metricDimensionSamples:ct,generateData:(t,e,s=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===i.Categorical){if(n.categories)return s?w(n.categories):E(n.categories,l)}else if(n.type===i.Linear){const t=rt[n.key];if(t)return s?P(t[1],t[0],a):D(t[1],t[0],e,l,a)}else if(n.type===i.Logarithmic){const t=rt[n.key];if(t&&n.logBase)return s?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=P(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**D(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return o})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?w(ht):E(ht,i))),s=e?w(ct):E(ct,0);return i.push(s),i}});class ut{constructor(t,e,i,s){this.config=g,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=I(v),this._=void 0;const a=(t=>k(t)?document.querySelector(t):t)(t);if(!a)throw new T("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new T("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new T("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):at((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return L(...t)}static getTester(){return dt}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const a=ut.validateDimensions(t);if(!a.valid)throw new T(a.message);const n=this.config.direction===s.Horizontal?s.Vertical:s.Horizontal;this.dimensionsOriginal=t,this.dimensions=I(t).map((t=>{const e=t.key,s=this.data[e]||[],a={...t,labelTruncated:O(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new R(n,0,100,0,100)};if(t.type===i.Linear||t.type===i.Logarithmic){const e=B(s,t.type);t.type===i.Linear?a.scale=new R(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===i.Logarithmic&&(a.scale=new V(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===i.Categorical&&(a.scale=new A(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,this.size,n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=I(v),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):at((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,i;const a={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:K(this.config.style.padding)}},{h:l,w:o}=this.size,r=a.layout,h=a.dims.shared.axes,c=a.dims.shared.label,d=a.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===s.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===n.Before,S=null!=p.angle,N=x.placement===n.Before;if(r.drawRect={h:l-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(i=p.angle)&&void 0!==i?i:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=Y(this.ctx,t.labelTruncated,p.font),s=a.dims.list[e].label;s.w=i.w,s.h=i.h,s.lengthCos=S?i.w*c.cos:i.w,s.lengthSin=S?i.w*c.sin:i.h,Math.abs(s.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=s.lengthCos),Math.abs(s.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=s.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=l-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=l-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=a.dims.list[e].axes,s=a.dims.list[e].label,n=a.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=Y(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(n.spaceBefore=f?s.lengthCos<0?-s.lengthCos:0:s.lengthSin>0?s.lengthSin:0,n.spaceAfter=f?s.lengthCos>0?s.lengthCos:0:s.lengthSin<0?-s.lengthSin:0):(n.spaceBefore=(f?s.lengthCos:s.lengthSin)/2,n.spaceAfter=(f?s.lengthCos:s.lengthSin)/2),N?n.spaceBefore=Math.max(n.spaceBefore,i.maxLength):n.spaceAfter=Math.max(n.spaceAfter,i.maxLength),f?(n.bound={h:l-r.padding[0]-r.padding[2],w:n.spaceBefore+n.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=n.bound.w):(n.bound={h:n.spaceBefore+n.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=n.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const n=((null==r?void 0:r.type)===a.Filter||(null==r?void 0:r.type)===a.FilterResize)&&(null==r?void 0:r.dimIndex)===e&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!n,h=n&&void 0===o.filterIndex,c=o.dimIndex===e&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===s.Horizontal?"y":"x",n=this._.dims.shared.axes.length;for(let s=0;sc>=t.p0&&c<=t.p1));let u=a.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?a.FilterResize:a.Filter}return{dimIndex:s,filterIndex:d,type:u}}}}updateActiveLabel(){var e,i;if(!this._||this.ix.shared.action.type!==t.LabelMove)return;const a=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===s.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(e,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[e]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[e][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=t.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=t.FilterResizeAfter:n.type=t.FilterMove):(n.type=t.FilterCreate,l.active={...x,p0:i,p1:i},s[e]=s[e]||[],s[e].push(l.active),n.filterIndex=s[e].length-1)}updateActiveFilter(e){var i,a,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,m=this.ix,v=m.filters,b=m.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===s.Horizontal?"y":"x";if(!(b.type===t.FilterCreate||b.type===t.FilterMove||b.type===t.FilterResizeAfter||b.type===t.FilterResizeBefore)||!v.key)return;const I=this.dimensions[b.dimIndex].key,L=y[b.dimIndex].layout.bound,B=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===t.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(a=v.active.startP1)&&void 0!==a?a:0,s=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=s):v.active.p1>=1&&(v.active.p0=1-s,v.active.p1=1)}else b.type===t.FilterResizeBefore?(v.active.p0=(b.p1[k]-L[k]-B)/g.length,v.active.p0=M(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-L[k]-B)/g.length,v.active.p1=M(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===e.type){if(E=b.p0,D=b.p1,Math.sqrt((D.x-E.x)**2+(D.y-E.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=t[i];null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[I]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...x};else for(let a=t+1;a!lt(t)))}))}updateCursor(){const e=this.ix,i=e.shared.action,n=e.shared.focus,l=this.config.direction===s.Horizontal;let o="default";i.type!==t.None?i.type===t.FilterMove||i.type===t.LabelMove?o="grabbing":i.type===t.FilterResizeAfter||i.type===t.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===t.FilterCreate&&(o="crosshair"):void 0!==n&&(n.type===a.DimensionLabel?o="grab":n.type===a.DimensionAxis?o="crosshair":n.type===a.Filter?o="grab":n.type===a.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,l=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===s.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===n.Before,x=f.label.placement===n.Before;for(let s=0;s{var f,y,g,x,m,v;const S=t.key,N=i[e].layout,k=nt(e,h,N.bound),I=this.data[S][s],M=b(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let P=k.x,z=k.y;if(L)P+=u?N.axisDataStart.x:N.axisBoundaryStart.x,z+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?N.axisInfinityStop.y:N.axisInfinityStart.y;P+=u?N.axisDataStart.x:t,z+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;P+=N.axisDataStart.x+(u?0:e),z+=N.axisDataStart.y+(u?e:0)}if(S===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=et(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[S]&&0!==d[S].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:P,y:z}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),J(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=nt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};G(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const S=null==f.label.angle&&u,N={textAlign:S?void 0:"center",textBaseline:S?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const s=this.dimensions[e].key,n=nt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[s]||[];if(j(this.ctx,n.x+m.x,n.y+m.y,n.x+v.x,n.y+v.y,r[e].axis),this.dataInfo.hasInfinity){j(this.ctx,n.x+y.x,n.y+y.y,n.x+m.x,n.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),j(this.ctx,n.x+v.x,n.y+v.y,n.x+g.x,n.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=n.x+y.x,s=n.y+y.y,a=t+M,l=s+L;j(this.ctx,t,s,a,l,r[e].tick);const o=n.x+g.x,h=n.y+g.y,c=o+M,d=h+L;j(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:l+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";G(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";G(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=n.x+(u?p.x:o.x),i=n.y+(u?p.y:o.y),s=t+M,a=i+L;j(this.ctx,t,i,s,a,r[e].tick);const l=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;G(this.ctx,"NaN",l,h,c,I)}for(let t=0;t{const s=t.p0*l.length,a=t.p1*l.length,h=r[e].filters[i].width,c=h/2,d=n.x+o.x+(u?-c:s),f=n.y+o.y+(u?s:-c),p=u?h:a-s,y=u?a-s:h;q(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,a=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===s.Horizontal,o={strokeStyle:"#dddddd"};j(this.ctx,0,i.padding[0],e,i.padding[0],o),j(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),j(this.ctx,i.padding[3],0,i.padding[3],t,o),j(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},y={strokeStyle:"#ffcc00"};a.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;q(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),q(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),W(this.ctx,g,y),W(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=I(v),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(e){var i,n;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===s.Horizontal,u=d?"x":"y",f=d?"y":"x",p=st(e,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const e=l.focus.dimIndex,s=this._.dims.list[e].layout,d=s.bound,p=s.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===a.DimensionLabel)o.type=t.LabelMove,o.dimIndex=e,r.axis=d[u]+p[u],r.bound=d;else if([a.DimensionAxis,a.Filter,a.FilterResize].includes(null===(n=l.focus)||void 0===n?void 0:n.type)){o.type=t.FilterCreate,o.dimIndex=e,h.key=this.dimensions[e].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,e)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=I(v),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}exports.ActionType=t,exports.DimensionLayout=e,exports.DimensionType=i,exports.Direction=s,exports.FocusType=a,exports.LabelPlacement=n,exports.PathType=l,exports.default=ut; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},e={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},i={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},s={Horizontal:"horizontal",Vertical:"vertical"},a={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},n={After:"after",Before:"before"},l={Bezier:"bezier",Straight:"straight"},o=Number.NaN,r={x:Number.NaN,y:Number.NaN},h={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},c={dimIndex:-1,p0:r,p1:r,type:t.None},d="normal 12px san-serif",u="butt",f="round",p=10,y="black",g={debug:!1,direction:s.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:n.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:l.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:n.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:e.AxisEvenlySpaced},padding:[32,64]}},x={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},m=.01,v={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:x,key:void 0},shared:{action:c,focus:void 0}},b=t=>"number"==typeof t,S=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!N(t),N=t=>t instanceof Set,k=t=>"string"==typeof t,I=t=>JSON.parse(JSON.stringify(t)),M=(t,e)=>Math.min(e[1],Math.max(e[0],t)),L=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{S(t[i])&&S(e[i])?t[i]=L(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),B=(t,e)=>t.reduce(((t,s)=>(b(s)&&!isNaN(s)&&((t=>e===i.Logarithmic?isFinite(Math.log(t)):isFinite(t))(s)&&(st.finite[1]&&(t.finite[1]=s)),st.actual[1]&&(t.actual[1]=s)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),E=(t,e)=>t[e%t.length],D=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},w=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],P=(t,e,i={})=>{if(null!=i.includeNaN){const t=M(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},O=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},F=t=>k(t)?t:t.toString();class C{constructor(t,e,i,a={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=a.dataOnEdge&&(this.dataOnEdge=a.dataOnEdge),this.reverse=t===s.Horizontal?null!=a.reverse&&a.reverse:null==a.reverse||!a.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class A extends C{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>F(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const _=t=>e=>Math.log(e)/Math.log(t);class V extends C{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=_(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!b(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=_(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=z(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const H=(t,e)=>t.x*e.x+t.y*e.y,$=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=H(a,a),r=H(a,n),h=H(a,l),c=H(n,n),d=H(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},W=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle||y,t.beginPath(),t.moveTo(e[0].x,e[0].y);const o=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle||y,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(Z(e),Z(i)),t.lineTo(Z(s),Z(a)),t.stroke(),t.restore()},q=(t,e,i,s,a,n={})=>{t.save();const l=Z(e),o=Z(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(U(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(U(t,l,o,s,a,r),t.stroke())),t.restore()},U=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},G=(t,e,i,s,a,n={})=>{const l=Q(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),tt(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},X=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Q(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},Y=(t,e,i=d)=>{tt(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},K=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Q=t=>(t+2*Math.PI)%(2*Math.PI),Z=t=>Math.round(t-.5)+.5,tt=(t,e=d)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},et=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(it(t[a]),it(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},it=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},st=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},at=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},nt=(e,i,s)=>{const a=i.shared.action,n=a.type===t.LabelMove&&a.dimIndex===e,l=i.dimension.bound||h,o=i.dimension.boundOffset||{x:0,y:0};return n?(c=o,{h:(r=l).h,w:r.w,x:r.x+c.x,y:r.y+c.y}):s;var r,c},lt=t=>isNaN(t.p0)&&isNaN(t.p1),ot=(t,e)=>{const i=I(x);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},rt={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ht=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:i.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:i.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:i.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:i.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:i.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:i.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:i.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:i.Linear}],ct=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:i.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:i.Logarithmic}];var dt=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:rt,dimensionSamples:ht,metricDimensionSamples:ct,generateData:(t,e,s=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===i.Categorical){if(n.categories)return s?w(n.categories):E(n.categories,l)}else if(n.type===i.Linear){const t=rt[n.key];if(t)return s?P(t[1],t[0],a):D(t[1],t[0],e,l,a)}else if(n.type===i.Logarithmic){const t=rt[n.key];if(t&&n.logBase)return s?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=P(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**D(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return o})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?w(ht):E(ht,i))),s=e?w(ct):E(ct,0);return i.push(s),i}});class ut{constructor(t,e,i,s){this.config=g,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=I(v),this._=void 0;const a=(t=>k(t)?document.querySelector(t):t)(t);if(!a)throw new T("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new T("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new T("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):at((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return L(...t)}static getTester(){return dt}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const a=ut.validateDimensions(t);if(!a.valid)throw new T(a.message);const n=this.config.direction===s.Horizontal?s.Vertical:s.Horizontal;this.dimensionsOriginal=t,this.dimensions=I(t).map((t=>{const e=t.key,s=this.data[e]||[],a={...t,labelTruncated:O(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new R(n,0,100,0,100)};if(t.type===i.Linear||t.type===i.Logarithmic){const e=B(s,t.type);t.type===i.Linear?a.scale=new R(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===i.Logarithmic&&(a.scale=new V(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===i.Categorical&&(a.scale=new A(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,I(this.size),n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=I(v),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):at((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,i;const a={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:K(this.config.style.padding)}},{h:l,w:o}=this.size,r=a.layout,h=a.dims.shared.axes,c=a.dims.shared.label,d=a.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===s.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===n.Before,S=null!=p.angle,N=x.placement===n.Before;if(r.drawRect={h:l-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(i=p.angle)&&void 0!==i?i:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=Y(this.ctx,t.labelTruncated,p.font),s=a.dims.list[e].label;s.w=i.w,s.h=i.h,s.lengthCos=S?i.w*c.cos:i.w,s.lengthSin=S?i.w*c.sin:i.h,Math.abs(s.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=s.lengthCos),Math.abs(s.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=s.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=l-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=l-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=a.dims.list[e].axes,s=a.dims.list[e].label,n=a.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=Y(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(n.spaceBefore=f?s.lengthCos<0?-s.lengthCos:0:s.lengthSin>0?s.lengthSin:0,n.spaceAfter=f?s.lengthCos>0?s.lengthCos:0:s.lengthSin<0?-s.lengthSin:0):(n.spaceBefore=(f?s.lengthCos:s.lengthSin)/2,n.spaceAfter=(f?s.lengthCos:s.lengthSin)/2),N?n.spaceBefore=Math.max(n.spaceBefore,i.maxLength):n.spaceAfter=Math.max(n.spaceAfter,i.maxLength),f?(n.bound={h:l-r.padding[0]-r.padding[2],w:n.spaceBefore+n.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=n.bound.w):(n.bound={h:n.spaceBefore+n.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=n.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const n=((null==r?void 0:r.type)===a.Filter||(null==r?void 0:r.type)===a.FilterResize)&&(null==r?void 0:r.dimIndex)===e&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!n,h=n&&void 0===o.filterIndex,c=o.dimIndex===e&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===s.Horizontal?"y":"x",n=this._.dims.shared.axes.length;for(let s=0;sc>=t.p0&&c<=t.p1));let u=a.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?a.FilterResize:a.Filter}return{dimIndex:s,filterIndex:d,type:u}}}}updateActiveLabel(){var e,i;if(!this._||this.ix.shared.action.type!==t.LabelMove)return;const a=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===s.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(e,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[e]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[e][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=t.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=t.FilterResizeAfter:n.type=t.FilterMove):(n.type=t.FilterCreate,l.active={...x,p0:i,p1:i},s[e]=s[e]||[],s[e].push(l.active),n.filterIndex=s[e].length-1)}updateActiveFilter(e){var i,a,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,m=this.ix,v=m.filters,b=m.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===s.Horizontal?"y":"x";if(!(b.type===t.FilterCreate||b.type===t.FilterMove||b.type===t.FilterResizeAfter||b.type===t.FilterResizeBefore)||!v.key)return;const L=this.dimensions[b.dimIndex].key,B=y[b.dimIndex].layout.bound,E=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===t.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(a=v.active.startP1)&&void 0!==a?a:0,s=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=s):v.active.p1>=1&&(v.active.p0=1-s,v.active.p1=1)}else b.type===t.FilterResizeBefore?(v.active.p0=(b.p1[k]-B[k]-E)/g.length,v.active.p0=M(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-B[k]-E)/g.length,v.active.p1=M(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===e.type){if(D=b.p0,w=b.p1,Math.sqrt((w.x-D.x)**2+(w.y-D.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=I(t[i]);null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[L]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...x};else for(let a=t+1;a!lt(t)))}))}updateCursor(){const e=this.ix,i=e.shared.action,n=e.shared.focus,l=this.config.direction===s.Horizontal;let o="default";i.type!==t.None?i.type===t.FilterMove||i.type===t.LabelMove?o="grabbing":i.type===t.FilterResizeAfter||i.type===t.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===t.FilterCreate&&(o="crosshair"):void 0!==n&&(n.type===a.DimensionLabel?o="grab":n.type===a.DimensionAxis?o="crosshair":n.type===a.Filter?o="grab":n.type===a.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,l=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===s.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===n.Before,x=f.label.placement===n.Before;for(let s=0;s{var f,y,g,x,m,v;const S=t.key,N=i[e].layout,k=nt(e,h,N.bound),I=this.data[S][s],M=b(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let P=k.x,z=k.y;if(L)P+=u?N.axisDataStart.x:N.axisBoundaryStart.x,z+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?u?N.axisInfinityStop.x:N.axisInfinityStart.x:u?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?u?N.axisInfinityStart.y:N.axisInfinityStop.y:u?N.axisInfinityStop.y:N.axisInfinityStart.y;P+=u?N.axisDataStart.x:t,z+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;P+=N.axisDataStart.x+(u?0:e),z+=N.axisDataStart.y+(u?e:0)}if(S===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=et(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[S]&&0!==d[S].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:P,y:z}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),J(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=nt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};G(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const S=null==f.label.angle&&u,N={textAlign:S?void 0:"center",textBaseline:S?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const s=this.dimensions[e].key,n=nt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[s]||[];if(j(this.ctx,n.x+m.x,n.y+m.y,n.x+v.x,n.y+v.y,r[e].axis),this.dataInfo.hasInfinity){j(this.ctx,n.x+y.x,n.y+y.y,n.x+m.x,n.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),j(this.ctx,n.x+v.x,n.y+v.y,n.x+g.x,n.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=n.x+y.x,s=n.y+y.y,a=t+M,l=s+L;j(this.ctx,t,s,a,l,r[e].tick);const o=n.x+g.x,h=n.y+g.y,c=o+M,d=h+L;j(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:l+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";G(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";G(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=n.x+(u?p.x:o.x),i=n.y+(u?p.y:o.y),s=t+M,a=i+L;j(this.ctx,t,i,s,a,r[e].tick);const l=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;G(this.ctx,"NaN",l,h,c,I)}for(let t=0;t{const s=t.p0*l.length,a=t.p1*l.length,h=r[e].filters[i].width,c=h/2,d=n.x+o.x+(u?-c:s),f=n.y+o.y+(u?s:-c),p=u?h:a-s,y=u?a-s:h;q(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,a=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===s.Horizontal,o={strokeStyle:"#dddddd"};j(this.ctx,0,i.padding[0],e,i.padding[0],o),j(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),j(this.ctx,i.padding[3],0,i.padding[3],t,o),j(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},y={strokeStyle:"#ffcc00"};a.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;q(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),q(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),W(this.ctx,g,y),W(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=I(v),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(e){var i,n;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===s.Horizontal,u=d?"x":"y",f=d?"y":"x",p=st(e,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const e=l.focus.dimIndex,s=this._.dims.list[e].layout,d=s.bound,p=s.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===a.DimensionLabel)o.type=t.LabelMove,o.dimIndex=e,r.axis=d[u]+p[u],r.bound=d;else if([a.DimensionAxis,a.Filter,a.FilterResize].includes(null===(n=l.focus)||void 0===n?void 0:n.type)){o.type=t.FilterCreate,o.dimIndex=e,h.key=this.dimensions[e].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,e)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=I(v),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}exports.ActionType=t,exports.DimensionLayout=e,exports.DimensionType=i,exports.Direction=s,exports.FocusType=a,exports.LabelPlacement=n,exports.PathType=l,exports.default=ut; diff --git a/dist/hermes.esm.js b/dist/hermes.esm.js index 0a5ec58..359be6b 100644 --- a/dist/hermes.esm.js +++ b/dist/hermes.esm.js @@ -1 +1 @@ -const t={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},e={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},i={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},s={Horizontal:"horizontal",Vertical:"vertical"},a={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},n={After:"after",Before:"before"},l={Bezier:"bezier",Straight:"straight"},o=Number.NaN,r={x:Number.NaN,y:Number.NaN},h={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},c={dimIndex:-1,p0:r,p1:r,type:t.None},d="normal 12px san-serif",u="butt",f="round",p=10,y="black",g={debug:!1,direction:s.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:n.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:l.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:n.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:e.AxisEvenlySpaced},padding:[32,64]}},x={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},m=.01,v={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:x,key:void 0},shared:{action:c,focus:void 0}},b=t=>"number"==typeof t,S=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!N(t),N=t=>t instanceof Set,k=t=>"string"==typeof t,I=t=>JSON.parse(JSON.stringify(t)),M=(t,e)=>Math.min(e[1],Math.max(e[0],t)),L=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{S(t[i])&&S(e[i])?t[i]=L(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),B=(t,e)=>t.reduce(((t,s)=>(b(s)&&!isNaN(s)&&((t=>e===i.Logarithmic?isFinite(Math.log(t)):isFinite(t))(s)&&(st.finite[1]&&(t.finite[1]=s)),st.actual[1]&&(t.actual[1]=s)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),E=(t,e)=>t[e%t.length],D=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},w=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],z=(t,e,i={})=>{if(null!=i.includeNaN){const t=M(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},O=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},F=t=>k(t)?t:t.toString();class C{constructor(t,e,i,a={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=a.dataOnEdge&&(this.dataOnEdge=a.dataOnEdge),this.reverse=t===s.Horizontal?null!=a.reverse&&a.reverse:null==a.reverse||!a.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class A extends C{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>F(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const _=t=>e=>Math.log(e)/Math.log(t);class V extends C{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=_(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!b(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=_(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=P(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const H=(t,e)=>t.x*e.x+t.y*e.y,$=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=H(a,a),r=H(a,n),h=H(a,l),c=H(n,n),d=H(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},W=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle||y,t.beginPath(),t.moveTo(e[0].x,e[0].y);const o=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle||y,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(Z(e),Z(i)),t.lineTo(Z(s),Z(a)),t.stroke(),t.restore()},q=(t,e,i,s,a,n={})=>{t.save();const l=Z(e),o=Z(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(U(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(U(t,l,o,s,a,r),t.stroke())),t.restore()},U=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},G=(t,e,i,s,a,n={})=>{const l=Q(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),tt(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},X=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Q(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},Y=(t,e,i=d)=>{tt(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},K=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Q=t=>(t+2*Math.PI)%(2*Math.PI),Z=t=>Math.round(t-.5)+.5,tt=(t,e=d)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},et=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(it(t[a]),it(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},it=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},st=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},at=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},nt=(e,i,s)=>{const a=i.shared.action,n=a.type===t.LabelMove&&a.dimIndex===e,l=i.dimension.bound||h,o=i.dimension.boundOffset||{x:0,y:0};return n?(c=o,{h:(r=l).h,w:r.w,x:r.x+c.x,y:r.y+c.y}):s;var r,c},lt=t=>isNaN(t.p0)&&isNaN(t.p1),ot=(t,e)=>{const i=I(x);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},rt={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ht=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:i.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:i.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:i.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:i.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:i.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:i.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:i.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:i.Linear}],ct=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:i.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:i.Logarithmic}];var dt=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:rt,dimensionSamples:ht,metricDimensionSamples:ct,generateData:(t,e,s=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===i.Categorical){if(n.categories)return s?w(n.categories):E(n.categories,l)}else if(n.type===i.Linear){const t=rt[n.key];if(t)return s?z(t[1],t[0],a):D(t[1],t[0],e,l,a)}else if(n.type===i.Logarithmic){const t=rt[n.key];if(t&&n.logBase)return s?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=z(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**D(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return o})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?w(ht):E(ht,i))),s=e?w(ct):E(ct,0);return i.push(s),i}});class ut{constructor(t,e,i,s){this.config=g,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=I(v),this._=void 0;const a=(t=>k(t)?document.querySelector(t):t)(t);if(!a)throw new T("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new T("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new T("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):at((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return L(...t)}static getTester(){return dt}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const a=ut.validateDimensions(t);if(!a.valid)throw new T(a.message);const n=this.config.direction===s.Horizontal?s.Vertical:s.Horizontal;this.dimensionsOriginal=t,this.dimensions=I(t).map((t=>{const e=t.key,s=this.data[e]||[],a={...t,labelTruncated:O(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new R(n,0,100,0,100)};if(t.type===i.Linear||t.type===i.Logarithmic){const e=B(s,t.type);t.type===i.Linear?a.scale=new R(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===i.Logarithmic&&(a.scale=new V(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===i.Categorical&&(a.scale=new A(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,this.size,n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=I(v),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):at((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,i;const a={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:K(this.config.style.padding)}},{h:l,w:o}=this.size,r=a.layout,h=a.dims.shared.axes,c=a.dims.shared.label,d=a.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===s.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===n.Before,S=null!=p.angle,N=x.placement===n.Before;if(r.drawRect={h:l-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(i=p.angle)&&void 0!==i?i:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=Y(this.ctx,t.labelTruncated,p.font),s=a.dims.list[e].label;s.w=i.w,s.h=i.h,s.lengthCos=S?i.w*c.cos:i.w,s.lengthSin=S?i.w*c.sin:i.h,Math.abs(s.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=s.lengthCos),Math.abs(s.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=s.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=l-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=l-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=a.dims.list[e].axes,s=a.dims.list[e].label,n=a.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=Y(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(n.spaceBefore=f?s.lengthCos<0?-s.lengthCos:0:s.lengthSin>0?s.lengthSin:0,n.spaceAfter=f?s.lengthCos>0?s.lengthCos:0:s.lengthSin<0?-s.lengthSin:0):(n.spaceBefore=(f?s.lengthCos:s.lengthSin)/2,n.spaceAfter=(f?s.lengthCos:s.lengthSin)/2),N?n.spaceBefore=Math.max(n.spaceBefore,i.maxLength):n.spaceAfter=Math.max(n.spaceAfter,i.maxLength),f?(n.bound={h:l-r.padding[0]-r.padding[2],w:n.spaceBefore+n.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=n.bound.w):(n.bound={h:n.spaceBefore+n.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=n.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const n=((null==r?void 0:r.type)===a.Filter||(null==r?void 0:r.type)===a.FilterResize)&&(null==r?void 0:r.dimIndex)===e&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!n,h=n&&void 0===o.filterIndex,c=o.dimIndex===e&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===s.Horizontal?"y":"x",n=this._.dims.shared.axes.length;for(let s=0;sc>=t.p0&&c<=t.p1));let u=a.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?a.FilterResize:a.Filter}return{dimIndex:s,filterIndex:d,type:u}}}}updateActiveLabel(){var e,i;if(!this._||this.ix.shared.action.type!==t.LabelMove)return;const a=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===s.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(e,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[e]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[e][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=t.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=t.FilterResizeAfter:n.type=t.FilterMove):(n.type=t.FilterCreate,l.active={...x,p0:i,p1:i},s[e]=s[e]||[],s[e].push(l.active),n.filterIndex=s[e].length-1)}updateActiveFilter(e){var i,a,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,m=this.ix,v=m.filters,b=m.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===s.Horizontal?"y":"x";if(!(b.type===t.FilterCreate||b.type===t.FilterMove||b.type===t.FilterResizeAfter||b.type===t.FilterResizeBefore)||!v.key)return;const I=this.dimensions[b.dimIndex].key,L=y[b.dimIndex].layout.bound,B=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===t.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(a=v.active.startP1)&&void 0!==a?a:0,s=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=s):v.active.p1>=1&&(v.active.p0=1-s,v.active.p1=1)}else b.type===t.FilterResizeBefore?(v.active.p0=(b.p1[k]-L[k]-B)/g.length,v.active.p0=M(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-L[k]-B)/g.length,v.active.p1=M(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===e.type){if(E=b.p0,D=b.p1,Math.sqrt((D.x-E.x)**2+(D.y-E.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=t[i];null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[I]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...x};else for(let a=t+1;a!lt(t)))}))}updateCursor(){const e=this.ix,i=e.shared.action,n=e.shared.focus,l=this.config.direction===s.Horizontal;let o="default";i.type!==t.None?i.type===t.FilterMove||i.type===t.LabelMove?o="grabbing":i.type===t.FilterResizeAfter||i.type===t.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===t.FilterCreate&&(o="crosshair"):void 0!==n&&(n.type===a.DimensionLabel?o="grab":n.type===a.DimensionAxis?o="crosshair":n.type===a.Filter?o="grab":n.type===a.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,l=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===s.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===n.Before,x=f.label.placement===n.Before;for(let s=0;s{var f,y,g,x,m,v;const S=t.key,N=i[e].layout,k=nt(e,h,N.bound),I=this.data[S][s],M=b(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let z=k.x,P=k.y;if(L)z+=u?N.axisDataStart.x:N.axisBoundaryStart.x,P+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?N.axisInfinityStop.y:N.axisInfinityStart.y;z+=u?N.axisDataStart.x:t,P+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;z+=N.axisDataStart.x+(u?0:e),P+=N.axisDataStart.y+(u?e:0)}if(S===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=et(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[S]&&0!==d[S].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:z,y:P}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),J(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=nt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};G(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const S=null==f.label.angle&&u,N={textAlign:S?void 0:"center",textBaseline:S?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const s=this.dimensions[e].key,n=nt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[s]||[];if(j(this.ctx,n.x+m.x,n.y+m.y,n.x+v.x,n.y+v.y,r[e].axis),this.dataInfo.hasInfinity){j(this.ctx,n.x+y.x,n.y+y.y,n.x+m.x,n.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),j(this.ctx,n.x+v.x,n.y+v.y,n.x+g.x,n.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=n.x+y.x,s=n.y+y.y,a=t+M,l=s+L;j(this.ctx,t,s,a,l,r[e].tick);const o=n.x+g.x,h=n.y+g.y,c=o+M,d=h+L;j(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:l+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";G(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";G(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=n.x+(u?p.x:o.x),i=n.y+(u?p.y:o.y),s=t+M,a=i+L;j(this.ctx,t,i,s,a,r[e].tick);const l=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;G(this.ctx,"NaN",l,h,c,I)}for(let t=0;t{const s=t.p0*l.length,a=t.p1*l.length,h=r[e].filters[i].width,c=h/2,d=n.x+o.x+(u?-c:s),f=n.y+o.y+(u?s:-c),p=u?h:a-s,y=u?a-s:h;q(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,a=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===s.Horizontal,o={strokeStyle:"#dddddd"};j(this.ctx,0,i.padding[0],e,i.padding[0],o),j(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),j(this.ctx,i.padding[3],0,i.padding[3],t,o),j(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},y={strokeStyle:"#ffcc00"};a.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;q(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),q(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),W(this.ctx,g,y),W(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=I(v),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(e){var i,n;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===s.Horizontal,u=d?"x":"y",f=d?"y":"x",p=st(e,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const e=l.focus.dimIndex,s=this._.dims.list[e].layout,d=s.bound,p=s.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===a.DimensionLabel)o.type=t.LabelMove,o.dimIndex=e,r.axis=d[u]+p[u],r.bound=d;else if([a.DimensionAxis,a.Filter,a.FilterResize].includes(null===(n=l.focus)||void 0===n?void 0:n.type)){o.type=t.FilterCreate,o.dimIndex=e,h.key=this.dimensions[e].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,e)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=I(v),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}export{t as ActionType,e as DimensionLayout,i as DimensionType,s as Direction,a as FocusType,n as LabelPlacement,l as PathType,ut as default}; +const t={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},e={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},i={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},s={Horizontal:"horizontal",Vertical:"vertical"},a={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},n={After:"after",Before:"before"},l={Bezier:"bezier",Straight:"straight"},o=Number.NaN,r={x:Number.NaN,y:Number.NaN},h={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},c={dimIndex:-1,p0:r,p1:r,type:t.None},d="normal 12px san-serif",u="butt",f="round",p=10,y="black",g={debug:!1,direction:s.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:n.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:l.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:n.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:e.AxisEvenlySpaced},padding:[32,64]}},x={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},m=.01,v={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:x,key:void 0},shared:{action:c,focus:void 0}},b=t=>"number"==typeof t,S=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!N(t),N=t=>t instanceof Set,k=t=>"string"==typeof t,I=t=>JSON.parse(JSON.stringify(t)),M=(t,e)=>Math.min(e[1],Math.max(e[0],t)),L=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{S(t[i])&&S(e[i])?t[i]=L(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),B=(t,e)=>t.reduce(((t,s)=>(b(s)&&!isNaN(s)&&((t=>e===i.Logarithmic?isFinite(Math.log(t)):isFinite(t))(s)&&(st.finite[1]&&(t.finite[1]=s)),st.actual[1]&&(t.actual[1]=s)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),E=(t,e)=>t[e%t.length],D=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},w=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],z=(t,e,i={})=>{if(null!=i.includeNaN){const t=M(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},O=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},F=t=>k(t)?t:t.toString();class C{constructor(t,e,i,a={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=a.dataOnEdge&&(this.dataOnEdge=a.dataOnEdge),this.reverse=t===s.Horizontal?null!=a.reverse&&a.reverse:null==a.reverse||!a.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class A extends C{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>F(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const _=t=>e=>Math.log(e)/Math.log(t);class V extends C{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=_(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!b(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=_(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=P(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const H=(t,e)=>t.x*e.x+t.y*e.y,$=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=H(a,a),r=H(a,n),h=H(a,l),c=H(n,n),d=H(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},W=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle||y,t.beginPath(),t.moveTo(e[0].x,e[0].y);const o=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle||y,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(Z(e),Z(i)),t.lineTo(Z(s),Z(a)),t.stroke(),t.restore()},q=(t,e,i,s,a,n={})=>{t.save();const l=Z(e),o=Z(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(U(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(U(t,l,o,s,a,r),t.stroke())),t.restore()},U=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},G=(t,e,i,s,a,n={})=>{const l=Q(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),tt(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||u,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||f,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||p,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},X=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Q(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},Y=(t,e,i=d)=>{tt(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},K=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Q=t=>(t+2*Math.PI)%(2*Math.PI),Z=t=>Math.round(t-.5)+.5,tt=(t,e=d)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},et=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(it(t[a]),it(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},it=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},st=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},at=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},nt=(e,i,s)=>{const a=i.shared.action,n=a.type===t.LabelMove&&a.dimIndex===e,l=i.dimension.bound||h,o=i.dimension.boundOffset||{x:0,y:0};return n?(c=o,{h:(r=l).h,w:r.w,x:r.x+c.x,y:r.y+c.y}):s;var r,c},lt=t=>isNaN(t.p0)&&isNaN(t.p1),ot=(t,e)=>{const i=I(x);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},rt={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ht=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:i.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:i.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:i.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:i.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:i.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:i.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:i.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:i.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:i.Linear}],ct=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:i.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:i.Logarithmic}];var dt=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:rt,dimensionSamples:ht,metricDimensionSamples:ct,generateData:(t,e,s=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===i.Categorical){if(n.categories)return s?w(n.categories):E(n.categories,l)}else if(n.type===i.Linear){const t=rt[n.key];if(t)return s?z(t[1],t[0],a):D(t[1],t[0],e,l,a)}else if(n.type===i.Logarithmic){const t=rt[n.key];if(t&&n.logBase)return s?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=z(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**D(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return o})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?w(ht):E(ht,i))),s=e?w(ct):E(ct,0);return i.push(s),i}});class ut{constructor(t,e,i,s){this.config=g,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=I(v),this._=void 0;const a=(t=>k(t)?document.querySelector(t):t)(t);if(!a)throw new T("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new T("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new T("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):at((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return L(...t)}static getTester(){return dt}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const a=ut.validateDimensions(t);if(!a.valid)throw new T(a.message);const n=this.config.direction===s.Horizontal?s.Vertical:s.Horizontal;this.dimensionsOriginal=t,this.dimensions=I(t).map((t=>{const e=t.key,s=this.data[e]||[],a={...t,labelTruncated:O(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new R(n,0,100,0,100)};if(t.type===i.Linear||t.type===i.Logarithmic){const e=B(s,t.type);t.type===i.Linear?a.scale=new R(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===i.Logarithmic&&(a.scale=new V(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===i.Categorical&&(a.scale=new A(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,I(this.size),n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=I(v),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):at((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,i;const a={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:K(this.config.style.padding)}},{h:l,w:o}=this.size,r=a.layout,h=a.dims.shared.axes,c=a.dims.shared.label,d=a.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===s.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===n.Before,S=null!=p.angle,N=x.placement===n.Before;if(r.drawRect={h:l-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(i=p.angle)&&void 0!==i?i:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=Y(this.ctx,t.labelTruncated,p.font),s=a.dims.list[e].label;s.w=i.w,s.h=i.h,s.lengthCos=S?i.w*c.cos:i.w,s.lengthSin=S?i.w*c.sin:i.h,Math.abs(s.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=s.lengthCos),Math.abs(s.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=s.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=l-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=l-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=a.dims.list[e].axes,s=a.dims.list[e].label,n=a.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=Y(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(n.spaceBefore=f?s.lengthCos<0?-s.lengthCos:0:s.lengthSin>0?s.lengthSin:0,n.spaceAfter=f?s.lengthCos>0?s.lengthCos:0:s.lengthSin<0?-s.lengthSin:0):(n.spaceBefore=(f?s.lengthCos:s.lengthSin)/2,n.spaceAfter=(f?s.lengthCos:s.lengthSin)/2),N?n.spaceBefore=Math.max(n.spaceBefore,i.maxLength):n.spaceAfter=Math.max(n.spaceAfter,i.maxLength),f?(n.bound={h:l-r.padding[0]-r.padding[2],w:n.spaceBefore+n.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=n.bound.w):(n.bound={h:n.spaceBefore+n.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=n.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const n=((null==r?void 0:r.type)===a.Filter||(null==r?void 0:r.type)===a.FilterResize)&&(null==r?void 0:r.dimIndex)===e&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!n,h=n&&void 0===o.filterIndex,c=o.dimIndex===e&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===s.Horizontal?"y":"x",n=this._.dims.shared.axes.length;for(let s=0;sc>=t.p0&&c<=t.p1));let u=a.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?a.FilterResize:a.Filter}return{dimIndex:s,filterIndex:d,type:u}}}}updateActiveLabel(){var e,i;if(!this._||this.ix.shared.action.type!==t.LabelMove)return;const a=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===s.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(e,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[e]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[e][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=t.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=t.FilterResizeAfter:n.type=t.FilterMove):(n.type=t.FilterCreate,l.active={...x,p0:i,p1:i},s[e]=s[e]||[],s[e].push(l.active),n.filterIndex=s[e].length-1)}updateActiveFilter(e){var i,a,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,m=this.ix,v=m.filters,b=m.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===s.Horizontal?"y":"x";if(!(b.type===t.FilterCreate||b.type===t.FilterMove||b.type===t.FilterResizeAfter||b.type===t.FilterResizeBefore)||!v.key)return;const L=this.dimensions[b.dimIndex].key,B=y[b.dimIndex].layout.bound,E=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===t.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(a=v.active.startP1)&&void 0!==a?a:0,s=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=s):v.active.p1>=1&&(v.active.p0=1-s,v.active.p1=1)}else b.type===t.FilterResizeBefore?(v.active.p0=(b.p1[k]-B[k]-E)/g.length,v.active.p0=M(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-B[k]-E)/g.length,v.active.p1=M(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===e.type){if(D=b.p0,w=b.p1,Math.sqrt((w.x-D.x)**2+(w.y-D.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=I(t[i]);null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[L]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...x};else for(let a=t+1;a!lt(t)))}))}updateCursor(){const e=this.ix,i=e.shared.action,n=e.shared.focus,l=this.config.direction===s.Horizontal;let o="default";i.type!==t.None?i.type===t.FilterMove||i.type===t.LabelMove?o="grabbing":i.type===t.FilterResizeAfter||i.type===t.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===t.FilterCreate&&(o="crosshair"):void 0!==n&&(n.type===a.DimensionLabel?o="grab":n.type===a.DimensionAxis?o="crosshair":n.type===a.Filter?o="grab":n.type===a.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,l=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===s.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===n.Before,x=f.label.placement===n.Before;for(let s=0;s{var f,y,g,x,m,v;const S=t.key,N=i[e].layout,k=nt(e,h,N.bound),I=this.data[S][s],M=b(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let z=k.x,P=k.y;if(L)z+=u?N.axisDataStart.x:N.axisBoundaryStart.x,P+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?u?N.axisInfinityStop.x:N.axisInfinityStart.x:u?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?u?N.axisInfinityStart.y:N.axisInfinityStop.y:u?N.axisInfinityStop.y:N.axisInfinityStart.y;z+=u?N.axisDataStart.x:t,P+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;z+=N.axisDataStart.x+(u?0:e),P+=N.axisDataStart.y+(u?e:0)}if(S===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=et(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[S]&&0!==d[S].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:z,y:P}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),J(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=nt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};G(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const S=null==f.label.angle&&u,N={textAlign:S?void 0:"center",textBaseline:S?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const s=this.dimensions[e].key,n=nt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[s]||[];if(j(this.ctx,n.x+m.x,n.y+m.y,n.x+v.x,n.y+v.y,r[e].axis),this.dataInfo.hasInfinity){j(this.ctx,n.x+y.x,n.y+y.y,n.x+m.x,n.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),j(this.ctx,n.x+v.x,n.y+v.y,n.x+g.x,n.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=n.x+y.x,s=n.y+y.y,a=t+M,l=s+L;j(this.ctx,t,s,a,l,r[e].tick);const o=n.x+g.x,h=n.y+g.y,c=o+M,d=h+L;j(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:l+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";G(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";G(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=n.x+(u?p.x:o.x),i=n.y+(u?p.y:o.y),s=t+M,a=i+L;j(this.ctx,t,i,s,a,r[e].tick);const l=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;G(this.ctx,"NaN",l,h,c,I)}for(let t=0;t{const s=t.p0*l.length,a=t.p1*l.length,h=r[e].filters[i].width,c=h/2,d=n.x+o.x+(u?-c:s),f=n.y+o.y+(u?s:-c),p=u?h:a-s,y=u?a-s:h;q(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,a=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===s.Horizontal,o={strokeStyle:"#dddddd"};j(this.ctx,0,i.padding[0],e,i.padding[0],o),j(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),j(this.ctx,i.padding[3],0,i.padding[3],t,o),j(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},y={strokeStyle:"#ffcc00"};a.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;q(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),q(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||u,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||f,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||p,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),W(this.ctx,g,y),W(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=I(v),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(e){var i,n;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===s.Horizontal,u=d?"x":"y",f=d?"y":"x",p=st(e,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const e=l.focus.dimIndex,s=this._.dims.list[e].layout,d=s.bound,p=s.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===a.DimensionLabel)o.type=t.LabelMove,o.dimIndex=e,r.axis=d[u]+p[u],r.bound=d;else if([a.DimensionAxis,a.Filter,a.FilterResize].includes(null===(n=l.focus)||void 0===n?void 0:n.type)){o.type=t.FilterCreate,o.dimIndex=e,h.key=this.dimensions[e].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,e)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=st(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=I(v),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}export{t as ActionType,e as DimensionLayout,i as DimensionType,s as Direction,a as FocusType,n as LabelPlacement,l as PathType,ut as default}; diff --git a/dist/hermes.iife.js b/dist/hermes.iife.js index bc80842..3e59541 100644 --- a/dist/hermes.iife.js +++ b/dist/hermes.iife.js @@ -1 +1 @@ -var Hermes=function(t){"use strict";const e={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},i={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},s={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},a={Horizontal:"horizontal",Vertical:"vertical"},n={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},l={After:"after",Before:"before"},o={Bezier:"bezier",Straight:"straight"},r=Number.NaN,h={x:Number.NaN,y:Number.NaN},c={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},d={dimIndex:-1,p0:h,p1:h,type:e.None},u="normal 12px san-serif",f="butt",p="round",y=10,g="black",x={debug:!1,direction:a.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:l.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:o.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:l.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:i.AxisEvenlySpaced},padding:[32,64]}},m={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},v=.01,b={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:m,key:void 0},shared:{action:d,focus:void 0}},S=t=>"number"==typeof t,N=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!k(t),k=t=>t instanceof Set,I=t=>"string"==typeof t,M=t=>JSON.parse(JSON.stringify(t)),L=(t,e)=>Math.min(e[1],Math.max(e[0],t)),B=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{N(t[i])&&N(e[i])?t[i]=B(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),E=(t,e)=>t.reduce(((t,i)=>(S(i)&&!isNaN(i)&&((t=>e===s.Logarithmic?isFinite(Math.log(t)):isFinite(t))(i)&&(it.finite[1]&&(t.finite[1]=i)),it.actual[1]&&(t.actual[1]=i)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),D=(t,e)=>t[e%t.length],w=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},P=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],z=(t,e,i={})=>{if(null!=i.includeNaN){const t=L(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},F=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},C=t=>I(t)?t:t.toString();class A{constructor(t,e,i,s={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=s.dataOnEdge&&(this.dataOnEdge=s.dataOnEdge),this.reverse=t===a.Horizontal?null!=s.reverse&&s.reverse:null==s.reverse||!s.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class T extends A{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>C(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const V=t=>e=>Math.log(e)/Math.log(t);class H extends A{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=V(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!S(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=V(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=O(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const $=(t,e)=>t.x*e.x+t.y*e.y,W=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=$(a,a),r=$(a,n),h=$(a,l),c=$(n,n),d=$(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},J=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle||g,t.beginPath(),t.moveTo(e[0].x,e[0].y);const l=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle||g,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(tt(e),tt(i)),t.lineTo(tt(s),tt(a)),t.stroke(),t.restore()},U=(t,e,i,s,a,n={})=>{t.save();const l=tt(e),o=tt(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(G(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(G(t,l,o,s,a,r),t.stroke())),t.restore()},G=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},X=(t,e,i,s,a,n={})=>{const l=Z(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),et(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},Y=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Z(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},K=(t,e,i=u)=>{et(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},Q=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Z=t=>(t+2*Math.PI)%(2*Math.PI),tt=t=>Math.round(t-.5)+.5,et=(t,e=u)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},it=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(st(t[a]),st(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},st=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},at=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},nt=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},lt=(t,i,s)=>{const a=i.shared.action,n=a.type===e.LabelMove&&a.dimIndex===t,l=i.dimension.bound||c,o=i.dimension.boundOffset||{x:0,y:0};return n?(h=o,{h:(r=l).h,w:r.w,x:r.x+h.x,y:r.y+h.y}):s;var r,h},ot=t=>isNaN(t.p0)&&isNaN(t.p1),rt=(t,e)=>{const i=M(m);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},ht={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ct=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:s.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:s.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:s.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:s.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:s.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:s.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:s.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:s.Linear}],dt=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:s.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:s.Logarithmic}];var ut=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:ht,dimensionSamples:ct,metricDimensionSamples:dt,generateData:(t,e,i=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===s.Categorical){if(n.categories)return i?P(n.categories):D(n.categories,l)}else if(n.type===s.Linear){const t=ht[n.key];if(t)return i?z(t[1],t[0],a):w(t[1],t[0],e,l,a)}else if(n.type===s.Logarithmic){const t=ht[n.key];if(t&&n.logBase)return i?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=z(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**w(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return r})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?P(ct):D(ct,i))),s=e?P(dt):D(dt,0);return i.push(s),i}});class ft{constructor(t,e,i,s){this.config=x,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=M(b),this._=void 0;const a=(t=>I(t)?document.querySelector(t):t)(t);if(!a)throw new R("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new R("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new R("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):nt((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return B(...t)}static getTester(){return ut}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const i=ft.validateDimensions(t);if(!i.valid)throw new R(i.message);const n=this.config.direction===a.Horizontal?a.Vertical:a.Horizontal;this.dimensionsOriginal=t,this.dimensions=M(t).map((t=>{const e=t.key,i=this.data[e]||[],a={...t,labelTruncated:F(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new _(n,0,100,0,100)};if(t.type===s.Linear||t.type===s.Logarithmic){const e=E(i,t.type);t.type===s.Linear?a.scale=new _(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===s.Logarithmic&&(a.scale=new H(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===s.Categorical&&(a.scale=new T(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,this.size,n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=M(b),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):nt((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,e;const s={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:Q(this.config.style.padding)}},{h:n,w:o}=this.size,r=s.layout,h=s.dims.shared.axes,c=s.dims.shared.label,d=s.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===a.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===l.Before,S=null!=p.angle,N=x.placement===l.Before;if(r.drawRect={h:n-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(e=p.angle)&&void 0!==e?e:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=K(this.ctx,t.labelTruncated,p.font),a=s.dims.list[e].label;a.w=i.w,a.h=i.h,a.lengthCos=S?i.w*c.cos:i.w,a.lengthSin=S?i.w*c.sin:i.h,Math.abs(a.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=a.lengthCos),Math.abs(a.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=a.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=n-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=n-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=s.dims.list[e].axes,a=s.dims.list[e].label,l=s.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=K(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(l.spaceBefore=f?a.lengthCos<0?-a.lengthCos:0:a.lengthSin>0?a.lengthSin:0,l.spaceAfter=f?a.lengthCos>0?a.lengthCos:0:a.lengthSin<0?-a.lengthSin:0):(l.spaceBefore=(f?a.lengthCos:a.lengthSin)/2,l.spaceAfter=(f?a.lengthCos:a.lengthSin)/2),N?l.spaceBefore=Math.max(l.spaceBefore,i.maxLength):l.spaceAfter=Math.max(l.spaceAfter,i.maxLength),f?(l.bound={h:n-r.padding[0]-r.padding[2],w:l.spaceBefore+l.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=l.bound.w):(l.bound={h:l.spaceBefore+l.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=l.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const a=((null==r?void 0:r.type)===n.Filter||(null==r?void 0:r.type)===n.FilterResize)&&(null==r?void 0:r.dimIndex)===t&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!a,h=a&&void 0===o.filterIndex,c=o.dimIndex===t&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===a.Horizontal?"y":"x",s=this._.dims.shared.axes.length;for(let a=0;ac>=t.p0&&c<=t.p1));let u=n.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?n.FilterResize:n.Filter}return{dimIndex:a,filterIndex:d,type:u}}}}updateActiveLabel(){var t,i;if(!this._||this.ix.shared.action.type!==e.LabelMove)return;const s=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===a.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(t,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[t]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[t][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=e.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=e.FilterResizeAfter:n.type=e.FilterMove):(n.type=e.FilterCreate,l.active={...m,p0:i,p1:i},s[t]=s[t]||[],s[t].push(l.active),n.filterIndex=s[t].length-1)}updateActiveFilter(t){var i,s,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,x=this.ix,v=x.filters,b=x.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===a.Horizontal?"y":"x";if(!(b.type===e.FilterCreate||b.type===e.FilterMove||b.type===e.FilterResizeAfter||b.type===e.FilterResizeBefore)||!v.key)return;const I=this.dimensions[b.dimIndex].key,M=y[b.dimIndex].layout.bound,B=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===e.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(s=v.active.startP1)&&void 0!==s?s:0,a=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=a):v.active.p1>=1&&(v.active.p0=1-a,v.active.p1=1)}else b.type===e.FilterResizeBefore?(v.active.p0=(b.p1[k]-M[k]-B)/g.length,v.active.p0=L(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-M[k]-B)/g.length,v.active.p1=L(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===t.type){if(E=b.p0,D=b.p1,Math.sqrt((D.x-E.x)**2+(D.y-E.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=t[i];null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[I]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...m};else for(let a=t+1;a!ot(t)))}))}updateCursor(){const t=this.ix,i=t.shared.action,s=t.shared.focus,l=this.config.direction===a.Horizontal;let o="default";i.type!==e.None?i.type===e.FilterMove||i.type===e.LabelMove?o="grabbing":i.type===e.FilterResizeAfter||i.type===e.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===e.FilterCreate&&(o="crosshair"):void 0!==s&&(s.type===n.DimensionLabel?o="grab":s.type===n.DimensionAxis?o="crosshair":s.type===n.Filter?o="grab":s.type===n.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,s=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===a.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===l.Before,x=f.label.placement===l.Before;for(let s=0;s{var f,y,g,x,m,v;const b=t.key,N=i[e].layout,k=lt(e,h,N.bound),I=this.data[b][s],M=S(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let P=k.x,z=k.y;if(L)P+=u?N.axisDataStart.x:N.axisBoundaryStart.x,z+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?N.axisInfinityStop.y:N.axisInfinityStart.y;P+=u?N.axisDataStart.x:t,z+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;P+=N.axisDataStart.x+(u?0:e),z+=N.axisDataStart.y+(u?e:0)}if(b===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=it(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[b]&&0!==d[b].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:P,y:z}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),j(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=lt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};X(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const b=null==f.label.angle&&u,N={textAlign:b?void 0:"center",textBaseline:b?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const a=this.dimensions[e].key,l=lt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[a]||[];if(q(this.ctx,l.x+m.x,l.y+m.y,l.x+v.x,l.y+v.y,r[e].axis),this.dataInfo.hasInfinity){q(this.ctx,l.x+y.x,l.y+y.y,l.x+m.x,l.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),q(this.ctx,l.x+v.x,l.y+v.y,l.x+g.x,l.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=l.x+y.x,s=l.y+y.y,a=t+M,n=s+L;q(this.ctx,t,s,a,n,r[e].tick);const o=l.x+g.x,h=l.y+g.y,c=o+M,d=h+L;q(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:n+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";X(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";X(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=l.x+(u?p.x:o.x),i=l.y+(u?p.y:o.y),s=t+M,a=i+L;q(this.ctx,t,i,s,a,r[e].tick);const n=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;X(this.ctx,"NaN",n,h,c,I)}for(let t=0;t{const a=t.p0*s.length,n=t.p1*s.length,h=r[e].filters[i].width,c=h/2,d=l.x+o.x+(u?-c:a),f=l.y+o.y+(u?a:-c),p=u?h:n-a,y=u?n-a:h;U(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,s=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===a.Horizontal,o={strokeStyle:"#dddddd"};q(this.ctx,0,i.padding[0],e,i.padding[0],o),q(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),q(this.ctx,i.padding[3],0,i.padding[3],t,o),q(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},u={strokeStyle:"#ffcc00"};s.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;U(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),U(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),J(this.ctx,g,u),J(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=M(b),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(t){var i,s;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===a.Horizontal,u=d?"x":"y",f=d?"y":"x",p=at(t,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const t=l.focus.dimIndex,a=this._.dims.list[t].layout,d=a.bound,p=a.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===n.DimensionLabel)o.type=e.LabelMove,o.dimIndex=t,r.axis=d[u]+p[u],r.bound=d;else if([n.DimensionAxis,n.Filter,n.FilterResize].includes(null===(s=l.focus)||void 0===s?void 0:s.type)){o.type=e.FilterCreate,o.dimIndex=t,h.key=this.dimensions[t].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,t)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=M(b),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}return t.ActionType=e,t.DimensionLayout=i,t.DimensionType=s,t.Direction=a,t.FocusType=n,t.LabelPlacement=l,t.PathType=o,t.default=ft,t}({}); +var Hermes=function(t){"use strict";const e={FilterCreate:"filter-create",FilterMove:"filter-move",FilterResizeAfter:"filter-resize-after",FilterResizeBefore:"filter-resize-before",LabelMove:"label-move",None:"none"},i={AxisEvenlySpaced:"axis-evenly-spaced",Equidistant:"equidistant"},s={Categorical:"categorical",Linear:"linear",Logarithmic:"logarithmic"},a={Horizontal:"horizontal",Vertical:"vertical"},n={DimensionAxis:"dimension-axis",DimensionLabel:"dimension-label",Filter:"filter",FilterResize:"filter-resize"},l={After:"after",Before:"before"},o={Bezier:"bezier",Straight:"straight"},r=Number.NaN,h={x:Number.NaN,y:Number.NaN},c={h:Number.NaN,w:Number.NaN,x:Number.NaN,y:Number.NaN},d={dimIndex:-1,p0:h,p1:h,type:e.None},u="normal 12px san-serif",f="butt",p="round",y=10,g="black",x={debug:!1,direction:a.Horizontal,filters:{},hooks:{},interactions:{throttleDelayMouseMove:50,throttleDelayResize:50},style:{axes:{axis:{boundaryPadding:15,infLineDash:[2,4],infOffset:24,lineWidth:1,nanGap:24,strokeStyle:"rgba(147, 147, 147, 1.0)"},axisActive:{lineWidth:3,strokeStyle:"rgba(99, 200, 255, 1.0)"},axisHover:{lineWidth:3,strokeStyle:"rgba(79, 180, 246, 1.0)"},filter:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",strokeStyle:"rgba(255, 255, 255, 1.0)",width:4},filterActive:{cornerRadius:3,fillStyle:"rgba(255, 120, 220, 1.0)",width:8},filterAxisHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:6},filterHover:{cornerRadius:2,fillStyle:"rgba(235, 100, 200, 1.0)",width:8},label:{fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:4,placement:l.After,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(0, 0, 0, 1.0)"},labelHover:{fillStyle:"rgba(0, 0, 0, 1.0)"},tick:{length:4,lineWidth:1,strokeStyle:"rgba(147, 147, 147, 1.0)"},tickActive:{strokeStyle:"rgba(99, 200, 255, 1.0)"},tickHover:{strokeStyle:"rgba(79, 180, 246, 1.0)"}},data:{default:{lineWidth:1,strokeStyle:"rgba(82, 144, 244, 1.0)"},filtered:{lineWidth:1,strokeStyle:"rgba(0, 0, 0, 0.05)"},overrideNaN:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overrideNegativeInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},overridePositiveInfinity:{lineWidth:1,strokeStyle:"rgba(255, 0, 0, 0.2)"},path:{options:{},type:o.Straight},series:[]},dimension:{label:{angle:void 0,boundaryPadding:5,fillStyle:"rgba(0, 0, 0, 1.0)",font:"normal 11px sans-serif",lineWidth:3,offset:16,placement:l.Before,strokeStyle:"rgba(255, 255, 255, 1.0)"},labelActive:{fillStyle:"rgba(99, 200, 255, 1.0)"},labelHover:{fillStyle:"rgba(79, 180, 246, 1.0)"},layout:i.AxisEvenlySpaced},padding:[32,64]}},m={hasNaN:!1,hasNegativeInfinity:!1,hasPositiveInfinity:!1,p0:Number.NaN,p1:Number.NaN,percent0:Number.NaN,percent1:Number.NaN,value0:Number.NaN,value1:Number.NaN},v=.01,b={dimension:{axis:0,bound:void 0,boundOffset:void 0,offset:0},filters:{active:m,key:void 0},shared:{action:d,focus:void 0}},S=t=>"number"==typeof t,N=t=>"object"==typeof t&&null!=t&&Object.getPrototypeOf(t)===Object.prototype&&!Array.isArray(t)&&!(t=>t instanceof Map)(t)&&!k(t),k=t=>t instanceof Set,I=t=>"string"==typeof t,M=t=>JSON.parse(JSON.stringify(t)),L=(t,e)=>Math.min(e[1],Math.max(e[0],t)),B=(...t)=>t.reduce(((t,e)=>(Object.keys(e).forEach((i=>{N(t[i])&&N(e[i])?t[i]=B(t[i],e[i]):(Array.isArray(t[i])&&Array.isArray(e[i]),t[i]=e[i])})),t)),{}),E=(t,e)=>t.reduce(((t,i)=>(S(i)&&!isNaN(i)&&((t=>e===s.Logarithmic?isFinite(Math.log(t)):isFinite(t))(i)&&(it.finite[1]&&(t.finite[1]=i)),it.actual[1]&&(t.actual[1]=i)),t)),{actual:[1/0,-1/0],finite:[Number.MAX_VALUE,-Number.MAX_VALUE]}),D=(t,e)=>t[e%t.length],w=(t,e,i,s,a={})=>{var n,l,o;const r=i>1?i-1:1,h=(t-e)/r;if(0!==Object.keys(a).length){const t=null!==(n=a.includeNaN)&&void 0!==n?n:0,e=(null!==(l=a.includeNegativeInfinity)&&void 0!==l?l:0)+t,r=(null!==(o=a.includePositiveInfinity)&&void 0!==o?o:0)+e,h=s/i;if(h<=t)return Number.NaN;if(h<=e)return Number.NEGATIVE_INFINITY;if(h<=r)return Number.POSITIVE_INFINITY}return s%(r+1)*h+e},P=t=>t[((t,e=0)=>Math.floor(Math.random()*(t-e))+e)(t.length)],z=(t,e,i={})=>{if(null!=i.includeNaN){const t=L(i.includeNaN,[0,1]);if(Math.random(){let e=((t,e=6)=>{let i=t.toString();const s=Math.abs(t);return isNaN(t)?i="NaN":Number.isFinite(t)?0!==s&&(s<.01||s>999?i=t.toExponential(e):Number.isInteger(t)||(i=t.toFixed(e))):i=(t<0?"-":"")+"Infinity",i})(t);return e=e.replace(/(e)\+(\d+)/,"$1$2"),e=e.replace(/0+(e-?\d+)$/,"$1"),e=e.replace(/(\.[0-9]+?)0+$/,"$1"),e=e.replace(/\.(e)/,"$1"),e},F=(t,e={})=>{var i,s;const a=null!==(i=e.size)&&void 0!==i?i:24,n=null!==(s=e.suffix)&&void 0!==s?s:"...";return t.length<=a?t:`${t.substring(0,a)}${n}`},C=t=>I(t)?t:t.toString();class A{constructor(t,e,i,s={}){this.direction=t,this.minValue=e,this.maxValue=i,this.range=0,this.reverse=false,this.tickLabels=[],this.tickPos=[],this.ticks=[],this.tickPadding=0,this.tickSpacing=0,this.axisLength=1,this.maxTicks=1,this.dataOnEdge=true,this.max=i,this.min=e,null!=s.dataOnEdge&&(this.dataOnEdge=s.dataOnEdge),this.reverse=t===a.Horizontal?null!=s.reverse&&s.reverse:null==s.reverse||!s.reverse,this.setMinMaxValues(e,i,!1)}setAxisLength(t){this.axisLength=t,this.maxTicks=t/50,this.calculate()}setMinMaxValues(t,e,i=!0){if(t===e){const i=t;if(0===i)t=-1,e=1;else if(i<0){t=i-((e=-(2**(Math.log2(Math.abs(i))-1)))-i)}else{e=i+(i-(t=2**(Math.log2(i)-1)))}}this.minValue=t,this.maxValue=e,this.max=e,this.min=t,this.range=e-t,i&&this.calculate()}niceNum(t,e){const i=Math.abs(t),s=Math.floor(Math.log10(i)),a=i/10**s;let n;return n=e?a<1.5?1:a<3?2:a<7?5:10:a<=1?1:a<=2?2:a<=5?5:10,n*10**s}}class T extends A{constructor(t,e=[],i={}){super(t,0,0,i),this.direction=t,this.categories=e,this.reverse&&this.categories.reverse(),this.tickLabels=this.categories.map((t=>C(t)))}percentToValue(t){return this.posToValue(t*this.axisLength)}posToValue(t){let e=1/0,i=Number.NaN;for(let s=0;st===e));return-1!==i?this.tickPos[i]/this.axisLength:0}valueToPos(t){return this.valueToPercent(t)*this.axisLength}calculate(){const t=this.tickLabels.length;let e=0;this.tickSpacing=this.axisLength/(this.dataOnEdge?t-1:t),this.tickPos=[];for(let i=0;ithis.valueToPos(t)))}}const V=t=>e=>Math.log(e)/Math.log(t);class H extends A{constructor(t,e,i,s,a,n=10,l={}){super(t,e,i,l),this.direction=t,this.finiteMin=e,this.finiteMax=i,this.actualMin=s,this.actualMax=a,this.logBase=n,this.maxExp=Number.NaN,this.maxExpExact=Number.NaN,this.minExp=Number.NaN,this.minExpExact=Number.NaN,this.log=V(n),this.logBase=n,this.actualMax=a,this.actualMin=s}setLogBase(t=10){this.logBase=t,this.calculate()}percentToValue(t){if(0===t)return this.reverse?this.actualMax:this.actualMin;if(1===t)return this.reverse?this.actualMin:this.actualMax;const e=this.dataOnEdge?this.minExpExact:this.minExp,i=(this.reverse?1-t:t)*this.rangeExp()+e;return this.logBase**i}posToValue(t){return this.percentToValue(t/this.axisLength)}valueToPercent(t){if(!S(t))return 0;const e=this.log(t),i=this.dataOnEdge?this.minExpExact:this.minExp,s=(e-i)/((this.dataOnEdge?this.maxExpExact:this.maxExp)-i);return this.reverse?1-s:s}valueToPos(t){return this.valueToPercent(t)*this.axisLength}rangeExp(){return this.dataOnEdge?this.maxExpExact-this.minExpExact:this.maxExp-this.minExp}calculate(){this.log=V(this.logBase),this.minExpExact=this.log(this.minValue),this.maxExpExact=this.log(this.maxValue),this.minExp=Math.floor(this.minExpExact),this.maxExp=Math.ceil(this.maxExpExact),this.range=this.logBase**this.maxExp-this.logBase**this.minExp,this.tickSpacing=1;const t=Math.round((this.maxExp-this.minExp)/this.tickSpacing);this.ticks=[],this.tickLabels=[];for(let e=0;e<=t;e++){const i=e*this.tickSpacing+this.minExp;let s=this.logBase**i;this.dataOnEdge&&0===e&&(s=this.logBase**this.minExpExact),this.dataOnEdge&&e===t&&(s=this.logBase**this.maxExpExact),this.ticks.push(s);let a=O(s);this.dataOnEdge&&[0,t].includes(e)&&(a=`*${a}`),this.tickLabels.push(a)}this.tickPos=this.ticks.map((t=>this.valueToPos(t)))}}const $=(t,e)=>t.x*e.x+t.y*e.y,W=(t,e,i,s)=>{const a={x:s.x-e.x,y:s.y-e.y},n={x:i.x-e.x,y:i.y-e.y},l={x:t.x-e.x,y:t.y-e.y},o=$(a,a),r=$(a,n),h=$(a,l),c=$(n,n),d=$(n,l),u=1/(o*c-r*r),f=(c*h-r*d)*u,p=(o*d-r*h)*u;return f>=0&&p>=0&&f+p<1},J=(t,e,i={})=>{if(t.save(),i.fillStyle){t.fillStyle=i.fillStyle,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let i=1;i{var n;if(e.length<2)return;t.save(),t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle||g,t.beginPath(),t.moveTo(e[0].x,e[0].y);const l=null!==(n=s.options.bezierFactor)&&void 0!==n?n:.3;for(let a=1;a{t.save(),t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle||g,t.beginPath(),t.setLineDash(n.lineDash||[]),t.moveTo(tt(e),tt(i)),t.lineTo(tt(s),tt(a)),t.stroke(),t.restore()},U=(t,e,i,s,a,n={})=>{t.save();const l=tt(e),o=tt(i),r=n.cornerRadius||0;n.fillStyle&&(t.fillStyle=n.fillStyle,0===r?t.fillRect(l,o,s,a):(G(t,l,o,s,a,r),t.fill())),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,0===r?t.strokeRect(l,o,s,a):(G(t,l,o,s,a,r),t.stroke())),t.restore()},G=(t,e,i,s,a,n)=>{t.beginPath(),t.moveTo(e+n,i),t.lineTo(e+s-n,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+a-n),t.quadraticCurveTo(e+s,i+a,e+s-n,i+a),t.lineTo(e+n,i+a),t.quadraticCurveTo(e,i+a,e,i+a-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+n,i),t.closePath()},X=(t,e,i,s,a,n={})=>{const l=Z(a),o=l>Math.PI/2&&l<=3*Math.PI/2,r=-a-(o?Math.PI:0);t.save(),et(t,n.font),t.direction=n.direction||"inherit",t.textAlign=n.textAlign||(o?"right":"left"),t.textBaseline=n.textBaseline||"middle",r%2*Math.PI!=0&&(t.translate(i,s),t.rotate(r),t.translate(-i,-s)),n.strokeStyle&&(t.lineCap=n.lineCap||f,t.lineDashOffset=n.lineDashOffset||0,t.lineJoin=n.lineJoin||p,t.lineWidth=n.lineWidth||1,t.miterLimit=n.miterLimit||y,t.strokeStyle=n.strokeStyle,t.strokeText(e,i,s)),n.fillStyle&&(t.fillStyle=n.fillStyle,t.fillText(e,i,s)),t.restore()},Y=(t,e,i,s,a,n=0,l=0,o=0)=>{const r=t+n-o,h=e+l-o,c=t+i+n+o,d=e+s+l+o,u=[{x:r,y:h},{x:c,y:h},{x:c,y:d},{x:r,y:d}];if(null!=a){const i=Z(a);return u.map((s=>((t,e,i,s=0,a=0)=>{const n=t-s,l=e-a,o=Math.cos(i),r=Math.sin(i);return{x:o*n-r*l+s,y:r*n+o*l+a}})(s.x,s.y,-i,t,e)))}return u},K=(t,e,i=u)=>{et(t,i);const s=t.measureText(e),a=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;return{h:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,w:a}},Q=t=>{const e=devicePixelRatio<=1?1:2-.5**(devicePixelRatio-1);return Array.isArray(t)?2===t.length?[t[0]*e,t[1]*e,t[0]*e,t[1]*e]:t.map((t=>t*e)):new Array(4).fill(t*e)},Z=t=>(t+2*Math.PI)%(2*Math.PI),tt=t=>Math.round(t-.5)+.5,et=(t,e=u)=>{const i=new RegExp(/(-?\d*\.?\d+)px/),s=e.match(i);if(2===(null==s?void 0:s.length)){const a=Math.round(parseFloat(s[1])*devicePixelRatio);t.font=e.replace(i,`${a}px`)}else t.font=e},it=(t,e)=>{const i=t.length;if(i<1)return"#000000";if(1===i)return t[0];const s=e*(i-1),a=Math.floor(s),n=Math.ceil(s),l=((t,e,i)=>{const s=Math.round((e.r-t.r)*i+t.r),a=Math.round((e.g-t.g)*i+t.g),n=Math.round((e.b-t.b)*i+t.b);if(null!=t.a&&null!=e.a)return{a:(e.a-t.a)*i+t.a,b:n,g:a,r:s};return{b:n,g:a,r:s}})(st(t[a]),st(t[n]),s-a);return(t=>null!=t.a?`rgba(${t.r}, ${t.g}, ${t.b}, ${t.a})`:`rgb(${t.r}, ${t.g}, ${t.b})`)(l)},st=t=>{if(/^#/.test(t))return(t=>{const e={b:0,g:0,r:0},i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return i&&i.length>3&&(e.r=parseInt(i[1],16),e.g=parseInt(i[2],16),e.b=parseInt(i[3],16)),e})(t);const e=/^rgba?\(\s*?(\d+)\s*?,\s*?(\d+)\s*?,\s*?(\d+)\s*?(,\s*?([\d.]+)\s*?)?\)$/i.exec(t);if(e&&e.length>3){const t={a:1,b:0,g:0,r:0};return t.r=parseInt(e[1]),t.g=parseInt(e[2]),t.b=parseInt(e[3]),e.length>5&&void 0!==e[5]&&(t.a=parseFloat(e[5])),t}return{a:1,b:0,g:0,r:0}},at=(t,e)=>{const i=e.getBoundingClientRect();return{x:(t.clientX-i.x)*devicePixelRatio,y:(t.clientY-i.y)*devicePixelRatio}},nt=(t,e)=>{let i;return(...s)=>{null==i&&(i=setTimeout((()=>{t(...s),i=void 0}),e))}},lt=(t,i,s)=>{const a=i.shared.action,n=a.type===e.LabelMove&&a.dimIndex===t,l=i.dimension.bound||c,o=i.dimension.boundOffset||{x:0,y:0};return n?(h=o,{h:(r=l).h,w:r.w,x:r.x+h.x,y:r.y+h.y}):s;var r,h},ot=t=>isNaN(t.p0)&&isNaN(t.p1),rt=(t,e)=>{const i=M(m);return t.p0e.p1?(i.p1=t.p1,i.percent1=t.percent1,i.value1=t.value1):(i.p1=e.p1,i.percent1=e.percent1,i.value1=e.value1),i.hasNaN=t.hasNaN||e.hasNaN,i.hasNegativeInfinity=t.hasNegativeInfinity||e.hasNegativeInfinity,i.hasPositiveInfinity=t.hasPositiveInfinity||e.hasPositiveInfinity,i},ht={accuracy:[.55,.99],dropout:[.2,.8],"global-batch-size":[5,30],"layer-free-decay":[.001,.1],"layer-split-factor":[1,16],"learning-rate":[1e-4,.1],"learning-rate-decay":[1e-6,.001],loss:[1.7,2.4],"metrics-base":[.5,.9],"n-filters":[8,64]},ct=[{dataOnEdge:!1,key:"dropout",label:"Dropout",type:s.Linear},{dataOnEdge:!1,key:"global-batch-size",label:"Global Batch Size",type:s.Linear},{categories:[4,8,16,32,64],dataOnEdge:!1,key:"layer-dense-size",label:"Layer Dense Size",type:s.Categorical},{dataOnEdge:!1,key:"layer-free-decay",label:"Layer Free Decay",logBase:10,type:s.Logarithmic},{categories:[!0,!1],dataOnEdge:!1,key:"layer-inverse",label:"Layer Inverse",type:s.Categorical},{dataOnEdge:!1,key:"learning-rate",label:"Learning Rate",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"learning-rate-decay",label:"Learning Rate Decay",logBase:10,type:s.Logarithmic},{dataOnEdge:!1,key:"layer-split-factor",label:"Layer Split Factor",logBase:2,type:s.Logarithmic},{dataOnEdge:!1,key:"metrics-base",label:"Metrics Base",type:s.Linear},{dataOnEdge:!1,key:"n-filters",label:"N Filters",type:s.Linear}],dt=[{dataOnEdge:!0,disableDrag:!0,key:"accuracy",label:"Accuracy",type:s.Linear},{dataOnEdge:!0,disableDrag:!0,key:"loss",label:"Loss",type:s.Logarithmic}];var ut=Object.freeze({__proto__:null,DEFAULT_DIMENSION_COUNT:10,dimensionRanges:ht,dimensionSamples:ct,metricDimensionSamples:dt,generateData:(t,e,i=!0,a={})=>t.reduce(((t,n)=>(t[n.key]=new Array(e).fill(null).map(((t,l)=>{if(n.type===s.Categorical){if(n.categories)return i?P(n.categories):D(n.categories,l)}else if(n.type===s.Linear){const t=ht[n.key];if(t)return i?z(t[1],t[0],a):w(t[1],t[0],e,l,a)}else if(n.type===s.Logarithmic){const t=ht[n.key];if(t&&n.logBase)return i?((t,e,i,s={})=>{const a=10===t?Math.log10:2===t?Math.log2:Math.log,n=a===Math.log?Math.log(t):1,l=a(e)/n,o=a(i)/n,r=z(l,o,s);return isNaN(r)||!isFinite(r)?r:t**r})(n.logBase,t[1],t[0],a):((t,e,i,s,a,n={})=>{const l=10===t?Math.log10:2===t?Math.log2:Math.log,o=l===Math.log?Math.log(t):1,r=l(e)/o,h=l(i)/o;return t**w(r,h,s,a,n)})(n.logBase,t[1],t[0],e,l)}return r})),t)),{}),generateDimensions:(t=10,e=!0)=>{const i=new Array(t-1).fill(null).map(((t,i)=>e?P(ct):D(ct,i))),s=e?P(dt):D(dt,0);return i.push(s),i}});class ft{constructor(t,e,i,s){this.config=x,this.data={},this.dataInfo={hasInfinity:!1,hasNaN:!1,seriesCount:0},this.dimensions=[],this.dimensionsOriginal=[],this.filters={},this.size={h:0,w:0},this.ix=M(b),this._=void 0;const a=(t=>I(t)?document.querySelector(t):t)(t);if(!a)throw new R("Target element selector did not match anything.");this.element=a;const n=this.element.getBoundingClientRect();if(0===n.width||0===n.height)throw new R("Target element width and height must both be greater than 0px.");const l=this.element.querySelectorAll("canvas");0===l.length?(this.canvas=document.createElement("canvas"),this.element.appendChild(this.canvas)):this.canvas=l[0];const o=this.canvas.getContext("2d");if(!o)throw new R("Unable to get context from target element.");this.ctx=o,e&&this.setDimensions(e,!1),i&&this.setConfig(i,!1),s&&this.setData(s,!1),(e||i||s)&&this.redraw(),this.listeners={dblclick:this.handleDoubleClick.bind(this),mousedown:this.handleMouseDown.bind(this),mousemove:0===this.config.interactions.throttleDelayMouseMove?this.handleMouseMove.bind(this):nt((t=>this.handleMouseMove.bind(this)(t)),this.config.interactions.throttleDelayMouseMove),mouseup:this.handleMouseUp.bind(this)},this.enable()}static deepMerge(...t){return B(...t)}static getTester(){return ut}static validateData(t,e){const i={count:0,message:"",valid:!0},s=Object.keys(t),a=Object.values(t);for(let t=0;tnull==t))){const a=null===e;return i.message=`Data for "${s[t]}" has ${a?"null":"undefined"}`,i.valid=!1,i}}const n=Object.keys(t);for(let t=0;t{const e=Object.keys(t),i={hasInfinity:!1,hasNaN:!1,seriesCount:0};for(const s of e){i.seriesCount=i.seriesCount||t[s].length;for(const e of t[s])isNaN(e)&&(i.hasNaN=!0),isNaN(e)||isFinite(e)||(i.hasInfinity=!0)}return i})(this.data),this.setDimensions(this.dimensionsOriginal,!1),e&&this.redraw()}setDimensions(t,e=!0){const i=ft.validateDimensions(t);if(!i.valid)throw new R(i.message);const n=this.config.direction===a.Horizontal?a.Vertical:a.Horizontal;this.dimensionsOriginal=t,this.dimensions=M(t).map((t=>{const e=t.key,i=this.data[e]||[],a={...t,labelTruncated:F(t.label,{size:this.config.style.dimension.label.truncate}),rangeActual:void 0,rangeFinite:void 0,scale:new _(n,0,100,0,100)};if(t.type===s.Linear||t.type===s.Logarithmic){const e=E(i,t.type);t.type===s.Linear?a.scale=new _(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t):t.type===s.Logarithmic&&(a.scale=new H(n,e.finite[0],e.finite[1],e.actual[0],e.actual[1],t.logBase,t))}else t.type===s.Categorical&&(a.scale=new T(n,t.categories,t));return a})),e&&this.redraw()}setSize(t,e,i=!0){var s,a;const n={h:this.size.h,w:this.size.w},l=Math.round(t*devicePixelRatio),o=Math.round(e*devicePixelRatio);this.canvas.width=l,this.canvas.height=o,this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`,this.size={h:o,w:l},null===(a=(s=this.config.hooks).onResize)||void 0===a||a.call(s,M(this.size),n),i&&this.redraw()}disable(){this.removeListeners(),this.removeObservers(),this.ix=M(b),this.updateCursor(),this.redraw()}enable(){this.addListeners(),this.addObservers()}redraw(){0===this.size.w&&0===this.size.h||(this.calculate(),this.clear(),this.config.debug&&this.drawDebugOutline(),this.draw())}destroy(){this.removeListeners(),this.removeObservers(),this.canvas&&this.element.contains(this.canvas)&&this.element.removeChild(this.canvas)}addListeners(){this.element.addEventListener("dblclick",this.listeners.dblclick),this.element.addEventListener("mousedown",this.listeners.mousedown),window.addEventListener("mousemove",this.listeners.mousemove),window.addEventListener("mouseup",this.listeners.mouseup)}addObservers(){this.resizeObserver&&(this.resizeObserver.unobserve(this.element),this.resizeObserver=void 0),this.resizeObserver=new ResizeObserver(0===this.config.interactions.throttleDelayResize?this.handleResize.bind(this):nt((t=>this.handleResize.bind(this)(t)),this.config.interactions.throttleDelayResize)),this.resizeObserver.observe(this.element)}removeListeners(){this.element.removeEventListener("dblclick",this.listeners.dblclick),this.element.removeEventListener("mousedown",this.listeners.mousedown),window.removeEventListener("mousemove",this.listeners.mousemove),window.removeEventListener("mouseup",this.listeners.mouseup)}removeObservers(){var t;null===(t=this.resizeObserver)||void 0===t||t.unobserve(this.element),this.resizeObserver=void 0}calculate(){this.calculateLayout(),this.calculateStyles()}calculateLayout(){var t,e;const s={dims:{list:new Array(this.dimensions.length).fill(void 0).map((()=>({axes:{},label:{},layout:{}}))),map:this.dimensions.reduce(((t,e,i)=>(t[e.key]=i,t)),{}),shared:{axes:{},label:{},layout:{}}},layout:{drawRect:{},padding:Q(this.config.style.padding)}},{h:n,w:o}=this.size,r=s.layout,h=s.dims.shared.axes,c=s.dims.shared.label,d=s.dims.shared.layout,u=this.dimensions.length,f=this.config.direction===a.Horizontal,p=this.config.style.dimension.label,y=this.config.style.dimension.label.boundaryPadding,g=this.config.style.dimension.layout,x=this.config.style.axes.label,m=this.config.style.axes.axis,v=this.config.style.axes.axis.boundaryPadding,b=p.placement===l.Before,S=null!=p.angle,N=x.placement===l.Before;if(r.drawRect={h:n-r.padding[0]-r.padding[2],w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:r.padding[0]},c.cos=S?Math.cos(null!==(t=p.angle)&&void 0!==t?t:0):void 0,c.sin=S?Math.sin(null!==(e=p.angle)&&void 0!==e?e:0):void 0,c.rad=p.angle||(f?void 0:b?-Math.PI:0),c.maxLengthCos=0,c.maxLengthSin=0,this.dimensions.forEach(((t,e)=>{const i=K(this.ctx,t.labelTruncated,p.font),a=s.dims.list[e].label;a.w=i.w,a.h=i.h,a.lengthCos=S?i.w*c.cos:i.w,a.lengthSin=S?i.w*c.sin:i.h,Math.abs(a.lengthCos)>Math.abs(c.maxLengthCos)&&(c.maxLengthCos=a.lengthCos),Math.abs(a.lengthSin)>Math.abs(c.maxLengthSin)&&(c.maxLengthSin=a.lengthSin)})),h.start=h.stop=0,h.startInfinity=h.stopInfinity=h.startNaN=h.stopNaN=void 0,f){if(b){const t=Math.max(0,c.maxLengthSin);h.start=r.padding[0]+t+p.offset,h.stop=n-r.padding[2]}else{const t=S?Math.max(0,-c.maxLengthSin):c.maxLengthSin;h.start=r.padding[0],h.stop=n-r.padding[2]-t-p.offset}h.stopNaN=this.dataInfo.hasNaN?h.stop:void 0,h.startInfinity=h.start,h.stopInfinity=h.stop-(this.dataInfo.hasNaN?m.nanGap:0),h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}else{if(b){const t=S?Math.max(0,-c.maxLengthCos):c.maxLengthCos;h.start=r.padding[3]+t+p.offset,h.stop=o-r.padding[1]}else{const t=Math.max(0,c.maxLengthCos);h.start=r.padding[3],h.stop=o-r.padding[1]-t-p.offset}h.startNaN=this.dataInfo.hasNaN?h.start:void 0,h.startInfinity=h.start+(this.dataInfo.hasNaN?m.nanGap:0),h.stopInfinity=h.stop,h.startData=h.startInfinity+(this.dataInfo.hasInfinity?m.infOffset:0),h.stopData=h.stopInfinity-(this.dataInfo.hasInfinity?m.infOffset:0)}if(h.length=h.stop-h.start,h.labelFactor=N?-1:1,d.totalBoundSpace=0,this.dimensions.forEach(((t,e)=>{const i=s.dims.list[e].axes,a=s.dims.list[e].label,l=s.dims.list[e].layout,c=t.scale;i.tickLabels=[],i.tickPos=[],i.maxLength=0,c&&(c.setAxisLength(h.stopData-h.startData),i.tickLabels=c.tickLabels.slice(),i.tickPos=c.tickPos.slice(),c.tickLabels.forEach((t=>{const e=K(this.ctx,t,x.font);i.maxLength=Math.max(e.w,i.maxLength)}))),S?(l.spaceBefore=f?a.lengthCos<0?-a.lengthCos:0:a.lengthSin>0?a.lengthSin:0,l.spaceAfter=f?a.lengthCos>0?a.lengthCos:0:a.lengthSin<0?-a.lengthSin:0):(l.spaceBefore=(f?a.lengthCos:a.lengthSin)/2,l.spaceAfter=(f?a.lengthCos:a.lengthSin)/2),N?l.spaceBefore=Math.max(l.spaceBefore,i.maxLength):l.spaceAfter=Math.max(l.spaceAfter,i.maxLength),f?(l.bound={h:n-r.padding[0]-r.padding[2],w:l.spaceBefore+l.spaceAfter,x:0,y:r.padding[0]},d.totalBoundSpace+=l.bound.w):(l.bound={h:l.spaceBefore+l.spaceAfter,w:o-r.padding[1]-r.padding[3],x:r.padding[3],y:0},d.totalBoundSpace+=l.bound.h)})),f){const t=r.drawRect.w-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[3],d.space=u>1?r.drawRect.w/(u-1):0}else{const t=r.drawRect.h-d.totalBoundSpace;d.gap=u>1?Math.max(t,0)/(u-1):0,d.offset=r.padding[0],d.space=u>1?r.drawRect.h/(u-1):0}let k=d.offset;for(let t=0;t{const a=((null==r?void 0:r.type)===n.Filter||(null==r?void 0:r.type)===n.FilterResize)&&(null==r?void 0:r.dimIndex)===t&&(null==r?void 0:r.filterIndex)===s,l=f||p&&!a,h=a&&void 0===o.filterIndex,c=o.dimIndex===t&&o.filterIndex===s;return{...i.filter,...l?i.filterAxisHover:{},...h?i.filterHover:{},...c?i.filterActive:{}}}))}}getFocusByPoint(t){if(!this._)return;const e=this._.dims.shared.axes,i=this.config.direction===a.Horizontal?"y":"x",s=this._.dims.shared.axes.length;for(let a=0;ac>=t.p0&&c<=t.p1));let u=n.DimensionAxis;if(-1!==d){const t=3/e.length,i=r[d];u=c<=i.p0+t||c>=i.p1-t?n.FilterResize:n.Filter}return{dimIndex:a,filterIndex:d,type:u}}}}updateActiveLabel(){var t,i;if(!this._||this.ix.shared.action.type!==e.LabelMove)return;const s=this._.dims.list,n=this.ix,l=n.dimension,o=n.shared.action,r=this.config.direction===a.Horizontal,h=r?"x":"y";l.boundOffset={x:r?o.p1.x-o.p0.x:0,y:r?0:o.p1.y-o.p0.y};let c=-1;const d=l.axis+l.boundOffset[h];for(let t=0;tt&&(d{this.filters[t]=this.config.filters[t].map((i=>this.processConfigFilter(i,e[t]))).filter((t=>null!=t))})),this.redraw()}setActiveFilter(t,i){if(!this._)return;const s=this.filters,a=this.ix,n=a.shared.action,l=a.filters,o=this._.dims.shared.axes,r=(s[t]||[]).findIndex((t=>i>=t.p0&&i<=t.p1));-1!==r?(l.active=s[t][r],l.active.startP0=l.active.p0,l.active.startP1=l.active.p1,n.filterIndex=r,i>=l.active.p0&&i<=l.active.p0+3/o.length?n.type=e.FilterResizeBefore:i>=l.active.p1-3/o.length&&i<=l.active.p1?n.type=e.FilterResizeAfter:n.type=e.FilterMove):(n.type=e.FilterCreate,l.active={...m,p0:i,p1:i},s[t]=s[t]||[],s[t].push(l.active),n.filterIndex=s[t].length-1)}updateActiveFilter(t){var i,s,n,l,o,r,h,c,d,u,f,p;if(!this._)return;const y=this._.dims.list,g=this._.dims.shared.axes,x=this.ix,v=x.filters,b=x.shared.action,S=this.filters,N=b.dimIndex,k=this.config.direction===a.Horizontal?"y":"x";if(!(b.type===e.FilterCreate||b.type===e.FilterMove||b.type===e.FilterResizeAfter||b.type===e.FilterResizeBefore)||!v.key)return;const I=this.dimensions[b.dimIndex].key,B=y[b.dimIndex].layout.bound,E=y[b.dimIndex].layout.axisBoundaryStart[k];if(b.type===e.FilterMove){const t=null!==(i=v.active.startP0)&&void 0!==i?i:0,e=null!==(s=v.active.startP1)&&void 0!==s?s:0,a=e-t,n=(b.p1[k]-b.p0[k])/g.length;v.active.p0=t+n,v.active.p1=e+n,v.active.p0<=0?(v.active.p0=0,v.active.p1=a):v.active.p1>=1&&(v.active.p0=1-a,v.active.p1=1)}else b.type===e.FilterResizeBefore?(v.active.p0=(b.p1[k]-B[k]-E)/g.length,v.active.p0=L(v.active.p0,[0,1])):(v.active.p1=(b.p1[k]-B[k]-E)/g.length,v.active.p1=L(v.active.p1,[0,1]));if(this.processFilter(v.active,N),"mouseup"===t.type){if(D=b.p0,w=b.p1,Math.sqrt((w.x-D.x)**2+(w.y-D.y)**2)<1){const t=S[v.key]||[],e=(v.active.p1-v.active.p0)/2+v.active.p0,i=t.findIndex((t=>e>=t.p0&&e<=t.p1));if(-1!==i){const e=M(t[i]);null===(l=(n=this.config.hooks).onFilterRemove)||void 0===l||l.call(n,{[I]:[e]}),t.splice(i,1)}}else{if(v.active.p1=e}else{const e=(i.layout.axisInfinityStart.x-i.layout.axisBoundaryStart.x)/i.xLength;t.hasNegativeInfinity=s<=e&&a>=e,t.hasPositiveInfinity=1===a}i.hasNaN&&(t.hasNaN=i.isHorizontal&&1===a||!i.isHorizontal&&0===s),s<=i.pStart?t.percent0=0:s>i.pStart&&s<=i.pStop&&(t.percent0=(s-i.pStart)/i.pLength),a>=i.pStop?t.percent1=1:a>=i.pStart&&a{const e=this.filters[t]||[];for(let t=0;t=a.p1)e[t]={...m};else for(let a=t+1;a!ot(t)))}))}updateCursor(){const t=this.ix,i=t.shared.action,s=t.shared.focus,l=this.config.direction===a.Horizontal;let o="default";i.type!==e.None?i.type===e.FilterMove||i.type===e.LabelMove?o="grabbing":i.type===e.FilterResizeAfter||i.type===e.FilterResizeBefore?o=l?"ns-resize":"ew-resize":i.type===e.FilterCreate&&(o="crosshair"):void 0!==s&&(s.type===n.DimensionLabel?o="grab":s.type===n.DimensionAxis?o="crosshair":s.type===n.Filter?o="grab":s.type===n.FilterResize&&(o=l?"ns-resize":"ew-resize")),this.canvas.style.cursor=o}clear(){const{h:t,w:e}=this.size;this.ctx.clearRect(0,0,e,t)}draw(){var t,e;if(!this._)return;const i=this._.dims.list,s=this._.dims.shared.axes,o=this._.dims.shared.label,r=this._.styles,h=this.ix,c=this.ix.shared.focus,d=this.filters,u=this.config.direction===a.Horizontal,f=this.config.style.axes,p=this.config.style.data,y=this.config.style.dimension,g=y.label.placement===l.Before,x=f.label.placement===l.Before;for(let s=0;s{var f,y,g,x,m,v;const b=t.key,N=i[e].layout,k=lt(e,h,N.bound),I=this.data[b][s],M=S(I),L=M&&isNaN(I),B=M&&!L&&!isFinite(I),E=B&&I===-1/0,D=B&&I===1/0,w=L||B?0:null!==(y=null===(f=t.scale)||void 0===f?void 0:f.valueToPercent(I))&&void 0!==y?y:0;let P=k.x,z=k.y;if(L)P+=u?N.axisDataStart.x:N.axisBoundaryStart.x,z+=u?N.axisBoundaryStop.y:N.axisDataStart.y;else if(B){const t=E?u?N.axisInfinityStop.x:N.axisInfinityStart.x:u?N.axisInfinityStart.x:N.axisInfinityStop.x,e=D?u?N.axisInfinityStart.y:N.axisInfinityStop.y:u?N.axisInfinityStop.y:N.axisInfinityStart.y;P+=u?N.axisDataStart.x:t,z+=u?e:N.axisDataStart.y}else{const e=null!==(x=null===(g=t.scale)||void 0===g?void 0:g.valueToPos(I))&&void 0!==x?x:0;P+=N.axisDataStart.x+(u?0:e),z+=N.axisDataStart.y+(u?e:0)}if(b===p.targetDimensionKey){const e=null!==(v=null===(m=t.scale)||void 0===m?void 0:m.reverse)&&void 0!==v&&v,i=p.targetColorScale||[],s=it(e?i.slice().reverse():i,w);a.strokeStyle=s}if(d[b]&&0!==d[b].length){n=!0;let t=!1;for(let e=0;e=i.percent0&&w<=i.percent1&&(t=!0)}t||(c=!0)}else L?l=!0:E?o=!0:D&&(r=!0);return{x:P,y:z}}));n&&c?a=p.filtered:l&&p.overrideNaN?a=p.overrideNaN:o&&p.overrideNegativeInfinity?a=p.overrideNegativeInfinity:r&&p.overridePositiveInfinity&&(a=p.overridePositiveInfinity),j(this.ctx,f,u,p.path,a)}const m=null==y.label.angle&&u,v={textAlign:m?"center":void 0,textBaseline:m?g?"bottom":"top":void 0};this.dimensions.forEach(((t,e)=>{var s;const a=lt(e,h,i[e].layout.bound),n=i[e].layout.labelPoint,l=a.x+n.x,c=a.y+n.y,d={...r[e].label,...v};X(this.ctx,t.labelTruncated,l,c,null!==(s=o.rad)&&void 0!==s?s:0,d)}));const b=null==f.label.angle&&u,N={textAlign:b?void 0:"center",textBaseline:b?void 0:x?"bottom":"top"};i.forEach(((t,e)=>{var i;const a=this.dimensions[e].key,l=lt(e,h,t.layout.bound),o=t.layout.axisBoundaryStart,p=t.layout.axisBoundaryStop,y=t.layout.axisInfinityStart,g=t.layout.axisInfinityStop,m=t.layout.axisDataStart,v=t.layout.axisDataStop,b=t.axes.tickLabels,S=t.axes.tickPos,k=x?-1:1,I={...r[e].tickLabel,...N},M=u?k*f.tick.length:0,L=u?0:k*f.tick.length,B=d[a]||[];if(q(this.ctx,l.x+m.x,l.y+m.y,l.x+v.x,l.y+v.y,r[e].axis),this.dataInfo.hasInfinity){q(this.ctx,l.x+y.x,l.y+y.y,l.x+m.x,l.y+m.y,{...r[e].axis,lineDash:f.axis.infLineDash}),q(this.ctx,l.x+v.x,l.y+v.y,l.x+g.x,l.y+g.y,{...r[e].axis,lineDash:f.axis.infLineDash,lineDashOffset:null!==(i=f.axis.infLineDash[0])&&void 0!==i?i:0});const t=l.x+y.x,s=l.y+y.y,a=t+M,n=s+L;q(this.ctx,t,s,a,n,r[e].tick);const o=l.x+g.x,h=l.y+g.y,c=o+M,d=h+L;q(this.ctx,o,h,c,d,r[e].tick);const p=u?a+k*f.label.offset:t,b=u?s:n+k*f.label.offset,S=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,N=u?"+Ꝏ":"-Ꝏ";X(this.ctx,N,p,b,S,I);const B=u?c+k*f.label.offset:o,E=u?h:d+k*f.label.offset,D=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0,w=u?"-Ꝏ":"+Ꝏ";X(this.ctx,w,B,E,D,I)}if(this.dataInfo.hasNaN){const t=l.x+(u?p.x:o.x),i=l.y+(u?p.y:o.y),s=t+M,a=i+L;q(this.ctx,t,i,s,a,r[e].tick);const n=u?s+k*f.label.offset:t,h=u?i:a+k*f.label.offset,c=null!=f.label.angle?f.label.angle:u&&x?Math.PI:0;X(this.ctx,"NaN",n,h,c,I)}for(let t=0;t{const a=t.p0*s.length,n=t.p1*s.length,h=r[e].filters[i].width,c=h/2,d=l.x+o.x+(u?-c:a),f=l.y+o.y+(u?a:-c),p=u?h:n-a,y=u?n-a:h;U(this.ctx,d,f,p,y,r[e].filters[i])}))}))}drawDebugOutline(){if(!this._)return;const{h:t,w:e}=this.size,i=this._.layout,s=this._.dims.list,n=this._.dims.shared.layout,l=this.config.direction===a.Horizontal,o={strokeStyle:"#dddddd"};q(this.ctx,0,i.padding[0],e,i.padding[0],o),q(this.ctx,0,t-i.padding[2],e,t-i.padding[2],o),q(this.ctx,i.padding[3],0,i.padding[3],t,o),q(this.ctx,e-i.padding[1],0,e-i.padding[1],t,o);const r={strokeStyle:"#999999"},h={strokeStyle:"#ff0000"},c={strokeStyle:"#eeeeee"},d={strokeStyle:"#0099cc"},u={strokeStyle:"#ffcc00"};s.forEach(((t,e)=>{const s=t.layout.bound,a=t.layout.axisBoundary,o=t.layout.labelPoint,g=t.layout.labelBoundary;U(this.ctx,l?i.padding[3]+e*n.space:s.x,l?s.y:i.padding[0]+e*n.space,l?n.space:s.w,l?s.h:n.space,r),U(this.ctx,s.x,s.y,s.w,s.h,h),((t,e,i,s,a={})=>{t.save(),a.fillStyle&&(t.fillStyle=null==a?void 0:a.fillStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.fill()),a.strokeStyle&&(t.lineCap=a.lineCap||f,t.lineDashOffset=a.lineDashOffset||0,t.lineJoin=a.lineJoin||p,t.lineWidth=a.lineWidth||1,t.miterLimit=a.miterLimit||y,t.strokeStyle=a.strokeStyle,t.moveTo(e+s,i),t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.stroke()),t.restore()})(this.ctx,s.x+o.x,s.y+o.y,3,d),J(this.ctx,g,u),J(this.ctx,a,c)}))}handleResize(t){const e=t.find((t=>t.target===this.element));if(!e)return;const{width:i,height:s}=e.contentRect;0===this.size.w&&0===this.size.h&&0!==i&&0!==s?(this.setSize(i,s),this.setConfigFilters(this.config.filters)):this.setSize(i,s)}handleDoubleClick(){var t,e;this.setDimensions(this.dimensionsOriginal,!1),this.filters={},this.ix=M(b),this.redraw(),null===(e=(t=this.config.hooks).onReset)||void 0===e||e.call(t)}handleMouseDown(t){var i,s;if(!this._)return;const l=this.ix.shared,o=this.ix.shared.action,r=this.ix.dimension,h=this.ix.filters,c=this._.dims.shared.axes,d=this.config.direction===a.Horizontal,u=d?"x":"y",f=d?"y":"x",p=at(t,this.element);if(o.p0=p,o.p1=p,o.filterIndex=-1,l.focus=this.getFocusByPoint(p),l.focus){const t=l.focus.dimIndex,a=this._.dims.list[t].layout,d=a.bound,p=a.axisBoundaryStart;if((null===(i=l.focus)||void 0===i?void 0:i.type)===n.DimensionLabel)o.type=e.LabelMove,o.dimIndex=t,r.axis=d[u]+p[u],r.bound=d;else if([n.DimensionAxis,n.Filter,n.FilterResize].includes(null===(s=l.focus)||void 0===s?void 0:s.type)){o.type=e.FilterCreate,o.dimIndex=t,h.key=this.dimensions[t].key;const i=(o.p0[f]-d[f]-p[f])/c.length;this.setActiveFilter(h.key,i),this.processFilter(h.active,t)}}this.updateCursor(),this.redraw()}handleMouseMove(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.ix.shared.focus=this.getFocusByPoint(e),this.updateActiveLabel(),this.updateActiveFilter(t),this.updateCursor(),this.redraw()}handleMouseUp(t){if(!this._)return;const e=at(t,this.element);this.ix.shared.action.p1=e,this.updateActiveLabel(),this.updateActiveFilter(t),this.ix=M(b),this.ix.shared.focus=this.getFocusByPoint(e),this.updateCursor(),this.redraw()}}return t.ActionType=e,t.DimensionLayout=i,t.DimensionType=s,t.Direction=a,t.FocusType=n,t.LabelPlacement=l,t.PathType=o,t.default=ft,t}({}); diff --git a/package-lock.json b/package-lock.json index c0a90f3..90418fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "hermes-parallel-coordinates", - "version": "0.6.5", + "version": "0.6.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hermes-parallel-coordinates", - "version": "0.6.5", + "version": "0.6.6", "license": "ISC", "devDependencies": { "@rollup/plugin-commonjs": "^21.0.1", diff --git a/package.json b/package.json index a04235a..5f036c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hermes-parallel-coordinates", - "version": "0.6.5", + "version": "0.6.6", "description": "A lightweight and fast canvas-based parallel coordinates chart library.", "keywords": [ "es6",