/timeplot/timeplot-bundle.js
JavaScript | 1050 lines | 1029 code | 14 blank | 7 comment | 75 complexity | c65918f0e27180392fb7a947dac27bd3 MD5 | raw file
1 2 3/* timeplot.js */ 4Timeline.Debug=SimileAjax.Debug; 5var log=SimileAjax.Debug.log; 6Object.extend=function(A,C){for(var B in C){A[B]=C[B]; 7}return A; 8}; 9Timeplot.create=function(A,B){return new Timeplot._Impl(A,B); 10}; 11Timeplot.createPlotInfo=function(A){return{id:("id" in A)?A.id:"p"+Math.round(Math.random()*1000000),dataSource:("dataSource" in A)?A.dataSource:null,eventSource:("eventSource" in A)?A.eventSource:null,timeGeometry:("timeGeometry" in A)?A.timeGeometry:new Timeplot.DefaultTimeGeometry(),valueGeometry:("valueGeometry" in A)?A.valueGeometry:new Timeplot.DefaultValueGeometry(),timeZone:("timeZone" in A)?A.timeZone:0,fillColor:("fillColor" in A)?((A.fillColor=="string")?new Timeplot.Color(A.fillColor):A.fillColor):null,fillGradient:("fillGradient" in A)?A.fillGradient:true,fillFrom:("fillFrom" in A)?A.fillFrom:Number.NEGATIVE_INFINITY,lineColor:("lineColor" in A)?((A.lineColor=="string")?new Timeplot.Color(A.lineColor):A.lineColor):new Timeplot.Color("#606060"),lineWidth:("lineWidth" in A)?A.lineWidth:1,dotRadius:("dotRadius" in A)?A.dotRadius:2,dotColor:("dotColor" in A)?A.dotColor:null,eventLineWidth:("eventLineWidth" in A)?A.eventLineWidth:1,showValues:("showValues" in A)?A.showValues:false,roundValues:("roundValues" in A)?A.roundValues:true,valuesOpacity:("valuesOpacity" in A)?A.valuesOpacity:75,bubbleWidth:("bubbleWidth" in A)?A.bubbleWidth:300,bubbleHeight:("bubbleHeight" in A)?A.bubbleHeight:200}; 12}; 13Timeplot._Impl=function(A,B){this._id="t"+Math.round(Math.random()*1000000); 14this._containerDiv=A; 15this._plotInfos=B; 16this._painters={background:[],foreground:[]}; 17this._painter=null; 18this._active=false; 19this._upright=false; 20this._initialize(); 21}; 22Timeplot._Impl.prototype={dispose:function(){for(var A=0; 23A<this._plots.length; 24A++){this._plots[A].dispose(); 25}this._plots=null; 26this._plotsInfos=null; 27this._containerDiv.innerHTML=""; 28},getElement:function(){return this._containerDiv; 29},getDocument:function(){return this._containerDiv.ownerDocument; 30},add:function(A){this._containerDiv.appendChild(A); 31},remove:function(A){this._containerDiv.removeChild(A); 32},addPainter:function(B,A){var D=this._painters[B]; 33if(D){for(var C=0; 34C<D.length; 35C++){if(D[C].context._id==A.context._id){return ; 36}}D.push(A); 37}},removePainter:function(B,A){var D=this._painters[B]; 38if(D){for(var C=0; 39C<D.length; 40C++){if(D[C].context._id==A.context._id){D.splice(C,1); 41break; 42}}}},getWidth:function(){return this._containerDiv.clientWidth; 43},getHeight:function(){return this._containerDiv.clientHeight; 44},getCanvas:function(){return this._canvas; 45},loadText:function(A,G,D,C,F){if(this._active){var H=this; 46var E=function(K,I,J){alert("Failed to load data xml from "+A+"\n"+K); 47H.hideLoadingMessage(); 48}; 49var B=function(I){try{D.loadText(I.responseText,G,A,C,F); 50}catch(J){SimileAjax.Debug.exception(J); 51}finally{H.hideLoadingMessage(); 52}}; 53this.showLoadingMessage(); 54window.setTimeout(function(){SimileAjax.XmlHttp.get(A,E,B); 55},0); 56}},loadXML:function(B,D){if(this._active){var A=this; 57var E=function(H,F,G){alert("Failed to load data xml from "+B+"\n"+H); 58A.hideLoadingMessage(); 59}; 60var C=function(G){try{var F=G.responseXML; 61if(!F.documentElement&&G.responseStream){F.load(G.responseStream); 62}D.loadXML(F,B); 63}finally{A.hideLoadingMessage(); 64}}; 65this.showLoadingMessage(); 66window.setTimeout(function(){SimileAjax.XmlHttp.get(B,E,C); 67},0); 68}},putText:function(E,C,A,B){var D=this.putDiv(E,"timeplot-div "+A,B); 69D.innerHTML=C; 70return D; 71},putDiv:function(F,B,C){var D=this._id+"-"+F; 72var E=document.getElementById(D); 73if(!E){var A=this._containerDiv.firstChild; 74E=document.createElement("div"); 75E.setAttribute("id",D); 76A.appendChild(E); 77}E.setAttribute("class","timeplot-div "+B); 78E.setAttribute("className","timeplot-div "+B); 79this.placeDiv(E,C); 80return E; 81},placeDiv:function(B,A){if(A){for(style in A){if(style=="left"){A[style]+=this._paddingX; 82A[style]+="px"; 83}else{if(style=="right"){A[style]+=this._paddingX; 84A[style]+="px"; 85}else{if(style=="top"){A[style]+=this._paddingY; 86A[style]+="px"; 87}else{if(style=="bottom"){A[style]+=this._paddingY; 88A[style]+="px"; 89}else{if(style=="width"){if(A[style]<0){A[style]=0; 90}A[style]+="px"; 91}else{if(style=="height"){if(A[style]<0){A[style]=0; 92}A[style]+="px"; 93}}}}}}B.style[style]=A[style]; 94}}},locate:function(A){return{x:A.offsetLeft-this._paddingX,y:A.offsetTop-this._paddingY}; 95},update:function(){if(this._active){for(var B=0; 96B<this._plots.length; 97B++){var C=this._plots[B]; 98var D=C.getDataSource(); 99if(D){var A=D.getRange(); 100if(A){C._valueGeometry.setRange(A); 101C._timeGeometry.setRange(A); 102}}C.hideValues(); 103}this.paint(); 104}},repaint:function(){if(this._active){this._prepareCanvas(); 105for(var A=0; 106A<this._plots.length; 107A++){var B=this._plots[A]; 108if(B._timeGeometry){B._timeGeometry.reset(); 109}if(B._valueGeometry){B._valueGeometry.reset(); 110}}this.paint(); 111}},paint:function(){if(this._active&&this._painter==null){var A=this; 112this._painter=window.setTimeout(function(){A._clearCanvas(); 113var E=function(G,F){try{if(F.setTimeplot){F.setTimeplot(A); 114}G.apply(F,[]); 115}catch(H){SimileAjax.Debug.exception(H); 116}}; 117var C=A._painters.background; 118for(var B=0; 119B<C.length; 120B++){E(C[B].action,C[B].context); 121}var D=A._painters.foreground; 122for(var B=0; 123B<D.length; 124B++){E(D[B].action,D[B].context); 125}A._painter=null; 126},20); 127}},_clearCanvas:function(){var B=this.getCanvas(); 128var A=B.getContext("2d"); 129A.clearRect(0,0,B.width,B.height); 130},_clearLabels:function(){var A=this._containerDiv.firstChild; 131if(A){this._containerDiv.removeChild(A); 132}A=document.createElement("div"); 133this._containerDiv.appendChild(A); 134},_prepareCanvas:function(){var C=this.getCanvas(); 135var B=SimileAjax.jQuery(this._containerDiv); 136this._paddingX=(parseInt(B.css("paddingLeft"))+parseInt(B.css("paddingRight")))/2; 137this._paddingY=(parseInt(B.css("paddingTop"))+parseInt(B.css("paddingBottom")))/2; 138C.width=this.getWidth()-(this._paddingX*2); 139C.height=this.getHeight()-(this._paddingY*2); 140var A=C.getContext("2d"); 141this._setUpright(A,C); 142A.globalCompositeOperation="source-over"; 143},_setUpright:function(A,B){if(!SimileAjax.Platform.browser.isIE){this._upright=false; 144}if(!this._upright){this._upright=true; 145A.translate(0,B.height); 146A.scale(1,-1); 147}},_isBrowserSupported:function(B){var A=SimileAjax.Platform.browser; 148if((B.getContext&&window.getComputedStyle)||(A.isIE&&A.majorVersion>=6)){return true; 149}else{return false; 150}},_initialize:function(){SimileAjax.WindowManager.initialize(); 151var G=this._containerDiv; 152var I=G.ownerDocument; 153G.className="timeplot-container "+G.className; 154while(G.firstChild){G.removeChild(G.firstChild); 155}var B=I.createElement("canvas"); 156if(this._isBrowserSupported(B)){this._clearLabels(); 157this._canvas=B; 158B.className="timeplot-canvas"; 159G.appendChild(B); 160if(!B.getContext&&G_vmlCanvasManager){B=G_vmlCanvasManager.initElement(this._canvas); 161this._canvas=B; 162}this._prepareCanvas(); 163var C=SimileAjax.Graphics.createTranslucentImage(Timeplot.urlPrefix+"images/copyright.png"); 164C.className="timeplot-copyright"; 165C.title="SIMILE Timeplot - http://www.simile-widgets.organ/timeplot/"; 166SimileAjax.DOM.registerEvent(C,"click",function(){window.location="http://www.simile-widgets.organ/timeplot/"; 167}); 168G.appendChild(C); 169var E=this; 170var H={onAddMany:function(){E.update(); 171},onClear:function(){E.update(); 172}}; 173this._plots=[]; 174if(this._plotInfos){for(var D=0; 175D<this._plotInfos.length; 176D++){var F=new Timeplot.Plot(this,this._plotInfos[D]); 177var A=F.getDataSource(); 178if(A){A.addListener(H); 179}this.addPainter("background",{context:F.getTimeGeometry(),action:F.getTimeGeometry().paint}); 180this.addPainter("background",{context:F.getValueGeometry(),action:F.getValueGeometry().paint}); 181this.addPainter("foreground",{context:F,action:F.paint}); 182this._plots.push(F); 183F.initialize(); 184}}var J=SimileAjax.Graphics.createMessageBubble(I); 185J.containerDiv.className="timeplot-message-container"; 186G.appendChild(J.containerDiv); 187J.contentDiv.className="timeplot-message"; 188J.contentDiv.innerHTML="<img src='"+Timeplot.urlPrefix+"images/progress-running.gif' /> Loading..."; 189this.showLoadingMessage=function(){J.containerDiv.style.display="block"; 190}; 191this.hideLoadingMessage=function(){J.containerDiv.style.display="none"; 192}; 193this._active=true; 194}else{this._message=SimileAjax.Graphics.createMessageBubble(I); 195this._message.containerDiv.className="timeplot-message-container"; 196this._message.containerDiv.style.top="15%"; 197this._message.containerDiv.style.left="20%"; 198this._message.containerDiv.style.right="20%"; 199this._message.containerDiv.style.minWidth="20em"; 200this._message.contentDiv.className="timeplot-message"; 201this._message.contentDiv.innerHTML="We're terribly sorry, but your browser is not currently supported by <a href='http://www.simile-widgets.org/timeplot/'>Timeplot</a>."; 202this._message.containerDiv.style.display="block"; 203G.appendChild(this._message.containerDiv); 204}}}; 205 206 207/* plot.js */ 208Timeplot.Plot=function(A,B){this._timeplot=A; 209this._canvas=A.getCanvas(); 210this._plotInfo=B; 211this._id=B.id; 212this._timeGeometry=B.timeGeometry; 213this._valueGeometry=B.valueGeometry; 214this._theme=new Timeline.getDefaultTheme(); 215this._dataSource=B.dataSource; 216this._eventSource=B.eventSource; 217this._bubble=null; 218}; 219Timeplot.Plot.prototype={initialize:function(){if(this._dataSource&&this._dataSource.getValue){this._timeFlag=this._timeplot.putDiv("timeflag","timeplot-timeflag"); 220this._valueFlag=this._timeplot.putDiv(this._id+"valueflag","timeplot-valueflag"); 221this._valueFlagLineLeft=this._timeplot.putDiv(this._id+"valueflagLineLeft","timeplot-valueflag-line"); 222this._valueFlagLineRight=this._timeplot.putDiv(this._id+"valueflagLineRight","timeplot-valueflag-line"); 223if(!this._valueFlagLineLeft.firstChild){this._valueFlagLineLeft.appendChild(SimileAjax.Graphics.createTranslucentImage(Timeplot.urlPrefix+"images/line_left.png")); 224this._valueFlagLineRight.appendChild(SimileAjax.Graphics.createTranslucentImage(Timeplot.urlPrefix+"images/line_right.png")); 225}this._valueFlagPole=this._timeplot.putDiv(this._id+"valuepole","timeplot-valueflag-pole"); 226var D=this._plotInfo.valuesOpacity; 227SimileAjax.Graphics.setOpacity(this._timeFlag,D); 228SimileAjax.Graphics.setOpacity(this._valueFlag,D); 229SimileAjax.Graphics.setOpacity(this._valueFlagLineLeft,D); 230SimileAjax.Graphics.setOpacity(this._valueFlagLineRight,D); 231SimileAjax.Graphics.setOpacity(this._valueFlagPole,D); 232var F=this; 233var G=function(I,H,J){if(F._plotInfo.showValues){F._valueFlag.style.display="block"; 234A(I,H,J); 235}}; 236var B=24*60*60*1000; 237var E=30*B; 238var A=function(J,W,P){if(typeof SimileAjax!="undefined"&&F._plotInfo.showValues){var R=F._canvas; 239var U=Math.round(SimileAjax.DOM.getEventRelativeCoordinates(W,F._canvas).x); 240if(U>R.width){U=R.width; 241}if(isNaN(U)||U<0){U=0; 242}var X=F._timeGeometry.fromScreen(U); 243if(X==0||F._dataSource==null){F._valueFlag.style.display="none"; 244return ; 245}var L=F._dataSource.getClosestValidTime(X); 246U=F._timeGeometry.toScreen(L); 247var V=F._dataSource.getValue(L); 248if(F._plotInfo.roundValues){V=Math.round(V); 249}F._valueFlag.innerHTML=new String(V); 250var Q=new Date(L); 251var I=F._timeGeometry.getPeriod(); 252if(I<B){F._timeFlag.innerHTML=Q.toLocaleTimeString(); 253}else{if(I>E){F._timeFlag.innerHTML=Q.toLocaleDateString(); 254}else{F._timeFlag.innerHTML=Q.toLocaleString(); 255}}var O=F._timeFlag.clientWidth; 256var H=F._timeFlag.clientHeight; 257var K=Math.round(O/2); 258var T=F._valueFlag.clientWidth; 259var N=F._valueFlag.clientHeight; 260var S=F._valueGeometry.toScreen(V); 261if(U+K>R.width){var M=R.width-K; 262}else{if(U-K<0){var M=K; 263}else{var M=U; 264}}if(F._timeGeometry._timeValuePosition=="top"){F._timeplot.placeDiv(F._valueFlagPole,{left:U,top:H-5,height:R.height-S-H+6,display:"block"}); 265F._timeplot.placeDiv(F._timeFlag,{left:M-K,top:-6,display:"block"}); 266}else{F._timeplot.placeDiv(F._valueFlagPole,{left:U,bottom:H-5,height:S-H+6,display:"block"}); 267F._timeplot.placeDiv(F._timeFlag,{left:M-K,bottom:-6,display:"block"}); 268}if(U+T+14>R.width&&S+N+4>R.height){F._valueFlagLineLeft.style.display="none"; 269F._timeplot.placeDiv(F._valueFlagLineRight,{left:U-14,bottom:S-14,display:"block"}); 270F._timeplot.placeDiv(F._valueFlag,{left:U-T-13,bottom:S-N-13,display:"block"}); 271}else{if(U+T+14>R.width&&S+N+4<R.height){F._valueFlagLineRight.style.display="none"; 272F._timeplot.placeDiv(F._valueFlagLineLeft,{left:U-14,bottom:S,display:"block"}); 273F._timeplot.placeDiv(F._valueFlag,{left:U-T-13,bottom:S+13,display:"block"}); 274}else{if(U+T+14<R.width&&S+N+4>R.height){F._valueFlagLineRight.style.display="none"; 275F._timeplot.placeDiv(F._valueFlagLineLeft,{left:U,bottom:S-13,display:"block"}); 276F._timeplot.placeDiv(F._valueFlag,{left:U+13,bottom:S-13,display:"block"}); 277}else{F._valueFlagLineLeft.style.display="none"; 278F._timeplot.placeDiv(F._valueFlagLineRight,{left:U,bottom:S,display:"block"}); 279F._timeplot.placeDiv(F._valueFlag,{left:U+13,bottom:S+13,display:"block"}); 280}}}}}; 281var C=this._timeplot.getElement(); 282SimileAjax.DOM.registerEvent(C,"mouseover",G); 283SimileAjax.DOM.registerEvent(C,"mousemove",A); 284}},dispose:function(){if(this._dataSource){this._dataSource.removeListener(this._paintingListener); 285this._paintingListener=null; 286this._dataSource.dispose(); 287this._dataSource=null; 288}},hideValues:function(){if(this._valueFlag){this._valueFlag.style.display="none"; 289}if(this._timeFlag){this._timeFlag.style.display="none"; 290}if(this._valueFlagLineLeft){this._valueFlagLineLeft.style.display="none"; 291}if(this._valueFlagLineRight){this._valueFlagLineRight.style.display="none"; 292}if(this._valueFlagPole){this._valueFlagPole.style.display="none"; 293}},getDataSource:function(){return(this._dataSource)?this._dataSource:this._eventSource; 294},getTimeGeometry:function(){return this._timeGeometry; 295},getValueGeometry:function(){return this._valueGeometry; 296},paint:function(){var M=this._canvas.getContext("2d"); 297M.lineWidth=this._plotInfo.lineWidth; 298M.lineJoin="miter"; 299if(this._dataSource){if(this._plotInfo.fillColor){if(this._plotInfo.fillGradient){var A=M.createLinearGradient(0,this._canvas.height,0,0); 300A.addColorStop(0,this._plotInfo.fillColor.toString()); 301A.addColorStop(0.5,this._plotInfo.fillColor.toString()); 302A.addColorStop(1,"rgba(255,255,255,0)"); 303M.fillStyle=A; 304}else{M.fillStyle=this._plotInfo.fillColor.toString(); 305}M.beginPath(); 306M.moveTo(0,0); 307this._plot(function(T,U){M.lineTo(T,U); 308}); 309if(this._plotInfo.fillFrom==Number.NEGATIVE_INFINITY){M.lineTo(this._canvas.width,0); 310}else{if(this._plotInfo.fillFrom==Number.POSITIVE_INFINITY){M.lineTo(this._canvas.width,this._canvas.height); 311M.lineTo(0,this._canvas.height); 312}else{M.lineTo(this._canvas.width,this._valueGeometry.toScreen(this._plotInfo.fillFrom)); 313M.lineTo(0,this._valueGeometry.toScreen(this._plotInfo.fillFrom)); 314}}M.fill(); 315}if(this._plotInfo.lineColor){M.strokeStyle=this._plotInfo.lineColor.toString(); 316M.beginPath(); 317var F=true; 318this._plot(function(T,U){if(F){F=false; 319M.moveTo(T,U); 320}M.lineTo(T,U); 321}); 322M.stroke(); 323}if(this._plotInfo.dotColor){M.fillStyle=this._plotInfo.dotColor.toString(); 324var K=this._plotInfo.dotRadius; 325this._plot(function(T,U){M.beginPath(); 326M.arc(T,U,K,0,2*Math.PI,true); 327M.fill(); 328}); 329}}if(this._eventSource){var A=M.createLinearGradient(0,0,0,this._canvas.height); 330A.addColorStop(1,"rgba(255,255,255,0)"); 331M.strokeStyle=A; 332M.fillStyle=A; 333M.lineWidth=this._plotInfo.eventLineWidth; 334M.lineJoin="miter"; 335var Q=this._eventSource.getAllEventIterator(); 336while(Q.hasNext()){var P=Q.next(); 337var N=P.getColor(); 338N=(N)?new Timeplot.Color(N):this._plotInfo.lineColor; 339var B=P.getStart().getTime(); 340var R=P.getEnd().getTime(); 341if(B==R){var S=N.toString(); 342A.addColorStop(0,S); 343var E=this._timeGeometry.toScreen(B); 344E=Math.floor(E)+0.5; 345var C=E; 346M.beginPath(); 347M.moveTo(E,0); 348M.lineTo(E,this._canvas.height); 349M.stroke(); 350var G=E-4; 351var I=7; 352}else{var S=N.toString(0.5); 353A.addColorStop(0,S); 354var E=this._timeGeometry.toScreen(B); 355E=Math.floor(E)+0.5; 356var C=this._timeGeometry.toScreen(R); 357C=Math.floor(C)+0.5; 358M.fillRect(E,0,C-E,this._canvas.height); 359var G=E; 360var I=C-E-1; 361}var J=this._timeplot.putDiv(P.getID(),"timeplot-event-box",{left:Math.round(G),width:Math.round(I),top:0,height:this._canvas.height-1}); 362var O=this; 363var H=function(T){return function(W,U,Z){var Y=O._timeplot.getDocument(); 364O._closeBubble(); 365var X=SimileAjax.DOM.getEventPageCoordinates(U); 366var V=SimileAjax.DOM.getPageCoordinates(W); 367O._bubble=SimileAjax.Graphics.createBubbleForPoint(X.x,V.top+O._canvas.height,O._plotInfo.bubbleWidth,O._plotInfo.bubbleHeight,"bottom"); 368T.fillInfoBubble(O._bubble.content,O._theme,O._timeGeometry.getLabeler()); 369}; 370}; 371var D=function(U,T,V){U.oldClass=U.className; 372U.className=U.className+" timeplot-event-box-highlight"; 373}; 374var L=function(U,T,V){U.className=U.oldClass; 375U.oldClass=null; 376}; 377if(!J.instrumented){SimileAjax.DOM.registerEvent(J,"click",H(P)); 378SimileAjax.DOM.registerEvent(J,"mouseover",D); 379SimileAjax.DOM.registerEvent(J,"mouseout",L); 380J.instrumented=true; 381}}}},_plot:function(F){var E=this._dataSource.getData(); 382if(E){var G=E.times; 383var B=E.values; 384var C=G.length; 385for(var D=0; 386D<C; 387D++){var A=this._timeGeometry.toScreen(G[D]); 388var H=this._valueGeometry.toScreen(B[D]); 389F(A,H); 390}}},_closeBubble:function(){if(this._bubble!=null){this._bubble.close(); 391this._bubble=null; 392}}}; 393 394 395/* sources.js */ 396Timeplot.DefaultEventSource=function(A){Timeline.DefaultEventSource.apply(this,arguments); 397}; 398Object.extend(Timeplot.DefaultEventSource.prototype,Timeline.DefaultEventSource.prototype); 399Timeplot.DefaultEventSource.prototype.loadText=function(M,I,A,C,K){if(M==null){return ; 400}this._events.maxValues=new Array(); 401var B=this._getBaseURL(A); 402if(!K){K="iso8601"; 403}var H=this._events.getUnit().getParser(K); 404var G=this._parseText(M,I); 405var J=false; 406if(C){G=C(G); 407}if(G){for(var F=0; 408F<G.length; 409F++){var N=G[F]; 410if(N.length>1){var E=SimileAjax.jQuery.trim(N[0]); 411var D=H(E); 412if(D){var L=new Timeplot.DefaultEventSource.NumericEvent(D,N.slice(1)); 413this._events.add(L); 414J=true; 415}}}}if(J){this._fire("onAddMany",[]); 416}}; 417Timeplot.DefaultEventSource.prototype._parseText=function(H,C){H=H.replace(/\r\n?/g,"\n"); 418var F=0; 419var E=H.length; 420var I=[]; 421while(F<E){var J=[]; 422if(H.charAt(F)!="#"){while(F<E){if(H.charAt(F)=='"'){var A=H.indexOf('"',F+1); 423while(A<E&&A>-1){if(H.charAt(A+1)!='"'){break; 424}A=H.indexOf('"',A+2); 425}if(A<0){}else{if(H.charAt(A+1)==C){var B=H.substr(F+1,A-F-1); 426B=B.replace(/""/g,'"'); 427J[J.length]=B; 428F=A+2; 429continue; 430}else{if(H.charAt(A+1)=="\n"||E==A+1){var B=H.substr(F+1,A-F-1); 431B=B.replace(/""/g,'"'); 432J[J.length]=B; 433F=A+2; 434break; 435}else{}}}}var G=H.indexOf(C,F); 436var D=H.indexOf("\n",F); 437if(D<0){D=E; 438}if(G>-1&&G<D){J[J.length]=H.substr(F,G-F); 439F=G+1; 440}else{J[J.length]=H.substr(F,D-F); 441F=D+1; 442break; 443}}}else{var D=H.indexOf("\n",F); 444F=(D>-1)?D+1:cur; 445}if(J.length>0){I[I.length]=J; 446}}if(I.length<0){return ; 447}return I; 448}; 449Timeplot.DefaultEventSource.prototype.getRange=function(){var A=this.getEarliestDate(); 450var B=this.getLatestDate(); 451return{earliestDate:(A)?A:null,latestDate:(B)?B:null,min:0,max:0}; 452}; 453Timeplot.DefaultEventSource.NumericEvent=function(B,A){this._id="e"+Math.round(Math.random()*1000000); 454this._time=B; 455this._values=A; 456}; 457Timeplot.DefaultEventSource.NumericEvent.prototype={getID:function(){return this._id; 458},getTime:function(){return this._time; 459},getValues:function(){return this._values; 460},getStart:function(){return this._time; 461},getEnd:function(){return this._time; 462}}; 463Timeplot.DataSource=function(B){this._eventSource=B; 464var A=this; 465this._processingListener={onAddMany:function(){A._process(); 466},onClear:function(){A._clear(); 467}}; 468this.addListener(this._processingListener); 469this._listeners=[]; 470this._data=null; 471this._range=null; 472}; 473Timeplot.DataSource.prototype={_clear:function(){this._data=null; 474this._range=null; 475},_process:function(){this._data={times:new Array(),values:new Array()}; 476this._range={earliestDate:null,latestDate:null,min:0,max:0}; 477},getRange:function(){return this._range; 478},getData:function(){return this._data; 479},getValue:function(C){if(this._data){for(var B=0; 480B<this._data.times.length; 481B++){var A=this._data.times[B]; 482if(A>=C){return this._data.values[B]; 483}}}return 0; 484},getClosestValidTime:function(B){if(this._data){for(var A=0; 485A<this._data.times.length; 486A++){var C=this._data.times[A]; 487if(C>=B){if(A<=0){return C; 488}else{var D=this._data.times[A-1]; 489if(B-D<C-B){return D; 490}else{return C; 491}}}}}return 0; 492},addListener:function(A){this._eventSource.addListener(A); 493},removeListener:function(A){this._eventSource.removeListener(A); 494},replaceListener:function(A,B){this.removeListener(A); 495this.addListener(B); 496}}; 497Timeplot.ColumnSource=function(B,A){Timeplot.DataSource.apply(this,arguments); 498this._column=A-1; 499}; 500Object.extend(Timeplot.ColumnSource.prototype,Timeplot.DataSource.prototype); 501Timeplot.ColumnSource.prototype.dispose=function(){this.removeListener(this._processingListener); 502this._clear(); 503}; 504Timeplot.ColumnSource.prototype._process=function(){var G=this._eventSource.getCount(); 505var A=new Array(G); 506var J=new Array(G); 507var D=Number.MAX_VALUE; 508var H=Number.MIN_VALUE; 509var E=0; 510var F=this._eventSource.getAllEventIterator(); 511while(F.hasNext()){var B=F.next(); 512var C=B.getTime(); 513A[E]=C; 514var I=this._getValue(B); 515if(!isNaN(I)){if(I<D){D=I; 516}if(I>H){H=I; 517}J[E]=I; 518}E++; 519}this._data={times:A,values:J}; 520if(H==Number.MIN_VALUE){H=1; 521}this._range={earliestDate:this._eventSource.getEarliestDate(),latestDate:this._eventSource.getLatestDate(),min:D,max:H}; 522}; 523Timeplot.ColumnSource.prototype._getValue=function(A){return parseFloat(A.getValues()[this._column]); 524}; 525Timeplot.ColumnDiffSource=function(C,B,A){Timeplot.ColumnSource.apply(this,arguments); 526this._column2=A-1; 527}; 528Object.extend(Timeplot.ColumnDiffSource.prototype,Timeplot.ColumnSource.prototype); 529Timeplot.ColumnDiffSource.prototype._getValue=function(C){var B=parseFloat(C.getValues()[this._column]); 530var A=parseFloat(C.getValues()[this._column2]); 531return B-A; 532}; 533 534 535/* geometry.js */ 536Timeplot.DefaultValueGeometry=function(A){if(!A){A={}; 537}this._id=("id" in A)?A.id:"g"+Math.round(Math.random()*1000000); 538this._axisColor=("axisColor" in A)?((typeof A.axisColor=="string")?new Timeplot.Color(A.axisColor):A.axisColor):new Timeplot.Color("#606060"),this._gridColor=("gridColor" in A)?((typeof A.gridColor=="string")?new Timeplot.Color(A.gridColor):A.gridColor):null,this._gridLineWidth=("gridLineWidth" in A)?A.gridLineWidth:0.5; 539this._axisLabelsPlacement=("axisLabelsPlacement" in A)?A.axisLabelsPlacement:"right"; 540this._gridSpacing=("gridSpacing" in A)?A.gridStep:50; 541this._gridType=("gridType" in A)?A.gridType:"short"; 542this._gridShortSize=("gridShortSize" in A)?A.gridShortSize:10; 543this._minValue=("min" in A)?A.min:null; 544this._maxValue=("max" in A)?A.max:null; 545this._linMap={direct:function(B){return B; 546},inverse:function(B){return B; 547}}; 548this._map=this._linMap; 549this._labels=[]; 550this._grid=[]; 551}; 552Timeplot.DefaultValueGeometry.prototype={setTimeplot:function(A){this._timeplot=A; 553this._canvas=A.getCanvas(); 554this.reset(); 555},setRange:function(A){if((this._minValue==null)||((this._minValue!=null)&&(A.min<this._minValue))){this._minValue=A.min; 556}if((this._maxValue==null)||((this._maxValue!=null)&&(A.max*1.05>this._maxValue))){this._maxValue=A.max*1.05; 557}this._updateMappedValues(); 558if(!(this._minValue==0&&this._maxValue==0)){this._grid=this._calculateGrid(); 559}},reset:function(){this._clearLabels(); 560this._updateMappedValues(); 561this._grid=this._calculateGrid(); 562},toScreen:function(B){if(this._canvas&&this._maxValue){var A=B-this._minValue; 563return this._canvas.height*(this._map.direct(A))/this._mappedRange; 564}else{return -50; 565}},fromScreen:function(A){if(this._canvas){return this._map.inverse(this._mappedRange*A/this._canvas.height)+this._minValue; 566}else{return 0; 567}},paint:function(){if(this._timeplot){var B=this._canvas.getContext("2d"); 568B.lineJoin="miter"; 569if(this._gridColor){var E=B.createLinearGradient(0,0,0,this._canvas.height); 570E.addColorStop(0,this._gridColor.toHexString()); 571E.addColorStop(0.3,this._gridColor.toHexString()); 572E.addColorStop(1,"rgba(255,255,255,0.5)"); 573B.lineWidth=this._gridLineWidth; 574B.strokeStyle=E; 575for(var D=0; 576D<this._grid.length; 577D++){var C=this._grid[D]; 578var G=Math.floor(C.y)+0.5; 579if(typeof C.label!="undefined"){if(this._axisLabelsPlacement=="left"){var F=this._timeplot.putText(this._id+"-"+D,C.label,"timeplot-grid-label",{left:4,bottom:G+2,color:this._gridColor.toHexString(),visibility:"hidden"}); 580this._labels.push(F); 581}else{if(this._axisLabelsPlacement=="right"){var F=this._timeplot.putText(this._id+"-"+D,C.label,"timeplot-grid-label",{right:4,bottom:G+2,color:this._gridColor.toHexString(),visibility:"hidden"}); 582this._labels.push(F); 583}}if(G+F.clientHeight<this._canvas.height+10){F.style.visibility="visible"; 584}}B.beginPath(); 585if(this._gridType=="long"||C.label==0){B.moveTo(0,G); 586B.lineTo(this._canvas.width,G); 587}else{if(this._gridType=="short"){if(this._axisLabelsPlacement=="left"){B.moveTo(0,G); 588B.lineTo(this._gridShortSize,G); 589}else{if(this._axisLabelsPlacement=="right"){B.moveTo(this._canvas.width,G); 590B.lineTo(this._canvas.width-this._gridShortSize,G); 591}}}}B.stroke(); 592}}var A=B.createLinearGradient(0,0,0,this._canvas.height); 593A.addColorStop(0,this._axisColor.toString()); 594A.addColorStop(0.5,this._axisColor.toString()); 595A.addColorStop(1,"rgba(255,255,255,0.5)"); 596B.lineWidth=1; 597B.strokeStyle=A; 598B.beginPath(); 599B.moveTo(0,this._canvas.height); 600B.lineTo(0,0); 601B.stroke(); 602B.beginPath(); 603B.moveTo(this._canvas.width,0); 604B.lineTo(this._canvas.width,this._canvas.height); 605B.stroke(); 606}},_clearLabels:function(){for(var B=0; 607B<this._labels.length; 608B++){var A=this._labels[B]; 609var C=A.parentNode; 610if(C){C.removeChild(A); 611}}},_calculateGrid:function(){var C=[]; 612if(!this._canvas||this._valueRange==0){return C; 613}var D=0; 614if(this._valueRange>1){while(Math.pow(10,D)<this._valueRange){D++; 615}D--; 616}else{while(Math.pow(10,D)>this._valueRange){D--; 617}}var E=Math.pow(10,D); 618var F=E; 619while(true){var A=this.toScreen(this._minValue+F); 620while(A<this._gridSpacing){F+=E; 621A=this.toScreen(this._minValue+F); 622}if(A>2*this._gridSpacing){E/=10; 623F=E; 624}else{break; 625}}var B=0; 626var G=this.toScreen(B); 627if(this._minValue>=0){while(G<this._canvas.height){if(G>0){C.push({y:G,label:B}); 628}B+=F; 629G=this.toScreen(B); 630}}else{if(this._maxValue<=0){while(G>0){if(G<this._canvas.height){C.push({y:G,label:B}); 631}B-=F; 632G=this.toScreen(B); 633}}else{while(G<this._canvas.height){if(G>0){C.push({y:G,label:B}); 634}B+=F; 635G=this.toScreen(B); 636}B=-F; 637G=this.toScreen(B); 638while(G>0){if(G<this._canvas.height){C.push({y:G,label:B}); 639}B-=F; 640G=this.toScreen(B); 641}}}return C; 642},_updateMappedValues:function(){this._valueRange=Math.abs(this._maxValue-this._minValue); 643this._mappedRange=this._map.direct(this._valueRange); 644}}; 645Timeplot.LogarithmicValueGeometry=function(A){Timeplot.DefaultValueGeometry.apply(this,arguments); 646this._logMap={direct:function(B){return Math.log(B+1)/Math.log(10); 647},inverse:function(B){return Math.exp(Math.log(10)*B)-1; 648}}; 649this._mode="log"; 650this._map=this._logMap; 651this._calculateGrid=this._logarithmicCalculateGrid; 652}; 653Timeplot.LogarithmicValueGeometry.prototype._linearCalculateGrid=Timeplot.DefaultValueGeometry.prototype._calculateGrid; 654Object.extend(Timeplot.LogarithmicValueGeometry.prototype,Timeplot.DefaultValueGeometry.prototype); 655Timeplot.LogarithmicValueGeometry.prototype._logarithmicCalculateGrid=function(){var B=[]; 656if(!this._canvas||this._valueRange==0){return B; 657}var A=1; 658var C=this.toScreen(A); 659while(C<this._canvas.height||isNaN(C)){if(C>0){B.push({y:C,label:A}); 660}A*=10; 661C=this.toScreen(A); 662}return B; 663}; 664Timeplot.LogarithmicValueGeometry.prototype.actLinear=function(){this._mode="lin"; 665this._map=this._linMap; 666this._calculateGrid=this._linearCalculateGrid; 667this.reset(); 668}; 669Timeplot.LogarithmicValueGeometry.prototype.actLogarithmic=function(){this._mode="log"; 670this._map=this._logMap; 671this._calculateGrid=this._logarithmicCalculateGrid; 672this.reset(); 673}; 674Timeplot.LogarithmicValueGeometry.prototype.toggle=function(){if(this._mode=="log"){this.actLinear(); 675}else{this.actLogarithmic(); 676}}; 677Timeplot.DefaultTimeGeometry=function(B){if(!B){B={}; 678}this._id=("id" in B)?B.id:"g"+Math.round(Math.random()*1000000); 679this._locale=("locale" in B)?B.locale:"en"; 680this._timeZone=("timeZone" in B)?B.timeZone:SimileAjax.DateTime.getTimezone(); 681this._labeler=("labeller" in B)?B.labeller:null; 682this._axisColor=("axisColor" in B)?((B.axisColor=="string")?new Timeplot.Color(B.axisColor):B.axisColor):new Timeplot.Color("#606060"),this._gridColor=("gridColor" in B)?((B.gridColor=="string")?new Timeplot.Color(B.gridColor):B.gridColor):null,this._gridLineWidth=("gridLineWidth" in B)?B.gridLineWidth:0.5; 683this._axisLabelsPlacement=("axisLabelsPlacement" in B)?B.axisLabelsPlacement:"bottom"; 684this._gridStep=("gridStep" in B)?B.gridStep:100; 685this._gridStepRange=("gridStepRange" in B)?B.gridStepRange:20; 686this._min=("min" in B)?B.min:null; 687this._max=("max" in B)?B.max:null; 688this._timeValuePosition=("timeValuePosition" in B)?B.timeValuePosition:"bottom"; 689this._unit=("unit" in B)?B.unit:SimileAjax.NativeDateUnit; 690this._linMap={direct:function(C){return C; 691},inverse:function(C){return C; 692}}; 693this._map=this._linMap; 694if(!this._labeler){this._labeler=(this._unit&&("createLabeller" in this._unit))?this._unit.createLabeller(this._locale,this._timeZone):new Timeline.GregorianDateLabeller(this._locale,this._timeZone); 695}var A=this._unit.getParser("iso8601"); 696if(this._min&&!this._min.getTime){this._min=A(this._min); 697}if(this._max&&!this._max.getTime){this._max=A(this._max); 698}this._labels=[]; 699this._grid=[]; 700}; 701Timeplot.DefaultTimeGeometry.prototype={setTimeplot:function(A){this._timeplot=A; 702this._canvas=A.getCanvas(); 703this.reset(); 704},setRange:function(A){if(this._min){this._earliestDate=this._min; 705}else{if(A.earliestDate&&((this._earliestDate==null)||((this._earliestDate!=null)&&(A.earliestDate.getTime()<this._earliestDate.getTime())))){this._earliestDate=A.earliestDate; 706}}if(this._max){this._latestDate=this._max; 707}else{if(A.latestDate&&((this._latestDate==null)||((this._latestDate!=null)&&(A.latestDate.getTime()>this._latestDate.getTime())))){this._latestDate=A.latestDate; 708}}if(!this._earliestDate&&!this._latestDate){this._grid=[]; 709}else{this.reset(); 710}},reset:function(){this._updateMappedValues(); 711if(this._canvas){this._grid=this._calculateGrid(); 712}},toScreen:function(C){if(this._canvas&&this._latestDate){var A=C-this._earliestDate.getTime(); 713var B=(this._mappedPeriod>0)?this._map.direct(A)/this._mappedPeriod:0; 714return this._canvas.width*B; 715}else{return -50; 716}},fromScreen:function(A){if(this._canvas){return this._map.inverse(this._mappedPeriod*A/this._canvas.width)+this._earliestDate.getTime(); 717}else{return 0; 718}},getPeriod:function(){return this._period; 719},getLabeler:function(){return this._labeler; 720},getUnit:function(){return this._unit; 721},paint:function(){if(this._canvas){var E=this._unit; 722var B=this._canvas.getContext("2d"); 723var F=B.createLinearGradient(0,0,0,this._canvas.height); 724B.strokeStyle=F; 725B.lineWidth=this._gridLineWidth; 726B.lineJoin="miter"; 727if(this._gridColor){F.addColorStop(0,this._gridColor.toString()); 728F.addColorStop(1,"rgba(255,255,255,0.9)"); 729for(var D=0; 730D<this._grid.length; 731D++){var C=this._grid[D]; 732var A=Math.floor(C.x)+0.5; 733if(this._axisLabelsPlacement=="top"){var G=this._timeplot.putText(this._id+"-"+D,C.label,"timeplot-grid-label",{left:A+4,top:2,visibility:"hidden"}); 734this._labels.push(G); 735}else{if(this._axisLabelsPlacement=="bottom"){var G=this._timeplot.putText(this._id+"-"+D,C.label,"timeplot-grid-label",{left:A+4,bottom:2,visibility:"hidden"}); 736this._labels.push(G); 737}}if(A+G.clientWidth<this._canvas.width+10){G.style.visibility="visible"; 738}B.beginPath(); 739B.moveTo(A,0); 740B.lineTo(A,this._canvas.height); 741B.stroke(); 742}}F.addColorStop(0,this._axisColor.toString()); 743F.addColorStop(1,"rgba(255,255,255,0.5)"); 744B.lineWidth=1; 745F.addColorStop(0,this._axisColor.toString()); 746B.beginPath(); 747B.moveTo(0,0); 748B.lineTo(this._canvas.width,0); 749B.stroke(); 750}},_calculateGrid:function(){var A=[]; 751var D=SimileAjax.DateTime; 752var H=this._unit; 753var B=this._period; 754if(B==0){return A; 755}if(B>D.gregorianUnitLengths[D.MILLENNIUM]){G=D.MILLENNIUM; 756}else{for(var G=D.MILLENNIUM; 757G>0; 758G--){if(D.gregorianUnitLengths[G-1]<=B&&B<D.gregorianUnitLengths[G]){G--; 759break; 760}}}var I=H.cloneValue(this._earliestDate); 761do{D.roundDownToInterval(I,G,this._timeZone,1,0); 762var F=this.toScreen(H.toNumber(I)); 763switch(G){case D.SECOND:var E=I.toLocaleTimeString(); 764break; 765case D.MINUTE:var C=I.getMinutes(); 766var E=I.getHours()+":"+((C<10)?"0":"")+C; 767break; 768case D.HOUR:var E=I.getHours()+":00"; 769break; 770case D.DAY:case D.WEEK:case D.MONTH:var E=I.toLocaleDateString(); 771break; 772case D.YEAR:case D.DECADE:case D.CENTURY:case D.MILLENNIUM:var E=I.getUTCFullYear(); 773break; 774}if(F>0){A.push({x:F,label:E}); 775}D.incrementByInterval(I,G,this._timeZone); 776}while(I.getTime()<this._latestDate.getTime()); 777return A; 778},_clearLabels:function(){for(var B=0; 779B<this._labels.length; 780B++){var A=this._labels[B]; 781var C=A.parentNode; 782if(C){C.removeChild(A); 783}}},_updateMappedValues:function(){if(this._latestDate&&this._earliestDate){this._period=this._latestDate.getTime()-this._earliestDate.getTime(); 784this._mappedPeriod=this._map.direct(this._period); 785}else{this._period=0; 786this._mappedPeriod=0; 787}}}; 788Timeplot.MagnifyingTimeGeometry=function(B){Timeplot.DefaultTimeGeometry.apply(this,arguments); 789var A=this; 790this._MagnifyingMap={direct:function(D){if(D<A._leftTimeMargin){var C=D*A._leftRate; 791}else{if(A._leftTimeMargin<D&&D<A._rightTimeMargin){var C=D*A._expandedRate+A._expandedTimeTranslation; 792}else{var C=D*A._rightRate+A._rightTimeTranslation; 793}}return C; 794},inverse:function(C){if(C<A._leftScreenMargin){var D=C/A._leftRate; 795}else{if(A._leftScreenMargin<C&&C<A._rightScreenMargin){var D=C/A._expandedRate+A._expandedScreenTranslation; 796}else{var D=C/A._rightRate+A._rightScreenTranslation; 797}}return D; 798}}; 799this._mode="lin"; 800this._map=this._linMap; 801}; 802Object.extend(Timeplot.MagnifyingTimeGeometry.prototype,Timeplot.DefaultTimeGeometry.prototype); 803Timeplot.MagnifyingTimeGeometry.prototype.initialize=function(F){Timeplot.DefaultTimeGeometry.prototype.initialize.apply(this,arguments); 804if(!this._lens){this._lens=this._timeplot.putDiv("lens","timeplot-lens"); 805}var G=1000*60*60*24*30; 806var H=this; 807var B=function(K){var M=K.clientWidth; 808var L=H._timeplot.locate(K); 809H.setMagnifyingParams(L.x+M/2,M,G); 810H.actMagnifying(); 811H._timeplot.paint(); 812}; 813var J=function(L,K,M){H._canvas.startCoords=SimileAjax.DOM.getEventRelativeCoordinates(K,L); 814H._canvas.pressed=true; 815}; 816var I=function(L,K,N){H._canvas.pressed=false; 817var M=SimileAjax.DOM.getEventRelativeCoordinates(K,L); 818if(Timeplot.Math.isClose(M,H._canvas.startCoords,5)){H._lens.style.display="none"; 819H.actLinear(); 820H._timeplot.paint(); 821}else{H._lens.style.cursor="move"; 822B(H._lens); 823}}; 824var D=function(L,K,N){if(H._canvas.pressed){var M=SimileAjax.DOM.getEventRelativeCoordinates(K,L); 825if(M.x<0){M.x=0; 826}if(M.x>H._canvas.width){M.x=H._canvas.width; 827}H._timeplot.placeDiv(H._lens,{left:H._canvas.startCoords.x,width:M.x-H._canvas.startCoords.x,bottom:0,height:H._canvas.height,display:"block"}); 828}}; 829var A=function(L,K,M){H._lens.startCoords=SimileAjax.DOM.getEventRelativeCoordinates(K,L); 830H._lens.pressed=true; 831}; 832var C=function(L,K,M){H._lens.pressed=false; 833}; 834var E=function(M,K,P){if(H._lens.pressed){var N=SimileAjax.DOM.getEventRelativeCoordinates(K,M); 835var L=H._lens; 836var O=L.offsetLeft+N.x-L.startCoords.x; 837if(O<H._timeplot._paddingX){O=H._timeplot._paddingX; 838}if(O+L.clientWidth>H._canvas.width-H._timeplot._paddingX){O=H._canvas.width-L.clientWidth+H._timeplot._paddingX; 839}L.style.left=O; 840B(L); 841}}; 842if(!this._canvas.instrumented){SimileAjax.DOM.registerEvent(this._canvas,"mousedown",J); 843SimileAjax.DOM.registerEvent(this._canvas,"mousemove",D); 844SimileAjax.DOM.registerEvent(this._canvas,"mouseup",I); 845SimileAjax.DOM.registerEvent(this._canvas,"mouseup",C); 846this._canvas.instrumented=true; 847}if(!this._lens.instrumented){SimileAjax.DOM.registerEvent(this._lens,"mousedown",A); 848SimileAjax.DOM.registerEvent(this._lens,"mousemove",E); 849SimileAjax.DOM.registerEvent(this._lens,"mouseup",C); 850SimileAjax.DOM.registerEvent(this._lens,"mouseup",I); 851this._lens.instrumented=true; 852}}; 853Timeplot.MagnifyingTimeGeometry.prototype.setMagnifyingParams=function(F,C,A){C=C/2; 854A=A/2; 855var B=this._canvas.width; 856var E=this._period; 857if(F<0){F=0; 858}if(F>B){F=B; 859}if(F-C<0){C=F; 860}if(F+C>B){C=B-F; 861}var D=this.fromScreen(F)-this._earliestDate.getTime(); 862if(D-A<0){A=D; 863}if(D+A>E){A=E-D; 864}this._centerX=F; 865this._centerTime=D; 866this._aperture=C; 867this._aperturePeriod=A; 868this._leftScreenMargin=this._centerX-this._aperture; 869this._rightScreenMargin=this._centerX+this._aperture; 870this._leftTimeMargin=this._centerTime-this._aperturePeriod; 871this._rightTimeMargin=this._centerTime+this._aperturePeriod; 872this._leftRate=(F-C)/(D-A); 873this._expandedRate=C/A; 874this._rightRate=(B-F-C)/(E-D-A); 875this._expandedTimeTranslation=this._centerX-this._centerTime*this._expandedRate; 876this._expandedScreenTranslation=this._centerTime-this._centerX/this._expandedRate; 877this._rightTimeTranslation=(F+C)-(D+A)*this._rightRate; 878this._rightScreenTranslation=(D+A)-(F+C)/this._rightRate; 879this._updateMappedValues(); 880}; 881Timeplot.MagnifyingTimeGeometry.prototype.actLinear=function(){this._mode="lin"; 882this._map=this._linMap; 883this.reset(); 884}; 885Timeplot.MagnifyingTimeGeometry.prototype.actMagnifying=function(){this._mode="Magnifying"; 886this._map=this._MagnifyingMap; 887this.reset(); 888}; 889Timeplot.MagnifyingTimeGeometry.prototype.toggle=function(){if(this._mode=="Magnifying"){this.actLinear(); 890}else{this.actMagnifying(); 891}}; 892 893 894/* color.js */ 895Timeplot.Color=function(A){this._fromHex(A); 896}; 897Timeplot.Color.prototype={set:function(D,C,A,B){this.r=D; 898this.g=C; 899this.b=A; 900this.a=(B)?B:1; 901return this.check(); 902},transparency:function(A){this.a=A; 903return this.check(); 904},lighten:function(B){var A=new Timeplot.Color(); 905return A.set(this.r+=parseInt(B,10),this.g+=parseInt(B,10),this.b+=parseInt(B,10)); 906},darken:function(B){var A=new Timeplot.Color(); 907return A.set(this.r-=parseInt(B,10),this.g-=parseInt(B,10),this.b-=parseInt(B,10)); 908},check:function(){if(this.r>255){this.r=255; 909}else{if(this.r<0){this.r=0; 910}}if(this.g>255){this.g=255; 911}else{if(this.g<0){this.g=0; 912}}if(this.b>255){this.b=255; 913}else{if(this.b<0){this.b=0; 914}}if(this.a>1){this.a=1; 915}else{if(this.a<0){this.a=0; 916}}return this; 917},toString:function(B){var A=(B)?B:((this.a)?this.a:1); 918return"rgba("+this.r+","+this.g+","+this.b+","+A+")"; 919},toHexString:function(){return"#"+this._toHex(this.r)+this._toHex(this.g)+this._toHex(this.b); 920},_fromHex:function(A){if(/^#?([\da-f]{3}|[\da-f]{6})$/i.test(A)){A=A.replace(/^#/,"").replace(/^([\da-f])([\da-f])([\da-f])$/i,"$1$1$2$2$3$3"); 921this.r=parseInt(A.substr(0,2),16); 922this.g=parseInt(A.substr(2,2),16); 923this.b=parseInt(A.substr(4,2),16); 924}else{if(/^rgb *\( *\d{0,3} *, *\d{0,3} *, *\d{0,3} *\)$/i.test(A)){A=A.match(/^rgb *\( *(\d{0,3}) *, *(\d{0,3}) *, *(\d{0,3}) *\)$/i); 925this.r=parseInt(A[1],10); 926this.g=parseInt(A[2],10); 927this.b=parseInt(A[3],10); 928}}this.a=1; 929return this.check(); 930},_toHex:function(D){var C="0123456789ABCDEF"; 931if(D<0){return"00"; 932}if(D>255){return"FF"; 933}var B=Math.floor(D/16); 934var A=D%16; 935return C.charAt(B)+C.charAt(A); 936}}; 937 938 939/* math.js */ 940Timeplot.Math={range:function(G){var D=G.length; 941var C=Number.MAX_VALUE; 942var A=Number.MIN_VALUE; 943for(var B=0; 944B<D; 945B++){var E=G[B]; 946if(E<C){C=E; 947}if(E>A){A=E; 948}}return{min:C,max:A}; 949},movingAverage:function(H,C){var E=H.length; 950var D=new Array(E); 951for(var I=0; 952I<E; 953I++){var G=0; 954for(var A=I-C; 955A<I+C; 956A++){if(A<0){var B=H[0]; 957}else{if(A>=E){var B=D[I-1]; 958}else{var B=H[A]; 959}}G+=B; 960}D[I]=G/(2*C); 961}return D; 962},integral:function(E){var D=E.length; 963var C=new Array(D); 964var B=0; 965for(var A=0; 966A<D; 967A++){B+=E[A]; 968C[A]=B; 969}return C; 970},normalize:function(D){var C=D.length; 971var B=0; 972for(var A=0; 973A<C; 974A++){B+=D[A]; 975}for(var A=0; 976A<C; 977A++){D[A]/=B; 978}return D; 979},convolution:function(H,E){var M=H.length; 980var L=E.length; 981var I=new Array(M); 982for(var C=0; 983C<M; 984C++){var A=0; 985var D=(C+L<M)?C+L:M; 986for(var B=C; 987B<D; 988B++){var K=H[B-L]; 989var J=E[B-C]; 990A+=K*J; 991}I[C]=A; 992}return I; 993},heavyside:function(B){var D=new Array(B); 994var C=1/B; 995for(var A=0; 996A<B; 997A++){D[A]=C; 998}return D; 999},gaussian:function(size,threshold){with(Math){var radius=size/2; 1000var variance=radius*radius/log(threshold); 1001var g=new Array(size); 1002for(var t=0; 1003t<size; 1004t++){var l=t-radius; 1005g[t]=exp(-variance*l*l); 1006}}return this.normalize(g); 1007},round:function(x,n){with(Math){if(abs(x)>1){var l=floor(log(x)/log(10)); 1008var d=round(exp((l-n+1)*log(10))); 1009var y=round(round(x/d)*d); 1010return y; 1011}else{log("FIXME(SM): still to implement for 0 < abs(x) < 1"); 1012return x; 1013}}},tanh:function(A){if(A>5){return 1; 1014}else{if(A<5){return -1; 1015}else{var B=Math.exp(2*A); 1016return(B-1)/(B+1); 1017}}},isClose:function(B,A,C){return(B&&A&&Math.abs(B.x-A.x)<C&&Math.abs(B.y-A.y)<C); 1018}}; 1019 1020 1021/* processor.js */ 1022Timeplot.Operator={sum:function(A,B){return Timeplot.Math.integral(A.values); 1023},average:function(C,D){var B=("size" in D)?D.size:30; 1024var A=Timeplot.Math.movingAverage(C.values,B); 1025return A; 1026}}; 1027Timeplot.Processor=function(D,A,C){this._dataSource=D; 1028this._operator=A; 1029this._params=C; 1030this._data={times:new Array(),values:new Array()}; 1031this._range={earliestDate:null,latestDate:null,min:0,max:0}; 1032var B=this; 1033this._processingListener={onAddMany:function(){B._process(); 1034},onClear:function(){B._clear(); 1035}}; 1036this.addListener(this._processingListener); 1037}; 1038Timeplot.Processor.prototype={_clear:function(){this.removeListener(this._processingListener); 1039this._dataSource._clear(); 1040},_process:function(){var D=this._dataSource.getData(); 1041var A=this._dataSource.getRange(); 1042var B=this._operator(D,this._params); 1043var C=Timeplot.Math.range(B); 1044this._data={times:D.times,values:B}; 1045this._range={earliestDate:A.earliestDate,latestDate:A.latestDate,min:C.min,max:C.max}; 1046},getRange:function(){return this._range; 1047},getData:function(){return this._data; 1048},getValue:Timeplot.DataSource.prototype.getValue,getClosestValidTime:Timeplot.DataSource.prototype.getClosestValidTime,addListener:function(A){this._dataSource.addListener(A); 1049},removeListener:function(A){this._dataSource.removeListener(A); 1050}};