UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 3.74 kB
import{getMouseCoordinate,pluckNumber,pluck,hasSVG}from'../../../fc-core/src/lib';import{ComponentInterface}from'../../../fc-core/src/component-interface';let UNDEF,DEFAULTCOLOR='#EEEEEE',DEFAULTALPHA=50,crispFixer=hasSVG?0:.5,crisping=(a,b)=>Math.round(a+(b%2/2+crispFixer))-(b%2/2+crispFixer),handlers=function(a){return{onhover:(b,c)=>{a.config.axisScrolling||a.show(c.axes?{axesInfo:c.axes}:{event:b})},onhoverout:b=>{a.hide({event:b})}}},createRaphaelGroup=function(a,b,c){var d=c.getFromEnv('animationManager');return d.setAnimation({el:'group',attr:{name:a},container:b,state:'appearing',component:c,label:'group'})};class CrossLineManagerBand extends ComponentInterface{constructor(){super(),this._handlerAPI=handlers(this),this.mouseOutTimer=void 0}getAttachedAxisInfo(a={}){let b,c,d,e,f,g=this,h=g.getLinkedParent(),j=h.getAxes(),k=a.originalEvent&&getMouseCoordinate(g.getFromEnv('chart-container'),a.originalEvent,g.getFromEnv('chart')),l=k&&k.chartX||0,m=k&&k.chartY||0;for(b=j.length-1;0<=b;b--)if(c=j[b].axis,d=j[b].isY,!d)return e=!!c.config.isVertical,f=c.getTranslation(),{value:e?c.getValue(m+f):c.getValue(l+f),axis:c,isVertical:e,isY:!1}}configure(){let a=this,b=a.config,c=a.getFromEnv('chartConfig'),d=a.getFromEnv('chart-attrib'),e=pluck(d.crosslinecolor,c.crosslinecolor,DEFAULTCOLOR),f=pluckNumber(c.defaultcrosslinethickness),g=pluckNumber(d.crosslineanimation,0),h=g&&1e3*pluckNumber(d.crosslineanimationduration,.09),i=pluckNumber(d.drawcrosslineontop,c.drawcrosslineontop,0),j=pluckNumber(d.crosslinealpha,c.crosslinealpha,DEFAULTALPHA);b.drawCrossLine=pluckNumber(d.drawcrossline,c.drawcrossline,0),b.bandStyle={fillcolor:e,alpha:j,thickness:f,managerId:a.getId(),onTop:i,cursor:'pointer',animDuration:h}}createGroup(){let a=this,b=a.getLinkedParent().getChildContainer('crosslineBottom'),c=a.getLinkedParent().getChildContainer('crosslineTop');a.getChildContainer('crosslineTop')||a.addChildContainer('crosslineTop',createRaphaelGroup('crosslineTop',c,a)),a.getChildContainer('crosslineBottom')||a.addChildContainer('crosslineBottom',createRaphaelGroup('crosslineBottom',b,a))}show(a={}){let b=this,c=a.event,d=b.config;clearTimeout(this.mouseOutTimer),d.attachedCanvasAxisInfo=b.getAttachedAxisInfo(c),b._setAptAxesInfo(a.axesInfo,a.value),b._show(c)}_setAptAxesInfo(a=[],b){let c,d,e=this,f=a.length,g=e.config.attachedCanvasAxisInfo;if(a.length)for(d=0;d<f;d++)if(c=a[d],c.axis===g.axis){g.value=c.value;break}b!==UNDEF&&(g.value=b)}_show(a){let b,c,d,e,f=this,g=f.config,h=f.getFromEnv('chartConfig'),i=f.getChildren('crossline')[0],j=g.attachedCanvasAxisInfo,k=j.value,l=j.axis,m=j.isVertical,n=l.config.endPad,o=l.getLimit().max-n,p=Math.round(k),q=j.axis.getPixel(p)-j.axis.getTranslation(),r=Object.assign({},g.bandStyle),s=f.getFromEnv('canvasConfig'),t=s.canvasTop,u=s.canvasLeft,v=s.canvasWidth,w=s.canvasHeight,x=g.drawCrossLine;0>p||p>o||f.config.lastIndex!==p&&x&&((d=r.thickness)===UNDEF&&(!1===h._hascolumn?d=1:(b=l.getPixel(0),c=l.getPixel(1),d=Math.abs(c-b))),e=crisping(q,d),f.createGroup(),r.thickness=d,r=m?Object.assign(r,{x1:u,y1:e,x2:u+v,y2:e}):Object.assign(r,{x1:e,y1:t,x2:e,y2:t+w}),i.show(r),f.getFromEnv('chart').fireChartInstanceEvent('onChangeCrossLine',{currentIndex:p,lastIndex:f.config.lastIndex,source:a?'mouse interaction':'public API'}),f.config.lastIndex=p)}hide(a={}){let b=this,c=a.event;this.mouseOutTimer=setTimeout(()=>{b.getFromEnv('chart').fireChartInstanceEvent('onChangeCrossLine',{lastIndex:b.config.lastIndex,source:c?'mouse interaction':'public API'}),delete this.config.lastIndex,this.getChildren('crossline')[0].hide()},20)}getType(){return'crossline-manager'}getName(){return'crossline-manager-band-category-axis'}}export default CrossLineManagerBand;