vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
2 lines (1 loc) • 15.8 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),s=require("./index-_gyicZFE.cjs"),ye=require("./Title-CsERtJKI.cjs"),oe=require("./usePrinter-BRTNfg7r.cjs"),be=require("./DataTable-DL8_xKlk.cjs"),we=require("./vue-ui-accordion-8mzPx86h.cjs"),Ce=require("./vue-ui-skeleton-KlT3Rmkn.cjs"),le=require("./useNestedProp-BJQoarHp.cjs"),Ne=require("./PackageVersion-DHtx9fnE.cjs"),xe=require("./PenAndPaper-DPoMEHE6.cjs"),$e=require("./useUserOptionState-BgepsfED.cjs"),Be=require("./useChartAccessibility-Cm7nkzTG.cjs"),_e=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),Se=["id"],Pe={key:1,ref:"noTitle",class:"vue-data-ui-no-title-space",style:"height:36px; width: 100%;background:transparent"},Ee={key:2,style:"width:100%;background:transparent;padding-bottom:24px"},Te=["xmlns","viewBox"],Oe=["width","height"],Fe=["id"],ze=["stop-color"],Ie=["stop-color"],Le=["d","fill","stroke","stroke-width"],Ve=["x","y","height","width","fill","stroke","stroke-width","onMouseenter"],Ae=["x","y","font-size","fill"],He=["x","y","font-size","fill"],Me={key:4,class:"vue-data-ui-watermark"},qe={key:6,ref:"source",dir:"auto"},De=["innerHTML"],Ue={__name:"vue-ui-flow",props:{config:{type:Object,default(){return{}}},dataset:{type:Array,default(){return[]}}},setup(ne,{expose:ae}){const{vue_ui_flow:re}=s.useConfig(),h=ne,B=e.computed(()=>!!h.dataset&&h.dataset.length);e.onMounted(()=>{z()});function z(){s.objectIsEmpty(h.dataset)&&s.error({componentName:"VueUiFlow",type:"dataset"})}const _=e.ref(s.createUid()),I=e.ref(null),L=e.ref(0),V=e.ref(0),y=e.ref(!1);function se(o){y.value=o,L.value+=1}const t=e.computed({get:()=>q(),set:o=>o}),{userOptionsVisible:S,setUserOptionsVisibility:A,keepUserOptionState:H}=$e.useUserOptionState({config:t.value}),{svgRef:M}=Be.useChartAccessibility({config:t.value.style.chart.title});function q(){const o=le.useNestedProp({userConfig:h.config,defaultConfig:re});return o.theme?{...le.useNestedProp({userConfig:s.themes.vue_ui_flow[o.theme]||h.config,defaultConfig:o}),customPalette:s.themePalettes[o.theme]||s.palette}:o}e.watch(()=>h.config,o=>{t.value=q(),S.value=!t.value.userOptions.showOnChartHover,z(),V.value+=1,b.value.showTable=t.value.table.show},{deep:!0});const{isPrinting:D,isImaging:U,generatePdf:Y,generateImage:G}=oe.usePrinter({elementId:`flow_${_.value}`,fileName:t.value.style.chart.title.text||"vue-ui-flow"}),ue=e.computed(()=>t.value.userOptions.show&&!t.value.style.chart.title.text),P=e.computed(()=>s.convertCustomPalette(t.value.customPalette)),R=e.computed(()=>t.value.style.chart.nodes.gap),g=e.computed(()=>t.value.style.chart.nodes.width),b=e.ref({showTable:t.value.table.show}),j=e.computed(()=>t.value.style.chart.links.width),E=e.computed(()=>!h.dataset||!h.dataset.length?[]:h.dataset.map(o=>[o[0],o[1],s.checkNaN(o[2])])),W=e.computed(()=>{const o={};function n(a){o[a]||(o[a]={inflow:0,outflow:0})}E.value.forEach(([a,r,c])=>{n(a),n(r),o[a].outflow+=c,o[r].inflow+=c});let l=0;for(const a in o){const r=Math.max(o[a].inflow,o[a].outflow);l=Math.max(l,r)}return l});function ie(o){return o/W.value*100+t.value.style.chart.nodes.minHeight}function ce(o){const n=t.value.style.chart.nodes.minHeight;return(o-n)/100*W.value}function de(o){const n={},l={};function a(u,i){n[u]||(n[u]={height:0,level:null,inflow:0,outflow:0}),n[u].level===null&&(n[u].level=i),l[i]||(l[i]=[]),l[i].includes(u)||l[i].push(u)}o.forEach(([u,i,v],k)=>{const m=n[u]?n[u].level:0,$=m+1;a(u,m),a(i,$),n[u].children||(n[u].children=[]),n[u].children.push({target:i,value:v}),n[u].outflow+=v,n[i].inflow+=v}),Object.keys(n).forEach((u,i)=>{n[u].color=P.value[i]||P.value[i%P.value.length]||s.palette[i]||s.palette[i%d.length]});for(const u in n)n[u].height=ie(Math.max(n[u].inflow,n[u].outflow)),n[u].name=u;const r={};for(const u in l){let i=0;l[u].forEach((v,k)=>{const m=n[v].height;r[v]={x:parseInt(u,10)*j.value+t.value.style.chart.padding.left,y:i,absoluteY:i,height:m,i:k,color:n[v].color,value:ce(m)},i+=m+R.value})}const c=[];for(const u in n){let i=r[u].absoluteY+t.value.style.chart.padding.top;n[u].children&&n[u].children.forEach(({target:v,value:k},m)=>{const $=r[v].y+t.value.style.chart.padding.top,O=r[u],F=r[v],K=s.checkNaN(i),Q=s.checkNaN(i+k/n[u].outflow*O.height),ee=s.checkNaN($),te=s.checkNaN($+k/n[v].inflow*F.height),ke={id:s.createUid(),source:u,target:v,path:`M ${s.checkNaN(O.x)+s.checkNaN(g.value)} ${K} L ${s.checkNaN(O.x)+s.checkNaN(g.value)} ${Q} L ${s.checkNaN(F.x)} ${te} L ${s.checkNaN(F.x)} ${ee} Z`,value:k,sourceColor:n[u].color,targetColor:n[v].color};c.push(ke),i+=Q-K,r[v].y+=te-ee})}return{nodeCoordinates:r,links:c}}const f=e.computed(()=>{const o=de(h.dataset);return{nodes:Object.keys(o.nodeCoordinates).map((n,l)=>({...o.nodeCoordinates[n],name:n})),links:o.links}}),ve=e.computed(()=>he(f.value.nodes));function he(o){const n={};for(const a in o){const{x:r,height:c}=o[a];n[r]||(n[r]=0),n[r]+=c+R.value}return Math.max(...Object.values(n))}const w=e.computed(()=>{const{top:o,right:n,left:l,bottom:a}=t.value.style.chart.padding,r=E.value.length*j.value;return{height:ve.value+o+a,width:n+Math.max(...f.value.nodes.map(c=>c.x))+g.value,left:l,top:o,right:r-n,p_top:o,p_bottom:a}});function fe(o){const n={},l={},a=new Set;return E.value.forEach(([r,c,u])=>{n[r]||(n[r]=[]),l[c]||(l[c]=[]),n[r].push(c),l[c].push(r)}),n[o]&&n[o].forEach(r=>a.add(r)),l[o]&&l[o].forEach(r=>a.add(r)),Array.from(a).concat(o)}const p=e.ref(null),C=e.ref(null);function pe(o){p.value=fe(o.name),C.value=o.name}function me(){p.value=null,C.value=null}const X=e.computed(()=>f.value.links.map(({source:o,target:n,sourceColor:l,targetColor:a,value:r})=>({source:o,target:n,sourceColor:l,targetColor:a,value:r})));function Z(){e.nextTick(()=>{const o=X.value.map((a,r)=>[[a.source],[a.target],[a.value]]),n=[[t.value.style.chart.title.text],[t.value.style.chart.title.subtitle.text],[[t.value.table.columnNames.source],[t.value.table.columnNames.target],[t.value.table.columnNames.value]]].concat(o),l=s.createCsvContent(n);s.downloadCsv({csvContent:l,title:t.value.style.chart.title.text||"vue-ui-flow"})})}const N=e.computed(()=>{const o=[t.value.table.columnNames.source,t.value.table.columnNames.target,t.value.table.columnNames.value],n=X.value.map((r,c)=>[{color:r.sourceColor,name:r.source},{color:r.targetColor,name:r.target},s.dataLabel({p:t.value.style.chart.nodes.labels.prefix,v:r.value,s:t.value.style.chart.nodes.labels.suffix,r:t.value.style.chart.nodes.labels.rounding})]),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.source,t.value.table.columnNames.target,t.value.table.columnNames.value],head:o,body:n,config:l}});function ge(){return f.value}function J(){b.value.showTable=!b.value.showTable}const x=e.ref(!1);function T(){x.value=!x.value}return ae({getData:ge,generateCsv:Z,generateImage:G,generatePdf:Y,toggleTable:J,toggleAnnotator:T}),(o,n)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"flowChart",ref:I,class:e.normalizeClass(`vue-ui-flow ${y.value?"vue-data-ui-wrapper-fullscreen":""}`),style:e.normalizeStyle(`font-family:${t.value.style.fontFamily};width:100%; text-align:center;background:${t.value.style.chart.backgroundColor}`),id:`flow_${_.value}`,onMouseenter:n[2]||(n[2]=()=>e.unref(A)(!0)),onMouseleave:n[3]||(n[3]=()=>e.unref(A)(!1))},[t.value.userOptions.buttons.annotator?(e.openBlock(),e.createBlock(xe.PenAndPaper,{key:0,svgRef:e.unref(M),backgroundColor:t.value.style.chart.backgroundColor,color:t.value.style.chart.color,active:x.value,onClose:T},null,8,["svgRef","backgroundColor","color","active"])):e.createCommentVNode("",!0),ue.value?(e.openBlock(),e.createElementBlock("div",Pe,null,512)):e.createCommentVNode("",!0),t.value.style.chart.title.text?(e.openBlock(),e.createElementBlock("div",Ee,[(e.openBlock(),e.createBlock(ye._sfc_main,{key:`title_${V.value}`,config:{title:{cy:"flow-title",...t.value.style.chart.title},subtitle:{cy:"flow-subtitle",...t.value.style.chart.title.subtitle}}},null,8,["config"]))])):e.createCommentVNode("",!0),t.value.userOptions.show&&B.value&&(e.unref(H)||e.unref(S))?(e.openBlock(),e.createBlock(oe.UserOptions,{ref:"details",key:`user_option_${L.value}`,backgroundColor:t.value.style.chart.backgroundColor,color:t.value.style.chart.color,isPrinting:e.unref(D),isImaging:e.unref(U),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:y.value,titles:{...t.value.userOptions.buttonTitles},chartElement:I.value,position:t.value.userOptions.position,hasAnnotator:t.value.userOptions.buttons.annotator,isAnnotation:x.value,onToggleFullscreen:se,onGeneratePdf:e.unref(Y),onGenerateCsv:Z,onGenerateImage:e.unref(G),onToggleTable:J,onToggleAnnotator:T,style:e.normalizeStyle({visibility:e.unref(H)?e.unref(S)?"visible":"hidden":"visible"})},e.createSlots({_:2},[o.$slots.menuIcon?{name:"menuIcon",fn:e.withCtx(({isOpen:l,color:a})=>[e.renderSlot(o.$slots,"menuIcon",e.normalizeProps(e.guardReactiveProps({isOpen:l,color:a})),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:a})=>[e.renderSlot(o.$slots,"optionFullscreen",e.normalizeProps(e.guardReactiveProps({toggleFullscreen:l,isFullscreen:a})),void 0,!0)]),key:"5"}:void 0,o.$slots.optionAnnotator?{name:"optionAnnotator",fn:e.withCtx(({toggleAnnotator:l,isAnnotator:a})=>[e.renderSlot(o.$slots,"optionAnnotator",e.normalizeProps(e.guardReactiveProps({toggleAnnotator:l,isAnnotator:a})),void 0,!0)]),key:"6"}:void 0]),1032,["backgroundColor","color","isPrinting","isImaging","uid","hasPdf","hasXls","hasImg","hasTable","hasFullscreen","isFullscreen","titles","chartElement","position","hasAnnotator","isAnnotation","onGeneratePdf","onGenerateImage","style"])):e.createCommentVNode("",!0),(e.openBlock(),e.createElementBlock("svg",{ref_key:"svgRef",ref:M,xmlns:e.unref(s.XMLNS),viewBox:`0 0 ${w.value.width} ${w.value.height}`,class:e.normalizeClass({"vue-data-ui-fullscreen--on":y.value,"vue-data-ui-fulscreen--off":!y.value}),style:e.normalizeStyle(`max-width:100%; overflow: visible; background:transparent;color:${t.value.style.chart.color}`)},[e.createVNode(Ne._sfc_main),o.$slots["chart-background"]?(e.openBlock(),e.createElementBlock("foreignObject",{key:0,x:0,y:0,width:w.value.width,height:w.value.height,style:{pointerEvents:"none"}},[e.renderSlot(o.$slots,"chart-background",{},void 0,!0)],8,Oe)):e.createCommentVNode("",!0),e.createElementVNode("defs",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value.links,(l,a)=>(e.openBlock(),e.createElementBlock("linearGradient",{id:l.id,x1:"0%",y1:"0%",x2:"100%",y2:"0%"},[e.createElementVNode("stop",{offset:"0%","stop-color":l.sourceColor},null,8,ze),e.createElementVNode("stop",{offset:"100%","stop-color":l.targetColor},null,8,Ie)],8,Fe))),256))]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value.links,l=>(e.openBlock(),e.createElementBlock("path",{class:"vue-ui-flow-link",d:l.path,fill:`url(#${l.id})`,stroke:t.value.style.chart.links.stroke,"stroke-width":t.value.style.chart.links.strokeWidth,style:e.normalizeStyle(`opacity:${C.value?[l.target,l.source].includes(C.value)?1:.3:t.value.style.chart.links.opacity}`)},null,12,Le))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value.nodes,(l,a)=>(e.openBlock(),e.createElementBlock("rect",{class:"vue-ui-flow-node",x:l.x,y:e.unref(s.checkNaN)(l.absoluteY)+t.value.style.chart.padding.top,height:e.unref(s.checkNaN)(l.height),width:g.value,fill:l.color,stroke:t.value.style.chart.nodes.stroke,"stroke-width":t.value.style.chart.nodes.strokeWidth,onMouseenter:r=>pe(l),onMouseleave:n[0]||(n[0]=r=>me()),style:e.normalizeStyle(`opacity:${p.value?p.value.includes(l.name)?1:.2:1}`)},null,44,Ve))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value.nodes,(l,a)=>(e.openBlock(),e.createElementBlock("text",{x:l.x+g.value/2,y:e.unref(s.checkNaN)(l.absoluteY+l.height/2-t.value.style.chart.nodes.labels.fontSize/4)+t.value.style.chart.padding.top,"font-size":t.value.style.chart.nodes.labels.fontSize,fill:e.unref(s.adaptColorToBackground)(l.color),"text-anchor":"middle",style:e.normalizeStyle(`pointer-events: none; opacity:${p.value?p.value.includes(l.name)?1:0:1}`)},e.toDisplayString(t.value.style.chart.nodes.labels.abbreviation.use?e.unref(s.abbreviate)({source:l.name,length:t.value.style.chart.nodes.labels.abbreviation.length}):l.name),13,Ae))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value.nodes,(l,a)=>(e.openBlock(),e.createElementBlock("text",{x:l.x+g.value/2,y:e.unref(s.checkNaN)(l.absoluteY+l.height/2+t.value.style.chart.nodes.labels.fontSize)+t.value.style.chart.padding.top,"font-size":t.value.style.chart.nodes.labels.fontSize,fill:e.unref(s.adaptColorToBackground)(l.color),"text-anchor":"middle",style:e.normalizeStyle(`pointer-events: none; opacity:${p.value?p.value.includes(l.name)?1:0:1}`)},e.toDisplayString(e.unref(s.applyDataLabel)(t.value.style.chart.nodes.labels.formatter,l.value,e.unref(s.dataLabel)({p:t.value.style.chart.nodes.labels.prefix,v:l.value,s:t.value.style.chart.nodes.labels.suffix,r:t.value.style.chart.nodes.labels.rounding}),{datapoint:l,seriesIndex:a})),13,He))),256)),e.renderSlot(o.$slots,"svg",{svg:w.value},void 0,!0)],14,Te)),o.$slots.watermark?(e.openBlock(),e.createElementBlock("div",Me,[e.renderSlot(o.$slots,"watermark",e.normalizeProps(e.guardReactiveProps({isPrinting:e.unref(D)||e.unref(U)})),void 0,!0)])):e.createCommentVNode("",!0),B.value?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(Ce.default,{key:5,config:{type:"flow",style:{backgroundColor:t.value.style.chart.backgroundColor}}},null,8,["config"])),o.$slots.source?(e.openBlock(),e.createElementBlock("div",qe,[e.renderSlot(o.$slots,"source",{},void 0,!0)],512)):e.createCommentVNode("",!0),B.value?(e.openBlock(),e.createBlock(we.default,{key:7,hideDetails:"",config:{open:b.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.createVNode(be.DataTable,{colNames:N.value.colNames,head:N.value.head,body:N.value.body,config:N.value.config,title:`${t.value.style.chart.title.text}${t.value.style.chart.title.subtitle.text?` : ${t.value.style.chart.title.subtitle.text}`:""}`,onClose:n[1]||(n[1]=l=>b.value.showTable=!1)},{th:e.withCtx(({th:l})=>[e.createElementVNode("div",{innerHTML:l,style:{display:"flex","align-items":"center"}},null,8,De)]),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)],46,Se))}},Ye=_e._export_sfc(Ue,[["__scopeId","data-v-0482669d"]]);exports.default=Ye;
;