@fusioncharts/features
Version:
FusionCharts JavaScript charting framework
1 lines • 6.94 kB
JavaScript
;var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports.default=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _annotationShape=_interopRequireDefault(require("./annotation-shape"));var _lib=require("@fusioncharts/core/src/lib");var POSITION_BOTTOM="bottom",POSITION_TOP="top",POSITION_MIDDLE="middle",BOLD="bold",DEFAULT_RADIUS=0,DEFAULT_BORDER_PADDING=2,DEFAULT_BORDER_THICKNESS=1,DEFAULT_COLOR="#FF0000",DEFAULT_ALPHA=100,FULL_ANGLE_DEGREES=360,RADIAL="radial",DEFAULT_FILL_ANGLE=0,DEFAULT_FONT_SIZE=10,ITALIC="italic",NORMAL="normal",TEXT_ALIGN_OPTIONS={left:"start",right:"end",center:"middle"},TEXT_V_ALIGN_OPTIONS={top:POSITION_BOTTOM,middle:POSITION_MIDDLE,bottom:POSITION_TOP},TEXT_ROTATION_OPTIONS={0:"0",1:"270",right:"90",cw:"90",left:"270",ccw:"270"},GRADIENT_UNIT_OBJECT_BBOX="objectBoundingBox",ELEMENT_TYPE_TEXT="text",applyTextBound=function applyTextBound(color,alpha){if(!color||color==="none"){return false}else if(alpha===0){return false}return true};function isValidColor(colorStr){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(colorStr)?colorStr:/(^[0-9A-F]{6}$)|(^[0-9A-F]{3}$)/i.test(colorStr)&&"#"+colorStr}var AnnotaionText=function(_AnnotationShape){function AnnotaionText(){return _AnnotationShape.apply(this,arguments)||this}(0,_inheritsLoose2.default)(AnnotaionText,_AnnotationShape);var _proto=AnnotaionText.prototype;_proto.getName=function getName(){return ELEMENT_TYPE_TEXT};_proto.configureAttributes=function configureAttributes(rawConfig){if(rawConfig===void 0){rawConfig={}}_AnnotationShape.prototype.configureAttributes.call(this,rawConfig);var text=this,shapeConfig=text.rawConfig,groupConfig=text.groupConfig;text.config.text=(0,_lib.parseUnsafeString)((0,_lib.pluck)(shapeConfig.text,shapeConfig.label,""));text.config.font=(0,_lib.pluck)(shapeConfig.font,groupConfig.font,"Verdana, sans");text.config.fontSize=(0,_lib.pluckFontSize)(shapeConfig.fontSize,groupConfig.fontSize,DEFAULT_FONT_SIZE);text.config.align=(0,_lib.pluck)(TEXT_ALIGN_OPTIONS[shapeConfig.align&&shapeConfig.align.toLowerCase()],TEXT_ALIGN_OPTIONS[groupConfig.textAlign&&groupConfig.textAlign.toLowerCase()],"middle");text.config.vAlign=(0,_lib.pluck)(TEXT_V_ALIGN_OPTIONS[shapeConfig.vAlign&&shapeConfig.vAlign.toLowerCase()],TEXT_V_ALIGN_OPTIONS[groupConfig.textVAlign&&groupConfig.textVAlign.toLowerCase()],"middle");text.config.radius=(0,_lib.pluckNumber)(parseFloat(shapeConfig.radius),DEFAULT_RADIUS);text.config.fontWeight=(0,_lib.pluckNumber)(shapeConfig.bold,0)?BOLD:NORMAL;text.config.outlineText=(0,_lib.pluckNumber)(rawConfig.outlineText,0);text.config.fontStyle=(0,_lib.pluckNumber)(shapeConfig.italic,0)?ITALIC:NORMAL;text.config.bgColor=isValidColor(shapeConfig.bgColor)?shapeConfig.bgColor:"none";text.config.borderThickness=(0,_lib.pluckNumber)(parseFloat(text.rawConfig.borderThickness),parseFloat(text.rawConfig.thickness),DEFAULT_BORDER_THICKNESS);text.config.rotateText=(0,_lib.pluck)(shapeConfig.rotateText,groupConfig.rotateText,"0");text.config.rotateAngle=TEXT_ROTATION_OPTIONS[text.config.rotateText&&text.config.rotateText.toLowerCase()];text.config.wrap=(0,_lib.pluckNumber)(shapeConfig.wrap,groupConfig.wrapText,shapeConfig.wrapHeight,shapeConfig.wrapWidth,1);if(text.config.wrap){text.config.wrapWidth=(0,_lib.pluckNumber)(shapeConfig.wrapWidth);text.config.wrapHeight=(0,_lib.pluckNumber)(shapeConfig.wrapHeight)}text.config.leftMargin=(0,_lib.pluckNumber)(shapeConfig.leftMargin,0);text.config.elementType=ELEMENT_TYPE_TEXT};_proto.getText=function getText(){var shape=this,conf=shape.config,smartLabel=shape.getFromEnv("smartLabel"),textStr,group=shape.getLinkedParent(),isScaleText=group&&group._getConfig("scaleText"),wrapWidth=isScaleText?shape.getScaledVal(conf.wrapWidth,true):conf.wrapWidth,wrapHeight=isScaleText?shape.getScaledVal(conf.wrapHeight,false):conf.wrapHeight,css={fontStyle:conf.fontStyle,fontFamily:conf.font,fontWeight:conf.fontWeight,fontSize:conf.fontSize+"px","text-anchor":conf.align,"vertical-align":conf.vAlign};(0,_lib.setLineHeight)(css);smartLabel&&smartLabel.setStyle(css);textStr=smartLabel&&conf.wrap?smartLabel.getSmartText(conf.text,wrapWidth,wrapHeight,0).text:conf.text;return textStr};_proto._getFillColor=function _getFillColor(rawConfig,groupConfig){var shape=this,shapeType=shape.config.type,colorObj={color:"",alpha:"",angle:"",ratio:"",radialGradient:shapeType==="circle"||shapeType==="arc"};colorObj.color=rawConfig.fontColor||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===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)};_proto.updateAttr=function updateAttr(){var text=this,config=text.config,attr=config.calculatedAttrs,x=(0,_lib.pluckNumber)(attr.x,text.getScaledVal(config.x,true)),y=(0,_lib.pluckNumber)(attr.y,text.getScaledVal(config.y,true)),transform;if(config.rotateText!=="0"){transform=(0,_lib.getSuggestiveRotation)(parseFloat(config.rotateAngle),x,y)}text._setConfig("attr",{x:x,y:y,transform:transform})};_proto._getAnnotationAttrs=function _getAnnotationAttrs(){var text=this,config=text.config,attr=text._getConfig("attr")||{},x=text.getScaledVal(config.x,true),y=text.getScaledVal(config.y,false);attr.x=(typeof attr.x==="undefined"?x:attr.x)+config.leftMargin/2;attr.y=typeof attr.y==="undefined"?y:attr.y;attr.text=text.getText();attr.fill=config.color;attr.outlineText=config.outlineText;if(attr.text&&(applyTextBound(text.rawConfig.borderColor,text.rawConfig.borderAlpha)||text.rawConfig.bgColor)){attr["text-bound"]=[(0,_lib.toRaphaelColor)(config.bgColor),config.borderColor,config.borderThickness,DEFAULT_BORDER_PADDING,config.radius,config.dashArrayStr]}else{attr["text-bound"]=[]}attr["font-style"]=config.fontStyle;attr["font-weight"]=config.fontWeight;attr["font-family"]=config.font;attr["font-size"]=text.getScaledFont(config.fontSize);attr["text-anchor"]=config.align;attr["vertical-align"]=config.vAlign;if(config.rotateText!=="0"){attr.transform=attr.transform||(0,_lib.getSuggestiveRotation)(parseFloat(config.rotateAngle),x,y)}return attr};return AnnotaionText}(_annotationShape.default);var _default=exports.default=AnnotaionText;