UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 11.4 kB
import GanttCommonAxis,{extractAttribToEnd}from'./gantt-common';import{pluck,pluckNumber,getDashStyle,extend2,parseUnsafeString,setLineHeight,convertColor,toPrecision,ONESTRING,getValidValue,parseTooltext,preDefStr}from'../lib';const DEFAULT_DASH_STYLE='none',TRANSFORM='t0,0',PXSTRING='px';let UNDEF,DASH_DEF='none',POSITION_START=preDefStr.POSITION_START,POSITION_TOP=preDefStr.POSITION_TOP,POSITION_END=preDefStr.POSITION_END;function prepareTrends(a){var b,c,d,e,f,g,h,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A=a.config,B=A.isVertical,C=A.isOpposit,D=a.getFromEnv('animationManager'),E=A.axisIndex,F=a.getFromEnv('number-formatter'),G=A.axisRange,H=G.max,I=G.min,J=A.trend.trendStyle,K=A.labelPadding,L=A.axisTrendLabelContainer,M={fontFamily:J.fontFamily,fontSize:J.fontSize,lineHeight:J.lineHeight,fontWeight:J.fontWeight,fontStyle:J.fontStyle},N=A.vTrendLines,O=A.trendLines,P=!0,Q=A.drawTrendLabels,R=A.axisDimention||{},S=a.getFromEnv('chartConfig'),T=a.getFromEnv('chart').getChildren('canvas')[0],U=T.config.canvasBottom||S.canvasBottom,V=T.config.canvasLeft||S.canvasLeft,W=T.config.canvasRight||S.canvasRight,X=[],Y=a.getVisibleConfig(),Z=a.getGraphicalElement('trendlabels')||[];for(d=0;d<Z.length;d++)Z[d].remove();if(A.hasBreakPoints&&(Y.minValue=a._getRealBreakValue(Y.minValue),Y.maxValue=a._getRealBreakValue(Y.maxValue)),P=a._isZoomed(),P?(b=Math.max(a.getPixel(Y.minValue,{wrtVisible:!0}),a.getPixel(Y.maxValue,{wrtVisible:!0})),c=Math.min(a.getPixel(Y.minValue,{wrtVisible:!0}),a.getPixel(Y.maxValue,{wrtVisible:!0}))):(Y.minValue=I,Y.maxValue=H),N?x=C?(R.opposite||U)-(A.trendBottomPadding||0):(R.y||U)+(A.trendBottomPadding||0):(x=C?(R.opposite||V)+(K||0):(R.x||V)-(K||0),y=C?(R.x||W)+(K||0):(R.opposite||W)+(K||0)),l=O||N,l)for(f=0,g=l.length;f<g;f+=1)for(d=0,e=l[f].line&&l[f].line.length;d<e;d+=1)(p=l[f].line[d],z=B?'yAxis':'xAxis',s=p.startvalue||p.value||0,s=F.getCleanValue(pluck(p.startvalue,p.value,0)),t=+p.endvalue||UNDEF,h=getValidValue(parseUnsafeString(pluck(l[f].line[d].tooltext,l[0].tooltext,A.trendlineToolText))),h=parseTooltext(h,[7,15,16,17,18,19],{startValue:s,startDataValue:F[z](s,E),endValue:t||s,endDataValue:F[z](t||s,E),axisName:A.axisName},p),!(s>H||s<I||t>H||t<I))&&(N?(q=pluck(parseUnsafeString(p.displayvalue),p.start,''),u=a.getPixel(A.hasBreakPoints?a._getRelativeBreakValue(s):s,{wrtVisible:!0}),m=pluckNumber(p.istrendzone,A.isTrendZone,1),v=t?a.getPixel(A.hasBreakPoints?a._getRelativeBreakValue(t):t,{wrtVisible:!0}):0,t!=UNDEF&&''!==t&&t!=s&&m?(n={fill:convertColor(pluck(p.color,A.trendlineColor),pluck(p.alpha,A.trendlineAlpha,40)),"stroke-width":0},o={fill:convertColor(pluck(p.color,J.color),pluck(p.alpha,A.trendlineAlpha,99)),"vertical-align":POSITION_TOP,text:q,x:u+(v-u)/2,y:x}):(w=pluckNumber(p.thickness,A.trendlineThickness,1),n={stroke:convertColor(pluck(p.color,A.trendlineColor),pluck(p.alpha,A.trendlineAlpha,99)),"stroke-width":w,"stroke-dasharray":pluck(p.dashed,A.trendlinesAreDashed)===ONESTRING?getDashStyle(pluckNumber(p.dashlen,A.trendlinesDashLen),pluckNumber(p.dashgap,A.trendlinesDashGap)):DASH_DEF},o={fill:convertColor(pluck(p.color,J.color),pluck(p.alpha,A.trendlineAlpha,99)),"vertical-align":POSITION_TOP,text:q,x:t?v:u,y:x})):O&&(q=pluck(parseUnsafeString(p.displayvalue),p.start,''),r=pluckNumber(p.valueonright,0),m=pluckNumber(p.istrendzone,A.isTrendZone,0),u=a.getPixel(s,{wrtVisible:!0}),v=t?a.getPixel(t,{wrtVisible:!0}):0,t!=UNDEF&&''!==t&&t!=s&&m?(n={fill:convertColor(pluck(p.color,A.trendlineColor),pluck(p.alpha,A.trendlineAlpha,40)),"stroke-width":0},o={"text-anchor":r?POSITION_START:POSITION_END,fill:convertColor(pluck(p.color,J.color),pluck(p.alpha,A.trendlineAlpha,99)),text:q,x:r?y:x,y:u+(v-u)/2}):(w=pluckNumber(p.thickness,A.trendlineThickness,1),n={stroke:convertColor(pluck(p.color,A.trendlineColor),pluck(p.alpha,A.trendlineAlpha,99)),"stroke-width":w,"stroke-dasharray":pluck(p.dashed,A.trendlinesAreDashed)===ONESTRING?getDashStyle(pluckNumber(p.dashlen,A.trendlinesDashLen),pluckNumber(p.dashgap,A.trendlinesDashGap)):DASH_DEF},o={"text-anchor":r?POSITION_START:POSITION_END,fill:convertColor(pluck(p.color,J.color),pluck(p.alpha,A.trendlineAlpha,99)),text:q,x:r?y:x,y:t?r?v:u:u}),P&&(!Q||o.y>b||o.y<c)&&(o.text='')),o['text-bound']=o.text?[J.backgroundColor,J.borderColor,J.borderThickness,J.borderPadding,J.borderRadius,J.borderDash]:[],k=D.setAnimation({el:'text',attr:o,css:M,container:L,component:a}).show(),A.showTooltip&&h||(h=''),a.addComponentInfo('trend',{marker:{isZone:m,startValue:s,endValue:t,fill:n.fill,stroke:n.stroke,strokeWidth:n['stroke-width'],strokeDashArray:n['stroke-dasharray'],shapeRendering:n['shape-rendering']},label:{fill:o.fill,text:q,textAnchor:o['text-anchor'],textBound:o['text-bound'],valueOnRight:pluckNumber(p.valueonright,0),toolText:h},showOnTop:pluckNumber(p.showontop)}),X.push(k));X.length&&a.addGraphicalElement('trendlabels',X)}class GanttTimeAxis extends GanttCommonAxis{getName(){return'GanttTimeCategory'}configure(a){let b,c=this,d=c.config,e=c.getFromEnv('chart'),f=c.getFromEnv('dataSource'),g=e.getFromEnv('color-manager'),h=f.chart;super.configure(a),b=d.rawAttr,d.plotLineColor=d.lineColor=convertColor(pluck(h.ganttlinecolor,g.getColor('gridColor')),pluckNumber(h.ganttlinealpha,100)),d.plotLineThickness=d.lineThickness=pluckNumber(h.ganttlinethickness,1),d.plotLineDashStyle=d.lineDashStyle=pluckNumber(h.ganttlinedashed,0)?getDashStyle(pluckNumber(h.ganttlinedashlen,1),h.ganttlinedashgap,d.lineThickness):DEFAULT_DASH_STYLE,d.hoverColor=pluck(h.categoryhoverbandcolor,h.hoverbandcolor,g.getColor('gridColor')),d.hoverAlpha=pluckNumber(h.categoryhoverbandalpha,h.hoverbandalpha,30),d.useHover=pluckNumber(h.showcategoryhoverband,h.showhoverband,h.showhovereffect,1),d.usePlotHover=pluckNumber(h.showganttpaneverticalhoverband),d.trendlinesDashLen=pluckNumber(b.trendlinesDashLen,3),d.trendlinesDashGap=pluckNumber(b.trendlinesDashGap,3),d.gridLineHeaderPath='',d.gridLinePath=''}setCategory(a){let b,c,d,e,f,g,h,k=this.getFromEnv('number-formatter'),l=this.config,m=l.startPad||0,n=l.endPad||0,o=1/0,p=-Infinity;if(l.categories={},a)l.hasCategory=1;else return void(l.hasCategory=0);for(g in c=l.categories.category=extend2({},a),extractAttribToEnd(c,{}),c)if(c.hasOwnProperty(g)&&'_attrib'!==g)for(h=0,b=c[g].category.length;h<b;h+=1)d=c[g].category[h],e=k.getDateValue(d.start).ms,f=k.getDateValue(d.end).ms,isNaN(e)&&(e=UNDEF),e>p&&(p=e),e<=o&&(o=e),isNaN(f)&&(f=UNDEF),f>p&&(p=f),f<=o&&(o=f);this.setAxisRange({min:+toPrecision(o-m,10),max:+toPrecision(p+n,10),tickInterval:+toPrecision(1,10)})}placeAxis(a){var b,c,d,e,f,g,h,k,l,m,n,o,p,q,r,s=this,t=s.config,u=s.getFromEnv('chart'),v=u.config,w=s.getFromEnv('number-formatter'),x=s.getFromEnv('smartLabel'),y=t.labels.style,z=0,A={top:0,bottom:0},B=0,C=t.trend.trendStyle,D=t.vTrendLines,E=t.useEllipsesWhenOverflow,F=0,G=0;if(x.useEllipsesOnOverflow(v.useEllipsesWhenOverflow),x.setStyle({fontSize:y.fontSize,fontFamily:y.fontFamily,lineHeight:y.lineHeight,fontWeight:y.fontWeight}),t.maxTopSpaceAvailable=v.canvasTop,t.hasCategory)for(d in b=t.categories.category,b)if(b.hasOwnProperty(d)&&'_attrib'!==d){for(g in z=0,c=b[d].category,c)c.hasOwnProperty(g)&&'_attrib'!==g&&(e=c[g],e.drawLabel=parseUnsafeString(e.label||e.name),h=e._attrib,k={fontFamily:pluck(h.fontfamily,y.fontFamily).replace(/px/i,'')+PXSTRING,fontSize:pluck(h.fontsize,y.fontSize),fontWeight:pluck(1===+h.isbold?'bold':h.isbold===UNDEF?'bold':UNDEF,y.fontWeight),fontStyle:pluck(h.isitalic?'italic':UNDEF,y.fontStyle)},setLineHeight(k),x.setStyle(k),f=x.getOriSize(e.drawLabel),f.height>z&&(n=f,z=f.height));b[d]._attrib.topPos=B,B+=n.height+8,b[d]._attrib.bottomPos=B}if(r=a-B,t.drawTrendLines&&t.drawTrendLabels&&D&&t.isActive)for(x.setStyle({fontSize:C.fontSize,fontFamily:C.fontFamily,lineHeight:C.lineHeight,fontWeight:C.fontWeight}),t.trendBottomPadding=-1,(g=0,l=D.length);g<l;g+=1)for(d=0,m=D[g].line.length;d<m;d+=1)o=D[g].line[d],e=o.origText||o.displayvalue||o.endvalue||o.startvalue||'',e=parseUnsafeString(e),o.startvalue=o.start&&w.getDateValue(o.start).ms,o.endvalue=o.end&&w.getDateValue(o.end).ms,o.origText=e,p=x.getSmartText(e,u.canvasWidth,C.lineHeight,E),q=p.height+2,0>r-q?o.displayvalue='':(o.displayvalue=p.text,F=F<p.height?p.height:F),p.tooltext?o.valueToolText=p.tooltext:delete o.valueToolText;return t.totalHeight=B,0<F&&(G+=F+Math.abs(t.trendBottomPadding||0)),B=B>a?a:B,A.top+=B,A.bottom+=G,v.categorySpaceUsed=B,A}_drawCategories(){var a,b,c,d,e,f,g,h,k,l=this,m=l.config,n=m.axisDimention||{},o=n.y,p=m.totalHeight||0,q=l.getFromEnv('chart'),r=q.config,s=q.getFromEnv('animationManager'),t=q.getFromEnv('number-formatter'),u=m.canvas,v=m.gridArr||(m.gridArr=[]),w=u.canvasLeft||r.canvasLeft,x=u.canvasTop||r.canvasTop,y=u.canvasHeight||r.canvasHeight,z=u.canvasWidth||r.canvasWidth,A=q.getChildContainer('axisBottomGroup'),B=0,C=l.getContainer('ganttPlotHoverBandContainerParent'),D=l.getContainer('ganttPlotHoverBandContainer'),E=l.getContainer('ganttPlotLineContainer'),F=l.getContainer('labelContainer'),G=l.getContainer('labelBackContainer'),H=l.getContainer('labelLineContainer'),I=l.getContainer('labelTextContainer');if(g=Math.min(p,x-(m.maxTopSpaceAvailable||0)),g=0<g?g:0,C||(C=l.addContainer('ganttPlotHoverBandContainerParent',s.setAnimation({el:'group',attr:{name:'gantt-plot-band-container-parent'},container:A,component:l}))),l.addContainer('ganttPlotHoverBandContainer',s.setAnimation({el:D||'group',attr:{name:'gantt-plot-band-container',"clip-rect":w+','+x+','+z+','+y},container:C,component:l})),l.addContainer('ganttPlotLineContainer',s.setAnimation({el:E||'group',attr:{name:'gantt-plot-line-container',"clip-rect":w+','+x+','+z+','+y,transform:TRANSFORM},container:A,component:l})),F=l.addContainer('labelContainer',s.setAnimation({el:F||'group',attr:{name:'gantt-label-container',"clip-rect":w+','+(x-g)+','+z+','+g,transform:TRANSFORM},container:A,component:l})),G||(G=l.addContainer('labelBackContainer',s.setAnimation({el:'group',attr:{name:'gantt-label-back-container'},container:F,component:l}))),H||(H=l.addContainer('labelLineContainer',s.setAnimation({el:'group',attr:{name:'gantt-label-line-container'},component:l,container:F}))),I||(I=l.addContainer('labelTextContainer',s.setAnimation({el:'group',attr:{name:'gantt-label-text-container'},container:F,component:l}))),m.gridLinePath='',m.gridLineHeaderPath='',m.hoverElemsArr=[],m.labelHoverEventName={click:'CategoryClick',rollOver:'CategoryRollOver',rollOut:'CategoryRollOut'},m.hasCategory)for(a in b=m.categories.category,b)if(b.hasOwnProperty(a)&&'_attrib'!==a)for(d in c=b[a].category,f=UNDEF,v=m.gridArr=[],c)(h=t.getDateValue(c[d].start).ms,k=t.getDateValue(c[d].end).ms,!(!c.hasOwnProperty(d)||'_attrib'===d||isNaN(h)||isNaN(k)))&&(e={elem:c[d],elemIndex:B,pos:B,dimension:{left:f||l.getPixel(h),right:l.getPixel(k),top:o-p+b[a]._attrib.topPos,bottom:o-p+b[a]._attrib.bottomPos},type:'category',isHeader:!1},f=e.dimension.right,l._drawProcessAndDataTableElement(e),B+=1,v.push({x:e.dimension.left}));l._drawGridLine(),l._disposeExtraProcessAndDataTableElement(B)}_drawComponents(){let a=this.config,b=this.getFromEnv('chartConfig');this._drawCategories(),b.scrolltodate&&this.translateAxis(-(b.viewPortConfig.x*b.viewPortConfig.scaleX),0),a.drawPlotlines&&this._drawPlotLine(),prepareTrends(this),a.drawTrendLines&&this._drawTrendLine()}}export default GanttTimeAxis;