quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 5.68 kB
JavaScript
import{SmartRenderer}from'../component-interface';import{pluck,toRaphaelColor,pluckNumber}from'../lib';const MOTHER_OF_COLOR='#eeeeee';class ToolBar extends SmartRenderer{constructor(a){super(a),this.props={}}configureAttributes(a={}){let b=this,c=b.config,d=b.getFromEnv('chartConfig');b.__setDefaultConfig(),this.props.width=pluckNumber(a.width,0),this.props.height=pluckNumber(a.height,0),c.orientation=pluck(a.toolbarorientation,c.orientation),c.hPadding=pluck(a.toolbarhpadding,c.hPadding),c.vPadding=pluck(a.toolbarvpadding,c.vPadding),c.backgroundcolor=pluck(a.toolbarbackgroundcolor,c.backgroundcolor),c.backgroundalpha=pluck(a.toolbarbackgroundalpha,c.backgroundalpha),c.bordercolor=pluck(a.toolbarbordercolor,c.bordercolor),c.borderalpha=pluck(a.toolbarborderalpha,c.borderalpha),c.borderthickness=pluck(a.toolbarborderthickness,c.borderthickness),c.hDirection=pluckNumber(a.toolbarhdirection,'r'===d.toolbarHAlign?-1:1),c.vDirection=pluckNumber(a.toolbarvdirection,'b'===d.toolbarBAlign?-1:1),c.hAlign=pluck(a.hAlign,'center').toLowerCase(),c.vAlign=pluck(a.vAlign,'middle').toLowerCase(),c.marginTop=pluckNumber(a.marginTop,a.spacing,c.marginTop),c.marginLeft=pluckNumber(a.marginLeft,a.spacing,c.marginLeft),c.marginRight=pluckNumber(a.marginRight,a.spacing,c.marginRight),c.marginBottom=pluckNumber(a.marginBottom,a.spacing,c.marginBottom)}__setDefaultConfig(){let a=this,b=a.config;b.orientation='horizontal',b.hPadding=0,b.vPadding=0,b.backgroundcolor=MOTHER_OF_COLOR,b.backgroundalpha=0,b.bordercolor=MOTHER_OF_COLOR,b.borderalpha=0,b.borderthickness=1,b.spacing=2.5,b.marginTop=2.5,b.marginLeft=2.5,b.marginRight=2.5,b.marginBottom=2.5}getLogicalSpace(){let a=this,b=a.config,c=a.props,d=0,e=0;return a.getChildren('tool')&&a.getChildren('tool').length&&(a.getChildren('tool').forEach(a=>{if(!a.getState('removed')){let{width:c,height:f,marginTop:g,marginLeft:h,marginRight:i,marginBottom:j}=a.getLogicalSpace();'horizontal'===b.orientation?(void 0!==c&&(d+=c+(i||0)+(h||0)),e<(f=f+(g||0)+(j||0))&&(e=f)):(void 0!==f&&(e+=f+(g||0)+(j||0)),d<(c=c+(i||0)+(h||0))&&(d=c))}}),d+=2*b.hPadding,e+=2*b.vPadding,c.width=c.width>d?c.width:d,c.height=c.height>e?c.height:e),{width:d,height:e,marginTop:b.marginTop,marginLeft:b.marginLeft,marginRight:b.marginLeft,marginBottom:b.marginLeft}}manageSpace(){let a,b=this,c=b.config,d=this.getChildren('tool')||[];for(let d in a='horizontal'===c.orientation?b._placeToolHorizontally():b._placeToolVertically(),a)a.hasOwnProperty(d)&&b.getChild(d).setDimension(a[d]);d.forEach(a=>{a.manageSpace&&a.manageSpace()})}_placeToolHorizontally(){let a,b,c,d,e=this,f=e.config,g=e.props,h=f.hPadding,i=g.width-f.hPadding,j={},k={left:[],right:[],center:[]},l={left:0,right:0,center:0};return e.getChildren('tool')&&e.getChildren('tool').length&&((0<f.hDirection?e.getChildren('tool'):e.getChildren('tool').slice(0).reverse()).forEach(a=>{if(!a.getState('removed')){let{hAlign:b}=a.getAlignment(),{width:c,height:d,marginTop:h,marginLeft:i,marginRight:m,marginBottom:n}=a.getLogicalSpace(),o=a.getId();l[b]+=c+(i||0)+(m||0),k[b].push(o),j[o]={},j[o].y=e.props.y+h+f.vPadding+(g.height-2*f.vPadding-(d+n+h))/2}}),k.left.forEach(a=>{let{width:b,marginLeft:c,marginRight:d}=e.getChild(a).getLogicalSpace();h+=c||0,j[a].x=e.props.x+f.hPadding+h,h+=b+(d||0)}),k.right.reverse().forEach(a=>{let{width:b,marginLeft:c,marginRight:d}=e.getChild(a).getLogicalSpace();i-=b+(d||0),j[a].x=e.props.x+f.hPadding+i,i-=c||0}),a=[l.left+f.hPadding,g.width-(l.right+f.hPadding)],b=Math.abs(a[0]-a[1]),c=a[0]+b/2,d=c-l.center/2,k.center.forEach(a=>{let{width:b,marginLeft:c,marginRight:g}=e.getChild(a).getLogicalSpace();d+=c||0,j[a].x=e.props.x+f.hPadding+d,d+=b+g||0})),j}getAlignment(){return{hAlign:this.config.hAlign,vAlign:this.config.vAlign}}_placeToolVertically(){let a,b,c,d,e=this,f=e.config,g=e.props,h=f.vPadding,i=g.height-f.vPadding,j={top:[],middle:[],bottom:[]},k={top:0,middle:0,bottom:0},l={};return e.getChildren('tool')&&e.getChildren('tool').length&&((0<f.vDirection?e.getChildren('tool'):e.getChildren('tool').reverse()).forEach(a=>{if(!a.getState('removed')){let{vAlign:b}=a.getAlignment(),{width:c,height:d,marginTop:h,marginLeft:i,marginRight:m,marginBottom:n}=a.getLogicalSpace(),o=a.getId();k[b]+=d+(h||0)+(n||0),j[b].push(a.getId()),l[o]={},l[o].x=e.props.x+i+f.hPadding+i+(g.width-2*f.hPadding-(c+i+m))/2}}),j.top.forEach(a=>{let{height:b,marginTop:c,marginBottom:d}=e.getChild(a).getLogicalSpace();h+=c||0,l[a].y=e.props.y+f.vPadding+h,h+=b+(d||0)}),j.bottom.reverse().forEach(a=>{let{height:b,marginTop:c,marginBottom:d}=e.getChild(a).getLogicalSpace();i-=b+(d||0),l[a].y=e.props.y+f.vPadding+i,i-=c||0}),a=[k.top+f.vPadding,g.height-(k.bottom+f.vPadding)],b=Math.abs(a[0]-a[1]),c=a[0]+b/2,d=c-k.middle/2,j.middle.forEach(a=>{let{height:b,marginTop:c,marginBottom:g}=e.getChild(a).getLogicalSpace();d+=c||0,l[a].y=e.props.y+f.vPadding+d,d+=b+g||0})),l}setDimension(a={}){a.x!==void 0&&(this.props.x=a.x),a.y!==void 0&&(this.props.y=a.y),a.width!==void 0&&(this.props.width=a.width),a.height!==void 0&&(this.props.height=a.height)}getDimension(){return this.props}draw(){let a=this,b=a.config,c=a.getDimension();a.addGraphicalElement({id:'group',el:'group',attr:{name:'toolbar'},container:{id:'toolbar-master',isParent:!0},component:a,label:'group'}),a.addGraphicalElement({id:'carpet',el:'rect',attr:Object.assign({fill:toRaphaelColor({color:b.backgroundcolor,alpha:b.backgroundalpha}),stroke:toRaphaelColor({color:b.bordercolor,alpha:b.borderalpha}),"stroke-width":b.borderthickness},c),container:{label:'group',id:'group'},component:a,label:'carpet'})}getName(){return'toolbar'}getType(){return'Toolbar'}}export default ToolBar;