UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 4.82 kB
import{pluckNumber,pluck,pluckFontSize,hiddenStr,visibleStr}from'../../../../fc-core/src/lib';import{pluckBoolean}from'../utils';import AnnotationBaseShape from'./annotation-base';import mergeDeepRight from'ramda/src/mergeDeepRight';import CircleAnnotation from'./annotation-circle';import PathAnnotation from'./annotation-path';import RectAnnotation from'./annotation-rect';import ImageAnnotation from'./annotation-image';import TextAnnotation from'./annotation-text';import PolygonAnnotation from'./annotation-polygon';import ComponentBase from'../../../../fc-core/src/component-interface/component-base';const DEFAULT_IS_VISIBLE=!0,DEFAULT_OPACITY=100,DEFAULT_COLOR='#FF0000',DEFAULT_SHOW_SHADOW=0,DEFAULT_POSITION=0,shapeMap={circle:CircleAnnotation,arc:CircleAnnotation,line:PathAnnotation,path:PathAnnotation,rectangle:RectAnnotation,polygon:PolygonAnnotation,image:ImageAnnotation,text:TextAnnotation};class AnnotationGroup extends AnnotationBaseShape{constructor(a){super(a),this.groups=[],this.items=[]}getName(){return'group'}configureAttributes(a){var b,c=this,d={},e=c.config;c.rawConfig={},d=mergeDeepRight(c.rawConfig,a),c.rawConfig=d,e.id=c.rawConfig.id||c.getId('group'),e.autoScale=pluckNumber(c.rawConfig.autoScale,1),e.scaleText=pluckNumber(c.rawConfig.scaleText,0),e.scaleX=e.origScaleX=pluckNumber(c.rawConfig.xScale)/100,e.scaleY=e.origScaleY=pluckNumber(c.rawConfig.yScale)/100,e.scaleImages=pluckNumber(c.rawConfig.scaleImages,0),e.constrainedScale=pluckNumber(c.rawConfig.constrainedScale,1),e.origH=+c.rawConfig.origH,e.origW=+c.rawConfig.origW,e.link=c.rawConfig.link,e.color=c.rawConfig.color||DEFAULT_COLOR,e.alpha=pluckNumber(parseFloat(c.rawConfig.alpha),DEFAULT_OPACITY),e.showShadow=pluckNumber(c.rawConfig.showShadow,DEFAULT_SHOW_SHADOW),e.x=pluckNumber(c.rawConfig.x,c.rawConfig.xPos,DEFAULT_POSITION),e.y=pluckNumber(c.rawConfig.y,c.rawConfig.yPos,DEFAULT_POSITION),e.font=pluck(c.rawConfig.font,'Verdana, sans'),e.fontSize=pluckFontSize(c.rawConfig.fontSize,10),e.textAlign=pluck(c.rawConfig.textAlign),e.textVAlign=pluck(c.rawConfig.textVAlign),e.rotateText=pluck(c.rawConfig.rotateText),e.wrapText=pluck(c.rawConfig.wrapText),e.grpXShift=pluckNumber(c.rawConfig.grpXShift,0),e.grpYShift=pluckNumber(c.rawConfig.grpYShift,0),e.xShift=pluckNumber(c.rawConfig.xShift,0),e.yShift=pluckNumber(c.rawConfig.yShift,0),e.toolText=c.rawConfig.toolText,e.isVisible=pluckBoolean(c.rawConfig.isVisible,DEFAULT_IS_VISIBLE),e.elementType='group',e.containerConfiguration={id:c.rawConfig.showBelow?'lowerAnnotationGroup':'upperAnnotationGroup',label:'group',isParent:!0},e.animationLabel='group',c.rawConfig.customComponent instanceof ComponentBase?e.customComponent=e.rawConfig.customComponent:delete e.customComponent,c.rawConfig.itemConfigs.forEach(a=>{b=a.type&&a.type.toLowerCase(),shapeMap[b]&&c.attachChild(shapeMap[b],'item',a.id).configure(a)}),c.items=c.getChildren('item')||[]}updateScale(){var a=Math.min;let b,c,d,e,f,g=this,h=g.config,i=h.origScaleX,j=h.origScaleY,k=g.getFromEnv('chart'),l=+k.getFromEnv('chartHeight'),m=+k.getFromEnv('chartWidth'),n=h.autoScale,o=h.constrainedScale;g._setConfig('origW',+h.origW||m),g._setConfig('origH',+h.origH||l),n?(c=m/h.origW*(+i||1),d=l/h.origH*(+j||1)):c=d=1,b=a(c,d),g._setConfig('scaleValue',b),(0<n||isNaN(h.scaleX))&&(e=o?b:c,g._setConfig('scaleX',e)),(0<n||isNaN(h.scaleY))&&(f=o?b:d,g._setConfig('scaleY',f)),h.scaleFont=h.scaleText?a(h.scaleX,h.scaleY):1,h.scaleImageX=h.scaleImages?h.scaleX:1,h.scaleImageY=h.scaleImages?h.scaleY:1,h.scaleInfo={scaleX:h.scaleX,scaleY:h.scaleY,scaleValue:h.scaleValue}}updateAttr(){let a,b,c,d=this,e=d.config,f=e.calculatedAttrs;for(a in f)f[a]&&(e[a]=f[a]);b=d.getScaledVal(e.grpXShift)+e.xShift,c=d.getScaledVal(e.grpYShift)+e.yShift,d._setConfig('attr',{transform:`T${b},${c}`})}retrieveItem(a){let b,c,d=this;for(b=0,c=d.items.length;b<c;b++)if(d.items[b].getId()===a)return d.items[b]}getScaledVal(a,b){let c,d=this;return d?(c=b?d._getConfig('scaleX'):(!1===b?d._getConfig('scaleY'):d._getConfig('scaleValue'))||1,a*c):a}getScaledFont(a){let b=this;return b?a*b._getConfig('scaleFont'):a}getScaledImageVal(a,b){let c,d=this;return d?(c=(b?d._getConfig('scaleImageX'):d._getConfig('scaleImageY'))||1,a*c):a}getScaleInfo(){return this.config.scaleInfo}draw(){var a,b,c=this,d=c._getConfig('attr')||{};c.updateScale(),c.parseAndSetAttribute(),a=c.getScaledVal(c._getConfig('grpXShift'))+c._getConfig('xShift'),b=c.getScaledVal(c._getConfig('grpYShift'))+c._getConfig('yShift'),d.name=c._getConfig('id'),d.transform=d.transform||`T${a},${b}`,d.visibility=c.config.isVisible?visibleStr:hiddenStr,c.addGraphicalElement({el:'group',attr:d,container:c.config.containerConfiguration,component:c.config.customComponent||c,label:c.config.animationLabel,id:c.config.id})}}export default AnnotationGroup;