quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 2.44 kB
JavaScript
import Tool from'../tool';import{getDep}from'../../../dependency-manager';import{TRACKER_FILL,polyPathToPath}from'../../../lib';import{priorityList}from'../../../schedular';let R=getDep('redraphael','plugin'),START='start';class ScrollButton extends Tool{constructor(){super(),this._evtHandlers={}}configureAttributes(a={}){let b=this.config;b.type=a.type,b.style={button:Object.assign({},{fill:TRACKER_FILL,stroke:'none'},a.style.button),arrow:Object.assign({},{fill:R.tintshade(a.color,-.4).rgba,stroke:'none'},a.style.arrow)}}attachEventHandlers(){let a,b,c=this,d=c.config,e=c.getLinkedParent(),f=e.config,g=e.getChildren('scrollAnchor')[0],h=function(){1<=f.scrollPosition?f.scrollPosition=1:(0>=f.scrollPosition||isNaN(f.scrollPosition))&&(f.scrollPosition=0),g.asyncDraw(),'function'==typeof f.evt.scroll&&f.evt.scroll(f.scrollPosition)},i=function(){b=!0,d.type===START?f.scrollPosition-=.01:f.scrollPosition+=.01,h(),c.addJob('dragScrollAnchor',i,priorityList.draw)};c.addEventListener('fc-mousedown',c._evtHandlers.mousedown||(c._evtHandlers.mousedown=function(){a=setTimeout(function(){c.addJob('dragScrollAnchor',i,priorityList.draw)},300)})),c.addEventListener('fc-mouseup',c._evtHandlers.mouseup||(c._evtHandlers.mouseup=function(){clearTimeout(a),c.removeJob('dragScrollAnchor'),b||(d.type===START?f.scrollPosition-=.1:f.scrollPosition+=.1,h()),b=!1})),c.addEventListener('fc-mouseout',function(){b&&c._evtHandlers.mouseup()})}draw(){var a=Math.min;let b=this,c=b.config,d=this.getLinkedParent(),e=d.config,f={id:'scrollbarGroup',label:'scrollbarGroup',isParent:!0},g=e.isHorizontal,h=e.x+.5,i=e.y+e.padding+.5,j=e.width-1,k=1>e.height-1?1:e.height-1,l=g?a(k,.5*j):a(j,.5*k),m=g?polyPathToPath([3,h+.5*l,i+.5*k,.25*l,180]):polyPathToPath([3,h+.5*j,i+.5*l,.25*l,90]),n=g?polyPathToPath([3,h+j-.5*l,i+.5*l,.25*l,0]):polyPathToPath([3,h+.5*j,i+k-.5*l,.25*l,-90]);b.addGraphicalElement({el:'rect',attr:{x:'start'===c.type?h:g?h+j-l:h,y:'start'===c.type?i:g?i:i+k-l,width:'start'===c.type?g?l:j:g?l:j,height:'start'===c.type?g?k:l:g?k:l,opacity:c.style.button.opacity},css:c.style.button,container:f,component:b,label:'scrollbar'+c.type+'ButtonRect',id:'scrollbar'+c.type+'ButtonRect'}),b.addGraphicalElement({el:'path',attr:{path:'start'===c.type?m:n,opacity:c.style.arrow.opacity},css:c.style.arrow,container:f,component:b,label:'scrollbar'+c.type+'ButtonPath',id:'scrollbar'+c.type+'ButtonPath'})}}export default ScrollButton;