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