UNPKG

mmjs-core

Version:
2 lines (1 loc) 6.31 kB
"use strict";const e=require("vue"),X=require("./const.js"),p=require("./methods.js"),F=require("./filters.js"),Z=require("./legend-action.js"),I=require("mmjs-share/utils"),$=require("./help.const.js"),ee=require("./tools.js"),k=require("./transform.js"),te={class:"cssom_legend"},ne={class:"cssom_legend__wrapper"},oe=["onWheelCapture"],se=["onClick","onMouseenter","onMouseleave"],re=["src"],le=["viewBox"],ce=["d"],ie=["innerHTML"],ae=e.defineComponent({__name:"cssomLegend",props:{ecInstance:{},eventName:{default:"rendered"},throttleTime:{default:500},disabled:{type:Boolean,default:!1},enchanceCenter:{type:Boolean,default:!0},transfromFn:{}},emits:["legendToggleSelect","highlight","downplay"],setup(i,{emit:q}){const R=e.inject(X.cssomLegendInjectKey,void 0),A=e.useTemplateRef("cssomLegendRefKey"),N=e.useTemplateRef("cssomLegendWrapRefKey"),W=e.shallowRef(),E=e.ref(),x=q;e.watchEffect(()=>{typeof i.transfromFn=="function"&&(k.transfromState.transform=i.transfromFn)});const{legendToggleSelect:D,highlight:K,downplay:O}=Z.useLegendAction(W);function P(n){!i.disabled&&D(n),x("legendToggleSelect",n)}function V(n){!i.disabled&&K(n),x("highlight",n)}function H(n){!i.disabled&&O(n),x("downplay",n)}function G(n,r){var s;const t=((s=E.value)==null?void 0:s.series)??[];return F.normalizeLegendName({legend:n,series:t,legendIndex:r})}function J(n,r){if(!i.enchanceCenter)return{};if(n.type==="scroll"||n.orient==="vertical"||!N.value)return{};if(n.left!=="center"&&n.right!=="center")return{};try{const t=N.value[r],s=t.parentElement,o=s.getBoundingClientRect(),a=window.getComputedStyle(t),l=window.getComputedStyle(s),f=parseFloat(l.paddingLeft),_=parseFloat(l.paddingRight),y=parseFloat(l.borderLeftWidth),d=parseFloat(l.borderRightWidth),u=parseFloat(a.rowGap),S=o.width-f-_-y-d;let v=0;const C=Array.from(t.children),B=u*(C.length-1),w=C.map(c=>{const m=window.getComputedStyle(c),g=parseFloat(m.marginLeft),T=parseFloat(m.marginRight);return c.clientWidth+g+T});let L=w.reduce((c,m)=>(c+=m,c<=S&&(v+=1),c),B);if(L>S){let c=w.slice(0,v).reduce((g,T)=>(g+=T,g),u*(v-1));return{"--custom-max-width":k.transfromState.transformWrapMaxWidth(c,"px")}}return{"--custom-max-width":k.transfromState.transformWrapMaxWidth(L,"px")}}catch(t){console.error(`[Enhance Center]: ${t}`)}}const j=e.computed(()=>{var n;return((n=E.value)==null?void 0:n.legend)??[]}),Y=e.computed(()=>{var r;let n=(r=E.value)==null?void 0:r.color;return Array.isArray(n)?n:n?[n]:[]}),z=I.throttle(function(){E.value=this.getOption()},i.throttleTime);function h(n,r,t){var d,u,S,v,C,B,w,L,M,c,m,g;let s=(u=(d=t==null?void 0:t.serie)==null?void 0:d.itemStyle)==null?void 0:u.color;Reflect.set(h,"__colors",JSON.parse(JSON.stringify(Y.value)));const o=t==null?void 0:t.name,a={$vars:["seriesName","name","value"],borderColor:(v=(S=t==null?void 0:t.serie)==null?void 0:S.itemStyle)==null?void 0:v.borderColor,dataIndex:n,seriesIndex:r,value:(B=(C=t.serie)==null?void 0:C.data)==null?void 0:B[n],data:(L=(w=t.serie)==null?void 0:w.data)==null?void 0:L[n],seriesType:(M=t.serie)==null?void 0:M.type,name:(c=t.serie)==null?void 0:c.name,seriesId:`\0${o}\x000`,seriesName:o,dataType:void 0,color:h.__colors[n],componentIndex:r,componentSubType:(m=t.serie)==null?void 0:m.type,componentType:"customSeries"};s&&h.__colors.splice(n,0,s);let l=h.__colors[n];const f={},_=(t==null?void 0:t.textStyle)??{};p.forPropertsEffect(_,f,"textStyle",F.transformCss);const y=typeof l=="function"?l(a):l;return{"--item-color":k.transfromState.transformGradientCss(y),"--data-item-icon":(g=t.icon)==null?void 0:g.replaceAll("image://",""),...f}}h.__colors=[];function Q(n,r,t){var a;if(r.type!=="scroll")return;n.preventDefault();const s=(a=A.value)==null?void 0:a[t];if(!s)return;const o=$.scrollDirMap[r.orient]??$.scrollDirMap.horizontal;s.scrollTo(o(s,n.deltaY))}function U(){var n;(n=W.value)==null||n.on(i.eventName,z)}function b(){var n;(n=W.value)==null||n.off(i.eventName,z)}return e.watchEffect(()=>{var n;W.value=i.ecInstance??((n=R==null?void 0:R.value)==null?void 0:n.ec),b(),U()}),e.onScopeDispose(()=>{b()}),(n,r)=>(e.openBlock(),e.createElementBlock("div",te,[e.createElementVNode("div",ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(j.value,(t,s)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["cssom_legend__legend",[`cssom_legend--box-${s}`,`cssom_legend__legend--${t.type??"plain"}`,`legend_orient--${t.orient??"horizontal"}`]]),ref_for:!0,ref:"cssomLegendRefKey",style:e.normalizeStyle(e.unref(p.getCustomLegendProperty)(t)),key:s,onWheelCapture:e.withModifiers(o=>Q(o,t,s),["stop"])},[e.createElementVNode("div",{ref_for:!0,ref:"cssomLegendWrapRefKey",class:e.normalizeClass(["cssom_legend__legend__wrap",[`cssom_legend__legend__wrap--${t.type??"plain"}`]]),style:e.normalizeStyle(J(t,s))},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(G(t,s),(o,a)=>{var l,f,_,y,d;return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["cssom_legend__legend_item",{"cssom_legend__legend_item--unselect":!e.unref(p.getSelectStatus)(t,o.name)}]),key:a,style:e.normalizeStyle(h(a,s,o)),onClick:e.withModifiers(u=>P(o.name),["stop"]),onMouseenter:e.withModifiers(u=>V(o.name),["stop"]),onMouseleave:e.withModifiers(u=>H(o.name),["stop"])},[(l=o.icon??t.icon)!=null&&l.startsWith("image://")?(e.openBlock(),e.createElementBlock("img",{key:0,class:e.normalizeClass(["cssom_legend__image_icon",{"cssom_legend__image_icon--unselect":!e.unref(p.getSelectStatus)(t,o.name)}]),src:(f=o.icon??t.icon)==null?void 0:f.slice(8),alt:""},null,10,re)):(_=o.icon??t.icon)!=null&&_.startsWith("path://")?(e.openBlock(),e.createElementBlock("svg",{key:1,class:e.normalizeClass(["cssom_legend__svg_icon",{"cssom_legend__svg_icon--unselect":!e.unref(p.getSelectStatus)(t,o.name)}]),viewBox:e.unref(ee.calculateViewBox)((y=o.icon??t.icon)==null?void 0:y.slice(7))},[e.createElementVNode("path",{d:(d=o.icon??t.icon)==null?void 0:d.slice(7)},null,8,ce)],10,le)):(e.openBlock(),e.createElementBlock("div",{key:2,class:e.normalizeClass(["cssom_legend__rect",[...e.unref(p.getIconModified)(o.icon??t.icon,o)]])},null,2)),e.createElementVNode("div",{class:"cssom_legend__text",innerHTML:e.unref(p.formatter)(t,o.name)},null,8,ie)],46,se)}),128))],6)],46,oe))),128))])]))}});module.exports=ae;