aliencharts 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/aliencharts.css +1 -1
- package/dist/aliencharts.global.js +87 -45
- package/dist/aliencharts.global.js.map +2 -2
- package/dist/aliencharts.global.min.js +19 -17
- package/dist/aliencharts.global.min.js.map +3 -3
- package/dist/react.js +87 -45
- package/dist/react.js.map +2 -2
- package/dist/vanilla.js +87 -45
- package/dist/vanilla.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var AlienCharts=(()=>{var Ct=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var $e=(e,t)=>{for(var r in t)Ct(e,r,{get:t[r],enumerable:!0})},Oe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Le(t))!Ie.call(e,i)&&i!==r&&Ct(e,i,{get:()=>t[i],enumerable:!(n=Ee(t,i))||n.enumerable});return e};var Ne=e=>Oe(Ct({},"__esModule",{value:!0}),e);var Sr={};$e(Sr,{BarSeries:()=>J,LineSeries:()=>K,createBarSeries:()=>ne,createChartGrid:()=>_e,createLineSeries:()=>B,createMockCharts:()=>De,createSeries:()=>re});var Fe={arrowLineRight:'<line x1="32" y1="128" x2="176" y2="128"/><polyline points="104 56 176 128 104 200"/><line x1="216" y1="40" x2="216" y2="216"/>',pushPinSimple:'<path d="M224,176a8,8,0,0,1-8,8H136v56a8,8,0,0,1-16,0V184H40a8,8,0,0,1,0-16h9.29L70.46,48H64a8,8,0,0,1,0-16H192a8,8,0,0,1,0,16h-6.46l21.17,120H216A8,8,0,0,1,224,176Z"/>',arrowCounterClockwise:'<polyline points="24 56 24 104 72 104"/><path d="M67.59,192A88,88,0,1,0,65.77,65.77L24,104"/>',arrowsIn:'<polyline points="192 104 152 104 152 64"/><line x1="208" y1="48" x2="152" y2="104"/><polyline points="64 152 104 152 104 192"/><line x1="48" y1="208" x2="104" y2="152"/><polyline points="152 192 152 152 192 152"/><line x1="208" y1="208" x2="152" y2="152"/><polyline points="104 64 104 104 64 104"/><line x1="48" y1="48" x2="104" y2="104"/>',arrowsOut:'<polyline points="160 48 208 48 208 96"/><line x1="152" y1="104" x2="208" y2="48"/><polyline points="96 208 48 208 48 160"/><line x1="104" y1="152" x2="48" y2="208"/><polyline points="208 160 208 208 160 208"/><line x1="152" y1="152" x2="208" y2="208"/><polyline points="48 96 48 48 96 48"/><line x1="104" y1="104" x2="48" y2="48"/>',broom:'<path d="M112,224a95.2,95.2,0,0,1-29-48"/><path d="M192,152c0,31.67,13.31,59,40,72H61A103.65,103.65,0,0,1,32,152c0-28.21,11.23-50.89,29.47-69.64a8,8,0,0,1,8.67-1.81L95.52,90.83a16,16,0,0,0,20.82-9l21-53.11c4.15-10,15.47-15.32,25.63-11.53a20,20,0,0,1,11.51,26.4L153.13,96.69a16,16,0,0,0,8.93,20.76L187,127.29a8,8,0,0,1,5,7.43Z"/><line x1="40.54" y1="112.21" x2="194.26" y2="173.7"/>',waveSine:'<path d="M24,128c104-221.7,104,221.7,208,0"/>',magnifyingGlassPlus:'<line x1="80" y1="112" x2="144" y2="112"/><circle cx="112" cy="112" r="80"/><line x1="168.57" y1="168.57" x2="224" y2="224"/><line x1="112" y1="80" x2="112" y2="144"/>',mapPin:'<circle cx="128" cy="104" r="32"/><path d="M208,104c0,72-80,128-80,128S48,176,48,104a80,80,0,0,1,160,0Z"/>',minus:'<line x1="40" y1="128" x2="216" y2="128"/>',eye:'<path d="M128,56C48,56,16,128,16,128s32,72,112,72,112-72,112-72S208,56,128,56Z"/><circle cx="128" cy="128" r="32"/>'},Pe=new Set(["pushPinSimple"]),M=(e,{size:t=16,className:r=""}={})=>{let n=Fe[e];if(!n)throw new Error(`Unknown AlienCharts icon: ${e}`);let i=Pe.has(e)?'fill="currentColor"':'fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="24"';return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="${t}" height="${t}" class="${r}" aria-hidden="true" ${i}>${n}</svg>`};var zt="#60a5fa";var Yt=new Set(["trendline","hline","vline","pin"]),ke=e=>({color:e?.style?.color||zt,lineWidth:Number.isFinite(e?.style?.lineWidth)?e.style.lineWidth:2,dashPattern:Array.isArray(e?.style?.dashPattern)?e.style.dashPattern:[],extendLeft:!!e?.style?.extendLeft,extendRight:e?.style?.extendRight!==!1,text:typeof e?.style?.text=="string"?e.style.text:""}),it=(e,t)=>Array.isArray(e)?e.filter(r=>r?.chartId===t):[],Xt=e=>({color:zt,lineWidth:2,dashPattern:[],extendLeft:!1,extendRight:e!=="vline",text:""}),Ht=({chartId:e,type:t,start:r,end:n,createDrawingId:i})=>({id:i?.({chartId:e,type:t})||`${e}-drawing-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,chartId:e,type:t,start:r,end:n,createdAt:Date.now(),style:Xt(t)}),At=({chartId:e,type:t,start:r,end:n})=>({id:"__draft__",chartId:e,type:t,start:r,end:n,createdAt:Date.now(),style:Xt(t)}),Bt=(e,t,r)=>{let n=t.x-e.x,i=t.y-e.y;if(Math.abs(n)<=1e-6&&Math.abs(i)<=1e-6)return t;let o=[];n>1e-6?o.push((r.x+r.width-e.x)/n):n<-1e-6&&o.push((r.x-e.x)/n),i>1e-6?o.push((r.y+r.height-e.y)/i):i<-1e-6&&o.push((r.y-e.y)/i);let a=Math.min(...o.filter(l=>Number.isFinite(l)&&l>=0)),s=Number.isFinite(a)?Math.max(1,a):1;return{x:e.x+n*s,y:e.y+i*s}},St=({drawing:e,layout:t,projectPoint:r})=>{if(!e?.start||!e?.end)return null;let n=r(e.start,t),i=r(e.end,t),o=ke(e),a=n,s=i;if(e.type==="pin")return{start:n,end:n,lineStart:n,lineEnd:n,style:o};if(e.type==="hline"){let l=Math.abs(i.x-n.x)>1e-6?i.x:t.plot.x+t.plot.width;a={x:o.extendRight?t.plot.x:n.x,y:n.y},s={x:o.extendRight?t.plot.x+t.plot.width:l,y:n.y}}else e.type==="vline"?(a={x:n.x,y:t.plot.y},s={x:n.x,y:t.plot.y+t.plot.height}):e.type==="trendline"&&(o.extendLeft&&(a=Bt(i,n,t.plot)),o.extendRight&&(s=Bt(n,i,t.plot)));return{start:n,end:i,lineStart:a,lineEnd:s,style:o}},Be=(e,t,r)=>{let n=r.x-t.x,i=r.y-t.y;if(n===0&&i===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*i)/(n*n+i*i)));return Math.hypot(e.x-(t.x+o*n),e.y-(t.y+o*i))},Ut=({point:e,drawing:t,layout:r,projectPoint:n})=>{let i=St({drawing:t,layout:r,projectPoint:n});return i?t.type!=="pin"&&Math.hypot(e.x-i.start.x,e.y-i.start.y)<=10?{drawing:t,endpoint:"start"}:t.type==="pin"&&Math.hypot(e.x-i.start.x,e.y-i.start.y)<=14?{drawing:t,endpoint:"move"}:t.type==="trendline"&&Math.hypot(e.x-i.end.x,e.y-i.end.y)<=10?{drawing:t,endpoint:"end"}:Be(e,i.lineStart,i.lineEnd)<=8?{drawing:t,endpoint:null}:null:null},Mt=(e,t,r)=>(Array.isArray(e)?e:[]).map(n=>n?.id===t?r(n):n),Vt=(e,t)=>(Array.isArray(e)?e:[]).filter(r=>r?.id!==t);var ze=Object.freeze({appendAnimation:!0,drawings:!0,latestValue:!0,markers:!0,movingAverage:!0}),Ye=Object.freeze({appendAnimation:!1,drawings:!1,latestValue:!1,markers:!1,movingAverage:!1}),_t=Object.freeze({line:Object.freeze({capabilities:ze,defaultOrientation:"vertical",orientationFromSeries:!1,orientations:Object.freeze(["vertical"]),rangeIncludesZero:!1}),bar:Object.freeze({capabilities:Ye,defaultOrientation:"vertical",orientationFromSeries:!0,orientations:Object.freeze(["vertical","horizontal"]),rangeIncludesZero:!0})}),F=e=>{if(e?.categories==null)return[];if(!Array.isArray(e.categories))throw new TypeError(`Chart "${e.id}" categories must be an array`);let t=new Set;return e.categories.map((r,n)=>{let i=typeof r=="string"?{value:n,label:r}:{value:Number(r?.value),label:r?.label};if(!Number.isFinite(i.value)||typeof i.label!="string")throw new TypeError(`Chart "${e.id}" category ${n} must be a string or a { value, label } object`);if(t.has(i.value))throw new TypeError(`Chart "${e.id}" has duplicate category value ${i.value}`);return t.add(i.value),i})},jt=(e,t)=>F(e).find(r=>r.value===t)?.label,Wt=e=>{if(e?.type==null)return"line";if(Object.prototype.hasOwnProperty.call(_t,e.type))return e.type;throw new TypeError(`Unknown AlienCharts series type: "${e.type}"`)},P=e=>{let t=Array.isArray(e?.series)?e.series:[],r=F(e),n=t.length?Wt(t[0]):"line",i=_t[n],o=i.orientationFromSeries&&t[0]?.orientation||i.defaultOrientation;return t.forEach(a=>{let s=Wt(a);if(s!==n){let c=new Set([n,s]),h=c.has("line")&&c.has("bar")?"line and bar":`${n} and ${s}`;throw new TypeError(`Chart "${e.id}" cannot mix ${h} series`)}let l=i.orientationFromSeries&&a.orientation||i.defaultOrientation;if(!i.orientations.includes(l))throw new TypeError(`Chart "${e.id}" has an invalid ${s} orientation`);if(l!==o)throw new TypeError(`Chart "${e.id}" cannot mix ${s} orientations`)}),Object.freeze({capabilities:i.capabilities,categorical:r.length>0,orientation:o,rangeIncludesZero:i.rangeIncludesZero,rendererType:n,type:n})},Rt=e=>{let t=new Map;return e.forEach(r=>{t.set(r.id,P(r))}),t},qt=(e,t)=>t?.get(e?.id)||P(e),T=(e,t)=>{let r=Array.isArray(e?.series)?e.series:[],n=t?.[e?.id];if(!Array.isArray(n)||n.length!==r.length)return r;let i=new Set,o=[];return n.forEach(a=>{Number.isInteger(a)&&(a<0||a>=r.length||i.has(a)||(i.add(a),o.push(r[a])))}),o.length===r.length?o:r},Dr=Object.freeze(Object.keys(_t));var Gt=(e,t)=>Math.max(1e-12,t-e),E=({orientation:e="vertical",categoryRange:t,valueRange:r,plot:n})=>{let i=e==="horizontal",o=Gt(t.min,t.max),a=Gt(r.min,r.max),s=i?n.height:n.width,l=i?n.width:n.height,c=g=>i?(g.y-n.y)/n.height:(g.x-n.x)/n.width,h=g=>i?(g.x-n.x)/n.width:1-(g.y-n.y)/n.height,d=g=>{let p=g.category??g.x,v=g.value??g.y,w=(p-t.min)/o,A=(v-r.min)/a;return i?{x:n.x+A*n.width,y:n.y+w*n.height}:{x:n.x+w*n.width,y:n.y+(1-A)*n.height}},u=g=>({x:t.min+c(g)*o,y:r.min+h(g)*a});return Object.freeze({categoryDragDelta:(g,p)=>(i?p.y-g.y:p.x-g.x)/s*o,categoryPixelLength:s,categoryRatio:c,categoryScaleDelta:(g,p)=>i?p.y-g.y:p.x-g.x,dataBoundsForRect:g=>{let p=u({x:g.left,y:g.top}),v=u({x:g.left+g.width,y:g.top+g.height});return{categoryMin:Math.min(p.x,v.x),categoryMax:Math.max(p.x,v.x),valueMin:Math.min(p.y,v.y),valueMax:Math.max(p.y,v.y)}},dataToScreen:d,horizontal:i,orientation:e,screenToData:u,valueOffsetDelta:(g,p)=>i?-((p.x-g.x)/l)*a:(p.y-g.y)/l*a,valuePixelLength:l,valueRatio:h,valueScaleDelta:(g,p)=>i?p.x-g.x:p.y-g.y})};var G=(e,t,r)=>{let n=(s,l)=>{let c=e.createShader(s);if(e.shaderSource(c,l),e.compileShader(c),!e.getShaderParameter(c,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(c)||"Shader compile failed");return c},i=e.createProgram(),o=n(e.VERTEX_SHADER,t),a=n(e.FRAGMENT_SHADER,r);if(e.attachShader(i,o),e.attachShader(i,a),e.linkProgram(i),e.deleteShader(o),e.deleteShader(a),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error(e.getProgramInfoLog(i)||"Program link failed");return i},k=e=>{let t=String(e||"#38bdf8").replace("#",""),r=t.length===3?t.split("").map(i=>i+i).join(""):t.padEnd(6,"0").slice(0,6),n=Number.parseInt(r,16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]},Zt=(e,t)=>{let r=Math.max(4096,e||0);for(;r<t;)r*=2;return r},X=(e,t,r,n)=>{let i=t.get(r);return i||(i={buffer:e.createBuffer(),gpuCapacity:0,vertices:new Float32Array(Zt(0,n))},t.set(r,i)),i.vertices.length<n&&(i.vertices=new Float32Array(Zt(i.vertices.length,n))),i.gpuCapacity<i.vertices.length&&(i.gpuCapacity=i.vertices.length,e.bindBuffer(e.ARRAY_BUFFER,i.buffer),e.bufferData(e.ARRAY_BUFFER,i.gpuCapacity*Float32Array.BYTES_PER_ELEMENT,e.DYNAMIC_DRAW)),i},Z=(e,t)=>{t.forEach(r=>{r.buffer&&e.deleteBuffer(r.buffer)}),t.clear()};var Kt=.8,Xe=.9,at=3,He=`#version 300 es
|
|
1
|
+
var AlienCharts=(()=>{var At=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var $e=(e,t)=>{for(var r in t)At(e,r,{get:t[r],enumerable:!0})},Oe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Le(t))!Ie.call(e,i)&&i!==r&&At(e,i,{get:()=>t[i],enumerable:!(n=Ee(t,i))||n.enumerable});return e};var Ne=e=>Oe(At({},"__esModule",{value:!0}),e);var Sr={};$e(Sr,{BarSeries:()=>K,LineSeries:()=>Z,createBarSeries:()=>ie,createChartGrid:()=>Re,createLineSeries:()=>k,createMockCharts:()=>De,createSeries:()=>ne});var Pe={arrowLineRight:'<line x1="32" y1="128" x2="176" y2="128"/><polyline points="104 56 176 128 104 200"/><line x1="216" y1="40" x2="216" y2="216"/>',pushPinSimple:'<path d="M224,176a8,8,0,0,1-8,8H136v56a8,8,0,0,1-16,0V184H40a8,8,0,0,1,0-16h9.29L70.46,48H64a8,8,0,0,1,0-16H192a8,8,0,0,1,0,16h-6.46l21.17,120H216A8,8,0,0,1,224,176Z"/>',arrowCounterClockwise:'<polyline points="24 56 24 104 72 104"/><path d="M67.59,192A88,88,0,1,0,65.77,65.77L24,104"/>',arrowsIn:'<polyline points="192 104 152 104 152 64"/><line x1="208" y1="48" x2="152" y2="104"/><polyline points="64 152 104 152 104 192"/><line x1="48" y1="208" x2="104" y2="152"/><polyline points="152 192 152 152 192 152"/><line x1="208" y1="208" x2="152" y2="152"/><polyline points="104 64 104 104 64 104"/><line x1="48" y1="48" x2="104" y2="104"/>',arrowsOut:'<polyline points="160 48 208 48 208 96"/><line x1="152" y1="104" x2="208" y2="48"/><polyline points="96 208 48 208 48 160"/><line x1="104" y1="152" x2="48" y2="208"/><polyline points="208 160 208 208 160 208"/><line x1="152" y1="152" x2="208" y2="208"/><polyline points="48 96 48 48 96 48"/><line x1="104" y1="104" x2="48" y2="48"/>',broom:'<path d="M112,224a95.2,95.2,0,0,1-29-48"/><path d="M192,152c0,31.67,13.31,59,40,72H61A103.65,103.65,0,0,1,32,152c0-28.21,11.23-50.89,29.47-69.64a8,8,0,0,1,8.67-1.81L95.52,90.83a16,16,0,0,0,20.82-9l21-53.11c4.15-10,15.47-15.32,25.63-11.53a20,20,0,0,1,11.51,26.4L153.13,96.69a16,16,0,0,0,8.93,20.76L187,127.29a8,8,0,0,1,5,7.43Z"/><line x1="40.54" y1="112.21" x2="194.26" y2="173.7"/>',waveSine:'<path d="M24,128c104-221.7,104,221.7,208,0"/>',magnifyingGlassPlus:'<line x1="80" y1="112" x2="144" y2="112"/><circle cx="112" cy="112" r="80"/><line x1="168.57" y1="168.57" x2="224" y2="224"/><line x1="112" y1="80" x2="112" y2="144"/>',mapPin:'<circle cx="128" cy="104" r="32"/><path d="M208,104c0,72-80,128-80,128S48,176,48,104a80,80,0,0,1,160,0Z"/>',minus:'<line x1="40" y1="128" x2="216" y2="128"/>',eye:'<path d="M128,56C48,56,16,128,16,128s32,72,112,72,112-72,112-72S208,56,128,56Z"/><circle cx="128" cy="128" r="32"/>'},Fe=new Set(["pushPinSimple"]),M=(e,{size:t=16,className:r=""}={})=>{let n=Pe[e];if(!n)throw new Error(`Unknown AlienCharts icon: ${e}`);let i=Fe.has(e)?'fill="currentColor"':'fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="24"';return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="${t}" height="${t}" class="${r}" aria-hidden="true" ${i}>${n}</svg>`};var zt="#60a5fa";var Xt=new Set(["trendline","hline","vline","pin"]),Be=e=>({color:e?.style?.color||zt,lineWidth:Number.isFinite(e?.style?.lineWidth)?e.style.lineWidth:2,dashPattern:Array.isArray(e?.style?.dashPattern)?e.style.dashPattern:[],extendLeft:!!e?.style?.extendLeft,extendRight:e?.style?.extendRight!==!1,text:typeof e?.style?.text=="string"?e.style.text:""}),at=(e,t)=>Array.isArray(e)?e.filter(r=>r?.chartId===t):[],Ht=e=>({color:zt,lineWidth:2,dashPattern:[],extendLeft:!1,extendRight:e!=="vline",text:""}),Ut=({chartId:e,type:t,start:r,end:n,createDrawingId:i})=>({id:i?.({chartId:e,type:t})||`${e}-drawing-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,chartId:e,type:t,start:r,end:n,createdAt:Date.now(),style:Ht(t)}),St=({chartId:e,type:t,start:r,end:n})=>({id:"__draft__",chartId:e,type:t,start:r,end:n,createdAt:Date.now(),style:Ht(t)}),Yt=(e,t,r)=>{let n=t.x-e.x,i=t.y-e.y;if(Math.abs(n)<=1e-6&&Math.abs(i)<=1e-6)return t;let s=[];n>1e-6?s.push((r.x+r.width-e.x)/n):n<-1e-6&&s.push((r.x-e.x)/n),i>1e-6?s.push((r.y+r.height-e.y)/i):i<-1e-6&&s.push((r.y-e.y)/i);let a=Math.min(...s.filter(l=>Number.isFinite(l)&&l>=0)),o=Number.isFinite(a)?Math.max(1,a):1;return{x:e.x+n*o,y:e.y+i*o}},Mt=({drawing:e,layout:t,projectPoint:r})=>{if(!e?.start||!e?.end)return null;let n=r(e.start,t),i=r(e.end,t),s=Be(e),a=n,o=i;if(e.type==="pin")return{start:n,end:n,lineStart:n,lineEnd:n,style:s};if(e.type==="hline"){let l=Math.abs(i.x-n.x)>1e-6?i.x:t.plot.x+t.plot.width;a={x:s.extendRight?t.plot.x:n.x,y:n.y},o={x:s.extendRight?t.plot.x+t.plot.width:l,y:n.y}}else e.type==="vline"?(a={x:n.x,y:t.plot.y},o={x:n.x,y:t.plot.y+t.plot.height}):e.type==="trendline"&&(s.extendLeft&&(a=Yt(i,n,t.plot)),s.extendRight&&(o=Yt(n,i,t.plot)));return{start:n,end:i,lineStart:a,lineEnd:o,style:s}},ke=(e,t,r)=>{let n=r.x-t.x,i=r.y-t.y;if(n===0&&i===0)return Math.hypot(e.x-t.x,e.y-t.y);let s=Math.max(0,Math.min(1,((e.x-t.x)*n+(e.y-t.y)*i)/(n*n+i*i)));return Math.hypot(e.x-(t.x+s*n),e.y-(t.y+s*i))},Vt=({point:e,drawing:t,layout:r,projectPoint:n})=>{let i=Mt({drawing:t,layout:r,projectPoint:n});return i?t.type!=="pin"&&Math.hypot(e.x-i.start.x,e.y-i.start.y)<=10?{drawing:t,endpoint:"start"}:t.type==="pin"&&Math.hypot(e.x-i.start.x,e.y-i.start.y)<=14?{drawing:t,endpoint:"move"}:t.type==="trendline"&&Math.hypot(e.x-i.end.x,e.y-i.end.y)<=10?{drawing:t,endpoint:"end"}:ke(e,i.lineStart,i.lineEnd)<=8?{drawing:t,endpoint:null}:null:null},Rt=(e,t,r)=>(Array.isArray(e)?e:[]).map(n=>n?.id===t?r(n):n),Wt=(e,t)=>(Array.isArray(e)?e:[]).filter(r=>r?.id!==t);var Ye=Object.freeze({appendAnimation:!0,drawings:!0,latestValue:!0,markers:!0,movingAverage:!0}),ze=Object.freeze({appendAnimation:!1,drawings:!1,latestValue:!1,markers:!1,movingAverage:!1}),_t=Object.freeze({line:Object.freeze({capabilities:Ye,defaultOrientation:"vertical",orientationFromSeries:!1,orientations:Object.freeze(["vertical"]),rangeIncludesZero:!1}),bar:Object.freeze({capabilities:ze,defaultOrientation:"vertical",orientationFromSeries:!0,orientations:Object.freeze(["vertical","horizontal"]),rangeIncludesZero:!0})}),P=e=>{if(e?.categories==null)return[];if(!Array.isArray(e.categories))throw new TypeError(`Chart "${e.id}" categories must be an array`);let t=new Set;return e.categories.map((r,n)=>{let i=typeof r=="string"?{value:n,label:r}:{value:Number(r?.value),label:r?.label};if(!Number.isFinite(i.value)||typeof i.label!="string")throw new TypeError(`Chart "${e.id}" category ${n} must be a string or a { value, label } object`);if(t.has(i.value))throw new TypeError(`Chart "${e.id}" has duplicate category value ${i.value}`);return t.add(i.value),i})},qt=(e,t)=>P(e).find(r=>r.value===t)?.label,jt=e=>{if(e?.type==null)return"line";if(Object.prototype.hasOwnProperty.call(_t,e.type))return e.type;throw new TypeError(`Unknown AlienCharts series type: "${e.type}"`)},F=e=>{let t=Array.isArray(e?.series)?e.series:[],r=P(e),n=t.length?jt(t[0]):"line",i=_t[n],s=i.orientationFromSeries&&t[0]?.orientation||i.defaultOrientation;return t.forEach(a=>{let o=jt(a);if(o!==n){let c=new Set([n,o]),h=c.has("line")&&c.has("bar")?"line and bar":`${n} and ${o}`;throw new TypeError(`Chart "${e.id}" cannot mix ${h} series`)}let l=i.orientationFromSeries&&a.orientation||i.defaultOrientation;if(!i.orientations.includes(l))throw new TypeError(`Chart "${e.id}" has an invalid ${o} orientation`);if(l!==s)throw new TypeError(`Chart "${e.id}" cannot mix ${o} orientations`)}),Object.freeze({capabilities:i.capabilities,categorical:r.length>0,orientation:s,rangeIncludesZero:i.rangeIncludesZero,rendererType:n,type:n})},Dt=e=>{let t=new Map;return e.forEach(r=>{t.set(r.id,F(r))}),t},Gt=(e,t)=>t?.get(e?.id)||F(e),E=(e,t)=>{let r=Array.isArray(e?.series)?e.series:[],n=t?.[e?.id];if(!Array.isArray(n)||n.length!==r.length)return r;let i=new Set,s=[];return n.forEach(a=>{Number.isInteger(a)&&(a<0||a>=r.length||i.has(a)||(i.add(a),s.push(r[a])))}),s.length===r.length?s:r},Dr=Object.freeze(Object.keys(_t));var Zt=(e,t)=>Math.max(1e-12,t-e),L=({orientation:e="vertical",categoryRange:t,valueRange:r,plot:n})=>{let i=e==="horizontal",s=Zt(t.min,t.max),a=Zt(r.min,r.max),o=i?n.height:n.width,l=i?n.width:n.height,c=g=>i?(g.y-n.y)/n.height:(g.x-n.x)/n.width,h=g=>i?(g.x-n.x)/n.width:1-(g.y-n.y)/n.height,d=g=>{let p=g.category??g.x,b=g.value??g.y,w=(p-t.min)/s,C=(b-r.min)/a;return i?{x:n.x+C*n.width,y:n.y+w*n.height}:{x:n.x+w*n.width,y:n.y+(1-C)*n.height}},u=g=>({x:t.min+c(g)*s,y:r.min+h(g)*a});return Object.freeze({categoryDragDelta:(g,p)=>(i?p.y-g.y:p.x-g.x)/o*s,categoryPixelLength:o,categoryRatio:c,categoryScaleDelta:(g,p)=>i?p.y-g.y:p.x-g.x,dataBoundsForRect:g=>{let p=u({x:g.left,y:g.top}),b=u({x:g.left+g.width,y:g.top+g.height});return{categoryMin:Math.min(p.x,b.x),categoryMax:Math.max(p.x,b.x),valueMin:Math.min(p.y,b.y),valueMax:Math.max(p.y,b.y)}},dataToScreen:d,horizontal:i,orientation:e,screenToData:u,valueOffsetDelta:(g,p)=>i?-((p.x-g.x)/l)*a:(p.y-g.y)/l*a,valuePixelLength:l,valueRatio:h,valueScaleDelta:(g,p)=>i?p.x-g.x:p.y-g.y})};var q=(e,t,r)=>{let n=(o,l)=>{let c=e.createShader(o);if(e.shaderSource(c,l),e.compileShader(c),!e.getShaderParameter(c,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(c)||"Shader compile failed");return c},i=e.createProgram(),s=n(e.VERTEX_SHADER,t),a=n(e.FRAGMENT_SHADER,r);if(e.attachShader(i,s),e.attachShader(i,a),e.linkProgram(i),e.deleteShader(s),e.deleteShader(a),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error(e.getProgramInfoLog(i)||"Program link failed");return i},B=e=>{let t=String(e||"#38bdf8").replace("#",""),r=t.length===3?t.split("").map(i=>i+i).join(""):t.padEnd(6,"0").slice(0,6),n=Number.parseInt(r,16);return[(n>>16&255)/255,(n>>8&255)/255,(n&255)/255]},Kt=(e,t)=>{let r=Math.max(4096,e||0);for(;r<t;)r*=2;return r},z=(e,t,r,n)=>{let i=t.get(r);return i||(i={buffer:e.createBuffer(),gpuCapacity:0,vertices:new Float32Array(Kt(0,n))},t.set(r,i)),i.vertices.length<n&&(i.vertices=new Float32Array(Kt(i.vertices.length,n))),i.gpuCapacity<i.vertices.length&&(i.gpuCapacity=i.vertices.length,e.bindBuffer(e.ARRAY_BUFFER,i.buffer),e.bufferData(e.ARRAY_BUFFER,i.gpuCapacity*Float32Array.BYTES_PER_ELEMENT,e.DYNAMIC_DRAW)),i},G=(e,t)=>{t.forEach(r=>{r.buffer&&e.deleteBuffer(r.buffer)}),t.clear()};var Jt=.8,Xe=.9,st=3,He=`#version 300 es
|
|
2
2
|
in vec2 a_unit;
|
|
3
3
|
in vec3 a_bar;
|
|
4
4
|
uniform vec2 u_resolution;
|
|
@@ -11,7 +11,7 @@ var AlienCharts=(()=>{var Ct=Object.defineProperty;var Ee=Object.getOwnPropertyD
|
|
|
11
11
|
uniform int u_orientation;
|
|
12
12
|
|
|
13
13
|
void main() {
|
|
14
|
-
float groupWidth = a_bar.z * ${
|
|
14
|
+
float groupWidth = a_bar.z * ${Jt.toFixed(1)};
|
|
15
15
|
float sliceWidth = groupWidth / max(1.0, u_seriesCount);
|
|
16
16
|
float center = a_bar.x - groupWidth * 0.5
|
|
17
17
|
+ sliceWidth * (u_seriesIndex + 0.5);
|
|
@@ -48,7 +48,7 @@ var AlienCharts=(()=>{var Ct=Object.defineProperty;var Ee=Object.getOwnPropertyD
|
|
|
48
48
|
void main() {
|
|
49
49
|
outColor = vec4(u_color, 1.0);
|
|
50
50
|
}
|
|
51
|
-
`,
|
|
51
|
+
`,Qt=({visiblePoints:e,index:t,categoryMin:r,categoryMax:n})=>{let i=e.pointCount,s=e.x[t],a=(n-r)/Math.max(10,i||1),o=t>0?s-e.x[t-1]:1/0,l=t+1<i?e.x[t+1]-s:1/0,c=Math.min(o>0?o:1/0,l>0?l:1/0);return Number.isFinite(c)||(c=Number.isFinite(o)&&o>0?o:Number.isFinite(l)&&l>0?l:a),Math.max(Number.EPSILON,c||a||1)},Ve=({visiblePoints:e,pointIndex:t,seriesIndex:r,seriesCount:n,categoryMin:i,categoryMax:s})=>{let a=e.x[t],l=Qt({visiblePoints:e,index:t,categoryMin:i,categoryMax:s})*Jt,c=l/Math.max(1,n);return a-l/2+c*(r+.5)},We=({vertices:e,visiblePoints:t,categoryMin:r,categoryMax:n})=>{for(let i=0;i<t.pointCount;i+=1){let s=i*st;e[s]=t.x[i],e[s+1]=t.y[i],e[s+2]=Qt({visiblePoints:t,index:i,categoryMin:r,categoryMax:n})}return t.pointCount},te=e=>{let t=q(e,He,Ue),r=e.createBuffer(),n=new Map;e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW);let i=Object.freeze({aBar:e.getAttribLocation(t,"a_bar"),aUnit:e.getAttribLocation(t,"a_unit"),uBaseline:e.getUniformLocation(t,"u_baseline"),uCategoryRange:e.getUniformLocation(t,"u_categoryRange"),uColor:e.getUniformLocation(t,"u_color"),uOrientation:e.getUniformLocation(t,"u_orientation"),uRect:e.getUniformLocation(t,"u_rect"),uResolution:e.getUniformLocation(t,"u_resolution"),uSeriesCount:e.getUniformLocation(t,"u_seriesCount"),uSeriesIndex:e.getUniformLocation(t,"u_seriesIndex"),uValueRange:e.getUniformLocation(t,"u_valueRange")});return{draw({categoryPixelLength:s,chart:a,descriptor:o,pixelHeight:l,pixelWidth:c,scaledPlot:h,seriesOrderByChart:d,state:u,yRange:m}){e.disable(e.BLEND),e.useProgram(t),e.enableVertexAttribArray(i.aUnit),e.enableVertexAttribArray(i.aBar),e.bindBuffer(e.ARRAY_BUFFER,r),e.vertexAttribPointer(i.aUnit,2,e.FLOAT,!1,0,0),e.vertexAttribDivisor(i.aUnit,0),e.uniform2f(i.uResolution,c,l),e.uniform4f(i.uRect,h.x,h.y,h.width,h.height),e.uniform2f(i.uCategoryRange,u.xMin,u.xMax),e.uniform2f(i.uValueRange,m.minY,m.maxY),e.uniform1f(i.uBaseline,0),e.uniform1i(i.uOrientation,o.orientation==="horizontal"?1:0);let x=E(a,d);return e.uniform1f(i.uSeriesCount,Math.max(1,x.length)),x.forEach((f,y)=>{let v=f.getVisiblePoints(u.xMin,u.xMax,s);if(!v.pointCount)return;let g=v.pointCount*st,p=z(e,n,f.id,g),b=We({vertices:p.vertices,visiblePoints:v,categoryMin:u.xMin,categoryMax:u.xMax}),[w,C,S]=B(f.color);e.uniform3f(i.uColor,w,C,S),e.uniform1f(i.uSeriesIndex,y),e.bindBuffer(e.ARRAY_BUFFER,p.buffer),e.vertexAttribPointer(i.aBar,st,e.FLOAT,!1,0,0),e.vertexAttribDivisor(i.aBar,1),e.bufferSubData(e.ARRAY_BUFFER,0,p.vertices,0,b*st),e.drawArraysInstanced(e.TRIANGLES,0,6,b)}),e.vertexAttribDivisor(i.aBar,0),{seriesEndpoints:new Map}},getTooltipCategory(s){return Ve(s)},destroy(){G(e,n),e.deleteBuffer(r),e.deleteProgram(t)}}};var ot=(e,t)=>e instanceof t?e:ArrayBuffer.isView(e)?new t(e):Array.isArray(e)?new t(e):new t(0),Tt=(e,t)=>{let r=0,n=e.length;for(;r<n;){let i=r+n>>1;e[i]<t?r=i+1:n=i}return r},ee=(e,t)=>{let r=0,n=e.length;for(;r<n;){let i=r+n>>1;e[i]<=t?r=i+1:n=i}return r},lt=(e,t)=>{t<0||e.includes(t)||e.push(t)},Et=(e,t,r,n=0,i=e.length)=>{if(r<=1||e.length<=r)return{x:e,y:t,bucketSize:1};let s=Math.max(0,Math.floor(n/r)*r),a=Math.min(e.length,i),o=Math.ceil((a-s)/r)*4,l=new Float64Array(o),c=new Float32Array(o),h=0;for(let d=s;d<a;d+=r){let u=Math.min(a,d+r),m=d,x=d;for(let y=d+1;y<u;y+=1)t[y]<t[m]&&(m=y),t[y]>t[x]&&(x=y);let f=[];lt(f,d),lt(f,m),lt(f,x),lt(f,u-1),f.sort((y,v)=>y-v);for(let y=0;y<f.length;y+=1){let v=f[y];l[h]=e[v],c[h]=t[v],h+=1}}return{x:l.subarray(0,h),y:c.subarray(0,h),bucketSize:r}},re=(e,t,r)=>{if(!t?.length)return r;if(!r?.length)return t;let n=new e(t.length+r.length);return n.set(t,0),n.set(r,t.length),n},ct=class{constructor({id:t,name:r,color:n,x:i,y:s,maxLevels:a=18}){this.id=t,this.name=r||t,this.color=n||"#38bdf8",this.maxLevels=a;let o=ot(i,Float64Array),l=ot(s,Float32Array);this._length=Math.min(o.length,l.length);let c=Math.max(1,this._length);this.rawX=new Float64Array(c),this.rawY=new Float32Array(c),this.rawX.set(o.subarray(0,this._length)),this.rawY.set(l.subarray(0,this._length)),this.levels=[],this.rebuildLevels()}get length(){return this._length}append(t,r){let n=ot(t,Float64Array),i=ot(r,Float32Array),s=Math.min(n.length,i.length);if(s===0)return;let a=this.length;this.ensureRawCapacity(a+s),this.rawX.set(n.subarray(0,s),a),this.rawY.set(i.subarray(0,s),a),this._length=a+s,this.markLevelsDirty(a)}rebuildLevels(){let t=this.rawX.subarray(0,this.length),r=this.rawY.subarray(0,this.length);this.levels=[{x:t,y:r,bucketSize:1}];let n=4;for(;this.levels.length<this.maxLevels&&n<Math.max(8,t.length);)this.levels.push(Et(t,r,n)),n*=4}ensureRawCapacity(t){if(t<=this.rawX.length&&t<=this.rawY.length)return;let r=Math.max(t,Math.ceil(this.rawX.length*1.5)),n=new Float64Array(r),i=new Float32Array(r);n.set(this.rawX.subarray(0,this.length)),i.set(this.rawY.subarray(0,this.length)),this.rawX=n,this.rawY=i}markLevelsDirty(t){let r=this.rawX.subarray(0,this.length),n=this.rawY.subarray(0,this.length);this.levels[0]={x:r,y:n,bucketSize:1};let i=this.levels.length>0?this.levels[this.levels.length-1].bucketSize*4:4;for(;this.levels.length<this.maxLevels&&i<Math.max(8,r.length);)this.levels.push(Et(r,n,i)),i*=4;for(let s=1;s<this.levels.length;s+=1){let a=this.levels[s],o=Math.floor(t/a.bucketSize)*a.bucketSize;a.dirtyFrom=Math.min(a.dirtyFrom??o,o)}}ensureLevel(t){let r=this.levels[t];if(!r||t===0||r.dirtyFrom==null)return r;let n=this.rawX.subarray(0,this.length),i=this.rawY.subarray(0,this.length),s=Math.floor(r.dirtyFrom/r.bucketSize)*r.bucketSize,a=n[s]??n[0]??0,o=Tt(r.x,a),l=Et(n,i,r.bucketSize,s,n.length);return this.levels[t]={x:re(Float64Array,r.x.subarray(0,o),l.x),y:re(Float32Array,r.y.subarray(0,o),l.y),bucketSize:r.bucketSize},this.levels[t]}selectLevel(t,r,n,i=2.5){let s=this.levels[0].x;if(s.length===0)return this.levels[0];let a=Tt(s,t),o=ee(s,r),l=Math.max(0,o-a),c=Math.max(32,n*i),h=Math.max(1,l/c),d=0;for(let u=1;u<this.levels.length&&this.levels[u].bucketSize<=h;u+=1)d=u;return this.ensureLevel(d)}getVisiblePoints(t,r,n){let i=this.selectLevel(t,r,n),s=Math.max(0,Tt(i.x,t)-1),a=Math.min(i.x.length,ee(i.x,r)+1);return{x:i.x.subarray(s,a),y:i.y.subarray(s,a),bucketSize:i.bucketSize,pointCount:Math.max(0,a-s)}}},Z=class extends ct{constructor(t){super(t),this.type="line"}},K=class extends ct{constructor({orientation:t="vertical",...r}){if(super(r),t!=="vertical"&&t!=="horizontal")throw new TypeError('BarSeries orientation must be "vertical" or "horizontal"');this.type="bar",this.orientation=t}},k=e=>new Z(e),ne=k,ie=e=>new K(e);var J=6,je=1.5,qe=1,ht=7,Ge=5,Ze=`#version 300 es
|
|
52
52
|
in vec2 a_xy;
|
|
53
53
|
uniform vec2 u_resolution;
|
|
54
54
|
uniform vec4 u_rect;
|
|
@@ -127,33 +127,35 @@ var AlienCharts=(()=>{var Ct=Object.defineProperty;var Ee=Object.getOwnPropertyD
|
|
|
127
127
|
float alpha = 1.0 - smoothstep(u_lineHalfWidth, expand, distanceFromCenter);
|
|
128
128
|
outColor = vec4(u_color, alpha);
|
|
129
129
|
}
|
|
130
|
-
`,tr=({vertices:e,visiblePoints:t,pointCount:r,animatedPoint:n})=>{for(let i=0;i<r;i+=1){let o=n&&i===n.index?n:{x:t.x[i],y:t.y[i]};e[i*2]=o.x,e[i*2+1]=o.y}},er=({series:e,state:t,yRange:r,plot:n})=>{if(e.length!==1)return null;let i=e.rawX[0],o=e.rawY[0];if(i<t.xMin||i>t.xMax||o<r.minY||o>r.maxY)return null;let a=(t.xMax-t.xMin)/Math.max(1,n.width)*3;return{x:new Float64Array([i-a,i+a]),y:new Float32Array([o,o]),bucketSize:1,pointCount:2,endpoint:{x:i,y:o}}},rr=(e,t,r,n,i,o)=>{e[t]=r.x,e[t+1]=r.y,e[t+2]=n.x,e[t+3]=n.y,e[t+4]=i,e[t+5]=o},ie=(e,t,r)=>t&&r===t.index?{x:t.x,y:t.y}:{x:e.x[r],y:e.y[r]},nr=({vertices:e,visiblePoints:t,pointCount:r,animatedPoint:n})=>{let i=0;for(let o=0;o<r-1;o+=1){let a=ie(t,n,o),s=ie(t,n,o+1);[[-1,0],[1,0],[-1,1],[-1,1],[1,0],[1,1]].forEach(([l,c])=>{rr(e,i,a,s,l,c),i+=Q})}return i/Q},ae=({x:e,y:t,state:r,yRange:n,plot:i})=>({x:i.x+(e-r.xMin)/(r.xMax-r.xMin)*i.width,y:i.y+(n.maxY-t)/(n.maxY-n.minY)*i.height}),ir=({vertices:e,visiblePoints:t,pointCount:r,state:n,yRange:i,plot:o})=>{let a=0,s=0,l=ct+Ge;for(let c=0;c<r-1;c+=1){let h={x:t.x[c],y:t.y[c]},d={x:t.x[c+1],y:t.y[c+1]},u=ae({...h,state:n,yRange:i,plot:o}),m=ae({...d,state:n,yRange:i,plot:o}),x=Math.hypot(m.x-u.x,m.y-u.y);if(!Number.isFinite(x)||x<=0)continue;let f=0;for(;f<x;){let y=s%l,b=y<ct?ct-y:l-y,g=Math.min(b,x-f);if(y<ct){if(a+4>e.length)return a/2;let p=f/x,v=(f+g)/x;e[a]=h.x+(d.x-h.x)*p,e[a+1]=h.y+(d.y-h.y)*p,e[a+2]=h.x+(d.x-h.x)*v,e[a+3]=h.y+(d.y-h.y)*v,a+=4}f+=g,s+=g}}return a/2},ar=e=>e?.enabled?{enabled:!0,period:Number.isFinite(Number(e.period))?Math.max(1,Math.round(Number(e.period))):21,type:e.type==="sma"?"sma":"ema"}:null,oe=({sourceY:e,startIndex:t,period:r,type:n,previousAverage:i})=>{let o=new Float32Array(Math.max(0,e.length-t));if(!o.length)return o;if(n==="sma"){let l=0,c=Math.max(0,t-r+1);for(let h=c;h<t;h+=1)l+=e[h];for(let h=t;h<e.length;h+=1){l+=e[h];let d=h-r;d>=c&&(l-=e[d]),o[h-t]=l/Math.min(r,h+1)}return o}let a=2/(r+1),s=Number.isFinite(i)?i:e[t];for(let l=t;l<e.length;l+=1)s=e[l]*a+s*(1-a),o[l-t]=s;return o},or=({chart:e,movingAverage:t,cache:r})=>{let n=ar(t);return n?e.series.map(i=>{if(!i.length)return null;let o=`${i.id}::ma:${n.type}:${n.period}`,a=r.get(o);if(a&&a.sourceSeries===i&&a.sourceLength<=i.length){let c=a.sourceLength;if(c<i.length){let h=oe({sourceY:i.rawY.subarray(0,i.length),startIndex:c,period:n.period,type:n.type,previousAverage:c>0?a.series.rawY[c-1]:void 0});a.series.append(i.rawX.subarray(c,i.length),h),a.sourceLength=i.length}return a.series.color=i.color,a.series.name=`${i.name} ${n.type.toUpperCase()} ${n.period}`,a.series}let s=oe({sourceY:i.rawY.subarray(0,i.length),startIndex:0,period:n.period,type:n.type}),l=B({id:o,name:`${i.name} ${n.type.toUpperCase()} ${n.period}`,color:i.color,x:i.rawX.subarray(0,i.length),y:s});return r.set(o,{sourceSeries:i,sourceLength:i.length,series:l}),l}).filter(Boolean):[]},sr=(e,t)=>Object.freeze({aXy:e.getAttribLocation(t,"a_xy"),uColor:e.getUniformLocation(t,"u_color"),uRect:e.getUniformLocation(t,"u_rect"),uResolution:e.getUniformLocation(t,"u_resolution"),uXRange:e.getUniformLocation(t,"u_xRange"),uYRange:e.getUniformLocation(t,"u_yRange")}),se=e=>{let t=G(e,Ze,Ke),r=G(e,Je,Qe),n=sr(e,t),i=Object.freeze({aAlong:e.getAttribLocation(r,"a_along"),aEnd:e.getAttribLocation(r,"a_end"),aSide:e.getAttribLocation(r,"a_side"),aStart:e.getAttribLocation(r,"a_start"),uColor:e.getUniformLocation(r,"u_color"),uEdgeWidth:e.getUniformLocation(r,"u_edgeWidth"),uLineHalfWidth:e.getUniformLocation(r,"u_lineHalfWidth"),uRect:e.getUniformLocation(r,"u_rect"),uResolution:e.getUniformLocation(r,"u_resolution"),uXRange:e.getUniformLocation(r,"u_xRange"),uYRange:e.getUniformLocation(r,"u_yRange")}),o=new Map,a=new Map,s=new Map,l=(c,h,d,u,m,x)=>{e.uniform2f(c.uResolution,h,d),e.uniform4f(c.uRect,u.x,u.y,u.width,u.height),e.uniform2f(c.uXRange,m.xMin,m.xMax),e.uniform2f(c.uYRange,x.minY,x.maxY)};return{draw({antialiasLines:c,chart:h,descriptor:d,dpr:u,getAppendAnimatedPoint:m,movingAverage:x,now:f,pixelHeight:y,pixelWidth:b,plot:g,scaledPlot:p,seriesOrderByChart:v,state:w,yRange:A}){let S=!!c,I=S?r:t,j=S?i:n;e.useProgram(I),l(j,b,y,p,w,A),S?(e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.enableVertexAttribArray(i.aStart),e.enableVertexAttribArray(i.aEnd),e.enableVertexAttribArray(i.aSide),e.enableVertexAttribArray(i.aAlong),e.uniform1f(i.uLineHalfWidth,je*u/2),e.uniform1f(i.uEdgeWidth,qe*u)):(e.disable(e.BLEND),e.enableVertexAttribArray(n.aXy));let Y=new Map;d.capabilities.movingAverage&&x?.enabled&&x?.hideBase||T(h,v).forEach(_=>{let R=_.getVisiblePoints(w.xMin,w.xMax,g.width),$=null;if(R.pointCount<2){let q=er({series:_,state:w,yRange:A,plot:g});if(!q)return;R=q,$=q.endpoint}let D=$?null:m({seriesId:_.id,visiblePoints:R,now:f}),O=D?.pointCount??R.pointCount;D?Y.set(_.id,{x:D.x,y:D.y}):$&&Y.set(_.id,$);let[yt,vt,Te]=k(_.color);if(e.uniform3f(j.uColor,yt,vt,Te),S){let q=Math.max(0,O-1)*6*Q,wt=X(e,a,_.id,q),kt=nr({vertices:wt.vertices,visiblePoints:R,pointCount:O,animatedPoint:D}),nt=Q*Float32Array.BYTES_PER_ELEMENT;e.bindBuffer(e.ARRAY_BUFFER,wt.buffer),e.vertexAttribPointer(i.aStart,2,e.FLOAT,!1,nt,0),e.vertexAttribPointer(i.aEnd,2,e.FLOAT,!1,nt,2*Float32Array.BYTES_PER_ELEMENT),e.vertexAttribPointer(i.aSide,1,e.FLOAT,!1,nt,4*Float32Array.BYTES_PER_ELEMENT),e.vertexAttribPointer(i.aAlong,1,e.FLOAT,!1,nt,5*Float32Array.BYTES_PER_ELEMENT),e.bufferSubData(e.ARRAY_BUFFER,0,wt.vertices,0,kt*Q),e.drawArrays(e.TRIANGLES,0,kt);return}let bt=X(e,o,_.id,O*2);tr({vertices:bt.vertices,visiblePoints:R,pointCount:O,animatedPoint:D}),e.bindBuffer(e.ARRAY_BUFFER,bt.buffer),e.vertexAttribPointer(n.aXy,2,e.FLOAT,!1,0,0),e.bufferSubData(e.ARRAY_BUFFER,0,bt.vertices,0,O*2),e.drawArrays(e.LINE_STRIP,0,O)});let Pt=or({chart:h,movingAverage:d.capabilities.movingAverage?x:null,cache:s});return Pt.length&&(e.disable(e.BLEND),e.useProgram(t),e.enableVertexAttribArray(n.aXy),l(n,b,y,p,w,A),T({...h,series:Pt},v).forEach(_=>{let R=_.getVisiblePoints(w.xMin,w.xMax,g.width);if(R.pointCount<2)return;let $=X(e,o,_.id,R.pointCount*8*2),D=ir({vertices:$.vertices,visiblePoints:R,pointCount:R.pointCount,state:w,yRange:A,plot:g});if(D<2)return;let[O,yt,vt]=k(_.color);e.uniform3f(n.uColor,O,yt,vt),e.bindBuffer(e.ARRAY_BUFFER,$.buffer),e.vertexAttribPointer(n.aXy,2,e.FLOAT,!1,0,0),e.bufferSubData(e.ARRAY_BUFFER,0,$.vertices,0,D*2),e.drawArrays(e.LINES,0,D)})),e.disable(e.BLEND),{seriesEndpoints:Y}},destroy(){Z(e,o),Z(e,a),s.clear(),e.deleteProgram(t),e.deleteProgram(r)}}};var lr=Object.freeze({bar:Qt,line:se}),le=e=>{let t=new Map(Object.entries(lr).map(([r,n])=>[r,n(e)]));return{draw(r,n){let i=t.get(r);if(!i)throw new TypeError(`No AlienCharts renderer registered for "${r}"`);return i.draw(n)},getTooltipCategory(r,n){let i=t.get(r);if(!i)throw new TypeError(`No AlienCharts renderer registered for "${r}"`);return i.getTooltipCategory?.(n)??n.visiblePoints.x[n.pointIndex]},destroy(){t.forEach(r=>r.destroy()),t.clear()}}};var ue=360,fe=58,dt=Object.freeze({left:38,right:fe,top:34,bottom:28}),pe=Object.freeze({left:fe,right:20,top:34,bottom:28}),cr=Object.freeze({...dt,bottom:42}),hr=Object.freeze({...pe,left:128}),ut=.05,ft=40,ce=5,he=5,dr=10,Lt=1e9,Et=.1,It="#f5f9ff";var xe=(e,t)=>(t||P(e)).orientation,tt=(e,t)=>{let r=F(e).length>0;return xe(e,t)==="horizontal"?r?hr:pe:r?cr:dt},H=(e,t,r)=>xe(e,r)==="horizontal"?t.height:t.width;var ur=e=>{let[t,r,n]=k(e),i=a=>a<=.03928?a/12.92:((a+.055)/1.055)**2.4;return .2126*i(t)+.7152*i(r)+.0722*i(n)>.45?"#111827":"#ffffff"},fr=e=>(e.__labelTextColorFor!==e.color&&(e.__labelTextColorFor=e.color,e.__labelTextColor=ur(e.color)),e.__labelTextColor),pr=(e,t)=>{let r=0,n=e.length;for(;r<n;){let i=r+n>>1;e[i]<t?r=i+1:n=i}return r},ge=(e,t)=>{if(!e.length)return-1;let r=pr(e,t);if(r<=0)return 0;if(r>=e.length)return e.length-1;let n=r-1;return Math.abs(e[r]-t)<Math.abs(t-e[n])?r:n},U=e=>{let t=1/0,r=-1/0;return e.series.forEach(n=>{n.length&&(t=Math.min(t,n.rawX[0]),r=Math.max(r,n.rawX[n.length-1]))}),{minX:t,maxX:r}},et=e=>{let t=F(e).map(n=>n.value).sort((n,i)=>n-i);if(!t.length)return dr;let r=1/0;for(let n=1;n<t.length;n+=1)r=Math.min(r,t[n]-t[n-1]);return Number.isFinite(r)?r:1},N=(e,t=null)=>{let r=F(e).map(a=>a.value).sort((a,s)=>a-s);if(r.length){let a=Number.isFinite(t)&&t>0?Math.max(1,Math.floor(t)):r.length,s=r.slice(-a),l=s[0],c=s[s.length-1],h=r.indexOf(l),d=r.lastIndexOf(c),u=h>0?l-r[h-1]:s[1]-l||1,m=d+1<r.length?r[d+1]-c:c-s[s.length-2]||u;return{xMin:l-u/2,xMax:c+m/2}}let{minX:n,maxX:i}=U(e);if(!Number.isFinite(n)||!Number.isFinite(i))return{xMin:0,xMax:1};if(n===i){let a=Number.isFinite(t)&&t>0?Math.max(10,t):10,s=i+a*Et;return{xMin:s-a,xMax:s}}let o=i-n;if(Number.isFinite(t)&&t>0){o=Math.min(o,t);let a=i+o*Et;return{xMin:a-o,xMax:a}}return{xMin:n,xMax:i+o*Et}},V=(e,t,r,n,i)=>{let o=i||P(e),a=1/0,s=-1/0,l=0,c=1;e.series.forEach(m=>{let x=m.getVisiblePoints(t,r,n);l+=x.pointCount,c=Math.max(c,x.bucketSize);for(let f=0;f<x.y.length;f+=1)a=Math.min(a,x.y[f]),s=Math.max(s,x.y[f])});let h=Number(e.yRange?.min),d=Number(e.yRange?.max);if(Number.isFinite(h)&&Number.isFinite(d)&&h<d)return{minY:h,maxY:d,renderedPoints:l,bucketSize:c};if(!Number.isFinite(a)||!Number.isFinite(s))return{minY:0,maxY:1,renderedPoints:l,bucketSize:c};if(o.rangeIncludesZero){if(a>=0)return{minY:0,maxY:s===0?1:s*1.08,renderedPoints:l,bucketSize:c};if(s<=0)return{minY:a===0?-1:a*1.08,maxY:0,renderedPoints:l,bucketSize:c}}a===s&&(a-=1,s+=1);let u=(s-a)*.08;return{minY:a-u,maxY:s+u,renderedPoints:l,bucketSize:c}},pt=(e,t=1,r=0)=>{let n=Math.min(ft,Math.max(ut,t)),i=(e.minY+e.maxY)/2+r,o=(e.maxY-e.minY)*n/2;return{...e,minY:i-o,maxY:i+o}},ht=e=>e.replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,""),xt=e=>{if(!Number.isFinite(e))return"";let t=Math.abs(e);return t!==0&&t<1e-4?e.toExponential(2):t<1?ht(e.toPrecision(5)):t>=1e5?e.toFixed(0):t>=1e3?ht(e.toFixed(1)):t>=10?ht(e.toFixed(2)):ht(e.toFixed(4))},me=e=>{if(!Number.isFinite(e))return"";let t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(t>=1e10?0:1)}B`:t>=1e6?`${(e/1e6).toFixed(t>=1e7?0:1)}M`:t>=1e3?`${(e/1e3).toFixed(t>=1e4?0:1)}k`:xt(e)},gt=(e,t)=>{if(!e||!t)return null;let r=Math.min(e.x,t.x),n=Math.min(e.y,t.y);return{left:r,top:n,width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}},de=(e,t)=>({x:Math.min(t.x+t.width,Math.max(t.x,e.x)),y:Math.min(t.y+t.height,Math.max(t.y,e.y))}),ye=({chart:e,descriptor:t,state:r,plot:n,yScaleRef:i,yCenterOffsetRef:o})=>pt(V(e,r.xMin,r.xMax,H(e,n,t),t),i.current.get(e.id)??1,o.current.get(e.id)??0),ve=({chart:e,descriptor:t,plot:r,start:n,end:i,initialVisiblePoints:o,viewStateRef:a,yScaleRef:s,yCenterOffsetRef:l,yManualScaleRef:c})=>{let h=gt(de(n,r),de(i,r));if(!h||h.width<6||h.height<6)return!1;let d=t||P(e),u=a.current.get(e.id)||N(e,o),m=ye({chart:e,descriptor:d,state:u,plot:r,yScaleRef:s,yCenterOffsetRef:l}),f=E({orientation:d.orientation,categoryRange:{min:u.xMin,max:u.xMax},valueRange:{min:m.minY,max:m.maxY},plot:r}).dataBoundsForRect(h);if(f.categoryMax-f.categoryMin<et(e))return!1;let y=f.valueMax-f.valueMin;if(!Number.isFinite(y)||y<=0)return!1;a.current.set(e.id,{xMin:f.categoryMin,xMax:f.categoryMax});let b=V(e,f.categoryMin,f.categoryMax,H(e,r,d),d),g=b.maxY-b.minY;if(Number.isFinite(g)&&g>0){let p=(f.valueMin+f.valueMax)/2,v=(b.minY+b.maxY)/2;s.current.set(e.id,Math.min(ft,Math.max(ut,y/g))),l.current.set(e.id,p-v),c.current.add(e.id)}return!0},rt=({point:e,chart:t,descriptor:r,plot:n,initialVisiblePoints:i,viewStateRef:o,yScaleRef:a,yCenterOffsetRef:s})=>{let l=r||P(t),c=o.current.get(t.id)||N(t,i),h=ye({chart:t,descriptor:l,state:c,plot:n,yScaleRef:a,yCenterOffsetRef:s});return E({orientation:l.orientation,categoryRange:{min:c.xMin,max:c.xMax},valueRange:{min:h.minY,max:h.maxY},plot:n}).screenToData(e)};var xr=({chart:e,descriptor:t,plot:r,state:n,yRange:i,seriesEndpoints:o,seriesOrderByChart:a})=>{let s=t.orientation==="horizontal",l=E({orientation:t.orientation,categoryRange:{min:n.xMin,max:n.xMax},valueRange:{min:i.minY,max:i.maxY},plot:{x:0,y:0,width:r.width,height:r.height}}),c=Array.from({length:ce},(p,v)=>{let w=v/(ce-1),A=i.maxY-w*(i.maxY-i.minY),S=l.dataToScreen({x:n.xMin,y:A});return{id:`${e.id}-tick-${v}`,value:A,top:s?void 0:S.y,left:s?S.x:void 0}}),h=F(e),d=h.filter(p=>p.value>=n.xMin&&p.value<=n.xMax).sort((p,v)=>p.value-v.value),u=s?r.height:r.width,m=Math.max(1,Math.floor(u/(s?22:72))),x=Math.max(1,Math.ceil(d.length/m)),f=d.filter((p,v)=>v%x===0||v===d.length-1),y=h.length?f.map((p,v)=>{let w=l.dataToScreen({x:p.value,y:i.minY});return{id:`${e.id}-category-${v}-${p.value}`,categorical:!0,label:p.label,value:p.value,left:s?void 0:w.x,top:s?w.y:void 0}}):Array.from({length:he},(p,v)=>{let w=v/(he-1);return{id:`${e.id}-x-tick-${v}`,value:n.xMin+w*(n.xMax-n.xMin),left:s?void 0:18+w*Math.max(1,r.width-36),top:s?10+w*Math.max(1,r.height-20):void 0}}),b=t.capabilities.latestValue?T(e,a).map(p=>{if(!p.length)return null;let v=p.rawY[p.length-1],w=p.rawX[p.length-1],A=o.get(p.id)||{x:w,y:v},S=l.dataToScreen(A);return{id:p.id,color:p.color,textColor:fr(p),value:A.y,rawValue:v,x:w,left:S.x,top:S.y}}).filter(p=>p&&Number.isFinite(p.top)&&p.top>=-10&&p.top<=r.height+10):[],{maxX:g}=U(e);return{orientation:t.orientation,ticks:c,xTicks:y,latestValues:b,plotWidth:r.width,showJumpLatest:Number.isFinite(g)&&(g<n.xMin||g>n.xMax)}},be=({canvas:e,width:t,height:r,gl:n,rendererRegistry:i,antialiasLines:o=!1,layouts:a,viewStateRef:s,yScaleRef:l,yCenterOffsetRef:c,initialVisiblePoints:h,getAppendAnimatedPoint:d,movingAverageByChart:u,seriesOrderByChart:m})=>{let x=Math.min(2,window.devicePixelRatio||1),f=Math.max(1,Math.floor(t*x)),y=Math.max(1,Math.floor(r*x));(e.width!==f||e.height!==y)&&(e.width=f,e.height=y,e.style.width=`${t}px`,e.style.height=`${r}px`),n.viewport(0,0,f,y),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);let b=performance.now(),g={};return a.forEach(p=>{if(!p.visible)return;let{chart:v,plot:w}=p,A=p.descriptor||qt(v),S=s.current.get(v.id)||N(v,h),I={x:w.x*x,y:w.y*x,width:w.width*x,height:w.height*x},j=H(v,w,A),Y=pt(V(v,S.xMin,S.xMax,j,A),l.current.get(v.id)??1,c.current.get(v.id)??0);n.enable(n.SCISSOR_TEST),n.scissor(Math.floor(I.x),Math.floor(y-I.y-I.height),Math.ceil(I.width),Math.ceil(I.height));let Ft=i.draw(A.rendererType,{antialiasLines:o,categoryPixelLength:j,chart:v,descriptor:A,dpr:x,getAppendAnimatedPoint:d,movingAverage:u?.[v.id],now:b,pixelHeight:y,pixelWidth:f,plot:w,scaledPlot:I,seriesOrderByChart:m,state:S,yRange:Y});g[v.id]=xr({chart:v,descriptor:A,plot:w,state:S,yRange:Y,seriesEndpoints:Ft?.seriesEndpoints||new Map,seriesOrderByChart:m}),n.disable(n.SCISSOR_TEST)}),n.disable(n.BLEND),g};var we=["aliencharts-root","relative","h-full","overflow-y-auto"],gr=Object.freeze({}),mr=0,yr=Object.freeze({charts:[],columns:2,initialVisiblePoints:null,backgroundColor:It,antialiasLines:!1,gridLines:!1,showToolbar:!0,showLatestValueLine:!0,showTooltips:!0,followLatest:!1,followVisibleLatest:!0,xAxisLabel:"STEP",disableDrawings:!1,seriesOrderByChart:gr,topMarkers:[],formatXTick:me,formatXValue:xt,formatYValue:xt}),$t=Object.freeze({durationMs:300,maxBucketSize:64,maxRevealPoints:100}),vr=.01,br=.001,Ce=(e,t,r)=>W(e*Math.exp(t*r),ut,ft),C=e=>String(e??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"),mt=(e,t)=>{let r=String(e||It).trim(),n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(r);return n?`rgba(${Number.parseInt(n[1],16)}, ${Number.parseInt(n[2],16)}, ${Number.parseInt(n[3],16)}, ${t})`:r},wr=e=>{let t=String(e||"#38bdf8").replace("#",""),r=t.length===3?t.split("").map(a=>a+a).join(""):t.padEnd(6,"0").slice(0,6),n=Number.parseInt(r,16),o=[16,8,0].map(a=>(n>>a&255)/255).map(a=>a<=.03928?a/12.92:((a+.055)/1.055)**2.4);return .2126*o[0]+.7152*o[1]+.0722*o[2]>.45?"#111827":"#ffffff"},z=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),W=(e,t,r)=>Math.min(r,Math.max(t,e)),L=({action:e,title:t,icon:r,hotkey:n="",active:i=!1,className:o=""})=>`
|
|
131
|
-
<button type="button" data-action="${e}" title="${
|
|
132
|
-
class="relative inline-flex size-6 items-center justify-center rounded-sm text-foreground hover:bg-accent hover:text-accent-foreground ${i?"bg-primary/15 text-primary ring-1 ring-primary/40":""} ${
|
|
130
|
+
`,tr=({vertices:e,visiblePoints:t,pointCount:r,animatedPoint:n})=>{for(let i=0;i<r;i+=1){let s=n&&i===n.index?n:{x:t.x[i],y:t.y[i]};e[i*2]=s.x,e[i*2+1]=s.y}},er=({series:e,state:t,yRange:r,plot:n})=>{if(e.length!==1)return null;let i=e.rawX[0],s=e.rawY[0];if(i<t.xMin||i>t.xMax||s<r.minY||s>r.maxY)return null;let a=(t.xMax-t.xMin)/Math.max(1,n.width)*3;return{x:new Float64Array([i-a,i+a]),y:new Float32Array([s,s]),bucketSize:1,pointCount:2,endpoint:{x:i,y:s}}},rr=(e,t,r,n,i,s)=>{e[t]=r.x,e[t+1]=r.y,e[t+2]=n.x,e[t+3]=n.y,e[t+4]=i,e[t+5]=s},ae=(e,t,r)=>t&&r===t.index?{x:t.x,y:t.y}:{x:e.x[r],y:e.y[r]},nr=({vertices:e,visiblePoints:t,pointCount:r,animatedPoint:n})=>{let i=0;for(let s=0;s<r-1;s+=1){let a=ae(t,n,s),o=ae(t,n,s+1);[[-1,0],[1,0],[-1,1],[-1,1],[1,0],[1,1]].forEach(([l,c])=>{rr(e,i,a,o,l,c),i+=J})}return i/J},se=({x:e,y:t,state:r,yRange:n,plot:i})=>({x:i.x+(e-r.xMin)/(r.xMax-r.xMin)*i.width,y:i.y+(n.maxY-t)/(n.maxY-n.minY)*i.height}),ir=({vertices:e,visiblePoints:t,pointCount:r,state:n,yRange:i,plot:s})=>{let a=0,o=0,l=ht+Ge;for(let c=0;c<r-1;c+=1){let h={x:t.x[c],y:t.y[c]},d={x:t.x[c+1],y:t.y[c+1]},u=se({...h,state:n,yRange:i,plot:s}),m=se({...d,state:n,yRange:i,plot:s}),x=Math.hypot(m.x-u.x,m.y-u.y);if(!Number.isFinite(x)||x<=0)continue;let f=0;for(;f<x;){let y=o%l,v=y<ht?ht-y:l-y,g=Math.min(v,x-f);if(y<ht){if(a+4>e.length)return a/2;let p=f/x,b=(f+g)/x;e[a]=h.x+(d.x-h.x)*p,e[a+1]=h.y+(d.y-h.y)*p,e[a+2]=h.x+(d.x-h.x)*b,e[a+3]=h.y+(d.y-h.y)*b,a+=4}f+=g,o+=g}}return a/2},ar=e=>e?.enabled?{enabled:!0,period:Number.isFinite(Number(e.period))?Math.max(1,Math.round(Number(e.period))):21,type:e.type==="sma"?"sma":"ema"}:null,oe=({sourceY:e,startIndex:t,period:r,type:n,previousAverage:i})=>{let s=new Float32Array(Math.max(0,e.length-t));if(!s.length)return s;if(n==="sma"){let l=0,c=Math.max(0,t-r+1);for(let h=c;h<t;h+=1)l+=e[h];for(let h=t;h<e.length;h+=1){l+=e[h];let d=h-r;d>=c&&(l-=e[d]),s[h-t]=l/Math.min(r,h+1)}return s}let a=2/(r+1),o=Number.isFinite(i)?i:e[t];for(let l=t;l<e.length;l+=1)o=e[l]*a+o*(1-a),s[l-t]=o;return s},sr=({chart:e,movingAverage:t,cache:r})=>{let n=ar(t);return n?e.series.map(i=>{if(!i.length)return null;let s=`${i.id}::ma:${n.type}:${n.period}`,a=r.get(s);if(a&&a.sourceSeries===i&&a.sourceLength<=i.length){let c=a.sourceLength;if(c<i.length){let h=oe({sourceY:i.rawY.subarray(0,i.length),startIndex:c,period:n.period,type:n.type,previousAverage:c>0?a.series.rawY[c-1]:void 0});a.series.append(i.rawX.subarray(c,i.length),h),a.sourceLength=i.length}return a.series.color=i.color,a.series.name=`${i.name} ${n.type.toUpperCase()} ${n.period}`,a.series}let o=oe({sourceY:i.rawY.subarray(0,i.length),startIndex:0,period:n.period,type:n.type}),l=k({id:s,name:`${i.name} ${n.type.toUpperCase()} ${n.period}`,color:i.color,x:i.rawX.subarray(0,i.length),y:o});return r.set(s,{sourceSeries:i,sourceLength:i.length,series:l}),l}).filter(Boolean):[]},or=(e,t)=>Object.freeze({aXy:e.getAttribLocation(t,"a_xy"),uColor:e.getUniformLocation(t,"u_color"),uRect:e.getUniformLocation(t,"u_rect"),uResolution:e.getUniformLocation(t,"u_resolution"),uXRange:e.getUniformLocation(t,"u_xRange"),uYRange:e.getUniformLocation(t,"u_yRange")}),le=e=>{let t=q(e,Ze,Ke),r=q(e,Je,Qe),n=or(e,t),i=Object.freeze({aAlong:e.getAttribLocation(r,"a_along"),aEnd:e.getAttribLocation(r,"a_end"),aSide:e.getAttribLocation(r,"a_side"),aStart:e.getAttribLocation(r,"a_start"),uColor:e.getUniformLocation(r,"u_color"),uEdgeWidth:e.getUniformLocation(r,"u_edgeWidth"),uLineHalfWidth:e.getUniformLocation(r,"u_lineHalfWidth"),uRect:e.getUniformLocation(r,"u_rect"),uResolution:e.getUniformLocation(r,"u_resolution"),uXRange:e.getUniformLocation(r,"u_xRange"),uYRange:e.getUniformLocation(r,"u_yRange")}),s=new Map,a=new Map,o=new Map,l=(c,h,d,u,m,x)=>{e.uniform2f(c.uResolution,h,d),e.uniform4f(c.uRect,u.x,u.y,u.width,u.height),e.uniform2f(c.uXRange,m.xMin,m.xMax),e.uniform2f(c.uYRange,x.minY,x.maxY)};return{draw({antialiasLines:c,chart:h,descriptor:d,dpr:u,getAppendAnimatedPoint:m,movingAverage:x,now:f,pixelHeight:y,pixelWidth:v,plot:g,scaledPlot:p,seriesOrderByChart:b,state:w,yRange:C}){let S=!!c,V=S?r:t,T=S?i:n;e.useProgram(V),l(T,v,y,p,w,C),S?(e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.enableVertexAttribArray(i.aStart),e.enableVertexAttribArray(i.aEnd),e.enableVertexAttribArray(i.aSide),e.enableVertexAttribArray(i.aAlong),e.uniform1f(i.uLineHalfWidth,je*u/2),e.uniform1f(i.uEdgeWidth,qe*u)):(e.disable(e.BLEND),e.enableVertexAttribArray(n.aXy));let W=new Map;d.capabilities.movingAverage&&x?.enabled&&x?.hideBase||E(h,b).forEach(R=>{let _=R.getVisiblePoints(w.xMin,w.xMax,g.width),$=null;if(_.pointCount<2){let j=er({series:R,state:w,yRange:C,plot:g});if(!j)return;_=j,$=j.endpoint}let D=$?null:m({seriesId:R.id,visiblePoints:_,now:f}),O=D?.pointCount??_.pointCount;D?W.set(R.id,{x:D.x,y:D.y}):$&&W.set(R.id,$);let[vt,bt,Te]=B(R.color);if(e.uniform3f(T.uColor,vt,bt,Te),S){let j=Math.max(0,O-1)*6*J,Ct=z(e,a,R.id,j),kt=nr({vertices:Ct.vertices,visiblePoints:_,pointCount:O,animatedPoint:D}),it=J*Float32Array.BYTES_PER_ELEMENT;e.bindBuffer(e.ARRAY_BUFFER,Ct.buffer),e.vertexAttribPointer(i.aStart,2,e.FLOAT,!1,it,0),e.vertexAttribPointer(i.aEnd,2,e.FLOAT,!1,it,2*Float32Array.BYTES_PER_ELEMENT),e.vertexAttribPointer(i.aSide,1,e.FLOAT,!1,it,4*Float32Array.BYTES_PER_ELEMENT),e.vertexAttribPointer(i.aAlong,1,e.FLOAT,!1,it,5*Float32Array.BYTES_PER_ELEMENT),e.bufferSubData(e.ARRAY_BUFFER,0,Ct.vertices,0,kt*J),e.drawArrays(e.TRIANGLES,0,kt);return}let wt=z(e,s,R.id,O*2);tr({vertices:wt.vertices,visiblePoints:_,pointCount:O,animatedPoint:D}),e.bindBuffer(e.ARRAY_BUFFER,wt.buffer),e.vertexAttribPointer(n.aXy,2,e.FLOAT,!1,0,0),e.bufferSubData(e.ARRAY_BUFFER,0,wt.vertices,0,O*2),e.drawArrays(e.LINE_STRIP,0,O)});let nt=sr({chart:h,movingAverage:d.capabilities.movingAverage?x:null,cache:o});return nt.length&&(e.disable(e.BLEND),e.useProgram(t),e.enableVertexAttribArray(n.aXy),l(n,v,y,p,w,C),E({...h,series:nt},b).forEach(R=>{let _=R.getVisiblePoints(w.xMin,w.xMax,g.width);if(_.pointCount<2)return;let $=z(e,s,R.id,_.pointCount*8*2),D=ir({vertices:$.vertices,visiblePoints:_,pointCount:_.pointCount,state:w,yRange:C,plot:g});if(D<2)return;let[O,vt,bt]=B(R.color);e.uniform3f(n.uColor,O,vt,bt),e.bindBuffer(e.ARRAY_BUFFER,$.buffer),e.vertexAttribPointer(n.aXy,2,e.FLOAT,!1,0,0),e.bufferSubData(e.ARRAY_BUFFER,0,$.vertices,0,D*2),e.drawArrays(e.LINES,0,D)})),e.disable(e.BLEND),{seriesEndpoints:W}},destroy(){G(e,s),G(e,a),o.clear(),e.deleteProgram(t),e.deleteProgram(r)}}};var lr=Object.freeze({bar:te,line:le}),ce=e=>{let t=new Map(Object.entries(lr).map(([r,n])=>[r,n(e)]));return{draw(r,n){let i=t.get(r);if(!i)throw new TypeError(`No AlienCharts renderer registered for "${r}"`);return i.draw(n)},getTooltipCategory(r,n){let i=t.get(r);if(!i)throw new TypeError(`No AlienCharts renderer registered for "${r}"`);return i.getTooltipCategory?.(n)??n.visiblePoints.x[n.pointIndex]},destroy(){t.forEach(r=>r.destroy()),t.clear()}}};var fe=360,pe=58,ut=Object.freeze({left:38,right:pe,top:34,bottom:28}),ge=Object.freeze({left:pe,right:20,top:34,bottom:28}),cr=Object.freeze({...ut,bottom:42}),hr=Object.freeze({...ge,left:128}),ft=.05,pt=40,he=5,de=5,dr=10,It=1e9,Lt=.1,$t="#f5f9ff";var xe=(e,t)=>(t||F(e)).orientation,Q=(e,t)=>{let r=P(e).length>0;return xe(e,t)==="horizontal"?r?hr:ge:r?cr:ut},X=(e,t,r)=>xe(e,r)==="horizontal"?t.height:t.width;var ur=e=>{let[t,r,n]=B(e),i=a=>a<=.03928?a/12.92:((a+.055)/1.055)**2.4;return .2126*i(t)+.7152*i(r)+.0722*i(n)>.45?"#111827":"#ffffff"},fr=e=>(e.__labelTextColorFor!==e.color&&(e.__labelTextColorFor=e.color,e.__labelTextColor=ur(e.color)),e.__labelTextColor),pr=(e,t)=>{let r=0,n=e.length;for(;r<n;){let i=r+n>>1;e[i]<t?r=i+1:n=i}return r},me=(e,t)=>{if(!e.length)return-1;let r=pr(e,t);if(r<=0)return 0;if(r>=e.length)return e.length-1;let n=r-1;return Math.abs(e[r]-t)<Math.abs(t-e[n])?r:n},H=e=>{let t=1/0,r=-1/0;return e.series.forEach(n=>{n.length&&(t=Math.min(t,n.rawX[0]),r=Math.max(r,n.rawX[n.length-1]))}),{minX:t,maxX:r}},tt=e=>{let t=P(e).map(n=>n.value).sort((n,i)=>n-i);if(!t.length)return dr;let r=1/0;for(let n=1;n<t.length;n+=1)r=Math.min(r,t[n]-t[n-1]);return Number.isFinite(r)?r:1},N=(e,t=null)=>{let r=P(e).map(a=>a.value).sort((a,o)=>a-o);if(r.length){let a=Number.isFinite(t)&&t>0?Math.max(1,Math.floor(t)):r.length,o=r.slice(-a),l=o[0],c=o[o.length-1],h=r.indexOf(l),d=r.lastIndexOf(c),u=h>0?l-r[h-1]:o[1]-l||1,m=d+1<r.length?r[d+1]-c:c-o[o.length-2]||u;return{xMin:l-u/2,xMax:c+m/2}}let{minX:n,maxX:i}=H(e);if(!Number.isFinite(n)||!Number.isFinite(i))return{xMin:0,xMax:1};if(n===i){let a=Number.isFinite(t)&&t>0?Math.max(10,t):10,o=i+a*Lt;return{xMin:o-a,xMax:o}}let s=i-n;if(Number.isFinite(t)&&t>0){s=Math.min(s,t);let a=i+s*Lt;return{xMin:a-s,xMax:a}}return{xMin:n,xMax:i+s*Lt}},et=(e,t,r,n,i)=>{let s=i||F(e),a=1/0,o=-1/0,l=0,c=1;e.series.forEach(m=>{let x=m.getVisiblePoints(t,r,n);l+=x.pointCount,c=Math.max(c,x.bucketSize);for(let f=0;f<x.y.length;f+=1)a=Math.min(a,x.y[f]),o=Math.max(o,x.y[f])});let h=Number(e.yRange?.min),d=Number(e.yRange?.max);if(Number.isFinite(h)&&Number.isFinite(d)&&h<d)return{minY:h,maxY:d,renderedPoints:l,bucketSize:c};if(!Number.isFinite(a)||!Number.isFinite(o))return{minY:0,maxY:1,renderedPoints:l,bucketSize:c};if(s.rangeIncludesZero){if(a>=0)return{minY:0,maxY:o===0?1:o*1.08,renderedPoints:l,bucketSize:c};if(o<=0)return{minY:a===0?-1:a*1.08,maxY:0,renderedPoints:l,bucketSize:c}}a===o&&(a-=1,o+=1);let u=(o-a)*.08;return{minY:a-u,maxY:o+u,renderedPoints:l,bucketSize:c}},Ot=(e,t=1,r=0)=>{let n=Math.min(pt,Math.max(ft,t)),i=(e.minY+e.maxY)/2+r,s=(e.maxY-e.minY)*n/2;return{...e,minY:i-s,maxY:i+s}},dt=e=>e.replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,""),gt=e=>{if(!Number.isFinite(e))return"";let t=Math.abs(e);return t!==0&&t<1e-4?e.toExponential(2):t<1?dt(e.toPrecision(5)):t>=1e5?e.toFixed(0):t>=1e3?dt(e.toFixed(1)):t>=10?dt(e.toFixed(2)):dt(e.toFixed(4))},ye=e=>{if(!Number.isFinite(e))return"";let t=Math.abs(e);return t>=1e9?`${(e/1e9).toFixed(t>=1e10?0:1)}B`:t>=1e6?`${(e/1e6).toFixed(t>=1e7?0:1)}M`:t>=1e3?`${(e/1e3).toFixed(t>=1e4?0:1)}k`:gt(e)},xt=(e,t)=>{if(!e||!t)return null;let r=Math.min(e.x,t.x),n=Math.min(e.y,t.y);return{left:r,top:n,width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}},ue=(e,t)=>({x:Math.min(t.x+t.width,Math.max(t.x,e.x)),y:Math.min(t.y+t.height,Math.max(t.y,e.y))}),Nt=({chart:e,descriptor:t,state:r,plot:n,yBaseRangeRef:i,yScaleRef:s,yCenterOffsetRef:a})=>{let o=et(e,r.xMin,r.xMax,X(e,n,t),t),l=i?.current.get(e.id);return Ot(l?{...o,...l}:o,s.current.get(e.id)??1,a.current.get(e.id)??0)},ve=({chart:e,descriptor:t,plot:r,start:n,end:i,initialVisiblePoints:s,viewStateRef:a,yBaseRangeRef:o,yScaleRef:l,yCenterOffsetRef:c,yManualScaleRef:h})=>{let d=xt(ue(n,r),ue(i,r));if(!d||d.width<6||d.height<6)return!1;let u=t||F(e),m=a.current.get(e.id)||N(e,s),x=Nt({chart:e,descriptor:u,state:m,plot:r,yBaseRangeRef:o,yScaleRef:l,yCenterOffsetRef:c}),y=L({orientation:u.orientation,categoryRange:{min:m.xMin,max:m.xMax},valueRange:{min:x.minY,max:x.maxY},plot:r}).dataBoundsForRect(d);if(y.categoryMax-y.categoryMin<tt(e))return!1;let v=y.valueMax-y.valueMin;if(!Number.isFinite(v)||v<=0)return!1;a.current.set(e.id,{xMin:y.categoryMin,xMax:y.categoryMax});let g=et(e,y.categoryMin,y.categoryMax,X(e,r,u),u),p=g.maxY-g.minY;if(Number.isFinite(p)&&p>0){let b=(y.valueMin+y.valueMax)/2,w=(g.minY+g.maxY)/2;l.current.set(e.id,Math.min(pt,Math.max(ft,v/p))),c.current.set(e.id,b-w),h.current.add(e.id)}return!0},rt=({point:e,chart:t,descriptor:r,plot:n,initialVisiblePoints:i,viewStateRef:s,yBaseRangeRef:a,yScaleRef:o,yCenterOffsetRef:l})=>{let c=r||F(t),h=s.current.get(t.id)||N(t,i),d=Nt({chart:t,descriptor:c,state:h,plot:n,yBaseRangeRef:a,yScaleRef:o,yCenterOffsetRef:l});return L({orientation:c.orientation,categoryRange:{min:h.xMin,max:h.xMax},valueRange:{min:d.minY,max:d.maxY},plot:n}).screenToData(e)};var gr=({chart:e,descriptor:t,plot:r,state:n,yRange:i,seriesEndpoints:s,seriesOrderByChart:a})=>{let o=t.orientation==="horizontal",l=L({orientation:t.orientation,categoryRange:{min:n.xMin,max:n.xMax},valueRange:{min:i.minY,max:i.maxY},plot:{x:0,y:0,width:r.width,height:r.height}}),c=Array.from({length:he},(p,b)=>{let w=b/(he-1),C=i.maxY-w*(i.maxY-i.minY),S=l.dataToScreen({x:n.xMin,y:C});return{id:`${e.id}-tick-${b}`,value:C,top:o?void 0:S.y,left:o?S.x:void 0}}),h=P(e),d=h.filter(p=>p.value>=n.xMin&&p.value<=n.xMax).sort((p,b)=>p.value-b.value),u=o?r.height:r.width,m=Math.max(1,Math.floor(u/(o?22:72))),x=Math.max(1,Math.ceil(d.length/m)),f=d.filter((p,b)=>b%x===0||b===d.length-1),y=h.length?f.map((p,b)=>{let w=l.dataToScreen({x:p.value,y:i.minY});return{id:`${e.id}-category-${b}-${p.value}`,categorical:!0,label:p.label,value:p.value,left:o?void 0:w.x,top:o?w.y:void 0}}):Array.from({length:de},(p,b)=>{let w=b/(de-1);return{id:`${e.id}-x-tick-${b}`,value:n.xMin+w*(n.xMax-n.xMin),left:o?void 0:18+w*Math.max(1,r.width-36),top:o?10+w*Math.max(1,r.height-20):void 0}}),v=t.capabilities.latestValue?E(e,a).map(p=>{if(!p.length)return null;let b=p.rawY[p.length-1],w=p.rawX[p.length-1],C=s.get(p.id)||{x:w,y:b},S=l.dataToScreen(C);return{id:p.id,color:p.color,textColor:fr(p),value:C.y,rawValue:b,x:w,left:S.x,top:S.y}}).filter(p=>p&&Number.isFinite(p.top)&&p.top>=-10&&p.top<=r.height+10):[],{maxX:g}=H(e);return{orientation:t.orientation,ticks:c,xTicks:y,latestValues:v,plotWidth:r.width,showJumpLatest:Number.isFinite(g)&&(g<n.xMin||g>n.xMax)}},be=({canvas:e,width:t,height:r,gl:n,rendererRegistry:i,antialiasLines:s=!1,layouts:a,viewStateRef:o,yBaseRangeRef:l,yScaleRef:c,yCenterOffsetRef:h,initialVisiblePoints:d,getAppendAnimatedPoint:u,movingAverageByChart:m,seriesOrderByChart:x})=>{let f=Math.min(2,window.devicePixelRatio||1),y=Math.max(1,Math.floor(t*f)),v=Math.max(1,Math.floor(r*f));(e.width!==y||e.height!==v)&&(e.width=y,e.height=v,e.style.width=`${t}px`,e.style.height=`${r}px`),n.viewport(0,0,y,v),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);let g=performance.now(),p={};return a.forEach(b=>{if(!b.visible)return;let{chart:w,plot:C}=b,S=b.descriptor||Gt(w),V=o.current.get(w.id)||N(w,d),T={x:C.x*f,y:C.y*f,width:C.width*f,height:C.height*f},W=X(w,C,S),yt=Nt({chart:w,descriptor:S,state:V,plot:C,yBaseRangeRef:l,yScaleRef:c,yCenterOffsetRef:h});n.enable(n.SCISSOR_TEST),n.scissor(Math.floor(T.x),Math.floor(v-T.y-T.height),Math.ceil(T.width),Math.ceil(T.height));let nt=i.draw(S.rendererType,{antialiasLines:s,categoryPixelLength:W,chart:w,descriptor:S,dpr:f,getAppendAnimatedPoint:u,movingAverage:m?.[w.id],now:g,pixelHeight:v,pixelWidth:y,plot:C,scaledPlot:T,seriesOrderByChart:x,state:V,yRange:yt});p[w.id]=gr({chart:w,descriptor:S,plot:C,state:V,yRange:yt,seriesEndpoints:nt?.seriesEndpoints||new Map,seriesOrderByChart:x}),n.disable(n.SCISSOR_TEST)}),n.disable(n.BLEND),p};var we=["aliencharts-root","relative","h-full","overflow-y-auto"],xr=Object.freeze({}),mr=0,yr=Object.freeze({charts:[],columns:2,initialVisiblePoints:null,backgroundColor:$t,antialiasLines:!1,gridLines:!1,showToolbar:!0,showLatestValueLine:!0,showTooltips:!0,followLatest:!1,followVisibleLatest:!0,xAxisLabel:"STEP",disableDrawings:!1,seriesOrderByChart:xr,topMarkers:[],formatXTick:ye,formatXValue:gt,formatYValue:gt}),Pt=Object.freeze({durationMs:300,maxBucketSize:64,maxRevealPoints:100}),vr=.01,br=.001,Ce=(e,t,r)=>U(e*Math.exp(t*r),ft,pt),A=e=>String(e??"").replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'"),mt=(e,t)=>{let r=String(e||$t).trim(),n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(r);return n?`rgba(${Number.parseInt(n[1],16)}, ${Number.parseInt(n[2],16)}, ${Number.parseInt(n[3],16)}, ${t})`:r},wr=e=>{let t=String(e||"#38bdf8").replace("#",""),r=t.length===3?t.split("").map(a=>a+a).join(""):t.padEnd(6,"0").slice(0,6),n=Number.parseInt(r,16),s=[16,8,0].map(a=>(n>>a&255)/255).map(a=>a<=.03928?a/12.92:((a+.055)/1.055)**2.4);return .2126*s[0]+.7152*s[1]+.0722*s[2]>.45?"#111827":"#ffffff"},Y=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),U=(e,t,r)=>Math.min(r,Math.max(t,e)),I=({action:e,title:t,icon:r,hotkey:n="",active:i=!1,className:s=""})=>`
|
|
131
|
+
<button type="button" data-action="${e}" title="${A(t)}" aria-label="${A(t)}"
|
|
132
|
+
class="relative inline-flex size-6 items-center justify-center rounded-sm text-foreground hover:bg-accent hover:text-accent-foreground ${i?"bg-primary/15 text-primary ring-1 ring-primary/40":""} ${s}">
|
|
133
133
|
${r}
|
|
134
134
|
${n?`<span class="pointer-events-none absolute left-full top-1/2 -translate-y-1/2 text-[10px] font-semibold leading-none text-foreground/50">${n}</span>`:""}
|
|
135
|
-
</button>`,Ae=(e,t,r,n)=>{let i=
|
|
136
|
-
<div data-chart-index="${r}" class="relative select-none overflow-hidden rounded-sm" style="height:${
|
|
135
|
+
</button>`,Ae=(e,t,r,n)=>{let i=Q(e,t),s=t.orientation==="horizontal",a=s?`left:${i.left}px;right:${i.right}px;bottom:0;height:${i.bottom}px;cursor:ew-resize`:`right:0;top:${i.top}px;bottom:${i.bottom}px;width:${i.right}px;cursor:ns-resize`,o=s?`left:0;top:${i.top}px;bottom:${i.bottom}px;width:${i.left}px;cursor:ns-resize`:`left:${i.left}px;right:${i.right}px;bottom:0;height:${i.bottom}px;cursor:ew-resize`;return`
|
|
136
|
+
<div data-chart-index="${r}" class="relative select-none overflow-hidden rounded-sm" style="height:${fe}px;background-color:${A(n)}">
|
|
137
137
|
<div class="pointer-events-none absolute inset-x-0 top-0 z-10 flex h-8 items-center px-2 backdrop-blur" data-header>
|
|
138
138
|
<div class="flex min-w-0 items-center gap-1 rounded-sm px-1 text-sm font-semibold text-foreground" data-title-wrap>
|
|
139
139
|
${e.pinned?M("pushPinSimple",{size:14,className:"shrink-0 text-foreground/80"}):""}
|
|
140
|
-
<span class="truncate">${
|
|
140
|
+
<span class="truncate">${A(e.title)}</span>
|
|
141
141
|
</div>
|
|
142
142
|
</div>
|
|
143
143
|
<div data-grid-lines class="pointer-events-none absolute text-border/40"></div>
|
|
144
144
|
<div data-latest-lines></div>
|
|
145
145
|
<div data-y-axis class="absolute z-20" style="${a}"></div>
|
|
146
|
-
<div data-x-axis class="absolute z-20" style="${
|
|
146
|
+
<div data-x-axis class="absolute z-20" style="${o}"></div>
|
|
147
147
|
<div data-toolbar></div>
|
|
148
|
-
</div>`},Se=(e,t)=>({canvas:e,gl:t,renderers:le(t)}),Me=e=>{e&&(e.renderers.destroy(),e.gl.getExtension("WEBGL_lose_context")?.loseContext())},Ot=class{constructor(t){this.requestRender=t,this.latest=new Map,this.animations=new Map,this.frame=null}scan(t,r){let n=performance.now();t.forEach(i=>{r.get(i.id)?.capabilities.appendAnimation&&i.series.forEach(a=>{if(!a.length)return;let s={x:a.rawX[a.length-1],y:a.rawY[a.length-1],length:a.length},l=this.latest.get(a.id);l&&s.x>l.x&&this.animations.set(a.id,{fromX:l.x,fromY:l.y,toX:s.x,toY:s.y,appendedCount:s.length-l.length,startedAt:n,duration:$t.durationMs}),this.latest.set(a.id,s)})}),this.animations.size&&this.start()}start(){if(this.frame!=null)return;let t=()=>{let r=performance.now();this.animations.forEach((n,i)=>{r-n.startedAt>=n.duration&&this.animations.delete(i)}),this.requestRender(),this.frame=this.animations.size?requestAnimationFrame(t):null};this.frame=requestAnimationFrame(t)}getPoint({seriesId:t,visiblePoints:r,now:n}){if(r.bucketSize>$t.maxBucketSize)return null;let i=this.animations.get(t);if(!i||r.x[0]>i.fromX||r.x[r.pointCount-1]<i.toX)return null;let o=0;for(;o<r.pointCount&&r.x[o]<=i.fromX;)o+=1;if(!o)return null;let s=1-(1-W((n-i.startedAt)/i.duration,0,1))**2;if(i.appendedCount>$t.maxRevealPoints)return{index:o,pointCount:o+1,x:i.fromX+(i.toX-i.fromX)*s,y:i.fromY+(i.toY-i.fromY)*s};let l=r.pointCount-o,c=s*l,h=Math.min(l,Math.floor(c)),d=Math.min(r.pointCount-1,o+h),u=Math.max(o-1,d-1),m=c-h,x=h<l;return{index:d,pointCount:Math.min(r.pointCount,d+1),x:x?r.x[u]+(r.x[d]-r.x[u])*m:r.x[d],y:x?r.y[u]+(r.y[d]-r.y[u])*m:r.y[d]}}destroy(){this.frame!=null&&cancelAnimationFrame(this.frame),this.frame=null,this.animations.clear()}},Nt=class{constructor(t,r){if(!(t instanceof HTMLElement))throw new TypeError("createChartGrid requires an HTMLElement target");if(this.container=t,this.controllerId=`aliencharts-${mr+=1}`,this.options={...yr,...r},!Array.isArray(this.options.charts))throw new TypeError("charts must be an array");this.chartDescriptors=Rt(this.options.charts),this.destroyed=!1,this.frame=null,this.structureDirty=!0,this.focusedChartId=null,this.fullscreenChartId=null,this.rectangleZoomChartId=null,this.rectangleZoomRect=null,this.crosshair=null,this.drag=null,this.draftDrawing=null,this.drawingSession=null,this.drawings=Array.isArray(r.drawings)?[...r.drawings]:[],this.activeDrawingTool=r.activeDrawingTool??null,this.selectedDrawingId=r.selectedDrawingId??null,this.movingAverageByChart={...r.movingAverageByChart||{}},this.viewStates=new Map,this.yScales=new Map,this.yOffsets=new Map,this.latestX=new Map,this.axisOverlays={},this.layouts=[],this.fullscreenLayouts=[],this.addedClasses=we.filter(i=>!t.classList.contains(i)),we.forEach(i=>t.classList.add(i)),this.canvas=document.createElement("canvas"),this.canvas.className="pointer-events-none absolute left-0 top-0 z-10 block",this.grid=document.createElement("div"),this.grid.className="relative z-0 grid gap-1 pt-1",this.overlays=document.createElement("div"),this.overlays.className="pointer-events-none absolute left-0 top-0 z-20",this.overlays.style.width="100%",t.append(this.canvas,this.grid,this.overlays);let n=this.canvas.getContext("webgl2",{antialias:!0,alpha:!0,depth:!1,stencil:!1});if(!n)throw this.cleanupDom(),new Error("AlienCharts requires WebGL2 support");this.surface=Se(this.canvas,n),this.fullscreenSurface=null,this.animator=new Ot(()=>this.requestRender()),this.animator.scan(this.options.charts,this.chartDescriptors),this.bound={click:i=>this.handleClick(i),input:i=>this.handleInput(i),change:i=>this.handleInput(i),pointerdown:i=>this.handlePointerDown(i),pointermove:i=>this.handlePointerMove(i),pointerup:i=>this.handlePointerUp(i),pointerleave:()=>this.clearCrosshair(),contextmenu:i=>this.handleContextMenu(i),wheel:i=>this.handleWheel(i),scroll:()=>this.requestRender(),keydown:i=>this.handleKeyDown(i)},Object.entries(this.bound).forEach(([i,o])=>{(i==="keydown"?window:t).addEventListener(i,o,i==="wheel"?{passive:!1}:void 0)}),this.resizeObserver=new ResizeObserver(()=>this.requestRender()),this.resizeObserver.observe(t),this.initializeChartState(),this.requestRender()}assertAlive(){if(this.destroyed)throw new Error("AlienCharts controller has been destroyed")}initializeChartState(){let t=new Set(this.options.charts.map(r=>r.id));[this.viewStates,this.yScales,this.yOffsets,this.latestX].forEach(r=>{[...r.keys()].forEach(n=>{t.has(n)||r.delete(n)})}),this.options.charts.forEach(r=>{this.viewStates.has(r.id)||this.viewStates.set(r.id,N(r,this.options.initialVisiblePoints)),this.yScales.has(r.id)||this.yScales.set(r.id,1),this.yOffsets.has(r.id)||this.yOffsets.set(r.id,0),this.latestX.has(r.id)||this.latestX.set(r.id,U(r).maxX)}),this.focusedChartId&&!t.has(this.focusedChartId)&&(this.focusedChartId=null),this.fullscreenChartId&&!t.has(this.fullscreenChartId)&&this.closeFullscreen()}requestRender(){this.destroyed||this.frame!=null||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.render()}))}setOptions(t){if(this.assertAlive(),!t||typeof t!="object")return;let r=this.options.charts,n=this.activeDrawingTool,i={...this.options,...t};if(!Array.isArray(i.charts))throw new TypeError("charts must be an array");let o=Rt(i.charts),a=i.charts.some(s=>{let l=this.chartDescriptors.get(s.id),c=o.get(s.id);return l?.rendererType!==c?.rendererType||l?.orientation!==c?.orientation||l?.categorical!==c?.categorical});this.options=i,this.chartDescriptors=o,z(t,"drawings")&&(this.drawings=Array.isArray(t.drawings)?[...t.drawings]:[]),z(t,"activeDrawingTool")&&(this.activeDrawingTool=t.activeDrawingTool??null,this.activeDrawingTool!==n&&(this.draftDrawing=null,this.drawingSession=null)),z(t,"selectedDrawingId")&&(this.selectedDrawingId=t.selectedDrawingId??null),z(t,"movingAverageByChart")&&(this.movingAverageByChart={...t.movingAverageByChart||{}}),(r!==this.options.charts||a||z(t,"columns")||z(t,"backgroundColor")||z(t,"gridLines"))&&(this.structureDirty=!0),this.initializeChartState(),this.requestRender()}setCharts(t){this.setOptions({charts:t})}invalidate(){this.assertAlive(),this.followAppendedData(),this.animator.scan(this.options.charts,this.chartDescriptors),this.requestRender()}followAppendedData(){this.options.charts.forEach(t=>{let r=this.latestX.get(t.id),n=U(t).maxX;if(Number.isFinite(r)&&Number.isFinite(n)&&n!==r){let i=this.viewStates.get(t.id)||N(t,this.options.initialVisiblePoints),o=i.xMax-i.xMin,a=r>=i.xMax-o*.15&&r>=i.xMin&&r<=i.xMax;if(this.options.followLatest||this.options.followVisibleLatest&&a){let s=n-r;this.viewStates.set(t.id,{xMin:i.xMin+s,xMax:i.xMax+s})}}this.latestX.set(t.id,n)})}jumpToLatest(t){this.assertAlive(),this.options.charts.forEach(r=>{if(t!=null&&r.id!==t)return;let n=U(r).maxX;if(!Number.isFinite(n))return;let i=this.viewStates.get(r.id)||N(r,this.options.initialVisiblePoints),o=Math.max(et(r),i.xMax-i.xMin),a=n+o*.1;this.viewStates.set(r.id,{xMin:a-o,xMax:a})}),this.requestRender()}scrollToTop(t={}){this.assertAlive(),this.container.scrollTo({...t,top:0})}renderStructure(){this.grid.style.gridTemplateColumns=`repeat(${Math.max(1,Number(this.options.columns)||1)}, minmax(18rem, 1fr))`,this.grid.innerHTML=this.options.charts.map((t,r)=>Ae(t,this.chartDescriptors.get(t.id),r,this.options.backgroundColor)).join(""),this.chartNodes=[...this.grid.querySelectorAll("[data-chart-index]")],this.chartNodes.forEach(t=>{t.querySelector("[data-header]").style.backgroundColor=mt(this.options.backgroundColor,.82)}),this.structureDirty=!1}getLayouts(t=!1){let r=t?this.fullscreenNode?[this.fullscreenNode]:[]:this.chartNodes||[],n=t?this.options.charts.filter(a=>a.id===this.fullscreenChartId):this.options.charts,i=t?this.fullscreenOverlay:this.container,o=i.getBoundingClientRect();return r.map((a,s)=>{let l=a.getBoundingClientRect(),c=l.left-o.left+i.scrollLeft,h=l.top-o.top+i.scrollTop,d=n[s],u=this.chartDescriptors.get(d.id),m=tt(d,u);return{chart:d,descriptor:u,rect:{x:c,y:h,width:l.width,height:l.height},plot:{x:c+m.left,y:h+m.top,width:Math.max(1,l.width-m.left-m.right),height:Math.max(1,l.height-m.top-m.bottom)},visible:t||l.bottom>=o.top&&l.top<=o.bottom,node:a,fullscreen:t}})}render(){let t=this.captureControlFocus();if(this.structureDirty&&this.renderStructure(),this.layouts=this.getLayouts(!1),this.axisOverlays=this.drawSurface(this.surface,this.layouts,this.container.scrollWidth,this.container.scrollHeight),this.updateCells(this.layouts,this.axisOverlays,!1),this.fullscreenChartId){this.fullscreenLayouts=this.getLayouts(!0);let r=this.drawSurface(this.fullscreenSurface,this.fullscreenLayouts,this.fullscreenOverlay.clientWidth,this.fullscreenOverlay.clientHeight);this.updateCells(this.fullscreenLayouts,r,!0)}this.renderOverlays(),this.restoreControlFocus(t)}captureControlFocus(){let t=document.activeElement;if(!(t instanceof HTMLInputElement))return null;let r=t.matches("[data-moving-period]")?"[data-moving-period]":t.matches("[data-pin-text]")?"[data-pin-text]":t.matches("[data-drawing-color]")?"[data-drawing-color]":null;if(!r)return null;let n=!!t.closest("[data-aliencharts-fullscreen]"),i=null,o=null;return t.type==="text"&&(i=t.selectionStart,o=t.selectionEnd),{selector:r,fullscreen:n,selectionStart:i,selectionEnd:o}}restoreControlFocus(t){if(!t)return;let n=(t.fullscreen?this.fullscreenOverlay:this.container)?.querySelector(t.selector);n instanceof HTMLInputElement&&(n.focus({preventScroll:!0}),n.type==="text"&&t.selectionStart!=null&&n.setSelectionRange(t.selectionStart,t.selectionEnd))}drawSurface(t,r,n,i){return t?be({canvas:t.canvas,width:Math.max(1,n),height:Math.max(1,i),gl:t.gl,rendererRegistry:t.renderers,antialiasLines:this.options.antialiasLines,layouts:r,viewStateRef:{current:this.viewStates},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets},initialVisiblePoints:this.options.initialVisiblePoints,getAppendAnimatedPoint:o=>this.animator.getPoint(o),movingAverageByChart:this.movingAverageByChart,seriesOrderByChart:this.options.seriesOrderByChart}):{}}updateCells(t,r,n){t.forEach(({chart:i,descriptor:o,node:a})=>{let s=r[i.id],l=tt(i,o),c=s?.orientation==="horizontal";a.querySelector("[data-title-wrap]").classList.toggle("ring-1",this.focusedChartId===i.id),a.querySelector("[data-title-wrap]").classList.toggle("ring-primary/70",this.focusedChartId===i.id);let h=a.querySelector("[data-grid-lines]"),d=this.options.gridLines===!0?{}:this.options.gridLines||{};h.style.display=this.options.gridLines?"block":"none",Object.assign(h.style,{left:`${l.left}px`,right:`${l.right}px`,top:`${l.top}px`,bottom:`${l.bottom}px`,backgroundImage:"linear-gradient(to right, transparent calc(100% - 1px), currentColor calc(100% - 1px)), linear-gradient(to bottom, transparent calc(100% - 1px), currentColor calc(100% - 1px))",backgroundSize:`${Math.max(8,Number(d.xSpacing)||80)}px 100%, 100% ${Math.max(8,Number(d.ySpacing)||48)}px`});let u=a.querySelector("[data-y-axis]");u.style.backgroundColor=mt(this.options.backgroundColor,.78),u.innerHTML=(s?.ticks||[]).map(f=>c?`<div class="pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="left:${f.left}px">${C(this.options.formatYValue(f.value))}</div>`:`<div class="pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="top:${f.top}px">${C(this.options.formatYValue(f.value))}</div>`).join("")+(s?.latestValues||[]).map(f=>`<div class="pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-sm px-1.5 py-0.5 text-center text-[10px] font-bold tabular-nums shadow-sm" style="top:${f.top}px;background:${f.color};color:${wr(f.color)}">${C(this.options.formatYValue(f.value))}</div>`).join("");let m=a.querySelector("[data-x-axis]");m.style.backgroundColor=mt(this.options.backgroundColor,.7),m.innerHTML=(s?.xTicks||[]).map(f=>{let y=f.categorical?f.label:this.options.formatXTick(f.value);return c&&f.categorical?`<div data-category-label title="${C(y)}" class="pointer-events-none absolute inset-x-2 -translate-y-1/2 truncate text-right text-[11px] font-medium text-foreground/70" style="top:${f.top}px">${C(y)}</div>`:f.categorical?`<div data-category-label title="${C(y)}" class="pointer-events-none absolute top-1/2 w-24 -translate-x-1/2 -translate-y-1/2 truncate text-center text-[11px] font-medium text-foreground/70" style="left:${f.left}px">${C(y)}</div>`:c?`<div class="pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="top:${f.top}px">${C(y)}</div>`:`<div class="pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="left:${f.left}px">${C(y)}</div>`}).join("");let x=a.querySelector("[data-latest-lines]");x.innerHTML=this.options.showLatestValueLine?(s?.latestValues||[]).filter(f=>f.left>=0&&f.left<=s.plotWidth).map(f=>`<div class="pointer-events-none absolute z-10 opacity-70" style="left:${l.left+f.left}px;top:${l.top+f.top}px;height:1px;width:${Math.max(0,s.plotWidth-f.left)}px;background-image:repeating-linear-gradient(to right,${f.color} 0 4px,transparent 4px 8px)"></div>`).join(""):"",this.updateToolbar(a,i,s,n)})}updateToolbar(t,r,n,i){let o=t.querySelector("[data-toolbar]"),a=i||this.focusedChartId===r.id,s=this.chartDescriptors.get(r.id),l=s.capabilities.drawings,c=s.capabilities.movingAverage,h=tt(r,s),d="";if(n?.showJumpLatest&&(d+=`<button type="button" data-action="jump-latest" aria-label="Jump to latest" class="absolute z-30 inline-flex size-7 items-center justify-center rounded-sm text-foreground hover:bg-accent" style="right:${h.right+6}px;bottom:${h.bottom+6}px;background:${mt(this.options.backgroundColor,.7)}">${M("arrowLineRight",{className:n.orientation==="horizontal"?"rotate-90":""})}</button>`),a&&this.options.showToolbar){let u=c&&!!this.movingAverageByChart[r.id]?.enabled,m=it(this.drawings,r.id).length>0;d+='<div class="absolute left-2 top-12 z-30 flex flex-col gap-0.5 rounded-sm bg-background/80 pr-3 text-foreground shadow-sm backdrop-blur">',d+=L({action:"fullscreen",title:i?"Exit fullscreen":"Maximize chart",hotkey:"F",icon:M(i?"arrowsIn":"arrowsOut")}),d+=L({action:"reset",title:"Reset chart",hotkey:"R",icon:M("arrowCounterClockwise")}),d+=L({action:"rectangle-zoom",title:"Rectangle zoom",hotkey:"Z",active:this.rectangleZoomChartId===r.id,icon:M("magnifyingGlassPlus")}),l&&!this.options.disableDrawings&&m&&(d+=L({action:"clear-drawings",title:"Clear drawings",className:"text-orange-500",icon:M("broom")})),(l||c)&&!this.options.disableDrawings&&(d+='<div class="my-1 h-px w-full"></div>',l&&(d+=L({action:"tool-trendline",title:"Draw trendline",hotkey:"T",active:this.activeDrawingTool==="trendline",icon:M("minus",{className:"-rotate-45"})}),d+=L({action:"tool-hline",title:"Draw horizontal line",hotkey:"H",active:this.activeDrawingTool==="hline",icon:M("minus")}),d+=L({action:"tool-vline",title:"Draw vertical line",hotkey:"V",active:this.activeDrawingTool==="vline",icon:M("minus",{className:"rotate-90"})}),d+=L({action:"tool-pin",title:"Place pin",hotkey:"P",active:this.activeDrawingTool==="pin",icon:M("mapPin")})),c&&(d+=L({action:"moving-average",title:"Toggle moving average",hotkey:"M",active:u,icon:M("waveSine")}))),d+="</div>",c&&!this.options.disableDrawings&&u&&(d+=this.movingAverageOptionsHtml(r))}o.innerHTML=d}movingAverageOptionsHtml(t){let r=this.movingAverageByChart[t.id]||{enabled:!0,period:21,type:"ema",hideBase:!1};return`<div data-moving-options class="absolute right-16 top-2 z-40 flex items-center gap-1 rounded-sm bg-background/85 p-1 text-xs text-foreground shadow-sm">
|
|
148
|
+
</div>`},Se=(e,t)=>({canvas:e,gl:t,renderers:ce(t)}),Me=e=>{e&&(e.renderers.destroy(),e.gl.getExtension("WEBGL_lose_context")?.loseContext())},Ft=class{constructor(t){this.requestRender=t,this.latest=new Map,this.animations=new Map,this.frame=null}scan(t,r){let n=performance.now();t.forEach(i=>{r.get(i.id)?.capabilities.appendAnimation&&i.series.forEach(a=>{if(!a.length)return;let o={x:a.rawX[a.length-1],y:a.rawY[a.length-1],length:a.length},l=this.latest.get(a.id);l&&o.x>l.x&&this.animations.set(a.id,{fromX:l.x,fromY:l.y,toX:o.x,toY:o.y,appendedCount:o.length-l.length,startedAt:n,duration:Pt.durationMs}),this.latest.set(a.id,o)})}),this.animations.size&&this.start()}start(){if(this.frame!=null)return;let t=()=>{let r=performance.now();this.animations.forEach((n,i)=>{r-n.startedAt>=n.duration&&this.animations.delete(i)}),this.requestRender(),this.frame=this.animations.size?requestAnimationFrame(t):null};this.frame=requestAnimationFrame(t)}getPoint({seriesId:t,visiblePoints:r,now:n}){if(r.bucketSize>Pt.maxBucketSize)return null;let i=this.animations.get(t);if(!i||r.x[0]>i.fromX||r.x[r.pointCount-1]<i.toX)return null;let s=0;for(;s<r.pointCount&&r.x[s]<=i.fromX;)s+=1;if(!s)return null;let o=1-(1-U((n-i.startedAt)/i.duration,0,1))**2;if(i.appendedCount>Pt.maxRevealPoints)return{index:s,pointCount:s+1,x:i.fromX+(i.toX-i.fromX)*o,y:i.fromY+(i.toY-i.fromY)*o};let l=r.pointCount-s,c=o*l,h=Math.min(l,Math.floor(c)),d=Math.min(r.pointCount-1,s+h),u=Math.max(s-1,d-1),m=c-h,x=h<l;return{index:d,pointCount:Math.min(r.pointCount,d+1),x:x?r.x[u]+(r.x[d]-r.x[u])*m:r.x[d],y:x?r.y[u]+(r.y[d]-r.y[u])*m:r.y[d]}}destroy(){this.frame!=null&&cancelAnimationFrame(this.frame),this.frame=null,this.animations.clear()}},Bt=class{constructor(t,r){if(!(t instanceof HTMLElement))throw new TypeError("createChartGrid requires an HTMLElement target");if(this.container=t,this.controllerId=`aliencharts-${mr+=1}`,this.options={...yr,...r},!Array.isArray(this.options.charts))throw new TypeError("charts must be an array");this.chartDescriptors=Dt(this.options.charts),this.destroyed=!1,this.frame=null,this.structureDirty=!0,this.focusedChartId=null,this.fullscreenChartId=null,this.rectangleZoomChartId=null,this.rectangleZoomRect=null,this.crosshair=null,this.drag=null,this.draftDrawing=null,this.drawingSession=null,this.drawings=Array.isArray(r.drawings)?[...r.drawings]:[],this.activeDrawingTool=r.activeDrawingTool??null,this.selectedDrawingId=r.selectedDrawingId??null,this.movingAverageByChart={...r.movingAverageByChart||{}},this.viewStates=new Map,this.yScales=new Map,this.yOffsets=new Map,this.yBaseRanges=new Map,this.latestX=new Map,this.axisOverlays={},this.layouts=[],this.fullscreenLayouts=[],this.addedClasses=we.filter(i=>!t.classList.contains(i)),we.forEach(i=>t.classList.add(i)),this.canvas=document.createElement("canvas"),this.canvas.className="pointer-events-none absolute left-0 top-0 z-10 block",this.grid=document.createElement("div"),this.grid.className="relative z-0 grid gap-1 pt-1",this.overlays=document.createElement("div"),this.overlays.className="pointer-events-none absolute left-0 top-0 z-20",this.overlays.style.width="100%",t.append(this.canvas,this.grid,this.overlays);let n=this.canvas.getContext("webgl2",{antialias:!0,alpha:!0,depth:!1,stencil:!1});if(!n)throw this.cleanupDom(),new Error("AlienCharts requires WebGL2 support");this.surface=Se(this.canvas,n),this.fullscreenSurface=null,this.animator=new Ft(()=>this.requestRender()),this.animator.scan(this.options.charts,this.chartDescriptors),this.bound={click:i=>this.handleClick(i),input:i=>this.handleInput(i),change:i=>this.handleInput(i),pointerdown:i=>this.handlePointerDown(i),pointermove:i=>this.handlePointerMove(i),pointerup:i=>this.handlePointerUp(i),pointerleave:()=>this.clearCrosshair(),contextmenu:i=>this.handleContextMenu(i),wheel:i=>this.handleWheel(i),scroll:()=>this.requestRender(),keydown:i=>this.handleKeyDown(i)},Object.entries(this.bound).forEach(([i,s])=>{(i==="keydown"?window:t).addEventListener(i,s,i==="wheel"?{passive:!1}:void 0)}),this.resizeObserver=new ResizeObserver(()=>this.requestRender()),this.resizeObserver.observe(t),this.initializeChartState(),this.requestRender()}assertAlive(){if(this.destroyed)throw new Error("AlienCharts controller has been destroyed")}initializeChartState(){let t=new Set(this.options.charts.map(r=>r.id));[this.viewStates,this.yScales,this.yOffsets,this.yBaseRanges,this.latestX].forEach(r=>{[...r.keys()].forEach(n=>{t.has(n)||r.delete(n)})}),this.options.charts.forEach(r=>{this.viewStates.has(r.id)||this.viewStates.set(r.id,N(r,this.options.initialVisiblePoints)),this.yScales.has(r.id)||this.yScales.set(r.id,1),this.yOffsets.has(r.id)||this.yOffsets.set(r.id,0),this.latestX.has(r.id)||this.latestX.set(r.id,H(r).maxX)}),this.focusedChartId&&!t.has(this.focusedChartId)&&(this.focusedChartId=null),this.fullscreenChartId&&!t.has(this.fullscreenChartId)&&this.closeFullscreen()}requestRender(){this.destroyed||this.frame!=null||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.render()}))}setOptions(t){if(this.assertAlive(),!t||typeof t!="object")return;let r=this.options.charts,n=this.activeDrawingTool,i={...this.options,...t};if(!Array.isArray(i.charts))throw new TypeError("charts must be an array");let s=Dt(i.charts),a=i.charts.some(o=>{let l=this.chartDescriptors.get(o.id),c=s.get(o.id);return l?.rendererType!==c?.rendererType||l?.orientation!==c?.orientation||l?.categorical!==c?.categorical});this.options=i,this.chartDescriptors=s,Y(t,"drawings")&&(this.drawings=Array.isArray(t.drawings)?[...t.drawings]:[]),Y(t,"activeDrawingTool")&&(this.activeDrawingTool=t.activeDrawingTool??null,this.activeDrawingTool!==n&&(this.draftDrawing=null,this.drawingSession=null)),Y(t,"selectedDrawingId")&&(this.selectedDrawingId=t.selectedDrawingId??null),Y(t,"movingAverageByChart")&&(this.movingAverageByChart={...t.movingAverageByChart||{}}),(r!==this.options.charts||a||Y(t,"columns")||Y(t,"backgroundColor")||Y(t,"gridLines"))&&(this.structureDirty=!0),this.initializeChartState(),this.requestRender()}setCharts(t){this.setOptions({charts:t})}invalidate(){this.assertAlive(),this.followAppendedData(),this.animator.scan(this.options.charts,this.chartDescriptors),this.requestRender()}followAppendedData(){this.options.charts.forEach(t=>{let r=this.latestX.get(t.id),n=H(t).maxX;if(Number.isFinite(r)&&Number.isFinite(n)&&n!==r){let i=this.viewStates.get(t.id)||N(t,this.options.initialVisiblePoints),s=i.xMax-i.xMin,a=r>=i.xMax-s*.15&&r>=i.xMin&&r<=i.xMax;if(this.options.followLatest||this.options.followVisibleLatest&&a){let o=n-r;this.viewStates.set(t.id,{xMin:i.xMin+o,xMax:i.xMax+o})}}this.latestX.set(t.id,n)})}jumpToLatest(t){this.assertAlive(),this.options.charts.forEach(r=>{if(t!=null&&r.id!==t)return;let n=H(r).maxX;if(!Number.isFinite(n))return;let i=this.viewStates.get(r.id)||N(r,this.options.initialVisiblePoints),s=Math.max(tt(r),i.xMax-i.xMin),a=n+s*.1;this.viewStates.set(r.id,{xMin:a-s,xMax:a})}),this.requestRender()}scrollToTop(t={}){this.assertAlive(),this.container.scrollTo({...t,top:0})}renderStructure(){this.grid.style.gridTemplateColumns=`repeat(${Math.max(1,Number(this.options.columns)||1)}, minmax(18rem, 1fr))`,this.grid.innerHTML=this.options.charts.map((t,r)=>Ae(t,this.chartDescriptors.get(t.id),r,this.options.backgroundColor)).join(""),this.chartNodes=[...this.grid.querySelectorAll("[data-chart-index]")],this.chartNodes.forEach(t=>{t.querySelector("[data-header]").style.backgroundColor=mt(this.options.backgroundColor,.82)}),this.structureDirty=!1}getLayouts(t=!1){let r=t?this.fullscreenNode?[this.fullscreenNode]:[]:this.chartNodes||[],n=t?this.options.charts.filter(a=>a.id===this.fullscreenChartId):this.options.charts,i=t?this.fullscreenOverlay:this.container,s=i.getBoundingClientRect();return r.map((a,o)=>{let l=a.getBoundingClientRect(),c=l.left-s.left+i.scrollLeft,h=l.top-s.top+i.scrollTop,d=n[o],u=this.chartDescriptors.get(d.id),m=Q(d,u);return{chart:d,descriptor:u,rect:{x:c,y:h,width:l.width,height:l.height},plot:{x:c+m.left,y:h+m.top,width:Math.max(1,l.width-m.left-m.right),height:Math.max(1,l.height-m.top-m.bottom)},visible:t||l.bottom>=s.top&&l.top<=s.bottom,node:a,fullscreen:t}})}render(){let t=this.captureControlFocus();if(this.structureDirty&&this.renderStructure(),this.layouts=this.getLayouts(!1),this.axisOverlays=this.drawSurface(this.surface,this.layouts,this.container.scrollWidth,this.container.scrollHeight),this.updateCells(this.layouts,this.axisOverlays,!1),this.fullscreenChartId){this.fullscreenLayouts=this.getLayouts(!0);let r=this.drawSurface(this.fullscreenSurface,this.fullscreenLayouts,this.fullscreenOverlay.clientWidth,this.fullscreenOverlay.clientHeight);this.updateCells(this.fullscreenLayouts,r,!0)}this.renderOverlays(),this.restoreControlFocus(t)}captureControlFocus(){let t=document.activeElement;if(!(t instanceof HTMLInputElement))return null;let r=t.matches("[data-moving-period]")?"[data-moving-period]":t.matches("[data-pin-text]")?"[data-pin-text]":t.matches("[data-drawing-color]")?"[data-drawing-color]":null;if(!r)return null;let n=!!t.closest("[data-aliencharts-fullscreen]"),i=null,s=null;return t.type==="text"&&(i=t.selectionStart,s=t.selectionEnd),{selector:r,fullscreen:n,selectionStart:i,selectionEnd:s}}restoreControlFocus(t){if(!t)return;let n=(t.fullscreen?this.fullscreenOverlay:this.container)?.querySelector(t.selector);n instanceof HTMLInputElement&&(n.focus({preventScroll:!0}),n.type==="text"&&t.selectionStart!=null&&n.setSelectionRange(t.selectionStart,t.selectionEnd))}drawSurface(t,r,n,i){return t?be({canvas:t.canvas,width:Math.max(1,n),height:Math.max(1,i),gl:t.gl,rendererRegistry:t.renderers,antialiasLines:this.options.antialiasLines,layouts:r,viewStateRef:{current:this.viewStates},yBaseRangeRef:{current:this.yBaseRanges},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets},initialVisiblePoints:this.options.initialVisiblePoints,getAppendAnimatedPoint:s=>this.animator.getPoint(s),movingAverageByChart:this.movingAverageByChart,seriesOrderByChart:this.options.seriesOrderByChart}):{}}updateCells(t,r,n){t.forEach(({chart:i,descriptor:s,node:a})=>{let o=r[i.id],l=Q(i,s),c=o?.orientation==="horizontal";a.querySelector("[data-title-wrap]").classList.toggle("ring-1",this.focusedChartId===i.id),a.querySelector("[data-title-wrap]").classList.toggle("ring-primary/70",this.focusedChartId===i.id);let h=a.querySelector("[data-grid-lines]"),d=this.options.gridLines===!0?{}:this.options.gridLines||{};h.style.display=this.options.gridLines?"block":"none",Object.assign(h.style,{left:`${l.left}px`,right:`${l.right}px`,top:`${l.top}px`,bottom:`${l.bottom}px`,backgroundImage:"linear-gradient(to right, transparent calc(100% - 1px), currentColor calc(100% - 1px)), linear-gradient(to bottom, transparent calc(100% - 1px), currentColor calc(100% - 1px))",backgroundSize:`${Math.max(8,Number(d.xSpacing)||80)}px 100%, 100% ${Math.max(8,Number(d.ySpacing)||48)}px`});let u=a.querySelector("[data-y-axis]");u.style.backgroundColor=mt(this.options.backgroundColor,.78),u.innerHTML=(o?.ticks||[]).map(f=>c?`<div class="pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="left:${f.left}px">${A(this.options.formatYValue(f.value))}</div>`:`<div class="pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="top:${f.top}px">${A(this.options.formatYValue(f.value))}</div>`).join("")+(o?.latestValues||[]).map(f=>`<div class="pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-sm px-1.5 py-0.5 text-center text-[10px] font-bold tabular-nums shadow-sm" style="top:${f.top}px;background:${f.color};color:${wr(f.color)}">${A(this.options.formatYValue(f.value))}</div>`).join("");let m=a.querySelector("[data-x-axis]");m.style.backgroundColor=mt(this.options.backgroundColor,.7),m.innerHTML=(o?.xTicks||[]).map(f=>{let y=f.categorical?f.label:this.options.formatXTick(f.value);return c&&f.categorical?`<div data-category-label title="${A(y)}" class="pointer-events-none absolute inset-x-2 -translate-y-1/2 truncate text-right text-[11px] font-medium text-foreground/70" style="top:${f.top}px">${A(y)}</div>`:f.categorical?`<div data-category-label title="${A(y)}" class="pointer-events-none absolute top-1/2 w-24 -translate-x-1/2 -translate-y-1/2 truncate text-center text-[11px] font-medium text-foreground/70" style="left:${f.left}px">${A(y)}</div>`:c?`<div class="pointer-events-none absolute left-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="top:${f.top}px">${A(y)}</div>`:`<div class="pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-center text-[11px] font-medium tabular-nums text-foreground/70" style="left:${f.left}px">${A(y)}</div>`}).join("");let x=a.querySelector("[data-latest-lines]");x.innerHTML=this.options.showLatestValueLine?(o?.latestValues||[]).filter(f=>f.left>=0&&f.left<=o.plotWidth).map(f=>`<div class="pointer-events-none absolute z-10 opacity-70" style="left:${l.left+f.left}px;top:${l.top+f.top}px;height:1px;width:${Math.max(0,o.plotWidth-f.left)}px;background-image:repeating-linear-gradient(to right,${f.color} 0 4px,transparent 4px 8px)"></div>`).join(""):"",this.updateToolbar(a,i,o,n)})}updateToolbar(t,r,n,i){let s=t.querySelector("[data-toolbar]"),a=i||this.focusedChartId===r.id,o=this.chartDescriptors.get(r.id),l=o.capabilities.drawings,c=o.capabilities.movingAverage,h=Q(r,o),d="";if(n?.showJumpLatest&&(d+=`<button type="button" data-action="jump-latest" aria-label="Jump to latest" class="absolute z-30 inline-flex size-7 items-center justify-center rounded-sm text-foreground hover:bg-accent" style="right:${h.right+6}px;bottom:${h.bottom+6}px;background:${mt(this.options.backgroundColor,.7)}">${M("arrowLineRight",{className:n.orientation==="horizontal"?"rotate-90":""})}</button>`),a&&this.options.showToolbar){let u=c&&!!this.movingAverageByChart[r.id]?.enabled,m=at(this.drawings,r.id).length>0;d+='<div class="absolute left-2 top-12 z-30 flex flex-col gap-0.5 rounded-sm bg-background/80 pr-3 text-foreground shadow-sm backdrop-blur">',d+=I({action:"fullscreen",title:i?"Exit fullscreen":"Maximize chart",hotkey:"F",icon:M(i?"arrowsIn":"arrowsOut")}),d+=I({action:"reset",title:"Reset chart",hotkey:"R",icon:M("arrowCounterClockwise")}),d+=I({action:"rectangle-zoom",title:"Rectangle zoom",hotkey:"Z",active:this.rectangleZoomChartId===r.id,icon:M("magnifyingGlassPlus")}),l&&!this.options.disableDrawings&&m&&(d+=I({action:"clear-drawings",title:"Clear drawings",className:"text-orange-500",icon:M("broom")})),(l||c)&&!this.options.disableDrawings&&(d+='<div class="my-1 h-px w-full"></div>',l&&(d+=I({action:"tool-trendline",title:"Draw trendline",hotkey:"T",active:this.activeDrawingTool==="trendline",icon:M("minus",{className:"-rotate-45"})}),d+=I({action:"tool-hline",title:"Draw horizontal line",hotkey:"H",active:this.activeDrawingTool==="hline",icon:M("minus")}),d+=I({action:"tool-vline",title:"Draw vertical line",hotkey:"V",active:this.activeDrawingTool==="vline",icon:M("minus",{className:"rotate-90"})}),d+=I({action:"tool-pin",title:"Place pin",hotkey:"P",active:this.activeDrawingTool==="pin",icon:M("mapPin")})),c&&(d+=I({action:"moving-average",title:"Toggle moving average",hotkey:"M",active:u,icon:M("waveSine")}))),d+="</div>",c&&!this.options.disableDrawings&&u&&(d+=this.movingAverageOptionsHtml(r))}s.innerHTML=d}movingAverageOptionsHtml(t){let r=this.movingAverageByChart[t.id]||{enabled:!0,period:21,type:"ema",hideBase:!1};return`<div data-moving-options class="absolute right-16 top-2 z-40 flex items-center gap-1 rounded-sm bg-background/85 p-1 text-xs text-foreground shadow-sm">
|
|
149
149
|
<button type="button" data-action="toggle-base" title="${r.hideBase?"Show":"Hide"} base series" aria-label="${r.hideBase?"Show":"Hide"} base series" class="inline-flex size-6 items-center justify-center rounded-sm ${r.hideBase?"bg-primary/15 text-primary ring-1 ring-primary/40":""}">${M("eye",{size:14})}</button>
|
|
150
150
|
<button type="button" data-action="moving-type" title="Toggle moving average type" class="h-6 rounded-sm px-2 text-[11px] font-semibold uppercase">${r.type==="sma"?"sma":"ema"}</button>
|
|
151
151
|
<input data-moving-period type="number" min="1" step="1" value="${Math.max(1,Number(r.period)||21)}" title="Moving average period" class="h-6 w-14 rounded-sm border border-border/50 px-1 text-xs" />
|
|
152
|
-
</div>`}renderOverlays(){let t=this.fullscreenChartId?this.fullscreenOverlay:this.container,r=this.fullscreenChartId?this.fullscreenOverlays:this.overlays,n=this.fullscreenChartId?this.fullscreenLayouts:this.layouts;if(!r)return;r.style.height=`${t.scrollHeight}px`;let i=this.drawingOverlayHtml(n);i+=this.topMarkersHtml(n),i+=this.crosshairHtml(),i+=this.rectangleOverlayHtml(),i+=this.drawingOptionsHtml(n),r.innerHTML=i}drawingOverlayHtml(t){let r=this.draftDrawing?[...this.drawings,this.draftDrawing]:this.drawings;if(!r.length)return"";let n=t.map((a,
|
|
153
|
-
${t.points.map(
|
|
154
|
-
|
|
155
|
-
${
|
|
156
|
-
|
|
152
|
+
</div>`}renderOverlays(){let t=this.fullscreenChartId?this.fullscreenOverlay:this.container,r=this.fullscreenChartId?this.fullscreenOverlays:this.overlays,n=this.fullscreenChartId?this.fullscreenLayouts:this.layouts;if(!r)return;r.style.height=`${t.scrollHeight}px`;let i=this.drawingOverlayHtml(n);i+=this.topMarkersHtml(n),i+=this.crosshairHtml(),i+=this.rectangleOverlayHtml(),i+=this.drawingOptionsHtml(n),r.innerHTML=i}drawingOverlayHtml(t){let r=this.draftDrawing?[...this.drawings,this.draftDrawing]:this.drawings;if(!r.length)return"";let n=t.map((a,o)=>({layout:a,index:o,drawings:a.descriptor.capabilities.drawings?at(r,a.chart.id):[]})).filter(a=>a.drawings.length>0);if(!n.length)return"";let i=n.map(({layout:a,index:o})=>`<clipPath id="${`${this.controllerId}-drawing-clip-${a.fullscreen?"fullscreen":"grid"}-${o}`}"><rect data-drawing-clip="${A(a.chart.id)}" x="${a.plot.x}" y="${a.plot.y}" width="${a.plot.width}" height="${a.plot.height}"/></clipPath>`).join(""),s=n.map(({layout:a,index:o,drawings:l})=>{let c=`${this.controllerId}-drawing-clip-${a.fullscreen?"fullscreen":"grid"}-${o}`,h=l.map(d=>{let u=Mt({drawing:d,layout:a,projectPoint:x=>this.projectPoint(x,a)});if(!u)return"";let m=d.id===this.selectedDrawingId||d.id==="__draft__";if(d.type==="pin"){let x=A(u.style.text?.trim()||"");return`<g opacity="${d.id==="__draft__"?.72:1}"><g transform="translate(${u.start.x} ${u.start.y})"><path d="M0 -11 C-6 -11 -10 -6 -10 -1 C-10 6 -2 12 0 15 C2 12 10 6 10 -1 C10 -6 6 -11 0 -11 Z" fill="${u.style.color}" stroke="var(--background,#fff)" stroke-width="1.5"/><circle cy="-2" r="3" fill="var(--background,#fff)"/></g>${x?`<text x="${u.start.x+14}" y="${u.start.y}" fill="${u.style.color}" stroke="var(--background,#fff)" stroke-width="3" paint-order="stroke" font-size="12" font-weight="600">${x}</text>`:""}${m?`<circle cx="${u.start.x}" cy="${u.start.y}" r="4" fill="${u.style.color}" stroke="var(--background,#fff)"/>`:""}</g>`}return`<g><line data-drawing-line x1="${u.lineStart.x}" y1="${u.lineStart.y}" x2="${u.lineEnd.x}" y2="${u.lineEnd.y}" stroke="${u.style.color}" stroke-width="${u.style.lineWidth}" stroke-dasharray="${u.style.dashPattern.join(" ")}" opacity="${d.id==="__draft__"?.72:1}"/>${m?`<circle data-drawing-anchor="start" cx="${u.start.x}" cy="${u.start.y}" r="4" fill="${u.style.color}" stroke="var(--background,#fff)"/>${d.type==="trendline"?`<circle data-drawing-anchor="end" cx="${u.end.x}" cy="${u.end.y}" r="4" fill="${u.style.color}" stroke="var(--background,#fff)"/>`:""}`:""}</g>`}).join("");return`<g data-drawing-chart="${A(a.chart.id)}" clip-path="url(#${c})">${h}</g>`}).join("");return`<svg class="pointer-events-none absolute left-0 top-0 z-20 block overflow-visible" style="width:100%;height:100%"><defs>${i}</defs>${s}</svg>`}topMarkersHtml(t){return this.options.topMarkers?.length?t.flatMap(r=>r.descriptor.capabilities.markers?this.options.topMarkers.map((n,i)=>{let s=Number(n.x??n.step),a=this.viewStates.get(r.chart.id),o=(s-a.xMin)/(a.xMax-a.xMin);return!Number.isFinite(s)||o<0||o>1?"":`<button type="button" data-marker-index="${i}" class="pointer-events-auto absolute z-30 -translate-x-1/2 rounded-full" style="left:${r.plot.x+o*r.plot.width}px;top:${r.plot.y+4}px" title="${A(n.title||"")}" aria-label="${A(n.ariaLabel||n.title||"Chart marker")}"><span class="block size-2.5 rounded-full border border-background shadow-sm" style="background:${n.color||"#f97316"}"></span></button>`}):[]).join(""):""}crosshairHtml(){let t=this.options.showTooltips?this.crosshair:null;if(!t)return"";let n=this.options.charts.find(s=>s.id===t.chartId)?.xAxisLabel??this.options.xAxisLabel,i=`<div data-crosshair-points class="pointer-events-none absolute z-30 overflow-hidden" style="left:${t.plot.x}px;top:${t.plot.y}px;width:${t.plot.width}px;height:${t.plot.height}px">
|
|
153
|
+
${t.points.map(s=>`<div data-crosshair-point class="absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full border border-background" style="left:${s.x-t.plot.x}px;top:${s.y-t.plot.y}px;background:${s.color}"></div>`).join("")}
|
|
154
|
+
</div>`;return`<div class="pointer-events-none absolute z-20 border-l border-foreground/40" style="left:${t.x}px;top:0;height:100%"></div><div class="pointer-events-none absolute z-20 border-t border-foreground/40" style="top:${t.y}px;left:0;width:100%"></div>
|
|
155
|
+
${i}
|
|
156
|
+
<div data-crosshair-tooltip class="pointer-events-none absolute z-30 w-[220px] rounded-sm border border-border/70 bg-popover/80 px-2 py-1.5 text-xs text-popover-foreground shadow-sm backdrop-blur-sm" style="left:${t.tooltipX}px;top:${t.tooltipY}px"><div class="mb-1 font-medium">${A(n)}: ${A(t.categoryLabel??this.options.formatXValue(t.xValue))}</div>${t.points.map(s=>`<div class="grid grid-cols-[auto_1fr] gap-x-2"><span class="mt-1 size-2 rounded-full" style="background:${s.color}"></span><div class="min-w-0"><div class="truncate text-muted-foreground">${A(s.name)}</div><div class="tabular-nums">${A(this.options.formatYValue(s.yValue))}</div></div></div>`).join("")}</div>`}rectangleOverlayHtml(){let t=this.rectangleZoomRect&&xt(this.rectangleZoomRect.start,this.rectangleZoomRect.end);return t?`<div class="pointer-events-none absolute z-40 rounded-sm border border-primary/70 bg-primary/10" style="left:${t.left}px;top:${t.top}px;width:${t.width}px;height:${t.height}px"></div>`:""}drawingOptionsHtml(t){let r=this.drawings.find(l=>l.id===this.selectedDrawingId);if(!r)return"";let n=t.find(l=>l.chart.id===r.chartId);if(!n||!n.descriptor.capabilities.drawings)return"";let i=r.style||{},s=r.type==="trendline"||r.type==="hline",a=r.type==="pin";return`<div data-drawing-options class="pointer-events-auto absolute z-40 flex items-center gap-1 rounded-sm bg-background/85 p-1 text-xs text-foreground shadow-sm backdrop-blur" style="left:${Math.max(n.rect.x+42,n.rect.x+n.rect.width-ut.right-8)}px;top:${n.plot.y+6}px;transform:translateX(-100%)">
|
|
157
|
+
${s?`<button type="button" data-action="extend-drawing" class="h-6 rounded-sm px-2 text-[11px] font-semibold ${i.extendRight?"bg-primary/15 text-primary ring-1 ring-primary/40":""}">Ext</button>`:""}
|
|
158
|
+
${a?`<input data-pin-text type="text" value="${A(i.text||"")}" placeholder="Text" class="h-6 w-24 rounded-sm border border-border/50 px-1.5 text-xs"/>`:""}
|
|
157
159
|
<input data-drawing-color type="color" value="${/^#[0-9a-f]{6}$/i.test(i.color||"")?i.color:"#60a5fa"}" title="Line color" class="size-6 rounded-sm border border-border/70"/>
|
|
158
|
-
</div>`}projectPoint(t,r){let n=this.viewStates.get(r.chart.id),i=this.getRange(r,n);return this.getTransform(r,n,i).dataToScreen(t)}getRange(t,r=this.viewStates.get(t.chart.id)){return pt(V(t.chart,r.xMin,r.xMax,H(t.chart,t.plot,t.descriptor),t.descriptor),this.yScales.get(t.chart.id),this.yOffsets.get(t.chart.id))}getTransform(t,r,n){return E({orientation:t.descriptor.orientation,categoryRange:{min:r.xMin,max:r.xMax},valueRange:{min:n.minY,max:n.maxY},plot:t.plot})}pointForEvent(t,r){let n=r.getBoundingClientRect();return{x:t.clientX-n.left+r.scrollLeft,y:t.clientY-n.top+r.scrollTop}}eventContext(t){let r=t.target.closest?.("[data-chart-index]");if(!r)return null;let n=!!r.closest("[data-aliencharts-fullscreen]"),i=n?this.fullscreenLayouts:this.layouts,o=Number(r.dataset.chartIndex),a=n?i[0]:i[o],s=n?this.fullscreenOverlay:this.container;return a?{layout:a,host:s,point:this.pointForEvent(t,s),fullscreen:n}:null}handleClick(t){let r=t.target.closest?.("[data-marker-index]");if(r){t.stopPropagation(),this.options.onTopMarkerClick?.(this.options.topMarkers[Number(r.dataset.markerIndex)]);return}let n=t.target.closest?.("[data-action]");if(!n)return;t.preventDefault(),t.stopPropagation();let o=this.eventContext(t)?.layout.chart.id||this.focusedChartId||this.fullscreenChartId;switch(n.dataset.action){case"fullscreen":this.fullscreenChartId?this.closeFullscreen():this.openFullscreen(o);break;case"reset":this.resetChart(o);break;case"jump-latest":this.jumpToLatest(o);break;case"rectangle-zoom":this.rectangleZoomChartId=this.rectangleZoomChartId===o?null:o,this.activeDrawingTool=null,this.emit("onActiveDrawingToolChange",null),this.requestRender();break;case"clear-drawings":this.options.onClearDrawingsRequest?this.emit("onClearDrawingsRequest",o):this.setDrawings(this.drawings.filter(a=>a.chartId!==o));break;case"moving-average":this.toggleMovingAverage(o);break;case"tool-trendline":this.toggleDrawingTool("trendline");break;case"tool-hline":this.toggleDrawingTool("hline");break;case"tool-vline":this.toggleDrawingTool("vline");break;case"tool-pin":this.toggleDrawingTool("pin");break;case"toggle-base":this.updateMovingAverage(o,{hideBase:!this.movingAverageByChart[o]?.hideBase});break;case"moving-type":this.updateMovingAverage(o,{type:this.movingAverageByChart[o]?.type==="sma"?"ema":"sma"});break;case"extend-drawing":this.updateSelectedDrawing(a=>({...a,style:{...a.style,extendRight:a.style?.extendRight===!1}}));break;default:break}}handleInput(t){if(t.target.matches("[data-moving-period]")){let r=this.eventContext(t);this.updateMovingAverage(r?.layout.chart.id,{period:Math.max(1,Math.round(Number(t.target.value)||1))})}else t.target.matches("[data-pin-text]")?this.updateSelectedDrawing(r=>({...r,style:{...r.style,text:t.target.value}})):t.target.matches("[data-drawing-color]")&&this.updateSelectedDrawing(r=>({...r,style:{...r.style,color:t.target.value}}))}handlePointerDown(t){if(t.target.closest?.("button,input")||t.button!==0)return;let r=this.eventContext(t);if(!r)return;let{layout:n,point:i}=r;this.activePointerContext=r,this.focusedChartId=n.chart.id;let o=i.x>=n.plot.x&&i.x<=n.plot.x+n.plot.width&&i.y>=n.plot.y&&i.y<=n.plot.y+n.plot.height;if(o&&this.activeDrawingTool&&!this.options.disableDrawings&&n.descriptor.capabilities.drawings){let a=rt({point:i,chart:n.chart,descriptor:n.descriptor,plot:n.plot,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}});["hline","vline","pin"].includes(this.activeDrawingTool)?this.commitDrawing(n.chart.id,this.activeDrawingTool,a,a):this.drawingSession?.chartId===n.chart.id?this.commitDrawing(n.chart.id,"trendline",this.drawingSession.start,a):(this.drawingSession={chartId:n.chart.id,type:"trendline",start:a},this.draftDrawing=At({chartId:n.chart.id,type:"trendline",start:a,end:a}))}else if(o&&this.rectangleZoomChartId===n.chart.id)this.drag={type:"rectangle",layout:n,start:i},this.rectangleZoomRect={start:i,end:i};else if(o){let a=n.descriptor.capabilities.drawings?this.hitDrawing(i,n):null;a?(this.selectedDrawingId=a.drawing.id,this.emit("onSelectedDrawingIdChange",a.drawing.id),(a.endpoint!=null||["hline","vline","pin"].includes(a.drawing.type))&&(this.drag={type:"drawing-edit",layout:n,drawingId:a.drawing.id,endpoint:a.endpoint})):(this.selectedDrawingId=null,this.emit("onSelectedDrawingIdChange",null),this.drag={type:"pan",layout:n,start:i,state:{...this.viewStates.get(n.chart.id)},yOffset:this.yOffsets.get(n.chart.id)||0})}else n.descriptor.orientation==="vertical"&&i.x>=n.plot.x+n.plot.width?this.drag={type:"y-scale",layout:n,start:i,scale:this.yScales.get(n.chart.id)||1}:n.descriptor.orientation==="horizontal"&&i.y>=n.plot.y+n.plot.height?this.drag={type:"y-scale",layout:n,start:i,scale:this.yScales.get(n.chart.id)||1}:n.descriptor.orientation==="vertical"&&i.y>=n.plot.y+n.plot.height?this.drag={type:"x-scale",layout:n,start:i,state:{...this.viewStates.get(n.chart.id)}}:n.descriptor.orientation==="horizontal"&&i.x<=n.plot.x&&(this.drag={type:"x-scale",layout:n,start:i,state:{...this.viewStates.get(n.chart.id)}});r.host.setPointerCapture?.(t.pointerId),this.pointerCaptureTarget=r.host,this.requestRender()}handlePointerMove(t){if(t.target.closest?.("button,input")&&!this.drag&&!this.drawingSession)return;let r=this.eventContext(t)||(this.activePointerContext&&(this.drag||this.drawingSession)?{...this.activePointerContext,point:this.pointForEvent(t,this.activePointerContext.host)}:null);if(!r)return this.clearCrosshair();let{layout:n,point:i}=r;if(this.drawingSession){if(n.chart.id!==this.drawingSession.chartId)return;let o=rt({point:i,chart:n.chart,descriptor:n.descriptor,plot:n.plot,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}});this.draftDrawing=At({...this.drawingSession,end:o}),this.requestRender();return}if(this.drag){let{chart:o,descriptor:a,plot:s}=this.drag.layout;if(this.drag.type==="drawing-edit"){let l=rt({point:i,chart:o,descriptor:a,plot:s,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}}),c=Mt(this.drawings,this.drag.drawingId,h=>{if(h.type==="hline"){let d=(h.end?.x??h.start.x)-h.start.x;return{...h,start:{x:l.x,y:l.y},end:{x:l.x+d,y:l.y}}}return h.type==="vline"?{...h,start:{...h.start,x:l.x},end:{...h.end,x:l.x}}:h.type==="pin"?{...h,start:l,end:l}:this.drag.endpoint==="start"||this.drag.endpoint==="end"?{...h,[this.drag.endpoint]:l}:h});this.drawings=c,this.emit("onDrawingsChange",[...c]),this.requestRender();return}if(this.drag.type==="rectangle"&&(this.rectangleZoomRect={start:this.drag.start,end:i}),this.drag.type==="pan"){let l=this.drag.state.xMax-this.drag.state.xMin,c=V(o,this.drag.state.xMin,this.drag.state.xMax,H(o,s,a),a),h=(c.maxY-c.minY)*(this.yScales.get(o.id)||1),d=E({orientation:a.orientation,categoryRange:{min:this.drag.state.xMin,max:this.drag.state.xMax},valueRange:{min:0,max:h},plot:s}),u=d.categoryDragDelta(this.drag.start,i),m=d.valueOffsetDelta(this.drag.start,i);this.viewStates.set(o.id,{xMin:this.drag.state.xMin-u,xMax:this.drag.state.xMax-u}),this.yOffsets.set(o.id,this.drag.yOffset+m)}if(this.drag.type==="y-scale"){let c=E({orientation:a.orientation,categoryRange:{min:0,max:1},valueRange:{min:0,max:1},plot:s}).valueScaleDelta(this.drag.start,i);this.yScales.set(o.id,Ce(this.drag.scale,c,vr))}if(this.drag.type==="x-scale"){let l=(this.drag.state.xMin+this.drag.state.xMax)/2,h=E({orientation:a.orientation,categoryRange:{min:0,max:1},valueRange:{min:0,max:1},plot:s}).categoryScaleDelta(this.drag.start,i),d=W((this.drag.state.xMax-this.drag.state.xMin)*Math.exp(h*.01),et(o),Lt);this.viewStates.set(o.id,{xMin:l-d/2,xMax:l+d/2})}this.drag.type==="pan"?(this.updateCrosshair(i,n),this.requestRender()):this.requestRender();return}this.updateCrosshair(i,n,r.fullscreen)}handlePointerUp(t){if(t.target.closest?.("button,input")&&!this.drag&&!this.drawingSession)return;let r=this.eventContext(t)||(this.activePointerContext?{...this.activePointerContext,point:this.pointForEvent(t,this.activePointerContext.host)}:null);if(this.drag?.type==="rectangle"&&this.rectangleZoomRect){let n=gt(this.rectangleZoomRect.start,this.rectangleZoomRect.end);if(n?.width>=4&&n?.height>=4){let i=this.drag.layout;ve({chart:i.chart,descriptor:i.descriptor,plot:i.plot,start:this.rectangleZoomRect.start,end:this.rectangleZoomRect.end,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets},yManualScaleRef:{current:new Set}})}this.rectangleZoomChartId=null,this.rectangleZoomRect=null}this.drag=null,this.pointerCaptureTarget?.releasePointerCapture?.(t.pointerId),this.pointerCaptureTarget=null,this.activePointerContext=null,this.requestRender()}handleWheel(t){let r=this.eventContext(t);if(!r)return;let{layout:n,point:i}=r;if(!(i.x>=n.plot.x&&i.x<=n.plot.x+n.plot.width&&i.y>=n.plot.y&&i.y<=n.plot.y+n.plot.height))return;if(t.preventDefault(),t.shiftKey){let u=t.deltaY||t.deltaX,m=this.yScales.get(n.chart.id)||1;this.yScales.set(n.chart.id,Ce(m,u,br)),this.requestRender();return}let a=this.viewStates.get(n.chart.id),s=this.getRange(n,a),l=W(this.getTransform(n,a,s).categoryRatio(i),0,1),c=a.xMin+l*(a.xMax-a.xMin),h=Math.exp(t.deltaY*.001),d=W((a.xMax-a.xMin)*h,et(n.chart),Lt);this.viewStates.set(n.chart.id,{xMin:c-l*d,xMax:c+(1-l)*d}),this.requestRender()}handleContextMenu(t){let r=this.eventContext(t);if(!r||!this.options.onChartContextMenu)return;t.preventDefault();let{layout:n,point:i}=r,a=i.x>=n.plot.x&&i.x<=n.plot.x+n.plot.width&&i.y>=n.plot.y&&i.y<=n.plot.y+n.plot.height?rt({point:i,chart:n.chart,descriptor:n.descriptor,plot:n.plot,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}}):null;this.options.onChartContextMenu({chart:n.chart,event:t,point:a})}updateCrosshair(t,r){if(!(t.x>=r.plot.x&&t.x<=r.plot.x+r.plot.width&&t.y>=r.plot.y&&t.y<=r.plot.y+r.plot.height)||!this.options.showTooltips)return this.clearCrosshair();let i=this.viewStates.get(r.chart.id),o=r.descriptor.orientation,a=this.getRange(r,i),s=this.getTransform(r,i,a),l=s.screenToData(t).x,c=T(r.chart,this.options.seriesOrderByChart),h=c.map((u,m)=>{let x=u.getVisiblePoints(i.xMin,i.xMax,s.categoryPixelLength);if(!x.pointCount)return null;let f=ge(x.x,l),b={x:this.surface.renderers.getTooltipCategory(r.descriptor.rendererType,{visiblePoints:x,pointIndex:f,seriesIndex:m,seriesCount:c.length,categoryMin:i.xMin,categoryMax:i.xMax}),y:x.y[f]},g=s.dataToScreen(b);return{id:u.id,name:u.name,color:u.color,x:g.x,y:g.y,xValue:x.x[f],yValue:b.y}}).filter(Boolean);if(!h.length)return this.clearCrosshair();let d=h.reduce((u,m)=>{let x=Math.abs(o==="horizontal"?m.y-t.y:m.x-t.x),f=Math.abs(o==="horizontal"?u.y-t.y:u.x-t.x);return x<f?m:u});this.crosshair={chartId:r.chart.id,x:t.x,y:t.y,xValue:d.xValue,categoryLabel:jt(r.chart,d.xValue),points:h,tooltipX:t.x+232>r.rect.x+r.rect.width?t.x-232:t.x+12,tooltipY:W(t.y+12,r.plot.y,r.rect.y+r.rect.height-96)},this.requestRender()}clearCrosshair(){this.crosshair&&(this.crosshair=null,this.requestRender())}hitDrawing(t,r){for(let n of it(this.drawings,r.chart.id)){let i=Ut({point:t,drawing:n,layout:r,projectPoint:o=>this.projectPoint(o,r)});if(i)return i}return null}commitDrawing(t,r,n,i){let o=Ht({chartId:t,type:r,start:n,end:i,createDrawingId:this.options.createDrawingId});this.setDrawings([...this.drawings,o]),this.selectedDrawingId=o.id,this.activeDrawingTool=null,this.draftDrawing=null,this.drawingSession=null,this.emit("onSelectedDrawingIdChange",o.id),this.emit("onActiveDrawingToolChange",null)}setDrawings(t){this.drawings=t,this.emit("onDrawingsChange",[...t]),this.requestRender()}updateSelectedDrawing(t){this.selectedDrawingId&&this.setDrawings(Mt(this.drawings,this.selectedDrawingId,t))}toggleDrawingTool(t){!Yt.has(t)||this.options.disableDrawings||(this.activeDrawingTool=this.activeDrawingTool===t?null:t,this.rectangleZoomChartId=null,this.draftDrawing=null,this.drawingSession=null,this.emit("onActiveDrawingToolChange",this.activeDrawingTool),this.requestRender())}toggleMovingAverage(t){if(!t||this.options.disableDrawings||!this.options.charts.find(i=>i.id===t)||!this.chartDescriptors.get(t)?.capabilities.movingAverage)return;let n=this.movingAverageByChart[t]||{period:21,type:"ema",hideBase:!1};this.movingAverageByChart={...this.movingAverageByChart,[t]:{...n,enabled:!n.enabled}},this.emit("onMovingAverageToggle",t),this.requestRender()}updateMovingAverage(t,r){if(!t)return;let n={enabled:!0,period:21,type:"ema",hideBase:!1,...this.movingAverageByChart[t]||{},...r};this.movingAverageByChart={...this.movingAverageByChart,[t]:n},this.emit("onMovingAverageChange",t,{...n}),this.requestRender()}resetChart(t){let r=this.options.charts.find(n=>n.id===t);r&&(this.viewStates.set(t,N(r,this.options.initialVisiblePoints)),this.yScales.set(t,1),this.yOffsets.set(t,0),this.requestRender())}openFullscreen(t){let r=this.options.charts.find(a=>a.id===t);if(!r||this.fullscreenChartId)return;this.fullscreenChartId=t;let n=document.createElement("div");n.dataset.alienchartsFullscreen="",n.className="aliencharts-root fixed inset-0 z-[60] bg-background p-2",n.innerHTML=`<canvas class="pointer-events-none absolute left-0 top-0 z-10 block"></canvas><div data-fullscreen-cell>${Ae(r,this.chartDescriptors.get(r.id),0,this.options.backgroundColor)}</div><div data-fullscreen-overlays class="pointer-events-none absolute left-0 top-0 z-20" style="width:100%;height:100%"></div>`,document.body.append(n),this.fullscreenOverlay=n,this.fullscreenNode=n.querySelector("[data-chart-index]"),this.fullscreenNode.style.height="calc(100vh - 16px)",this.fullscreenOverlays=n.querySelector("[data-fullscreen-overlays]");let i=n.querySelector("canvas"),o=i.getContext("webgl2",{antialias:!0,alpha:!0,depth:!1,stencil:!1});if(!o){n.remove(),this.fullscreenChartId=null;return}this.fullscreenSurface=Se(i,o),this.fullscreenListeners=Object.entries(this.bound).filter(([a])=>a!=="keydown"&&a!=="scroll"),this.fullscreenListeners.forEach(([a,s])=>n.addEventListener(a,s,a==="wheel"?{passive:!1}:void 0)),this.resizeObserver.observe(n),this.requestRender()}closeFullscreen(){this.fullscreenChartId&&(this.fullscreenOverlay&&this.resizeObserver?.unobserve(this.fullscreenOverlay),this.fullscreenListeners?.forEach(([t,r])=>this.fullscreenOverlay?.removeEventListener(t,r)),this.fullscreenListeners=null,Me(this.fullscreenSurface),this.fullscreenOverlay?.remove(),this.fullscreenSurface=null,this.fullscreenOverlay=null,this.fullscreenNode=null,this.fullscreenOverlays=null,this.fullscreenLayouts=[],this.fullscreenChartId=null,this.requestRender())}handleKeyDown(t){if(t.target instanceof HTMLElement&&(t.target.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(t.target.tagName)))return;let n=this.fullscreenChartId||this.focusedChartId,o=this.options.charts.find(s=>s.id===n)&&this.chartDescriptors.get(n)?.capabilities,a=t.key.toLowerCase();if(["arrowleft","arrowright","arrowup","arrowdown"].includes(a)&&!this.fullscreenChartId){this.moveFocus(a.replace("arrow","")),t.preventDefault();return}a==="r"?(this.resetChart(n),t.preventDefault()):a==="z"?(this.rectangleZoomChartId=this.rectangleZoomChartId===n?null:n,t.preventDefault(),this.requestRender()):a==="m"&&o?.movingAverage?(this.toggleMovingAverage(n),t.preventDefault()):["t","h","v","p"].includes(a)&&o?.drawings?(this.toggleDrawingTool({t:"trendline",h:"hline",v:"vline",p:"pin"}[a]),t.preventDefault()):(a==="delete"||a==="backspace")&&this.selectedDrawingId?(this.setDrawings(Vt(this.drawings,this.selectedDrawingId)),this.selectedDrawingId=null,this.emit("onSelectedDrawingIdChange",null),t.preventDefault()):a==="escape"&&(this.activeDrawingTool||this.draftDrawing||this.rectangleZoomChartId)?(this.activeDrawingTool=null,this.draftDrawing=null,this.drawingSession=null,this.rectangleZoomChartId=null,this.rectangleZoomRect=null,this.emit("onActiveDrawingToolChange",null),this.requestRender(),t.preventDefault()):(a==="f"||a==="escape"&&this.fullscreenChartId)&&(this.fullscreenChartId?this.closeFullscreen():this.openFullscreen(n),t.preventDefault())}moveFocus(t){let r=this.options.charts;if(!r.length)return;let n=Math.max(0,r.findIndex(o=>o.id===this.focusedChartId)),i=Math.max(1,Number(this.options.columns)||1);t==="left"&&(n=Math.max(Math.floor(n/i)*i,n-1)),t==="right"&&(n=Math.min(r.length-1,n+1)),t==="up"&&(n=Math.max(0,n-i)),t==="down"&&(n=Math.min(r.length-1,n+i)),this.focusedChartId=r[n].id,this.chartNodes[n]?.scrollIntoView({block:"nearest",inline:"nearest"}),this.requestRender()}emit(t,...r){this.options[t]?.(...r)}cleanupDom(){this.canvas?.remove(),this.grid?.remove(),this.overlays?.remove(),this.addedClasses?.forEach(t=>this.container.classList.remove(t))}destroy(){this.destroyed||(this.closeFullscreen(),this.destroyed=!0,this.frame!=null&&cancelAnimationFrame(this.frame),this.animator.destroy(),this.resizeObserver.disconnect(),Object.entries(this.bound).forEach(([t,r])=>{(t==="keydown"?window:this.container).removeEventListener(t,r)}),Me(this.surface),this.cleanupDom())}},_e=(e,t={})=>new Nt(e,t);var Re=["#38bdf8","#22c55e","#f59e0b","#ef4444","#a855f7","#14b8a6"],Cr=e=>{let t=e>>>0;return()=>(t=t*1664525+1013904223>>>0,t/4294967296)},Ar=({chartIndex:e,seriesIndex:t,pointCount:r})=>{let n=new Float64Array(r),i=new Float32Array(r),o=Cr((e+1)*1009+t*9176),a=15+o()*45+t*4,s=8e-4+o()*.004,l=.006+o()*.03,c=5e-5+o()*6e-4,h=.015+o()*.09,d=.005+o()*.04,u=(o()-.5)*.004,m=.004+o()*.025,x=180+Math.floor(o()*900),f=.12+o()*.7,y=a;for(let b=0;b<r;b+=1){n[b]=b;let g=(b+e*13+t*31)%x===0?f*(o()>.45?1:-1):0;y+=Math.sin(b*s+e)*h+Math.cos(b*l+t)*d+Math.sin(b*c)*h*.35+u+(o()-.5)*m+g,i[b]=y}return B({id:`chart-${e}-series-${t}`,name:`Run ${t+1}`,color:Re[(e+t)%Re.length],x:n,y:i})},De=({chartCount:e=50,seriesPerChart:t=2,pointCount:r=5e5}={})=>Array.from({length:e},(n,i)=>({id:`metric-${i+1}`,title:`metric_${String(i+1).padStart(2,"0")}`,series:Array.from({length:t},(o,a)=>Ar({chartIndex:i,seriesIndex:a,pointCount:r}))}));return Ne(Sr);})();
|
|
160
|
+
</div>`}projectPoint(t,r){let n=this.viewStates.get(r.chart.id),i=this.getRange(r,n);return this.getTransform(r,n,i).dataToScreen(t)}getRange(t,r=this.viewStates.get(t.chart.id)){let n=et(t.chart,r.xMin,r.xMax,X(t.chart,t.plot,t.descriptor),t.descriptor),i=this.yBaseRanges.get(t.chart.id);return Ot(i?{...n,...i}:n,this.yScales.get(t.chart.id),this.yOffsets.get(t.chart.id))}lockYRange(t,r=this.viewStates.get(t.chart.id)){if(this.yBaseRanges.has(t.chart.id))return;let n=et(t.chart,r.xMin,r.xMax,X(t.chart,t.plot,t.descriptor),t.descriptor);this.yBaseRanges.set(t.chart.id,{minY:n.minY,maxY:n.maxY})}getTransform(t,r,n){return L({orientation:t.descriptor.orientation,categoryRange:{min:r.xMin,max:r.xMax},valueRange:{min:n.minY,max:n.maxY},plot:t.plot})}pointForEvent(t,r){let n=r.getBoundingClientRect();return{x:t.clientX-n.left+r.scrollLeft,y:t.clientY-n.top+r.scrollTop}}eventContext(t){let r=t.target.closest?.("[data-chart-index]");if(!r)return null;let n=!!r.closest("[data-aliencharts-fullscreen]"),i=n?this.fullscreenLayouts:this.layouts,s=Number(r.dataset.chartIndex),a=n?i[0]:i[s],o=n?this.fullscreenOverlay:this.container;return a?{layout:a,host:o,point:this.pointForEvent(t,o),fullscreen:n}:null}handleClick(t){let r=t.target.closest?.("[data-marker-index]");if(r){t.stopPropagation(),this.options.onTopMarkerClick?.(this.options.topMarkers[Number(r.dataset.markerIndex)]);return}let n=t.target.closest?.("[data-action]");if(!n)return;t.preventDefault(),t.stopPropagation();let s=this.eventContext(t)?.layout.chart.id||this.focusedChartId||this.fullscreenChartId;switch(n.dataset.action){case"fullscreen":this.fullscreenChartId?this.closeFullscreen():this.openFullscreen(s);break;case"reset":this.resetChart(s);break;case"jump-latest":this.jumpToLatest(s);break;case"rectangle-zoom":this.rectangleZoomChartId=this.rectangleZoomChartId===s?null:s,this.activeDrawingTool=null,this.emit("onActiveDrawingToolChange",null),this.requestRender();break;case"clear-drawings":this.options.onClearDrawingsRequest?this.emit("onClearDrawingsRequest",s):this.setDrawings(this.drawings.filter(a=>a.chartId!==s));break;case"moving-average":this.toggleMovingAverage(s);break;case"tool-trendline":this.toggleDrawingTool("trendline");break;case"tool-hline":this.toggleDrawingTool("hline");break;case"tool-vline":this.toggleDrawingTool("vline");break;case"tool-pin":this.toggleDrawingTool("pin");break;case"toggle-base":this.updateMovingAverage(s,{hideBase:!this.movingAverageByChart[s]?.hideBase});break;case"moving-type":this.updateMovingAverage(s,{type:this.movingAverageByChart[s]?.type==="sma"?"ema":"sma"});break;case"extend-drawing":this.updateSelectedDrawing(a=>({...a,style:{...a.style,extendRight:a.style?.extendRight===!1}}));break;default:break}}handleInput(t){if(t.target.matches("[data-moving-period]")){let r=this.eventContext(t);this.updateMovingAverage(r?.layout.chart.id,{period:Math.max(1,Math.round(Number(t.target.value)||1))})}else t.target.matches("[data-pin-text]")?this.updateSelectedDrawing(r=>({...r,style:{...r.style,text:t.target.value}})):t.target.matches("[data-drawing-color]")&&this.updateSelectedDrawing(r=>({...r,style:{...r.style,color:t.target.value}}))}handlePointerDown(t){if(t.target.closest?.("button,input")||t.button!==0)return;let r=this.eventContext(t);if(!r)return;let{layout:n,point:i}=r;this.activePointerContext=r,this.focusedChartId=n.chart.id;let s=i.x>=n.plot.x&&i.x<=n.plot.x+n.plot.width&&i.y>=n.plot.y&&i.y<=n.plot.y+n.plot.height;if(s&&this.activeDrawingTool&&!this.options.disableDrawings&&n.descriptor.capabilities.drawings){let a=rt({point:i,chart:n.chart,descriptor:n.descriptor,plot:n.plot,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yBaseRangeRef:{current:this.yBaseRanges},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}});["hline","vline","pin"].includes(this.activeDrawingTool)?this.commitDrawing(n.chart.id,this.activeDrawingTool,a,a):this.drawingSession?.chartId===n.chart.id?this.commitDrawing(n.chart.id,"trendline",this.drawingSession.start,a):(this.drawingSession={chartId:n.chart.id,type:"trendline",start:a},this.draftDrawing=St({chartId:n.chart.id,type:"trendline",start:a,end:a}))}else if(s&&this.rectangleZoomChartId===n.chart.id)this.drag={type:"rectangle",layout:n,start:i},this.rectangleZoomRect={start:i,end:i};else if(s){let a=n.descriptor.capabilities.drawings?this.hitDrawing(i,n):null;if(a)this.selectedDrawingId=a.drawing.id,this.emit("onSelectedDrawingIdChange",a.drawing.id),(a.endpoint!=null||["hline","vline","pin"].includes(a.drawing.type))&&(this.drag={type:"drawing-edit",layout:n,drawingId:a.drawing.id,endpoint:a.endpoint});else{this.selectedDrawingId=null,this.emit("onSelectedDrawingIdChange",null);let o={...this.viewStates.get(n.chart.id)},l=this.getRange(n,o);this.drag={type:"pan",layout:n,start:i,state:o,yOffset:this.yOffsets.get(n.chart.id)||0,canPanY:this.yBaseRanges.has(n.chart.id),valueSpan:l.maxY-l.minY}}}else n.descriptor.orientation==="vertical"&&i.x>=n.plot.x+n.plot.width?this.drag={type:"y-scale",layout:n,start:i,scale:this.yScales.get(n.chart.id)||1}:n.descriptor.orientation==="horizontal"&&i.y>=n.plot.y+n.plot.height?this.drag={type:"y-scale",layout:n,start:i,scale:this.yScales.get(n.chart.id)||1}:n.descriptor.orientation==="vertical"&&i.y>=n.plot.y+n.plot.height?this.drag={type:"x-scale",layout:n,start:i,state:{...this.viewStates.get(n.chart.id)}}:n.descriptor.orientation==="horizontal"&&i.x<=n.plot.x&&(this.drag={type:"x-scale",layout:n,start:i,state:{...this.viewStates.get(n.chart.id)}});r.host.setPointerCapture?.(t.pointerId),this.pointerCaptureTarget=r.host,this.requestRender()}handlePointerMove(t){if(t.target.closest?.("button,input")&&!this.drag&&!this.drawingSession)return;let r=this.eventContext(t)||(this.activePointerContext&&(this.drag||this.drawingSession)?{...this.activePointerContext,point:this.pointForEvent(t,this.activePointerContext.host)}:null);if(!r)return this.clearCrosshair();let{layout:n,point:i}=r;if(this.drawingSession){if(n.chart.id!==this.drawingSession.chartId)return;let s=rt({point:i,chart:n.chart,descriptor:n.descriptor,plot:n.plot,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yBaseRangeRef:{current:this.yBaseRanges},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}});this.draftDrawing=St({...this.drawingSession,end:s}),this.requestRender();return}if(this.drag){let{chart:s,descriptor:a,plot:o}=this.drag.layout;if(this.drag.type==="drawing-edit"){let l=rt({point:i,chart:s,descriptor:a,plot:o,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yBaseRangeRef:{current:this.yBaseRanges},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}}),c=Rt(this.drawings,this.drag.drawingId,h=>{if(h.type==="hline"){let d=(h.end?.x??h.start.x)-h.start.x;return{...h,start:{x:l.x,y:l.y},end:{x:l.x+d,y:l.y}}}return h.type==="vline"?{...h,start:{...h.start,x:l.x},end:{...h.end,x:l.x}}:h.type==="pin"?{...h,start:l,end:l}:this.drag.endpoint==="start"||this.drag.endpoint==="end"?{...h,[this.drag.endpoint]:l}:h});this.drawings=c,this.emit("onDrawingsChange",[...c]),this.requestRender();return}if(this.drag.type==="rectangle"&&(this.rectangleZoomRect={start:this.drag.start,end:i}),this.drag.type==="pan"){let l=L({orientation:a.orientation,categoryRange:{min:this.drag.state.xMin,max:this.drag.state.xMax},valueRange:{min:0,max:this.drag.valueSpan},plot:o}),c=l.categoryDragDelta(this.drag.start,i),h=l.valueOffsetDelta(this.drag.start,i);this.viewStates.set(s.id,{xMin:this.drag.state.xMin-c,xMax:this.drag.state.xMax-c}),this.drag.canPanY&&this.yOffsets.set(s.id,this.drag.yOffset+h)}if(this.drag.type==="y-scale"){let c=L({orientation:a.orientation,categoryRange:{min:0,max:1},valueRange:{min:0,max:1},plot:o}).valueScaleDelta(this.drag.start,i);c!==0&&this.lockYRange(this.drag.layout),this.yScales.set(s.id,Ce(this.drag.scale,c,vr))}if(this.drag.type==="x-scale"){let l=(this.drag.state.xMin+this.drag.state.xMax)/2,h=L({orientation:a.orientation,categoryRange:{min:0,max:1},valueRange:{min:0,max:1},plot:o}).categoryScaleDelta(this.drag.start,i),d=U((this.drag.state.xMax-this.drag.state.xMin)*Math.exp(h*.01),tt(s),It);this.viewStates.set(s.id,{xMin:l-d/2,xMax:l+d/2})}this.drag.type==="pan"?(this.updateCrosshair(i,n),this.requestRender()):this.requestRender();return}this.updateCrosshair(i,n,r.fullscreen)}handlePointerUp(t){if(t.target.closest?.("button,input")&&!this.drag&&!this.drawingSession)return;let r=this.eventContext(t)||(this.activePointerContext?{...this.activePointerContext,point:this.pointForEvent(t,this.activePointerContext.host)}:null);if(this.drag?.type==="rectangle"&&this.rectangleZoomRect){let n=xt(this.rectangleZoomRect.start,this.rectangleZoomRect.end);if(n?.width>=4&&n?.height>=4){let i=this.drag.layout;ve({chart:i.chart,descriptor:i.descriptor,plot:i.plot,start:this.rectangleZoomRect.start,end:this.rectangleZoomRect.end,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yBaseRangeRef:{current:this.yBaseRanges},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets},yManualScaleRef:{current:new Set}})&&this.lockYRange(i)}this.rectangleZoomChartId=null,this.rectangleZoomRect=null}this.drag=null,this.pointerCaptureTarget?.releasePointerCapture?.(t.pointerId),this.pointerCaptureTarget=null,this.activePointerContext=null,this.requestRender()}handleWheel(t){let r=this.eventContext(t);if(!r)return;let{layout:n,point:i}=r;if(!(i.x>=n.plot.x&&i.x<=n.plot.x+n.plot.width&&i.y>=n.plot.y&&i.y<=n.plot.y+n.plot.height))return;if(t.preventDefault(),t.shiftKey){let u=t.deltaY||t.deltaX,m=this.yScales.get(n.chart.id)||1;u!==0&&this.lockYRange(n),this.yScales.set(n.chart.id,Ce(m,u,br)),this.requestRender();return}let a=this.viewStates.get(n.chart.id),o=this.getRange(n,a),l=U(this.getTransform(n,a,o).categoryRatio(i),0,1),c=a.xMin+l*(a.xMax-a.xMin),h=Math.exp(t.deltaY*.001),d=U((a.xMax-a.xMin)*h,tt(n.chart),It);this.viewStates.set(n.chart.id,{xMin:c-l*d,xMax:c+(1-l)*d}),this.requestRender()}handleContextMenu(t){let r=this.eventContext(t);if(!r||!this.options.onChartContextMenu)return;t.preventDefault();let{layout:n,point:i}=r,a=i.x>=n.plot.x&&i.x<=n.plot.x+n.plot.width&&i.y>=n.plot.y&&i.y<=n.plot.y+n.plot.height?rt({point:i,chart:n.chart,descriptor:n.descriptor,plot:n.plot,initialVisiblePoints:this.options.initialVisiblePoints,viewStateRef:{current:this.viewStates},yBaseRangeRef:{current:this.yBaseRanges},yScaleRef:{current:this.yScales},yCenterOffsetRef:{current:this.yOffsets}}):null;this.options.onChartContextMenu({chart:n.chart,event:t,point:a})}updateCrosshair(t,r){if(!(t.x>=r.plot.x&&t.x<=r.plot.x+r.plot.width&&t.y>=r.plot.y&&t.y<=r.plot.y+r.plot.height)||!this.options.showTooltips)return this.clearCrosshair();let i=this.viewStates.get(r.chart.id),s=r.descriptor.orientation,a=this.getRange(r,i),o=this.getTransform(r,i,a),l=o.screenToData(t).x,c=E(r.chart,this.options.seriesOrderByChart),h=c.map((u,m)=>{let x=u.getVisiblePoints(i.xMin,i.xMax,o.categoryPixelLength);if(!x.pointCount)return null;let f=me(x.x,l),v={x:this.surface.renderers.getTooltipCategory(r.descriptor.rendererType,{visiblePoints:x,pointIndex:f,seriesIndex:m,seriesCount:c.length,categoryMin:i.xMin,categoryMax:i.xMax}),y:x.y[f]},g=o.dataToScreen(v);return{id:u.id,name:u.name,color:u.color,x:g.x,y:g.y,xValue:x.x[f],yValue:v.y}}).filter(Boolean);if(!h.length)return this.clearCrosshair();let d=h.reduce((u,m)=>{let x=Math.abs(s==="horizontal"?m.y-t.y:m.x-t.x),f=Math.abs(s==="horizontal"?u.y-t.y:u.x-t.x);return x<f?m:u});this.crosshair={chartId:r.chart.id,x:t.x,y:t.y,xValue:d.xValue,categoryLabel:qt(r.chart,d.xValue),points:h,plot:{...r.plot},tooltipX:t.x+232>r.rect.x+r.rect.width?t.x-232:t.x+12,tooltipY:U(t.y+12,r.plot.y,r.rect.y+r.rect.height-96)},this.requestRender()}clearCrosshair(){this.crosshair&&(this.crosshair=null,this.requestRender())}hitDrawing(t,r){for(let n of at(this.drawings,r.chart.id)){let i=Vt({point:t,drawing:n,layout:r,projectPoint:s=>this.projectPoint(s,r)});if(i)return i}return null}commitDrawing(t,r,n,i){let s=Ut({chartId:t,type:r,start:n,end:i,createDrawingId:this.options.createDrawingId});this.setDrawings([...this.drawings,s]),this.selectedDrawingId=s.id,this.activeDrawingTool=null,this.draftDrawing=null,this.drawingSession=null,this.emit("onSelectedDrawingIdChange",s.id),this.emit("onActiveDrawingToolChange",null)}setDrawings(t){this.drawings=t,this.emit("onDrawingsChange",[...t]),this.requestRender()}updateSelectedDrawing(t){this.selectedDrawingId&&this.setDrawings(Rt(this.drawings,this.selectedDrawingId,t))}toggleDrawingTool(t){!Xt.has(t)||this.options.disableDrawings||(this.activeDrawingTool=this.activeDrawingTool===t?null:t,this.rectangleZoomChartId=null,this.draftDrawing=null,this.drawingSession=null,this.emit("onActiveDrawingToolChange",this.activeDrawingTool),this.requestRender())}toggleMovingAverage(t){if(!t||this.options.disableDrawings||!this.options.charts.find(i=>i.id===t)||!this.chartDescriptors.get(t)?.capabilities.movingAverage)return;let n=this.movingAverageByChart[t]||{period:21,type:"ema",hideBase:!1};this.movingAverageByChart={...this.movingAverageByChart,[t]:{...n,enabled:!n.enabled}},this.emit("onMovingAverageToggle",t),this.requestRender()}updateMovingAverage(t,r){if(!t)return;let n={enabled:!0,period:21,type:"ema",hideBase:!1,...this.movingAverageByChart[t]||{},...r};this.movingAverageByChart={...this.movingAverageByChart,[t]:n},this.emit("onMovingAverageChange",t,{...n}),this.requestRender()}resetChart(t){let r=this.options.charts.find(n=>n.id===t);r&&(this.viewStates.set(t,N(r,this.options.initialVisiblePoints)),this.yScales.set(t,1),this.yOffsets.set(t,0),this.yBaseRanges.delete(t),this.requestRender())}openFullscreen(t){let r=this.options.charts.find(a=>a.id===t);if(!r||this.fullscreenChartId)return;this.fullscreenChartId=t;let n=document.createElement("div");n.dataset.alienchartsFullscreen="",n.className="aliencharts-root fixed inset-0 z-[60] bg-background p-2",n.innerHTML=`<canvas class="pointer-events-none absolute left-0 top-0 z-10 block"></canvas><div data-fullscreen-cell>${Ae(r,this.chartDescriptors.get(r.id),0,this.options.backgroundColor)}</div><div data-fullscreen-overlays class="pointer-events-none absolute left-0 top-0 z-20" style="width:100%;height:100%"></div>`,document.body.append(n),this.fullscreenOverlay=n,this.fullscreenNode=n.querySelector("[data-chart-index]"),this.fullscreenNode.style.height="calc(100vh - 16px)",this.fullscreenOverlays=n.querySelector("[data-fullscreen-overlays]");let i=n.querySelector("canvas"),s=i.getContext("webgl2",{antialias:!0,alpha:!0,depth:!1,stencil:!1});if(!s){n.remove(),this.fullscreenChartId=null;return}this.fullscreenSurface=Se(i,s),this.fullscreenListeners=Object.entries(this.bound).filter(([a])=>a!=="keydown"&&a!=="scroll"),this.fullscreenListeners.forEach(([a,o])=>n.addEventListener(a,o,a==="wheel"?{passive:!1}:void 0)),this.resizeObserver.observe(n),this.requestRender()}closeFullscreen(){this.fullscreenChartId&&(this.fullscreenOverlay&&this.resizeObserver?.unobserve(this.fullscreenOverlay),this.fullscreenListeners?.forEach(([t,r])=>this.fullscreenOverlay?.removeEventListener(t,r)),this.fullscreenListeners=null,Me(this.fullscreenSurface),this.fullscreenOverlay?.remove(),this.fullscreenSurface=null,this.fullscreenOverlay=null,this.fullscreenNode=null,this.fullscreenOverlays=null,this.fullscreenLayouts=[],this.fullscreenChartId=null,this.requestRender())}handleKeyDown(t){if(t.target instanceof HTMLElement&&(t.target.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(t.target.tagName)))return;let n=this.fullscreenChartId||this.focusedChartId,s=this.options.charts.find(o=>o.id===n)&&this.chartDescriptors.get(n)?.capabilities,a=t.key.toLowerCase();if(["arrowleft","arrowright","arrowup","arrowdown"].includes(a)&&!this.fullscreenChartId){this.moveFocus(a.replace("arrow","")),t.preventDefault();return}a==="r"?(this.resetChart(n),t.preventDefault()):a==="z"?(this.rectangleZoomChartId=this.rectangleZoomChartId===n?null:n,t.preventDefault(),this.requestRender()):a==="m"&&s?.movingAverage?(this.toggleMovingAverage(n),t.preventDefault()):["t","h","v","p"].includes(a)&&s?.drawings?(this.toggleDrawingTool({t:"trendline",h:"hline",v:"vline",p:"pin"}[a]),t.preventDefault()):(a==="delete"||a==="backspace")&&this.selectedDrawingId?(this.setDrawings(Wt(this.drawings,this.selectedDrawingId)),this.selectedDrawingId=null,this.emit("onSelectedDrawingIdChange",null),t.preventDefault()):a==="escape"&&(this.activeDrawingTool||this.draftDrawing||this.rectangleZoomChartId)?(this.activeDrawingTool=null,this.draftDrawing=null,this.drawingSession=null,this.rectangleZoomChartId=null,this.rectangleZoomRect=null,this.emit("onActiveDrawingToolChange",null),this.requestRender(),t.preventDefault()):(a==="f"||a==="escape"&&this.fullscreenChartId)&&(this.fullscreenChartId?this.closeFullscreen():this.openFullscreen(n),t.preventDefault())}moveFocus(t){let r=this.options.charts;if(!r.length)return;let n=Math.max(0,r.findIndex(s=>s.id===this.focusedChartId)),i=Math.max(1,Number(this.options.columns)||1);t==="left"&&(n=Math.max(Math.floor(n/i)*i,n-1)),t==="right"&&(n=Math.min(r.length-1,n+1)),t==="up"&&(n=Math.max(0,n-i)),t==="down"&&(n=Math.min(r.length-1,n+i)),this.focusedChartId=r[n].id,this.chartNodes[n]?.scrollIntoView({block:"nearest",inline:"nearest"}),this.requestRender()}emit(t,...r){this.options[t]?.(...r)}cleanupDom(){this.canvas?.remove(),this.grid?.remove(),this.overlays?.remove(),this.addedClasses?.forEach(t=>this.container.classList.remove(t))}destroy(){this.destroyed||(this.closeFullscreen(),this.destroyed=!0,this.frame!=null&&cancelAnimationFrame(this.frame),this.animator.destroy(),this.resizeObserver.disconnect(),Object.entries(this.bound).forEach(([t,r])=>{(t==="keydown"?window:this.container).removeEventListener(t,r)}),Me(this.surface),this.cleanupDom())}},Re=(e,t={})=>new Bt(e,t);var _e=["#38bdf8","#22c55e","#f59e0b","#ef4444","#a855f7","#14b8a6"],Cr=e=>{let t=e>>>0;return()=>(t=t*1664525+1013904223>>>0,t/4294967296)},Ar=({chartIndex:e,seriesIndex:t,pointCount:r})=>{let n=new Float64Array(r),i=new Float32Array(r),s=Cr((e+1)*1009+t*9176),a=15+s()*45+t*4,o=8e-4+s()*.004,l=.006+s()*.03,c=5e-5+s()*6e-4,h=.015+s()*.09,d=.005+s()*.04,u=(s()-.5)*.004,m=.004+s()*.025,x=180+Math.floor(s()*900),f=.12+s()*.7,y=a;for(let v=0;v<r;v+=1){n[v]=v;let g=(v+e*13+t*31)%x===0?f*(s()>.45?1:-1):0;y+=Math.sin(v*o+e)*h+Math.cos(v*l+t)*d+Math.sin(v*c)*h*.35+u+(s()-.5)*m+g,i[v]=y}return k({id:`chart-${e}-series-${t}`,name:`Run ${t+1}`,color:_e[(e+t)%_e.length],x:n,y:i})},De=({chartCount:e=50,seriesPerChart:t=2,pointCount:r=5e5}={})=>Array.from({length:e},(n,i)=>({id:`metric-${i+1}`,title:`metric_${String(i+1).padStart(2,"0")}`,series:Array.from({length:t},(s,a)=>Ar({chartIndex:i,seriesIndex:a,pointCount:r}))}));return Ne(Sr);})();
|
|
159
161
|
//# sourceMappingURL=aliencharts.global.min.js.map
|