UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 5.33 kB
import Message from'./message';import{ComponentInterface}from'../../../fc-core/src/component-interface';import{pluckNumber,pluck,HEXtoRGB}from'../../../fc-core/src/lib';let mathMin=Math.min;const defAnimEffect='normal',PX='px';var UNDEF;class MessageLogger extends ComponentInterface{constructor(){super(),this.pIndex=1,this.linkedItems=this.linkedItems||(this.linkedItems={}),this.components=this.components||{},this.components.messages=this.components.messages||[],this.graphics=this.graphics||{},this.config=this.config||(this.config={})}getType(){return'extension'}getName(){return'MessageLogger'}configure(a){this.linkedItems.chart=a;let b=a.getFromEnv('chart-attrib')||{},c=this.config.usemessagelog=a.getFromEnv('chartConfig').usemessagelog;this.config.messageLogWPercent=mathMin(pluckNumber(b.messagelogwpercent,80),100),this.config.messageLogHPercent=mathMin(pluckNumber(b.messageloghpercent,70),100),this.config.messageLogShowTitle=pluckNumber(b.messagelogshowtitle,1),this.config.messageLogTitle=pluck(b.messagelogtitle,'Message Log'),this.config.messageLogColor=pluck(b.messagelogcolor,'#fbfbfb').replace(/^#?([a-f0-9]+)/ig,'$1'),this.config.messageLogColorRgb=HEXtoRGB(this.config.messageLogColor),this.config.messageGoesToJS=pluckNumber(b.messagegoestojs,0),this.config.messageGoesToLog=pluckNumber(b.messagegoestolog,1),this.config.messageJSHandler=pluck(b.messagejshandler,''),this.config.messagePassAllToJS=pluckNumber(b.messagepassalltojs,0),this.config.messagePassAsObject=pluckNumber(b.messagepassasobject,0),this.config.messageLogIsCancelable=pluckNumber(b.messagelogiscancelable,1),this.config.alwaysShowMessageLogMenu=pluckNumber(b.alwaysshowmessagelogmenu,c),a.config.useShowLogMenu=c&&this.config.messageGoesToLog,this.config.dynamicScrolling=!1,this.config.scrollToBottom=!0}_createMessage(a){let b=this,c=new Message(a,b);return this.graphics.container&&c.draw(),c}addLog(a){let b,c=this.components.messages,d=pluckNumber(a.msgGoesToLog,this.config.messageGoesToLog),e=pluckNumber(a.msgGoesToJS,this.config.messageGoesToJS),f=window[this.config.messageJSHandler],g=pluck(a.msgId,''),h=pluck(a.msgTitle,''),i=pluck(a.msgText,''),j=pluck(a.msgType,'literal');0==this.config.usemessagelog||(e&&f&&'function'==typeof f&&(this.config.messagePassAllToJS?this.config.messagePassAsObject?f(a):f(g,h,i,j):f(i)),'1'===a.clearLog&&this.clearLog(),d&&(a.msgTitle||a.msgText)&&(b=this._createMessage(a),c.push(b),1===c.length&&!this.config.visible&&this.show()))}show(){this.config.visible||1!=this.config.usemessagelog||(this.config.visible=!0,this.draw(),!this.graphics.container&&this.draw(),this.graphics.container&&this.graphics.container.show())}hide(){this.config.visible=!1,this.graphics.container&&this.graphics.container.hide()}clearLog(){let a,b=this.components.messages,c=b.length;for(a=0;a<c;a+=1)b[a]&&b[a].dispose&&b[a].dispose();b.splice(0,c)}isDrawn(){return!!this.graphics.container}draw(){let a,b,c=this.components.messages;if(0===this.config.usemessagelog)this.isDrawn()&&(this.clearLog(),this.hide());else for(this._createHTMLDialogue(),this.config.visible||this.hide(),b=c.length,a=0;a<b;a+=1)c[a]&&c[a].draw&&c[a].draw()}_createHTMLDialogue(){var a,b,c,d,e=this,f=this.config,g=this.graphics,h=this.linkedItems.chart,i=this.getFromEnv('paper'),j=this.getFromEnv('chart-container'),k=h.config,l=k.width,m=k.height,n=k.style,o=n&&n.inCanvasStyle,p=this.config.messageLogWPercent,q=this.config.messageLogHPercent,r=this.config.messageLogShowTitle,s=this.config.messageLogIsCancelable,t=this.config.messageLogColor,u=this.config.messageLogTitle,v=l*(p/100),w=m*(q/100),x=v-18-22,y=w-18-22,z=g.container,A=this.isDrawn()&&k.animation&&k.animation.transposeAnimDuration;z||(z=g.container=i.html('div',{fill:'transparent'},{fontSize:'10px',lineHeight:'15px'},j),g.veil=i.html('div',{id:'veil',fill:'000000',opacity:.1},UNDEF,z).on('click',function(){s&&e.hide()}),u&&r&&(g.title=i.html('p',{id:'Title',innerHTML:u,x:5,y:5},{"font-weight":'bold'},z)),g.dialog=i.html('div',{id:'dialog',strokeWidth:1},{borderRadius:'5px',boxShadow:'1px 1px 3px #000000',"-webkit-border-radius":'5px',"-webkit-box-shadow":'1px 1px 3px #000000',filter:'progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color="#000000")'},z),g.logBackground=i.html('div',{id:'dialogBackground',x:0,y:0},UNDEF,g.dialog),s&&(g.closeButton=i.html('div',{id:'closeButton',x:v-11-3,y:2,innerHTML:'<b>x</b>'},{cursor:'pointer',_cursor:'hand'},g.dialog).on('click',function(){s&&e.hide()})),g.logWrapper=i.html('div',{id:'logWrapper'},{overflow:'auto'},g.dialog).on('scroll',function(){var a=this,b=a&&a.scrollTop,c=a&&a.scrollHeight,d=a&&a.offsetHeight;return f.dynamicScrolling?void(f.dynamicScrolling=!1):void(f.scrollToBottom=c-b===d)}),g.log=i.html('div',{id:'log',x:0,y:0},{},g.logWrapper)),z.css({fontFamily:o.fontFamily}),g.dialog.attr({fill:'ffffff',stroke:t}),g.logBackground.attr({fill:t}),a={width:l,height:m},b={x:(l-v)/2,y:(m-w)/2,width:v,height:w},c={width:v,height:w},d={x:(v-x)/2,y:(w-y)/2,width:x,height:y},A?(z.animate(a,A,defAnimEffect),g.veil.animate(a,A,defAnimEffect),g.dialog.animate(b,A,defAnimEffect),g.logBackground.animate(c,A,defAnimEffect),g.logWrapper.animate(d,A,defAnimEffect)):(z.attr(a),g.veil.attr(a),g.dialog.attr(b),g.logBackground.attr(c),g.logWrapper.attr(d))}}export default MessageLogger;