@fusioncharts/charts
Version:
JavaScript Data Visualisation Library
1 lines • 8.73 kB
JavaScript
"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("@fusioncharts/core/src/component-interface");var _lib=require("@fusioncharts/core/src/lib");var _dependencyManager=require("@fusioncharts/core/src/dependency-manager");var _index=_interopRequireDefault(require("./index.animation"));var stringConstants={BACKGROUNDLOADED:"BackgroundLoaded",BACKGROUNDLOADERROR:"BackgroundLoadError",clipRectStr:"clip-rect"},POSITION_TOP="top",POSITION_BOTTOM="bottom",POSITION_MIDDLE="middle",POSITION_RIGHT="right",POSITION_LEFT="left",TILE="tile",FILL="fill",FIT="fit",noneStr,DASH_DEF=noneStr="none",getHandler=function getHandler(_this){var config=_this.config;return{load:function load(){var bgImageDisplayMode=config.bgImageDisplayMode,bgImageVAlign=config.bgImageVAlign,bgImageHAlign=config.bgImageHAlign,bgImageScale=config.bgImageScale,bgSWFAlpha=config.bgSWFAlpha,bgSWF=config.bgSWF,backgroundImage=_this.getGraphicalElement("backgroundImage"),imgRef=backgroundImage._.RefImg,chart=_this.getFromEnv("chart");chart.fireChartInstanceEvent(stringConstants.BACKGROUNDLOADED,{url:bgSWF,bgImageAlpha:bgSWFAlpha,bgImageDisplayMode:bgImageDisplayMode,bgImageVAlign:bgImageVAlign,bgImageHAlign:bgImageHAlign,bgImageScale:bgImageScale,imageheight:imgRef.height,imagewidth:imgRef.width})},error:function error(e){var bgImageDisplayMode=config.bgImageDisplayMode,bgImageVAlign=config.bgImageVAlign,bgImageHAlign=config.bgImageHAlign,bgImageScale=config.bgImageScale,bgSWFAlpha=config.bgSWFAlpha,bgSWF=config.bgSWF,chart=_this.getFromEnv("chart");chart.fireChartInstanceEvent(stringConstants.BACKGROUNDLOADERROR,{url:bgSWF,bgImageAlpha:bgSWFAlpha,error:e,bgImageDisplayMode:bgImageDisplayMode,bgImageVAlign:bgImageVAlign,bgImageHAlign:bgImageHAlign,bgImageScale:bgImageScale})}}},COMMA=",",BLANKSTRING="";(0,_dependencyManager.addDep)({name:"backgroundAnimation",type:"animationRule",extension:_index.default});var Background=function(_ComponentInterface){function Background(){var _this2;_this2=_ComponentInterface.call(this)||this;_this2.config.handler=getHandler(_this2);return _this2}(0,_inheritsLoose2.default)(Background,_ComponentInterface);var _proto=Background.prototype;_proto.getName=function getName(){return"background"};_proto.getType=function getType(){return"background"};_proto._getBackgroundCosmetics=function _getBackgroundCosmetics(){var backGroundComp=this,chartAttrs=backGroundComp.getFromEnv("chart-attrib"),colorM=backGroundComp.getFromEnv("color-manager"),is3D=backGroundComp.getFromEnv("chartConfig").is3D,palleteString=is3D?_lib.chartPaletteStr.chart3D:_lib.chartPaletteStr.chart2D;return{FCcolor:{color:(0,_lib.pluck)(chartAttrs.bgcolor,colorM.getColor(palleteString.bgColor)),alpha:(0,_lib.pluck)(chartAttrs.bgalpha,colorM.getColor(palleteString.bgAlpha)),angle:(0,_lib.pluck)(chartAttrs.bgangle,colorM.getColor(palleteString.bgAngle)),ratio:(0,_lib.pluck)(chartAttrs.bgratio,colorM.getColor(palleteString.bgRatio))}}};_proto.configureAttributes=function configureAttributes(){var backGroundComp=this,config=backGroundComp.config,chartAttrs=backGroundComp.getFromEnv("chart-attrib"),chartConfig=backGroundComp.getFromEnv("chartConfig"),is3D=chartConfig.is3D,colorM=backGroundComp.getFromEnv("color-manager"),chartBorderWidth,showBorder,bgImageVAlign,bgImageHAlign,bgImageDisplayMode=config.bgImageDisplayMode=(0,_lib.pluck)(chartAttrs.bgimagedisplaymode,noneStr).toLowerCase();config.bgSWF=(0,_lib.pluck)(chartAttrs.bgimage,chartAttrs.bgswf);config.bgSWFAlpha=(0,_lib.pluckNumber)(chartAttrs.bgimagealpha,chartAttrs.bgswfalpha,100);showBorder=config.showBorder=(0,_lib.pluckNumber)(chartAttrs.showborder,chartConfig.showBorder,is3D?0:1);config.borderWidth=Math.max(showBorder?(0,_lib.pluckNumber)(chartAttrs.borderthickness,1):0,0);config.borderRadius=(0,_lib.pluckNumber)(chartAttrs.borderradius,0);config.borderDashStyle=(0,_lib.pluckNumber)(chartAttrs.borderdashed,0)?(0,_lib.getDashStyle)((0,_lib.pluckNumber)(chartAttrs.borderdashlen,4),(0,_lib.pluckNumber)(chartAttrs.borderdashgap,2),chartBorderWidth):DASH_DEF;config.borderAlpha=(0,_lib.pluck)(chartAttrs.borderalpha,is3D?"100":colorM&&colorM.getColor("borderAlpha"));config.borderColor=(0,_lib.convertColor)((0,_lib.pluck)(chartAttrs.bordercolor,is3D?"#666666":colorM&&colorM.getColor("borderColor")),config.borderAlpha);config.bgImageVAlign=bgImageVAlign=(0,_lib.getValidValue)(chartAttrs.bgimagevalign,BLANKSTRING).toLowerCase();config.bgImageHAlign=bgImageHAlign=(chartAttrs.bgimagehalign||BLANKSTRING).toLowerCase();config.bgImageScale=(0,_lib.pluckNumber)(chartAttrs.bgimagescale,100);config.containerBackgroundColor=(0,_lib.getContainerBackgroundColor)(backGroundComp.getFromEnv("chartInstance"));config.backgroundColor=backGroundComp._getBackgroundCosmetics();if(bgImageDisplayMode===TILE||bgImageDisplayMode===FILL||bgImageDisplayMode===FIT){if(bgImageVAlign!==POSITION_TOP&&bgImageVAlign!==POSITION_MIDDLE&&bgImageVAlign!==POSITION_BOTTOM){config.bgImageVAlign=POSITION_MIDDLE}if(bgImageHAlign!==POSITION_LEFT&&bgImageHAlign!==POSITION_MIDDLE&&bgImageHAlign!==POSITION_RIGHT){config.bgImageHAlign=POSITION_MIDDLE}}else{if(bgImageVAlign!==POSITION_TOP&&bgImageVAlign!==POSITION_MIDDLE&&bgImageVAlign!==POSITION_BOTTOM){config.bgImageVAlign=POSITION_TOP}if(bgImageHAlign!==POSITION_LEFT&&bgImageHAlign!==POSITION_MIDDLE&&bgImageHAlign!==POSITION_RIGHT){config.bgImageHAlign=POSITION_LEFT}}};_proto.draw=function draw(){var backGroundComp=this,paper=backGroundComp.getFromEnv("paper"),backgroundElementDummy=backGroundComp.getGraphicalElement("backgroundElement"),backgroundElement,borderElementDummy=backGroundComp.getGraphicalElement("borderElement"),borderElement,config=backGroundComp.config,chart=backGroundComp.getFromEnv("chart"),chartConfig=backGroundComp.getFromEnv("chartConfig"),attrObj,backgroundColor=config.backgroundColor,animationManager=backGroundComp.getFromEnv("animationManager"),backgroundImageDummy=backGroundComp.getGraphicalElement("backgroundImage"),backgroundImage,bgSWF=config.bgSWF,backgroundGroup=chart.getChildContainer("backgroundGroup"),chartWidth=chartConfig.width,chartHeight=chartConfig.height,chartBorderWidth=config.borderWidth||0,borderRadius=config.borderRadius,borderDashStyle=config.borderDashStyle,borderColor=config.borderColor,bgSWFAlpha=config.bgSWFAlpha,imgClipRect=chartBorderWidth+COMMA+chartBorderWidth+COMMA+(chartWidth-chartBorderWidth*2)+COMMA+(chartHeight-chartBorderWidth*2),bgImageDisplayMode=config.bgImageDisplayMode,bgImageVAlign=config.bgImageVAlign,bgImageHAlign=config.bgImageHAlign,bgImageScale=config.bgImageScale,height,width;paper.canvas.style.backgroundColor=config.containerBackgroundColor;width=chartWidth-chartBorderWidth*2;height=chartHeight-chartBorderWidth*2;attrObj={x:chartBorderWidth,y:chartBorderWidth,width:width<0?0:width,height:height>0?height:0,stroke:_lib.preDefStr.noneStr,fill:(0,_lib.toRaphaelColor)(backgroundColor)};backgroundElement=animationManager.setAnimation({el:backgroundElementDummy||"rect",attr:attrObj,container:backgroundGroup,component:backGroundComp,label:"rect"});backgroundElement.show();if(!backgroundElementDummy){backGroundComp.addGraphicalElement("backgroundElement",backgroundElement)}width=chartWidth-chartBorderWidth;height=chartHeight-chartBorderWidth;attrObj={x:chartBorderWidth/2,y:chartBorderWidth/2,width:width<0?0:width,height:height>0?height:0,stroke:borderColor,"stroke-width":chartBorderWidth,"stroke-dasharray":borderDashStyle,fill:_lib.preDefStr.noneStr,r:borderRadius||0};borderElement=animationManager.setAnimation({el:borderElementDummy||"rect",attr:attrObj,container:backgroundGroup,component:backGroundComp,label:"rect"});borderElement.show();if(!borderElementDummy){backGroundComp.addGraphicalElement("borderElement",borderElement)}if(bgSWF&&!backGroundComp.getState("removed")){backgroundImage=animationManager.setAnimation({el:backgroundImageDummy||"imagegrid",attr:{imagegrid:[bgImageDisplayMode,bgImageVAlign,bgImageHAlign,bgImageScale,chartBorderWidth,chartWidth,chartHeight],src:bgSWF,opacity:bgSWFAlpha*.01,"clip-rect":imgClipRect},container:backgroundGroup,component:backGroundComp,label:"imagegrid"});backgroundImage.show();if(!backgroundImageDummy){backGroundComp.addGraphicalElement("backgroundImage",backgroundImage);backgroundImage.on("load",config.handler.load);backgroundImage.on("error",config.handler.error)}}else{backgroundImageDummy&&backGroundComp.removeGraphicalElement(backgroundImageDummy)}};return Background}(_componentInterface.ComponentInterface);var _default=exports.default=Background;