quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 2.81 kB
JavaScript
import{SmartRenderer}from'../../../../../fc-core/src/component-interface';import{UNDEF}from'../../../../../fc-core/src/lib';const LEFT='left',RIGHT='right',MIDDLE='middle',START='start',END='end',TOP='top',DEFAULT_CAPTION_PADDING=10,CAPTION_SUBCAPTION_GAP_RATIO=.02,CAPTION_HEIGHT_RATIO=.7,SUBCAPTION_HEIGHT_RATIO=.3,FONTSTYLE='font-style',FONTSIZE='font-size',FONTWEIGHT='font-weight',TEXT_ANCHOR='text-anchor',VERTICAL_ALIGN='vertical-align',FILL='fill',DEFAULT_CAPTION_CSS={"font-size":'16px',"font-style":'normal',"font-weight":'bold',fill:'#5F5F5F'},DEFAULT_SUBCAPTION_CSS={"font-size":'12px',"font-style":'normal',"font-weight":'normal',fill:'#B1B1B1'};class Caption extends SmartRenderer{__setDefaultConfig(){super.__setDefaultConfig();let a=this,b=a.config;b.captionCss=DEFAULT_CAPTION_CSS,b.subCaptionCss=DEFAULT_SUBCAPTION_CSS,b.alignment=LEFT,b.gap=0}configureAttributes(a={}){super.configureAttributes(a);let b=this,c=b.config,d=b.getFromEnv('baseTextStyle');Object.keys(a).forEach(b=>c[b]=a[b]),c.captionCss=Object.assign({},DEFAULT_CAPTION_CSS,d,c.captionCss||{}),c.subCaptionCss=Object.assign({},DEFAULT_SUBCAPTION_CSS,d,c.subCaptionCss||{})}setDimension(a){let b,c,d,e,f=this,g=f.config,h=f.getFromEnv('smartLabel'),i=a.height-DEFAULT_CAPTION_PADDING,j=a.width,k=0,l=0;return g.subCaption?(e=g.gap=i*CAPTION_SUBCAPTION_GAP_RATIO,b=i-e,k=b*CAPTION_HEIGHT_RATIO,l=g.caption?b*SUBCAPTION_HEIGHT_RATIO:i):b=k=i,h.useEllipsesOnOverflow(!0),h.setStyle(g.captionCss),c=g.captionDim=h.getSmartText(g.caption,j,k),h.setStyle(g.subCaptionCss),d=g.subCaptionDim=h.getSmartText(g.subCaption,j,l),i=c.height+(g.subCaption?e:0)+d.height,i+=0===i?0:DEFAULT_CAPTION_PADDING,g.spaceTaken={width:j,height:i},{height:i,width:j}}draw(){let a,b,c=this,d=c.config,e=c.getFromEnv('chart').config,f=d.captionDim,g=d.subCaptionDim,h=d.spaceTaken,i={text:f.text},j={text:g.text};switch(d.alignment){case RIGHT:a=h.width,b=END;break;case MIDDLE:a=h.width/2,b=MIDDLE;break;case LEFT:default:a=0,b=START;}i.x=j.x=a,i[TEXT_ANCHOR]=j[TEXT_ANCHOR]=b,i[VERTICAL_ALIGN]=j[VERTICAL_ALIGN]=TOP,i.y=0,j.y=d.gap+f.height,c.addGraphicalElement({el:'group',container:{id:'strato',label:'group',isParent:!0},component:c,label:'group',attr:{name:'caption-strato',transform:d.translate},id:'strato'}),d.caption&&c.addGraphicalElement({el:'text',attr:{x:i.x,y:i.y,text:i.text,opacity:d.captionCss.opacity},css:d.captionCss,container:{id:'strato',label:'group',isParent:!1},tooltext:e.showTooltip?f.tooltext:UNDEF,component:c,id:'caption',label:'text'}),d.subCaption&&c.addGraphicalElement({el:'text',attr:{x:j.x,y:j.y,text:j.text,opacity:d.subCaptionCss.opacity},css:d.subCaptionCss,container:{id:'strato',label:'group',isParent:!1},tooltext:e.showTooltip?g.tooltext:UNDEF,component:c,id:'subCaption',label:'text'})}}export default Caption;