quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 2.07 kB
JavaScript
import{SmartRenderer}from'../../../../fc-core/src/component-interface';import{extend2}from'../../../../fc-core/src/lib';const HORIZONTAL='horizontal',VERTICAL='vertical',M='M',H='H',V='V',BLANKREGEX=/\S/,SPACE=' ',STROKEDASH='stroke-dasharray',iswithinDomain=(a,b)=>!!(+a>=+b[0]&&+a<=+b[1]);class GridLine extends SmartRenderer{__setDefaultConfig(){super.__setDefaultConfig(),this.config.direction=HORIZONTAL,this.config.showgridlines=1,this.config.showboundarygridlines=1,this.config.style={},this.config.defaultStyle={stroke:'#EFEFEF',"stroke-width":'1',"stroke-opacity":'1'}}configureAttributes(a={}){super.configureAttributes(a);let b=this.config;for(let c in a)a.hasOwnProperty(c)&&'undefined'!=typeof a[c]&&(b[c]=a[c])}getPathArr(){let a,b,c,d,e,f,g,h,j,k,l,m=this,n=m.config,o=m.getFromEnv('getStyleDef'),p=m.getLinkedParent().config,q=n.direction,r=[],s=[];if(q===VERTICAL?(b=p.xConfigs[0],g=b.scale,f=V,c=g.getRangeValue,d=p.canvasBGTop+p.canvasBGHeight-p.padding.top,e=p.canvasBGTop-p.padding.top):(b=p.yConfigs[0],g=b.scale,f=H,c=p.canvasBGLeft,d=g.getRangeValue,e=p.canvasBGLeft+p.canvasBGWidth),b.tickarguments&&(s=b.tickarguments),a=b.style||{},n.style=o(a['grid-line']||{}),s.push(b.skipinfo||{}),s.push(b.dayinmajor||!1),j=g.ticks(...s),n.showgridlines)for(h=g.getDomain(),k=0,l=j.length;k<l;k++)(n.showboundarygridlines||0!==k&&k!==l-1)&&iswithinDomain(j[k],h)&&r.push([M,'function'==typeof c?c.call(g,j[k]):c,'function'==typeof d?d.call(g,j[k]):d,f,e]);return r}draw(){let a=this,b=a.config,c=b.styleGridLines,d=a.getPathArr(),e=extend2(extend2({},b.defaultStyle),c&&b.style);e[STROKEDASH]&&(e[STROKEDASH]='string'==typeof e[STROKEDASH]?e[STROKEDASH].split(SPACE).filter(a=>BLANKREGEX.test(a)).map(a=>+a):e[STROKEDASH]),a.addGraphicalElement({el:'group',container:{id:'strato',label:'strato',isParent:!0},component:a,label:'gridLine',attr:{name:'grid-line-group'},id:'gridLine'}),d.forEach((b,c)=>{a.addGraphicalElement({el:'path',attr:{path:b},css:e,container:{label:'gridLine'},id:'grid-line-'+c,component:a,label:'line'})})}}export default GridLine;