UNPKG

@fusioncharts/core

Version:

JavaScript Data Visualisation Library

1 lines 3.33 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 _tool=_interopRequireDefault(require("./tool"));var _lib=require("../../lib");var NORMAL="normal",DEFAULT_FONT_SIZE=10,DEFAULT_BORDER_PADDING=2,TEXT_ALIGN_OPTIONS={left:"start",right:"end",center:"middle"},TEXT_V_ALIGN_OPTIONS={top:_lib.POSITION_TOP,middle:_lib.POSITION_MIDDLE,bottom:_lib.POSITION_BOTTOM},TEXT_ROTATION_OPTIONS={0:"0",1:"270",right:"90",cw:"90",left:"270",ccw:"270"},LABEL_FONT="Verdana, sans";var Label=function(_Tool){function Label(){return _Tool.apply(this,arguments)||this}(0,_inheritsLoose2.default)(Label,_Tool);var _proto=Label.prototype;_proto.__setDefaultConfig=function __setDefaultConfig(){_Tool.prototype.__setDefaultConfig.call(this);var toolConfig=this.config;toolConfig.font=LABEL_FONT;toolConfig.rotateText=0};_proto.configureAttributes=function configureAttributes(options){if(options===void 0){options={}}_Tool.prototype.configureAttributes.call(this,options);var toolConfig=this.config;toolConfig.font=(0,_lib.pluck)(options.font,toolConfig.font);toolConfig.fontSize=(0,_lib.pluckFontSize)(options["font-size"],options.fontSize,DEFAULT_FONT_SIZE)*toolConfig.scale;toolConfig.fontStyle=(0,_lib.pluck)(options["font-style"],options.fontStyle,NORMAL);toolConfig.fontWeight=(0,_lib.pluck)(options["font-weight"],options.fontWeight,NORMAL);toolConfig.rotateText=(0,_lib.pluckNumber)(options.rotateText,toolConfig.rotateText);toolConfig.rotateAngle=parseFloat(TEXT_ROTATION_OPTIONS[(0,_lib.pluck)(options.rotateAngle&&options.rotateAngle.toLowerCase(),"0")])};_proto.getTextBound=function getTextBound(){var toolConfig=this.config,bound=[];if(toolConfig.showTextBound){bound=[(0,_lib.convertColor)(toolConfig.fill),toolConfig.borderColor,toolConfig.borderThickness,DEFAULT_BORDER_PADDING,toolConfig.radius]}return bound};_proto.getLogicalSpace=function getLogicalSpace(){var tool=this,dim,_tool$config=tool.config,width=_tool$config.width,height=_tool$config.height,marginTop=_tool$config.marginTop,marginLeft=_tool$config.marginLeft,marginRight=_tool$config.marginRight,marginBottom=_tool$config.marginBottom;dim=tool.getFromEnv("smartLabel").getOriSize(tool.config.text,false);width=dim.width;height=dim.height;return{width:width,height:height,marginTop:marginTop,marginLeft:marginLeft,marginRight:marginRight,marginBottom:marginBottom}};_proto.draw=function draw(){var tool=this,toolConfig=tool.config,attr;if(!toolConfig.text){return}attr={x:toolConfig.x,y:toolConfig.y,text:toolConfig.text,fill:(0,_lib.convertColor)(toolConfig.labelFill),"text-bound":tool.getTextBound(),"font-style":toolConfig.fontStyle,"font-weight":toolConfig.fontWeight,"font-family":toolConfig.font,"font-size":toolConfig.fontSize,"text-anchor":TEXT_ALIGN_OPTIONS[toolConfig.hAlign],"vertical-align":TEXT_V_ALIGN_OPTIONS[toolConfig.vAlign],transform:toolConfig.rotateText?(0,_lib.getSuggestiveRotation)(toolConfig.rotateAngle,toolConfig.x,toolConfig.y):"t0,0"};!toolConfig.isHidden&&tool.addGraphicalElement({el:"text",attr:attr,component:tool,container:{id:"group",label:"group",isParent:true},label:"text",id:"label"})};return Label}(_tool.default);var _default=exports.default=Label;