UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 2.81 kB
const FC_TOOLTIP_CLASS='fc__tooltip',GUTTER_12=12;let UNDEF,_getContainerBounds=function(a){let b=a.getBoundingClientRect();return{left:0,top:0,right:b.width||b.right-b.left,bottom:b.height||b.bottom-b.top}};class ToolTip{constructor(a,b){let c=this;c.text='',c.x=0,c.y=0,c.visibleWidth=0,c.universe=a,c.setUniverseBounds(b||_getContainerBounds(a)),c.data={active:!1,target:!1},c.createElement(a),c.previousStyle={},c.restrictWithinCanvas={left:!1,right:!1,top:!1,bottom:!1}}setUniverseBounds(a){this.universeBounds=a||this.universe&&_getContainerBounds(this.universe)}setRestrictionWithinCanvas(a={}){Object.assign(this.restrictWithinCanvas,a)}getRestrictionWithinCanvas(){return this.restrictWithinCanvas}createElement(a){let b=this.element=document.createElement('div');return b.setAttribute('class',FC_TOOLTIP_CLASS),b.className+=' fusioncharts-div',b.innerHTML=this.text,a.appendChild(this.setDefaultStyle()),b}setDefaultStyle(){let a=this.element;return a.setAttribute('style',''),a.style.color='#545454',a.style.padding='3px',a.style.fontSize='10px',a.style.overflow='hidden',a.style.borderWidth='1px',a.style.borderColor='#000000',a.style.whiteSpace='nowrap',a.style.position='absolute',a.style.borderStyle='solid',a.style.backgroundColor='#ffffff',a.style['user-select']='none',a.style['-ms-user-select']='none',a.style['-moz-user-select']='none',a.style['-webkit-user-select']='none',a.style['-webkit-touch-callout']='none',a.style.top=this.x+'px',a.style.left=this.y+'px',a.style.visibility='hidden',a.style['pointer-events']='none',a}setData(a,b){this.data[a]=b}getData(a){return this.data[a]}setStyle(a){var b,c=this.element,d=c.style;for(b in this.setDefaultStyle(),a)d[b]=a[b]}show(a){this.text!==a&&(this.text=a,this.element.innerHTML=this.text),this.setData('active',!0),'visible'!==this.element.style.visibility&&(this.element.style.visibility='visible'),this.element.style['will-change']='left, top',this.element.style['max-width']=this.universeBounds.right-this.universeBounds.left-24+'px'}update(a=this.x,b=this.y,c){let d=this.restrictWithinCanvas,e=d.right?this.universeBounds.right:this.universe.clientWidth,f=c.left+GUTTER_12,g=(d.bottom?this.universeBounds.bottom:this.universe.clientHeight)-GUTTER_12,h=this.universeBounds.right-this.universeBounds.left-24,i=this.element,j=i.offsetWidth,k=i.offsetHeight,l=i.style;a+j<e?(l.left=a+'px',l.whiteSpace='nowrap'):j<h?l.left=a-j-GUTTER_12+'px':(l.left=f+'px',l.whiteSpace='normal'),l.top=b+k<g?b+'px':g-k+'px'}hide(){this.y=0,this.x=0,this.x='',this.setData('active',!1),this.setData('target',!1),this.element.style.visibility='hidden',this.element.style['will-change']='auto',this.element.innerHTML='',this.text=UNDEF}dispose(){this.hide(),this.universe.removeChild(this.element),this.universe=void 0,this.disposed=!0}}export default ToolTip;