UNPKG

vue-data-ui

Version:

A user-empowering data visualization Vue 3 components library for eloquent data storytelling

2 lines (1 loc) 18.2 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("./index-CBRI5uwl.cjs"),J=require("./useNestedProp-0jJvFRhK.cjs"),K=require("./usePrinter-C1Rlqzcj.cjs"),ue=require("./Title-BP4K_GLE.cjs"),ie=require("./PenAndPaper-DWG9pfri.cjs"),ce=require("./DataTable-Be-eTBzq.cjs"),ve=require("./vue-ui-accordion-C5C3XQ8f.cjs"),Q=require("./useResponsive-N8jl0-aC.cjs"),de=require("./vue-ui-skeleton-CM4wEsYA.cjs"),he=require("./useUserOptionState-BgepsfED.cjs"),fe=require("./PackageVersion-D_gJvbGU.cjs"),me=require("./useChartAccessibility-Cm7nkzTG.cjs"),pe=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),be=["id"],ye=["xmlns","viewBox"],ge=["width","height"],ke=["id"],Ce=["stop-color"],we=["stop-color"],xe=["stop-color"],Le=["stroke","stroke-width"],$e=["stroke","stroke-width"],Be=["x","y","font-size","fill","font-weight"],_e=["points","fill"],Se=["stroke","stroke-width","rx"],Ne=["x","y","font-size","fill","font-weight"],ze=["x","y","font-size","fill","font-weight"],Te={key:5,class:"vue-data-ui-watermark"},Ae=["innerHTML"],Pe={__name:"vue-ui-funnel",props:{config:{type:Object,default(){return{}}},dataset:{type:Array,default(){return[]}}},setup(Z,{expose:ee}){e.useCssVars(a=>({"4a21a112":ne.value}));const{vue_ui_funnel:te}=r.useConfig(),d=Z,b=e.computed(()=>!!d.dataset&&d.dataset.length);e.onMounted(z);function z(){if(r.objectIsEmpty(d.dataset)?r.error({componentName:"VueUiFunnel",type:"dataset"}):d.dataset.forEach((a,o)=>{r.getMissingDatasetAttributes({datasetObject:a,requiredAttributes:["name","value"]}).forEach(l=>{b.value=!1,r.error({componentName:"VueUiFunnel",type:"datasetSerieAttribute",property:l,index:o})})}),t.value.responsive){const a=Q.throttle(()=>{const{width:o,height:l}=Q.useResponsive({chart:L.value,title:t.value.style.chart.title.text?O.value:null,source:V.value,noTitle:E.value});requestAnimationFrame(()=>{u.value.height=l,u.value.width=o,f.value=H(),i.value.circles=r.translateSize({relator:Math.min(o,l),adjuster:600,source:t.value.style.chart.circles.dataLabels.fontSize,threshold:10,fallback:10}),i.value.names=r.translateSize({relator:Math.min(o,l),adjuster:600,source:t.value.style.chart.bars.dataLabels.name.fontSize,threshold:10,fallback:10}),i.value.values=r.translateSize({relator:Math.min(o,l),adjuster:600,source:t.value.style.chart.bars.dataLabels.value.fontSize,threshold:10,fallback:10})})});D.value=new ResizeObserver(a),D.value.observe(L.value.parentNode)}}const L=e.ref(null),g=e.ref(r.createUid()),T=e.ref(0),A=e.ref(0),P=e.ref(0),E=e.ref(null),V=e.ref(null),O=e.ref(null),D=e.ref(null),m=e.ref(!1);function F(){const a=J.useNestedProp({userConfig:d.config,defaultConfig:te});return a.theme?{...J.useNestedProp({userConfig:r.themes.vue_ui_funnel[a.theme]||d.config,defaultConfig:a})}:a}const t=e.computed({get:()=>F(),set:a=>a}),{userOptionsVisible:_,setUserOptionsVisibility:I,keepUserOptionState:R}=he.useUserOptionState({config:t.value}),{svgRef:q}=me.useChartAccessibility({config:t.value.style.chart.title});e.watch(()=>d.config,a=>{t.value=F(),_.value=!t.value.userOptions.showOnChartHover,z(),A.value+=1,P.value+=1,i.value.circles=t.value.style.chart.circles.dataLabels.fontSize,i.value.names=t.value.style.chart.bars.dataLabels.name.fontSize,i.value.values=t.value.style.chart.bars.dataLabels.value.fontSize,k.value.showTable=t.value.table.show},{deep:!0});const{isPrinting:M,isImaging:U,generatePdf:j,generateImage:G}=K.usePrinter({elementId:`funnel_${g.value}`,fileName:t.value.style.chart.title.text||"vue-ui-funnel"}),ae=e.computed(()=>t.value.userOptions.show&&!t.value.style.chart.title.text),k=e.ref({showTable:t.value.table.show}),i=e.ref({circles:t.value.style.chart.circles.dataLabels.fontSize,names:t.value.style.chart.bars.dataLabels.name.fontSize,values:t.value.style.chart.bars.dataLabels.value.fontSize}),u=e.computed({get:()=>({height:t.value.style.chart.height,width:t.value.style.chart.width}),set:a=>a}),h=e.computed(()=>b.value?d.dataset.map((a,o)=>({...a,color:a.color?r.convertColorToHex(a.color):r.lightenHexColor(t.value.style.chart.bars.defaultColor,o/d.dataset.length)})):[]);setTimeout(()=>{m.value=!0},h.value.length*150);function H(){const a=t.value.style.chart.padding.left,o=t.value.style.chart.padding.top;return{left:a,top:o,right:u.value.width-t.value.style.chart.padding.right,bottom:u.value.height-t.value.style.chart.padding.bottom,width:u.value.width-a-t.value.style.chart.padding.right,height:u.value.height-o-t.value.style.chart.padding.bottom}}const f=e.ref(H()),y=e.computed(()=>f.value.height/d.dataset.length),p=e.computed(()=>y.value*t.value.style.chart.bars.gapRatio),X=e.computed(()=>f.value.width*t.value.style.chart.barCircleSpacingRatio),s=e.computed(()=>h.value.map((a,o)=>{const l=y.value-p.value,n=f.value.top+p.value/2*o+(y.value-p.value/2)*o+p.value/2,v=a.value/h.value[0].value,c=(f.value.width-l-X.value)*(a.value/h.value[0].value);return{...a,cx:f.value.left+l/2,cy:n+l/2,datapointIndex:o,fill:a.color,height:Math.max(l,0),proportion:v,r:Math.max(l/2,0),width:Math.max(c,0),x:f.value.left+l+X.value,y:n}})),le=e.computed(()=>{const a=s.value.map(o=>`${o.x+o.width},${o.y+(y.value-p.value)/2}`);return`${s.value[0].x},${s.value[0].y+(y.value-p.value)/2} ${a.toString()} ${s.value.at(-1).x},${s.value.at(-1).y+(y.value-p.value)/2}`}),oe=e.computed(()=>({x1:s.value[0].cx,y1:s.value[0].cy,x2:s.value.at(-1).cx,y2:s.value.at(-1).cy})),C=e.ref(!1);function re(a){C.value=a,T.value+=1}const ne=e.computed(()=>`${h.value.length*150}ms`),$=e.ref(!1);function S(){$.value=!$.value}function Y(){k.value.showTable=!k.value.showTable}const w=e.computed(()=>{const a=h.value.map(l=>({name:l.name,color:l.color})),o=h.value.map(l=>l.value);return{head:a,body:o}}),B=e.computed(()=>{const a=[t.value.table.columnNames.series,t.value.table.columnNames.value,t.value.table.columnNames.percentage],o=w.value.head.map((v,c)=>{const x=r.applyDataLabel(t.value.style.chart.bars.dataLabels.value.formatter,w.value.body[c],r.dataLabel({p:t.value.style.chart.bars.dataLabels.value.prefix,v:w.value.body[c],s:t.value.style.chart.bars.dataLabels.value.suffix,r:t.value.table.td.roundingValue}),{datapoint:s.value[c]}),N=r.applyDataLabel(t.value.style.chart.circles.dataLabels.formatter,s.value[c].proportion*100,r.dataLabel({v:s.value[c].proportion*100,s:"%",r:t.value.table.td.roundingPercentage}),{datapoint:s.value[c]});return[{color:v.color,name:v.name},x,N]}),l={th:{backgroundColor:t.value.table.th.backgroundColor,color:t.value.table.th.color,outline:t.value.table.th.outline},td:{backgroundColor:t.value.table.td.backgroundColor,color:t.value.table.td.color,outline:t.value.table.td.outline},breakpoint:t.value.table.responsiveBreakpoint};return{colNames:[t.value.table.columnNames.series,t.value.table.columnNames.value,t.value.table.columnNames.percentage],head:a,body:o,config:l}});function W(){e.nextTick(()=>{const a=w.value.head.map((n,v)=>[[n.name],[w.value.body[v]],[s.value[v].proportion*100]]),o=[[t.value.style.chart.title.text],[t.value.style.chart.title.subtitle.text],[[t.value.table.columnNames.series],[t.value.table.columnNames.value],["%"]]].concat(a),l=r.createCsvContent(o);r.downloadCsv({csvContent:l,title:t.value.style.chart.title.text||"vue-ui-funnel"})})}function se(){return h.value}return ee({getData:se,generatePdf:j,generateCsv:W,generateImage:G,toggleTable:Y,toggleAnnotator:S}),(a,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"funnelChart",ref:L,class:e.normalizeClass(`vue-ui-funnel ${C.value?"vue-data-ui-wrapper-fullscreen":""} ${t.value.useCssAnimation?"":"vue-ui-dna"}`),style:e.normalizeStyle(`font-family:${t.value.style.fontFamily};width:100%; ${t.value.responsive?"height:100%;":""} text-align:center;background:${t.value.style.chart.backgroundColor}`),id:`funnel_${g.value}`,onMouseenter:o[1]||(o[1]=()=>e.unref(I)(!0)),onMouseleave:o[2]||(o[2]=()=>e.unref(I)(!1))},[t.value.userOptions.buttons.annotator?(e.openBlock(),e.createBlock(ie.PenAndPaper,{key:0,svgRef:e.unref(q),backgroundColor:t.value.style.chart.backgroundColor,color:t.value.style.chart.color,active:$.value,onClose:S},null,8,["svgRef","backgroundColor","color","active"])):e.createCommentVNode("",!0),ae.value?(e.openBlock(),e.createElementBlock("div",{key:1,ref_key:"noTitle",ref:E,class:"vue-data-ui-no-title-space",style:"height:36px; width: 100%;background:transparent"},null,512)):e.createCommentVNode("",!0),t.value.style.chart.title.text?(e.openBlock(),e.createElementBlock("div",{key:2,ref_key:"chartTitle",ref:O,style:"width:100%;background:transparent;padding-bottom:24px"},[(e.openBlock(),e.createBlock(ue._sfc_main,{key:`title_${A.value}`,config:{title:{cy:"funnel-div-title",...t.value.style.chart.title},subtitle:{cy:"funnel-div-subtitle",...t.value.style.chart.title.subtitle}}},null,8,["config"]))],512)):e.createCommentVNode("",!0),t.value.userOptions.show&&b.value&&(e.unref(R)||e.unref(_))?(e.openBlock(),e.createBlock(K.UserOptions,{ref:"details",key:`user_option_${T.value}`,backgroundColor:t.value.style.chart.backgroundColor,color:t.value.style.chart.color,isPrinting:e.unref(M),isImaging:e.unref(U),uid:g.value,hasTooltip:!1,hasPdf:t.value.userOptions.buttons.pdf,hasImg:t.value.userOptions.buttons.img,hasXls:t.value.userOptions.buttons.csv,hasTable:t.value.userOptions.buttons.table,hasLabel:!1,hasFullscreen:t.value.userOptions.buttons.fullscreen,isFullscreen:C.value,chartElement:L.value,position:t.value.userOptions.position,titles:{...t.value.userOptions.buttonTitles},hasAnnotator:t.value.userOptions.buttons.annotator,isAnnotation:$.value,onToggleAnnotator:S,onToggleFullscreen:re,onGeneratePdf:e.unref(j),onGenerateImage:e.unref(G),onToggleTable:Y,onGenerateCsv:W,style:e.normalizeStyle({visibility:e.unref(R)?e.unref(_)?"visible":"hidden":"visible"})},e.createSlots({_:2},[a.$slots.menuIcon?{name:"menuIcon",fn:e.withCtx(({isOpen:l,color:n})=>[e.renderSlot(a.$slots,"menuIcon",e.normalizeProps(e.guardReactiveProps({isOpen:l,color:n})),void 0,!0)]),key:"0"}:void 0,a.$slots.optionPdf?{name:"optionPdf",fn:e.withCtx(()=>[e.renderSlot(a.$slots,"optionPdf",{},void 0,!0)]),key:"1"}:void 0,a.$slots.optionCsv?{name:"optionCsv",fn:e.withCtx(()=>[e.renderSlot(a.$slots,"optionCsv",{},void 0,!0)]),key:"2"}:void 0,a.$slots.optionImg?{name:"optionImg",fn:e.withCtx(()=>[e.renderSlot(a.$slots,"optionImg",{},void 0,!0)]),key:"3"}:void 0,a.$slots.optionTable?{name:"optionTable",fn:e.withCtx(()=>[e.renderSlot(a.$slots,"optionTable",{},void 0,!0)]),key:"4"}:void 0,a.$slots.optionFullscreen?{name:"optionFullscreen",fn:e.withCtx(({toggleFullscreen:l,isFullscreen:n})=>[e.renderSlot(a.$slots,"optionFullscreen",e.normalizeProps(e.guardReactiveProps({toggleFullscreen:l,isFullscreen:n})),void 0,!0)]),key:"5"}:void 0,a.$slots.optionAnnotator?{name:"optionAnnotator",fn:e.withCtx(({toggleAnnotator:l,isAnnotator:n})=>[e.renderSlot(a.$slots,"optionAnnotator",e.normalizeProps(e.guardReactiveProps({toggleAnnotator:l,isAnnotator:n})),void 0,!0)]),key:"6"}:void 0]),1032,["backgroundColor","color","isPrinting","isImaging","uid","hasPdf","hasImg","hasXls","hasTable","hasFullscreen","isFullscreen","chartElement","position","titles","hasAnnotator","isAnnotation","onGeneratePdf","onGenerateImage","style"])):e.createCommentVNode("",!0),b.value?(e.openBlock(),e.createElementBlock("svg",{key:4,ref_key:"svgRef",ref:q,xmlns:e.unref(r.XMLNS),class:e.normalizeClass({"vue-data-ui-fullscreen--on":C.value,"vue-data-ui-fulscreen--off":!C.value}),viewBox:`0 0 ${u.value.width<=0?10:u.value.width} ${u.value.height<=0?10:u.value.height}`,style:e.normalizeStyle(`max-width:100%; overflow: visible; background:transparent;color:${t.value.style.chart.color}`)},[e.createVNode(fe._sfc_main),a.$slots["chart-background"]?(e.openBlock(),e.createElementBlock("foreignObject",{key:0,x:0,y:0,width:u.value.width<=0?10:u.value.width,height:u.value.height<=0?10:u.value.height,style:{pointerEvents:"none"}},[e.renderSlot(a.$slots,"chart-background",{},void 0,!0)],8,ge)):e.createCommentVNode("",!0),e.createElementVNode("defs",null,[e.createElementVNode("linearGradient",{id:`funnel_area_${g.value}`,x1:"0%",x2:"100%",y1:"0%",y2:"0%"},[e.createElementVNode("stop",{offset:"0%","stop-color":t.value.style.chart.backgroundColor,"stop-opacity":0},null,8,Ce),e.createElementVNode("stop",{offset:"20%","stop-color":t.value.style.chart.area.color},null,8,we),e.createElementVNode("stop",{offset:"100%","stop-color":t.value.style.chart.area.color},null,8,xe)],8,ke)]),t.value.style.chart.circleLinks.show?(e.openBlock(),e.createElementBlock("line",e.mergeProps({key:1},oe.value,{stroke:t.value.style.chart.circleLinks.color,"stroke-width":12*t.value.style.chart.circleLinks.widthRatio,"stroke-linecap":"round",class:{animated:t.value.useCssAnimation},style:{strokeDasharray:t.value.useCssAnimation?f.value.height:0,strokeDashoffset:t.value.useCssAnimation?f.value.height:0}}),null,16,Le)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,({cx:l,cy:n,r:v,fill:c},x)=>(e.openBlock(),e.createElementBlock("circle",e.mergeProps({ref_for:!0},{cx:l,cy:n,r:v,fill:c},{stroke:t.value.style.chart.circles.stroke,"stroke-width":t.value.style.chart.circles.strokeWidth,class:{animated:t.value.useCssAnimation&&!m.value},style:{animationDelay:`${150*x}ms`}}),null,16,$e))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,(l,n)=>(e.openBlock(),e.createElementBlock("text",{x:l.cx,y:l.cy+i.value.circles/3+t.value.style.chart.circles.dataLabels.offsetY,"text-anchor":"middle","font-size":i.value.circles,fill:t.value.style.chart.circles.dataLabels.adaptColorToBackground?e.unref(r.adaptColorToBackground)(l.color):t.value.style.chart.circles.dataLabels.color,"font-weight":t.value.style.chart.circles.dataLabels.bold?"bold":"normal",class:e.normalizeClass({animated:t.value.useCssAnimation&&!m.value}),style:e.normalizeStyle({animationDelay:`${150*n}ms`})},e.toDisplayString(e.unref(r.applyDataLabel)(t.value.style.chart.circles.dataLabels.formatter,l.proportion*100,e.unref(r.dataLabel)({v:l.proportion*100,s:"%",r:t.value.style.chart.circles.dataLabels.rounding}),{datapoint:l})),15,Be))),256)),t.value.style.chart.area.show?(e.openBlock(),e.createElementBlock("polygon",{key:2,points:le.value,fill:`url(#funnel_area_${g.value})`,class:e.normalizeClass({animated:t.value.useCssAnimation&&!m.value}),style:e.normalizeStyle({transition:t.value.useCssAnimation?`all ${150*h.value.length}ms ease-in`:"none"})},null,14,_e)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,({x:l,y:n,height:v,width:c,fill:x},N)=>(e.openBlock(),e.createElementBlock("rect",e.mergeProps({ref_for:!0},{x:l,y:n,height:v,width:c,fill:x},{stroke:t.value.style.chart.bars.stroke,"stroke-width":t.value.style.chart.bars.strokeWidth,rx:t.value.style.chart.bars.borderRadius,class:{animated:t.value.useCssAnimation&&!m.value},style:{animationDelay:`${150*N}ms`}}),null,16,Se))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,(l,n)=>(e.openBlock(),e.createElementBlock("g",null,[e.createElementVNode("text",{x:l.x+l.width+t.value.style.chart.bars.dataLabels.name.offsetX+12,y:l.cy-i.value.names/2+t.value.style.chart.bars.dataLabels.name.offsetY,"text-anchor":"start","font-size":i.value.names,fill:t.value.style.chart.bars.dataLabels.name.color,"font-weight":t.value.style.chart.bars.dataLabels.name.bold?"bold":"normal",class:e.normalizeClass({animated:t.value.useCssAnimation&&!m.value}),style:e.normalizeStyle({animationDelay:`${150*n}ms`})},e.toDisplayString(l.name),15,Ne),e.createElementVNode("text",{x:l.x+l.width+t.value.style.chart.bars.dataLabels.value.offsetX+12,y:l.cy+i.value.values+t.value.style.chart.bars.dataLabels.value.offsetY,"text-anchor":"start","font-size":i.value.values,fill:t.value.style.chart.bars.dataLabels.value.color,"font-weight":t.value.style.chart.bars.dataLabels.value.bold?"bold":"normal",class:e.normalizeClass({animated:t.value.useCssAnimation&&!m.value}),style:e.normalizeStyle({animationDelay:`${150*n}ms`})},e.toDisplayString(e.unref(r.applyDataLabel)(t.value.style.chart.bars.dataLabels.value.formatter,l.value,e.unref(r.dataLabel)({p:t.value.style.chart.bars.dataLabels.value.prefix,v:l.value,s:t.value.style.chart.bars.dataLabels.value.suffix,r:t.value.style.chart.bars.dataLabels.value.rounding}),{datapoint:l})),15,ze)]))),256)),e.renderSlot(a.$slots,"svg",{svg:u.value},void 0,!0)],14,ye)):e.createCommentVNode("",!0),a.$slots.watermark?(e.openBlock(),e.createElementBlock("div",Te,[e.renderSlot(a.$slots,"watermark",e.normalizeProps(e.guardReactiveProps({isPrinting:e.unref(M)||e.unref(U)})),void 0,!0)])):e.createCommentVNode("",!0),b.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(de.default,{key:6,config:{type:"verticalBar",style:{backgroundColor:t.value.style.chart.backgroundColor,verticalBar:{axis:{color:"#CCCCCC"},color:"#CCCCCC"}}}},null,8,["config"])),a.$slots.source?(e.openBlock(),e.createElementBlock("div",{key:7,ref_key:"source",ref:V,dir:"auto"},[e.renderSlot(a.$slots,"source",{},void 0,!0)],512)):e.createCommentVNode("",!0),b.value?(e.openBlock(),e.createBlock(ve.default,{key:8,hideDetails:"",config:{open:k.value.showTable,maxHeight:1e4,body:{backgroundColor:t.value.style.chart.backgroundColor,color:t.value.style.chart.color},head:{backgroundColor:t.value.style.chart.backgroundColor,color:t.value.style.chart.color}}},{content:e.withCtx(()=>[(e.openBlock(),e.createBlock(ce.DataTable,{key:`table_${P.value}`,colNames:B.value.colNames,head:B.value.head,body:B.value.body,config:B.value.config,title:`${t.value.style.chart.title.text}${t.value.style.chart.title.subtitle.text?` : ${t.value.style.chart.title.subtitle.text}`:""}`,onClose:o[0]||(o[0]=l=>k.value.showTable=!1)},{th:e.withCtx(({th:l})=>[e.createElementVNode("div",{innerHTML:l,style:{display:"flex","align-items":"center"}},null,8,Ae)]),td:e.withCtx(({td:l})=>[e.createTextVNode(e.toDisplayString(l.name?l.name:l),1)]),_:1},8,["colNames","head","body","config","title"]))]),_:1},8,["config"])):e.createCommentVNode("",!0)],46,be))}},Ee=pe._export_sfc(Pe,[["__scopeId","data-v-fb07d7cc"]]);exports.default=Ee;