UNPKG

@fusioncharts/core

Version:

JavaScript Data Visualisation Library

1 lines 10.5 kB
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports.default=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _componentInterface=require("../component-interface");var _lib=require("../lib");var MOTHER_OF_COLOR="#eeeeee",ORIENTATION_HORIZ="horizontal",callManageSpaceIfPresent=function callManageSpaceIfPresent(child){child.manageSpace&&child.manageSpace()};var ToolBar=function(_SmartRenderer){function ToolBar(id){var _this2;_this2=_SmartRenderer.call(this,id)||this;_this2.props={};return _this2}(0,_inheritsLoose2.default)(ToolBar,_SmartRenderer);var _proto=ToolBar.prototype;_proto.configureAttributes=function configureAttributes(options){if(options===void 0){options={}}var _this=this,conf=_this.config,chartConfig=_this.getFromEnv("chartConfig");_this.__setDefaultConfig();this.props.width=(0,_lib.pluckNumber)(options.width,0);this.props.height=(0,_lib.pluckNumber)(options.height,0);conf.orientation=(0,_lib.pluck)(options.toolbarorientation,conf.orientation);conf.hPadding=(0,_lib.pluck)(options.toolbarhpadding,conf.hPadding);conf.vPadding=(0,_lib.pluck)(options.toolbarvpadding,conf.vPadding);conf.backgroundcolor=(0,_lib.pluck)(options.toolbarbackgroundcolor,conf.backgroundcolor);conf.backgroundalpha=(0,_lib.pluck)(options.toolbarbackgroundalpha,conf.backgroundalpha);conf.bordercolor=(0,_lib.pluck)(options.toolbarbordercolor,conf.bordercolor);conf.borderalpha=(0,_lib.pluck)(options.toolbarborderalpha,conf.borderalpha);conf.borderthickness=(0,_lib.pluck)(options.toolbarborderthickness,conf.borderthickness);conf.hDirection=(0,_lib.pluckNumber)(options.toolbarhdirection,chartConfig.toolbarHAlign==="r"?-1:1);conf.vDirection=(0,_lib.pluckNumber)(options.toolbarvdirection,chartConfig.toolbarBAlign==="b"?-1:1);conf.hAlign=(0,_lib.pluck)(options.hAlign,"center").toLowerCase();conf.vAlign=(0,_lib.pluck)(options.vAlign,"middle").toLowerCase();conf.marginTop=(0,_lib.pluckNumber)(options.marginTop,options.spacing,conf.marginTop);conf.marginLeft=(0,_lib.pluckNumber)(options.marginLeft,options.spacing,conf.marginLeft);conf.marginRight=(0,_lib.pluckNumber)(options.marginRight,options.spacing,conf.marginRight);conf.marginBottom=(0,_lib.pluckNumber)(options.marginBottom,options.spacing,conf.marginBottom)};_proto.__setDefaultConfig=function __setDefaultConfig(){var conf=this.config;conf.orientation=ORIENTATION_HORIZ;conf.hPadding=0;conf.vPadding=0;conf.backgroundcolor=MOTHER_OF_COLOR;conf.backgroundalpha=0;conf.bordercolor=MOTHER_OF_COLOR;conf.borderalpha=0;conf.borderthickness=1;conf.spacing=2.5;conf.marginTop=2.5;conf.marginLeft=2.5;conf.marginRight=2.5;conf.marginBottom=2.5};_proto.getLogicalSpace=function getLogicalSpace(){var _this=this,conf=_this.config,props=_this.props,_width=0,_height=0;if(_this.getChildren("tool")&&_this.getChildren("tool").length){_this.getChildren("tool").forEach((function(tool){if(!tool.getState("removed")){var _tool$getLogicalSpace=tool.getLogicalSpace(),width=_tool$getLogicalSpace.width,height=_tool$getLogicalSpace.height,marginTop=_tool$getLogicalSpace.marginTop,marginLeft=_tool$getLogicalSpace.marginLeft,marginRight=_tool$getLogicalSpace.marginRight,marginBottom=_tool$getLogicalSpace.marginBottom;if(conf.orientation==="horizontal"){width!==_lib.UNDEF&&(_width+=width+(marginRight||0)+(marginLeft||0));_height<(height=height+(marginTop||0)+(marginBottom||0))&&(_height=height)}else{height!==_lib.UNDEF&&(_height+=height+(marginTop||0)+(marginBottom||0));_width<(width=width+(marginRight||0)+(marginLeft||0))&&(_width=width)}}}));_width+=2*conf.hPadding;_height+=2*conf.vPadding;props.width=props.width>_width?props.width:_width;props.height=props.height>_height?props.height:_height}return{width:_width,height:_height,marginTop:conf.marginTop,marginLeft:conf.marginLeft,marginRight:conf.marginLeft,marginBottom:conf.marginLeft}};_proto.manageSpace=function manageSpace(){var _this=this,childTools=this.getChildren("tool")||[],pos;if(this.config.orientation==="horizontal"){pos=_this._placeToolHorizontally()}else{pos=_this._placeToolVertically()}for(var key in pos){if(pos.hasOwnProperty(key)){_this.getChild(key).setDimension(pos[key])}}childTools.forEach(callManageSpaceIfPresent)};_proto._placeToolHorizontally=function _placeToolHorizontally(){var _this=this,conf=_this.config,props=_this.props,centerSpaceRange,availableSpaceForCenter,centerPoint,centerPivot,leftPivot=conf.hPadding,rigthPivot=props.width-conf.hPadding,posById={},hAlignMap={left:[],right:[],center:[]},hAlignSpace={left:0,right:0,center:0};if(_this.getChildren("tool")&&_this.getChildren("tool").length){(conf.hDirection>0?_this.getChildren("tool"):_this.getChildren("tool").slice(0).reverse()).forEach((function(tool){if(!tool.getState("removed")){var _tool$getAlignment=tool.getAlignment(),hAlign=_tool$getAlignment.hAlign,_tool$getLogicalSpace2=tool.getLogicalSpace(),width=_tool$getLogicalSpace2.width,height=_tool$getLogicalSpace2.height,marginTop=_tool$getLogicalSpace2.marginTop,marginLeft=_tool$getLogicalSpace2.marginLeft,marginRight=_tool$getLogicalSpace2.marginRight,marginBottom=_tool$getLogicalSpace2.marginBottom,id=tool.getId();hAlignSpace[hAlign]+=width+(marginLeft||0)+(marginRight||0);hAlignMap[hAlign].push(id);posById[id]={};posById[id].y=_this.props.y+marginTop+conf.vPadding+(props.height-conf.vPadding*2-(height+marginBottom+marginTop))/2}}));hAlignMap.left.forEach((function(id){var _this$getChild$getLog=_this.getChild(id).getLogicalSpace(),width=_this$getChild$getLog.width,marginLeft=_this$getChild$getLog.marginLeft,marginRight=_this$getChild$getLog.marginRight;leftPivot+=marginLeft||0;posById[id].x=_this.props.x+conf.hPadding+leftPivot;leftPivot+=width+(marginRight||0)}));hAlignMap.right.reverse().forEach((function(id){var _this$getChild$getLog2=_this.getChild(id).getLogicalSpace(),width=_this$getChild$getLog2.width,marginLeft=_this$getChild$getLog2.marginLeft,marginRight=_this$getChild$getLog2.marginRight;rigthPivot-=width+(marginRight||0);posById[id].x=_this.props.x+conf.hPadding+rigthPivot;rigthPivot-=marginLeft||0}));centerSpaceRange=[hAlignSpace.left+conf.hPadding,props.width-(hAlignSpace.right+conf.hPadding)];availableSpaceForCenter=Math.abs(centerSpaceRange[0]-centerSpaceRange[1]);centerPoint=centerSpaceRange[0]+availableSpaceForCenter/2;centerPivot=centerPoint-hAlignSpace.center/2;hAlignMap.center.forEach((function(id){var _this$getChild$getLog3=_this.getChild(id).getLogicalSpace(),width=_this$getChild$getLog3.width,marginLeft=_this$getChild$getLog3.marginLeft,marginRight=_this$getChild$getLog3.marginRight;centerPivot+=marginLeft||0;posById[id].x=_this.props.x+conf.hPadding+centerPivot;centerPivot+=width+marginRight||0}))}return posById};_proto.getAlignment=function getAlignment(){return{hAlign:this.config.hAlign,vAlign:this.config.vAlign}};_proto._placeToolVertically=function _placeToolVertically(){var _this=this,conf=_this.config,props=_this.props,middleSpaceRange,availableSpaceForCenter,middlePoint,middlePivot,topPivot=conf.vPadding,bottomPivot=props.height-conf.vPadding,vAlignMap={top:[],middle:[],bottom:[]},vAlignSpace={top:0,middle:0,bottom:0},posById={};if(_this.getChildren("tool")&&_this.getChildren("tool").length){(conf.vDirection>0?_this.getChildren("tool"):_this.getChildren("tool").reverse()).forEach((function(tool){if(!tool.getState("removed")){var _tool$getAlignment2=tool.getAlignment(),vAlign=_tool$getAlignment2.vAlign,_tool$getLogicalSpace3=tool.getLogicalSpace(),width=_tool$getLogicalSpace3.width,height=_tool$getLogicalSpace3.height,marginTop=_tool$getLogicalSpace3.marginTop,marginLeft=_tool$getLogicalSpace3.marginLeft,marginRight=_tool$getLogicalSpace3.marginRight,marginBottom=_tool$getLogicalSpace3.marginBottom,id=tool.getId();vAlignSpace[vAlign]+=height+(marginTop||0)+(marginBottom||0);vAlignMap[vAlign].push(tool.getId());posById[id]={};posById[id].x=_this.props.x+marginLeft+conf.hPadding+marginLeft+(props.width-conf.hPadding*2-(width+marginLeft+marginRight))/2}}));vAlignMap.top.forEach((function(id){var _this$getChild$getLog4=_this.getChild(id).getLogicalSpace(),height=_this$getChild$getLog4.height,marginTop=_this$getChild$getLog4.marginTop,marginBottom=_this$getChild$getLog4.marginBottom;topPivot+=marginTop||0;posById[id].y=_this.props.y+conf.vPadding+topPivot;topPivot+=height+(marginBottom||0)}));vAlignMap.bottom.reverse().forEach((function(id){var _this$getChild$getLog5=_this.getChild(id).getLogicalSpace(),height=_this$getChild$getLog5.height,marginTop=_this$getChild$getLog5.marginTop,marginBottom=_this$getChild$getLog5.marginBottom;bottomPivot-=height+(marginBottom||0);posById[id].y=_this.props.y+conf.vPadding+bottomPivot;bottomPivot-=marginTop||0}));middleSpaceRange=[vAlignSpace.top+conf.vPadding,props.height-(vAlignSpace.bottom+conf.vPadding)];availableSpaceForCenter=Math.abs(middleSpaceRange[0]-middleSpaceRange[1]);middlePoint=middleSpaceRange[0]+availableSpaceForCenter/2;middlePivot=middlePoint-vAlignSpace.middle/2;vAlignMap.middle.forEach((function(id){var _this$getChild$getLog6=_this.getChild(id).getLogicalSpace(),height=_this$getChild$getLog6.height,marginTop=_this$getChild$getLog6.marginTop,marginBottom=_this$getChild$getLog6.marginBottom;middlePivot+=marginTop||0;posById[id].y=_this.props.y+conf.vPadding+middlePivot;middlePivot+=height+marginBottom||0}))}return posById};_proto.setDimension=function setDimension(dim){if(dim===void 0){dim={}}dim.x!==_lib.UNDEF&&(this.props.x=dim.x);dim.y!==_lib.UNDEF&&(this.props.y=dim.y);dim.width!==_lib.UNDEF&&(this.props.width=dim.width);dim.height!==_lib.UNDEF&&(this.props.height=dim.height)};_proto.getDimension=function getDimension(){return this.props};_proto.draw=function draw(){var _this=this,conf=_this.config;_this.addGraphicalElement({id:"group",el:"group",attr:{name:"toolbar"},container:{id:"toolbar-master",isParent:true},component:_this,label:"group"});_this.addGraphicalElement({id:"carpet",el:"rect",attr:Object.assign({fill:(0,_lib.toRaphaelColor)({color:conf.backgroundcolor,alpha:conf.backgroundalpha}),stroke:(0,_lib.toRaphaelColor)({color:conf.bordercolor,alpha:conf.borderalpha}),"stroke-width":conf.borderthickness},_this.getDimension()),container:{label:"group",id:"group"},component:_this,label:"carpet"})};_proto.getName=function getName(){return"toolbar"};_proto.getType=function getType(){return"Toolbar"};return ToolBar}(_componentInterface.SmartRenderer);var _default=exports.default=ToolBar;