UNPKG

@fusioncharts/features

Version:

FusionCharts JavaScript charting framework

1 lines 9.82 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 _mergeDeepRight=_interopRequireDefault(require("ramda/src/mergeDeepRight"));var _annotationBase=_interopRequireDefault(require("./annotation-base"));var _lib=require("@fusioncharts/core/src/lib");var _utils=require("../utils");var _componentBase=_interopRequireDefault(require("@fusioncharts/core/src/component-interface/component-base"));var selectionGroup,UNDEF,DEFAULT="default";var DEFAULT_COLOR="#FF0000",DEFAULT_BORDER_COLOR="#000000",DEFAULT_ALPHA=100,DEFAULT_SHOW_BORDER=0,DEFAULT_BORDER_THICKNESS=2,DEFAULT_DASH_LEN=5,DEFAULT_DASH_GAP=3,FULL_ANGLE_DEGREES=360,DEFAULT_IS_DASHED=0,DEFAULT_SHOW_SHADOW=0,DEFAULT_TOOLTEXT="",RADIAL="radial",DEFAULT_FILL_ANGLE=0,DEFAULT_IS_VISIBLE=true,SHAPE_TYPE_LINE="line",BORDER_COLOR_NONE="none",GRADIENT_UNIT_OBJECT_BBOX="objectBoundingBox",isDefined=function isDefined(value){return value===UNDEF?UNDEF:1};var AnnotationShape=function(_AnnotationBaseShape){function AnnotationShape(){return _AnnotationBaseShape.apply(this,arguments)||this}(0,_inheritsLoose2.default)(AnnotationShape,_AnnotationBaseShape);var _proto=AnnotationShape.prototype;_proto.configureAttributes=function configureAttributes(rawConfig){var _ref,_ref2;var shape=this,conf=shape.config,chart=shape.getFromEnv("chart"),group=shape.getLinkedParent();shape.groupConfig={};shape.rawConfig={};if(group!==null){shape.groupConfig.x=group._getConfig("x");shape.groupConfig.y=group._getConfig("y");shape.groupConfig.grpXShift=group._getConfig("grpXShift");shape.groupConfig.grpYShift=group._getConfig("grpYShift");shape.groupConfig.color=group._getConfig("color");shape.groupConfig.alpha=group._getConfig("alpha");shape.groupConfig.font=group._getConfig("font");shape.groupConfig.fontSize=group._getConfig("fontSize");shape.groupConfig.textAlign=group._getConfig("textAlign");shape.groupConfig.textVAlign=group._getConfig("textVAlign");shape.groupConfig.rotateText=group._getConfig("rotateText");shape.groupConfig.wrapText=group._getConfig("wrapText");shape.groupConfig.toolText=group._getConfig("toolText");shape.groupConfig.scaleX=group._getConfig("scaleX");shape.groupConfig.scaleY=group._getConfig("scaleY");shape.groupConfig.scaleImageX=group._getConfig("scaleImageX");shape.groupConfig.scaleImageY=group._getConfig("scaleImageY");shape.groupConfig.link=group._getConfig("link")}shape.rawConfig=(0,_mergeDeepRight.default)(shape.rawConfig,rawConfig)||{};conf.type=shape.rawConfig.type;conf.color=shape._getFillColor(shape.rawConfig,this.groupConfig);conf.link=(0,_lib.pluck)(shape.rawConfig.link,shape.groupConfig.link);conf.borderThickness=(0,_lib.pluckNumber)(parseFloat(shape.rawConfig.borderThickness),parseFloat(shape.rawConfig.thickness),DEFAULT_BORDER_THICKNESS);conf.showBorder=(0,_lib.pluckNumber)(shape.rawConfig.showBorder,parseFloat(shape.rawConfig.borderThickness),parseFloat(shape.rawConfig.thickness),isDefined(shape.rawConfig.borderColor),isDefined(shape.rawConfig.borderAlpha),DEFAULT_SHOW_BORDER);conf.borderColor=shape._getBorderColor(shape.rawConfig);conf.dashed=(0,_lib.pluckNumber)(shape.rawConfig.dashed,DEFAULT_IS_DASHED);conf.dashLen=(0,_lib.pluckNumber)(shape.rawConfig.dashLen,DEFAULT_DASH_LEN);conf.dashGap=(0,_lib.pluckNumber)(parseFloat(shape.rawConfig.dashGap),DEFAULT_DASH_GAP);conf.dashArrayStr=conf.dashed?(0,_lib.getDashStyle)(conf.dashLen,conf.dashGap):"none";conf.x=(0,_lib.pluckNumber)(shape.rawConfig.x,shape.rawConfig.xPos,0);conf.y=(0,_lib.pluckNumber)(shape.rawConfig.y,shape.rawConfig.yPos,0);conf.tox=(0,_lib.pluckNumber)(shape.rawConfig.toX,conf.x,0);conf.toy=(0,_lib.pluckNumber)(shape.rawConfig.toY,conf.y,0);conf.toy>=0&&conf.y>=0&&conf.toy<conf.y&&(_ref=[conf.toy,conf.y],conf.y=_ref[0],conf.toy=_ref[1],_ref);conf.tox>=0&&conf.x>=0&&conf.tox<conf.x&&(_ref2=[conf.tox,conf.x],conf.x=_ref2[0],conf.tox=_ref2[1],_ref2);conf.showShadow=(0,_lib.pluckNumber)(shape.rawConfig.showShadow,group.config.showShadow,DEFAULT_SHOW_SHADOW);conf.toolText=(0,_lib.getFirstValue)(shape.rawConfig.toolText,this.groupConfig.toolText,DEFAULT_TOOLTEXT);conf.isVisible=(0,_utils.pluckBoolean)(shape.rawConfig.isVisible,DEFAULT_IS_VISIBLE);conf.id=(0,_lib.pluck)(shape.rawConfig.id,shape.getId(shape.config.elementType));conf.containerConfiguration={id:shape.getLinkedParent().config.id,label:"group",isParent:true};shape._clickHandler=shape._clickHandler||function(event){shape.config.link&&shape.getFromEnv("linkClickFN").call({link:shape.config.link},true);if(shape.rawConfig.onAnnotationClick instanceof Function){shape.rawConfig.onAnnotationClick()}else if(group.rawConfig.onAnnotationClick instanceof Function){group.rawConfig.onAnnotationClick()}else{chart.fireChartInstanceEvent("annotationclick",(0,_utils.getEventData)(event,shape,chart),UNDEF,UNDEF,event)}};shape._rollOverHandler=shape._rollOverHandler||function(event){if(shape.rawConfig.onAnnotationRollover instanceof Function){shape.rawConfig.onAnnotationRollover()}else if(group.rawConfig.onAnnotationRollover instanceof Function){group.rawConfig.onAnnotationRollover()}else{chart.fireChartInstanceEvent("annotationrollover",(0,_utils.getEventData)(event,shape,chart),UNDEF,UNDEF,event)}};shape._rollOutHandler=shape._rollOutHandler||function(event){if(shape.rawConfig.onAnnotationRollout instanceof Function){shape.rawConfig.onAnnotationRollout()}else if(group.rawConfig.onAnnotationRollout instanceof Function){group.rawConfig.onAnnotationRollout()}else{chart.fireChartInstanceEvent("annotationrollout",(0,_utils.getEventData)(event,shape,chart),UNDEF,UNDEF,event)}};if(shape.rawConfig.customComponent instanceof _componentBase.default){conf.customComponent=conf.rawConfig.customComponent}else{delete conf.customComponent}};_proto._getBorderColor=function _getBorderColor(rawConfig){var shape=this,borderColor=BORDER_COLOR_NONE,colorObj={color:_lib.BLANKSTRING,alpha:_lib.BLANKSTRING};if(shape.getType()!==SHAPE_TYPE_LINE){colorObj.color=shape.config.rawBorderColor=(0,_lib.pluck)(rawConfig.borderColor,rawConfig.fillColor&&rawConfig.fillColor.split(",")[0],rawConfig.color&&rawConfig.color.split(",")[0],DEFAULT_BORDER_COLOR);if(shape.config.showBorder===0){colorObj.alpha=1;shape.config.borderThickness=DEFAULT_BORDER_THICKNESS}else{colorObj.alpha=shape.config.rawBorderAlpha=(0,_lib.pluckNumber)(parseFloat(rawConfig.borderAlpha),parseFloat(rawConfig.alpha),DEFAULT_ALPHA)}borderColor=(0,_lib.toRaphaelColor)(colorObj)}return borderColor};_proto._getFillColor=function _getFillColor(rawConfig,groupConfig){var shape=this,shapeType=shape.config.type,colorObj={color:_lib.BLANKSTRING,alpha:_lib.BLANKSTRING,angle:_lib.BLANKSTRING,ratio:_lib.BLANKSTRING,radialGradient:shapeType==="circle"||shapeType==="arc"};if(shapeType==="line"||shapeType==="image"){colorObj.color=rawConfig.color||groupConfig.color||DEFAULT_COLOR;colorObj.alpha=(0,_lib.pluckNumber)(parseFloat(rawConfig.alpha),groupConfig.alpha,DEFAULT_ALPHA)}else{colorObj.color=rawConfig.fillColor||rawConfig.color||groupConfig.color||DEFAULT_COLOR;colorObj.alpha=(0,_lib.pluck)(rawConfig.fillAlpha,parseFloat(rawConfig.alpha),groupConfig.alpha,DEFAULT_ALPHA);colorObj.angle=FULL_ANGLE_DEGREES-(0,_lib.pluckNumber)(rawConfig.fillAngle,DEFAULT_FILL_ANGLE);colorObj.ratio=(0,_lib.pluck)(rawConfig.fillRatio);if(rawConfig.fillPattern){colorObj.radialGradient=rawConfig.fillPattern.toLowerCase()===RADIAL||(0,_lib.pluckNumber)(rawConfig.fillPattern)}if(colorObj.radialGradient){colorObj.gradientUnits=GRADIENT_UNIT_OBJECT_BBOX;colorObj.cx=.5;colorObj.cy=.5;colorObj.fx=.5;colorObj.fy=.5}}shape.config.rawColor=colorObj.color;shape.config.rawAlpha=colorObj.alpha;shape.config.rawAngle=colorObj.angle;shape.config.rawFillPattern=colorObj.radialGradient?"radial":"linear";shape.config.rawRatio=colorObj.ratio;return(0,_lib.toRaphaelColor)(colorObj)};AnnotationShape.destroySelectionBox=function destroySelectionBox(){selectionGroup&&selectionGroup.remove()};_proto._applyAttr=function _applyAttr(attrs){var shape=this,elementType=shape.config.elementType,attr=Object.assign({},attrs),css;if(elementType==="image"&&!shape.config.url){return}css=shape.rawConfig.css||{};css.cursor=shape.config.link?_lib.POINTER:DEFAULT;if(shape.config.isVisible){attr.visibility=_lib.visibleStr}else{attr.visibility=_lib.hiddenStr}shape.addEventListener("fc-click",shape._clickHandler);shape.addEventListener("fc-mouseover",shape._rollOverHandler);shape.addEventListener("fc-mouseout",shape._rollOutHandler);shape.config.animationLabel=shape.rawConfig.animationLabel||shape.getLinkedParent().config.animationLabel||elementType;shape.addGraphicalElement({el:elementType,attr:attr,css:css,container:shape.config.containerConfiguration,component:shape.config.customComponent||shape,label:shape.config.animationLabel,id:shape.config.id,tooltext:shape.config.toolText,shadow:{opacity:shape.config.showShadow!==0?1:0,useFilter:elementType==="path"?0:1},outlineText:attr.outlineText})};_proto.getScaledVal=function getScaledVal(val,isX){var group=this.getLinkedParent();if(group){return group.getScaledVal(val,isX)}return val};_proto.getScaledFont=function getScaledFont(fontSize){var group=this.getLinkedParent();if(group){return group.getScaledFont(fontSize)}return fontSize};_proto.getScaledImageVal=function getScaledImageVal(val,isX){var group=this.getLinkedParent();if(group){return group.getScaledImageVal(val,isX)}return val};_proto.getScaleInfo=function getScaleInfo(){return this.getLinkedParent().config.scaleInfo};_proto.draw=function draw(){var shape=this;shape.parseAndSetAttribute();shape._applyAttr(shape._getAnnotationAttrs()||{})};return AnnotationShape}(_annotationBase.default);var _default=exports.default=AnnotationShape;