PageRenderTime 415ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/timeplot/timeplot-bundle.js

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