UNPKG

vue-data-ui

Version:

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

2 lines (1 loc) 12.3 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),a=require("./index-CBRI5uwl.cjs"),V=require("./useNestedProp-0jJvFRhK.cjs"),U=require("./vue-ui-skeleton-CM4wEsYA.cjs"),M=require("./PackageVersion-D_gJvbGU.cjs"),j=require("./Tooltip-KXn1rQhr.cjs"),R=require("./useChartAccessibility-Cm7nkzTG.cjs"),H=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),I=["xmlns","viewBox"],W=["id"],Y=["stop-color"],G=["stop-color"],X=["stop-color"],J={id:"stackPill",clipPathUnits:"objectBoundingBox"},K=["fill"],Q={key:0,"clip-path":"url(#stackPill)"},Z=["x","width","height","fill"],ee=["x","width","height","fill","stroke"],te=["onClick","x","width","height","onMouseenter"],le=["width","height","rx"],oe=["onClick"],ae={style:{display:"flex","flex-direction":"row","align-items":"center",gap:"4px","justify-content":"center"}},re=["height","width"],ne=["fill"],se={key:4,ref:"source",dir:"auto"},ue={__name:"vue-ui-sparkstackbar",props:{config:{type:Object,default(){return{}}},dataset:{type:Array,default(){return[]}}},emits:["selectDatapoint"],setup(P,{emit:D}){const{vue_ui_sparkstackbar:L}=a.useConfig(),u=P,F=e.useSlots();e.onMounted(()=>{F["chart-background"]&&console.warn("VueUiSparkStackbar does not support the #chart-background slot.")});const x=e.computed(()=>!!u.dataset&&u.dataset.length),B=e.ref(null),S=e.ref(a.createUid()),b=e.ref(!1),C=e.ref(""),t=e.computed({get:()=>$(),set:l=>l}),{svgRef:A}=R.useChartAccessibility({config:t.value.style.title});function $(){const l=V.useNestedProp({userConfig:u.config,defaultConfig:L});return l.theme?{...V.useNestedProp({userConfig:a.themes.vue_ui_sparkstackbar[l.theme]||u.config,defaultConfig:l}),customPalette:a.themePalettes[l.theme]||a.palette}:l}e.watch(()=>u.config,l=>{t.value=$(),E()},{deep:!0}),e.watch(()=>u.dataset,l=>{p.value=u.dataset.map((n,o)=>({...n,color:n.color?a.convertColorToHex(n.color):f.value[o]||a.palette[o]||a.palette[o%a.palette.length]}))},{deep:!0});const f=e.computed(()=>a.convertCustomPalette(t.value.customPalette)),p=e.ref(u.dataset.map((l,n)=>({...l,value:t.value.style.animation.show?0:l.value||0,color:l.color?a.convertColorToHex(l.color):f.value[n]||a.palette[n]||a.palette[n%a.palette.length]}))),g=e.ref(!0);e.onMounted(()=>{if(E(),t.value.style.animation.show){let v=function(){r+=o/l,r<o?(p.value=p.value.map((s,i)=>({...s,value:s.value+=n[i],color:s.color?a.convertColorToHex(s.color):f.value[i]||a.palette[i]||a.palette[i%a.palette.length]})),requestAnimationFrame(v)):(g.value=!1,p.value=u.dataset.map((s,i)=>({...s,value:s.value||0,color:s.color?a.convertColorToHex(s.color):f.value[i]||a.palette[i]||a.palette[i%a.palette.length],id:a.createUid()})))};const l=t.value.style.animation.animationFrames,n=u.dataset.map((s,i)=>s.value/l),o=u.dataset.map(s=>s.value||0).reduce((s,i)=>s+i,0);let r=0;g.value=!0,v()}});function E(){a.objectIsEmpty(u.dataset)?a.error({componentName:"VueUiSparkStackbar",type:"dataset"}):u.dataset.forEach((l,n)=>{a.getMissingDatasetAttributes({datasetObject:l,requiredAttributes:["name","value"]}).forEach(o=>{a.error({componentName:"VueUiSparkStackbar",type:"datasetSerieAttribute",property:o,index:n})})})}const c=e.ref({width:500,height:16}),d=e.ref([]),N=e.computed(()=>u.dataset.map(l=>l.value||0).filter((l,n)=>!d.value.includes(n)).reduce((l,n)=>l+n,0)),y=e.computed(()=>p.value.map((l,n)=>{const o=l.value||0,r=o/N.value,v=isNaN(r)?0:r,s=v*c.value.width;return{...l,value:o,proportion:v,width:s,proportionLabel:a.dataLabel({v:v*100,s:"%",r:t.value.style.legend.percentage.rounding})}})),_=e.computed(()=>y.value.filter((l,n)=>!d.value.includes(n)));function T(l){d.value.includes(l)?d.value=d.value.filter(n=>n!==l):d.value.length<p.value.length-1&&d.value.push(l)}const h=e.computed(()=>{let l=0;const n=[];for(let o=0;o<_.value.length;o+=1)n.push({..._.value[o],start:l}),l+=_.value[o].width;return n}),q=D;function z(l,n){q("selectDatapoint",{datapoint:l,index:n})}const w=e.ref(null),k=e.ref(!1),m=e.ref(null);function O({datapoint:l,seriesIndex:n}){if(!t.value.style.tooltip.show)return;w.value={datapoint:l,seriesIndex:n,config:t.value,series:y.value},b.value=!0,m.value=n;const o=t.value.style.tooltip.customFormat;if(a.isFunction(o))try{const r=o({seriesIndex:n,datapoint:l,series:y.value,config:t.value});typeof r=="string"&&(C.value=r,k.value=!0)}catch{console.warn("Custom format cannot be applied."),k.value=!1}if(!k.value){let r="";r+=`<div style="width:100%;text-align:center;border-bottom:1px solid ${t.value.style.tooltip.borderColor};padding-bottom:6px;margin-bottom:3px;">${l.name}</div>`,r+=`<div style="display:flex;flex-direction:row;gap:6px;align-items:center;"><svg viewBox="0 0 12 12" height="14" width="14"><circle cx="6" cy="6" r="6" stroke="none" fill="${l.color}"/></svg>`,r+=`<b>${l.proportionLabel}</b>`,r+=`<span>(${a.applyDataLabel(t.value.style.legend.value.formatter,l.value,a.dataLabel({p:t.value.style.legend.value.prefix,v:l.value,s:t.value.style.legend.value.suffix,r:t.value.style.legend.value.rounding}),{datapoint:l,seriesIndex:n})})</span>`,C.value=`<div>${r}</div>`}}return(l,n)=>(e.openBlock(),e.createElementBlock("div",{class:"vue-ui-spark-stackbar",ref_key:"sparkstackbarChart",ref:B,style:e.normalizeStyle(`width:100%; background:${t.value.style.backgroundColor}`)},[t.value.style.title.text?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(`width:calc(100% - 12px);background:transparent;margin:0 auto;margin:${t.value.style.title.margin};padding: 0 6px;text-align:${t.value.style.title.textAlign}`)},[e.createElementVNode("div",{class:"atom-title",style:e.normalizeStyle(`font-size:${t.value.style.title.fontSize}px;color:${t.value.style.title.color};font-weight:${t.value.style.title.bold?"bold":"normal"}`)},e.toDisplayString(t.value.style.title.text),5),t.value.style.title.subtitle.text?(e.openBlock(),e.createElementBlock("div",{key:0,class:"atom-subtitle",style:e.normalizeStyle(`font-size:${t.value.style.title.subtitle.fontSize}px;color:${t.value.style.title.subtitle.color};font-weight:${t.value.style.title.subtitle.bold?"bold":"normal"}`)},e.toDisplayString(t.value.style.title.subtitle.text),5)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0),x.value?(e.openBlock(),e.createElementBlock("svg",{key:1,ref_key:"svgRef",ref:A,xmlns:e.unref(a.XMLNS),width:"100%",viewBox:`0 0 ${c.value.width} ${c.value.height}`},[e.createVNode(M._sfc_main),e.createElementVNode("defs",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,(o,r)=>(e.openBlock(),e.createElementBlock("linearGradient",{key:`stack_gradient_${r}`,gradientTransform:"rotate(90)",id:`stack_gradient_${r}_${S.value}`},[e.createElementVNode("stop",{offset:"0%","stop-color":o.color},null,8,Y),e.createElementVNode("stop",{offset:"50%","stop-color":e.unref(a.setOpacity)(e.unref(a.shiftHue)(o.color,.05),100-t.value.style.bar.gradient.intensity)},null,8,G),e.createElementVNode("stop",{offset:"100%","stop-color":o.color},null,8,X)],8,W))),128)),e.createElementVNode("clipPath",J,[e.createElementVNode("rect",{x:"0.005",y:"-2",width:"0.99",height:"5",rx:"3",ry:"3",fill:t.value.style.backgroundColor},null,8,K)])]),N.value>0?(e.openBlock(),e.createElementBlock("g",Q,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,(o,r)=>(e.openBlock(),e.createElementBlock("rect",{key:`stack_underlayer_${r}`,x:o.start,y:0,width:o.width,height:c.value.height,fill:t.value.style.bar.gradient.underlayerColor,class:e.normalizeClass({animated:!g.value}),style:e.normalizeStyle({opacity:m.value!==null&&t.value.style.tooltip.show?m.value===r?1:.5:1})},null,14,Z))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,(o,r)=>(e.openBlock(),e.createElementBlock("rect",{key:`stack_${r}`,x:o.start,y:0,width:o.width,height:c.value.height,fill:t.value.style.bar.gradient.show?`url(#stack_gradient_${r}_${S.value})`:o.color,stroke:t.value.style.backgroundColor,"stroke-linecap":"round",class:e.normalizeClass({animated:!g.value}),style:e.normalizeStyle({opacity:m.value!==null&&t.value.style.tooltip.show?m.value===r?1:.5:1})},null,14,ee))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(h.value,(o,r)=>(e.openBlock(),e.createElementBlock("rect",{key:`stack_trap_${r}`,onClick:()=>z(o,r),x:o.start,y:0,width:o.width,height:c.value.height,fill:"transparent",stroke:"none",class:e.normalizeClass({animated:!g.value}),onMouseenter:()=>O({datapoint:o,seriesIndex:r}),onMouseleave:n[0]||(n[0]=v=>{b.value=!1,m.value=null})},null,42,te))),128))])):(e.openBlock(),e.createElementBlock("rect",{key:1,x:2,y:1,width:c.value.width-4,height:c.value.height-2,stroke:"#CCCCCC","stroke-width":"2",fill:"transparent",rx:(c.value.height-4)/2},null,8,le))],8,I)):e.createCommentVNode("",!0),x.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(U.default,{key:2,config:{type:"sparkStackbar",style:{backgroundColor:t.value.style.backgroundColor,sparkStackbar:{color:"#CCCCCC"}}}},null,8,["config"])),t.value.style.legend.show?(e.openBlock(),e.createElementBlock("div",{key:3,style:e.normalizeStyle(`background:transparent;margin:0 auto;margin:${t.value.style.legend.margin};justify-content:${t.value.style.legend.textAlign==="left"?"flex-start":t.value.style.legend.textAlign==="right"?"flex-end":"center"}`),class:"vue-ui-sparkstackbar-legend"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(y.value,(o,r)=>(e.openBlock(),e.createElementBlock("div",{style:e.normalizeStyle(`font-size:${t.value.style.legend.fontSize}px;`),class:e.normalizeClass({"vue-ui-sparkstackbar-legend-item":!0,"vue-ui-sparkstackbar-legend-item-unselected":d.value.includes(r)}),onClick:v=>{T(r),z(o,r)}},[e.createElementVNode("div",ae,[(e.openBlock(),e.createElementBlock("svg",{height:`${t.value.style.legend.fontSize}px`,width:`${t.value.style.legend.fontSize}px`,viewBox:"0 0 10 10"},[e.createElementVNode("circle",{cx:5,cy:5,r:5,fill:o.color},null,8,ne)],8,re)),e.createElementVNode("span",{style:e.normalizeStyle(`color:${t.value.style.legend.name.color}; font-weight:${t.value.style.legend.name.bold?"bold":"normal"}`)},e.toDisplayString(o.name),5),t.value.style.legend.percentage.show?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(`font-weight:${t.value.style.legend.percentage.bold?"bold":"normal"};color:${t.value.style.legend.percentage.color}`)},e.toDisplayString(d.value.includes(r)?" - ":o.proportionLabel),5)):e.createCommentVNode("",!0),t.value.style.legend.value.show?(e.openBlock(),e.createElementBlock("span",{key:1,style:e.normalizeStyle(`font-weight:${t.value.style.legend.value.bold?"bold":"normal"};color:${t.value.style.legend.value.color}`)}," ("+e.toDisplayString(e.unref(a.applyDataLabel)(t.value.style.legend.value.formatter,o.value,e.unref(a.dataLabel)({p:t.value.style.legend.value.prefix,v:o.value,s:t.value.style.legend.value.suffix,r:t.value.style.legend.value.rounding}),{datapoint:o,seriesIndex:r}))+") ",5)):e.createCommentVNode("",!0)])],14,oe))),256))],4)):e.createCommentVNode("",!0),e.createVNode(j._sfc_main,{show:b.value&&t.value.style.tooltip.show,parent:B.value,backgroundColor:t.value.style.tooltip.backgroundColor,color:t.value.style.tooltip.color,fontSize:t.value.style.tooltip.fontSize,borderRadius:t.value.style.tooltip.borderRadius,borderColor:t.value.style.tooltip.borderColor,borderWidth:t.value.style.tooltip.borderWidth,backgroundOpacity:t.value.style.tooltip.backgroundOpacity,position:t.value.style.tooltip.position,content:C.value,isCustom:k.value,offsetY:-124+t.value.style.tooltip.offsetY,blockShiftY:!0},{"tooltip-before":e.withCtx(()=>[e.renderSlot(l.$slots,"tooltip-before",e.normalizeProps(e.guardReactiveProps({...w.value})),void 0,!0)]),"tooltip-after":e.withCtx(()=>[e.renderSlot(l.$slots,"tooltip-after",e.normalizeProps(e.guardReactiveProps({...w.value})),void 0,!0)]),_:3},8,["show","parent","backgroundColor","color","fontSize","borderRadius","borderColor","borderWidth","backgroundOpacity","position","content","isCustom","offsetY"]),l.$slots.source?(e.openBlock(),e.createElementBlock("div",se,[e.renderSlot(l.$slots,"source",{},void 0,!0)],512)):e.createCommentVNode("",!0)],4))}},ie=H._export_sfc(ue,[["__scopeId","data-v-7955299f"]]);exports.default=ie;