vue-data-ui-hq
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
2 lines (1 loc) • 17.8 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),s=require("./index-ZfICPrrM.cjs"),Se=require("./Title-FbHK83tB.cjs"),se=require("./usePrinter-B-gh2f22.cjs"),j=require("./useResponsive-BJ7DTGpm.cjs"),$e=require("./vue-ui-accordion-Dp6uTsJi.cjs"),Te=require("./DataTable-CC6dPSer.cjs"),Ne=require("./BaseIcon-DO69J5Rk.cjs"),ie=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),ue=require("./useNestedProp-C14rfl0j.cjs"),Pe=require("./PackageVersion-D3dK8oA3.cjs"),Be=require("./Tooltip-C7TJODUx.cjs"),Fe=require("./PenAndPaper-PL3bp4ud.cjs"),ze=require("./useUserOptionState-BgepsfED.cjs"),Oe={"data-html2canvas-ignore":""},Ve={key:0,class:"reset-wrapper"},Ae={key:1,class:"reset-wrapper"},Ee={class:"mono-slicer"},Me=["min","max","value"],_e={__name:"MonoSlicer",props:{min:{type:Number,default:0},max:{type:Number,default:0},inputColor:{type:String,default:"#1A1A1A"},background:{type:String,default:"#FFFFFF"},borderColor:{type:String,default:"#FFFFFF"},selectColor:{type:String,default:"#4A4A4A"},textColor:{type:String,default:"#1A1A1A"},useResetSlot:{type:Boolean,default:!1},value:{type:Number,default:0},source:{type:Number,default:0}},emits:["update:value","reset"],setup(c,{emit:M}){e.useCssVars(y=>({"42c5938f":e.unref(i),"4a89c7fa":e.unref($),fd094998:e.unref(g),"8a1f459a":c.selectColor,"4906137e":e.unref(k)}));const d=c,i=e.computed(()=>d.inputColor),k=e.computed(()=>d.background),g=e.computed(()=>`${d.selectColor}33`),$=e.computed(()=>d.borderColor),T=M;function p(){T("reset")}const B=e.computed(()=>{const y=d.max-d.min,m=0,C=(d.value-d.min)/y*100;return{left:`${m}%`,width:`${C-m}%`,background:d.selectColor}});return(y,m)=>(e.openBlock(),e.createElementBlock("div",Oe,[c.value!==c.source?(e.openBlock(),e.createElementBlock("div",Ve,[c.useResetSlot?e.renderSlot(y.$slots,"reset-action",{key:1,reset:p},void 0,!0):(e.openBlock(),e.createElementBlock("button",{key:0,"data-cy-reset":"",tabindex:"0",role:"button",class:"vue-data-ui-refresh-button",onClick:p},[e.createVNode(Ne.default,{name:"refresh",stroke:c.textColor},null,8,["stroke"])]))])):(e.openBlock(),e.createElementBlock("div",Ae)),e.createElementVNode("div",Ee,[m[1]||(m[1]=e.createElementVNode("div",{class:"slider-track"},null,-1)),e.createElementVNode("div",{class:"range-highlight",style:e.normalizeStyle(e.unref(B))},null,4),e.createElementVNode("input",{type:"range",min:c.min,max:c.max,value:Number(c.value),onInput:m[0]||(m[0]=C=>T("update:value",Number(C.target.value)))},null,40,Me)])]))}},Ie=ie._export_sfc(_e,[["__scopeId","data-v-9ca789eb"]]),Re=["id"],qe=["xmlns","viewBox"],Ue=["width","height"],We=["transform"],De=["fill","font-weight","x","y","font-size","transform","onMouseover"],Ge={key:4,class:"vue-data-ui-watermark"},Le=["innerHTML"],je={__name:"vue-ui-word-cloud",props:{config:{type:Object,default(){return{}}},dataset:{type:[Array,String],default(){return[]}}},setup(c,{expose:M}){const{vue_ui_word_cloud:d}=s.useConfig(),i=c,k=e.computed({get(){return!!i.dataset&&i.dataset.length},set(o){return o}}),g=e.ref(typeof i.dataset=="string"?s.createWordCloudDatasetFromPlainText(i.dataset):i.dataset.map(o=>({...o,value:s.checkNaN(o.value)}))),$=e.ref(s.createUid()),T=e.ref(0),p=e.ref(null),B=e.ref(null),y=e.ref(null),m=e.ref(0),C=e.ref(0),_=e.ref(!1),t=e.computed({get:()=>Y(),set:o=>o}),{userOptionsVisible:I,setUserOptionsVisibility:H,keepUserOptionState:X}=ze.useUserOptionState({config:t.value});function Y(){const o=ue.useNestedProp({userConfig:i.config,defaultConfig:d});return o.theme?{...ue.useNestedProp({userConfig:s.themes.vue_ui_word_cloud[o.theme]||i.config,defaultConfig:o}),customPalette:s.themePalettes[o.theme]||s.palette}:o}e.watch(()=>i.config,o=>{t.value=Y(),I.value=!t.value.showOnChartHover,K(),m.value+=1,C.value+=1,R()},{deep:!0});const J=e.ref(null),b=e.ref(0),a=e.ref({width:t.value.style.chart.width,height:t.value.style.chart.height,maxFontSize:t.value.style.chart.words.maxFontSize,minFontSize:t.value.style.chart.words.minFontSize}),ce=j.throttle(()=>{const{width:o,height:r}=j.useResponsive({chart:p.value,title:t.value.style.chart.title.text?B.value:null,slicer:t.value.style.chart.zoom.show&&J.value,source:y.value});a.value.width=o,a.value.height=r,e.nextTick(q)});e.watch(()=>b.value,()=>{de()});const de=j.debounce(()=>{q()},10);function R(){b.value=oe.value}const F=e.ref(null);e.onMounted(()=>{K(),R()});function K(){s.objectIsEmpty(i.dataset)?s.error({componentName:"VueUiWordCloud",type:"dataset"}):g.value.forEach((o,r)=>{s.getMissingDatasetAttributes({datasetObject:o,requiredAttributes:["name","value"]}).forEach(n=>{k.value=!1,s.error({componentName:"VueUiWordCloud",type:"datasetSerieAttribute",property:n,index:r})})}),t.value.responsive&&(F.value=new ResizeObserver(ce),F.value.observe(p.value.parentNode))}e.onBeforeUnmount(()=>{F.value&&F.value.disconnect()});const{isPrinting:Q,isImaging:Z,generatePdf:ee,generateImage:te}=se.usePrinter({elementId:`wordCloud_${$.value}`,fileName:t.value.style.chart.title.text||"vue-ui-word-cloud"}),f=e.ref({showTable:t.value.table.show,showTooltip:t.value.style.chart.tooltip.show});function fe(o,r,n="Arial"){const l=document.createElement("canvas").getContext("2d");return l.font=`${r}px ${t.value.style.chart.words.bold?"bold":"normal"} ${n}`,{width:l.measureText(o).width+t.value.style.chart.words.proximity,height:r}}function he(o,r){return o.x<r.x+r.width&&o.x+o.width>r.x&&o.y<r.y+r.height&&o.y+o.height>r.y}function me(o,r,n){const u=[],l={x:-r/2,y:-n/2,width:r,height:n},h=0,x=0;return o.forEach(S=>{let G=!1;for(let E=0;E<Math.max(r,n)/2&&!G;E+=t.value.style.chart.words.packingWeight)for(let L=0;L<360&&!G;L+=t.value.style.chart.words.packingWeight){const ae=L*Math.PI/180,be=h+E*Math.cos(ae)-S.width/2,ke=x+E*Math.sin(ae)-S.height/2,v={...S,x:be,y:ke},Ce=v.x>=l.x&&v.y>=l.y&&v.x+v.width<=l.x+l.width&&v.y+v.height<=l.y+l.height,we=u.some(xe=>he(v,xe));Ce&&!we&&(u.push(v),G=!0)}}),u}const N=e.ref([]);e.watch(()=>i.dataset,q,{immediate:!0});const oe=e.computed(()=>Math.min(...g.value.map(o=>o.value))),pe=e.computed(()=>Math.max(...g.value.map(o=>o.value)));function q(){const o=[...g.value].filter(l=>l.value>=b.value).map(l=>l.value),r=Math.max(...o),n=Math.min(...o),u=[...g.value].filter(l=>l.value>=b.value).map((l,h)=>{const x=(l.value-n)/(r-n)*(a.value.maxFontSize-a.value.minFontSize)+a.value.minFontSize,S=fe(l.name,x);return{...l,id:s.createUid(),fontSize:x,width:S.width,height:S.height,color:t.value.style.chart.words.usePalette?t.value.customPalette[h]||t.value.customPalette[h%t.value.customPalette.length]||s.palette[h]||s.palette[h%s.palette.length]:t.value.style.chart.words.color}});N.value=me(u,a.value.width,a.value.height).sort((l,h)=>h.fontSize-l.fontSize)}const z=e.computed(()=>{const o=N.value.map(n=>({name:n.name,color:n.color})),r=N.value.map(n=>n.value);return{head:o,body:r}});function ne(){e.nextTick(()=>{const o=z.value.head.map((u,l)=>[[u.name],[z.value.body[l]]]),r=[[t.value.style.chart.title.text],[t.value.style.chart.title.subtitle.text],[[""],[t.value.table.columnNames.value]]].concat(o),n=s.createCsvContent(r);s.downloadCsv({csvContent:n,title:t.value.style.chart.title.text||"vue-ui-word-cloud"})})}const O=e.computed(()=>{const o=[t.value.table.columnNames.series,t.value.table.columnNames.value],r=z.value.head.map((l,h)=>{const x=s.dataLabel({p:t.value.table.td.prefix,v:z.value.body[h],s:t.value.table.td.suffix,r:t.value.table.td.roundingValue});return[{color:l.color,name:l.name},x]}),n={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],head:o,body:r,config:n}}),V=e.ref(!1);function ve(o){V.value=o,T.value+=1}function ge(){return N.value}function re(){f.value.showTable=!f.value.showTable}function le(){f.value.showTooltip=!f.value.showTooltip}const A=e.ref(!1);function U(){A.value=!A.value}M({getData:ge,generateCsv:ne,generatePdf:ee,generateImage:te,toggleTable:re,toggleTooltip:le,toggleAnnotator:U});const w=e.ref(null),P=e.ref(!1),W=e.ref(""),D=e.ref(null);function ye(o){if(!f.value.showTooltip)return;w.value=o.id,D.value={datapoint:o,config:t.value};const r=t.value.style.chart.tooltip.customFormat;if(P.value=!1,s.isFunction(r))try{const n=r({datapoint:o,config:t.value});typeof n=="string"&&(W.value=n,P.value=!0)}catch{console.warn("Custom format cannot be applied."),P.value=!1}if(!P.value){let n=`<svg viewBox="0 0 10 10" height="${t.value.style.chart.tooltip.fontSize}"><circle cx="5" cy="5" r="5" fill="${o.color}"/></svg><span>${o.name}:</span><b>${(o.value||0).toFixed(t.value.style.chart.tooltip.roundingValue)}</b>`;W.value=`<div dir="auto" style="display:flex; gap:4px; align-items:center; jsutify-content:center;">${n}</div>`}_.value=!0}return(o,r)=>(e.openBlock(),e.createElementBlock("div",{class:"vue-ui-word-cloud",ref_key:"wordCloudChart",ref:p,id:`wordCloud_${e.unref($)}`,style:e.normalizeStyle(`width: 100%; font-family:${e.unref(t).style.fontFamily};background:${e.unref(t).style.chart.backgroundColor};${e.unref(t).responsive?"height:100%":""}`),onMouseenter:r[3]||(r[3]=()=>e.unref(H)(!0)),onMouseleave:r[4]||(r[4]=()=>e.unref(H)(!1))},[e.unref(t).userOptions.buttons.annotator?(e.openBlock(),e.createBlock(Fe.PenAndPaper,{key:0,parent:e.unref(p),backgroundColor:e.unref(t).style.chart.backgroundColor,color:e.unref(t).style.chart.color,active:e.unref(A),onClose:U},null,8,["parent","backgroundColor","color","active"])):e.createCommentVNode("",!0),e.unref(t).style.chart.title.text?(e.openBlock(),e.createElementBlock("div",{key:1,ref_key:"chartTitle",ref:B,style:"width:100%;background:transparent;padding-bottom:24px"},[(e.openBlock(),e.createBlock(Se._sfc_main,{key:`title_${e.unref(m)}`,config:{title:{...e.unref(t).style.chart.title},subtitle:{...e.unref(t).style.chart.title.subtitle}}},null,8,["config"]))],512)):e.createCommentVNode("",!0),e.unref(t).userOptions.show&&e.unref(k)&&(e.unref(X)||e.unref(I))?(e.openBlock(),e.createBlock(se.UserOptions,{ref:"details",key:`user_option_${e.unref(T)}`,backgroundColor:e.unref(t).style.chart.backgroundColor,color:e.unref(t).style.chart.color,isPrinting:e.unref(Q),isImaging:e.unref(Z),uid:e.unref($),hasPdf:e.unref(t).userOptions.buttons.pdf,hasXls:e.unref(t).userOptions.buttons.csv,hasImg:e.unref(t).userOptions.buttons.img,hasTable:e.unref(t).userOptions.buttons.table,hasFullscreen:e.unref(t).userOptions.buttons.fullscreen,isFullscreen:e.unref(V),titles:{...e.unref(t).userOptions.buttonTitles},chartElement:e.unref(p),position:e.unref(t).userOptions.position,hasTooltip:e.unref(t).style.chart.tooltip.show&&e.unref(t).userOptions.buttons.tooltip,isTooltip:e.unref(f).showTooltip,hasAnnotator:e.unref(t).userOptions.buttons.annotator,isAnnotation:e.unref(A),onToggleFullscreen:ve,onGeneratePdf:e.unref(ee),onGenerateCsv:ne,onGenerateImage:e.unref(te),onToggleTable:re,onToggleTooltip:le,onToggleAnnotator:U,style:e.normalizeStyle({visibility:e.unref(X)?e.unref(I)?"visible":"hidden":"visible"})},e.createSlots({_:2},[o.$slots.optionPdf?{name:"optionPdf",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionPdf",{},void 0,!0)]),key:"0"}:void 0,o.$slots.optionCsv?{name:"optionCsv",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionCsv",{},void 0,!0)]),key:"1"}:void 0,o.$slots.optionImg?{name:"optionImg",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionImg",{},void 0,!0)]),key:"2"}:void 0,o.$slots.optionTable?{name:"optionTable",fn:e.withCtx(()=>[e.renderSlot(o.$slots,"optionTable",{},void 0,!0)]),key:"3"}:void 0,o.$slots.optionFullscreen?{name:"optionFullscreen",fn:e.withCtx(({toggleFullscreen:n,isFullscreen:u})=>[e.renderSlot(o.$slots,"optionFullscreen",e.normalizeProps(e.guardReactiveProps({toggleFullscreen:n,isFullscreen:u})),void 0,!0)]),key:"4"}:void 0,o.$slots.optionAnnotator?{name:"optionAnnotator",fn:e.withCtx(({toggleAnnotator:n,isAnnotator:u})=>[e.renderSlot(o.$slots,"optionAnnotator",e.normalizeProps(e.guardReactiveProps({toggleAnnotator:n,isAnnotator:u})),void 0,!0)]),key:"5"}:void 0]),1032,["backgroundColor","color","isPrinting","isImaging","uid","hasPdf","hasXls","hasImg","hasTable","hasFullscreen","isFullscreen","titles","chartElement","position","hasTooltip","isTooltip","hasAnnotator","isAnnotation","onGeneratePdf","onGenerateImage","style"])):e.createCommentVNode("",!0),e.unref(k)?(e.openBlock(),e.createElementBlock("svg",{key:3,class:e.normalizeClass({"vue-data-ui-fullscreen--on":e.unref(V),"vue-data-ui-fulscreen--off":!e.unref(V)}),xmlns:e.unref(s.XMLNS),viewBox:`0 0 ${e.unref(a).width<=0?10:e.unref(a).width} ${e.unref(a).height<=0?10:e.unref(a).height}`,style:"overflow:visible;background:transparent;"},[e.createVNode(Pe._sfc_main),o.$slots["chart-background"]?(e.openBlock(),e.createElementBlock("foreignObject",{key:0,x:0,y:0,width:e.unref(a).width<=0?10:e.unref(a).width,height:e.unref(a).height<=0?10:e.unref(a).height,style:{pointerEvents:"none"}},[e.renderSlot(o.$slots,"chart-background",{},void 0,!0)],8,Ue)):e.createCommentVNode("",!0),e.createElementVNode("g",{transform:`translate(${(e.unref(a).width<=0?10:e.unref(a).width)/2}, ${(e.unref(a).height<=0?10:e.unref(a).height)/2})`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(N),(n,u)=>(e.openBlock(),e.createElementBlock("g",null,[(e.openBlock(),e.createElementBlock("text",{fill:n.color,"font-weight":e.unref(t).style.chart.words.bold?"bold":"normal",key:u,x:n.x,y:n.y,"font-size":n.fontSize,transform:`translate(${n.width/2}, ${n.height/2})`,class:e.normalizeClass({animated:e.unref(t).useCssAnimation,"word-selected":e.unref(w)&&e.unref(w)===n.id&&e.unref(f).showTooltip,"word-not-selected":e.unref(w)&&e.unref(w)!==n.id&&e.unref(f).showTooltip}),"text-anchor":"middle","dominant-baseline":"central",onMouseover:l=>ye(n),onMouseleave:r[0]||(r[0]=l=>{w.value=null,_.value=!1}),style:e.normalizeStyle(`animation-delay:${u*e.unref(t).animationDelayMs}ms !important;`)},e.toDisplayString(n.name),47,De))]))),256))],8,We),e.renderSlot(o.$slots,"svg",{svg:{height:e.unref(a).height,width:e.unref(a).width}},void 0,!0)],10,qe)):e.createCommentVNode("",!0),o.$slots.watermark?(e.openBlock(),e.createElementBlock("div",Ge,[e.renderSlot(o.$slots,"watermark",e.normalizeProps(e.guardReactiveProps({isPrinting:e.unref(Q)||e.unref(Z)})),void 0,!0)])):e.createCommentVNode("",!0),e.createVNode(Be._sfc_main,{show:e.unref(f).showTooltip&&e.unref(_),backgroundColor:e.unref(t).style.chart.tooltip.backgroundColor,color:e.unref(t).style.chart.tooltip.color,fontSize:e.unref(t).style.chart.tooltip.fontSize,borderRadius:e.unref(t).style.chart.tooltip.borderRadius,borderColor:e.unref(t).style.chart.tooltip.borderColor,borderWidth:e.unref(t).style.chart.tooltip.borderWidth,backgroundOpacity:e.unref(t).style.chart.tooltip.backgroundOpacity,position:e.unref(t).style.chart.tooltip.position,offsetY:e.unref(t).style.chart.tooltip.offsetY,parent:e.unref(p),content:e.unref(W),isCustom:e.unref(P)},{"tooltip-before":e.withCtx(()=>[e.renderSlot(o.$slots,"tooltip-before",e.normalizeProps(e.guardReactiveProps({...e.unref(D)})),void 0,!0)]),"tooltip-after":e.withCtx(()=>[e.renderSlot(o.$slots,"tooltip-after",e.normalizeProps(e.guardReactiveProps({...e.unref(D)})),void 0,!0)]),_:3},8,["show","backgroundColor","color","fontSize","borderRadius","borderColor","borderWidth","backgroundOpacity","position","offsetY","parent","content","isCustom"]),e.createElementVNode("div",{ref_key:"chartSlicer",ref:J,style:"width:100%;background:transparent","data-html2canvas-ignore":""},[e.unref(t).style.chart.zoom.show?(e.openBlock(),e.createBlock(Ie,{key:0,value:e.unref(b),"onUpdate:value":r[1]||(r[1]=n=>e.isRef(b)?b.value=n:null),min:e.unref(oe),max:e.unref(pe),textColor:e.unref(t).style.chart.color,inputColor:e.unref(t).style.chart.zoom.color,selectColor:e.unref(t).style.chart.zoom.highlightColor,useResetSlot:e.unref(t).style.chart.zoom.useResetSlot,background:e.unref(t).style.chart.zoom.color,borderColor:e.unref(t).style.chart.backgroundColor,source:e.unref(t).style.chart.width,onReset:R},{"reset-action":e.withCtx(({reset:n})=>[e.renderSlot(o.$slots,"reset-action",e.normalizeProps(e.guardReactiveProps({reset:n})),void 0,!0)]),_:3},8,["value","min","max","textColor","inputColor","selectColor","useResetSlot","background","borderColor","source"])):e.createCommentVNode("",!0)],512),o.$slots.source?(e.openBlock(),e.createElementBlock("div",{key:5,ref_key:"source",ref:y,dir:"auto"},[e.renderSlot(o.$slots,"source",{},void 0,!0)],512)):e.createCommentVNode("",!0),e.unref(k)?(e.openBlock(),e.createBlock($e.default,{key:6,hideDetails:"",config:{open:e.unref(f).showTable,maxHeight:1e4,body:{backgroundColor:e.unref(t).style.chart.backgroundColor,color:e.unref(t).style.chart.color},head:{backgroundColor:e.unref(t).style.chart.backgroundColor,color:e.unref(t).style.chart.color}}},{content:e.withCtx(()=>[(e.openBlock(),e.createBlock(Te.DataTable,{key:`table_${e.unref(C)}`,colNames:e.unref(O).colNames,head:e.unref(O).head,body:e.unref(O).body,config:e.unref(O).config,title:`${e.unref(t).style.chart.title.text}${e.unref(t).style.chart.title.subtitle.text?` : ${e.unref(t).style.chart.title.subtitle.text}`:""}`,onClose:r[2]||(r[2]=n=>e.unref(f).showTable=!1)},{th:e.withCtx(({th:n})=>[e.createElementVNode("div",{innerHTML:n,style:{display:"flex","align-items":"center"}},null,8,Le)]),td:e.withCtx(({td:n})=>[e.createTextVNode(e.toDisplayString(n.name||n),1)]),_:1},8,["colNames","head","body","config","title"]))]),_:1},8,["config"])):e.createCommentVNode("",!0)],44,Re))}},He=ie._export_sfc(je,[["__scopeId","data-v-c154455a"]]);exports.default=He;
;