UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 6.67 kB
import{pluck,pluckNumber,preDefStr,extend2,TRACKER_FILL,polyPathToPath,convertColor,mapSymbolName}from'../../../../../../fc-core/src/lib';import{ComponentInterface}from'../../../../../../fc-core/src/component-interface';import{addDep}from'../../../../../../fc-core/src/dependency-manager';import legendItemAnimation from'./legend-item.animation';let POINTER=preDefStr.POINTER,NONE='none',M='M',L='L',_getSymbolPath=(a,b,c,d,e)=>{var f,g,h,i,j,k,l,m,n,o,p,q=[M];return'column'===e||'dragColumn'===e||'column3D'===e||'realtimeColumn'===e||'errorBar2D'===e?(f=.25*c,g=.5*f,h=.7*d,i=.4*d,q=q.concat([a,b+d,'l',0,-h,f,0,0,h,'z','m',f+g,0,'l',0,-d,f,0,0,d,'z','m',f+g,0,'l',0,-i,f,0,0,i,'z'])):'bar2D'===e||'bar3D'===e?(f=.3*c,g=.6*c,h=d/4,i=h/2,q=q.concat([a,b,L,a+g,b,a+g,b+h,a,b+h,'Z',M,a,b+h+i,L,a+c,b+h+i,a+c,b+h+i+h,a,b+2*h+i,'Z',M,a,b+2*(h+i),L,a+f,b+2*(h+i),a+f,b+d,a,b+d,'Z'])):'area'===e||'area3d'===e||'areaspline'===e||'dragArea'===e||'realTimeArea'===e||'splinearea'===e?(f=.3*c,g=.6*c,h=.6*d,i=.2*d,j=.8*d,q=q.concat([a,b+j,L,a,b+h,a+f,b+i,a+g,b+h,a+c,b+i,a+c,b+j,'Z'])):'pie2D'===e||'pie3d'===e||'doughnut2D'===e||'doughnut3D'===e?(f=.5*c,g=.9*f,o=1,p=1,k=a+f+o,m=b+f-o,l=a+f-p,n=b+f+p,q=q.concat([k,m,L,k,m-g+o,'A',g-o,g-o,0,0,1,k+g-o,m,'Z',M,l,n,L,l,n-g,'A',g,g,0,1,0,l+g,n,'Z'])):'boxandwhisker2d'===e?q=q.concat([a,b,L,a+c,b,a+c,b+d,a,b+d,'Z']):q=q.concat([a,b,L,a+c,b,a+c,b+d,a,b+d,'Z']),{path:q}},getAnchorProps=function(a,b){let c=a.config,d=a.getLinkedParent().config,e=d.symbolWidth,f=pluckNumber(d.padding,4),g=.5*e,h=(d.initialItemX||0)+c._legendX+f,i=(d.initialItemY||0)+c._legendY-f,j=h+d.symbolPadding+g,k=i+(c._markerYGutter||0)+d.symbolPadding+g,l=mapSymbolName(c.anchorSide),m=c.symbol=l&&l.split('_')||[],n='spoke'===m[0]?1:0;return('line'===c.type||c.drawLine)&&(g*=.6),{path:polyPathToPath([m[1]||2,j,k,g,c.startAngle,c.spoke||n]),cursor:b.cursor||POINTER,stroke:b.stroke,fill:b.fill,"stroke-width":b['stroke-width']||.5}};addDep({name:'legendItemAnimation',type:'animationRule',extension:legendItemAnimation});class LegendItem extends ComponentInterface{constructor(){super(),this._stateCosmetics={},this._legendState=[]}getName(){return'legendItem'}parseLegendCosmetics(){let a,b,c,d=this,e=this.getLinkedParent(),f=e.getLegendState(),g=d.getLegendState(),h=['default'],j={};for(h=h.concat(f,g),c=0;c<h.length;c++)a=e.getStateCosmetics(h[c]),b=d.getStateCosmetics(h[c]),a&&('function'==typeof a?j=a(j,d):extend2(j,a)),b&&('function'==typeof b?j=b(j,d):extend2(j,b));return j}getType(){return'legendItem'}configure(a){var b,c,d=this,e=d.config;for(b in a)if(a.hasOwnProperty(b))if('object'!=typeof a[b])e[b]=a[b];else{let d=e[b]?e[b]:{};for(c in a[b])d[c]=a[b][c];e[b]=d}}itemClickFn(){let a=this,b=a.getFromEnv('chart-attrib'),c=pluckNumber(b.interactivelegend,1),d=a.getLinkedItem('owner');c&&d.legendInteractivity(a)}dispose(){this.removeEventListener('fc-click',this.click),this.removeEventListener('fc-mouseover',this.mouseover),this._dispose()}getLegendState(){return this._legendState}hasState(a){var b,c,d=this.getLegendState();for(b=0,c=d.length;b<c;b++)if(d[b]===a)return!0;return!1}setLegendState(a,b){this.hasState(a)||(b?this._legendState.push(a):this._legendState.unshift(a)),this.asyncDraw()}removeLegendState(a){var b,c,d=1;if(a)for(b=0,c=this._legendState.length;b<c&&d;b++)a===this._legendState[b]&&(this._legendState.splice(b,1),d=0);else this._legendState.length=0;this.asyncDraw()}removeStateCosmetics(a){delete this._stateCosmetics[a]}setStateCosmetics(a,b){this._stateCosmetics[a]=b}getStateCosmetics(a){return this._stateCosmetics[a]}draw(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,N,O,P,Q,R=this.getLinkedParent(),S=R.getFromEnv('chart'),T=S.config,U=this,V=U.getFromEnv('animationManager'),W=U.config,X=R.config,Y=X.legendHeight,Z=X.symbolPadding,$=X.symbolWidth,_=X.interactiveLegend,aa=X.textPadding||2,ba=pluckNumber(X.padding,4),ca=X.itemHoverStyle,da=R.getChildContainer('itemGroup'),ea=X.drawCustomLegendIcon,fa=U.hasState('hidden'),ga={};a=U.parseLegendCosmetics(),c=a.symbol,d=X.initialItemX||0,e=X.initialItemY||0,i=W.type,t=a.symbol.stroke||'000000',u=a.symbol.fill,b=a.symbol.lineWidth||X.lineWidth,w=W.anchorSide,x=W.drawLine,j=d+W._legendX+ba,k=e+W._legendY-ba,G=U.getGraphicalElement('legendItemBackground'),h=U.getGraphicalElement('legendItemText'),l=U.getGraphicalElement('legendItemLine'),o=U.getGraphicalElement('legendItemSymbol'),_=pluck(W.interactiveLegend,_),_||(a.cursor='default'),H=a.text,P=j+Y+aa-2,Q=k+(W._legendTestY||0),H.text=W.name,H.x=P,H.y=Q,g=V.setAnimation({el:h||'text',attr:H,component:U,container:da,label:'icon'}),h||(g=U.addGraphicalElement('legendItemText',g)),g.data('legendItem',W),I=!1,ea&&!1!==W.customLegendIcon?(B=!fa&&c.borderColor,C=pluck(c.borderAlpha),z=!fa&&c.bgColor,A=pluck(c.bgAlpha,'100'),D=a.symbol.rawFillColor,u=fa?a.symbol.fill:z||D,u=convertColor(u,A),E=a.symbol.rawStrokeColor,t=fa?a.symbol.stroke:B||E||D,t=convertColor(t,C),q=.5*$,p=j+Z+q,f=k+(W._markerYGutter||0)+Z+q,y=mapSymbolName(c.sides),s=y&&mapSymbolName(c.sides).split('_')||[],r='spoke'===s[0]?1:0,J={path:polyPathToPath([s[1]||2,p,f,q,c.startAngle||0,r]),cursor:a.symbol.cursor||POINTER,stroke:t,fill:u,"stroke-width":pluckNumber(c.borderThickness,1)}):'line'===i||x?(f=k+(W._markerYGutter||0)+Z+.5*$,O={path:[M,j+Z,f,L,j+Z+$,f]},I=!0,ga={opacity:T.legendiconalpha||1,"stroke-width":b,stroke:t,cursor:a.cursor||POINTER},w&&(J=getAnchorProps(U,a.symbol))):w?J=getAnchorProps(U,a.symbol):'line'!==i&&(t=W.symbolStroke||t,m=_getSymbolPath(j+Z,k+(W._markerYGutter||0)+Z,$,$,i),J={path:m.path,"stroke-width":.5,stroke:t,fill:u,cursor:a.cursor||POINTER}),O&&I?(Object.assign(O,ga),l=V.setAnimation({el:l||'path',attr:O,component:U,callback:function(){this.show()},container:da}),!U.getGraphicalElement('legendItemLine')&&(l=U.addGraphicalElement('legendItemLine',l))):l&&l.hide(),J?(J.opacity=pluckNumber(a.symbol.opacity,1),n=V.setAnimation({el:o||'path',attr:J,component:U,callback:function(){this.show()},container:da,label:'icon'}),(!o||!o.node)&&(n=U.addGraphicalElement('legendItemSymbol',n)),n.data('legendItem',W)):o&&o.hide(),v=a.background&&a.background.legendBackgroundColor?convertColor(a.background.legendBackgroundColor,a.background.alpha):TRACKER_FILL,K={x:j,y:k,width:W._totalWidth,height:W._legendH,r:0,fill:v,opacity:1,"stroke-width":1,stroke:NONE,cursor:a.symbol.cursor||POINTER},F=V.setAnimation({el:G||'rect',attr:K,css:N,component:U,label:'background',container:da}),G||U.addGraphicalElement('legendItemBackground',F),F.data('legendItem',U).data('interactive',_).data('itemHoverStyle',ca).data('itemStyle',a)}}export default LegendItem;