UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 6.91 kB
import mergeDeepRight from'ramda/src/mergeDeepRight';import AnnotationBaseShape from'./annotation-base';import{toRaphaelColor,getDashStyle,pluckNumber,pluck,getFirstValue,POINTER,visibleStr,hiddenStr}from'../../../../fc-core/src/lib';import{pluckBoolean,getEventData}from'../utils';import ComponentBase from'../../../../fc-core/src/component-interface/component-base';let selectionGroup,UNDEF,DEFAULT='default';const 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=!0,isDefined=a=>a===UNDEF?UNDEF:1;class AnnotationShape extends AnnotationBaseShape{configureAttributes(a){let b=this,c={},d=b.config,e=b.getFromEnv('chart'),f=b.getLinkedParent();b.groupConfig={},b.rawConfig={},null!==f&&(b.groupConfig.x=f._getConfig('x'),b.groupConfig.y=f._getConfig('y'),b.groupConfig.grpXShift=f._getConfig('grpXShift'),b.groupConfig.grpYShift=f._getConfig('grpYShift'),b.groupConfig.color=f._getConfig('color'),b.groupConfig.alpha=f._getConfig('alpha'),b.groupConfig.font=f._getConfig('font'),b.groupConfig.fontSize=f._getConfig('fontSize'),b.groupConfig.textAlign=f._getConfig('textAlign'),b.groupConfig.textVAlign=f._getConfig('textVAlign'),b.groupConfig.rotateText=f._getConfig('rotateText'),b.groupConfig.wrapText=f._getConfig('wrapText'),b.groupConfig.toolText=f._getConfig('toolText'),b.groupConfig.scaleX=f._getConfig('scaleX'),b.groupConfig.scaleY=f._getConfig('scaleY'),b.groupConfig.scaleImageX=f._getConfig('scaleImageX'),b.groupConfig.scaleImageY=f._getConfig('scaleImageY'),b.groupConfig.link=f._getConfig('link')),c=mergeDeepRight(b.rawConfig,a),b.rawConfig=c,d.type=b.rawConfig.type,d.color=b._getFillColor(b.rawConfig,this.groupConfig),d.link=pluck(b.rawConfig.link,b.groupConfig.link),d.borderThickness=pluckNumber(parseFloat(b.rawConfig.borderThickness),parseFloat(b.rawConfig.thickness),DEFAULT_BORDER_THICKNESS),d.showBorder=pluckNumber(b.rawConfig.showBorder,parseFloat(b.rawConfig.borderThickness),parseFloat(b.rawConfig.thickness),isDefined(b.rawConfig.borderColor),isDefined(b.rawConfig.borderAlpha),DEFAULT_SHOW_BORDER),d.borderColor=b._getBorderColor(b.rawConfig),d.dashed=pluckNumber(b.rawConfig.dashed,DEFAULT_IS_DASHED),d.dashLen=pluckNumber(b.rawConfig.dashLen,DEFAULT_DASH_LEN),d.dashGap=pluckNumber(parseFloat(b.rawConfig.dashGap),DEFAULT_DASH_GAP),d.dashArrayStr=d.dashed?getDashStyle(d.dashLen,d.dashGap):'none',d.x=pluckNumber(b.rawConfig.x,b.rawConfig.xPos,0),d.y=pluckNumber(b.rawConfig.y,b.rawConfig.yPos,0),d.tox=pluckNumber(b.rawConfig.toX,d.x,0),d.toy=pluckNumber(b.rawConfig.toY,d.y,0),0<=d.toy&&0<=d.y&&d.toy<d.y&&([d.y,d.toy]=[d.toy,d.y]),0<=d.tox&&0<=d.x&&d.tox<d.x&&([d.x,d.tox]=[d.tox,d.x]),d.showShadow=pluckNumber(b.rawConfig.showShadow,f.config.showShadow,DEFAULT_SHOW_SHADOW),d.toolText=getFirstValue(b.rawConfig.toolText,this.groupConfig.toolText,DEFAULT_TOOLTEXT),d.isVisible=pluckBoolean(b.rawConfig.isVisible,DEFAULT_IS_VISIBLE),d.id=pluck(b.rawConfig.id,b.getId(b.config.elementType)),d.containerConfiguration={id:b.getLinkedParent().config.id,label:'group',isParent:!0},b._clickHandler=b._clickHandler||function(a){b.config.link&&b.getFromEnv('linkClickFN').call({link:b.config.link},!0),b.rawConfig.onAnnotationClick instanceof Function?b.rawConfig.onAnnotationClick():f.rawConfig.onAnnotationClick instanceof Function?f.rawConfig.onAnnotationClick():e.fireChartInstanceEvent('annotationclick',getEventData(a,b,e),UNDEF,UNDEF,a)},b._rollOverHandler=b._rollOverHandler||function(a){b.rawConfig.onAnnotationRollover instanceof Function?b.rawConfig.onAnnotationRollover():f.rawConfig.onAnnotationRollover instanceof Function?f.rawConfig.onAnnotationRollover():e.fireChartInstanceEvent('annotationrollover',getEventData(a,b,e),UNDEF,UNDEF,a)},b._rollOutHandler=b._rollOutHandler||function(a){b.rawConfig.onAnnotationRollout instanceof Function?b.rawConfig.onAnnotationRollout():f.rawConfig.onAnnotationRollout instanceof Function?f.rawConfig.onAnnotationRollout():e.fireChartInstanceEvent('annotationrollout',getEventData(a,b,e),UNDEF,UNDEF,a)},b.rawConfig.customComponent instanceof ComponentBase?d.customComponent=d.rawConfig.customComponent:delete d.customComponent}_getBorderColor(a){let b=this,c=b.config.type,d='none',e={color:'',alpha:''};return'line'!==c&&(e.color=b.config.rawBorderColor=pluck(a.borderColor,a.fillColor&&a.fillColor.split(',')[0],a.color&&a.color.split(',')[0],DEFAULT_BORDER_COLOR),0===b.config.showBorder?(e.alpha=1,b.config.borderThickness=DEFAULT_BORDER_THICKNESS):e.alpha=b.config.rawBorderAlpha=pluckNumber(parseFloat(a.borderAlpha),parseFloat(a.alpha),DEFAULT_ALPHA),d=toRaphaelColor(e)),d}_getFillColor(a,b){let c=this,d=c.config.type,e={color:'',alpha:'',angle:'',ratio:'',radialGradient:'circle'===d||'arc'===d};return'line'===d||'image'===d?(e.color=a.color||b.color||DEFAULT_COLOR,e.alpha=pluckNumber(parseFloat(a.alpha),b.alpha,DEFAULT_ALPHA)):(e.color=a.fillColor||a.color||b.color||DEFAULT_COLOR,e.alpha=pluck(a.fillAlpha,parseFloat(a.alpha),b.alpha,DEFAULT_ALPHA),e.angle=FULL_ANGLE_DEGREES-pluckNumber(a.fillAngle,DEFAULT_FILL_ANGLE),e.ratio=pluck(a.fillRatio),a.fillPattern&&(e.radialGradient=a.fillPattern.toLowerCase()===RADIAL||pluckNumber(a.fillPattern)),e.radialGradient&&(e.gradientUnits='objectBoundingBox',e.cx=.5,e.cy=.5,e.fx=.5,e.fy=.5)),c.config.rawColor=e.color,c.config.rawAlpha=e.alpha,c.config.rawAngle=e.angle,c.config.rawFillPattern=e.radialGradient?'radial':'linear',c.config.rawRatio=e.ratio,toRaphaelColor(e)}static destroySelectionBox(){selectionGroup&&selectionGroup.remove()}_applyAttr(a){var b,c=this,d=c.getLinkedParent(),e=c.rawConfig.animationLabel,f=d.config.animationLabel,g=c.config.elementType,h=c.config.link,i=Object.assign({},a);('image'!==g||c.config.url)&&(b=c.rawConfig.css||{},b.cursor=h?POINTER:DEFAULT,i.visibility=c.config.isVisible?visibleStr:hiddenStr,c.addEventListener('fc-click',c._clickHandler),c.addEventListener('fc-mouseover',c._rollOverHandler),c.addEventListener('fc-mouseout',c._rollOutHandler),c.config.animationLabel=e||f||g,c.addGraphicalElement({el:g,attr:i,css:b,container:c.config.containerConfiguration,component:c.config.customComponent||c,label:c.config.animationLabel,id:c.config.id,tooltext:c.config.toolText,shadow:{opacity:0===c.config.showShadow?0:1,useFilter:'path'===g?0:1}}))}getScaledVal(a,b){let c=this.getLinkedParent();return c?c.getScaledVal(a,b):a}getScaledFont(a){let b=this.getLinkedParent();return b?b.getScaledFont(a):a}getScaledImageVal(a,b){let c=this.getLinkedParent();return c?c.getScaledImageVal(a,b):a}getScaleInfo(){return this.getLinkedParent().config.scaleInfo}draw(){var a,b=this;b.parseAndSetAttribute(),a=b._getAnnotationAttrs()||{},b._applyAttr(a)}}export default AnnotationShape;