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