UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 9.15 kB
import CustomRangeManager from'./manager';import{Tool}from'../../../../../fc-core/src/toolbox';import{TRACKER_FILL,getMouseCoordinate}from'../../../../../fc-core/src/lib';import Cover from'./cover';import FusionEventWrapper from'../../../vendors/fc-calendar/src/events/fusion-event-wrapper';const TIME_INTERVALS=['hour','minute','second','millisecond'],VISIBLE='visible',NORMAL='normal',CRS='CRS',SPACE_BETWEEN_ICON_AND_TEXT=5,SCALING_STEP_VALUE=.0278,getScalingParam=a=>(a=parseFloat(a),(a-12)*SCALING_STEP_VALUE+1);class CustomRangeSelectorTool extends Tool{constructor(a){super(a);let b=this,c=b.config;c.wrapper=new FusionEventWrapper,b.addToEnv('eventWrapper',c.wrapper),c.documentClicked=a=>{let{chartX:d,chartY:e}=getMouseCoordinate(b.getFromEnv('chart-container'),a,b.getFromEnv('chart')),f=a.target;b.getChildren('manager')[0].isWithinWidget(d,e)||'fc__select__time'===f.className||f.parentElement&&'fc__select__time'===f.parentElement.className||(c.wrapper.off(document,'fc-click',c.documentClicked),b.setData({},!0))},b.keyDownHandler=a=>{let b=!1;b='key'in a?'Escape'===a.key||'Esc'===a.key:27===a.keyCode,b&&this.setData({},!0)},b.clickHandler=function(a){a.stopPropagation();let d=b,e=c.domain,f=d.getFromEnv('chart'),g=f.getFromEnv('UTC'),h=f.getFromEnv('dateAPI'),i=f.getContextLimit(),j=new Date(i[0]),k=new Date(i[1]),l=new Date(e[0]),m=new Date(e[1]);d.setData({blockUpdate:!0,interactionStyle:c.extStyle['title:active']},!0),d.getChildren('cover')[0].setData({visibility:'visible'},!0),d.getChildren('manager')[0].setData({visibility:'visible',position:d.config.containerPos,drawCalendars:!0,startDate:{year:h(l,'FullYear',g),month:h(l,'Month',g)+1,day:h(l,'Date',g),hours:h(l,'Hours',g),minutes:h(l,'Minutes',g),seconds:h(l,'Seconds',g)},endDate:{year:h(m,'FullYear',g),month:h(m,'Month',g)+1,day:h(m,'Date',g),hours:h(m,'Hours',g),minutes:h(m,'Minutes',g),seconds:h(m,'Seconds',g)},contextStart:{year:h(j,'FullYear',g),month:h(j,'Month',g)+1,day:h(j,'Date',g)},contextEnd:{year:h(k,'FullYear',g),month:h(k,'Month',g)+1,day:h(k,'Date',g)}},!0),c.wrapper.on(document,'fc-click',b.config.documentClicked)},this.addEventListener('fc-click',b.clickHandler),this.addEventListener('fc-mouseover',function(){this.setData({interactionStyle:this.config.extStyle['title:hover'],hoverConfig:!0},!0)}),this.addEventListener('fc-mouseout',function(){b.config.blockUpdate||b.setData({interactionStyle:this.config.extStyle['title:hoverout'],hoverConfig:!0},!0)}),document.addEventListener('keydown',b.keyDownHandler)}__setDefaultConfig(){super.__setDefaultConfig();let a=this.config;a.containerState=0,a.showDate=!0,a.calendarIconPath='M15.604605,2.6231875 C15.3617479,2.39715625 15.0736134,2.284125 14.7409412,2.284125 L13.5126723,2.284125 L13.5126723,1.4275625 C13.5126723,1.0350625 13.3621849,0.69896875 13.0615126,0.41940625 C12.7606723,0.13984375 12.3993613,0 11.9769748,0 L11.3629244,0 C10.9405714,0 10.5791261,0.13984375 10.2784202,0.4194375 C9.97761345,0.69896875 9.8272605,1.03509375 9.8272605,1.42759375 L9.8272605,2.28415625 L6.14221849,2.28415625 L6.14221849,1.42759375 C6.14221849,1.03509375 5.99179832,0.699 5.69105882,0.4194375 C5.39038655,0.13984375 5.02890756,0 4.60655462,0 L3.99240336,0 C3.57015126,0 3.20863866,0.13984375 2.90789916,0.4194375 C2.60722689,0.69896875 2.45677311,1.03509375 2.45677311,1.42759375 L2.45677311,2.28415625 L1.22847059,2.28415625 C0.895697479,2.28415625 0.607831933,2.3971875 0.364705882,2.62321875 C0.121579832,2.84921875 0,3.11696875 0,3.42625 L0,14.8466563 C0,15.1557188 0.121579832,15.4234063 0.364705882,15.6495625 C0.607798319,15.8755312 0.895663866,15.9885937 1.22847059,15.9885937 L14.7407059,15.9885937 C15.0733782,15.9885937 15.3615462,15.8755625 15.6043697,15.6495625 C15.8475294,15.4235 15.9691429,15.1556875 15.9691429,14.8466563 L15.9691429,3.42621875 C15.9691092,3.11684375 15.8476303,2.84921875 15.604605,2.6231875 Z M11.0558319,1.4276875 C11.0558319,1.34434375 11.0843697,1.275875 11.1418824,1.22246875 C11.199395,1.169 11.2730084,1.14221875 11.3627227,1.14221875 L11.9767731,1.14221875 C12.066521,1.14221875 12.1398992,1.16890625 12.1976134,1.22246875 C12.2551597,1.27596875 12.2838992,1.3444375 12.2838992,1.4276875 L12.2838992,3.9971875 C12.2838992,4.0805 12.2551597,4.14884375 12.1976134,4.20240625 C12.1398655,4.2558125 12.066521,4.28265625 11.9767731,4.28265625 L11.3627227,4.28265625 C11.2730084,4.28265625 11.199395,4.2559375 11.1418824,4.20240625 C11.0843697,4.1488125 11.0558319,4.0805 11.0558319,3.9971875 L11.0558319,1.4276875 Z M3.68534454,1.4276875 C3.68534454,1.34434375 3.71408403,1.275875 3.77166387,1.22246875 C3.82927731,1.169 3.90278992,1.14221875 3.99240336,1.14221875 L4.60655462,1.14221875 C4.69620168,1.14221875 4.76984874,1.16890625 4.82729412,1.22246875 C4.88480672,1.27596875 4.91368067,1.3444375 4.91368067,1.4276875 L4.91368067,3.9971875 C4.91368067,4.0805 4.88494118,4.1489375 4.82729412,4.20240625 C4.76971429,4.2558125 4.69620168,4.28265625 4.60655462,4.28265625 L3.99240336,4.28265625 C3.90278992,4.28265625 3.82917647,4.2559375 3.77166387,4.20240625 C3.71421849,4.1488125 3.68534454,4.0805 3.68534454,3.9971875 L3.68534454,1.4276875 Z M14.7407059,14.8465 L1.22847059,14.8465 L1.22847059,5.71025 L14.7407059,5.71025 L14.7407059,14.8465 Z',a.calendarIconDim={width:16,height:16},a.containerPos={x:100,y:100},a.containerInfo={id:'group',label:'group',isParent:!0},a.spaceNotHardCoded=!0,a.hoveredState=NORMAL,a._iconStyle={fill:'#5648D4',transform:'',opacity:1},a._textStyle={"font-size":'12px',"font-style":'normal',"font-weight":'600',"text-anchor":'start',fill:'#5648D4',opacity:1},a.prevDim={height:0,width:0}}configureAttributes(a={}){let b,c=this,d=c.config,e=c.getFromEnv('focusScalesX'),f=!1,g={},h={},i=c.getFromEnv('getStyleDef'),j=c.getFromEnv('baseTextStyle');for(b in a)d[b]=a[b];a.blockUpdate||delete d.blockUpdate,a.interactionStyle||delete d.interactionStyle,g=d.extStyle||{},h=d.interactionStyle||{},c.setState(VISIBLE,!0!==d.isHidden),d.symbolName=d.name,e.forEach(a=>{TIME_INTERVALS.includes(a.getBinMin()[0].name())&&(f=!0)}),c.attachChild(Cover,'cover','cover').configure({visibility:'hidden'}),c.attachChild(CustomRangeManager,'manager','manager').configure({visibility:'hidden',position:d.containerPos,showTime:f,extStyle:g,drawCalendars:!1}),d.showTime=f,d._finalIconStyle=Object.assign({},d._iconStyle,i(g.title&&g.title.icon),i(h.icon)),d._finalTextStyle=Object.assign({},d._textStyle,j,i(g.title&&g.title.text),i(h.text))}getLabel(){let a,b=this,c=b.config,d='',e=c.showTimeInLabel,f=+b.getFromEnv('chartWidth'),g=b.getLinkedParent(),h=b.getFromEnv('chart'),i=h.getFromEnv('contextScalesX')[0],j=c.domain||i.getDomain(),k=b.getFromEnv('smartLabel'),l=new Date(j[0]),m=new Date(j[1]),n=Object.assign(c.prevDim),o=n;return k.setStyle(c._finalTextStyle),d=i.getFormattedTime({dateRange:{startDate:l,endDate:m},type:CRS,showTimeInLabel:e}),a=k.getOriSize(d),10<Math.abs(a.width-n.width)&&(o=c.prevDim=Object.assign(a)),600>f&&.4<(o.width+c.calendarIconDim.width)/g.props.width&&(d='',o.width=0),c.label=d,{text:d,dim:o}}getLogicalSpace(){let a,b=this,c=b.config,d=b.getChildren('manager')[0],e=b.getFromEnv('focusScalesX'),f=!1,{width:g,height:h,marginTop:i,marginLeft:j,marginRight:k,marginBottom:l}=c;return e.forEach(a=>{TIME_INTERVALS.includes(a.getBinMin()[0].name())&&(c.showTime=!0),a._timeFormat&&(f=TIME_INTERVALS.includes(a._timeFormat.major)||TIME_INTERVALS.includes(a._timeFormat.minor)||f)}),c.showTimeInLabel=f,d.configure({showTime:c.showTime},!0),a=b.getLabel().dim,g=a.width,h=a.height,(c.skipGraphics||c.isHidden||b.getState('removed'))&&(g=h=l=j=k=i=0),c.width=a.width,c.height=a.height,{width:g,height:h,marginLeft:j,marginBottom:l,marginRight:k,marginTop:i}}draw(){let a,b,c,d,e,f=this,g=f.config,h=f.getLinkedParent();f.addGraphicalElement({el:'group',attr:{name:'range-selector-text',transform:`t${g.x}, ${g.y+h.props.height/2}`},container:g.containerInfo,component:f,id:'group',label:'group'},!0),c=getScalingParam(g._finalTextStyle['font-size']),d=c*g.calendarIconDim.width,e=c*g.calendarIconDim.height,a=-1*d-SPACE_BETWEEN_ICON_AND_TEXT,b=-1*(3*e/4),f.addGraphicalElement({el:'group',attr:{name:'range-selector-icon-group',transform:`t${a}, ${b}`},container:{id:'group',label:'group'},component:f,label:'group',id:'icon-group'},!0),g._finalIconStyle.transform+=` s${c}`,f.addGraphicalElement({el:'path',attr:{path:g.calendarIconPath},css:g._finalIconStyle,container:{id:'icon-group',label:'group'},component:f,label:'path',id:'icon'},!0),f.addGraphicalElement({el:'text',attr:{text:g.label,opacity:g._finalTextStyle.opacity},css:g._finalTextStyle,container:{id:'group',label:'group'},component:f,label:'text',id:'display'},!0),f.addGraphicalElement({el:'rect',attr:{fill:TRACKER_FILL,x:a-SPACE_BETWEEN_ICON_AND_TEXT,y:-1*h.props.height/2,width:d+10+g.width,height:h.props.height},component:f,container:{label:'group',id:'group'},css:{cursor:'pointer'},label:'rect',id:'rect'}),g.containerPos={x:g.x-d/2-SPACE_BETWEEN_ICON_AND_TEXT*c,y:g.y+h.props.height/2+e}}removeDocumentListener(){this.config.wrapper.off(document,'fc-click',this.config.documentClicked)}}export default CustomRangeSelectorTool;