monobill-mintui 0.6.618 → 0.6.620
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/alert/browser.js +3 -3
- package/dist/components/alert/index.cjs +1 -1
- package/dist/components/alert/index.js +3 -3
- package/dist/components/back-button/browser.js +2 -2
- package/dist/components/back-button/index.cjs +1 -1
- package/dist/components/back-button/index.js +2 -2
- package/dist/components/bottom-navigation/browser.js +2 -2
- package/dist/components/bottom-navigation/index.cjs +1 -1
- package/dist/components/bottom-navigation/index.js +2 -2
- package/dist/components/button/browser.js +1 -1
- package/dist/components/button/index.cjs +1 -1
- package/dist/components/button/index.js +1 -1
- package/dist/components/chart/browser.js +110 -99
- package/dist/components/chart/index.cjs +3 -3
- package/dist/components/chart/index.js +110 -99
- package/dist/components/checkbox/browser.js +2 -2
- package/dist/components/checkbox/index.cjs +1 -1
- package/dist/components/checkbox/index.js +2 -2
- package/dist/components/chip/browser.js +1 -1
- package/dist/components/chip/index.cjs +1 -1
- package/dist/components/chip/index.js +1 -1
- package/dist/components/chunks/{button-BZ25puI2.js → button-BYQbRAwl.js} +2 -2
- package/dist/components/chunks/{button-CgYC1lB7.js → button-DbxqmBWQ.js} +1 -1
- package/dist/components/chunks/caret-down-CeADWana.js +1 -0
- package/dist/components/chunks/{caret-down-CDGP3GB2.js → caret-down-DD9Ie5js.js} +1 -1
- package/dist/components/chunks/caret-right-3V_JDnOP.js +1 -0
- package/dist/components/chunks/{caret-right-CQ5hBjsy.js → caret-right-fnCcTJKp.js} +1 -1
- package/dist/components/chunks/{caret-up-1paz-pnI.js → caret-up-CK7JOG6X.js} +1 -1
- package/dist/components/chunks/caret-up-hwsMK8n3.js +1 -0
- package/dist/components/chunks/{chip-p6RXdzHa.js → chip-08aR26vc.js} +3 -3
- package/dist/components/chunks/{chip-Bb1Epj5C.js → chip-8BYSJ7yI.js} +1 -1
- package/dist/components/chunks/close-BdZJfr6m.js +1 -0
- package/dist/components/chunks/{close-y8q0rMSE.js → close-CFxX3WCG.js} +1 -1
- package/dist/components/chunks/icon-B8p3Co0-.js +1 -0
- package/dist/components/chunks/{icon-B01tq_aJ.js → icon-BWUYe89V.js} +4 -3
- package/dist/components/chunks/{icon-BcsWL4kZ.js → icon-B_7c8b8e.js} +1 -1
- package/dist/components/chunks/icon-CSqBgTae.js +1 -0
- package/dist/components/chunks/{input-BzrCXBg4.js → input-Dwrs8tJH.js} +4 -4
- package/dist/components/chunks/{input-DnVgj6QV.js → input-lLl8cB6r.js} +1 -1
- package/dist/components/chunks/{modal-9S-FF3_o.js → modal-CNBmdA63.js} +1 -1
- package/dist/components/chunks/{modal-D7KKb4f9.js → modal-CPcIPIO7.js} +2 -2
- package/dist/components/chunks/search-Bsaoxa30.js +1 -0
- package/dist/components/chunks/{search-Dd28O4mG.js → search-xHKqAXph.js} +1 -1
- package/dist/components/confirm-action/browser.js +2 -2
- package/dist/components/confirm-action/index.cjs +1 -1
- package/dist/components/confirm-action/index.js +2 -2
- package/dist/components/date-picker/browser.js +4 -4
- package/dist/components/date-picker/index.cjs +1 -1
- package/dist/components/date-picker/index.js +4 -4
- package/dist/components/dropzone/browser.js +3 -3
- package/dist/components/dropzone/index.cjs +1 -1
- package/dist/components/dropzone/index.js +3 -3
- package/dist/components/icon/browser.js +1 -1
- package/dist/components/icon/index.cjs +1 -1
- package/dist/components/icon/index.js +1 -1
- package/dist/components/input/browser.js +1 -1
- package/dist/components/input/index.cjs +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/modal/browser.js +1 -1
- package/dist/components/modal/index.cjs +1 -1
- package/dist/components/modal/index.js +1 -1
- package/dist/components/navigation/browser.js +2 -2
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/off-canvas/browser.js +2 -2
- package/dist/components/off-canvas/index.cjs +1 -1
- package/dist/components/off-canvas/index.js +2 -2
- package/dist/components/resource-table/browser.js +7 -7
- package/dist/components/resource-table/index.cjs +1 -1
- package/dist/components/resource-table/index.js +7 -7
- package/dist/components/search/browser.js +7 -7
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +7 -7
- package/dist/components/select/browser.js +4 -4
- package/dist/components/select/index.cjs +1 -1
- package/dist/components/select/index.js +4 -4
- package/dist/components/side-navigation/browser.js +4 -4
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +4 -4
- package/dist/components/switch/browser.js +2 -2
- package/dist/components/switch/index.cjs +1 -1
- package/dist/components/switch/index.js +2 -2
- package/dist/components/tags/browser.js +3 -3
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +3 -3
- package/dist/components/time-picker/browser.js +2 -2
- package/dist/components/time-picker/index.cjs +1 -1
- package/dist/components/time-picker/index.js +2 -2
- package/dist/icons/pin.svg +1 -3
- package/dist/index.cjs +4 -4
- package/dist/index.css +1 -1
- package/dist/index.js +115 -103
- package/dist/input.css +1 -1
- package/package.json +1 -1
- package/dist/components/chunks/caret-down-C5a1fGvt.js +0 -1
- package/dist/components/chunks/caret-right-BMyWflHN.js +0 -1
- package/dist/components/chunks/caret-up-BJAyfrty.js +0 -1
- package/dist/components/chunks/close-Bg0kqvrY.js +0 -1
- package/dist/components/chunks/icon-DNWs0suS.js +0 -1
- package/dist/components/chunks/icon-uMo_iGkX.js +0 -1
- package/dist/components/chunks/search-C5jD2OC-.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`../chunks/register-element-tCL_F1YI.js`);var t=class e extends HTMLElement{static get observedAttributes(){return[`type`,`data`,`width`,`height`,`show-legend`,`show-grid`,`show-tooltip`,`curve-tension`]}static{this.MAX_CACHE_SIZE=100}constructor(){super(),this._chartContainer=null,this._svg=null,this._tooltip=null,this._chartType=`line`,this._chartData=null,this._width=800,this._height=400,this._padding={top:20,right:20,bottom:60,left:60},this._showLegend=!0,this._showGrid=!0,this._showTooltip=!0,this._curveTension=.5,this._dataObserver=null,this._darkModeObserver=null,this._tooltipHideTimeout=null,this._lastTooltipContent=``,this._activeXValue=null,this._pinnedXValue=null,this._tooltipAnimationFrame=null,this._cachedTooltipContent=new Map,this._cachedXPositions=new Map,this._verticalLine=null,this._plotPoints=new Map,this._resizeObserver=null,this._windowResizeHandler=null,this._pieChartTimeouts=new Set,this._pieChartTooltipShown=!1,this._pieChartClickOutsideHandler=null,this._pieChartGroup=null,this._chartClickOutsideHandler=null,this._chartTooltipScrollHandler=null,this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``},this._renderScheduled=!1,this._animateNextRender=!1,this._observedDataReference=null,this._observedDataFingerprint=``,this._datasetVisibility=new Map,this._widthValue=`100%`,this._heightValue=400,this._defaultColors=[`#2563eb`,`#3b82f6`,`#0d9488`,`#7c3aed`,`#d97706`,`#059669`,`#dc2626`,`#c026d3`],this._legendHeight=0,this._rotatedLabelHeight=0}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`),this._setupDataObserver(),this._setupDarkModeObserver(),this._setupResizeObserver(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.render()})})}_setupDataObserver(){let e=()=>{if(!this.isConnected)return;let e=this.data,t=null;e&&typeof e==`object`&&!Array.isArray(e)&&`datasets`in e&&(t=e);let n=``;if(t)try{n=JSON.stringify(t)}catch{n=``}t&&(t!==this._observedDataReference||n&&n!==this._observedDataFingerprint)&&(this._observedDataReference=t,this._observedDataFingerprint=n,this._chartData=t,this._animateNextRender=!0,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this.render())};requestAnimationFrame(()=>{e(),requestAnimationFrame(()=>{e()})});let t=setInterval(()=>{if(!this.isConnected){clearInterval(t);return}e()},250);this._dataCheckInterval=t}_setupDarkModeObserver(){this._darkModeObserver=new MutationObserver(()=>{this.isConnected&&this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]})}disconnectedCallback(){if(this._tooltip&&this._tooltip.parentNode&&(this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=null),this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._pieChartTimeouts.forEach(e=>clearTimeout(e)),this._pieChartTimeouts.clear(),this._pieChartClickOutsideHandler&&=(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),null),this._chartClickOutsideHandler&&=(document.removeEventListener(`click`,this._chartClickOutsideHandler,!0),null),this._pieChartTooltipShown=!1,this._pieChartGroup=null,this._pinnedXValue=null,this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._dataObserver&&=(this._dataObserver.disconnect(),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null),this._dataCheckInterval&&=(clearInterval(this._dataCheckInterval),null),this._svg&&(this._chartTooltipMouseMove&&=(this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),null),this._chartTooltipMouseLeave&&=(this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),null),this._chartTooltipTouchStart&&=(this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),null),this._chartTooltipTouchMove&&=(this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),null),this._chartTooltipTouchEnd&&=(this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),null)),this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement;this._chartTooltipScrollHandler=null}this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null),this._cachedTooltipContent.clear(),this._cachedXPositions.clear(),this._plotPoints.clear(),this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``}}_handleResize(){if(!this.isConnected)return;let e=this.getBoundingClientRect(),t=e.width||this.parentElement?.clientWidth||800,n=e.height||this.parentElement?.clientHeight||400,r=this._calculateDimension(this._widthValue,t,t),i=this._calculateDimension(this._heightValue,n,400);(r!==this._width||i!==this._height)&&(this._width=r,this._height=i,this.render())}_setupResizeObserver(){this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null);let e=null,t=()=>{e&&clearTimeout(e),e=window.setTimeout(()=>{this._handleResize()},100)};this._windowResizeHandler=t,this._resizeObserver=new ResizeObserver(()=>{t()}),this._resizeObserver.observe(this),window.addEventListener(`resize`,t)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`data`){if(n)try{this._chartData=JSON.parse(n)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}else this._chartData=null;this._invalidateDataCaches(),this._animateNextRender=!0}(e===`width`||e===`height`)&&this.isConnected&&(t&&t.endsWith(`%`))!==(n&&n.endsWith(`%`))&&this._setupResizeObserver(),this.isConnected&&requestAnimationFrame(()=>{this.render()})}}get type(){let e=this.getAttribute(`type`)||`line`;return e===`line`||e===`bar`||e===`area`||e===`pie`?e:`line`}set type(e){this.setAttribute(`type`,e)}get data(){return this._chartData}set data(e){if(typeof e==`string`)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}else this._chartData=e;this._invalidateDataCaches(),this._animateNextRender=!0,this.isConnected&&requestAnimationFrame(()=>{this.render()})}get width(){let e=this.getAttribute(`width`);if(!e)return this._widthValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._widthValue:t}set width(e){this.setAttribute(`width`,e.toString())}get height(){let e=this.getAttribute(`height`);if(!e)return this._heightValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._heightValue:t}set height(e){this.setAttribute(`height`,e.toString())}_calculateDimension(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!isNaN(n))return t*n/100}return n}_scheduleRender(){this._animateNextRender=!0,this._syncObservedData(),!this._renderScheduled&&(this._renderScheduled=!0,requestAnimationFrame(()=>{this._renderScheduled=!1,this.render()}))}_invalidateDataCaches(){this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent?.clear()}_syncObservedData(){this._observedDataReference=this._chartData;try{this._observedDataFingerprint=this._chartData?JSON.stringify(this._chartData):``}catch{this._observedDataFingerprint=``}}_isDatasetVisible(e,t){if(e.id){let t=this._datasetVisibility.get(e.id);if(t!==void 0)return t}return e.visible!==!1}_initializeDatasetVisibility(){this._chartData&&this._chartData.datasets.forEach((e,t)=>{e.id&&(this._datasetVisibility.has(e.id)||this._datasetVisibility.set(e.id,e.visible!==!1))})}render(){if(!this.isConnected)return;let e=this._animateNextRender&&!window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches&&this._svg?this._svg.cloneNode(!0):null;this._animateNextRender=!1,this._plotPoints.clear(),this._activeXValue=null,this._cachedTooltipContent?.clear(),this._cachedXPositions?.clear(),this._chartType=this.type;let t=this.data;if(t&&typeof t==`object`&&!Array.isArray(t)&&`datasets`in t&&(this._chartData=t),!this._chartData){let e=this.getAttribute(`data`);if(e)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}}this._widthValue=this.width,this._heightValue=this.height;let n=this.getBoundingClientRect(),r=n.width||this.parentElement?.clientWidth||800,i=n.height||this.parentElement?.clientHeight||400;this._width=this._calculateDimension(this._widthValue,r,r),this._height=this._calculateDimension(this._heightValue,i,400),this._showLegend=this.getAttribute(`show-legend`)!==`false`,this._showGrid=this.getAttribute(`show-grid`)!==`false`,this._showTooltip=this.getAttribute(`show-tooltip`)!==`false`;let a=this.getAttribute(`curve-tension`);if(a!==null){let e=parseFloat(a);this._curveTension=isNaN(e)?.5:Math.max(0,Math.min(1,e))}else this._curveTension=.5;if(!this._chartData||!this._chartData.datasets||this._chartData.datasets.length===0){this.innerHTML=`<div class="p-4 text-gray-500">No chart data provided</div>`;return}this.innerHTML=``,this._chartContainer=document.createElement(`div`),this._chartContainer.className=`relative w-full`,this._chartContainer.style.position=`relative`,typeof this._widthValue==`string`&&this._widthValue.endsWith(`%`)?this._chartContainer.style.width=this._widthValue:this._chartContainer.style.width=`${this._width}px`,typeof this._heightValue==`string`&&this._heightValue.endsWith(`%`)?this._chartContainer.style.height=this._heightValue:this._chartContainer.style.height=`${this._height}px`,this.appendChild(this._chartContainer),this._svg=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this._svg.setAttribute(`width`,this._width.toString()),this._svg.setAttribute(`height`,this._height.toString()),this._svg.setAttribute(`viewBox`,`0 0 ${this._width} ${this._height}`),this._svg.setAttribute(`class`,`w-full h-full`),this._svg.setAttribute(`role`,`img`);let o=this._chartData.datasets.map(e=>e.name).filter(Boolean),s=this.getAttribute(`aria-label`)?.trim()||`${this.type} chart${o.length?` showing ${o.join(`, `)}`:``}. ${Math.max(0,...this._chartData.datasets.map(e=>e.data.length))} data points.`,c=`${this.id||`mint-chart-${Math.random().toString(36).slice(2,10)}`}-data`;this._svg.setAttribute(`aria-label`,s),this._svg.setAttribute(`aria-describedby`,c),this._chartContainer&&this._svg&&(e&&(e.style.position=`absolute`,e.style.inset=`0`,e.style.width=`100%`,e.style.height=`100%`,e.style.pointerEvents=`none`,e.style.zIndex=`1`,e.style.opacity=`1`,e.style.transition=`opacity 260ms ease`,this._chartContainer.appendChild(e),this._svg.style.position=`relative`,this._svg.style.zIndex=`0`,this._svg.style.opacity=`0`,this._svg.style.transition=`opacity 260ms ease`),this._chartContainer.appendChild(this._svg));let l=document.createElement(`table`);l.id=c,Object.assign(l.style,{position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,top:`0`,left:`0`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:`0`});let u=document.createElement(`caption`);u.textContent=`Data for ${s}`,l.appendChild(u);let d=document.createElement(`thead`),f=document.createElement(`tr`),p=document.createElement(`th`);p.scope=`col`,p.textContent=`Category`,f.appendChild(p),this._chartData.datasets.forEach(e=>{let t=document.createElement(`th`);t.scope=`col`,t.textContent=e.name||`Series`,f.appendChild(t)}),d.appendChild(f),l.appendChild(d);let m=document.createElement(`tbody`),h=Math.max(0,...this._chartData.datasets.map(e=>e.data.length));for(let e=0;e<h;e+=1){let t=document.createElement(`tr`),n=document.createElement(`th`);n.scope=`row`,n.textContent=String(this._chartData.datasets.find(t=>t.data[e])?.data[e]?.x??e+1),t.appendChild(n),this._chartData.datasets.forEach(n=>{let r=document.createElement(`td`),i=n.data[e];r.textContent=i?this._formatValue(i.y,n):``,t.appendChild(r)}),m.appendChild(t)}switch(l.appendChild(m),this.appendChild(l),this._showTooltip&&this._createTooltip(),this._initializeDatasetVisibility(),this._calculateRotatedLabelHeight(),this._showLegend?this._legendHeight=this._calculateLegendHeight():this._legendHeight=0,this._showLegend&&this._renderLegend(),this._chartType!==`pie`&&this._pieChartClickOutsideHandler&&(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),this._pieChartClickOutsideHandler=null,this._pieChartTooltipShown=!1,this._pieChartGroup=null),this._pinnedXValue=null,this._chartType){case`line`:this._renderLineChart();break;case`bar`:this._renderBarChart();break;case`area`:this._renderAreaChart();break;case`pie`:this._renderPieChart();break}if(this._showTooltip&&this._chartType!==`pie`&&(this._setupChartTooltip(),this._setupTooltipScrollHandler()),this._createVerticalLine(),e&&this._svg){let t=this._svg;requestAnimationFrame(()=>requestAnimationFrame(()=>{t.isConnected&&(e.style.opacity=`0`,t.style.opacity=`1`,window.setTimeout(()=>e.remove(),280))}))}}_createTooltip(){this._tooltip&&this._tooltip.parentNode&&this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=document.createElement(`div`),this._tooltip.className=`fixed pointer-events-none z-50 bg-gray-900 dark:bg-mint-elevated text-white text-xs rounded px-2 py-1 shadow-lg opacity-0`,this._tooltip.style.display=`none`,document.body.appendChild(this._tooltip)}_showTooltipAt(e,t,n){if(!this._tooltip)return;this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._lastTooltipContent!==n&&(this._tooltip.innerHTML=n,this._lastTooltipContent=n),(this._tooltip.style.display===`none`||this._tooltip.style.opacity===`0`)&&(this._tooltip.style.display=`block`,this._tooltip.style.opacity=`1`,this._tooltip.style.padding=`8px 12px`);let r=this._tooltip.getBoundingClientRect(),i=window.innerWidth,a=window.innerHeight,o=e+10,s=t-r.height-8;o+r.width>i&&(o=e-r.width-10),o<0&&(o=10),s<0&&(s=t+20),s+r.height>a&&(s=t-r.height-8,s<0&&(s=10));let c=`${o}px`,l=`${s}px`;this._tooltip.style.left!==c&&(this._tooltip.style.left=c),this._tooltip.style.top!==l&&(this._tooltip.style.top=l)}_hideTooltip(){this._tooltip&&(this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._tooltip.style.opacity=`0`,this._tooltipHideTimeout=window.setTimeout(()=>{this._tooltip&&(this._tooltip.style.display=`none`),this._tooltipHideTimeout=null},200))}_createVerticalLine(){if(!this._svg)return;this._verticalLine&&this._verticalLine.parentNode&&this._verticalLine.parentNode.removeChild(this._verticalLine),this._verticalLine=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);let e=document.documentElement.classList.contains(`dark`);this._verticalLine.setAttribute(`stroke`,e?`#9ca3af`:`#6b7280`),this._verticalLine.setAttribute(`stroke-width`,`1`),this._verticalLine.setAttribute(`stroke-dasharray`,`4,2`),this._verticalLine.style.opacity=`0`,this._verticalLine.style.pointerEvents=`none`;let t=this._svg.querySelector(`.chart-legend`);t&&t.parentNode?t.parentNode.insertBefore(this._verticalLine,t):this._svg.appendChild(this._verticalLine)}_showVerticalLineAtX(e,t){if(!this._verticalLine)return;let n=this._chartType===`bar`?this._scaleXForBarChart(e,t):this._scaleX(e,t);this._verticalLine.setAttribute(`x1`,n.toString()),this._verticalLine.setAttribute(`y1`,t.y.toString()),this._verticalLine.setAttribute(`x2`,n.toString()),this._verticalLine.setAttribute(`y2`,(t.y+t.height).toString()),this._verticalLine.style.opacity=`1`}_hideVerticalLine(){this._verticalLine&&(this._verticalLine.style.opacity=`0`)}_showPlotPointsForX(e){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})});let t=String(e),n=this._plotPoints.get(t);n&&n.forEach(e=>{e.style.opacity=`1`})}_hidePlotPoints(){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})})}_calculateMaxYAxisLabelWidth(){if(!this._showGrid||!this._chartData)return 0;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return 60;e.font=`12px system-ui, -apple-system, sans-serif`;let t=this._showLegend?Math.max(this._legendHeight,60):0,n=this._height-t,r=Math.floor(n/35),i=Math.min(5,r),a=0;for(let t=0;t<=i;t++){let n=this._getYRange(),r=n.max-(n.max-n.min)/i*t,o=this._formatYAxisValue(r),s=e.measureText(o);a=Math.max(a,s.width)}return Math.ceil(a)+20}_getChartBounds(){let e=this._calculateMaxYAxisLabelWidth(),t=`${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${e}-${this._rotatedLabelHeight}`;if(this._cachedBounds.bounds&&this._cachedBounds.dataHash===t)return this._cachedBounds.bounds;let n=0,r=0;this._showGrid&&(n=e+10);let i=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,a=i;this._showLegend&&(a=i+20+Math.max(this._legendHeight,60));let o=this._height-0-n-0,s=o-a,c=1;if(s<100&&a>0){let e=o-100;e>0?(c=Math.min(1,e/a),c=Math.max(.5,c)):c=.5}r=a*c;let l=this._width*.3,u=n,d=1;n>l&&(d=l/n,u=l);let f={width:(this._width-u-0)*d,height:this._height-0-r,x:u,y:0};return this._cachedBounds={bounds:f,dataHash:t},f}_getAllDataPoints(){if(!this._chartData)return[];let e=[];return this._chartData.datasets.forEach((t,n)=>{this._isDatasetVisible(t,n)&&e.push(...t.data)}),e}_getXValues(){if(!this._chartData)return[];let e=JSON.stringify(this._chartData.labels)+JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.x)));if(this._cachedXValues.values&&this._cachedXValues.dataHash===e)return this._cachedXValues.values;if(this._chartData.labels&&this._chartData.labels.length>0)return this._cachedXValues={values:this._chartData.labels,dataHash:e},this._chartData.labels;let t=new Set;this._chartData.datasets.forEach((e,n)=>{this._isDatasetVisible(e,n)&&e.data.forEach(e=>{t.add(e.x)})});let n=Array.from(t).sort((e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;let n=String(e),r=String(t),i=/^([A-Za-z]{3})\s+(\d{4})$/,a=n.match(i),o=r.match(i);if(a&&o){let e=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],t=e.indexOf(a[1]),n=e.indexOf(o[1]),r=parseInt(a[2]),i=parseInt(o[2]);return r===i?t-n:r-i}return n.localeCompare(r)});return this._cachedXValues={values:n,dataHash:e},n}_getYRange(){if(!this._chartData)return{min:0,max:100};let e=JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.y)));if(this._cachedYRange.range&&this._cachedYRange.dataHash===e)return this._cachedYRange.range;let t=this._getAllDataPoints();if(t.length===0){let t={min:0,max:100};return this._cachedYRange={range:t,dataHash:e},t}let n=t.map(e=>e.y),r=Math.min(...n),i=Math.max(...n),a=(i-r)*.1,o={min:Math.max(0,r-a),max:i+a};return this._cachedYRange={range:o,dataHash:e},o}_hasDecimalValues(){return this._getAllDataPoints().some(e=>e.y%1!=0)}_formatValueByString(e,t){switch(t.toLowerCase()){case`currency`:case`currency-usd`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`}).format(e);case`currency-eur`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`EUR`}).format(e);case`currency-gbp`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`GBP`}).format(e);case`number`:case`number-with-commas`:return new Intl.NumberFormat(`en-US`).format(e);case`percent`:return new Intl.NumberFormat(`en-US`,{style:`percent`,minimumFractionDigits:1}).format(e/100);default:return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}}_formatXAxisValue(e){if(this._chartData?.formatXAxis){if(typeof this._chartData.formatXAxis==`function`)return this._chartData.formatXAxis(e);if(typeof this._chartData.formatXAxis==`string`)return String(e)}return String(e)}_escapeHtmlForTooltip(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}_tooltipXHeadingHtml(e){return`<strong>${this._escapeHtmlForTooltip(this._formatXAxisValue(e))}</strong><br/>`}_formatYAxisValue(e){if(this._chartData?.formatYAxis){if(typeof this._chartData.formatYAxis==`function`)return this._chartData.formatYAxis(e);if(typeof this._chartData.formatYAxis==`string`)return this._formatValueByString(e,this._chartData.formatYAxis)}if(this._chartData?.datasets?.[0]?.formatValue){if(typeof this._chartData.datasets[0].formatValue==`function`)return this._chartData.datasets[0].formatValue(e);if(typeof this._chartData.datasets[0].formatValue==`string`)return this._formatValueByString(e,this._chartData.datasets[0].formatValue)}return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}_formatValue(e,t){if(t.formatValue){if(typeof t.formatValue==`function`)return t.formatValue(e);if(typeof t.formatValue==`string`)return this._formatValueByString(e,t.formatValue)}return String(e)}_getAllDatasetsAtX(e){if(!this._chartData)return[];let t=[];return this._chartData.datasets.forEach((n,r)=>{if(!this._isDatasetVisible(n,r))return;let i=n.data.find(t=>String(t.x)===String(e));if(i){let e=this._getDatasetColor(n,r),a=this._formatValue(i.y,n);t.push({name:n.name,value:i.y,color:e,formattedValue:a})}}),t}_findNearestXValue(e){if(!this._chartData)return null;let t=this._getChartBounds(),n=this._getXValues();if(n.length===0)return null;let r=this._chartType===`bar`,i=null,a=1/0;return n.forEach(n=>{let o=r?this._scaleXForBarChart(n,t):this._scaleX(n,t),s=Math.abs(e-o);s<a&&(a=s,i=n)}),i}_setupTooltipScrollHandler(){if(this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}this._chartTooltipScrollHandler=()=>{this._hideTooltip(),this._pinnedXValue=null},window.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;){let t=window.getComputedStyle(e),n=t.overflow,r=t.overflowY;(n===`auto`||n===`scroll`||r===`auto`||r===`scroll`)&&e.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}}_setupChartTooltip(){if(!this._svg||!this._showTooltip)return;this._chartTooltipMouseMove&&this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),this._chartTooltipMouseLeave&&this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),this._chartTooltipClick&&this._svg.removeEventListener(`click`,this._chartTooltipClick),this._chartTooltipTouchStart&&this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),this._chartTooltipTouchMove&&this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),this._chartTooltipTouchEnd&&this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),this._cachedTooltipContent.clear(),this._cachedXPositions.clear();let t=this._getChartBounds(),n=0,r=0,i=i=>{!this._chartContainer||!this._svg||(n=i.clientX,r=i.clientY,this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;let i=this._svg.getBoundingClientRect(),a=n-i.left,o=r-i.top;if(a<t.x||a>t.x+t.width||o<t.y||o>t.y+t.height){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}let s=this._findNearestXValue(a);if(!s){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}if(this._pinnedXValue!==null&&this._pinnedXValue===s){let e=this._pinnedXValue,i=this._getAllDatasetsAtX(e);if(i.length>0){this._activeXValue=e,this._showPlotPointsForX(e),this._showVerticalLineAtX(e,t);let a=this._cachedTooltipContent.get(e);a||(a=this._tooltipXHeadingHtml(e),i.forEach(e=>{a+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
1
|
+
const e=require(`../chunks/register-element-tCL_F1YI.js`);var t=class e extends HTMLElement{static get observedAttributes(){return[`type`,`data`,`width`,`height`,`show-legend`,`show-grid`,`show-tooltip`,`curve-tension`]}static{this.MAX_CACHE_SIZE=100}constructor(){super(),this._chartContainer=null,this._svg=null,this._tooltip=null,this._chartType=`line`,this._chartData=null,this._width=800,this._height=400,this._padding={top:20,right:20,bottom:60,left:60},this._showLegend=!0,this._showGrid=!0,this._showTooltip=!0,this._curveTension=.5,this._dataObserver=null,this._darkModeObserver=null,this._tooltipHideTimeout=null,this._lastTooltipContent=``,this._activeXValue=null,this._pinnedXValue=null,this._tooltipAnimationFrame=null,this._cachedTooltipContent=new Map,this._cachedXPositions=new Map,this._verticalLine=null,this._plotPoints=new Map,this._resizeObserver=null,this._windowResizeHandler=null,this._pieChartTimeouts=new Set,this._pieChartTooltipShown=!1,this._pieChartClickOutsideHandler=null,this._pieChartGroup=null,this._chartClickOutsideHandler=null,this._chartTooltipScrollHandler=null,this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``},this._renderScheduled=!1,this._animateNextRender=!1,this._observedDataReference=null,this._observedDataFingerprint=``,this._datasetVisibility=new Map,this._widthValue=`100%`,this._heightValue=400,this._defaultColors=[`#2563eb`,`#3b82f6`,`#0d9488`,`#7c3aed`,`#d97706`,`#059669`,`#dc2626`,`#c026d3`],this._legendHeight=0,this._rotatedLabelHeight=0}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`),this._setupDataObserver(),this._setupDarkModeObserver(),this._setupResizeObserver(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.render()})})}_setupDataObserver(){let e=()=>{if(!this.isConnected)return;let e=this.data,t=null;e&&typeof e==`object`&&!Array.isArray(e)&&`datasets`in e&&(t=e);let n=``;if(t)try{n=JSON.stringify(t)}catch{n=``}t&&(t!==this._observedDataReference||n&&n!==this._observedDataFingerprint)&&(this._observedDataReference=t,this._observedDataFingerprint=n,this._chartData=t,this._animateNextRender=!0,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this.render())};requestAnimationFrame(()=>{e(),requestAnimationFrame(()=>{e()})});let t=setInterval(()=>{if(!this.isConnected){clearInterval(t);return}e()},250);this._dataCheckInterval=t}_setupDarkModeObserver(){this._darkModeObserver=new MutationObserver(()=>{this.isConnected&&this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]})}disconnectedCallback(){if(this._tooltip&&this._tooltip.parentNode&&(this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=null),this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._pieChartTimeouts.forEach(e=>clearTimeout(e)),this._pieChartTimeouts.clear(),this._pieChartClickOutsideHandler&&=(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),null),this._chartClickOutsideHandler&&=(document.removeEventListener(`click`,this._chartClickOutsideHandler,!0),null),this._pieChartTooltipShown=!1,this._pieChartGroup=null,this._pinnedXValue=null,this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._dataObserver&&=(this._dataObserver.disconnect(),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null),this._dataCheckInterval&&=(clearInterval(this._dataCheckInterval),null),this._svg&&(this._chartTooltipMouseMove&&=(this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),null),this._chartTooltipMouseLeave&&=(this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),null),this._chartTooltipTouchStart&&=(this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),null),this._chartTooltipTouchMove&&=(this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),null),this._chartTooltipTouchEnd&&=(this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),null)),this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement;this._chartTooltipScrollHandler=null}this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null),this._cachedTooltipContent.clear(),this._cachedXPositions.clear(),this._plotPoints.clear(),this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``}}_handleResize(){if(!this.isConnected)return;let e=this.getBoundingClientRect(),t=e.width||this.parentElement?.clientWidth||800,n=e.height||this.parentElement?.clientHeight||400,r=this._calculateDimension(this._widthValue,t,t),i=this._calculateDimension(this._heightValue,n,400);(r!==this._width||i!==this._height)&&(this._width=r,this._height=i,this.render())}_setupResizeObserver(){this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null);let e=null,t=()=>{e&&clearTimeout(e),e=window.setTimeout(()=>{this._handleResize()},100)};this._windowResizeHandler=t,this._resizeObserver=new ResizeObserver(()=>{t()}),this._resizeObserver.observe(this),window.addEventListener(`resize`,t)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`data`){if(n)try{this._chartData=JSON.parse(n)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}else this._chartData=null;this._invalidateDataCaches(),this._animateNextRender=!0}(e===`width`||e===`height`)&&this.isConnected&&(t&&t.endsWith(`%`))!==(n&&n.endsWith(`%`))&&this._setupResizeObserver(),this.isConnected&&requestAnimationFrame(()=>{this.render()})}}get type(){let e=this.getAttribute(`type`)||`line`;return e===`line`||e===`bar`||e===`area`||e===`pie`?e:`line`}set type(e){this.setAttribute(`type`,e)}get data(){return this._chartData}set data(e){if(typeof e==`string`)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}else this._chartData=e;this._invalidateDataCaches(),this._animateNextRender=!0,this.isConnected&&requestAnimationFrame(()=>{this.render()})}get width(){let e=this.getAttribute(`width`);if(!e)return this._widthValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._widthValue:t}set width(e){this.setAttribute(`width`,e.toString())}get height(){let e=this.getAttribute(`height`);if(!e)return this._heightValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._heightValue:t}set height(e){this.setAttribute(`height`,e.toString())}_calculateDimension(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!isNaN(n))return t*n/100}return n}_scheduleRender(){this._animateNextRender=!0,this._syncObservedData(),!this._renderScheduled&&(this._renderScheduled=!0,requestAnimationFrame(()=>{this._renderScheduled=!1,this.render()}))}_invalidateDataCaches(){this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent?.clear()}_syncObservedData(){this._observedDataReference=this._chartData;try{this._observedDataFingerprint=this._chartData?JSON.stringify(this._chartData):``}catch{this._observedDataFingerprint=``}}_isDatasetVisible(e,t){if(e.id){let t=this._datasetVisibility.get(e.id);if(t!==void 0)return t}return e.visible!==!1}_initializeDatasetVisibility(){this._chartData&&this._chartData.datasets.forEach((e,t)=>{e.id&&(this._datasetVisibility.has(e.id)||this._datasetVisibility.set(e.id,e.visible!==!1))})}render(){if(!this.isConnected)return;let e=this._animateNextRender&&!window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches&&this._svg?this._svg.cloneNode(!0):null;this._animateNextRender=!1,this._plotPoints.clear(),this._activeXValue=null,this._cachedTooltipContent?.clear(),this._cachedXPositions?.clear(),this._chartType=this.type;let t=this.data;if(t&&typeof t==`object`&&!Array.isArray(t)&&`datasets`in t&&(this._chartData=t),!this._chartData){let e=this.getAttribute(`data`);if(e)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}}this._widthValue=this.width,this._heightValue=this.height;let n=this.getBoundingClientRect(),r=n.width||this.parentElement?.clientWidth||800,i=n.height||this.parentElement?.clientHeight||400;this._width=this._calculateDimension(this._widthValue,r,r),this._height=this._calculateDimension(this._heightValue,i,400),this._showLegend=this.getAttribute(`show-legend`)!==`false`,this._showGrid=this.getAttribute(`show-grid`)!==`false`,this._showTooltip=this.getAttribute(`show-tooltip`)!==`false`;let a=this.getAttribute(`curve-tension`);if(a!==null){let e=parseFloat(a);this._curveTension=isNaN(e)?.5:Math.max(0,Math.min(1,e))}else this._curveTension=.5;if(!this._chartData||!this._chartData.datasets||this._chartData.datasets.length===0){this.innerHTML=`<div class="p-4 text-gray-500">No chart data provided</div>`;return}this.innerHTML=``,this._chartContainer=document.createElement(`div`),this._chartContainer.className=`relative w-full`,this._chartContainer.style.position=`relative`,typeof this._widthValue==`string`&&this._widthValue.endsWith(`%`)?this._chartContainer.style.width=this._widthValue:this._chartContainer.style.width=`${this._width}px`,typeof this._heightValue==`string`&&this._heightValue.endsWith(`%`)?this._chartContainer.style.height=this._heightValue:this._chartContainer.style.height=`${this._height}px`,this.appendChild(this._chartContainer),this._svg=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this._svg.setAttribute(`width`,this._width.toString()),this._svg.setAttribute(`height`,this._height.toString()),this._svg.setAttribute(`viewBox`,`0 0 ${this._width} ${this._height}`),this._svg.setAttribute(`class`,`w-full h-full`),this._svg.setAttribute(`role`,`img`);let o=this._chartData.datasets.map(e=>e.name).filter(Boolean),s=this.getAttribute(`aria-label`)?.trim()||`${this.type} chart${o.length?` showing ${o.join(`, `)}`:``}. ${Math.max(0,...this._chartData.datasets.map(e=>e.data.length))} data points.`,c=`${this.id||`mint-chart-${Math.random().toString(36).slice(2,10)}`}-data`;this._svg.setAttribute(`aria-label`,s),this._svg.setAttribute(`aria-describedby`,c),this._chartContainer&&this._svg&&(e&&(e.style.position=`absolute`,e.style.inset=`0`,e.style.width=`100%`,e.style.height=`100%`,e.style.pointerEvents=`none`,e.style.zIndex=`1`,e.style.opacity=`1`,e.style.transition=`opacity 260ms ease`,this._chartContainer.appendChild(e),this._svg.style.position=`relative`,this._svg.style.zIndex=`0`,this._svg.style.opacity=`0`,this._svg.style.transition=`opacity 260ms ease`),this._chartContainer.appendChild(this._svg));let l=document.createElement(`table`);l.id=c,Object.assign(l.style,{position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,top:`0`,left:`0`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,border:`0`});let u=document.createElement(`caption`);u.textContent=`Data for ${s}`,l.appendChild(u);let d=document.createElement(`thead`),f=document.createElement(`tr`),p=document.createElement(`th`);p.scope=`col`,p.textContent=`Category`,f.appendChild(p),this._chartData.datasets.forEach(e=>{let t=document.createElement(`th`);t.scope=`col`,t.textContent=e.name||`Series`,f.appendChild(t)}),d.appendChild(f),l.appendChild(d);let m=document.createElement(`tbody`),h=Math.max(0,...this._chartData.datasets.map(e=>e.data.length));for(let e=0;e<h;e+=1){let t=document.createElement(`tr`),n=document.createElement(`th`);n.scope=`row`,n.textContent=String(this._chartData.datasets.find(t=>t.data[e])?.data[e]?.x??e+1),t.appendChild(n),this._chartData.datasets.forEach(n=>{let r=document.createElement(`td`),i=n.data[e];r.textContent=i?this._formatValue(i.y,n):``,t.appendChild(r)}),m.appendChild(t)}switch(l.appendChild(m),this.appendChild(l),this._showTooltip&&this._createTooltip(),this._initializeDatasetVisibility(),this._calculateRotatedLabelHeight(),this._showLegend?this._legendHeight=this._calculateLegendHeight():this._legendHeight=0,this._showLegend&&this._renderLegend(),this._chartType!==`pie`&&this._pieChartClickOutsideHandler&&(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),this._pieChartClickOutsideHandler=null,this._pieChartTooltipShown=!1,this._pieChartGroup=null),this._pinnedXValue=null,this._chartType){case`line`:this._renderLineChart();break;case`bar`:this._renderBarChart();break;case`area`:this._renderAreaChart();break;case`pie`:this._renderPieChart();break}if(this._showTooltip&&this._chartType!==`pie`&&(this._setupChartTooltip(),this._setupTooltipScrollHandler()),this._createVerticalLine(),e&&this._svg){let t=this._svg;requestAnimationFrame(()=>requestAnimationFrame(()=>{t.isConnected&&(e.style.opacity=`0`,t.style.opacity=`1`,window.setTimeout(()=>e.remove(),280))}))}}_createTooltip(){this._tooltip&&this._tooltip.parentNode&&this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=document.createElement(`div`),this._tooltip.className=`fixed pointer-events-none z-50 bg-gray-900 dark:bg-mint-elevated text-white text-xs rounded px-2 py-1 shadow-lg opacity-0`,this._tooltip.style.display=`none`,document.body.appendChild(this._tooltip)}_showTooltipAt(e,t,n){if(!this._tooltip)return;this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._lastTooltipContent!==n&&(this._tooltip.innerHTML=n,this._lastTooltipContent=n),(this._tooltip.style.display===`none`||this._tooltip.style.opacity===`0`)&&(this._tooltip.style.display=`block`,this._tooltip.style.opacity=`1`,this._tooltip.style.padding=`8px 12px`);let r=this._tooltip.getBoundingClientRect(),i=window.innerWidth,a=window.innerHeight,o=e+10,s=t-r.height-8;o+r.width>i&&(o=e-r.width-10),o<0&&(o=10),s<0&&(s=t+20),s+r.height>a&&(s=t-r.height-8,s<0&&(s=10));let c=`${o}px`,l=`${s}px`;this._tooltip.style.left!==c&&(this._tooltip.style.left=c),this._tooltip.style.top!==l&&(this._tooltip.style.top=l)}_hideTooltip(){this._tooltip&&(this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._tooltip.style.opacity=`0`,this._tooltipHideTimeout=window.setTimeout(()=>{this._tooltip&&(this._tooltip.style.display=`none`),this._tooltipHideTimeout=null},200))}_createVerticalLine(){if(!this._svg)return;this._verticalLine&&this._verticalLine.parentNode&&this._verticalLine.parentNode.removeChild(this._verticalLine),this._verticalLine=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);let e=document.documentElement.classList.contains(`dark`);this._verticalLine.setAttribute(`stroke`,e?`#9ca3af`:`#6b7280`),this._verticalLine.setAttribute(`stroke-width`,`1`),this._verticalLine.setAttribute(`stroke-dasharray`,`4,2`),this._verticalLine.style.opacity=`0`,this._verticalLine.style.pointerEvents=`none`;let t=this._svg.querySelector(`.chart-legend`);t&&t.parentNode?t.parentNode.insertBefore(this._verticalLine,t):this._svg.appendChild(this._verticalLine)}_showVerticalLineAtX(e,t){if(!this._verticalLine)return;let n=this._chartType===`bar`?this._scaleXForBarChart(e,t):this._scaleX(e,t);this._verticalLine.setAttribute(`x1`,n.toString()),this._verticalLine.setAttribute(`y1`,t.y.toString()),this._verticalLine.setAttribute(`x2`,n.toString()),this._verticalLine.setAttribute(`y2`,(t.y+t.height).toString()),this._verticalLine.style.opacity=`1`}_hideVerticalLine(){this._verticalLine&&(this._verticalLine.style.opacity=`0`)}_showPlotPointsForX(e){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})});let t=String(e),n=this._plotPoints.get(t);n&&n.forEach(e=>{e.style.opacity=`1`})}_hidePlotPoints(){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})})}_calculateMaxYAxisLabelWidth(){if(!this._showGrid||!this._chartData)return 0;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return 60;e.font=`12px system-ui, -apple-system, sans-serif`;let t=this._showLegend?Math.max(this._legendHeight,60):0,n=this._height-t,r=Math.floor(n/35),i=Math.max(1,Math.min(5,r)),a=this._getYRange();if(this._hasOnlyZeroValues())return Math.ceil(e.measureText(this._formatYAxisValue(0)).width)+20;let o=0;for(let t=0;t<=i;t++){let n=a.max-(a.max-a.min)/i*t,r=this._formatYAxisValue(n),s=e.measureText(r);o=Math.max(o,s.width)}return Math.ceil(o)+20}_getChartBounds(){let e=this._calculateMaxYAxisLabelWidth(),t=`${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${e}-${this._rotatedLabelHeight}`;if(this._cachedBounds.bounds&&this._cachedBounds.dataHash===t)return this._cachedBounds.bounds;let n=0,r=0;this._showGrid&&(n=e+10);let i=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,a=i;this._showLegend&&(a=i+20+Math.max(this._legendHeight,60));let o=this._height-0-n-0,s=o-a,c=1;if(s<100&&a>0){let e=o-100;e>0?(c=Math.min(1,e/a),c=Math.max(.5,c)):c=.5}r=a*c;let l=this._width*.3,u=n,d=1;n>l&&(d=l/n,u=l);let f={width:(this._width-u-0)*d,height:this._height-0-r,x:u,y:0};return this._cachedBounds={bounds:f,dataHash:t},f}_getAllDataPoints(){if(!this._chartData)return[];let e=[];return this._chartData.datasets.forEach((t,n)=>{this._isDatasetVisible(t,n)&&e.push(...t.data)}),e}_hasOnlyZeroValues(){let e=this._getAllDataPoints();return e.length>0&&e.every(e=>e.y===0)}_getXValues(){if(!this._chartData)return[];let e=JSON.stringify(this._chartData.labels)+JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.x)));if(this._cachedXValues.values&&this._cachedXValues.dataHash===e)return this._cachedXValues.values;if(this._chartData.labels&&this._chartData.labels.length>0)return this._cachedXValues={values:this._chartData.labels,dataHash:e},this._chartData.labels;let t=new Set;this._chartData.datasets.forEach((e,n)=>{this._isDatasetVisible(e,n)&&e.data.forEach(e=>{t.add(e.x)})});let n=Array.from(t).sort((e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;let n=String(e),r=String(t),i=/^([A-Za-z]{3})\s+(\d{4})$/,a=n.match(i),o=r.match(i);if(a&&o){let e=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],t=e.indexOf(a[1]),n=e.indexOf(o[1]),r=parseInt(a[2]),i=parseInt(o[2]);return r===i?t-n:r-i}return n.localeCompare(r)});return this._cachedXValues={values:n,dataHash:e},n}_getYRange(){if(!this._chartData)return{min:0,max:100};let e=JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.y)));if(this._cachedYRange.range&&this._cachedYRange.dataHash===e)return this._cachedYRange.range;let t=this._getAllDataPoints();if(t.length===0){let t={min:0,max:100};return this._cachedYRange={range:t,dataHash:e},t}let n=t.map(e=>e.y),r=Math.min(...n),i=Math.max(...n),a=(i-r)*.1,o={min:Math.max(0,r-a),max:i+a};return this._cachedYRange={range:o,dataHash:e},o}_hasDecimalValues(){return this._getAllDataPoints().some(e=>e.y%1!=0)}_formatValueByString(e,t){switch(t.toLowerCase()){case`currency`:case`currency-usd`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`}).format(e);case`currency-eur`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`EUR`}).format(e);case`currency-gbp`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`GBP`}).format(e);case`number`:case`number-with-commas`:return new Intl.NumberFormat(`en-US`).format(e);case`percent`:return new Intl.NumberFormat(`en-US`,{style:`percent`,minimumFractionDigits:1}).format(e/100);default:return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}}_formatXAxisValue(e){if(this._chartData?.formatXAxis){if(typeof this._chartData.formatXAxis==`function`)return this._chartData.formatXAxis(e);if(typeof this._chartData.formatXAxis==`string`)return String(e)}return String(e)}_escapeHtmlForTooltip(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}_tooltipXHeadingHtml(e){return`<strong>${this._escapeHtmlForTooltip(this._formatXAxisValue(e))}</strong><br/>`}_formatYAxisValue(e){if(this._chartData?.formatYAxis){if(typeof this._chartData.formatYAxis==`function`)return this._chartData.formatYAxis(e);if(typeof this._chartData.formatYAxis==`string`)return this._formatValueByString(e,this._chartData.formatYAxis)}if(this._chartData?.datasets?.[0]?.formatValue){if(typeof this._chartData.datasets[0].formatValue==`function`)return this._chartData.datasets[0].formatValue(e);if(typeof this._chartData.datasets[0].formatValue==`string`)return this._formatValueByString(e,this._chartData.datasets[0].formatValue)}return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}_formatValue(e,t){if(t.formatValue){if(typeof t.formatValue==`function`)return t.formatValue(e);if(typeof t.formatValue==`string`)return this._formatValueByString(e,t.formatValue)}return String(e)}_getAllDatasetsAtX(e){if(!this._chartData)return[];let t=[];return this._chartData.datasets.forEach((n,r)=>{if(!this._isDatasetVisible(n,r))return;let i=n.data.find(t=>String(t.x)===String(e));if(i){let e=this._getDatasetColor(n,r),a=this._formatValue(i.y,n);t.push({name:n.name,value:i.y,color:e,formattedValue:a})}}),t}_findNearestXValue(e){if(!this._chartData)return null;let t=this._getChartBounds(),n=this._getXValues();if(n.length===0)return null;let r=this._chartType===`bar`,i=null,a=1/0;return n.forEach(n=>{let o=r?this._scaleXForBarChart(n,t):this._scaleX(n,t),s=Math.abs(e-o);s<a&&(a=s,i=n)}),i}_setupTooltipScrollHandler(){if(this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}this._chartTooltipScrollHandler=()=>{this._hideTooltip(),this._pinnedXValue=null},window.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;){let t=window.getComputedStyle(e),n=t.overflow,r=t.overflowY;(n===`auto`||n===`scroll`||r===`auto`||r===`scroll`)&&e.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}}_setupChartTooltip(){if(!this._svg||!this._showTooltip)return;this._chartTooltipMouseMove&&this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),this._chartTooltipMouseLeave&&this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),this._chartTooltipClick&&this._svg.removeEventListener(`click`,this._chartTooltipClick),this._chartTooltipTouchStart&&this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),this._chartTooltipTouchMove&&this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),this._chartTooltipTouchEnd&&this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),this._cachedTooltipContent.clear(),this._cachedXPositions.clear();let t=this._getChartBounds(),n=0,r=0,i=i=>{!this._chartContainer||!this._svg||(n=i.clientX,r=i.clientY,this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;let i=this._svg.getBoundingClientRect(),a=n-i.left,o=r-i.top;if(a<t.x||a>t.x+t.width||o<t.y||o>t.y+t.height){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}let s=this._findNearestXValue(a);if(!s){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}if(this._pinnedXValue!==null&&this._pinnedXValue===s){let e=this._pinnedXValue,i=this._getAllDatasetsAtX(e);if(i.length>0){this._activeXValue=e,this._showPlotPointsForX(e),this._showVerticalLineAtX(e,t);let a=this._cachedTooltipContent.get(e);a||(a=this._tooltipXHeadingHtml(e),i.forEach(e=>{a+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
2
2
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${e.color}; border-radius: 2px;"></span>
|
|
3
3
|
<span>${e.name}: ${e.formattedValue}</span>
|
|
4
4
|
</div>`}),this._cachedTooltipContent.set(e,a)),this._updateTooltipPosition(n,r),this._lastTooltipContent!==a&&this._showTooltipAt(n,r,a);return}}if(this._activeXValue===s){this._updateTooltipPosition(n,r);return}let c=this._getAllDatasetsAtX(s);if(c.length===0){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine();return}this._activeXValue=s,this._showPlotPointsForX(s),this._showVerticalLineAtX(s,t);let l=this._cachedTooltipContent.get(s);if(!l){if(l=this._tooltipXHeadingHtml(s),c.forEach(e=>{l+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
@@ -19,10 +19,10 @@ const e=require(`../chunks/register-element-tCL_F1YI.js`);var t=class e extends
|
|
|
19
19
|
</div>`}),this._cachedTooltipContent.set(e,i)),this._updateTooltipPosition(r.clientX,r.clientY),this._lastTooltipContent!==i&&this._showTooltipAt(r.clientX,r.clientY,i);return}}let o=this._findNearestXValue(i);if(!o){this._pinnedXValue===null&&(this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null);return}if(this._activeXValue===o){this._updateTooltipPosition(r.clientX,r.clientY);return}let s=this._getAllDatasetsAtX(o);if(s.length===0){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine();return}this._activeXValue=o,this._showPlotPointsForX(o),this._showVerticalLineAtX(o,t);let c=this._cachedTooltipContent.get(o);if(!c){if(c=this._tooltipXHeadingHtml(o),s.forEach(e=>{c+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
20
20
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${e.color}; border-radius: 2px;"></span>
|
|
21
21
|
<span>${e.name}: ${e.formattedValue}</span>
|
|
22
|
-
</div>`}),this._cachedTooltipContent.size>=e.MAX_CACHE_SIZE){let e=this._cachedTooltipContent.keys().next().value;e!==void 0&&this._cachedTooltipContent.delete(e)}this._cachedTooltipContent.set(o,c)}this._showTooltipAt(r.clientX,r.clientY,c)}))},l=()=>{this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._pinnedXValue===null&&setTimeout(()=>{this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null},500)};this._chartClickOutsideHandler||(this._chartClickOutsideHandler=e=>{if(this._pinnedXValue===null)return;let t=e.target;this._svg&&!this._svg.contains(t)&&(this._pinnedXValue=null,this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null)},document.addEventListener(`click`,this._chartClickOutsideHandler,!0)),this._svg.addEventListener(`mousemove`,i),this._svg.addEventListener(`mouseleave`,a),this._svg.addEventListener(`click`,o),this._svg.addEventListener(`touchstart`,s,{passive:!0}),this._svg.addEventListener(`touchmove`,c,{passive:!0}),this._svg.addEventListener(`touchend`,l),this._chartTooltipMouseMove=i,this._chartTooltipMouseLeave=a,this._chartTooltipClick=o,this._chartTooltipTouchStart=s,this._chartTooltipTouchMove=c,this._chartTooltipTouchEnd=l}_updateTooltipPosition(e,t){if(!this._tooltip||this._tooltip.style.display===`none`||this._tooltip.style.opacity===`0`)return;let n=this._tooltip.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=e+10,o=t-n.height-8;a+n.width>r&&(a=e-n.width-10),a<0&&(a=10),o<0&&(o=t+20),o+n.height>i&&(o=t-n.height-8,o<0&&(o=10));let s=`${a}px`,c=`${o}px`;this._tooltip.style.left!==s&&(this._tooltip.style.left=s),this._tooltip.style.top!==c&&(this._tooltip.style.top=c)}_scaleX(e,t){let n=this._getXValues();if(n.length===0)return t.x;let r=n.indexOf(e);if(r===-1)return t.x;let i=t.width/Math.max(1,n.length-1);return t.x+r*i}_scaleY(e,t){let n=this._getYRange();if(n.max===n.min)return t.y+t.height/2;let r=(e-n.min)/(n.max-n.min);return t.y+t.height-r*t.height}_getDatasetColor(e,t,n){return n===void 0?e.color||this._defaultColors[t%this._defaultColors.length]:e.color||this._defaultColors[n%this._defaultColors.length]}_getContrastColor(e){let t=e.replace(`#`,``),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return(.299*n+.587*r+.114*i)/255>.5?`#000000`:`#ffffff`}_calculateRotatedLabelHeight(){if(this._rotatedLabelHeight=0,!this._chartData||!this._showGrid)return;let e=this._getXValues();if(e.length<=1)return;let t={width:this._width-(this._showGrid?60:0)-0,height:this._height-(this._showLegend?Math.max(this._legendHeight,60):0)-0,x:this._showGrid?60:0,y:0},n=this._chartType===`bar`,r=[];e.forEach(e=>{let i=n?this._scaleXForBarChart(e,t):this._scaleX(e,t);r.push(i)});let i=document.createElement(`canvas`).getContext(`2d`);if(!i)return;i.font=`12px system-ui, -apple-system, sans-serif`;let a=[];e.forEach(e=>{let t=this._formatXAxisValue(e),n=i.measureText(t);a.push(n.width)});let o=!0;for(let t=1;t<e.length;t++){let e=r[t]-r[t-1],n=a[t-1]/2+a[t]/2+10;if(e<Math.max(n,80)){o=!1;break}}if(!o){let e=(Math.max(...a)+12*1.2)*.707;this._rotatedLabelHeight=Math.ceil(e)+10}}_renderGrid(e){if(!this._svg||!this._showGrid)return;let t=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);t.setAttribute(`class`,`chart-grid`);let n=this._getYRange(),r=Math.floor(e.height/35),i=Math.min(5,r);for(let r=0;r<=i;r++){let a=e.y+e.height/i*r,o=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);o.setAttribute(`x1`,e.x.toString()),o.setAttribute(`y1`,a.toString()),o.setAttribute(`x2`,(e.x+e.width).toString()),o.setAttribute(`y2`,a.toString()),o.setAttribute(`stroke`,`#e5e7eb`),o.setAttribute(`stroke-width`,`1`),o.setAttribute(`stroke-dasharray`,`2,2`),document.documentElement.classList.contains(`dark`)&&o.setAttribute(`stroke`,`#374151`),t.appendChild(o);let s=n.max-(n.max-n.min)/i*r,c=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),l=a+4;r===0&&(l=a+12),c.setAttribute(`x`,`5`),c.setAttribute(`y`,l.toString()),c.setAttribute(`text-anchor`,`start`),c.setAttribute(`fill`,`#6b7280`),c.setAttribute(`font-size`,`12`),c.textContent=this._formatYAxisValue(s),document.documentElement.classList.contains(`dark`)&&c.setAttribute(`fill`,`#9ca3af`),t.appendChild(c)}let a=this._getXValues();if(a.length===0){this._svg.appendChild(t);return}let o=this._chartType===`bar`,s=[];a.forEach(t=>{let n=o?this._scaleXForBarChart(t,e):this._scaleX(t,e);s.push(n)});let c=document.createElement(`canvas`).getContext(`2d`),l=!1,u=Array(a.length).fill(!0);if(c&&a.length>1){c.font=`12px system-ui, -apple-system, sans-serif`;let e=[];a.forEach(t=>{let n=this._formatXAxisValue(t),r=c.measureText(n);e.push(r.width)});let t=!0;for(let n=1;n<a.length;n++){let r=s[n]-s[n-1],i=e[n-1]/2+e[n]/2+10;if(r<Math.max(i,80)){t=!1;break}}if(!t){l=!0;let t=12*1.2;if(this._rotatedLabelHeight===0){let n=(Math.max(...e)+t)*.707;this._rotatedLabelHeight=Math.ceil(n)+10}let n=t*1.5,r=!0;for(let e=1;e<a.length;e++)if(s[e]-s[e-1]<n){r=!1;break}if(!r){let e=n;u=Array(a.length).fill(!1);let t=-1/0;a.length>0&&(u[0]=!0,t=s[0]);for(let n=1;n<a.length-1;n++){let r=s[n];r-t>=e&&(u[n]=!0,t=r)}if(a.length>1){let n=s[a.length-1];if(n-t>=e)u[a.length-1]=!0;else{for(;n-t<e;){let e=!1;for(let n=a.length-2;n>=0;n--)if(u[n]){if(u[n]=!1,n>0){for(let r=n-1;r>=0;r--)if(u[r]){t=s[r],e=!0;break}e||(t=s[0])}else t=s[0];e=!0;break}if(!e)break}n-t>=e&&(u[a.length-1]=!0)}}}}}else u=Array(a.length).fill(!1),a.length>0&&(u[0]=!0),a.length>1&&(u[a.length-1]=!0),this._rotatedLabelHeight=0;l||(this._rotatedLabelHeight=0),a.forEach((n,r)=>{if(u[r]){let i=s[r],o=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);o.setAttribute(`x1`,i.toString()),o.setAttribute(`y1`,e.y.toString()),o.setAttribute(`x2`,i.toString()),o.setAttribute(`y2`,(e.y+e.height).toString()),o.setAttribute(`stroke`,`#e5e7eb`),o.setAttribute(`stroke-width`,`1`),o.setAttribute(`stroke-dasharray`,`2,2`),document.documentElement.classList.contains(`dark`)&&o.setAttribute(`stroke`,`#374151`),t.appendChild(o);let c=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),u=i,d=`middle`;if(!l){if(r===0){let t=e.x;u=Math.max(i,t),d=`start`}else if(r===a.length-1){let t=e.x+e.width;u=Math.min(i,t),d=`end`}}else if(d=`end`,r===a.length-1){let t=document.createElement(`canvas`).getContext(`2d`);if(t){t.font=`12px system-ui, -apple-system, sans-serif`;let r=this._formatXAxisValue(n),a=t.measureText(r).width*.707,o=e.x+e.width+100;u=Math.min(i,o-a)}}c.setAttribute(`x`,u.toString());let f=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,p=f;this._showLegend&&(p=f+20+Math.max(this._legendHeight,60));let m=(this._height-e.y-e.height)/p,h=(l?30:20)*m,g=e.y+e.height+h;c.setAttribute(`y`,g.toString()),c.setAttribute(`text-anchor`,d),c.setAttribute(`fill`,`#6b7280`),c.setAttribute(`font-size`,`12`),l&&c.setAttribute(`transform`,`rotate(-45 ${u} ${g})`),c.textContent=this._formatXAxisValue(n),document.documentElement.classList.contains(`dark`)&&c.setAttribute(`fill`,`#9ca3af`),t.appendChild(c)}}),this._svg.appendChild(t)}_buildMonotoneXLinePathD(e){let t=e=>e<0?-1:1,n=(e,n,r,i,a,o)=>{let s=r-e,c=a-r,l=(i-n)/(s||c<0&&-0),u=(o-i)/(c||s<0&&-0),d=(l*c+u*s)/(s+c||1e-12);return(t(l)+t(u))*Math.min(Math.abs(l),Math.abs(u),.5*Math.abs(d))||0},r=(e,t,n,r,i)=>{let a=n-e;return a?(3*((r-t)/a)-i)/2:i},i=(e,t,n,r,i,a,o)=>{let s=(r-t)/3;e.push(`C ${t+s} ${n+s*a} ${r-s} ${i-s*o} ${r} ${i}`)},a=[];for(let t of e){let e=a[a.length-1];(!e||e.x!==t.x||e.y!==t.y)&&a.push(t)}if(a.length===0)return``;if(a.length===1)return`M ${a[0].x} ${a[0].y}`;let o=[],s=NaN,c=NaN,l=NaN,u=NaN,d=NaN,f=0;for(let e of a){let t=e.x,a=e.y;if(!(t===l&&a===u))switch(f){case 0:o.push(`M ${t} ${a}`),s=t,c=a,l=t,u=a,f=1;break;case 1:l=t,u=a,f=2;break;case 2:{let e=n(s,c,l,u,t,a);i(o,s,c,l,u,r(s,c,l,u,e),e),s=l,c=u,l=t,u=a,d=e,f=3;break}default:{let e=n(s,c,l,u,t,a);i(o,s,c,l,u,d,e),s=l,c=u,l=t,u=a,d=e}}}return f===2?o.push(`L ${l} ${u}`):f===3&&i(o,s,c,l,u,d,r(s,c,l,u,d)),o.join(` `)}_stripLeadingMoveTo(e){return e.replace(/^M\s+[\d.-]+\s+[\d.-]+\s*/i,``).trim()}_buildAreaFillPathD(e,t){if(e.length===0)return``;let n=e[e.length-1];if(e.length===1)return`M ${e[0].x} ${t} L ${e[0].x} ${e[0].y} L ${e[0].x} ${t} Z`;if(this._curveTension<=0){let r=[`M ${e[0].x} ${t}`,`L ${e[0].x} ${e[0].y}`];for(let t=1;t<e.length;t++)r.push(`L ${e[t].x} ${e[t].y}`);return r.push(`L ${n.x} ${t}`,`Z`),r.join(` `)}let r=this._buildMonotoneXLinePathD(e),i=this._stripLeadingMoveTo(r);return`M ${e[0].x} ${t} L ${e[0].x} ${e[0].y} ${i} L ${n.x} ${t} Z`}_buildSmoothLinePathD(e){if(e.length===0)return``;if(e.length===1)return`M ${e[0].x} ${e[0].y}`;if(this._curveTension<=0){let t=[`M ${e[0].x} ${e[0].y}`];for(let n=1;n<e.length;n++)t.push(`L ${e[n].x} ${e[n].y}`);return t.join(` `)}return this._buildMonotoneXLinePathD(e)}_renderLineChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds();this._renderGrid(e);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);t.setAttribute(`class`,`chart-data`);let n=document.createDocumentFragment();this._chartData.datasets.forEach((t,r)=>{if(!this._isDatasetVisible(t,r))return;let i=this._getDatasetColor(t,r),a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`),o=t.data.map(t=>({x:this._scaleX(t.x,e),y:this._scaleY(t.y,e)}));o.length!==0&&(a.setAttribute(`d`,this._buildSmoothLinePathD(o)),a.setAttribute(`fill`,`none`),a.setAttribute(`stroke`,i),a.setAttribute(`stroke-width`,`2`),a.setAttribute(`stroke-linecap`,`round`),a.setAttribute(`stroke-linejoin`,`round`),n.appendChild(a),t.data.forEach(a=>{let o=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`),s=this._scaleX(a.x,e),c=this._scaleY(a.y,e);o.setAttribute(`cx`,s.toString()),o.setAttribute(`cy`,c.toString()),o.setAttribute(`r`,`4`),o.setAttribute(`fill`,i);let l=document.documentElement.classList.contains(`dark`);o.setAttribute(`stroke`,l?`#1f2937`:`#fff`),o.setAttribute(`stroke-width`,`2`),o.setAttribute(`class`,`chart-point`),o.setAttribute(`data-dataset`,r.toString()),o.setAttribute(`data-x`,String(a.x)),o.setAttribute(`data-y`,a.y.toString()),o.setAttribute(`data-name`,t.name),o.style.opacity=`0`,o.style.pointerEvents=`none`;let u=String(a.x);this._plotPoints.has(u)||this._plotPoints.set(u,[]),this._plotPoints.get(u).push(o),n.appendChild(o)}))}),t.appendChild(n),this._svg.appendChild(t)}_scaleXForBarChart(e,t){let n=this._getXValues();if(n.length===0)return t.x;let r=n.indexOf(e);if(r===-1)return t.x;let i=n.length+1,a=t.width/i;return t.x+(r+1)*a}_renderBarChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds();this._renderGrid(e);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);t.setAttribute(`class`,`chart-data`);let n=document.createDocumentFragment(),r=this._getXValues(),i=this._chartData.datasets.filter((e,t)=>this._isDatasetVisible(e,t)).length,a=r.length;if(a===0)return;let o=[];r.forEach(t=>{o.push(this._scaleXForBarChart(t,e))}),o.sort((e,t)=>e-t);let s=e.width;if(a>1)for(let e=0;e<o.length-1;e++){let t=o[e+1]-o[e];t>0&&t<s&&(s=t)}else s=e.width*.5;let c=s*.7,l=.2,u=c/((1+l)*i-l),d=u*l,f=(u+d)*i-d;if(f>c){let e=c/f;u*=e,d=u*l,f=(u+d)*i-d}let p=0;this._chartData.datasets.forEach((t,r)=>{if(!this._isDatasetVisible(t,r))return;let i=this._getDatasetColor(t,r),a=-f/2+(u+d)*p;p++,t.data.forEach(o=>{let s=this._scaleXForBarChart(o.x,e),c=this._scaleY(o.y,e),l=e.y+e.height-c,d=s+a,f=document.createElementNS(`http://www.w3.org/2000/svg`,`rect`);f.setAttribute(`x`,d.toString()),f.setAttribute(`y`,c.toString()),f.setAttribute(`width`,u.toString()),f.setAttribute(`height`,l.toString()),f.setAttribute(`fill`,i),f.setAttribute(`rx`,`2`),f.setAttribute(`class`,`chart-bar`),f.setAttribute(`data-dataset`,r.toString()),f.setAttribute(`data-x`,String(o.x)),f.setAttribute(`data-y`,o.y.toString()),f.setAttribute(`data-name`,t.name),f.style.cursor=`pointer`,this._showTooltip&&f.addEventListener(`mouseenter`,e=>{let t=this._getAllDatasetsAtX(o.x),n=this._tooltipXHeadingHtml(o.x);t.forEach(e=>{n+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
22
|
+
</div>`}),this._cachedTooltipContent.size>=e.MAX_CACHE_SIZE){let e=this._cachedTooltipContent.keys().next().value;e!==void 0&&this._cachedTooltipContent.delete(e)}this._cachedTooltipContent.set(o,c)}this._showTooltipAt(r.clientX,r.clientY,c)}))},l=()=>{this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._pinnedXValue===null&&setTimeout(()=>{this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null},500)};this._chartClickOutsideHandler||(this._chartClickOutsideHandler=e=>{if(this._pinnedXValue===null)return;let t=e.target;this._svg&&!this._svg.contains(t)&&(this._pinnedXValue=null,this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null)},document.addEventListener(`click`,this._chartClickOutsideHandler,!0)),this._svg.addEventListener(`mousemove`,i),this._svg.addEventListener(`mouseleave`,a),this._svg.addEventListener(`click`,o),this._svg.addEventListener(`touchstart`,s,{passive:!0}),this._svg.addEventListener(`touchmove`,c,{passive:!0}),this._svg.addEventListener(`touchend`,l),this._chartTooltipMouseMove=i,this._chartTooltipMouseLeave=a,this._chartTooltipClick=o,this._chartTooltipTouchStart=s,this._chartTooltipTouchMove=c,this._chartTooltipTouchEnd=l}_updateTooltipPosition(e,t){if(!this._tooltip||this._tooltip.style.display===`none`||this._tooltip.style.opacity===`0`)return;let n=this._tooltip.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=e+10,o=t-n.height-8;a+n.width>r&&(a=e-n.width-10),a<0&&(a=10),o<0&&(o=t+20),o+n.height>i&&(o=t-n.height-8,o<0&&(o=10));let s=`${a}px`,c=`${o}px`;this._tooltip.style.left!==s&&(this._tooltip.style.left=s),this._tooltip.style.top!==c&&(this._tooltip.style.top=c)}_scaleX(e,t){let n=this._getXValues();if(n.length===0)return t.x;let r=n.indexOf(e);if(r===-1)return t.x;let i=t.width/Math.max(1,n.length-1);return t.x+r*i}_scaleY(e,t){let n=this._getYRange();if(n.max===n.min)return n.min===0?t.y+t.height:t.y+t.height/2;let r=(e-n.min)/(n.max-n.min);return t.y+t.height-r*t.height}_getDatasetColor(e,t,n){return n===void 0?e.color||this._defaultColors[t%this._defaultColors.length]:e.color||this._defaultColors[n%this._defaultColors.length]}_getContrastColor(e){let t=e.replace(`#`,``),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return(.299*n+.587*r+.114*i)/255>.5?`#000000`:`#ffffff`}_calculateRotatedLabelHeight(){if(this._rotatedLabelHeight=0,!this._chartData||!this._showGrid)return;let e=this._getXValues();if(e.length<=1)return;let t={width:this._width-(this._showGrid?60:0)-0,height:this._height-(this._showLegend?Math.max(this._legendHeight,60):0)-0,x:this._showGrid?60:0,y:0},n=this._chartType===`bar`,r=[];e.forEach(e=>{let i=n?this._scaleXForBarChart(e,t):this._scaleX(e,t);r.push(i)});let i=document.createElement(`canvas`).getContext(`2d`);if(!i)return;i.font=`12px system-ui, -apple-system, sans-serif`;let a=[];e.forEach(e=>{let t=this._formatXAxisValue(e),n=i.measureText(t);a.push(n.width)});let o=!0;for(let t=1;t<e.length;t++){let e=r[t]-r[t-1],n=a[t-1]/2+a[t]/2+10;if(e<Math.max(n,80)){o=!1;break}}if(!o){let e=(Math.max(...a)+12*1.2)*.707;this._rotatedLabelHeight=Math.ceil(e)+10}}_renderGrid(e){let t=this._chartType!==`pie`&&this._hasOnlyZeroValues();if(!this._svg||!this._showGrid&&!t)return;let n=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);n.setAttribute(`class`,`chart-grid`);let r=this._getYRange(),i=Math.floor(e.height/35),a=t?0:Math.max(1,Math.min(5,i));for(let i=0;i<=a;i++){let o=t?e.y+e.height:e.y+e.height/a*i,s=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);if(s.setAttribute(`x1`,e.x.toString()),s.setAttribute(`y1`,o.toString()),s.setAttribute(`x2`,(e.x+e.width).toString()),s.setAttribute(`y2`,o.toString()),s.setAttribute(`stroke`,t?`#9ca3af`:`#e5e7eb`),s.setAttribute(`stroke-width`,`1`),t||s.setAttribute(`stroke-dasharray`,`2,2`),document.documentElement.classList.contains(`dark`)&&s.setAttribute(`stroke`,`#374151`),n.appendChild(s),t&&!this._showGrid)continue;let c=t?0:r.max-(r.max-r.min)/a*i,l=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),u=o+4;i===0&&(u=o+12),l.setAttribute(`x`,`5`),l.setAttribute(`y`,u.toString()),l.setAttribute(`text-anchor`,`start`),l.setAttribute(`fill`,`#6b7280`),l.setAttribute(`font-size`,`12`),l.textContent=this._formatYAxisValue(c),document.documentElement.classList.contains(`dark`)&&l.setAttribute(`fill`,`#9ca3af`),n.appendChild(l)}let o=this._getXValues();if(o.length===0){this._svg.appendChild(n);return}let s=this._chartType===`bar`,c=[];o.forEach(t=>{let n=s?this._scaleXForBarChart(t,e):this._scaleX(t,e);c.push(n)});let l=document.createElement(`canvas`).getContext(`2d`),u=!1,d=Array(o.length).fill(!0);if(l&&o.length>1){l.font=`12px system-ui, -apple-system, sans-serif`;let e=[];o.forEach(t=>{let n=this._formatXAxisValue(t),r=l.measureText(n);e.push(r.width)});let t=!0;for(let n=1;n<o.length;n++){let r=c[n]-c[n-1],i=e[n-1]/2+e[n]/2+10;if(r<Math.max(i,80)){t=!1;break}}if(!t){u=!0;let t=12*1.2;if(this._rotatedLabelHeight===0){let n=(Math.max(...e)+t)*.707;this._rotatedLabelHeight=Math.ceil(n)+10}let n=t*1.5,r=!0;for(let e=1;e<o.length;e++)if(c[e]-c[e-1]<n){r=!1;break}if(!r){let e=n;d=Array(o.length).fill(!1);let t=-1/0;o.length>0&&(d[0]=!0,t=c[0]);for(let n=1;n<o.length-1;n++){let r=c[n];r-t>=e&&(d[n]=!0,t=r)}if(o.length>1){let n=c[o.length-1];if(n-t>=e)d[o.length-1]=!0;else{for(;n-t<e;){let e=!1;for(let n=o.length-2;n>=0;n--)if(d[n]){if(d[n]=!1,n>0){for(let r=n-1;r>=0;r--)if(d[r]){t=c[r],e=!0;break}e||(t=c[0])}else t=c[0];e=!0;break}if(!e)break}n-t>=e&&(d[o.length-1]=!0)}}}}}else d=Array(o.length).fill(!1),o.length>0&&(d[0]=!0),o.length>1&&(d[o.length-1]=!0),this._rotatedLabelHeight=0;u||(this._rotatedLabelHeight=0),o.forEach((t,r)=>{if(d[r]){let i=c[r],a=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);a.setAttribute(`x1`,i.toString()),a.setAttribute(`y1`,e.y.toString()),a.setAttribute(`x2`,i.toString()),a.setAttribute(`y2`,(e.y+e.height).toString()),a.setAttribute(`stroke`,`#e5e7eb`),a.setAttribute(`stroke-width`,`1`),a.setAttribute(`stroke-dasharray`,`2,2`),document.documentElement.classList.contains(`dark`)&&a.setAttribute(`stroke`,`#374151`),n.appendChild(a);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),l=i,d=`middle`;if(!u){if(r===0){let t=e.x;l=Math.max(i,t),d=`start`}else if(r===o.length-1){let t=e.x+e.width;l=Math.min(i,t),d=`end`}}else if(d=`end`,r===o.length-1){let n=document.createElement(`canvas`).getContext(`2d`);if(n){n.font=`12px system-ui, -apple-system, sans-serif`;let r=this._formatXAxisValue(t),a=n.measureText(r).width*.707,o=e.x+e.width+100;l=Math.min(i,o-a)}}s.setAttribute(`x`,l.toString());let f=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,p=f;this._showLegend&&(p=f+20+Math.max(this._legendHeight,60));let m=(this._height-e.y-e.height)/p,h=(u?30:20)*m,g=e.y+e.height+h;s.setAttribute(`y`,g.toString()),s.setAttribute(`text-anchor`,d),s.setAttribute(`fill`,`#6b7280`),s.setAttribute(`font-size`,`12`),u&&s.setAttribute(`transform`,`rotate(-45 ${l} ${g})`),s.textContent=this._formatXAxisValue(t),document.documentElement.classList.contains(`dark`)&&s.setAttribute(`fill`,`#9ca3af`),n.appendChild(s)}}),this._svg.appendChild(n)}_buildMonotoneXLinePathD(e){let t=e=>e<0?-1:1,n=(e,n,r,i,a,o)=>{let s=r-e,c=a-r,l=(i-n)/(s||c<0&&-0),u=(o-i)/(c||s<0&&-0),d=(l*c+u*s)/(s+c||1e-12);return(t(l)+t(u))*Math.min(Math.abs(l),Math.abs(u),.5*Math.abs(d))||0},r=(e,t,n,r,i)=>{let a=n-e;return a?(3*((r-t)/a)-i)/2:i},i=(e,t,n,r,i,a,o)=>{let s=(r-t)/3;e.push(`C ${t+s} ${n+s*a} ${r-s} ${i-s*o} ${r} ${i}`)},a=[];for(let t of e){let e=a[a.length-1];(!e||e.x!==t.x||e.y!==t.y)&&a.push(t)}if(a.length===0)return``;if(a.length===1)return`M ${a[0].x} ${a[0].y}`;let o=[],s=NaN,c=NaN,l=NaN,u=NaN,d=NaN,f=0;for(let e of a){let t=e.x,a=e.y;if(!(t===l&&a===u))switch(f){case 0:o.push(`M ${t} ${a}`),s=t,c=a,l=t,u=a,f=1;break;case 1:l=t,u=a,f=2;break;case 2:{let e=n(s,c,l,u,t,a);i(o,s,c,l,u,r(s,c,l,u,e),e),s=l,c=u,l=t,u=a,d=e,f=3;break}default:{let e=n(s,c,l,u,t,a);i(o,s,c,l,u,d,e),s=l,c=u,l=t,u=a,d=e}}}return f===2?o.push(`L ${l} ${u}`):f===3&&i(o,s,c,l,u,d,r(s,c,l,u,d)),o.join(` `)}_stripLeadingMoveTo(e){return e.replace(/^M\s+[\d.-]+\s+[\d.-]+\s*/i,``).trim()}_buildAreaFillPathD(e,t){if(e.length===0)return``;let n=e[e.length-1];if(e.length===1)return`M ${e[0].x} ${t} L ${e[0].x} ${e[0].y} L ${e[0].x} ${t} Z`;if(this._curveTension<=0){let r=[`M ${e[0].x} ${t}`,`L ${e[0].x} ${e[0].y}`];for(let t=1;t<e.length;t++)r.push(`L ${e[t].x} ${e[t].y}`);return r.push(`L ${n.x} ${t}`,`Z`),r.join(` `)}let r=this._buildMonotoneXLinePathD(e),i=this._stripLeadingMoveTo(r);return`M ${e[0].x} ${t} L ${e[0].x} ${e[0].y} ${i} L ${n.x} ${t} Z`}_buildSmoothLinePathD(e){if(e.length===0)return``;if(e.length===1)return`M ${e[0].x} ${e[0].y}`;if(this._curveTension<=0){let t=[`M ${e[0].x} ${e[0].y}`];for(let n=1;n<e.length;n++)t.push(`L ${e[n].x} ${e[n].y}`);return t.join(` `)}return this._buildMonotoneXLinePathD(e)}_renderLineChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds(),t=this._hasOnlyZeroValues();this._renderGrid(e);let n=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);n.setAttribute(`class`,`chart-data`);let r=document.createDocumentFragment();this._chartData.datasets.forEach((n,i)=>{if(!this._isDatasetVisible(n,i))return;let a=this._getDatasetColor(n,i),o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`),s=n.data.map(t=>({x:this._scaleX(t.x,e),y:this._scaleY(t.y,e)}));s.length!==0&&(t||(o.setAttribute(`d`,this._buildSmoothLinePathD(s)),o.setAttribute(`fill`,`none`),o.setAttribute(`stroke`,a),o.setAttribute(`stroke-width`,`2`),o.setAttribute(`stroke-linecap`,`round`),o.setAttribute(`stroke-linejoin`,`round`),r.appendChild(o)),n.data.forEach(t=>{let o=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`),s=this._scaleX(t.x,e),c=this._scaleY(t.y,e);o.setAttribute(`cx`,s.toString()),o.setAttribute(`cy`,c.toString()),o.setAttribute(`r`,`4`),o.setAttribute(`fill`,a);let l=document.documentElement.classList.contains(`dark`);o.setAttribute(`stroke`,l?`#1f2937`:`#fff`),o.setAttribute(`stroke-width`,`2`),o.setAttribute(`class`,`chart-point`),o.setAttribute(`data-dataset`,i.toString()),o.setAttribute(`data-x`,String(t.x)),o.setAttribute(`data-y`,t.y.toString()),o.setAttribute(`data-name`,n.name),o.style.opacity=`0`,o.style.pointerEvents=`none`;let u=String(t.x);this._plotPoints.has(u)||this._plotPoints.set(u,[]),this._plotPoints.get(u).push(o),r.appendChild(o)}))}),n.appendChild(r),this._svg.appendChild(n)}_scaleXForBarChart(e,t){let n=this._getXValues();if(n.length===0)return t.x;let r=n.indexOf(e);if(r===-1)return t.x;let i=n.length+1,a=t.width/i;return t.x+(r+1)*a}_renderBarChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds();this._renderGrid(e);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);t.setAttribute(`class`,`chart-data`);let n=document.createDocumentFragment(),r=this._getXValues(),i=this._chartData.datasets.filter((e,t)=>this._isDatasetVisible(e,t)).length,a=r.length;if(a===0)return;let o=[];r.forEach(t=>{o.push(this._scaleXForBarChart(t,e))}),o.sort((e,t)=>e-t);let s=e.width;if(a>1)for(let e=0;e<o.length-1;e++){let t=o[e+1]-o[e];t>0&&t<s&&(s=t)}else s=e.width*.5;let c=s*.7,l=.2,u=c/((1+l)*i-l),d=u*l,f=(u+d)*i-d;if(f>c){let e=c/f;u*=e,d=u*l,f=(u+d)*i-d}let p=0;this._chartData.datasets.forEach((t,r)=>{if(!this._isDatasetVisible(t,r))return;let i=this._getDatasetColor(t,r),a=-f/2+(u+d)*p;p++,t.data.forEach(o=>{let s=this._scaleXForBarChart(o.x,e),c=this._scaleY(o.y,e),l=e.y+e.height-c,d=s+a,f=document.createElementNS(`http://www.w3.org/2000/svg`,`rect`);f.setAttribute(`x`,d.toString()),f.setAttribute(`y`,c.toString()),f.setAttribute(`width`,u.toString()),f.setAttribute(`height`,l.toString()),f.setAttribute(`fill`,i),f.setAttribute(`rx`,`2`),f.setAttribute(`class`,`chart-bar`),f.setAttribute(`data-dataset`,r.toString()),f.setAttribute(`data-x`,String(o.x)),f.setAttribute(`data-y`,o.y.toString()),f.setAttribute(`data-name`,t.name),f.style.cursor=`pointer`,this._showTooltip&&f.addEventListener(`mouseenter`,e=>{let t=this._getAllDatasetsAtX(o.x),n=this._tooltipXHeadingHtml(o.x);t.forEach(e=>{n+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
23
23
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${e.color}; border-radius: 2px;"></span>
|
|
24
24
|
<span>${e.name}: ${e.formattedValue}</span>
|
|
25
|
-
</div>`}),this._showTooltipAt(e.clientX,e.clientY,n)}),n.appendChild(f)})}),t.appendChild(n),this._svg.appendChild(t)}_renderAreaChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds();this._renderGrid(e);let
|
|
25
|
+
</div>`}),this._showTooltipAt(e.clientX,e.clientY,n)}),n.appendChild(f)})}),t.appendChild(n),this._svg.appendChild(t)}_renderAreaChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds(),t=this._hasOnlyZeroValues();this._renderGrid(e);let n=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);n.setAttribute(`class`,`chart-data`);let r=document.createDocumentFragment();this._chartData.datasets.forEach((n,i)=>{if(!this._isDatasetVisible(n,i))return;let a=this._getDatasetColor(n,i),o=n.data.map(t=>({x:this._scaleX(t.x,e),y:this._scaleY(t.y,e)}));if(o.length!==0){if(!t){let t=e.y+e.height,n=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);n.setAttribute(`d`,this._buildAreaFillPathD(o,t)),n.setAttribute(`fill`,a),n.setAttribute(`fill-opacity`,`0.3`),r.appendChild(n);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this._buildSmoothLinePathD(o)),i.setAttribute(`fill`,`none`),i.setAttribute(`stroke`,a),i.setAttribute(`stroke-width`,`2`),i.setAttribute(`stroke-linecap`,`round`),i.setAttribute(`stroke-linejoin`,`round`),r.appendChild(i)}n.data.forEach(t=>{let o=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`),s=this._scaleX(t.x,e),c=this._scaleY(t.y,e);o.setAttribute(`cx`,s.toString()),o.setAttribute(`cy`,c.toString()),o.setAttribute(`r`,`4`),o.setAttribute(`fill`,a);let l=document.documentElement.classList.contains(`dark`);o.setAttribute(`stroke`,l?`#1f2937`:`#fff`),o.setAttribute(`stroke-width`,`2`),o.setAttribute(`class`,`chart-point`),o.setAttribute(`data-dataset`,i.toString()),o.setAttribute(`data-x`,String(t.x)),o.setAttribute(`data-y`,t.y.toString()),o.setAttribute(`data-name`,n.name),o.style.opacity=`0`,o.style.pointerEvents=`none`;let u=String(t.x);this._plotPoints.has(u)||this._plotPoints.set(u,[]),this._plotPoints.get(u).push(o),r.appendChild(o)})}}),n.appendChild(r),this._svg.appendChild(n)}_renderPieChart(){if(!this._svg||!this._chartData)return;let e=this._getChartBounds(),t=e.x+e.width/2,n=e.y+e.height/2,r=Math.min(e.width,e.height)/2-20,i=this._chartData.datasets[0];if(!i||!i.data||i.data.length===0)return;let a=i.data.reduce((e,t)=>e+t.y,0);if(a===0)return;let o=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);o.setAttribute(`class`,`chart-data`),this._pieChartGroup=o,this._pieChartClickOutsideHandler||(this._pieChartClickOutsideHandler=e=>{if(!this._pieChartTooltipShown)return;let t=e.target;this._pieChartGroup&&!this._pieChartGroup.contains(t)&&(this._pieChartTooltipShown=!1,this._hideTooltip())},document.addEventListener(`click`,this._pieChartClickOutsideHandler,!0));let s=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);s.setAttribute(`cx`,t.toString()),s.setAttribute(`cy`,n.toString()),s.setAttribute(`r`,r.toString()),s.setAttribute(`fill`,`transparent`),s.setAttribute(`pointer-events`,`none`),o.appendChild(s);let c=-Math.PI/2;i.data.forEach((e,s)=>{let l=e.y,u=l/a*100,d=l/a*2*Math.PI,f=e.color||this._getDatasetColor(i,0,s),p=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);p.setAttribute(`class`,`chart-pie-slice-group`),p.setAttribute(`data-index`,s.toString()),p.style.cursor=`pointer`,p.style.transition=`transform 0.2s ease-out`;let m=document.createElementNS(`http://www.w3.org/2000/svg`,`path`),h=r+2,g=t+h*Math.cos(c),_=n+h*Math.sin(c),v=t+h*Math.cos(c+d),y=n+h*Math.sin(c+d),b=d>Math.PI?1:0,x=[`M ${t} ${n}`,`L ${g} ${_}`,`A ${h} ${h} 0 ${b} 1 ${v} ${y}`,`Z`].join(` `);m.setAttribute(`d`,x),m.setAttribute(`fill`,f),m.setAttribute(`class`,`chart-pie-slice`),m.setAttribute(`data-index`,s.toString()),m.setAttribute(`data-x`,String(e.x)),m.setAttribute(`data-y`,e.y.toString()),m.setAttribute(`data-name`,i.name),m.setAttribute(`data-percentage`,u.toFixed(1)),p.appendChild(m);let S=c+d/2,C=Math.cos(S)*10,w=Math.sin(S)*10,T=null,E=null,D=!1;if(p.__chartInstance=this,p.addEventListener(`mouseenter`,function(){if(E!==null&&(clearTimeout(E),E=null),!D){T!==null&&clearTimeout(T);let e=window.setTimeout(()=>{D=!0,this.setAttribute(`transform`,`translate(${C}, ${w})`),T=null,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.delete(e)},150);T=e,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.add(e)}}),p.addEventListener(`mouseleave`,function(){if(T!==null&&(clearTimeout(T),T=null),D){E!==null&&clearTimeout(E);let e=window.setTimeout(()=>{D=!1,this.setAttribute(`transform`,`translate(0, 0)`),E=null,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.delete(e)},200);E=e,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.add(e)}}),p.addEventListener(`click`,function(){T!==null&&(clearTimeout(T),T=null),E!==null&&(clearTimeout(E),E=null),D=!0,this.setAttribute(`transform`,`translate(${C}, ${w})`)}),this._showTooltip){let t=this._formatValue(l,i),n=`${this._tooltipXHeadingHtml(e.x)}${i.name}: ${t}<br/>${u.toFixed(1)}%`,r=e=>{this._pieChartTooltipShown=!0,this._showTooltipAt(e.clientX,e.clientY,n)};p.addEventListener(`mouseenter`,r),p.addEventListener(`mousemove`,r),p.addEventListener(`click`,e=>{e.stopPropagation(),r(e)}),p.addEventListener(`mouseleave`,()=>{this._tooltipHideTimeout=window.setTimeout(()=>{this._pieChartTooltipShown=!1,this._hideTooltip()},90)})}if(u>5){let e=c+d/2,i=r*.7,a=t+i*Math.cos(e),o=n+i*Math.sin(e),s=this._getContrastColor(f),l=document.createElementNS(`http://www.w3.org/2000/svg`,`text`);l.setAttribute(`x`,a.toString()),l.setAttribute(`y`,o.toString()),l.setAttribute(`text-anchor`,`middle`),l.setAttribute(`dominant-baseline`,`middle`),l.setAttribute(`fill`,s),l.setAttribute(`font-size`,`12`),l.setAttribute(`font-weight`,`500`),l.textContent=`${u.toFixed(1)}%`,p.appendChild(l)}o.appendChild(p),c+=d}),this._svg.appendChild(o),this._showTooltip&&(this._svg.addEventListener(`mousemove`,e=>{this._pieChartTooltipShown&&this._lastTooltipContent&&this._showTooltipAt(e.clientX,e.clientY,this._lastTooltipContent)}),this._svg.addEventListener(`mouseleave`,()=>{this._pieChartTooltipShown=!1,this._hideTooltip()}))}_calculateLegendHeight(){if(!this._chartData)return 0;let e=this._width-40,t=[];this._chartType===`pie`&&this._chartData.datasets.length>0?this._chartData.datasets[0].data.forEach(e=>{t.push({name:String(e.x),row:0})}):this._chartData.datasets.forEach(e=>{t.push({name:e.name,row:0})});let n=0,r=[];return t.forEach(t=>{let i=20+Math.min(t.name.length*7.5,150);r[n]||(r[n]=[]),r[n].reduce((e,t)=>e+(20+Math.min(t.name.length*7.5,150))+32,0)+i>e&&r[n].length>0&&(n++,r[n]=[]),t.row=n,r[n].push(t)}),r.length*36}_renderLegend(){if(!this._chartData||!this._svg)return{height:0};let e=this._svg.querySelector(`.chart-legend`);e&&e.remove();let t=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);if(t.setAttribute(`class`,`chart-legend`),!this._chartData)return{height:0};let n=this._chartData,r=this._width-40,i=[];if(this._chartType===`pie`&&n.datasets.length>0){let e=n.datasets[0];e.data.forEach((t,n)=>{let r=t.color||this._getDatasetColor(e,0,n),a=String(t.x);i.push({name:a,color:r,x:0,textX:0,row:0})})}else n.datasets.forEach((e,t)=>{if(!this._isDatasetVisible(e,t))return;let n=this._getDatasetColor(e,t);i.push({name:e.name,color:n,x:0,textX:0,row:0})});let a=0,o=[];i.forEach(e=>{let t=20+Math.min(e.name.length*7.5,150);o[a]||(o[a]=[]),o[a].reduce((e,t)=>e+(20+Math.min(t.name.length*7.5,150))+32,0)+t>r&&o[a].length>0&&(a++,o[a]=[]),e.row=a,o[a].push(e)}),o.forEach(e=>{let t=e.reduce((e,t)=>e+(20+Math.min(t.name.length*7.5,150)),0)+(e.length-1)*32,n=(this._width-t)/2;e.forEach(e=>{let t=Math.min(e.name.length*7.5,150);e.x=n,e.textX=n+6+8,n+=20+t+32})}),o.length*36;let s=this._getChartBounds(),c=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,l=c;this._showLegend&&(l=c+20+Math.max(this._legendHeight,60));let u=this._height-s.y-s.height,d=l>0?u/l:1,f=(this._rotatedLabelHeight>0?30:20)*d,p=12*d,m=this._rotatedLabelHeight*d,h=s.y+s.height+f+(this._rotatedLabelHeight>0?m:p)+20*d;return i.forEach(e=>{let n=h+e.row*36+16/2,r=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);r.setAttribute(`cx`,e.x.toString()),r.setAttribute(`cy`,n.toString()),r.setAttribute(`r`,`6`),r.setAttribute(`fill`,e.color),t.appendChild(r);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`foreignObject`);i.setAttribute(`x`,e.textX.toString()),i.setAttribute(`y`,(n-12).toString()),i.setAttribute(`width`,`150`),i.setAttribute(`height`,`24`);let a=document.createElement(`div`);a.style.cssText=`
|
|
26
26
|
font-size: 12px;
|
|
27
27
|
font-family: system-ui, -apple-system, sans-serif;
|
|
28
28
|
color: ${document.documentElement.classList.contains(`dark`)?`#d1d5db`:`#374151`};
|
|
@@ -346,12 +346,14 @@ var t = class e extends HTMLElement {
|
|
|
346
346
|
let e = document.createElement("canvas").getContext("2d");
|
|
347
347
|
if (!e) return 60;
|
|
348
348
|
e.font = "12px system-ui, -apple-system, sans-serif";
|
|
349
|
-
let t = this._showLegend ? Math.max(this._legendHeight, 60) : 0, n = this._height - t, r = Math.floor(n / 35), i = Math.min(5, r), a =
|
|
349
|
+
let t = this._showLegend ? Math.max(this._legendHeight, 60) : 0, n = this._height - t, r = Math.floor(n / 35), i = Math.max(1, Math.min(5, r)), a = this._getYRange();
|
|
350
|
+
if (this._hasOnlyZeroValues()) return Math.ceil(e.measureText(this._formatYAxisValue(0)).width) + 20;
|
|
351
|
+
let o = 0;
|
|
350
352
|
for (let t = 0; t <= i; t++) {
|
|
351
|
-
let n =
|
|
352
|
-
|
|
353
|
+
let n = a.max - (a.max - a.min) / i * t, r = this._formatYAxisValue(n), s = e.measureText(r);
|
|
354
|
+
o = Math.max(o, s.width);
|
|
353
355
|
}
|
|
354
|
-
return Math.ceil(
|
|
356
|
+
return Math.ceil(o) + 20;
|
|
355
357
|
}
|
|
356
358
|
_getChartBounds() {
|
|
357
359
|
let e = this._calculateMaxYAxisLabelWidth(), t = `${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${e}-${this._rotatedLabelHeight}`;
|
|
@@ -386,6 +388,10 @@ var t = class e extends HTMLElement {
|
|
|
386
388
|
this._isDatasetVisible(t, n) && e.push(...t.data);
|
|
387
389
|
}), e;
|
|
388
390
|
}
|
|
391
|
+
_hasOnlyZeroValues() {
|
|
392
|
+
let e = this._getAllDataPoints();
|
|
393
|
+
return e.length > 0 && e.every((e) => e.y === 0);
|
|
394
|
+
}
|
|
389
395
|
_getXValues() {
|
|
390
396
|
if (!this._chartData) return [];
|
|
391
397
|
let e = JSON.stringify(this._chartData.labels) + JSON.stringify(this._chartData.datasets.map((e) => e.data.map((e) => e.x)));
|
|
@@ -754,7 +760,7 @@ var t = class e extends HTMLElement {
|
|
|
754
760
|
}
|
|
755
761
|
_scaleY(e, t) {
|
|
756
762
|
let n = this._getYRange();
|
|
757
|
-
if (n.max === n.min) return t.y + t.height / 2;
|
|
763
|
+
if (n.max === n.min) return n.min === 0 ? t.y + t.height : t.y + t.height / 2;
|
|
758
764
|
let r = (e - n.min) / (n.max - n.min);
|
|
759
765
|
return t.y + t.height - r * t.height;
|
|
760
766
|
}
|
|
@@ -801,116 +807,117 @@ var t = class e extends HTMLElement {
|
|
|
801
807
|
}
|
|
802
808
|
}
|
|
803
809
|
_renderGrid(e) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
o
|
|
811
|
-
|
|
812
|
-
|
|
810
|
+
let t = this._chartType !== "pie" && this._hasOnlyZeroValues();
|
|
811
|
+
if (!this._svg || !this._showGrid && !t) return;
|
|
812
|
+
let n = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
813
|
+
n.setAttribute("class", "chart-grid");
|
|
814
|
+
let r = this._getYRange(), i = Math.floor(e.height / 35), a = t ? 0 : Math.max(1, Math.min(5, i));
|
|
815
|
+
for (let i = 0; i <= a; i++) {
|
|
816
|
+
let o = t ? e.y + e.height : e.y + e.height / a * i, s = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
817
|
+
if (s.setAttribute("x1", e.x.toString()), s.setAttribute("y1", o.toString()), s.setAttribute("x2", (e.x + e.width).toString()), s.setAttribute("y2", o.toString()), s.setAttribute("stroke", t ? "#9ca3af" : "#e5e7eb"), s.setAttribute("stroke-width", "1"), t || s.setAttribute("stroke-dasharray", "2,2"), document.documentElement.classList.contains("dark") && s.setAttribute("stroke", "#374151"), n.appendChild(s), t && !this._showGrid) continue;
|
|
818
|
+
let c = t ? 0 : r.max - (r.max - r.min) / a * i, l = document.createElementNS("http://www.w3.org/2000/svg", "text"), u = o + 4;
|
|
819
|
+
i === 0 && (u = o + 12), l.setAttribute("x", "5"), l.setAttribute("y", u.toString()), l.setAttribute("text-anchor", "start"), l.setAttribute("fill", "#6b7280"), l.setAttribute("font-size", "12"), l.textContent = this._formatYAxisValue(c), document.documentElement.classList.contains("dark") && l.setAttribute("fill", "#9ca3af"), n.appendChild(l);
|
|
813
820
|
}
|
|
814
|
-
let
|
|
815
|
-
if (
|
|
816
|
-
this._svg.appendChild(
|
|
821
|
+
let o = this._getXValues();
|
|
822
|
+
if (o.length === 0) {
|
|
823
|
+
this._svg.appendChild(n);
|
|
817
824
|
return;
|
|
818
825
|
}
|
|
819
|
-
let
|
|
820
|
-
|
|
821
|
-
let n =
|
|
822
|
-
|
|
826
|
+
let s = this._chartType === "bar", c = [];
|
|
827
|
+
o.forEach((t) => {
|
|
828
|
+
let n = s ? this._scaleXForBarChart(t, e) : this._scaleX(t, e);
|
|
829
|
+
c.push(n);
|
|
823
830
|
});
|
|
824
|
-
let
|
|
825
|
-
if (
|
|
826
|
-
|
|
831
|
+
let l = document.createElement("canvas").getContext("2d"), u = !1, d = Array(o.length).fill(!0);
|
|
832
|
+
if (l && o.length > 1) {
|
|
833
|
+
l.font = "12px system-ui, -apple-system, sans-serif";
|
|
827
834
|
let e = [];
|
|
828
|
-
|
|
829
|
-
let n = this._formatXAxisValue(t), r =
|
|
835
|
+
o.forEach((t) => {
|
|
836
|
+
let n = this._formatXAxisValue(t), r = l.measureText(n);
|
|
830
837
|
e.push(r.width);
|
|
831
838
|
});
|
|
832
839
|
let t = !0;
|
|
833
|
-
for (let n = 1; n <
|
|
834
|
-
let r =
|
|
840
|
+
for (let n = 1; n < o.length; n++) {
|
|
841
|
+
let r = c[n] - c[n - 1], i = e[n - 1] / 2 + e[n] / 2 + 10;
|
|
835
842
|
if (r < Math.max(i, 80)) {
|
|
836
843
|
t = !1;
|
|
837
844
|
break;
|
|
838
845
|
}
|
|
839
846
|
}
|
|
840
847
|
if (!t) {
|
|
841
|
-
|
|
848
|
+
u = !0;
|
|
842
849
|
let t = 12 * 1.2;
|
|
843
850
|
if (this._rotatedLabelHeight === 0) {
|
|
844
851
|
let n = (Math.max(...e) + t) * .707;
|
|
845
852
|
this._rotatedLabelHeight = Math.ceil(n) + 10;
|
|
846
853
|
}
|
|
847
854
|
let n = t * 1.5, r = !0;
|
|
848
|
-
for (let e = 1; e <
|
|
855
|
+
for (let e = 1; e < o.length; e++) if (c[e] - c[e - 1] < n) {
|
|
849
856
|
r = !1;
|
|
850
857
|
break;
|
|
851
858
|
}
|
|
852
859
|
if (!r) {
|
|
853
860
|
let e = n;
|
|
854
|
-
|
|
861
|
+
d = Array(o.length).fill(!1);
|
|
855
862
|
let t = -Infinity;
|
|
856
|
-
|
|
857
|
-
for (let n = 1; n <
|
|
858
|
-
let r =
|
|
859
|
-
r - t >= e && (
|
|
863
|
+
o.length > 0 && (d[0] = !0, t = c[0]);
|
|
864
|
+
for (let n = 1; n < o.length - 1; n++) {
|
|
865
|
+
let r = c[n];
|
|
866
|
+
r - t >= e && (d[n] = !0, t = r);
|
|
860
867
|
}
|
|
861
|
-
if (
|
|
862
|
-
let n =
|
|
863
|
-
if (n - t >= e)
|
|
868
|
+
if (o.length > 1) {
|
|
869
|
+
let n = c[o.length - 1];
|
|
870
|
+
if (n - t >= e) d[o.length - 1] = !0;
|
|
864
871
|
else {
|
|
865
872
|
for (; n - t < e;) {
|
|
866
873
|
let e = !1;
|
|
867
|
-
for (let n =
|
|
868
|
-
if (
|
|
869
|
-
for (let r = n - 1; r >= 0; r--) if (
|
|
870
|
-
t =
|
|
874
|
+
for (let n = o.length - 2; n >= 0; n--) if (d[n]) {
|
|
875
|
+
if (d[n] = !1, n > 0) {
|
|
876
|
+
for (let r = n - 1; r >= 0; r--) if (d[r]) {
|
|
877
|
+
t = c[r], e = !0;
|
|
871
878
|
break;
|
|
872
879
|
}
|
|
873
|
-
e || (t =
|
|
874
|
-
} else t =
|
|
880
|
+
e || (t = c[0]);
|
|
881
|
+
} else t = c[0];
|
|
875
882
|
e = !0;
|
|
876
883
|
break;
|
|
877
884
|
}
|
|
878
885
|
if (!e) break;
|
|
879
886
|
}
|
|
880
|
-
n - t >= e && (
|
|
887
|
+
n - t >= e && (d[o.length - 1] = !0);
|
|
881
888
|
}
|
|
882
889
|
}
|
|
883
890
|
}
|
|
884
891
|
}
|
|
885
|
-
} else
|
|
886
|
-
|
|
887
|
-
if (
|
|
888
|
-
let i =
|
|
889
|
-
|
|
890
|
-
let
|
|
891
|
-
if (!
|
|
892
|
+
} else d = Array(o.length).fill(!1), o.length > 0 && (d[0] = !0), o.length > 1 && (d[o.length - 1] = !0), this._rotatedLabelHeight = 0;
|
|
893
|
+
u || (this._rotatedLabelHeight = 0), o.forEach((t, r) => {
|
|
894
|
+
if (d[r]) {
|
|
895
|
+
let i = c[r], a = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
896
|
+
a.setAttribute("x1", i.toString()), a.setAttribute("y1", e.y.toString()), a.setAttribute("x2", i.toString()), a.setAttribute("y2", (e.y + e.height).toString()), a.setAttribute("stroke", "#e5e7eb"), a.setAttribute("stroke-width", "1"), a.setAttribute("stroke-dasharray", "2,2"), document.documentElement.classList.contains("dark") && a.setAttribute("stroke", "#374151"), n.appendChild(a);
|
|
897
|
+
let s = document.createElementNS("http://www.w3.org/2000/svg", "text"), l = i, d = "middle";
|
|
898
|
+
if (!u) {
|
|
892
899
|
if (r === 0) {
|
|
893
900
|
let t = e.x;
|
|
894
|
-
|
|
895
|
-
} else if (r ===
|
|
901
|
+
l = Math.max(i, t), d = "start";
|
|
902
|
+
} else if (r === o.length - 1) {
|
|
896
903
|
let t = e.x + e.width;
|
|
897
|
-
|
|
904
|
+
l = Math.min(i, t), d = "end";
|
|
898
905
|
}
|
|
899
|
-
} else if (d = "end", r ===
|
|
900
|
-
let
|
|
901
|
-
if (
|
|
902
|
-
|
|
903
|
-
let r = this._formatXAxisValue(
|
|
904
|
-
|
|
906
|
+
} else if (d = "end", r === o.length - 1) {
|
|
907
|
+
let n = document.createElement("canvas").getContext("2d");
|
|
908
|
+
if (n) {
|
|
909
|
+
n.font = "12px system-ui, -apple-system, sans-serif";
|
|
910
|
+
let r = this._formatXAxisValue(t), a = n.measureText(r).width * .707, o = e.x + e.width + 100;
|
|
911
|
+
l = Math.min(i, o - a);
|
|
905
912
|
}
|
|
906
913
|
}
|
|
907
|
-
|
|
914
|
+
s.setAttribute("x", l.toString());
|
|
908
915
|
let f = (this._rotatedLabelHeight > 0 ? 30 : 20) + this._rotatedLabelHeight + 12, p = f;
|
|
909
916
|
this._showLegend && (p = f + 20 + Math.max(this._legendHeight, 60));
|
|
910
|
-
let m = (this._height - e.y - e.height) / p, h = (
|
|
911
|
-
|
|
917
|
+
let m = (this._height - e.y - e.height) / p, h = (u ? 30 : 20) * m, g = e.y + e.height + h;
|
|
918
|
+
s.setAttribute("y", g.toString()), s.setAttribute("text-anchor", d), s.setAttribute("fill", "#6b7280"), s.setAttribute("font-size", "12"), u && s.setAttribute("transform", `rotate(-45 ${l} ${g})`), s.textContent = this._formatXAxisValue(t), document.documentElement.classList.contains("dark") && s.setAttribute("fill", "#9ca3af"), n.appendChild(s);
|
|
912
919
|
}
|
|
913
|
-
}), this._svg.appendChild(
|
|
920
|
+
}), this._svg.appendChild(n);
|
|
914
921
|
}
|
|
915
922
|
_buildMonotoneXLinePathD(e) {
|
|
916
923
|
let t = (e) => e < 0 ? -1 : 1, n = (e, n, r, i, a, o) => {
|
|
@@ -979,26 +986,26 @@ var t = class e extends HTMLElement {
|
|
|
979
986
|
}
|
|
980
987
|
_renderLineChart() {
|
|
981
988
|
if (!this._svg || !this._chartData) return;
|
|
982
|
-
let e = this._getChartBounds();
|
|
989
|
+
let e = this._getChartBounds(), t = this._hasOnlyZeroValues();
|
|
983
990
|
this._renderGrid(e);
|
|
984
|
-
let
|
|
985
|
-
|
|
986
|
-
let
|
|
987
|
-
this._chartData.datasets.forEach((
|
|
988
|
-
if (!this._isDatasetVisible(
|
|
989
|
-
let
|
|
991
|
+
let n = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
992
|
+
n.setAttribute("class", "chart-data");
|
|
993
|
+
let r = document.createDocumentFragment();
|
|
994
|
+
this._chartData.datasets.forEach((n, i) => {
|
|
995
|
+
if (!this._isDatasetVisible(n, i)) return;
|
|
996
|
+
let a = this._getDatasetColor(n, i), o = document.createElementNS("http://www.w3.org/2000/svg", "path"), s = n.data.map((t) => ({
|
|
990
997
|
x: this._scaleX(t.x, e),
|
|
991
998
|
y: this._scaleY(t.y, e)
|
|
992
999
|
}));
|
|
993
|
-
|
|
994
|
-
let o = document.createElementNS("http://www.w3.org/2000/svg", "circle"), s = this._scaleX(
|
|
995
|
-
o.setAttribute("cx", s.toString()), o.setAttribute("cy", c.toString()), o.setAttribute("r", "4"), o.setAttribute("fill",
|
|
1000
|
+
s.length !== 0 && (t || (o.setAttribute("d", this._buildSmoothLinePathD(s)), o.setAttribute("fill", "none"), o.setAttribute("stroke", a), o.setAttribute("stroke-width", "2"), o.setAttribute("stroke-linecap", "round"), o.setAttribute("stroke-linejoin", "round"), r.appendChild(o)), n.data.forEach((t) => {
|
|
1001
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "circle"), s = this._scaleX(t.x, e), c = this._scaleY(t.y, e);
|
|
1002
|
+
o.setAttribute("cx", s.toString()), o.setAttribute("cy", c.toString()), o.setAttribute("r", "4"), o.setAttribute("fill", a);
|
|
996
1003
|
let l = document.documentElement.classList.contains("dark");
|
|
997
|
-
o.setAttribute("stroke", l ? "#1f2937" : "#fff"), o.setAttribute("stroke-width", "2"), o.setAttribute("class", "chart-point"), o.setAttribute("data-dataset",
|
|
998
|
-
let u = String(
|
|
999
|
-
this._plotPoints.has(u) || this._plotPoints.set(u, []), this._plotPoints.get(u).push(o),
|
|
1004
|
+
o.setAttribute("stroke", l ? "#1f2937" : "#fff"), o.setAttribute("stroke-width", "2"), o.setAttribute("class", "chart-point"), o.setAttribute("data-dataset", i.toString()), o.setAttribute("data-x", String(t.x)), o.setAttribute("data-y", t.y.toString()), o.setAttribute("data-name", n.name), o.style.opacity = "0", o.style.pointerEvents = "none";
|
|
1005
|
+
let u = String(t.x);
|
|
1006
|
+
this._plotPoints.has(u) || this._plotPoints.set(u, []), this._plotPoints.get(u).push(o), r.appendChild(o);
|
|
1000
1007
|
}));
|
|
1001
|
-
}),
|
|
1008
|
+
}), n.appendChild(r), this._svg.appendChild(n);
|
|
1002
1009
|
}
|
|
1003
1010
|
_scaleXForBarChart(e, t) {
|
|
1004
1011
|
let n = this._getXValues();
|
|
@@ -1051,30 +1058,34 @@ var t = class e extends HTMLElement {
|
|
|
1051
1058
|
}
|
|
1052
1059
|
_renderAreaChart() {
|
|
1053
1060
|
if (!this._svg || !this._chartData) return;
|
|
1054
|
-
let e = this._getChartBounds();
|
|
1061
|
+
let e = this._getChartBounds(), t = this._hasOnlyZeroValues();
|
|
1055
1062
|
this._renderGrid(e);
|
|
1056
|
-
let
|
|
1057
|
-
|
|
1058
|
-
let
|
|
1059
|
-
this._chartData.datasets.forEach((
|
|
1060
|
-
if (!this._isDatasetVisible(
|
|
1061
|
-
let
|
|
1063
|
+
let n = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
1064
|
+
n.setAttribute("class", "chart-data");
|
|
1065
|
+
let r = document.createDocumentFragment();
|
|
1066
|
+
this._chartData.datasets.forEach((n, i) => {
|
|
1067
|
+
if (!this._isDatasetVisible(n, i)) return;
|
|
1068
|
+
let a = this._getDatasetColor(n, i), o = n.data.map((t) => ({
|
|
1062
1069
|
x: this._scaleX(t.x, e),
|
|
1063
1070
|
y: this._scaleY(t.y, e)
|
|
1064
1071
|
}));
|
|
1065
|
-
if (
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1072
|
+
if (o.length !== 0) {
|
|
1073
|
+
if (!t) {
|
|
1074
|
+
let t = e.y + e.height, n = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1075
|
+
n.setAttribute("d", this._buildAreaFillPathD(o, t)), n.setAttribute("fill", a), n.setAttribute("fill-opacity", "0.3"), r.appendChild(n);
|
|
1076
|
+
let i = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1077
|
+
i.setAttribute("d", this._buildSmoothLinePathD(o)), i.setAttribute("fill", "none"), i.setAttribute("stroke", a), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), r.appendChild(i);
|
|
1078
|
+
}
|
|
1079
|
+
n.data.forEach((t) => {
|
|
1080
|
+
let o = document.createElementNS("http://www.w3.org/2000/svg", "circle"), s = this._scaleX(t.x, e), c = this._scaleY(t.y, e);
|
|
1081
|
+
o.setAttribute("cx", s.toString()), o.setAttribute("cy", c.toString()), o.setAttribute("r", "4"), o.setAttribute("fill", a);
|
|
1082
|
+
let l = document.documentElement.classList.contains("dark");
|
|
1083
|
+
o.setAttribute("stroke", l ? "#1f2937" : "#fff"), o.setAttribute("stroke-width", "2"), o.setAttribute("class", "chart-point"), o.setAttribute("data-dataset", i.toString()), o.setAttribute("data-x", String(t.x)), o.setAttribute("data-y", t.y.toString()), o.setAttribute("data-name", n.name), o.style.opacity = "0", o.style.pointerEvents = "none";
|
|
1084
|
+
let u = String(t.x);
|
|
1085
|
+
this._plotPoints.has(u) || this._plotPoints.set(u, []), this._plotPoints.get(u).push(o), r.appendChild(o);
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
}), n.appendChild(r), this._svg.appendChild(n);
|
|
1078
1089
|
}
|
|
1079
1090
|
_renderPieChart() {
|
|
1080
1091
|
if (!this._svg || !this._chartData) return;
|
|
@@ -13,9 +13,9 @@ const __mintLoadStyle = (key, url) => {
|
|
|
13
13
|
__mintLoadStyle('theme', '../../theme.css')
|
|
14
14
|
__mintLoadStyle('icon', '../../icon.css')
|
|
15
15
|
__mintLoadStyle('checkbox', '../../checkbox.css')
|
|
16
|
-
import { a as e } from "../chunks/icon-
|
|
16
|
+
import { a as e } from "../chunks/icon-BWUYe89V.js";
|
|
17
17
|
import { t } from "../chunks/register-element-BFYmIynH.js";
|
|
18
|
-
import "../chunks/icon-
|
|
18
|
+
import "../chunks/icon-B8p3Co0-.js";
|
|
19
19
|
e({
|
|
20
20
|
name: "check",
|
|
21
21
|
viewBox: "0 0 24 24",
|