vue-data-ui-hq
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
10 lines (9 loc) • 36.4 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),u=require("./index-ZfICPrrM.cjs"),c=require("./useResponsive-BJ7DTGpm.cjs"),rt=require("./Tooltip-C7TJODUx.cjs"),nt=require("./Legend-HgHPyA_4.cjs"),ut=require("./Title-FbHK83tB.cjs"),st=require("./Slicer-CtTQxL9r.cjs"),Ee=require("./usePrinter-B-gh2f22.cjs"),it=require("./vue-ui-accordion-Dp6uTsJi.cjs"),ct=require("./DataTable-CC6dPSer.cjs"),vt=require("./vue-ui-skeleton-Bvmpr51u.cjs"),Ne=require("./useNestedProp-C14rfl0j.cjs"),ft=require("./PenAndPaper-PL3bp4ud.cjs"),dt=require("./useUserOptionState-BgepsfED.cjs"),ht=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),yt=["id"],gt=["onClick"],pt={key:2,class:"vue-data-ui-watermark"},mt=["innerHTML"],bt={__name:"vue-ui-xy-canvas",props:{dataset:{type:Array,default(){return[]}},config:{type:Object,default(){return{}}}},emits:["selectLegend"],setup(re,{expose:Be,emit:Fe}){const{vue_ui_xy_canvas:De}=u.useConfig(),p=re,Z=t.ref(u.createUid()),N=t.ref(null),S=t.ref(null),B=t.ref(null),i=t.ref(null),g=t.ref(1),T=t.ref(1),H=t.ref(!1),h=t.ref(null),V=t.ref(""),ne=t.ref(null),C=t.ref([]),O=t.ref(1),M=t.ref(!0),z=t.ref(!0),G=t.ref(null),ue=t.ref(0),se=t.ref(0),U=t.ref(!1),ie=t.ref(null),ce=t.ref(null),ve=t.ref(null),fe=t.ref(null),j=t.ref(0),J=t.ref(0),K=t.ref(0),Q=t.computed(()=>!!p.dataset&&p.dataset.length),Ae=Fe,He=t.useSlots();t.onMounted(()=>{He["chart-background"]&&console.warn("VueUiXyCanvas does not support the #chart-background slot.")});const l=t.computed({get:()=>ye(),set:e=>e}),{userOptionsVisible:ee,setUserOptionsVisibility:de,keepUserOptionState:he}=dt.useUserOptionState({config:l.value});function ye(){const e=Ne.useNestedProp({userConfig:p.config,defaultConfig:De});let a={};return e.theme?a={...Ne.useNestedProp({userConfig:u.themes.vue_ui_xy_canvas[e.theme]||p.config,defaultConfig:e}),customPalette:u.themePalettes[e.theme]||u.palette}:a=e,p.config&&u.hasDeepProperty(p.config,"style.chart.scale.min")?a.style.chart.scale.min=p.config.style.chart.scale.min:a.style.chart.scale.min=null,p.config&&u.hasDeepProperty(p.config,"style.chart.scale.max")?a.style.chart.scale.max=p.config.style.chart.scale.max:a.style.chart.scale.max=null,p.config&&u.hasDeepProperty(p.config,"style.chart.zoom.startIndex")?a.style.chart.zoom.startIndex=p.config.style.chart.zoom.startIndex:a.style.chart.zoom.startIndex=null,p.config&&u.hasDeepProperty(p.config,"style.chart.zoom.endIndex")?a.style.chart.zoom.endIndex=p.config.style.chart.zoom.endIndex:a.style.chart.zoom.endIndex=null,a}t.watch(()=>p.config,e=>{l.value=ye(),ee.value=!l.value.showOnChartHover,le(),j.value+=1,J.value+=1,K.value+=1},{deep:!0}),t.watch(()=>p.dataset,()=>{le(),j.value+=1,J.value+=1,K.value+=1},{deep:!0});const ge=t.ref(l.value.style.chart.aspectRatio),{isPrinting:pe,isImaging:me,generatePdf:be,generateImage:xe}=Ee.usePrinter({elementId:`xy_canvas_${Z.value}`,fileName:l.value.style.chart.title.text||"vue-ui-xy-canvas"}),s=t.ref({showTable:l.value.table.show,showDataLabels:l.value.style.chart.dataLabels.show,stacked:l.value.style.chart.stacked,showTooltip:l.value.style.chart.tooltip.show});function Ve(e){U.value=e,se.value+=1}const ke=t.computed(()=>u.convertCustomPalette(l.value.customPalette)),w=t.computed(()=>R.value?Math.max(...R.value.filter((e,a)=>!C.value.includes(e.absoluteIndex)).map(e=>e.series.length)):0),o=t.computed(()=>{const e=g.value-g.value*(l.value.style.chart.paddingProportions.left+l.value.style.chart.paddingProportions.right);return{canvasWidth:g.value,canvasHeight:T.value,left:g.value*l.value.style.chart.paddingProportions.left,top:T.value*l.value.style.chart.paddingProportions.top,right:g.value-g.value*l.value.style.chart.paddingProportions.right,bottom:T.value-T.value*l.value.style.chart.paddingProportions.bottom,width:e,height:T.value-T.value*(l.value.style.chart.paddingProportions.top+l.value.style.chart.paddingProportions.bottom),slot:e/(n.value.end-n.value.start)}});function Le(e,a){return e/a}function Ue({hasAutoScale:e,series:a,min:r,max:f,scale:d,yOffset:m,individualHeight:v,stackIndex:b=null}){return a.map((L,oe)=>{const $=d.min<0?Math.abs(d.min):0,I=Le(L+$,$+d.max);let P,F;e&&(P=Math.abs(d.min),F=Le(L+P,d.max+P));let D=0;return b===null?D=o.value.bottom-o.value.height*(e?F:I):D=o.value.bottom-m-v*(e?F:I),{x:o.value.left+o.value.slot*oe+o.value.slot/2,y:D,value:L}})}const x=t.computed(()=>{const e=l.value.style.chart.scale.min!==null?l.value.style.chart.scale.min:Math.min(...R.value.filter((v,b)=>!C.value.includes(v.absoluteIndex)).flatMap(v=>v.series.slice(n.value.start,n.value.end))),a=l.value.style.chart.scale.max!==null?l.value.style.chart.scale.max:Math.max(...R.value.filter((v,b)=>!C.value.includes(v.absoluteIndex)).flatMap(v=>v.series.slice(n.value.start,n.value.end))),r=u.calculateNiceScale(e<0?e:0,a===e?e+1<0?0:e+1:a<0?0:a,l.value.style.chart.scale.ticks),f=r.min<0?Math.abs(r.min):0,d=o.value.bottom-o.value.height*(f/(r.max+f)),m=r.ticks.map(v=>({y:o.value.bottom-o.value.height*((v+f)/(r.max+f)),x:o.value.left-8,value:v}));return{absoluteMin:f,max:a,min:e,scale:r,yLabels:m,zero:d}}),_e=t.computed(()=>y.value.map(e=>`
<div style="display:flex;flex-direction:row;gap:6px;align-items:center;">
<svg viewBox="0 0 10 10" height="12" width="12">
<circle cx="5" cy="5" r="5" fill="${e.color}"/>
</svg>
<span>${e.name?e.name+": ":""}</span>
<span>${u.applyDataLabel(l.value.style.chart.dataLabels.formatter,e.series[h.value],u.dataLabel({p:e.prefix||"",v:e.series[h.value],s:e.suffix||"",r:e.rounding||0}),{datapoint:e,seriesIndex:h.value})}</span>
</div>
`)),R=t.computed(()=>p.dataset.map((e,a)=>({...e,series:u.largestTriangleThreeBucketsArray({data:u.sanitizeArray(e.series),threshold:l.value.downsample.threshold}),absoluteIndex:a,color:u.convertColorToHex(e.color||ke.value[a]||u.palette[a]||u.palette[a%u.palette.length])})));t.watch(w,e=>{e&&Ce()});const y=t.computed(()=>u.assignStackRatios(R.value.filter((e,a)=>!C.value.includes(e.absoluteIndex))).map((e,a)=>({...e,series:e.series.slice(n.value.start,n.value.end)})).map((e,a)=>{let r=[null,void 0].includes(e.scaleMin)?Math.min(...e.series)||0:e.scaleMin,f=[null,void 0].includes(e.scaleMax)?Math.max(...e.series)||1:e.scaleMax;r===f&&(r=r>=0?f-1:r,f=f>=0?f:r+1);const m={ratios:e.series.filter(A=>![null,void 0].includes(A)).map(A=>(A-r)/(f-r)),valueMin:r,valueMax:f},v=e.scaleSteps||l.value.style.chart.scale.ticks;let b;e.autoScaling?b=u.calculateNiceScale(m.valueMin,m.valueMax,v):b=u.calculateNiceScale(m.valueMin<0?m.valueMin:0,m.valueMax<=0?0:m.valueMax,v);const L=s.value.stacked?o.value.height*(1-e.cumulatedStackRatio):0,oe=s.value.stacked?o.value.height/l.value.style.chart.stackGap:0,$=s.value.stacked?o.value.height*e.stackRatio-oe:o.value.height,I=b.min<0?Math.abs(b.min):0;let P;e.autoScaling&&s.value.stacked&&f<=0?P=o.value.bottom-L-$:P=o.value.bottom-L-$*(I/(b.max+I));const F=b.ticks.map((A,ot)=>({y:o.value.bottom-L-$*(ot/(b.ticks.length-1)),x:o.value.left-8,value:A})),D=Ue({hasAutoScale:s.value.stacked&&e.autoScaling,series:e.series,min:s.value.stacked?r:x.value.min,max:s.value.stacked?f:x.value.max,scale:s.value.stacked?b:x.value.scale,yOffset:L,individualHeight:$,stackIndex:s.value.stacked?a:null});return{...e,coordinatesLine:D,min:r,max:f,localScale:b,localZero:P,localMin:I,localYLabels:F,yOffset:L,individualHeight:$}})),n=t.ref({start:0,end:w.value});function Ce(){we()}const E=t.ref(null);async function we(){(l.value.style.chart.zoom.startIndex!==null||l.value.style.chart.zoom.endIndex!==null)&&E.value?(l.value.style.chart.zoom.startIndex!==null&&(await t.nextTick(),await t.nextTick(),E.value&&E.value.setStartValue(l.value.style.chart.zoom.startIndex)),l.value.style.chart.zoom.endIndex!==null&&(await t.nextTick(),await t.nextTick(),E.value&&E.value.setEndValue(qe(l.value.style.chart.zoom.endIndex+1)))):(n.value={start:0,end:w.value},ue.value+=1)}function qe(e){const a=w.value;return e>a?a:e<0||l.value.style.chart.zoom.startIndex!==null&&e<l.value.style.chart.zoom.startIndex?l.value.style.chart.zoom.startIndex!==null?l.value.style.chart.zoom.startIndex+1:1:e}const We=t.computed(()=>y.value.filter(e=>["line","plot",void 0].includes(e.type))),k=t.computed(()=>y.value.filter(e=>e.type==="bar"));function Xe(){if(!S.value)return;const e=B.value.offsetWidth,a=B.value.offsetHeight;S.value.width=e*O.value*2,S.value.height=a*O.value*2,g.value=e*O.value*2,T.value=a*O.value*2,i.value.scale(O.value,O.value),te()}function Ye(){if(i.value.clearRect(0,0,1e4,1e4),i.value.fillStyle=l.value.style.chart.backgroundColor,i.value.fillRect(0,0,o.value.canvasWidth,o.value.canvasHeight),s.value.stacked)l.value.style.chart.grid.y.verticalLines.show&&n.value.end-n.value.start<l.value.style.chart.grid.y.verticalLines.hideUnderXLength?y.value.forEach(e=>{for(let a=0;a<n.value.end-n.value.start+1;a+=1)c.line(i.value,[{x:o.value.left+o.value.slot*a,y:o.value.bottom-e.yOffset-e.individualHeight},{x:o.value.left+o.value.slot*a,y:o.value.bottom-e.yOffset}],{color:l.value.style.chart.grid.y.verticalLines.color})}):l.value.style.chart.grid.y.verticalLines.show&&n.value.end-n.value.start>=l.value.style.chart.grid.y.verticalLines.hideUnderXLength&&y.value.forEach(e=>{for(let a=n.value.start;a<n.value.end;a+=1)a%Math.floor((n.value.end-n.value.start)/l.value.style.chart.grid.y.timeLabels.modulo)===0&&c.line(i.value,[{x:o.value.left+o.value.slot*(a-n.value.start)+o.value.slot/2,y:o.value.bottom-e.yOffset-e.individualHeight},{x:o.value.left+o.value.slot*(a-n.value.start)+o.value.slot/2,y:o.value.bottom-e.yOffset}],{color:l.value.style.chart.grid.y.verticalLines.color})}),l.value.style.chart.grid.x.horizontalLines.show&&(l.value.style.chart.grid.x.horizontalLines.alternate?y.value.forEach(e=>{e.localYLabels.forEach((a,r)=>{r<e.localYLabels.length-1&&c.rect(i.value,[{x:o.value.left,y:a.y},{x:o.value.right,y:a.y},{x:o.value.right,y:e.localYLabels[r+1].y},{x:o.value.left,y:e.localYLabels[r+1].y}],{fillColor:r%2===0?"transparent":u.setOpacity(l.value.style.chart.grid.x.horizontalLines.color,l.value.style.chart.grid.x.horizontalLines.opacity),strokeColor:"transparent"})})}):y.value.forEach(e=>{e.localYLabels.slice(n.value.start,n.value.end).forEach(a=>{c.line(i.value,[{x:o.value.left,y:a.y},{x:o.value.right,y:a.y}],{color:l.value.style.chart.grid.x.horizontalLines.color})})})),l.value.style.chart.grid.zeroLine.show&&y.value.forEach(e=>{c.line(i.value,[{x:o.value.left,y:e.localZero},{x:o.value.right,y:e.localZero}],{color:l.value.style.chart.grid.zeroLine.color,lineDash:l.value.style.chart.grid.zeroLine.dashed?[10,10]:[0,0]})}),l.value.style.chart.grid.y.axisLabels.show&&y.value.forEach(e=>{c.line(i.value,[{x:o.value.left,y:o.value.bottom-e.yOffset},{x:o.value.left,y:o.value.bottom-e.yOffset-e.individualHeight}],{color:e.color}),c.line(i.value,[{x:o.value.right,y:o.value.bottom-e.yOffset},{x:o.value.right,y:o.value.bottom-e.yOffset-e.individualHeight}],{color:e.color}),e.localYLabels.forEach((a,r)=>{c.text(i.value,u.applyDataLabel(l.value.style.chart.dataLabels.formatter,a.value,u.dataLabel({p:e.prefix||l.value.style.chart.grid.y.axisLabels.prefix||"",v:a.value,s:e.suffix||l.value.style.chart.grid.y.axisLabels.suffix||"",r:e.rounding||l.value.style.chart.grid.y.axisLabels.rounding||0}),{datapoint:a,seriesIndex:r}),a.x+l.value.style.chart.grid.y.axisLabels.offsetX,a.y,{align:"right",font:`${Math.round(g.value/40*l.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:e.color})})}),y.value.forEach(e=>{c.text(i.value,e.name,g.value/35,o.value.bottom-e.yOffset-e.individualHeight/2,{align:"center",rotation:-90,color:e.color,font:`${Math.round(g.value/40*l.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`})});else{if(l.value.style.chart.grid.y.verticalLines.show&&n.value.end-n.value.start<l.value.style.chart.grid.y.verticalLines.hideUnderXLength)for(let e=0;e<n.value.end-n.value.start+1;e+=1)c.line(i.value,[{x:o.value.left+o.value.slot*e,y:o.value.top},{x:o.value.left+o.value.slot*e,y:o.value.bottom}],{color:l.value.style.chart.grid.y.verticalLines.color});else if(l.value.style.chart.grid.y.verticalLines.show&&n.value.end-n.value.start>=l.value.style.chart.grid.y.verticalLines.hideUnderXLength)for(let e=n.value.start;e<n.value.end;e+=1)e%Math.floor((n.value.end-n.value.start)/l.value.style.chart.grid.y.timeLabels.modulo)===0&&c.line(i.value,[{x:o.value.left+o.value.slot*(e-n.value.start)+o.value.slot/2,y:o.value.top},{x:o.value.left+o.value.slot*(e-n.value.start)+o.value.slot/2,y:o.value.bottom}],{color:l.value.style.chart.grid.y.verticalLines.color});l.value.style.chart.grid.x.horizontalLines.show&&(l.value.style.chart.grid.x.horizontalLines.alternate?x.value.yLabels.forEach((e,a)=>{a<x.value.yLabels.length-1&&c.rect(i.value,[{x:o.value.left,y:e.y},{x:o.value.right,y:e.y},{x:o.value.right,y:x.value.yLabels[a+1].y},{x:o.value.left,y:x.value.yLabels[a+1].y}],{fillColor:a%2===0?"transparent":u.setOpacity(l.value.style.chart.grid.x.horizontalLines.color,l.value.style.chart.grid.x.horizontalLines.opacity),strokeColor:"transparent"})}):x.value.yLabels.forEach(e=>{c.line(i.value,[{x:o.value.left,y:e.y},{x:o.value.right,y:e.y}],{color:l.value.style.chart.grid.x.horizontalLines.color})})),l.value.style.chart.grid.y.showAxis&&c.line(i.value,[{x:o.value.left,y:o.value.top},{x:o.value.left,y:o.value.bottom}],{color:l.value.style.chart.grid.y.axisColor,lineWidth:l.value.style.chart.grid.y.axisThickness}),l.value.style.chart.grid.x.showAxis&&c.line(i.value,[{x:o.value.left,y:o.value.bottom},{x:o.value.right,y:o.value.bottom}],{color:l.value.style.chart.grid.x.axisColor,lineWidth:l.value.style.chart.grid.x.axisThickness}),l.value.style.chart.grid.zeroLine.show&&c.line(i.value,[{x:o.value.left,y:x.value.zero},{x:o.value.right,y:x.value.zero}],{color:l.value.style.chart.grid.zeroLine.color,lineDash:l.value.style.chart.grid.zeroLine.dashed?[10,10]:[0,0]}),l.value.style.chart.grid.y.axisLabels.show&&x.value.yLabels.forEach((e,a)=>{c.text(i.value,u.applyDataLabel(l.value.style.chart.dataLabels.formatter,e.value,u.dataLabel({p:l.value.style.chart.grid.y.axisLabels.prefix||"",v:e.value,s:l.value.style.chart.grid.y.axisLabels.suffix||"",r:l.value.style.chart.grid.y.axisLabels.rounding||0}),{datapoint:e,seriesIndex:a}),e.x+l.value.style.chart.grid.y.axisLabels.offsetX,e.y,{align:"right",font:`${Math.round(g.value/40*l.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:l.value.style.chart.grid.y.axisLabels.color})})}l.value.style.chart.grid.y.axisName&&c.text(i.value,l.value.style.chart.grid.y.axisName,g.value-g.value/40*l.value.style.chart.grid.y.axisLabels.fontSizeRatio*1.2,o.value.bottom-o.value.height/2,{font:`${Math.round(g.value/40*l.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:l.value.style.chart.color,align:"center",rotation:90}),l.value.style.chart.grid.x.axisName&&c.text(i.value,l.value.style.chart.grid.x.axisName,g.value/2,T.value,{font:`${Math.round(g.value/40*l.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:l.value.style.chart.color,align:"center"})}function Ze(e){for(let a=0;a<e.coordinatesLine.length;a+=1){const r=(h.value===a?g.value/150:l.value.style.chart.line.plots.show?g.value/200:0)*l.value.style.chart.line.plots.radiusRatio;c.circle(i.value,{x:e.coordinatesLine[a].x,y:e.coordinatesLine[a].y},r,{color:l.value.style.chart.backgroundColor,fillStyle:e.color,strokeColor:"transparent"})}}function Ge(e){for(let a=0;a<e.coordinatesLine.length;a+=1)c.text(i.value,u.applyDataLabel(l.value.style.chart.dataLabels.formatter,e.coordinatesLine[a].value,u.dataLabel({p:e.prefix||"",v:e.coordinatesLine[a].value,s:e.suffix||"",r:e.rounding||0}),{datapoint:e.coordinatesLine[a],seriesIndex:a}),e.coordinatesLine[a].x,e.coordinatesLine[a].y+l.value.style.chart.dataLabels.offsetY,{align:"center",font:`${Math.round(g.value/40*l.value.style.chart.dataLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:l.value.style.chart.dataLabels.useSerieColor?e.color:l.value.style.chart.dataLabels.color,strokeColor:l.value.style.chart.backgroundColor,lineWidth:.8})}function je(){for(let e=n.value.start;e<n.value.end;e+=1)(n.value.end-n.value.start<l.value.style.chart.grid.y.timeLabels.modulo||n.value.end-n.value.start>=l.value.style.chart.grid.y.timeLabels.modulo&&(e%Math.floor((n.value.end-n.value.start)/l.value.style.chart.grid.y.timeLabels.modulo)===0||e===h.value+n.value.start))&&c.text(i.value,l.value.style.chart.grid.y.timeLabels.values[e]||e+1,o.value.left+o.value.slot*(e-n.value.start)+o.value.slot/2,o.value.bottom+g.value/l.value.style.chart.grid.y.timeLabels.offsetY,{align:l.value.style.chart.grid.y.timeLabels.rotation===0?"center":l.value.style.chart.grid.y.timeLabels.rotation>0?"left":"right",font:`${Math.round(g.value/40*l.value.style.chart.grid.y.timeLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:u.setOpacity(l.value.style.chart.grid.y.timeLabels.color,h.value!==null?h.value+n.value.start===e?100:20:100),rotation:l.value.style.chart.grid.y.timeLabels.rotation})}function Se(){c.line(i.value,[{x:o.value.left+o.value.slot*h.value+o.value.slot/2,y:o.value.top},{x:o.value.left+o.value.slot*h.value+o.value.slot/2,y:o.value.bottom}],{color:l.value.style.chart.selector.color,lineDash:l.value.style.chart.selector.dashed?[8,8]:[0,0],lineWidth:2,linceCap:"round"})}function Je(){k.value.forEach((e,a)=>{for(let r=0;r<e.coordinatesLine.length;r+=1)c.rect(i.value,[{x:o.value.left+o.value.slot*r+o.value.slot/10+(s.value.stacked?0:o.value.slot/k.value.length*a-(a===0?0:o.value.slot/(5*k.value.length)*a)),y:s.value.stacked?e.localZero:x.value.zero},{x:o.value.left+o.value.slot*r+o.value.slot/10+(s.value.stacked?0:o.value.slot/k.value.length*a-(a===0?0:o.value.slot/(5*k.value.length)*a))+o.value.slot*.8/(s.value.stacked?1:k.value.length),y:s.value.stacked?e.localZero:x.value.zero},{x:o.value.left+o.value.slot*r+o.value.slot/10+(s.value.stacked?0:o.value.slot/k.value.length*a-(a===0?0:o.value.slot/(5*k.value.length)*a))+o.value.slot*.8/(s.value.stacked?1:k.value.length),y:e.coordinatesLine[r].y},{x:o.value.left+o.value.slot*r+o.value.slot/10+(s.value.stacked?0:o.value.slot/k.value.length*a-(a===0?0:o.value.slot/(5*k.value.length)*a)),y:e.coordinatesLine[r].y}],{strokeColor:l.value.style.chart.backgroundColor,gradient:{type:"linear",start:{x:e.coordinatesLine[r].x,y:e.coordinatesLine[r].y},end:{x:e.coordinatesLine[r].x,y:s.value.stacked?e.localZero:x.value.zero},stops:[{offset:0,color:e.color},{offset:1,color:u.lightenHexColor(e.color,.5)}]}}),s.value.showDataLabels&&[!0,void 0].includes(e.dataLabels)&&c.text(i.value,u.applyDataLabel(l.value.style.chart.dataLabels.formatter,e.coordinatesLine[r].value,u.dataLabel({p:e.prefix||"",v:e.coordinatesLine[r].value,s:e.suffix||"",r:e.rounding||0}),{datapoint:e.coordinatesLine[r],seriesIndex:r}),o.value.left+o.value.slot*r+o.value.slot/10+(s.value.stacked?0:o.value.slot/k.value.length*a-(a===0?0:o.value.slot/(5*k.value.length)*a))+o.value.slot*.4/(s.value.stacked?1:k.value.length),(e.coordinatesLine[r].value<0?s.value.stacked?e.localZero:x.value.zero:e.coordinatesLine[r].y)+l.value.style.chart.dataLabels.offsetY,{align:"center",font:`${Math.round(g.value/40*l.value.style.chart.dataLabels.fontSizeRatio)}px ${l.value.style.fontFamily}`,color:l.value.style.chart.dataLabels.useSerieColor?e.color:l.value.style.chart.dataLabels.color,strokeColor:l.value.style.chart.backgroundColor,lineWidth:.8})})}function Ke(e){e.useArea?s.value.stacked?c.polygon(i.value,[{x:e.coordinatesLine[0].x,y:e.localZero},...e.coordinatesLine,{x:e.coordinatesLine.at(-1).x,y:e.localZero}],{fillColor:u.setOpacity(e.color,l.value.style.chart.area.opacity),strokeColor:"transparent"}):c.polygon(i.value,[{x:e.coordinatesLine[0].x,y:x.value.zero},...e.coordinatesLine,{x:e.coordinatesLine.at(-1).x,y:x.value.zero}],{fillColor:u.setOpacity(e.color,l.value.style.chart.area.opacity),strokeColor:"transparent"}):c.line(i.value,e.coordinatesLine,{color:e.color,lineWidth:3})}function Qe(){y.value.forEach((e,a)=>{c.line(i.value,[{x:o.value.left,y:o.value.bottom-e.yOffset},{x:o.value.right,y:o.value.bottom-e.yOffset}],{color:l.value.style.chart.grid.x.horizontalLines.color,lineWidth:1})})}function te(){Ye(),M.value?(z.value&&h.value!==null&&l.value.style.chart.selector.show&&Se(),Je(),s.value.stacked&&l.value.style.chart.grid.x.showAxis&&Qe(),We.value.forEach(e=>{(e.type==="line"||!e.type)&&Ke(e),z.value&&(Ze(e),s.value.showDataLabels&&[!0,void 0].includes(e.dataLabels)&&Ge(e))}),G.value=c.cloneCanvas(S.value)):(G.value&&(i.value.clearRect(0,0,1e4,1e4),i.value.drawImage(G.value,0,0)),z.value&&h.value!==null&&l.value.style.chart.selector.show&&Se(),z.value&&h.value!==null&&y.value.forEach(e=>{if(e.type==="line"||!e.type||e.type==="plot"){if(!e.coordinatesLine[h.value])return;e.coordinatesLine[h.value].x!==void 0&&e.coordinatesLine[h.value].y!==void 0&&c.circle(i.value,{x:e.coordinatesLine[h.value].x,y:e.coordinatesLine[h.value].y},g.value/150*l.value.style.chart.line.plots.radiusRatio,{color:l.value.style.chart.backgroundColor,fillStyle:e.color,strokeColor:"transparent"})}})),l.value.style.chart.grid.y.timeLabels.show&&je(),M.value=!1}const _=c.debounce(()=>{z.value=!0,Xe()},w.value>200?10:1,!z.value);function et(e){const{left:a}=S.value.getBoundingClientRect(),r=e.clientX-a;if(r*2<o.value.left||r*2>o.value.right){H.value=!1,h.value=null;return}const f=r*2-o.value.left;if(h.value=Math.floor(f/o.value.slot),H.value=!0,!z.value)return;let d="";const m=l.value.style.chart.tooltip.customFormat;u.isFunction(m)&&u.functionReturnsString(()=>m({seriesIndex:h.value,datapoint:y.value.map(v=>({shape:v.shape||null,name:v.name,color:v.color,type:v.type||"line",value:v.series.find((b,L)=>L===h.value)})),series:y.value,config:l.value}))?V.value=m({seriesIndex:h.value,datapoint:y.value.map(v=>({shape:v.shape||null,name:v.name,color:v.color,type:v.type||"line",value:v.series.find((b,L)=>L===h.value)})),series:y.value,config:l.value}):(l.value.style.chart.grid.y.timeLabels.values.slice(n.value.start,n.value.end)[h.value]&&(d+=`<div style="padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid ${l.value.style.chart.tooltip.borderColor}; width:100%">${l.value.style.chart.grid.y.timeLabels.values.slice(n.value.start,n.value.end)[h.value]}</div>`),d+=_e.value.join(""),V.value=d),z.value=!1}t.watch(()=>h.value,e=>{_()}),t.watch(()=>n.value,e=>{M.value=!0,te()},{deep:!0}),t.watch(()=>s.value.showDataLabels,e=>{M.value=!0,te()}),t.watch(()=>s.value.stacked,e=>{M.value=!0,z.value=!0,_()});function tt(){H.value=!1,h.value=null,V.value=""}const q=t.ref(null),W=t.ref(null);t.onMounted(()=>{le()});function le(){if(u.objectIsEmpty(p.dataset)?u.error({componentName:"VueUiXyCanvas",type:"dataset"}):S.value&&(i.value=S.value.getContext("2d",{willReadFrequently:!0})),l.value.responsive){const e=c.throttle(()=>{const{width:a,height:r}=c.useResponsive({chart:N.value,title:l.value.style.chart.title.text?ie.value:null,legend:l.value.style.chart.legend.show?ce.value:null,slicer:l.value.style.chart.zoom.show&&w.value>1?ve.value:null,source:fe.value});ge.value=`${a} / ${r}`});q.value=new ResizeObserver(e),q.value.observe(N.value.parentNode)}W.value=new ResizeObserver(e=>{for(const a of e)a.contentBoxSize&&B.value&&(M.value=!0,_())}),W.value.observe(B.value),we()}t.onBeforeUnmount(()=>{W.value&&W.value.disconnect(),q.value&&q.value.disconnect()});function ze(e){Ae("selectLegend",y.value.find(a=>a.absoluteIndex===e)),C.value.includes(e)?C.value=C.value.filter(a=>a!==e):C.value.push(e),M.value=!0,_()}const $e=t.computed(()=>R.value.map((e,a)=>({...e,name:e.name,color:u.convertColorToHex(e.color)||ke.value[a]||u.palette[a]||u.palette[a%u.palette.length],shape:e.shape||"circle",prefix:e.prefix||"",suffix:e.suffix||"",rounding:e.rounding||0})).map(e=>({...e,opacity:C.value.includes(e.absoluteIndex)?.5:1,segregate:()=>ze(e.absoluteIndex),isSegregated:C.value.includes(e.absoluteIndex)}))),lt=t.computed(()=>({cy:"donut-div-legend",backgroundColor:l.value.style.chart.legend.backgroundColor,color:l.value.style.chart.legend.color,fontSize:l.value.style.chart.legend.fontSize,paddingBottom:12,fontWeight:l.value.style.chart.legend.bold?"bold":""})),X=t.computed(()=>{const e=[""].concat(y.value.map(d=>d.name)).concat(' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>');let a=[];for(let d=0;d<w.value;d+=1){const m=y.value.map(v=>v.series[d]??0).reduce((v,b)=>v+b,0);a.push([l.value.style.chart.grid.y.timeLabels.values.slice(n.value.start,n.value.end)[d]??d+1].concat(y.value.map(v=>(v.series[d]??0).toFixed(l.value.table.rounding))).concat((m??0).toFixed(l.value.table.rounding)))}const r={th:{backgroundColor:l.value.table.th.backgroundColor,color:l.value.table.th.color,outline:l.value.table.th.outline},td:{backgroundColor:l.value.table.td.backgroundColor,color:l.value.table.td.color,outline:l.value.table.td.outline},breakpoint:l.value.table.responsiveBreakpoint},f=[l.value.table.columnNames.period].concat(y.value.map(d=>d.name)).concat(l.value.table.columnNames.total);return{head:e,body:a.slice(0,n.value.end-n.value.start),config:r,colNames:f}}),Te=t.computed(()=>{if(y.value.length===0)return{head:[],body:[],config:{},columnNames:[]};const e=y.value.map(r=>({label:r.name,color:r.color,type:r.type})),a=[];for(let r=n.value.start;r<n.value.end;r+=1){const f=[l.value.style.chart.grid.y.timeLabels.values[r]||r+1];y.value.forEach(d=>{f.push(Number((d.series[r]||0).toFixed(l.value.table.rounding)))}),a.push(f)}return{head:e,body:a}});function Ie(){const e=[[l.value.style.chart.title.text],[l.value.style.chart.title.subtitle.text],[""]],a=["",...Te.value.head.map(m=>m.label)],r=Te.value.body,f=e.concat([a]).concat(r),d=u.createCsvContent(f);u.downloadCsv({csvContent:d,title:l.value.style.chart.title.text||"vue-ui-xy-canvas"})}function at(){return y.value}function Pe(){s.value.showTable=!s.value.showTable}function Me(){s.value.showDataLabels=!s.value.showDataLabels}function Oe(){s.value.stacked=!s.value.stacked}function Re(){s.value.showTooltip=!s.value.showTooltip}const Y=t.ref(!1);function ae(){Y.value=!Y.value}return Be({getData:at,generateCsv:Ie,generatePdf:be,generateImage:xe,toggleTable:Pe,toggleLabels:Me,toggleStack:Oe,toggleTooltip:Re,toggleAnnotator:ae}),(e,a)=>(t.openBlock(),t.createElementBlock("div",{style:t.normalizeStyle(`width:100%; position:relative; ${t.unref(l).responsive?"height: 100%":""}`),ref_key:"xy",ref:N,id:`xy_canvas_${t.unref(Z)}`,class:t.normalizeClass(`vue-ui-donut ${t.unref(U)?"vue-data-ui-wrapper-fullscreen":""}`),onMouseenter:a[5]||(a[5]=()=>t.unref(de)(!0)),onMouseleave:a[6]||(a[6]=()=>t.unref(de)(!1))},[t.unref(l).style.chart.title.text?(t.openBlock(),t.createElementBlock("div",{key:0,ref_key:"chartTitle",ref:ie,style:t.normalizeStyle(`width:100%;background:${t.unref(l).style.chart.backgroundColor};`)},[(t.openBlock(),t.createBlock(ut._sfc_main,{key:`title_${t.unref(j)}`,config:{title:{cy:"xy-canvas-title",...t.unref(l).style.chart.title},subtitle:{cy:"xy-canvas-subtitle",...t.unref(l).style.chart.title.subtitle}}},null,8,["config"]))],4)):t.createCommentVNode("",!0),t.unref(l).userOptions.show&&t.unref(Q)&&(t.unref(he)||t.unref(ee))?(t.openBlock(),t.createBlock(Ee.UserOptions,{ref:"details",key:`user_option_${t.unref(se)}`,backgroundColor:t.unref(l).style.chart.backgroundColor,color:t.unref(l).style.chart.color,isPrinting:t.unref(pe),isImaging:t.unref(me),uid:t.unref(Z),hasTooltip:t.unref(l).userOptions.buttons.tooltip&&t.unref(l).style.chart.tooltip.show,hasPdf:t.unref(l).userOptions.buttons.pdf,hasImg:t.unref(l).userOptions.buttons.img,hasXls:t.unref(l).userOptions.buttons.csv,hasLabel:t.unref(l).userOptions.buttons.labels,hasStack:re.dataset.length>1&&t.unref(l).userOptions.buttons.stack,hasFullscreen:t.unref(l).userOptions.buttons.fullscreen,hasTable:t.unref(n).end-t.unref(n).start<200&&t.unref(l).userOptions.buttons.table,isFullscreen:t.unref(U),isTooltip:t.unref(s).showTooltip,isStacked:t.unref(s).stacked,titles:{...t.unref(l).userOptions.buttonTitles},chartElement:t.unref(N),position:t.unref(l).userOptions.position,hasAnnotator:t.unref(l).userOptions.buttons.annotator,isAnnotation:t.unref(Y),onToggleFullscreen:Ve,onGeneratePdf:t.unref(be),onGenerateCsv:Ie,onGenerateImage:t.unref(xe),onToggleTable:Pe,onToggleLabels:Me,onToggleStack:Oe,onToggleTooltip:Re,onToggleAnnotator:ae,style:t.normalizeStyle({visibility:t.unref(he)?t.unref(ee)?"visible":"hidden":"visible"})},t.createSlots({_:2},[e.$slots.optionTooltip?{name:"optionTooltip",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionTooltip",{},void 0,!0)]),key:"0"}:void 0,e.$slots.optionPdf?{name:"optionPdf",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionPdf",{},void 0,!0)]),key:"1"}:void 0,e.$slots.optionCsv?{name:"optionCsv",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionCsv",{},void 0,!0)]),key:"2"}:void 0,e.$slots.optionImg?{name:"optionImg",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionImg",{},void 0,!0)]),key:"3"}:void 0,e.$slots.optionTable?{name:"optionTable",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionTable",{},void 0,!0)]),key:"4"}:void 0,e.$slots.optionLabels?{name:"optionLabels",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionLabels",{},void 0,!0)]),key:"5"}:void 0,e.$slots.optionStack?{name:"optionStack",fn:t.withCtx(()=>[t.renderSlot(e.$slots,"optionStack",{},void 0,!0)]),key:"6"}:void 0,e.$slots.optionFullscreen?{name:"optionFullscreen",fn:t.withCtx(({toggleFullscreen:r,isFullscreen:f})=>[t.renderSlot(e.$slots,"optionFullscreen",t.normalizeProps(t.guardReactiveProps({toggleFullscreen:r,isFullscreen:f})),void 0,!0)]),key:"7"}:void 0,e.$slots.optionAnnotator?{name:"optionAnnotator",fn:t.withCtx(({toggleAnnotator:r,isAnnotator:f})=>[t.renderSlot(e.$slots,"optionAnnotator",t.normalizeProps(t.guardReactiveProps({toggleAnnotator:r,isAnnotator:f})),void 0,!0)]),key:"8"}:void 0]),1032,["backgroundColor","color","isPrinting","isImaging","uid","hasTooltip","hasPdf","hasImg","hasXls","hasLabel","hasStack","hasFullscreen","hasTable","isFullscreen","isTooltip","isStacked","titles","chartElement","position","hasAnnotator","isAnnotation","onGeneratePdf","onGenerateImage","style"])):t.createCommentVNode("",!0),t.createElementVNode("div",{class:"vue-ui-xy-canvas",style:t.normalizeStyle(`position: relative; aspect-ratio: ${t.unref(ge)}`),ref_key:"container",ref:B},[t.unref(Q)?(t.openBlock(),t.createElementBlock("canvas",{key:0,ref_key:"canvas",ref:S,style:{width:"100%",height:"100%"},onMousemove:a[0]||(a[0]=r=>et(r)),onMouseleave:tt},null,544)):(t.openBlock(),t.createBlock(vt.default,{key:1,config:{type:"line",style:{backgroundColor:t.unref(l).style.chart.backgroundColor,line:{axis:{color:"#CCCCCC"},path:{color:"#CCCCCC",strokeWidth:.5}}}}},null,8,["config"])),t.createVNode(rt._sfc_main,{show:t.unref(s).showTooltip&&t.unref(H),backgroundColor:t.unref(l).style.chart.tooltip.backgroundColor,color:t.unref(l).style.chart.tooltip.color,fontSize:t.unref(l).style.chart.tooltip.fontSize,borderRadius:t.unref(l).style.chart.tooltip.borderRadius,borderColor:t.unref(l).style.chart.tooltip.borderColor,borderWidth:t.unref(l).style.chart.tooltip.borderWidth,position:t.unref(l).style.chart.tooltip.position,offsetY:t.unref(l).style.chart.tooltip.offsetY,parent:t.unref(S),content:t.unref(V),isFullscreen:t.unref(U),backgroundOpacity:t.unref(l).style.chart.tooltip.backgroundOpacity,isCustom:t.unref(u.isFunction)(t.unref(l).style.chart.tooltip.customFormat)},{"tooltip-before":t.withCtx(()=>[t.renderSlot(e.$slots,"tooltip-before",t.normalizeProps(t.guardReactiveProps({...t.unref(ne)})),void 0,!0)]),"tooltip-after":t.withCtx(()=>[t.renderSlot(e.$slots,"tooltip-after",t.normalizeProps(t.guardReactiveProps({...t.unref(ne)})),void 0,!0)]),_:3},8,["show","backgroundColor","color","fontSize","borderRadius","borderColor","borderWidth","position","offsetY","parent","content","isFullscreen","backgroundOpacity","isCustom"])],4),t.createElementVNode("div",{ref_key:"chartSlicer",ref:ve,style:t.normalizeStyle(`width:100%;background:${t.unref(l).style.chart.backgroundColor}`),"data-html2canvas-ignore":""},[t.unref(l).style.chart.zoom.show&&t.unref(w)>1?(t.openBlock(),t.createBlock(st.Slicer,{ref_key:"slicerComponent",ref:E,key:`slicer_${t.unref(ue)}`,background:t.unref(l).style.chart.zoom.color,borderColor:t.unref(l).style.chart.backgroundColor,fontSize:t.unref(l).style.chart.zoom.fontSize,useResetSlot:t.unref(l).style.chart.zoom.useResetSlot,labelLeft:t.unref(l).style.chart.grid.y.timeLabels.values[t.unref(n).start]?t.unref(l).style.chart.grid.y.timeLabels.values[t.unref(n).start]:"",labelRight:t.unref(l).style.chart.grid.y.timeLabels.values[t.unref(n).end-1]?t.unref(l).style.chart.grid.y.timeLabels.values[t.unref(n).end-1]:"",textColor:t.unref(l).style.chart.color,inputColor:t.unref(l).style.chart.zoom.color,selectColor:t.unref(l).style.chart.zoom.highlightColor,max:t.unref(w),min:0,valueStart:t.unref(n).start,valueEnd:t.unref(n).end,start:t.unref(n).start,"onUpdate:start":a[1]||(a[1]=r=>t.unref(n).start=r),end:t.unref(n).end,"onUpdate:end":a[2]||(a[2]=r=>t.unref(n).end=r),refreshStartPoint:t.unref(l).style.chart.zoom.startIndex!==null?t.unref(l).style.chart.zoom.startIndex:0,refreshEndPoint:t.unref(l).style.chart.zoom.endIndex!==null?t.unref(l).style.chart.zoom.endIndex+1:t.unref(w),onReset:Ce},{"reset-action":t.withCtx(({reset:r})=>[t.renderSlot(e.$slots,"reset-action",t.normalizeProps(t.guardReactiveProps({reset:r})),void 0,!0)]),_:3},8,["background","borderColor","fontSize","useResetSlot","labelLeft","labelRight","textColor","inputColor","selectColor","max","valueStart","valueEnd","start","end","refreshStartPoint","refreshEndPoint"])):t.createCommentVNode("",!0)],4),t.createElementVNode("div",{ref_key:"chartLegend",ref:ce},[t.unref(l).style.chart.legend.show&&t.unref(Q)?(t.openBlock(),t.createBlock(nt.Legend,{legendSet:t.unref($e),config:t.unref(lt),key:`legend_${t.unref(K)}`,onClickMarker:a[3]||(a[3]=({i:r})=>ze(r))},{item:t.withCtx(({legend:r,index:f})=>[t.createElementVNode("div",{onClick:d=>r.segregate(),style:t.normalizeStyle(`opacity:${t.unref(C).includes(f)?.5:1}`)},t.toDisplayString(r.name),13,gt)]),_:1},8,["legendSet","config"])):t.renderSlot(e.$slots,"legend",{key:1,legend:t.unref($e)},void 0,!0)],512),e.$slots.watermark?(t.openBlock(),t.createElementBlock("div",pt,[t.renderSlot(e.$slots,"watermark",t.normalizeProps(t.guardReactiveProps({isPrinting:t.unref(pe)||t.unref(me)})),void 0,!0)])):t.createCommentVNode("",!0),e.$slots.source?(t.openBlock(),t.createElementBlock("div",{key:3,ref_key:"source",ref:fe,dir:"auto"},[t.renderSlot(e.$slots,"source",{},void 0,!0)],512)):t.createCommentVNode("",!0),t.unref(n).end-t.unref(n).start<200?(t.openBlock(),t.createBlock(it.default,{key:4,hideDetails:"",config:{open:t.unref(s).showTable,maxHeight:1e4,body:{backgroundColor:t.unref(l).style.chart.backgroundColor,color:t.unref(l).style.chart.color},head:{backgroundColor:t.unref(l).style.chart.backgroundColor,color:t.unref(l).style.chart.color}}},{content:t.withCtx(()=>[(t.openBlock(),t.createBlock(ct.DataTable,{key:`table_${t.unref(J)}`,colNames:t.unref(X).colNames,head:t.unref(X).head,body:t.unref(X).body,config:t.unref(X).config,title:`${t.unref(l).style.chart.title.text}${t.unref(l).style.chart.title.subtitle.text?` : ${t.unref(l).style.chart.title.subtitle.text}`:""}`,onClose:a[4]||(a[4]=r=>t.unref(s).showTable=!1)},{th:t.withCtx(({th:r})=>[t.createElementVNode("div",{innerHTML:r},null,8,mt)]),td:t.withCtx(({td:r})=>[t.createTextVNode(t.toDisplayString(r),1)]),_:1},8,["colNames","head","body","config","title"]))]),_:1},8,["config"])):t.createCommentVNode("",!0),t.unref(l).userOptions.buttons.annotator&&t.unref(y).length?(t.openBlock(),t.createBlock(ft.PenAndPaper,{key:5,parent:t.unref(N),backgroundColor:t.unref(l).style.chart.backgroundColor,color:t.unref(l).style.chart.color,active:t.unref(Y),onClose:ae},null,8,["parent","backgroundColor","color","active"])):t.createCommentVNode("",!0)],46,yt))}},xt=ht._export_sfc(bt,[["__scopeId","data-v-6d4d2ea8"]]);exports.default=xt;
;