vue-data-ui-hq
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
2 lines (1 loc) • 11.3 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),l=require("./index-ZfICPrrM.cjs"),_=require("./useNestedProp-C14rfl0j.cjs"),M=require("./Shape-C3YtaYr4.cjs"),O=require("./vue-ui-skeleton-Bvmpr51u.cjs"),A=require("./PackageVersion-D3dK8oA3.cjs"),H=require("./_plugin-vue_export-helper-BHFhmbuH.cjs"),q={key:0},I={key:1},U=["xmlns","viewBox"],W=["width","height"],j=["id"],P=["stop-color"],G=["stop-color"],T=["id"],X=["stop-color"],Y=["stop-color"],R=["id"],J=["stop-color"],K=["stop-color"],Q={key:1},Z=["x","y","height","width","fill","stroke","stroke-width","rx"],ee={key:2},te=["x","y","font-size","font-weight","fill"],oe=["x","y","font-size","fill"],ne=["x","y","font-size","fill"],le=["height","width","x","onMouseover","stroke","stroke-width","rx","stroke-dasharray","onClick"],re={key:2,ref:"source",dir:"auto"},se={__name:"vue-ui-sparkhistogram",props:{config:{type:Object,default(){return{}}},dataset:{type:Array,default(){return[]}}},emits:["selectDatapoint"],setup(B,{emit:x}){e.useCssVars(n=>({bc5cc542:e.unref(N)}));const{vue_ui_sparkhistogram:E}=l.useConfig(),c=B,k=e.computed(()=>!!c.dataset&&c.dataset.length);e.onMounted(()=>{v()});function v(){l.objectIsEmpty(c.dataset)?l.error({componentName:"VueUiSparkHistogram",type:"dataset"}):c.dataset.forEach((n,a)=>{l.getMissingDatasetAttributes({datasetObject:n,requiredAttributes:["value"]}).forEach(o=>{l.error({componentName:"VueUiSparkHistogram",type:"datasetSerieAttribute",property:o,index:a})})})}const d=e.ref(l.createUid()),t=e.computed({get:()=>b(),set:n=>n});function b(){const n=_.useNestedProp({userConfig:c.config,defaultConfig:E});return n.theme?{..._.useNestedProp({userConfig:l.themes.vue_ui_sparkhistogram[n.theme]||c.config,defaultConfig:n})}:n}e.watch(()=>c.config,n=>{t.value=b(),v()},{deep:!0});const u=e.computed(()=>{const n=t.value.style.layout.height,a=t.value.style.layout.width,o=t.value.style.layout.padding.top,r=n-t.value.style.layout.padding.bottom,f=t.value.style.layout.padding.left,y=a-t.value.style.layout.padding.right,p=o+(n-o-t.value.style.layout.padding.bottom)/2,h=n-t.value.style.layout.padding.top-t.value.style.layout.padding.bottom,m=a-t.value.style.layout.padding.left-t.value.style.layout.padding.right;return{bottom:r,centerY:p,drawingHeight:h,drawingWidth:m,height:n,left:f,right:y,top:o,width:a}}),w=e.computed(()=>Math.max(...c.dataset.map(n=>Math.abs(n.value||0))));function C(n){return Math.abs(n)/w.value}const i=e.computed(()=>c.dataset.map((n,a)=>{const o=C(n.value||0),r=u.value.drawingHeight*o,f=u.value.drawingWidth/c.dataset.length,y=f*(t.value.style.bars.gap/100),p=f-y,h=u.value.centerY-r/2,m=u.value.left+(y/2+a*f),L=u.value.left+a*f,g=typeof n.intensity>"u"?100:Math.round(n.intensity*100),V=n.color?n.color:n.value>=0?l.setOpacity(t.value.style.bars.colors.positive,g):l.setOpacity(t.value.style.bars.colors.negative,g),z=n.color?n.color:n.value>=0?t.value.style.bars.colors.positive:t.value.style.bars.colors.negative,D=n.color?`url(#gradient_datapoint_${a}_${d.value})`:n.value>=0?`url(#gradient_positive_${a}_${d.value})`:`url(#gradient_negative_${a}_${d.value})`,F=m+p/2;return{...n,color:V,gradient:D,height:r,intensity:g,proportion:o,stroke:z,textAnchor:F,trapX:L,unitWidth:f,width:p,x:m,y:h}})),s=e.ref(null),$=x;function S(n,a){$("selectDatapoint",{datapoint:n,index:a})}const N=e.computed(()=>`${t.value.style.animation.speedMs}ms`);return(n,a)=>(e.openBlock(),e.createElementBlock("div",{style:e.normalizeStyle(`width:100%;background:${e.unref(t).style.backgroundColor};font-family:${e.unref(t).style.fontFamily}`),onMouseleave:a[1]||(a[1]=o=>s.value=null)},[e.unref(t).style.title.text?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(`width:calc(100% - 12px);background:transparent;margin:0 auto;margin:${e.unref(t).style.title.margin};padding: 0 6px;text-align:${e.unref(t).style.title.textAlign}`)},[e.createElementVNode("div",{style:e.normalizeStyle(`font-size:${e.unref(t).style.title.fontSize}px;color:${e.unref(t).style.title.color};font-weight:${e.unref(t).style.title.bold?"bold":"normal"}`)},[e.createTextVNode(e.toDisplayString(e.unref(t).style.title.text)+" ",1),e.unref(s)!==null?(e.openBlock(),e.createElementBlock("span",q,"- "+e.toDisplayString(e.unref(i)[e.unref(s)].timeLabel||"")+" "+e.toDisplayString(e.unref(l.applyDataLabel)(e.unref(t).style.labels.value.formatter,e.unref(i)[e.unref(s)].value,e.unref(l.dataLabel)({p:e.unref(t).style.labels.value.prefix,v:e.unref(i)[e.unref(s)].value,s:e.unref(t).style.labels.value.suffix,r:e.unref(t).style.labels.value.rounding}),{datapoint:e.unref(i)[e.unref(s)],seriesIndex:e.unref(s)})),1)):e.createCommentVNode("",!0),![void 0,null].includes(e.unref(s))&&![null,void 0].includes(e.unref(i)[e.unref(s)].valueLabel)?(e.openBlock(),e.createElementBlock("span",I,"("+e.toDisplayString(e.unref(i)[e.unref(s)].valueLabel||0)+")",1)):e.createCommentVNode("",!0)],4),e.unref(t).style.title.subtitle.text?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle(`font-size:${e.unref(t).style.title.subtitle.fontSize}px;color:${e.unref(t).style.title.subtitle.color};font-weight:${e.unref(t).style.title.subtitle.bold?"bold":"normal"}`)},e.toDisplayString(e.unref(t).style.title.subtitle.text),5)):e.createCommentVNode("",!0)],4)):e.createCommentVNode("",!0),e.unref(k)?(e.openBlock(),e.createElementBlock("svg",{key:1,xmlns:e.unref(l.XMLNS),viewBox:`0 0 ${e.unref(u).width} ${e.unref(u).height}`,style:{overflow:"visible"}},[e.createVNode(A._sfc_main),n.$slots["chart-background"]?(e.openBlock(),e.createElementBlock("foreignObject",{key:0,x:0,y:0,width:e.unref(u).width,height:e.unref(u).height,style:{pointerEvents:"none"}},[e.renderSlot(n.$slots,"chart-background",{},void 0,!0)],8,W)):e.createCommentVNode("",!0),e.createElementVNode("defs",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("radialGradient",{id:`gradient_positive_${r}_${e.unref(d)}`,cy:"50%",cx:"50%",r:"50%",fx:"50%",fy:"50%"},[e.createElementVNode("stop",{offset:"0%","stop-color":e.unref(l.setOpacity)(e.unref(l.shiftHue)(e.unref(t).style.bars.colors.positive,.05),o.intensity)},null,8,P),e.createElementVNode("stop",{offset:"100%","stop-color":e.unref(l.setOpacity)(e.unref(t).style.bars.colors.positive,o.intensity)},null,8,G)],8,j))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("radialGradient",{id:`gradient_negative_${r}_${e.unref(d)}`,cy:"50%",cx:"50%",r:"50%",fx:"50%",fy:"50%"},[e.createElementVNode("stop",{offset:"0%","stop-color":e.unref(l.setOpacity)(e.unref(l.shiftHue)(e.unref(t).style.bars.colors.negative,.05),o.intensity)},null,8,X),e.createElementVNode("stop",{offset:"100%","stop-color":e.unref(l.setOpacity)(e.unref(t).style.bars.colors.negative,o.intensity)},null,8,Y)],8,T))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("radialGradient",{id:`gradient_datapoint_${r}_${e.unref(d)}`,cy:"50%",cx:"50%",r:"50%",fx:"50%",fy:"50%"},[e.createElementVNode("stop",{offset:"0%","stop-color":e.unref(l.setOpacity)(e.unref(l.shiftHue)(o.color,.05),o.intensity)},null,8,J),e.createElementVNode("stop",{offset:"100%","stop-color":e.unref(l.setOpacity)(o.color,o.intensity)},null,8,K)],8,R))),256))]),!e.unref(t).style.bars.shape||e.unref(t).style.bars.shape==="square"?(e.openBlock(),e.createElementBlock("g",Q,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("rect",{x:o.x,y:o.y,height:o.height,width:o.width,fill:e.unref(t).style.bars.colors.gradient.show?o.gradient:o.color,stroke:o.stroke,"stroke-width":e.unref(t).style.bars.strokeWidth,rx:`${e.unref(t).style.bars.borderRadius*o.proportion/12}%`,class:e.normalizeClass({"vue-ui-sparkhistogram-shape":e.unref(t).style.animation.show})},null,10,Z))),256))])):(e.openBlock(),e.createElementBlock("g",ee,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createBlock(M._sfc_main,{plot:{x:o.x+o.width/2,y:o.y+o.height/2},color:e.unref(t).style.bars.colors.gradient.show?o.gradient:o.color,shape:e.unref(t).style.bars.shape,radius:o.height*.4,class:e.normalizeClass({"vue-ui-sparkhistogram-shape":e.unref(t).style.animation.show})},null,8,["plot","color","shape","radius","class"]))),256))])),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("text",{"text-anchor":"middle",x:o.textAnchor,y:o.y-e.unref(t).style.labels.value.fontSize/3+e.unref(t).style.labels.value.offsetY,"font-size":e.unref(t).style.labels.value.fontSize,"font-weight":e.unref(t).style.labels.value.bold?"bold":"normal",fill:e.unref(t).style.labels.value.color},e.toDisplayString(e.unref(l.applyDataLabel)(e.unref(t).style.labels.value.formatter,o.value,e.unref(l.dataLabel)({p:e.unref(t).style.labels.value.prefix,v:o.value,s:e.unref(t).style.labels.value.suffix,r:e.unref(t).style.labels.value.rounding}),{datapoint:e.unref(i)[e.unref(s)],seriesIndex:e.unref(s)})),9,te))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("g",null,[o.valueLabel?(e.openBlock(),e.createElementBlock("text",{key:0,x:o.textAnchor,y:o.y+o.height+e.unref(t).style.labels.valueLabel.fontSize,"font-size":e.unref(t).style.labels.valueLabel.fontSize,"text-anchor":"middle",fill:e.unref(t).style.labels.valueLabel.color},e.toDisplayString(o.valueLabel),9,oe)):e.createCommentVNode("",!0)]))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("g",null,[o.timeLabel?(e.openBlock(),e.createElementBlock("text",{key:0,x:o.textAnchor,y:e.unref(u).height-e.unref(t).style.labels.timeLabel.fontSize/2,"font-size":e.unref(t).style.labels.timeLabel.fontSize,fill:e.unref(t).style.labels.timeLabel.color,"text-anchor":"middle"},e.toDisplayString(o.timeLabel),9,ne)):e.createCommentVNode("",!0)]))),256)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i),(o,r)=>(e.openBlock(),e.createElementBlock("g",null,[e.createElementVNode("rect",{height:e.unref(u).height,width:o.unitWidth,fill:"transparent",x:o.trapX,y:0,onMouseover:f=>s.value=r,onMouseleave:a[0]||(a[0]=f=>s.value=null),stroke:e.unref(s)!==null&&e.unref(s)===r?e.unref(t).style.selector.stroke:"","stroke-width":e.unref(s)!==null&&e.unref(s)===r?e.unref(t).style.selector.strokeWidth:0,rx:e.unref(t).style.selector.borderRadius,"stroke-dasharray":e.unref(t).style.selector.strokeDasharray,onClick:()=>S(o,r)},null,40,le)]))),256))],8,U)):e.createCommentVNode("",!0),n.$slots.source?(e.openBlock(),e.createElementBlock("div",re,[e.renderSlot(n.$slots,"source",{},void 0,!0)],512)):e.createCommentVNode("",!0),e.unref(k)?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(O.default,{key:3,config:{type:"sparkHistogram",style:{backgroundColor:e.unref(t).style.backgroundColor,sparkHistogram:{color:"#CCCCCC"}}}},null,8,["config"]))],36))}},ae=H._export_sfc(se,[["__scopeId","data-v-c1906709"]]);exports.default=ae;