Commit | Line | Data |
---|---|---|
6a1aa64f DV |
1 | /*** |
2 | ||
3 | MochiKit.MochiKit 1.4 : PACKED VERSION | |
4 | ||
5 | THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please | |
6 | diff against the source tree, not this file. | |
7 | ||
8 | See <http://mochikit.com/> for documentation, downloads, license, etc. | |
9 | ||
10 | (c) 2005 Bob Ippolito. All rights Reserved. | |
11 | ||
12 | ***/ | |
13 | ||
14 | if(typeof (dojo)!="undefined"){ | |
15 | dojo.provide("MochiKit.Base"); | |
16 | } | |
17 | if(typeof (MochiKit)=="undefined"){ | |
18 | MochiKit={}; | |
19 | } | |
20 | if(typeof (MochiKit.Base)=="undefined"){ | |
21 | MochiKit.Base={}; | |
22 | } | |
23 | if(typeof (MochiKit.__export__)=="undefined"){ | |
24 | MochiKit.__export__=(MochiKit.__compat__||(typeof (JSAN)=="undefined"&&typeof (dojo)=="undefined")); | |
25 | } | |
26 | MochiKit.Base.VERSION="1.4"; | |
27 | MochiKit.Base.NAME="MochiKit.Base"; | |
28 | MochiKit.Base.update=function(_1,_2){ | |
29 | if(_1===null){ | |
30 | _1={}; | |
31 | } | |
32 | for(var i=1;i<arguments.length;i++){ | |
33 | var o=arguments[i]; | |
34 | if(typeof (o)!="undefined"&&o!==null){ | |
35 | for(var k in o){ | |
36 | _1[k]=o[k]; | |
37 | } | |
38 | } | |
39 | } | |
40 | return _1; | |
41 | }; | |
42 | MochiKit.Base.update(MochiKit.Base,{__repr__:function(){ | |
43 | return "["+this.NAME+" "+this.VERSION+"]"; | |
44 | },toString:function(){ | |
45 | return this.__repr__(); | |
46 | },camelize:function(_6){ | |
47 | var _7=_6.split("-"); | |
48 | var cc=_7[0]; | |
49 | for(var i=1;i<_7.length;i++){ | |
50 | cc+=_7[i].charAt(0).toUpperCase()+_7[i].substring(1); | |
51 | } | |
52 | return cc; | |
53 | },counter:function(n){ | |
54 | if(arguments.length===0){ | |
55 | n=1; | |
56 | } | |
57 | return function(){ | |
58 | return n++; | |
59 | }; | |
60 | },clone:function(_b){ | |
61 | var me=arguments.callee; | |
62 | if(arguments.length==1){ | |
63 | me.prototype=_b; | |
64 | return new me(); | |
65 | } | |
66 | },_flattenArray:function(_d,_e){ | |
67 | for(var i=0;i<_e.length;i++){ | |
68 | var o=_e[i]; | |
69 | if(o instanceof Array){ | |
70 | arguments.callee(_d,o); | |
71 | }else{ | |
72 | _d.push(o); | |
73 | } | |
74 | } | |
75 | return _d; | |
76 | },flattenArray:function(lst){ | |
77 | return MochiKit.Base._flattenArray([],lst); | |
78 | },flattenArguments:function(lst){ | |
79 | var res=[]; | |
80 | var m=MochiKit.Base; | |
81 | var _15=m.extend(null,arguments); | |
82 | while(_15.length){ | |
83 | var o=_15.shift(); | |
84 | if(o&&typeof (o)=="object"&&typeof (o.length)=="number"){ | |
85 | for(var i=o.length-1;i>=0;i--){ | |
86 | _15.unshift(o[i]); | |
87 | } | |
88 | }else{ | |
89 | res.push(o); | |
90 | } | |
91 | } | |
92 | return res; | |
93 | },extend:function(_18,obj,_1a){ | |
94 | if(!_1a){ | |
95 | _1a=0; | |
96 | } | |
97 | if(obj){ | |
98 | var l=obj.length; | |
99 | if(typeof (l)!="number"){ | |
100 | if(typeof (MochiKit.Iter)!="undefined"){ | |
101 | obj=MochiKit.Iter.list(obj); | |
102 | l=obj.length; | |
103 | }else{ | |
104 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
105 | } | |
106 | } | |
107 | if(!_18){ | |
108 | _18=[]; | |
109 | } | |
110 | for(var i=_1a;i<l;i++){ | |
111 | _18.push(obj[i]); | |
112 | } | |
113 | } | |
114 | return _18; | |
115 | },updatetree:function(_1d,obj){ | |
116 | if(_1d===null){ | |
117 | _1d={}; | |
118 | } | |
119 | for(var i=1;i<arguments.length;i++){ | |
120 | var o=arguments[i]; | |
121 | if(typeof (o)!="undefined"&&o!==null){ | |
122 | for(var k in o){ | |
123 | var v=o[k]; | |
124 | if(typeof (_1d[k])=="object"&&typeof (v)=="object"){ | |
125 | arguments.callee(_1d[k],v); | |
126 | }else{ | |
127 | _1d[k]=v; | |
128 | } | |
129 | } | |
130 | } | |
131 | } | |
132 | return _1d; | |
133 | },setdefault:function(_23,obj){ | |
134 | if(_23===null){ | |
135 | _23={}; | |
136 | } | |
137 | for(var i=1;i<arguments.length;i++){ | |
138 | var o=arguments[i]; | |
139 | for(var k in o){ | |
140 | if(!(k in _23)){ | |
141 | _23[k]=o[k]; | |
142 | } | |
143 | } | |
144 | } | |
145 | return _23; | |
146 | },keys:function(obj){ | |
147 | var _29=[]; | |
148 | for(var _2a in obj){ | |
149 | _29.push(_2a); | |
150 | } | |
151 | return _29; | |
152 | },values:function(obj){ | |
153 | var _2c=[]; | |
154 | for(var _2d in obj){ | |
155 | _2c.push(obj[_2d]); | |
156 | } | |
157 | return _2c; | |
158 | },items:function(obj){ | |
159 | var _2f=[]; | |
160 | var e; | |
161 | for(var _31 in obj){ | |
162 | var v; | |
163 | try{ | |
164 | v=obj[_31]; | |
165 | } | |
166 | catch(e){ | |
167 | continue; | |
168 | } | |
169 | _2f.push([_31,v]); | |
170 | } | |
171 | return _2f; | |
172 | },_newNamedError:function(_33,_34,_35){ | |
173 | _35.prototype=new MochiKit.Base.NamedError(_33.NAME+"."+_34); | |
174 | _33[_34]=_35; | |
175 | },operator:{truth:function(a){ | |
176 | return !!a; | |
177 | },lognot:function(a){ | |
178 | return !a; | |
179 | },identity:function(a){ | |
180 | return a; | |
181 | },not:function(a){ | |
182 | return ~a; | |
183 | },neg:function(a){ | |
184 | return -a; | |
185 | },add:function(a,b){ | |
186 | return a+b; | |
187 | },sub:function(a,b){ | |
188 | return a-b; | |
189 | },div:function(a,b){ | |
190 | return a/b; | |
191 | },mod:function(a,b){ | |
192 | return a%b; | |
193 | },mul:function(a,b){ | |
194 | return a*b; | |
195 | },and:function(a,b){ | |
196 | return a&b; | |
197 | },or:function(a,b){ | |
198 | return a|b; | |
199 | },xor:function(a,b){ | |
200 | return a^b; | |
201 | },lshift:function(a,b){ | |
202 | return a<<b; | |
203 | },rshift:function(a,b){ | |
204 | return a>>b; | |
205 | },zrshift:function(a,b){ | |
206 | return a>>>b; | |
207 | },eq:function(a,b){ | |
208 | return a==b; | |
209 | },ne:function(a,b){ | |
210 | return a!=b; | |
211 | },gt:function(a,b){ | |
212 | return a>b; | |
213 | },ge:function(a,b){ | |
214 | return a>=b; | |
215 | },lt:function(a,b){ | |
216 | return a<b; | |
217 | },le:function(a,b){ | |
218 | return a<=b; | |
219 | },seq:function(a,b){ | |
220 | return a===b; | |
221 | },sne:function(a,b){ | |
222 | return a!==b; | |
223 | },ceq:function(a,b){ | |
224 | return MochiKit.Base.compare(a,b)===0; | |
225 | },cne:function(a,b){ | |
226 | return MochiKit.Base.compare(a,b)!==0; | |
227 | },cgt:function(a,b){ | |
228 | return MochiKit.Base.compare(a,b)==1; | |
229 | },cge:function(a,b){ | |
230 | return MochiKit.Base.compare(a,b)!=-1; | |
231 | },clt:function(a,b){ | |
232 | return MochiKit.Base.compare(a,b)==-1; | |
233 | },cle:function(a,b){ | |
234 | return MochiKit.Base.compare(a,b)!=1; | |
235 | },logand:function(a,b){ | |
236 | return a&&b; | |
237 | },logor:function(a,b){ | |
238 | return a||b; | |
239 | },contains:function(a,b){ | |
240 | return b in a; | |
241 | }},forwardCall:function(_73){ | |
242 | return function(){ | |
243 | return this[_73].apply(this,arguments); | |
244 | }; | |
245 | },itemgetter:function(_74){ | |
246 | return function(arg){ | |
247 | return arg[_74]; | |
248 | }; | |
249 | },typeMatcher:function(){ | |
250 | var _76={}; | |
251 | for(var i=0;i<arguments.length;i++){ | |
252 | var typ=arguments[i]; | |
253 | _76[typ]=typ; | |
254 | } | |
255 | return function(){ | |
256 | for(var i=0;i<arguments.length;i++){ | |
257 | if(!(typeof (arguments[i]) in _76)){ | |
258 | return false; | |
259 | } | |
260 | } | |
261 | return true; | |
262 | }; | |
263 | },isNull:function(){ | |
264 | for(var i=0;i<arguments.length;i++){ | |
265 | if(arguments[i]!==null){ | |
266 | return false; | |
267 | } | |
268 | } | |
269 | return true; | |
270 | },isUndefinedOrNull:function(){ | |
271 | for(var i=0;i<arguments.length;i++){ | |
272 | var o=arguments[i]; | |
273 | if(!(typeof (o)=="undefined"||o===null)){ | |
274 | return false; | |
275 | } | |
276 | } | |
277 | return true; | |
278 | },isEmpty:function(obj){ | |
279 | return !MochiKit.Base.isNotEmpty.apply(this,arguments); | |
280 | },isNotEmpty:function(obj){ | |
281 | for(var i=0;i<arguments.length;i++){ | |
282 | var o=arguments[i]; | |
283 | if(!(o&&o.length)){ | |
284 | return false; | |
285 | } | |
286 | } | |
287 | return true; | |
288 | },isArrayLike:function(){ | |
289 | for(var i=0;i<arguments.length;i++){ | |
290 | var o=arguments[i]; | |
291 | var typ=typeof (o); | |
292 | if((typ!="object"&&!(typ=="function"&&typeof (o.item)=="function"))||o===null||typeof (o.length)!="number"||o.nodeType===3){ | |
293 | return false; | |
294 | } | |
295 | } | |
296 | return true; | |
297 | },isDateLike:function(){ | |
298 | for(var i=0;i<arguments.length;i++){ | |
299 | var o=arguments[i]; | |
300 | if(typeof (o)!="object"||o===null||typeof (o.getTime)!="function"){ | |
301 | return false; | |
302 | } | |
303 | } | |
304 | return true; | |
305 | },xmap:function(fn){ | |
306 | if(fn===null){ | |
307 | return MochiKit.Base.extend(null,arguments,1); | |
308 | } | |
309 | var _87=[]; | |
310 | for(var i=1;i<arguments.length;i++){ | |
311 | _87.push(fn(arguments[i])); | |
312 | } | |
313 | return _87; | |
314 | },map:function(fn,lst){ | |
315 | var m=MochiKit.Base; | |
316 | var itr=MochiKit.Iter; | |
317 | var _8d=m.isArrayLike; | |
318 | if(arguments.length<=2){ | |
319 | if(!_8d(lst)){ | |
320 | if(itr){ | |
321 | lst=itr.list(lst); | |
322 | if(fn===null){ | |
323 | return lst; | |
324 | } | |
325 | }else{ | |
326 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
327 | } | |
328 | } | |
329 | if(fn===null){ | |
330 | return m.extend(null,lst); | |
331 | } | |
332 | var _8e=[]; | |
333 | for(var i=0;i<lst.length;i++){ | |
334 | _8e.push(fn(lst[i])); | |
335 | } | |
336 | return _8e; | |
337 | }else{ | |
338 | if(fn===null){ | |
339 | fn=Array; | |
340 | } | |
341 | var _90=null; | |
342 | for(i=1;i<arguments.length;i++){ | |
343 | if(!_8d(arguments[i])){ | |
344 | if(itr){ | |
345 | return itr.list(itr.imap.apply(null,arguments)); | |
346 | }else{ | |
347 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
348 | } | |
349 | } | |
350 | var l=arguments[i].length; | |
351 | if(_90===null||_90>l){ | |
352 | _90=l; | |
353 | } | |
354 | } | |
355 | _8e=[]; | |
356 | for(i=0;i<_90;i++){ | |
357 | var _92=[]; | |
358 | for(var j=1;j<arguments.length;j++){ | |
359 | _92.push(arguments[j][i]); | |
360 | } | |
361 | _8e.push(fn.apply(this,_92)); | |
362 | } | |
363 | return _8e; | |
364 | } | |
365 | },xfilter:function(fn){ | |
366 | var _95=[]; | |
367 | if(fn===null){ | |
368 | fn=MochiKit.Base.operator.truth; | |
369 | } | |
370 | for(var i=1;i<arguments.length;i++){ | |
371 | var o=arguments[i]; | |
372 | if(fn(o)){ | |
373 | _95.push(o); | |
374 | } | |
375 | } | |
376 | return _95; | |
377 | },filter:function(fn,lst,_9a){ | |
378 | var _9b=[]; | |
379 | var m=MochiKit.Base; | |
380 | if(!m.isArrayLike(lst)){ | |
381 | if(MochiKit.Iter){ | |
382 | lst=MochiKit.Iter.list(lst); | |
383 | }else{ | |
384 | throw new TypeError("Argument not an array-like and MochiKit.Iter not present"); | |
385 | } | |
386 | } | |
387 | if(fn===null){ | |
388 | fn=m.operator.truth; | |
389 | } | |
390 | if(typeof (Array.prototype.filter)=="function"){ | |
391 | return Array.prototype.filter.call(lst,fn,_9a); | |
392 | }else{ | |
393 | if(typeof (_9a)=="undefined"||_9a===null){ | |
394 | for(var i=0;i<lst.length;i++){ | |
395 | var o=lst[i]; | |
396 | if(fn(o)){ | |
397 | _9b.push(o); | |
398 | } | |
399 | } | |
400 | }else{ | |
401 | for(i=0;i<lst.length;i++){ | |
402 | o=lst[i]; | |
403 | if(fn.call(_9a,o)){ | |
404 | _9b.push(o); | |
405 | } | |
406 | } | |
407 | } | |
408 | } | |
409 | return _9b; | |
410 | },_wrapDumbFunction:function(_9f){ | |
411 | return function(){ | |
412 | switch(arguments.length){ | |
413 | case 0: | |
414 | return _9f(); | |
415 | case 1: | |
416 | return _9f(arguments[0]); | |
417 | case 2: | |
418 | return _9f(arguments[0],arguments[1]); | |
419 | case 3: | |
420 | return _9f(arguments[0],arguments[1],arguments[2]); | |
421 | } | |
422 | var _a0=[]; | |
423 | for(var i=0;i<arguments.length;i++){ | |
424 | _a0.push("arguments["+i+"]"); | |
425 | } | |
426 | return eval("(func("+_a0.join(",")+"))"); | |
427 | }; | |
428 | },methodcaller:function(_a2){ | |
429 | var _a3=MochiKit.Base.extend(null,arguments,1); | |
430 | if(typeof (_a2)=="function"){ | |
431 | return function(obj){ | |
432 | return _a2.apply(obj,_a3); | |
433 | }; | |
434 | }else{ | |
435 | return function(obj){ | |
436 | return obj[_a2].apply(obj,_a3); | |
437 | }; | |
438 | } | |
439 | },method:function(_a6,_a7){ | |
440 | var m=MochiKit.Base; | |
441 | return m.bind.apply(this,m.extend([_a7,_a6],arguments,2)); | |
442 | },compose:function(f1,f2){ | |
443 | var _ab=[]; | |
444 | var m=MochiKit.Base; | |
445 | if(arguments.length===0){ | |
446 | throw new TypeError("compose() requires at least one argument"); | |
447 | } | |
448 | for(var i=0;i<arguments.length;i++){ | |
449 | var fn=arguments[i]; | |
450 | if(typeof (fn)!="function"){ | |
451 | throw new TypeError(m.repr(fn)+" is not a function"); | |
452 | } | |
453 | _ab.push(fn); | |
454 | } | |
455 | return function(){ | |
456 | var _af=arguments; | |
457 | for(var i=_ab.length-1;i>=0;i--){ | |
458 | _af=[_ab[i].apply(this,_af)]; | |
459 | } | |
460 | return _af[0]; | |
461 | }; | |
462 | },bind:function(_b1,_b2){ | |
463 | if(typeof (_b1)=="string"){ | |
464 | _b1=_b2[_b1]; | |
465 | } | |
466 | var _b3=_b1.im_func; | |
467 | var _b4=_b1.im_preargs; | |
468 | var _b5=_b1.im_self; | |
469 | var m=MochiKit.Base; | |
470 | if(typeof (_b1)=="function"&&typeof (_b1.apply)=="undefined"){ | |
471 | _b1=m._wrapDumbFunction(_b1); | |
472 | } | |
473 | if(typeof (_b3)!="function"){ | |
474 | _b3=_b1; | |
475 | } | |
476 | if(typeof (_b2)!="undefined"){ | |
477 | _b5=_b2; | |
478 | } | |
479 | if(typeof (_b4)=="undefined"){ | |
480 | _b4=[]; | |
481 | }else{ | |
482 | _b4=_b4.slice(); | |
483 | } | |
484 | m.extend(_b4,arguments,2); | |
485 | var _b7=function(){ | |
486 | var _b8=arguments; | |
487 | var me=arguments.callee; | |
488 | if(me.im_preargs.length>0){ | |
489 | _b8=m.concat(me.im_preargs,_b8); | |
490 | } | |
491 | var _ba=me.im_self; | |
492 | if(!_ba){ | |
493 | _ba=this; | |
494 | } | |
495 | return me.im_func.apply(_ba,_b8); | |
496 | }; | |
497 | _b7.im_self=_b5; | |
498 | _b7.im_func=_b3; | |
499 | _b7.im_preargs=_b4; | |
500 | return _b7; | |
501 | },bindMethods:function(_bb){ | |
502 | var _bc=MochiKit.Base.bind; | |
503 | for(var k in _bb){ | |
504 | var _be=_bb[k]; | |
505 | if(typeof (_be)=="function"){ | |
506 | _bb[k]=_bc(_be,_bb); | |
507 | } | |
508 | } | |
509 | },registerComparator:function(_bf,_c0,_c1,_c2){ | |
510 | MochiKit.Base.comparatorRegistry.register(_bf,_c0,_c1,_c2); | |
511 | },_primitives:{"boolean":true,"string":true,"number":true},compare:function(a,b){ | |
512 | if(a==b){ | |
513 | return 0; | |
514 | } | |
515 | var _c5=(typeof (a)=="undefined"||a===null); | |
516 | var _c6=(typeof (b)=="undefined"||b===null); | |
517 | if(_c5&&_c6){ | |
518 | return 0; | |
519 | }else{ | |
520 | if(_c5){ | |
521 | return -1; | |
522 | }else{ | |
523 | if(_c6){ | |
524 | return 1; | |
525 | } | |
526 | } | |
527 | } | |
528 | var m=MochiKit.Base; | |
529 | var _c8=m._primitives; | |
530 | if(!(typeof (a) in _c8&&typeof (b) in _c8)){ | |
531 | try{ | |
532 | return m.comparatorRegistry.match(a,b); | |
533 | } | |
534 | catch(e){ | |
535 | if(e!=m.NotFound){ | |
536 | throw e; | |
537 | } | |
538 | } | |
539 | } | |
540 | if(a<b){ | |
541 | return -1; | |
542 | }else{ | |
543 | if(a>b){ | |
544 | return 1; | |
545 | } | |
546 | } | |
547 | var _c9=m.repr; | |
548 | throw new TypeError(_c9(a)+" and "+_c9(b)+" can not be compared"); | |
549 | },compareDateLike:function(a,b){ | |
550 | return MochiKit.Base.compare(a.getTime(),b.getTime()); | |
551 | },compareArrayLike:function(a,b){ | |
552 | var _ce=MochiKit.Base.compare; | |
553 | var _cf=a.length; | |
554 | var _d0=0; | |
555 | if(_cf>b.length){ | |
556 | _d0=1; | |
557 | _cf=b.length; | |
558 | }else{ | |
559 | if(_cf<b.length){ | |
560 | _d0=-1; | |
561 | } | |
562 | } | |
563 | for(var i=0;i<_cf;i++){ | |
564 | var cmp=_ce(a[i],b[i]); | |
565 | if(cmp){ | |
566 | return cmp; | |
567 | } | |
568 | } | |
569 | return _d0; | |
570 | },registerRepr:function(_d3,_d4,_d5,_d6){ | |
571 | MochiKit.Base.reprRegistry.register(_d3,_d4,_d5,_d6); | |
572 | },repr:function(o){ | |
573 | if(typeof (o)=="undefined"){ | |
574 | return "undefined"; | |
575 | }else{ | |
576 | if(o===null){ | |
577 | return "null"; | |
578 | } | |
579 | } | |
580 | try{ | |
581 | if(typeof (o.__repr__)=="function"){ | |
582 | return o.__repr__(); | |
583 | }else{ | |
584 | if(typeof (o.repr)=="function"&&o.repr!=arguments.callee){ | |
585 | return o.repr(); | |
586 | } | |
587 | } | |
588 | return MochiKit.Base.reprRegistry.match(o); | |
589 | } | |
590 | catch(e){ | |
591 | if(typeof (o.NAME)=="string"&&(o.toString==Function.prototype.toString||o.toString==Object.prototype.toString)){ | |
592 | return o.NAME; | |
593 | } | |
594 | } | |
595 | try{ | |
596 | var _d8=(o+""); | |
597 | } | |
598 | catch(e){ | |
599 | return "["+typeof (o)+"]"; | |
600 | } | |
601 | if(typeof (o)=="function"){ | |
602 | o=_d8.replace(/^\s+/,""); | |
603 | var idx=o.indexOf("{"); | |
604 | if(idx!=-1){ | |
605 | o=o.substr(0,idx)+"{...}"; | |
606 | } | |
607 | } | |
608 | return _d8; | |
609 | },reprArrayLike:function(o){ | |
610 | var m=MochiKit.Base; | |
611 | return "["+m.map(m.repr,o).join(", ")+"]"; | |
612 | },reprString:function(o){ | |
613 | return ("\""+o.replace(/(["\\])/g,"\\$1")+"\"").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r"); | |
614 | },reprNumber:function(o){ | |
615 | return o+""; | |
616 | },registerJSON:function(_de,_df,_e0,_e1){ | |
617 | MochiKit.Base.jsonRegistry.register(_de,_df,_e0,_e1); | |
618 | },evalJSON:function(){ | |
619 | return eval("("+arguments[0]+")"); | |
620 | },serializeJSON:function(o){ | |
621 | var _e3=typeof (o); | |
622 | if(_e3=="number"||_e3=="boolean"){ | |
623 | return o+""; | |
624 | }else{ | |
625 | if(o===null){ | |
626 | return "null"; | |
627 | } | |
628 | } | |
629 | var m=MochiKit.Base; | |
630 | var _e5=m.reprString; | |
631 | if(_e3=="string"){ | |
632 | return _e5(o); | |
633 | } | |
634 | var me=arguments.callee; | |
635 | var _e7; | |
636 | if(typeof (o.__json__)=="function"){ | |
637 | _e7=o.__json__(); | |
638 | if(o!==_e7){ | |
639 | return me(_e7); | |
640 | } | |
641 | } | |
642 | if(typeof (o.json)=="function"){ | |
643 | _e7=o.json(); | |
644 | if(o!==_e7){ | |
645 | return me(_e7); | |
646 | } | |
647 | } | |
648 | if(_e3!="function"&&typeof (o.length)=="number"){ | |
649 | var res=[]; | |
650 | for(var i=0;i<o.length;i++){ | |
651 | var val=me(o[i]); | |
652 | if(typeof (val)!="string"){ | |
653 | val="undefined"; | |
654 | } | |
655 | res.push(val); | |
656 | } | |
657 | return "["+res.join(", ")+"]"; | |
658 | } | |
659 | try{ | |
660 | _e7=m.jsonRegistry.match(o); | |
661 | if(o!==_e7){ | |
662 | return me(_e7); | |
663 | } | |
664 | } | |
665 | catch(e){ | |
666 | if(e!=m.NotFound){ | |
667 | throw e; | |
668 | } | |
669 | } | |
670 | if(_e3=="undefined"){ | |
671 | throw new TypeError("undefined can not be serialized as JSON"); | |
672 | } | |
673 | if(_e3=="function"){ | |
674 | return null; | |
675 | } | |
676 | res=[]; | |
677 | for(var k in o){ | |
678 | var _ec; | |
679 | if(typeof (k)=="number"){ | |
680 | _ec="\""+k+"\""; | |
681 | }else{ | |
682 | if(typeof (k)=="string"){ | |
683 | _ec=_e5(k); | |
684 | }else{ | |
685 | continue; | |
686 | } | |
687 | } | |
688 | val=me(o[k]); | |
689 | if(typeof (val)!="string"){ | |
690 | continue; | |
691 | } | |
692 | res.push(_ec+":"+val); | |
693 | } | |
694 | return "{"+res.join(", ")+"}"; | |
695 | },objEqual:function(a,b){ | |
696 | return (MochiKit.Base.compare(a,b)===0); | |
697 | },arrayEqual:function(_ef,arr){ | |
698 | if(_ef.length!=arr.length){ | |
699 | return false; | |
700 | } | |
701 | return (MochiKit.Base.compare(_ef,arr)===0); | |
702 | },concat:function(){ | |
703 | var _f1=[]; | |
704 | var _f2=MochiKit.Base.extend; | |
705 | for(var i=0;i<arguments.length;i++){ | |
706 | _f2(_f1,arguments[i]); | |
707 | } | |
708 | return _f1; | |
709 | },keyComparator:function(key){ | |
710 | var m=MochiKit.Base; | |
711 | var _f6=m.compare; | |
712 | if(arguments.length==1){ | |
713 | return function(a,b){ | |
714 | return _f6(a[key],b[key]); | |
715 | }; | |
716 | } | |
717 | var _f9=m.extend(null,arguments); | |
718 | return function(a,b){ | |
719 | var _fc=0; | |
720 | for(var i=0;(_fc===0)&&(i<_f9.length);i++){ | |
721 | var key=_f9[i]; | |
722 | _fc=_f6(a[key],b[key]); | |
723 | } | |
724 | return _fc; | |
725 | }; | |
726 | },reverseKeyComparator:function(key){ | |
727 | var _100=MochiKit.Base.keyComparator.apply(this,arguments); | |
728 | return function(a,b){ | |
729 | return _100(b,a); | |
730 | }; | |
731 | },partial:function(func){ | |
732 | var m=MochiKit.Base; | |
733 | return m.bind.apply(this,m.extend([func,undefined],arguments,1)); | |
734 | },listMinMax:function(_105,lst){ | |
735 | if(lst.length===0){ | |
736 | return null; | |
737 | } | |
738 | var cur=lst[0]; | |
739 | var _108=MochiKit.Base.compare; | |
740 | for(var i=1;i<lst.length;i++){ | |
741 | var o=lst[i]; | |
742 | if(_108(o,cur)==_105){ | |
743 | cur=o; | |
744 | } | |
745 | } | |
746 | return cur; | |
747 | },objMax:function(){ | |
748 | return MochiKit.Base.listMinMax(1,arguments); | |
749 | },objMin:function(){ | |
750 | return MochiKit.Base.listMinMax(-1,arguments); | |
751 | },findIdentical:function(lst,_10c,_10d,end){ | |
752 | if(typeof (end)=="undefined"||end===null){ | |
753 | end=lst.length; | |
754 | } | |
755 | if(typeof (_10d)=="undefined"||_10d===null){ | |
756 | _10d=0; | |
757 | } | |
758 | for(var i=_10d;i<end;i++){ | |
759 | if(lst[i]===_10c){ | |
760 | return i; | |
761 | } | |
762 | } | |
763 | return -1; | |
764 | },mean:function(){ | |
765 | var sum=0; | |
766 | var m=MochiKit.Base; | |
767 | var args=m.extend(null,arguments); | |
768 | var _113=args.length; | |
769 | while(args.length){ | |
770 | var o=args.shift(); | |
771 | if(o&&typeof (o)=="object"&&typeof (o.length)=="number"){ | |
772 | _113+=o.length-1; | |
773 | for(var i=o.length-1;i>=0;i--){ | |
774 | sum+=o[i]; | |
775 | } | |
776 | }else{ | |
777 | sum+=o; | |
778 | } | |
779 | } | |
780 | if(_113<=0){ | |
781 | throw new TypeError("mean() requires at least one argument"); | |
782 | } | |
783 | return sum/_113; | |
784 | },median:function(){ | |
785 | var data=MochiKit.Base.flattenArguments(arguments); | |
786 | if(data.length===0){ | |
787 | throw new TypeError("median() requires at least one argument"); | |
788 | } | |
789 | data.sort(compare); | |
790 | if(data.length%2==0){ | |
791 | var _117=data.length/2; | |
792 | return (data[_117]+data[_117-1])/2; | |
793 | }else{ | |
794 | return data[(data.length-1)/2]; | |
795 | } | |
796 | },findValue:function(lst,_119,_11a,end){ | |
797 | if(typeof (end)=="undefined"||end===null){ | |
798 | end=lst.length; | |
799 | } | |
800 | if(typeof (_11a)=="undefined"||_11a===null){ | |
801 | _11a=0; | |
802 | } | |
803 | var cmp=MochiKit.Base.compare; | |
804 | for(var i=_11a;i<end;i++){ | |
805 | if(cmp(lst[i],_119)===0){ | |
806 | return i; | |
807 | } | |
808 | } | |
809 | return -1; | |
810 | },nodeWalk:function(node,_11f){ | |
811 | var _120=[node]; | |
812 | var _121=MochiKit.Base.extend; | |
813 | while(_120.length){ | |
814 | var res=_11f(_120.shift()); | |
815 | if(res){ | |
816 | _121(_120,res); | |
817 | } | |
818 | } | |
819 | },nameFunctions:function(_123){ | |
820 | var base=_123.NAME; | |
821 | if(typeof (base)=="undefined"){ | |
822 | base=""; | |
823 | }else{ | |
824 | base=base+"."; | |
825 | } | |
826 | for(var name in _123){ | |
827 | var o=_123[name]; | |
828 | if(typeof (o)=="function"&&typeof (o.NAME)=="undefined"){ | |
829 | try{ | |
830 | o.NAME=base+name; | |
831 | } | |
832 | catch(e){ | |
833 | } | |
834 | } | |
835 | } | |
836 | },queryString:function(_127,_128){ | |
837 | if(typeof (MochiKit.DOM)!="undefined"&&arguments.length==1&&(typeof (_127)=="string"||(typeof (_127.nodeType)!="undefined"&&_127.nodeType>0))){ | |
838 | var kv=MochiKit.DOM.formContents(_127); | |
839 | _127=kv[0]; | |
840 | _128=kv[1]; | |
841 | }else{ | |
842 | if(arguments.length==1){ | |
843 | if(typeof (_127.length)=="number"&&_127.length==2){ | |
844 | return arguments.callee(_127[0],_127[1]); | |
845 | } | |
846 | var o=_127; | |
847 | _127=[]; | |
848 | _128=[]; | |
849 | for(var k in o){ | |
850 | var v=o[k]; | |
851 | if(typeof (v)=="function"){ | |
852 | continue; | |
853 | }else{ | |
854 | if(typeof (v)!="string"&&typeof (v.length)=="number"){ | |
855 | for(var i=0;i<v.length;i++){ | |
856 | _127.push(k); | |
857 | _128.push(v[i]); | |
858 | } | |
859 | }else{ | |
860 | _127.push(k); | |
861 | _128.push(v); | |
862 | } | |
863 | } | |
864 | } | |
865 | } | |
866 | } | |
867 | var rval=[]; | |
868 | var len=Math.min(_127.length,_128.length); | |
869 | var _130=MochiKit.Base.urlEncode; | |
870 | for(var i=0;i<len;i++){ | |
871 | v=_128[i]; | |
872 | if(typeof (v)!="undefined"&&v!==null){ | |
873 | rval.push(_130(_127[i])+"="+_130(v)); | |
874 | } | |
875 | } | |
876 | return rval.join("&"); | |
877 | },parseQueryString:function(_131,_132){ | |
878 | var qstr=(_131.charAt(0)=="?")?_131.substring(1):_131; | |
879 | var _134=qstr.replace(/\+/g,"%20").split(/(\&\;|\&\#38\;|\&|\&)/); | |
880 | var o={}; | |
881 | var _136; | |
882 | if(typeof (decodeURIComponent)!="undefined"){ | |
883 | _136=decodeURIComponent; | |
884 | }else{ | |
885 | _136=unescape; | |
886 | } | |
887 | if(_132){ | |
888 | for(var i=0;i<_134.length;i++){ | |
889 | var pair=_134[i].split("="); | |
890 | var name=_136(pair.shift()); | |
891 | if(!name){ | |
892 | continue; | |
893 | } | |
894 | var arr=o[name]; | |
895 | if(!(arr instanceof Array)){ | |
896 | arr=[]; | |
897 | o[name]=arr; | |
898 | } | |
899 | arr.push(_136(pair.join("="))); | |
900 | } | |
901 | }else{ | |
902 | for(i=0;i<_134.length;i++){ | |
903 | pair=_134[i].split("="); | |
904 | var name=pair.shift(); | |
905 | if(!name){ | |
906 | continue; | |
907 | } | |
908 | o[_136(name)]=_136(pair.join("=")); | |
909 | } | |
910 | } | |
911 | return o; | |
912 | }}); | |
913 | MochiKit.Base.AdapterRegistry=function(){ | |
914 | this.pairs=[]; | |
915 | }; | |
916 | MochiKit.Base.AdapterRegistry.prototype={register:function(name,_13c,wrap,_13e){ | |
917 | if(_13e){ | |
918 | this.pairs.unshift([name,_13c,wrap]); | |
919 | }else{ | |
920 | this.pairs.push([name,_13c,wrap]); | |
921 | } | |
922 | },match:function(){ | |
923 | for(var i=0;i<this.pairs.length;i++){ | |
924 | var pair=this.pairs[i]; | |
925 | if(pair[1].apply(this,arguments)){ | |
926 | return pair[2].apply(this,arguments); | |
927 | } | |
928 | } | |
929 | throw MochiKit.Base.NotFound; | |
930 | },unregister:function(name){ | |
931 | for(var i=0;i<this.pairs.length;i++){ | |
932 | var pair=this.pairs[i]; | |
933 | if(pair[0]==name){ | |
934 | this.pairs.splice(i,1); | |
935 | return true; | |
936 | } | |
937 | } | |
938 | return false; | |
939 | }}; | |
940 | MochiKit.Base.EXPORT=["flattenArray","noop","camelize","counter","clone","extend","update","updatetree","setdefault","keys","values","items","NamedError","operator","forwardCall","itemgetter","typeMatcher","isCallable","isUndefined","isUndefinedOrNull","isNull","isEmpty","isNotEmpty","isArrayLike","isDateLike","xmap","map","xfilter","filter","methodcaller","compose","bind","bindMethods","NotFound","AdapterRegistry","registerComparator","compare","registerRepr","repr","objEqual","arrayEqual","concat","keyComparator","reverseKeyComparator","partial","merge","listMinMax","listMax","listMin","objMax","objMin","nodeWalk","zip","urlEncode","queryString","serializeJSON","registerJSON","evalJSON","parseQueryString","findValue","findIdentical","flattenArguments","method","average","mean","median"]; | |
941 | MochiKit.Base.EXPORT_OK=["nameFunctions","comparatorRegistry","reprRegistry","jsonRegistry","compareDateLike","compareArrayLike","reprArrayLike","reprString","reprNumber"]; | |
942 | MochiKit.Base._exportSymbols=function(_144,_145){ | |
943 | if(!MochiKit.__export__){ | |
944 | return; | |
945 | } | |
946 | var all=_145.EXPORT_TAGS[":all"]; | |
947 | for(var i=0;i<all.length;i++){ | |
948 | _144[all[i]]=_145[all[i]]; | |
949 | } | |
950 | }; | |
951 | MochiKit.Base.__new__=function(){ | |
952 | var m=this; | |
953 | m.noop=m.operator.identity; | |
954 | m.forward=m.forwardCall; | |
955 | m.find=m.findValue; | |
956 | if(typeof (encodeURIComponent)!="undefined"){ | |
957 | m.urlEncode=function(_149){ | |
958 | return encodeURIComponent(_149).replace(/\'/g,"%27"); | |
959 | }; | |
960 | }else{ | |
961 | m.urlEncode=function(_14a){ | |
962 | return escape(_14a).replace(/\+/g,"%2B").replace(/\"/g,"%22").rval.replace(/\'/g,"%27"); | |
963 | }; | |
964 | } | |
965 | m.NamedError=function(name){ | |
966 | this.message=name; | |
967 | this.name=name; | |
968 | }; | |
969 | m.NamedError.prototype=new Error(); | |
970 | m.update(m.NamedError.prototype,{repr:function(){ | |
971 | if(this.message&&this.message!=this.name){ | |
972 | return this.name+"("+m.repr(this.message)+")"; | |
973 | }else{ | |
974 | return this.name+"()"; | |
975 | } | |
976 | },toString:m.forwardCall("repr")}); | |
977 | m.NotFound=new m.NamedError("MochiKit.Base.NotFound"); | |
978 | m.listMax=m.partial(m.listMinMax,1); | |
979 | m.listMin=m.partial(m.listMinMax,-1); | |
980 | m.isCallable=m.typeMatcher("function"); | |
981 | m.isUndefined=m.typeMatcher("undefined"); | |
982 | m.merge=m.partial(m.update,null); | |
983 | m.zip=m.partial(m.map,null); | |
984 | m.average=m.mean; | |
985 | m.comparatorRegistry=new m.AdapterRegistry(); | |
986 | m.registerComparator("dateLike",m.isDateLike,m.compareDateLike); | |
987 | m.registerComparator("arrayLike",m.isArrayLike,m.compareArrayLike); | |
988 | m.reprRegistry=new m.AdapterRegistry(); | |
989 | m.registerRepr("arrayLike",m.isArrayLike,m.reprArrayLike); | |
990 | m.registerRepr("string",m.typeMatcher("string"),m.reprString); | |
991 | m.registerRepr("numbers",m.typeMatcher("number","boolean"),m.reprNumber); | |
992 | m.jsonRegistry=new m.AdapterRegistry(); | |
993 | var all=m.concat(m.EXPORT,m.EXPORT_OK); | |
994 | m.EXPORT_TAGS={":common":m.concat(m.EXPORT_OK),":all":all}; | |
995 | m.nameFunctions(this); | |
996 | }; | |
997 | MochiKit.Base.__new__(); | |
998 | if(MochiKit.__export__){ | |
999 | compare=MochiKit.Base.compare; | |
1000 | compose=MochiKit.Base.compose; | |
1001 | serializeJSON=MochiKit.Base.serializeJSON; | |
1002 | } | |
1003 | MochiKit.Base._exportSymbols(this,MochiKit.Base); | |
1004 | if(typeof (dojo)!="undefined"){ | |
b0c3b730 | 1005 | dojo.provide("MochiKit.Color"); |
5fb1199a DV |
1006 | dojo.require("MochiKit.Base"); |
1007 | } | |
1008 | if(typeof (JSAN)!="undefined"){ | |
1009 | JSAN.use("MochiKit.Base",[]); | |
1010 | } | |
1011 | try{ | |
1012 | if(typeof (MochiKit.Base)=="undefined"){ | |
1013 | throw ""; | |
1014 | } | |
1015 | } | |
1016 | catch(e){ | |
b0c3b730 | 1017 | throw "MochiKit.Color depends on MochiKit.Base"; |
5fb1199a | 1018 | } |
b0c3b730 DV |
1019 | if(typeof (MochiKit.Color)=="undefined"){ |
1020 | MochiKit.Color={}; | |
5fb1199a | 1021 | } |
b0c3b730 DV |
1022 | MochiKit.Color.NAME="MochiKit.Color"; |
1023 | MochiKit.Color.VERSION="1.4"; | |
1024 | MochiKit.Color.__repr__=function(){ | |
5fb1199a | 1025 | return "["+this.NAME+" "+this.VERSION+"]"; |
b0c3b730 DV |
1026 | }; |
1027 | MochiKit.Color.toString=function(){ | |
5fb1199a | 1028 | return this.__repr__(); |
b0c3b730 DV |
1029 | }; |
1030 | MochiKit.Color.Color=function(red,_14e,blue,_150){ | |
1031 | if(typeof (_150)=="undefined"||_150===null){ | |
1032 | _150=1; | |
5fb1199a | 1033 | } |
b0c3b730 DV |
1034 | this.rgb={r:red,g:_14e,b:blue,a:_150}; |
1035 | }; | |
1036 | MochiKit.Color.Color.prototype={__class__:MochiKit.Color.Color,colorWithAlpha:function(_151){ | |
1037 | var rgb=this.rgb; | |
1038 | var m=MochiKit.Color; | |
1039 | return m.Color.fromRGB(rgb.r,rgb.g,rgb.b,_151); | |
1040 | },colorWithHue:function(hue){ | |
1041 | var hsl=this.asHSL(); | |
1042 | hsl.h=hue; | |
1043 | var m=MochiKit.Color; | |
1044 | return m.Color.fromHSL(hsl); | |
1045 | },colorWithSaturation:function(_157){ | |
1046 | var hsl=this.asHSL(); | |
1047 | hsl.s=_157; | |
1048 | var m=MochiKit.Color; | |
1049 | return m.Color.fromHSL(hsl); | |
1050 | },colorWithLightness:function(_15a){ | |
1051 | var hsl=this.asHSL(); | |
1052 | hsl.l=_15a; | |
1053 | var m=MochiKit.Color; | |
1054 | return m.Color.fromHSL(hsl); | |
1055 | },darkerColorWithLevel:function(_15d){ | |
1056 | var hsl=this.asHSL(); | |
1057 | hsl.l=Math.max(hsl.l-_15d,0); | |
1058 | var m=MochiKit.Color; | |
1059 | return m.Color.fromHSL(hsl); | |
1060 | },lighterColorWithLevel:function(_160){ | |
1061 | var hsl=this.asHSL(); | |
1062 | hsl.l=Math.min(hsl.l+_160,1); | |
1063 | var m=MochiKit.Color; | |
1064 | return m.Color.fromHSL(hsl); | |
1065 | },blendedColor:function(_163,_164){ | |
1066 | if(typeof (_164)=="undefined"||_164===null){ | |
1067 | _164=0.5; | |
5fb1199a | 1068 | } |
b0c3b730 DV |
1069 | var sf=1-_164; |
1070 | var s=this.rgb; | |
1071 | var d=_163.rgb; | |
1072 | var df=_164; | |
1073 | return MochiKit.Color.Color.fromRGB((s.r*sf)+(d.r*df),(s.g*sf)+(d.g*df),(s.b*sf)+(d.b*df),(s.a*sf)+(d.a*df)); | |
1074 | },compareRGB:function(_169){ | |
1075 | var a=this.asRGB(); | |
1076 | var b=_169.asRGB(); | |
1077 | return MochiKit.Base.compare([a.r,a.g,a.b,a.a],[b.r,b.g,b.b,b.a]); | |
1078 | },isLight:function(){ | |
1079 | return this.asHSL().b>0.5; | |
1080 | },isDark:function(){ | |
1081 | return (!this.isLight()); | |
1082 | },toHSLString:function(){ | |
1083 | var c=this.asHSL(); | |
1084 | var ccc=MochiKit.Color.clampColorComponent; | |
1085 | var rval=this._hslString; | |
1086 | if(!rval){ | |
1087 | var mid=(ccc(c.h,360).toFixed(0)+","+ccc(c.s,100).toPrecision(4)+"%"+","+ccc(c.l,100).toPrecision(4)+"%"); | |
1088 | var a=c.a; | |
1089 | if(a>=1){ | |
1090 | a=1; | |
1091 | rval="hsl("+mid+")"; | |
1092 | }else{ | |
1093 | if(a<=0){ | |
1094 | a=0; | |
5fb1199a | 1095 | } |
b0c3b730 | 1096 | rval="hsla("+mid+","+a+")"; |
5fb1199a | 1097 | } |
b0c3b730 | 1098 | this._hslString=rval; |
5fb1199a | 1099 | } |
5fb1199a | 1100 | return rval; |
b0c3b730 DV |
1101 | },toRGBString:function(){ |
1102 | var c=this.rgb; | |
1103 | var ccc=MochiKit.Color.clampColorComponent; | |
1104 | var rval=this._rgbString; | |
1105 | if(!rval){ | |
1106 | var mid=(ccc(c.r,255).toFixed(0)+","+ccc(c.g,255).toFixed(0)+","+ccc(c.b,255).toFixed(0)); | |
1107 | if(c.a!=1){ | |
1108 | rval="rgba("+mid+","+c.a+")"; | |
5fb1199a | 1109 | }else{ |
b0c3b730 | 1110 | rval="rgb("+mid+")"; |
5fb1199a | 1111 | } |
b0c3b730 | 1112 | this._rgbString=rval; |
5fb1199a | 1113 | } |
5fb1199a | 1114 | return rval; |
b0c3b730 DV |
1115 | },asRGB:function(){ |
1116 | return MochiKit.Base.clone(this.rgb); | |
1117 | },toHexString:function(){ | |
1118 | var m=MochiKit.Color; | |
1119 | var c=this.rgb; | |
1120 | var ccc=MochiKit.Color.clampColorComponent; | |
1121 | var rval=this._hexString; | |
1122 | if(!rval){ | |
1123 | rval=("#"+m.toColorPart(ccc(c.r,255))+m.toColorPart(ccc(c.g,255))+m.toColorPart(ccc(c.b,255))); | |
1124 | this._hexString=rval; | |
5fb1199a | 1125 | } |
5fb1199a | 1126 | return rval; |
b0c3b730 DV |
1127 | },asHSV:function(){ |
1128 | var hsv=this.hsv; | |
1129 | var c=this.rgb; | |
1130 | if(typeof (hsv)=="undefined"||hsv===null){ | |
1131 | hsv=MochiKit.Color.rgbToHSV(this.rgb); | |
1132 | this.hsv=hsv; | |
5fb1199a | 1133 | } |
b0c3b730 DV |
1134 | return MochiKit.Base.clone(hsv); |
1135 | },asHSL:function(){ | |
1136 | var hsl=this.hsl; | |
1137 | var c=this.rgb; | |
1138 | if(typeof (hsl)=="undefined"||hsl===null){ | |
1139 | hsl=MochiKit.Color.rgbToHSL(this.rgb); | |
1140 | this.hsl=hsl; | |
5fb1199a | 1141 | } |
b0c3b730 DV |
1142 | return MochiKit.Base.clone(hsl); |
1143 | },toString:function(){ | |
1144 | return this.toRGBString(); | |
1145 | },repr:function(){ | |
1146 | var c=this.rgb; | |
1147 | var col=[c.r,c.g,c.b,c.a]; | |
1148 | return this.__class__.NAME+"("+col.join(", ")+")"; | |
5fb1199a | 1149 | }}; |
b0c3b730 DV |
1150 | MochiKit.Base.update(MochiKit.Color.Color,{fromRGB:function(red,_180,blue,_182){ |
1151 | var _183=MochiKit.Color.Color; | |
5fb1199a | 1152 | if(arguments.length==1){ |
b0c3b730 DV |
1153 | var rgb=red; |
1154 | red=rgb.r; | |
1155 | _180=rgb.g; | |
1156 | blue=rgb.b; | |
1157 | if(typeof (rgb.a)=="undefined"){ | |
1158 | _182=undefined; | |
1159 | }else{ | |
1160 | _182=rgb.a; | |
5fb1199a | 1161 | } |
5fb1199a | 1162 | } |
b0c3b730 DV |
1163 | return new _183(red,_180,blue,_182); |
1164 | },fromHSL:function(hue,_186,_187,_188){ | |
1165 | var m=MochiKit.Color; | |
1166 | return m.Color.fromRGB(m.hslToRGB.apply(m,arguments)); | |
1167 | },fromHSV:function(hue,_18b,_18c,_18d){ | |
1168 | var m=MochiKit.Color; | |
1169 | return m.Color.fromRGB(m.hsvToRGB.apply(m,arguments)); | |
1170 | },fromName:function(name){ | |
1171 | var _190=MochiKit.Color.Color; | |
1172 | if(name.charAt(0)=="\""){ | |
1173 | name=name.substr(1,name.length-2); | |
5fb1199a | 1174 | } |
b0c3b730 DV |
1175 | var _191=_190._namedColors[name.toLowerCase()]; |
1176 | if(typeof (_191)=="string"){ | |
1177 | return _190.fromHexString(_191); | |
5fb1199a | 1178 | }else{ |
b0c3b730 DV |
1179 | if(name=="transparent"){ |
1180 | return _190.transparentColor(); | |
5fb1199a | 1181 | } |
5fb1199a | 1182 | } |
b0c3b730 DV |
1183 | return null; |
1184 | },fromString:function(_192){ | |
1185 | var self=MochiKit.Color.Color; | |
1186 | var _194=_192.substr(0,3); | |
1187 | if(_194=="rgb"){ | |
1188 | return self.fromRGBString(_192); | |
1189 | }else{ | |
1190 | if(_194=="hsl"){ | |
1191 | return self.fromHSLString(_192); | |
1192 | }else{ | |
1193 | if(_192.charAt(0)=="#"){ | |
1194 | return self.fromHexString(_192); | |
5fb1199a | 1195 | } |
5fb1199a | 1196 | } |
5fb1199a | 1197 | } |
b0c3b730 DV |
1198 | return self.fromName(_192); |
1199 | },fromHexString:function(_195){ | |
1200 | if(_195.charAt(0)=="#"){ | |
1201 | _195=_195.substring(1); | |
5fb1199a | 1202 | } |
b0c3b730 DV |
1203 | var _196=[]; |
1204 | var i,hex; | |
1205 | if(_195.length==3){ | |
1206 | for(i=0;i<3;i++){ | |
1207 | hex=_195.substr(i,1); | |
1208 | _196.push(parseInt(hex+hex,16)/255); | |
5fb1199a | 1209 | } |
b0c3b730 DV |
1210 | }else{ |
1211 | for(i=0;i<6;i+=2){ | |
1212 | hex=_195.substr(i,2); | |
1213 | _196.push(parseInt(hex,16)/255); | |
5fb1199a | 1214 | } |
5fb1199a | 1215 | } |
b0c3b730 DV |
1216 | var _199=MochiKit.Color.Color; |
1217 | return _199.fromRGB.apply(_199,_196); | |
1218 | },_fromColorString:function(pre,_19b,_19c,_19d){ | |
1219 | if(_19d.indexOf(pre)===0){ | |
1220 | _19d=_19d.substring(_19d.indexOf("(",3)+1,_19d.length-1); | |
5fb1199a | 1221 | } |
b0c3b730 DV |
1222 | var _19e=_19d.split(/\s*,\s*/); |
1223 | var _19f=[]; | |
1224 | for(var i=0;i<_19e.length;i++){ | |
1225 | var c=_19e[i]; | |
1226 | var val; | |
1227 | var _1a3=c.substring(c.length-3); | |
1228 | if(c.charAt(c.length-1)=="%"){ | |
1229 | val=0.01*parseFloat(c.substring(0,c.length-1)); | |
1230 | }else{ | |
1231 | if(_1a3=="deg"){ | |
1232 | val=parseFloat(c)/360; | |
1233 | }else{ | |
1234 | if(_1a3=="rad"){ | |
1235 | val=parseFloat(c)/(Math.PI*2); | |
1236 | }else{ | |
1237 | val=_19c[i]*parseFloat(c); | |
5fb1199a | 1238 | } |
5fb1199a | 1239 | } |
5fb1199a | 1240 | } |
b0c3b730 | 1241 | _19f.push(val); |
5fb1199a | 1242 | } |
b0c3b730 DV |
1243 | return this[_19b].apply(this,_19f); |
1244 | },fromBackground:function(elem){ | |
1245 | var cls=MochiKit.Color.Color; | |
1246 | return cls.fromComputedStyle(elem,"backgroundColor","background-color")||cls.whiteColor(); | |
1247 | },fromText:function(elem){ | |
1248 | var cls=MochiKit.Color.Color; | |
1249 | return cls.fromComputedStyle(elem,"color","color")||cls.blackColor(); | |
1250 | },namedColors:function(){ | |
1251 | return MochiKit.Base.clone(MochiKit.Color.Color._namedColors); | |
1252 | }}); | |
1253 | MochiKit.Base.update(MochiKit.Color,{clampColorComponent:function(v,_1a9){ | |
1254 | v*=_1a9; | |
1255 | if(v<0){ | |
1256 | return 0; | |
1257 | }else{ | |
1258 | if(v>_1a9){ | |
1259 | return _1a9; | |
1260 | }else{ | |
1261 | return v; | |
5fb1199a DV |
1262 | } |
1263 | } | |
b0c3b730 DV |
1264 | },_hslValue:function(n1,n2,hue){ |
1265 | if(hue>6){ | |
1266 | hue-=6; | |
1267 | }else{ | |
1268 | if(hue<0){ | |
1269 | hue+=6; | |
5fb1199a DV |
1270 | } |
1271 | } | |
b0c3b730 DV |
1272 | var val; |
1273 | if(hue<1){ | |
1274 | val=n1+(n2-n1)*hue; | |
5fb1199a | 1275 | }else{ |
b0c3b730 DV |
1276 | if(hue<3){ |
1277 | val=n2; | |
5fb1199a | 1278 | }else{ |
b0c3b730 DV |
1279 | if(hue<4){ |
1280 | val=n1+(n2-n1)*(4-hue); | |
5fb1199a | 1281 | }else{ |
b0c3b730 | 1282 | val=n1; |
5fb1199a | 1283 | } |
5fb1199a | 1284 | } |
5fb1199a | 1285 | } |
b0c3b730 DV |
1286 | return val; |
1287 | },hsvToRGB:function(hue,_1af,_1b0,_1b1){ | |
1288 | if(arguments.length==1){ | |
1289 | var hsv=hue; | |
1290 | hue=hsv.h; | |
1291 | _1af=hsv.s; | |
1292 | _1b0=hsv.v; | |
1293 | _1b1=hsv.a; | |
5fb1199a | 1294 | } |
b0c3b730 DV |
1295 | var red; |
1296 | var _1b4; | |
1297 | var blue; | |
1298 | if(_1af===0){ | |
1299 | red=_1b0; | |
1300 | _1b4=_1b0; | |
1301 | blue=_1b0; | |
5fb1199a | 1302 | }else{ |
b0c3b730 DV |
1303 | var i=Math.floor(hue*6); |
1304 | var f=(hue*6)-i; | |
1305 | var p=_1b0*(1-_1af); | |
1306 | var q=_1b0*(1-(_1af*f)); | |
1307 | var t=_1b0*(1-(_1af*(1-f))); | |
1308 | switch(i){ | |
1309 | case 1: | |
1310 | red=q; | |
1311 | _1b4=_1b0; | |
1312 | blue=p; | |
1313 | break; | |
1314 | case 2: | |
1315 | red=p; | |
1316 | _1b4=_1b0; | |
1317 | blue=t; | |
1318 | break; | |
1319 | case 3: | |
1320 | red=p; | |
1321 | _1b4=q; | |
1322 | blue=_1b0; | |
1323 | break; | |
1324 | case 4: | |
1325 | red=t; | |
1326 | _1b4=p; | |
1327 | blue=_1b0; | |
1328 | break; | |
1329 | case 5: | |
1330 | red=_1b0; | |
1331 | _1b4=p; | |
1332 | blue=q; | |
1333 | break; | |
1334 | case 6: | |
1335 | case 0: | |
1336 | red=_1b0; | |
1337 | _1b4=t; | |
1338 | blue=p; | |
1339 | break; | |
5fb1199a | 1340 | } |
5fb1199a | 1341 | } |
b0c3b730 DV |
1342 | return {r:red,g:_1b4,b:blue,a:_1b1}; |
1343 | },hslToRGB:function(hue,_1bc,_1bd,_1be){ | |
5fb1199a | 1344 | if(arguments.length==1){ |
b0c3b730 DV |
1345 | var hsl=hue; |
1346 | hue=hsl.h; | |
1347 | _1bc=hsl.s; | |
1348 | _1bd=hsl.l; | |
1349 | _1be=hsl.a; | |
5fb1199a | 1350 | } |
b0c3b730 DV |
1351 | var red; |
1352 | var _1c1; | |
1353 | var blue; | |
1354 | if(_1bc===0){ | |
1355 | red=_1bd; | |
1356 | _1c1=_1bd; | |
1357 | blue=_1bd; | |
5fb1199a | 1358 | }else{ |
b0c3b730 DV |
1359 | var m2; |
1360 | if(_1bd<=0.5){ | |
1361 | m2=_1bd*(1+_1bc); | |
1362 | }else{ | |
1363 | m2=_1bd+_1bc-(_1bd*_1bc); | |
5fb1199a | 1364 | } |
b0c3b730 DV |
1365 | var m1=(2*_1bd)-m2; |
1366 | var f=MochiKit.Color._hslValue; | |
1367 | var h6=hue*6; | |
1368 | red=f(m1,m2,h6+2); | |
1369 | _1c1=f(m1,m2,h6); | |
1370 | blue=f(m1,m2,h6-2); | |
5fb1199a | 1371 | } |
b0c3b730 DV |
1372 | return {r:red,g:_1c1,b:blue,a:_1be}; |
1373 | },rgbToHSV:function(red,_1c8,blue,_1ca){ | |
1374 | if(arguments.length==1){ | |
1375 | var rgb=red; | |
1376 | red=rgb.r; | |
1377 | _1c8=rgb.g; | |
1378 | blue=rgb.b; | |
1379 | _1ca=rgb.a; | |
5fb1199a | 1380 | } |
b0c3b730 DV |
1381 | var max=Math.max(Math.max(red,_1c8),blue); |
1382 | var min=Math.min(Math.min(red,_1c8),blue); | |
1383 | var hue; | |
1384 | var _1cf; | |
1385 | var _1d0=max; | |
1386 | if(min==max){ | |
1387 | hue=0; | |
1388 | _1cf=0; | |
1389 | }else{ | |
1390 | var _1d1=(max-min); | |
1391 | _1cf=_1d1/max; | |
1392 | if(red==max){ | |
1393 | hue=(_1c8-blue)/_1d1; | |
1394 | }else{ | |
1395 | if(_1c8==max){ | |
1396 | hue=2+((blue-red)/_1d1); | |
1397 | }else{ | |
1398 | hue=4+((red-_1c8)/_1d1); | |
5fb1199a | 1399 | } |
5fb1199a | 1400 | } |
b0c3b730 DV |
1401 | hue/=6; |
1402 | if(hue<0){ | |
1403 | hue+=1; | |
5fb1199a | 1404 | } |
b0c3b730 DV |
1405 | if(hue>1){ |
1406 | hue-=1; | |
5fb1199a | 1407 | } |
5fb1199a | 1408 | } |
b0c3b730 DV |
1409 | return {h:hue,s:_1cf,v:_1d0,a:_1ca}; |
1410 | },rgbToHSL:function(red,_1d3,blue,_1d5){ | |
1411 | if(arguments.length==1){ | |
1412 | var rgb=red; | |
1413 | red=rgb.r; | |
1414 | _1d3=rgb.g; | |
1415 | blue=rgb.b; | |
1416 | _1d5=rgb.a; | |
5fb1199a | 1417 | } |
b0c3b730 DV |
1418 | var max=Math.max(red,Math.max(_1d3,blue)); |
1419 | var min=Math.min(red,Math.min(_1d3,blue)); | |
1420 | var hue; | |
5fb1199a | 1421 | var _1da; |
b0c3b730 DV |
1422 | var _1db=(max+min)/2; |
1423 | var _1dc=max-min; | |
1424 | if(_1dc===0){ | |
1425 | hue=0; | |
1426 | _1da=0; | |
1427 | }else{ | |
1428 | if(_1db<=0.5){ | |
1429 | _1da=_1dc/(max+min); | |
1430 | }else{ | |
1431 | _1da=_1dc/(2-max-min); | |
5fb1199a | 1432 | } |
b0c3b730 DV |
1433 | if(red==max){ |
1434 | hue=(_1d3-blue)/_1dc; | |
1435 | }else{ | |
1436 | if(_1d3==max){ | |
1437 | hue=2+((blue-red)/_1dc); | |
1438 | }else{ | |
1439 | hue=4+((red-_1d3)/_1dc); | |
5fb1199a | 1440 | } |
5fb1199a | 1441 | } |
b0c3b730 DV |
1442 | hue/=6; |
1443 | if(hue<0){ | |
1444 | hue+=1; | |
5fb1199a | 1445 | } |
b0c3b730 DV |
1446 | if(hue>1){ |
1447 | hue-=1; | |
5fb1199a | 1448 | } |
5fb1199a | 1449 | } |
b0c3b730 DV |
1450 | return {h:hue,s:_1da,l:_1db,a:_1d5}; |
1451 | },toColorPart:function(num){ | |
1452 | num=Math.round(num); | |
1453 | var _1de=num.toString(16); | |
1454 | if(num<16){ | |
1455 | return "0"+_1de; | |
5fb1199a | 1456 | } |
b0c3b730 DV |
1457 | return _1de; |
1458 | },__new__:function(){ | |
5fb1199a | 1459 | var m=MochiKit.Base; |
b0c3b730 DV |
1460 | this.Color.fromRGBString=m.bind(this.Color._fromColorString,this.Color,"rgb","fromRGB",[1/255,1/255,1/255,1]); |
1461 | this.Color.fromHSLString=m.bind(this.Color._fromColorString,this.Color,"hsl","fromHSL",[1/360,0.01,0.01,1]); | |
1462 | var _1e0=1/3; | |
1463 | var _1e1={black:[0,0,0],blue:[0,0,1],brown:[0.6,0.4,0.2],cyan:[0,1,1],darkGray:[_1e0,_1e0,_1e0],gray:[0.5,0.5,0.5],green:[0,1,0],lightGray:[2*_1e0,2*_1e0,2*_1e0],magenta:[1,0,1],orange:[1,0.5,0],purple:[0.5,0,0.5],red:[1,0,0],transparent:[0,0,0,0],white:[1,1,1],yellow:[1,1,0]}; | |
1464 | var _1e2=function(name,r,g,b,a){ | |
1465 | var rval=this.fromRGB(r,g,b,a); | |
1466 | this[name]=function(){ | |
1467 | return rval; | |
5fb1199a | 1468 | }; |
b0c3b730 DV |
1469 | return rval; |
1470 | }; | |
1471 | for(var k in _1e1){ | |
1472 | var name=k+"Color"; | |
1473 | var _1eb=m.concat([_1e2,this.Color,name],_1e1[k]); | |
1474 | this.Color[name]=m.bind.apply(null,_1eb); | |
1475 | } | |
1476 | var _1ec=function(){ | |
1477 | for(var i=0;i<arguments.length;i++){ | |
1478 | if(!(arguments[i] instanceof Color)){ | |
1479 | return false; | |
1480 | } | |
5fb1199a | 1481 | } |
b0c3b730 DV |
1482 | return true; |
1483 | }; | |
1484 | var _1ee=function(a,b){ | |
1485 | return a.compareRGB(b); | |
1486 | }; | |
1487 | m.nameFunctions(this); | |
1488 | m.registerComparator(this.Color.NAME,_1ec,_1ee); | |
1489 | this.EXPORT_TAGS={":common":this.EXPORT,":all":m.concat(this.EXPORT,this.EXPORT_OK)}; | |
1490 | }}); | |
1491 | MochiKit.Color.EXPORT=["Color"]; | |
1492 | MochiKit.Color.EXPORT_OK=["clampColorComponent","rgbToHSL","hslToRGB","rgbToHSV","hsvToRGB","toColorPart"]; | |
1493 | MochiKit.Color.__new__(); | |
1494 | MochiKit.Base._exportSymbols(this,MochiKit.Color); | |
1495 | MochiKit.Color.Color._namedColors={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"}; | |
6a1aa64f DV |
1496 | |
1497 | ||
6219c9d6 | 1498 | Date.ext={};Date.ext.util={};Date.ext.util.xPad=function(x,pad,r){if(typeof (r)=="undefined"){r=10}for(;parseInt(x,10)<r&&r>1;r/=10){x=pad.toString()+x}return x.toString()};Date.prototype.locale="en-GB";if(document.getElementsByTagName("html")&&document.getElementsByTagName("html")[0].lang){Date.prototype.locale=document.getElementsByTagName("html")[0].lang}Date.ext.locales={};Date.ext.locales.en={a:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],b:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],B:["January","February","March","April","May","June","July","August","September","October","November","December"],c:"%a %d %b %Y %T %Z",p:["AM","PM"],P:["am","pm"],x:"%d/%m/%y",X:"%T"};Date.ext.locales["en-US"]=Date.ext.locales.en;Date.ext.locales["en-US"].c="%a %d %b %Y %r %Z";Date.ext.locales["en-US"].x="%D";Date.ext.locales["en-US"].X="%r";Date.ext.locales["en-GB"]=Date.ext.locales.en;Date.ext.locales["en-AU"]=Date.ext.locales["en-GB"];Date.ext.formats={a:function(d){return Date.ext.locales[d.locale].a[d.getDay()]},A:function(d){return Date.ext.locales[d.locale].A[d.getDay()]},b:function(d){return Date.ext.locales[d.locale].b[d.getMonth()]},B:function(d){return Date.ext.locales[d.locale].B[d.getMonth()]},c:"toLocaleString",C:function(d){return Date.ext.util.xPad(parseInt(d.getFullYear()/100,10),0)},d:["getDate","0"],e:["getDate"," "],g:function(d){return Date.ext.util.xPad(parseInt(Date.ext.util.G(d)/100,10),0)},G:function(d){var y=d.getFullYear();var V=parseInt(Date.ext.formats.V(d),10);var W=parseInt(Date.ext.formats.W(d),10);if(W>V){y++}else{if(W===0&&V>=52){y--}}return y},H:["getHours","0"],I:function(d){var I=d.getHours()%12;return Date.ext.util.xPad(I===0?12:I,0)},j:function(d){var ms=d-new Date(""+d.getFullYear()+"/1/1 GMT");ms+=d.getTimezoneOffset()*60000;var doy=parseInt(ms/60000/60/24,10)+1;return Date.ext.util.xPad(doy,0,100)},m:function(d){return Date.ext.util.xPad(d.getMonth()+1,0)},M:["getMinutes","0"],p:function(d){return Date.ext.locales[d.locale].p[d.getHours()>=12?1:0]},P:function(d){return Date.ext.locales[d.locale].P[d.getHours()>=12?1:0]},S:["getSeconds","0"],u:function(d){var dow=d.getDay();return dow===0?7:dow},U:function(d){var doy=parseInt(Date.ext.formats.j(d),10);var rdow=6-d.getDay();var woy=parseInt((doy+rdow)/7,10);return Date.ext.util.xPad(woy,0)},V:function(d){var woy=parseInt(Date.ext.formats.W(d),10);var dow1_1=(new Date(""+d.getFullYear()+"/1/1")).getDay();var idow=woy+(dow1_1>4||dow1_1<=1?0:1);if(idow==53&&(new Date(""+d.getFullYear()+"/12/31")).getDay()<4){idow=1}else{if(idow===0){idow=Date.ext.formats.V(new Date(""+(d.getFullYear()-1)+"/12/31"))}}return Date.ext.util.xPad(idow,0)},w:"getDay",W:function(d){var doy=parseInt(Date.ext.formats.j(d),10);var rdow=7-Date.ext.formats.u(d);var woy=parseInt((doy+rdow)/7,10);return Date.ext.util.xPad(woy,0,10)},y:function(d){return Date.ext.util.xPad(d.getFullYear()%100,0)},Y:"getFullYear",z:function(d){var o=d.getTimezoneOffset();var H=Date.ext.util.xPad(parseInt(Math.abs(o/60),10),0);var M=Date.ext.util.xPad(o%60,0);return(o>0?"-":"+")+H+M},Z:function(d){return d.toString().replace(/^.*\(([^)]+)\)$/,"$1")},"%":function(d){return"%"}};Date.ext.aggregates={c:"locale",D:"%m/%d/%y",h:"%b",n:"\n",r:"%I:%M:%S %p",R:"%H:%M",t:"\t",T:"%H:%M:%S",x:"locale",X:"locale"};Date.ext.aggregates.z=Date.ext.formats.z(new Date());Date.ext.aggregates.Z=Date.ext.formats.Z(new Date());Date.ext.unsupported={};Date.prototype.strftime=function(fmt){if(!(this.locale in Date.ext.locales)){if(this.locale.replace(/-[a-zA-Z]+$/,"") in Date.ext.locales){this.locale=this.locale.replace(/-[a-zA-Z]+$/,"")}else{this.locale="en-GB"}}var d=this;while(fmt.match(/%[cDhnrRtTxXzZ]/)){fmt=fmt.replace(/%([cDhnrRtTxXzZ])/g,function(m0,m1){var f=Date.ext.aggregates[m1];return(f=="locale"?Date.ext.locales[d.locale][m1]:f)})}var str=fmt.replace(/%([aAbBCdegGHIjmMpPSuUVwWyY%])/g,function(m0,m1){var f=Date.ext.formats[m1];if(typeof (f)=="string"){return d[f]()}else{if(typeof (f)=="function"){return f.call(d,d)}else{if(typeof (f)=="object"&&typeof (f[0])=="string"){return Date.ext.util.xPad(d[f[0]](),f[1])}else{return m1}}}});d=null;return str}; |
efe0829a DV |
1499 | DygraphLayout=function(_1,_2){ |
1500 | this.dygraph_=_1; | |
1501 | this.options={}; | |
1502 | MochiKit.Base.update(this.options,_2?_2:{}); | |
1503 | this.datasets=new Array(); | |
1504 | }; | |
1505 | DygraphLayout.prototype.attr_=function(_3){ | |
1506 | return this.dygraph_.attr_(_3); | |
1507 | }; | |
1508 | DygraphLayout.prototype.addDataset=function(_4,_5){ | |
1509 | this.datasets[_4]=_5; | |
1510 | }; | |
1511 | DygraphLayout.prototype.evaluate=function(){ | |
1512 | this._evaluateLimits(); | |
1513 | this._evaluateLineCharts(); | |
1514 | this._evaluateLineTicks(); | |
1515 | }; | |
1516 | DygraphLayout.prototype._evaluateLimits=function(){ | |
1517 | this.minxval=this.maxxval=null; | |
1518 | for(var _6 in this.datasets){ | |
1519 | var _7=this.datasets[_6]; | |
1520 | var x1=_7[0][0]; | |
1521 | if(!this.minxval||x1<this.minxval){ | |
1522 | this.minxval=x1; | |
1523 | } | |
1524 | var x2=_7[_7.length-1][0]; | |
1525 | if(!this.maxxval||x2>this.maxxval){ | |
1526 | this.maxxval=x2; | |
1527 | } | |
1528 | } | |
1529 | this.xrange=this.maxxval-this.minxval; | |
1530 | this.xscale=(this.xrange!=0?1/this.xrange:1); | |
1531 | this.minyval=this.options.yAxis[0]; | |
1532 | this.maxyval=this.options.yAxis[1]; | |
1533 | this.yrange=this.maxyval-this.minyval; | |
1534 | this.yscale=(this.yrange!=0?1/this.yrange:1); | |
1535 | }; | |
1536 | DygraphLayout.prototype._evaluateLineCharts=function(){ | |
1537 | this.points=new Array(); | |
1538 | for(var _10 in this.datasets){ | |
1539 | var _11=this.datasets[_10]; | |
1540 | for(var j=0;j<_11.length;j++){ | |
1541 | var _13=_11[j]; | |
1542 | var _14={x:((parseFloat(_13[0])-this.minxval)*this.xscale),y:1-((parseFloat(_13[1])-this.minyval)*this.yscale),xval:parseFloat(_13[0]),yval:parseFloat(_13[1]),name:_10}; | |
1543 | if(_14.y<=0){ | |
1544 | _14.y=0; | |
1545 | } | |
1546 | if(_14.y>=1){ | |
1547 | _14.y=1; | |
1548 | } | |
1549 | if((_14.x>=0)&&(_14.x<=1)){ | |
1550 | this.points.push(_14); | |
1551 | } | |
1552 | } | |
1553 | } | |
1554 | }; | |
1555 | DygraphLayout.prototype._evaluateLineTicks=function(){ | |
1556 | this.xticks=new Array(); | |
1557 | for(var i=0;i<this.options.xTicks.length;i++){ | |
1558 | var _16=this.options.xTicks[i]; | |
1559 | var _17=_16.label; | |
1560 | var pos=this.xscale*(_16.v-this.minxval); | |
1561 | if((pos>=0)&&(pos<=1)){ | |
1562 | this.xticks.push([pos,_17]); | |
1563 | } | |
1564 | } | |
1565 | this.yticks=new Array(); | |
1566 | for(var i=0;i<this.options.yTicks.length;i++){ | |
1567 | var _16=this.options.yTicks[i]; | |
1568 | var _17=_16.label; | |
1569 | var pos=1-(this.yscale*(_16.v-this.minyval)); | |
1570 | if((pos>=0)&&(pos<=1)){ | |
1571 | this.yticks.push([pos,_17]); | |
1572 | } | |
1573 | } | |
6a1aa64f | 1574 | }; |
285a6bda | 1575 | DygraphLayout.prototype.evaluateWithError=function(){ |
b2a516b8 DV |
1576 | this.evaluate(); |
1577 | if(!this.options.errorBars){ | |
1578 | return; | |
1579 | } | |
1580 | var i=0; | |
efe0829a | 1581 | for(var _19 in this.datasets){ |
b2a516b8 | 1582 | var j=0; |
efe0829a | 1583 | var _20=this.datasets[_19]; |
efe0829a DV |
1584 | for(var j=0;j<_20.length;j++,i++){ |
1585 | var _21=_20[j]; | |
1586 | var xv=parseFloat(_21[0]); | |
1587 | var yv=parseFloat(_21[1]); | |
b2a516b8 | 1588 | if(xv==this.points[i].xval&&yv==this.points[i].yval){ |
efe0829a DV |
1589 | this.points[i].errorMinus=parseFloat(_21[2]); |
1590 | this.points[i].errorPlus=parseFloat(_21[3]); | |
b2a516b8 DV |
1591 | } |
1592 | } | |
1593 | } | |
6a1aa64f | 1594 | }; |
285a6bda | 1595 | DygraphLayout.prototype.removeAllDatasets=function(){ |
b2a516b8 DV |
1596 | delete this.datasets; |
1597 | this.datasets=new Array(); | |
6a1aa64f | 1598 | }; |
efe0829a DV |
1599 | DygraphLayout.prototype.updateOptions=function(_24){ |
1600 | MochiKit.Base.update(this.options,_24?_24:{}); | |
b2a516b8 | 1601 | }; |
efe0829a | 1602 | DygraphCanvasRenderer=function(_25,_26,_27,_28){ |
efe0829a | 1603 | this.dygraph_=_25; |
fbe31dc8 | 1604 | this.options={"strokeWidth":0.5,"drawXAxis":true,"drawYAxis":true,"axisLineColor":Color.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":Color.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"drawYGrid":true,"drawXGrid":true,"gridLineColor":MochiKit.Color.Color.grayColor()}; |
efe0829a | 1605 | MochiKit.Base.update(this.options,_28); |
fbe31dc8 | 1606 | this.layout=_27; |
b0c3b730 | 1607 | this.element=_26; |
fbe31dc8 | 1608 | this.container=this.element.parentNode; |
3df0ccf0 | 1609 | this.isIE=(/MSIE/.test(navigator.userAgent)&&!window.opera); |
fbe31dc8 DV |
1610 | if(this.isIE&&!isNil(G_vmlCanvasManager)){ |
1611 | this.IEDelay=0.5; | |
1612 | this.maxTries=5; | |
1613 | this.renderDelay=null; | |
1614 | this.clearDelay=null; | |
1615 | this.element=G_vmlCanvasManager.initElement(this.element); | |
1616 | } | |
1617 | this.height=this.element.height; | |
1618 | this.width=this.element.width; | |
1619 | if(!this.isIE&&!(DygraphCanvasRenderer.isSupported(this.element))){ | |
1620 | throw "Canvas is not supported."; | |
1621 | } | |
1622 | this.xlabels=new Array(); | |
1623 | this.ylabels=new Array(); | |
1624 | this.area={x:this.options.yAxisLabelWidth+2*this.options.axisTickSize,y:0}; | |
1625 | this.area.w=this.width-this.area.x-this.options.rightGap; | |
1626 | this.area.h=this.height-this.options.axisLabelFontSize-2*this.options.axisTickSize; | |
b0c3b730 DV |
1627 | this.container.style.position="relative"; |
1628 | this.container.style.width=this.width+"px"; | |
fbe31dc8 DV |
1629 | }; |
1630 | DygraphCanvasRenderer.prototype.clear=function(){ | |
1631 | if(this.isIE){ | |
1632 | try{ | |
1633 | if(this.clearDelay){ | |
1634 | this.clearDelay.cancel(); | |
1635 | this.clearDelay=null; | |
1636 | } | |
1637 | var _29=this.element.getContext("2d"); | |
1638 | } | |
1639 | catch(e){ | |
1640 | this.clearDelay=MochiKit.Async.wait(this.IEDelay); | |
1641 | this.clearDelay.addCallback(bind(this.clear,this)); | |
1642 | return; | |
1643 | } | |
1644 | } | |
1645 | var _29=this.element.getContext("2d"); | |
1646 | _29.clearRect(0,0,this.width,this.height); | |
2160ed4a | 1647 | for(var i=0;i<this.xlabels.length;i++){ |
b0c3b730 DV |
1648 | var el=this.xlabels[i]; |
1649 | el.parentNode.removeChild(el); | |
2160ed4a DV |
1650 | } |
1651 | for(var i=0;i<this.ylabels.length;i++){ | |
b0c3b730 DV |
1652 | var el=this.ylabels[i]; |
1653 | el.parentNode.removeChild(el); | |
2160ed4a | 1654 | } |
fbe31dc8 DV |
1655 | this.xlabels=new Array(); |
1656 | this.ylabels=new Array(); | |
1657 | }; | |
b0c3b730 DV |
1658 | DygraphCanvasRenderer.isSupported=function(_31){ |
1659 | var _32=null; | |
fbe31dc8 | 1660 | try{ |
b0c3b730 DV |
1661 | if(MochiKit.Base.isUndefinedOrNull(_31)){ |
1662 | _32=document.createElement("canvas"); | |
fbe31dc8 | 1663 | }else{ |
b0c3b730 | 1664 | _32=_31; |
fbe31dc8 | 1665 | } |
b0c3b730 | 1666 | var _33=_32.getContext("2d"); |
fbe31dc8 DV |
1667 | } |
1668 | catch(e){ | |
1669 | var ie=navigator.appVersion.match(/MSIE (\d\.\d)/); | |
b0c3b730 DV |
1670 | var _35=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1); |
1671 | if((!ie)||(ie[1]<6)||(_35)){ | |
fbe31dc8 DV |
1672 | return false; |
1673 | } | |
1674 | return true; | |
1675 | } | |
1676 | return true; | |
b2a516b8 | 1677 | }; |
285a6bda | 1678 | DygraphCanvasRenderer.prototype.render=function(){ |
b2a516b8 DV |
1679 | var ctx=this.element.getContext("2d"); |
1680 | if(this.options.drawYGrid){ | |
b0c3b730 | 1681 | var _37=this.layout.yticks; |
b2a516b8 DV |
1682 | ctx.save(); |
1683 | ctx.strokeStyle=this.options.gridLineColor.toRGBString(); | |
1684 | ctx.lineWidth=this.options.axisLineWidth; | |
b0c3b730 | 1685 | for(var i=0;i<_37.length;i++){ |
b2a516b8 | 1686 | var x=this.area.x; |
b0c3b730 | 1687 | var y=this.area.y+_37[i][0]*this.area.h; |
b2a516b8 DV |
1688 | ctx.beginPath(); |
1689 | ctx.moveTo(x,y); | |
1690 | ctx.lineTo(x+this.area.w,y); | |
1691 | ctx.closePath(); | |
1692 | ctx.stroke(); | |
1693 | } | |
1694 | } | |
1695 | if(this.options.drawXGrid){ | |
b0c3b730 | 1696 | var _37=this.layout.xticks; |
b2a516b8 DV |
1697 | ctx.save(); |
1698 | ctx.strokeStyle=this.options.gridLineColor.toRGBString(); | |
1699 | ctx.lineWidth=this.options.axisLineWidth; | |
b0c3b730 DV |
1700 | for(var i=0;i<_37.length;i++){ |
1701 | var x=this.area.x+_37[i][0]*this.area.w; | |
b2a516b8 DV |
1702 | var y=this.area.y+this.area.h; |
1703 | ctx.beginPath(); | |
1704 | ctx.moveTo(x,y); | |
1705 | ctx.lineTo(x,this.area.y); | |
1706 | ctx.closePath(); | |
1707 | ctx.stroke(); | |
1708 | } | |
1709 | } | |
2ce09b19 | 1710 | this._renderLineChart(); |
fbe31dc8 | 1711 | this._renderAxis(); |
b2a516b8 | 1712 | }; |
fbe31dc8 DV |
1713 | DygraphCanvasRenderer.prototype._renderAxis=function(){ |
1714 | if(!this.options.drawXAxis&&!this.options.drawYAxis){ | |
1715 | return; | |
1716 | } | |
b0c3b730 | 1717 | var _40=this.element.getContext("2d"); |
bd597afc DV |
1718 | var _41={"position":"absolute","fontSize":this.options.axisLabelFontSize+"px","zIndex":10,"color":this.options.axisLabelColor.toRGBString(),"width":this.options.axisLabelWidth+"px","overflow":"hidden"}; |
1719 | var _42=function(txt){ | |
1720 | var div=document.createElement("div"); | |
1721 | for(var _45 in _41){ | |
1722 | div.style[_45]=_41[_45]; | |
1723 | } | |
1724 | div.appendChild(document.createTextNode(txt)); | |
1725 | return div; | |
1726 | }; | |
b0c3b730 DV |
1727 | _40.save(); |
1728 | _40.strokeStyle=this.options.axisLineColor.toRGBString(); | |
1729 | _40.lineWidth=this.options.axisLineWidth; | |
fbe31dc8 DV |
1730 | if(this.options.drawYAxis){ |
1731 | if(this.layout.yticks){ | |
2160ed4a | 1732 | for(var i=0;i<this.layout.yticks.length;i++){ |
bd597afc DV |
1733 | var _46=this.layout.yticks[i]; |
1734 | if(typeof (_46)=="function"){ | |
fbe31dc8 DV |
1735 | return; |
1736 | } | |
1737 | var x=this.area.x; | |
bd597afc | 1738 | var y=this.area.y+_46[0]*this.area.h; |
b0c3b730 DV |
1739 | _40.beginPath(); |
1740 | _40.moveTo(x,y); | |
1741 | _40.lineTo(x-this.options.axisTickSize,y); | |
1742 | _40.closePath(); | |
1743 | _40.stroke(); | |
bd597afc | 1744 | var _47=_42(_46[1]); |
fbe31dc8 DV |
1745 | var top=(y-this.options.axisLabelFontSize/2); |
1746 | if(top<0){ | |
1747 | top=0; | |
1748 | } | |
1749 | if(top+this.options.axisLabelFontSize+3>this.height){ | |
bd597afc | 1750 | _47.style.bottom="0px"; |
fbe31dc8 | 1751 | }else{ |
bd597afc | 1752 | _47.style.top=top+"px"; |
fbe31dc8 | 1753 | } |
bd597afc DV |
1754 | _47.style.left="0px"; |
1755 | _47.style.textAlign="right"; | |
1756 | _47.style.width=this.options.yAxisLabelWidth+"px"; | |
1757 | this.container.appendChild(_47); | |
1758 | this.ylabels.push(_47); | |
2160ed4a | 1759 | } |
bd597afc DV |
1760 | var _49=this.ylabels[0]; |
1761 | var _50=this.options.axisLabelFontSize; | |
1762 | var _51=parseInt(_49.style.top)+_50; | |
1763 | if(_51>this.height-_50){ | |
1764 | _49.style.top=(parseInt(_49.style.top)-_50/2)+"px"; | |
fbe31dc8 DV |
1765 | } |
1766 | } | |
b0c3b730 DV |
1767 | _40.beginPath(); |
1768 | _40.moveTo(this.area.x,this.area.y); | |
1769 | _40.lineTo(this.area.x,this.area.y+this.area.h); | |
1770 | _40.closePath(); | |
1771 | _40.stroke(); | |
fbe31dc8 DV |
1772 | } |
1773 | if(this.options.drawXAxis){ | |
1774 | if(this.layout.xticks){ | |
2160ed4a | 1775 | for(var i=0;i<this.layout.xticks.length;i++){ |
bd597afc | 1776 | var _46=this.layout.xticks[i]; |
fbe31dc8 DV |
1777 | if(typeof (dataset)=="function"){ |
1778 | return; | |
1779 | } | |
bd597afc | 1780 | var x=this.area.x+_46[0]*this.area.w; |
fbe31dc8 | 1781 | var y=this.area.y+this.area.h; |
b0c3b730 DV |
1782 | _40.beginPath(); |
1783 | _40.moveTo(x,y); | |
1784 | _40.lineTo(x,y+this.options.axisTickSize); | |
1785 | _40.closePath(); | |
1786 | _40.stroke(); | |
bd597afc DV |
1787 | var _47=_42(_46[1]); |
1788 | _47.style.textAlign="center"; | |
1789 | _47.style.bottom="0px"; | |
1790 | var _52=(x-this.options.axisLabelWidth/2); | |
1791 | if(_52+this.options.axisLabelWidth>this.width){ | |
1792 | _52=this.width-this.options.xAxisLabelWidth; | |
1793 | _47.style.textAlign="right"; | |
b0c3b730 | 1794 | } |
bd597afc DV |
1795 | if(_52<0){ |
1796 | _52=0; | |
1797 | _47.style.textAlign="left"; | |
b0c3b730 | 1798 | } |
bd597afc DV |
1799 | _47.style.left=_52+"px"; |
1800 | _47.style.width=this.options.xAxisLabelWidth+"px"; | |
1801 | this.container.appendChild(_47); | |
1802 | this.xlabels.push(_47); | |
b0c3b730 DV |
1803 | } |
1804 | } | |
1805 | _40.beginPath(); | |
1806 | _40.moveTo(this.area.x,this.area.y+this.area.h); | |
1807 | _40.lineTo(this.area.x+this.area.w,this.area.y+this.area.h); | |
1808 | _40.closePath(); | |
1809 | _40.stroke(); | |
1810 | } | |
1811 | _40.restore(); | |
efe0829a | 1812 | }; |
fbe31dc8 | 1813 | DygraphCanvasRenderer.prototype._renderLineChart=function(){ |
bd597afc DV |
1814 | var _53=this.element.getContext("2d"); |
1815 | var _54=this.options.colorScheme.length; | |
1816 | var _55=this.options.colorScheme; | |
1817 | var _56=MochiKit.Base.keys(this.layout.datasets); | |
1818 | var _57=this.layout.options.errorBars; | |
1819 | var _58=_56.length; | |
1820 | var _59=MochiKit.Base.bind; | |
1821 | var _60=MochiKit.Base.partial; | |
2160ed4a | 1822 | for(var i=0;i<this.layout.points.length;i++){ |
bd597afc DV |
1823 | var _61=this.layout.points[i]; |
1824 | _61.canvasx=this.area.w*_61.x+this.area.x; | |
1825 | _61.canvasy=this.area.h*_61.y+this.area.y; | |
2160ed4a | 1826 | } |
bd597afc | 1827 | var _62=function(x){ |
9317362d DV |
1828 | return x&&!isNaN(x); |
1829 | }; | |
bd597afc DV |
1830 | var _63=function(ctx){ |
1831 | for(var i=0;i<_58;i++){ | |
1832 | var _64=_56[i]; | |
1833 | var _65=_55[i%_54]; | |
1834 | var _66=this.options.strokeColorTransform; | |
1835 | _53.save(); | |
1836 | _53.strokeStyle=_65.toRGBString(); | |
1837 | _53.lineWidth=this.options.strokeWidth; | |
1838 | var _61=this.layout.points[0]; | |
1839 | var _67=this.dygraph_.attr_("pointSize"); | |
1840 | var _68=null,prevY=null; | |
1841 | var _69=this.dygraph_.attr_("drawPoints"); | |
1842 | var _70=this.layout.points; | |
1843 | for(var j=0;j<_70.length;j++){ | |
1844 | var _61=_70[j]; | |
1845 | if(_61.name==_64){ | |
1846 | if(!_62(_61.canvasy)){ | |
1847 | _68=prevY=null; | |
1848 | }else{ | |
1849 | var _71=(!_68&&(j==_70.length-1||!_62(_70[j+1].canvasy))); | |
1850 | if(!_68){ | |
1851 | _68=_61.canvasx; | |
1852 | prevY=_61.canvasy; | |
b2a516b8 | 1853 | }else{ |
9317362d | 1854 | ctx.beginPath(); |
bd597afc DV |
1855 | ctx.moveTo(_68,prevY); |
1856 | _68=_61.canvasx; | |
1857 | prevY=_61.canvasy; | |
1858 | ctx.lineTo(_68,prevY); | |
9317362d DV |
1859 | ctx.stroke(); |
1860 | } | |
bd597afc | 1861 | if(_69||_71){ |
9317362d | 1862 | ctx.beginPath(); |
bd597afc DV |
1863 | ctx.fillStyle=_65.toRGBString(); |
1864 | ctx.arc(_61.canvasx,_61.canvasy,_67,0,360,false); | |
9317362d DV |
1865 | ctx.fill(); |
1866 | } | |
b2a516b8 | 1867 | } |
648acd28 | 1868 | } |
b2a516b8 | 1869 | } |
b2a516b8 DV |
1870 | } |
1871 | }; | |
bd597afc DV |
1872 | var _72=function(ctx){ |
1873 | for(var i=0;i<_58;i++){ | |
1874 | var _73=_56[i]; | |
1875 | var _74=_55[i%_54]; | |
1876 | var _75=this.options.strokeColorTransform; | |
1877 | _53.save(); | |
1878 | _53.strokeStyle=_74.toRGBString(); | |
1879 | _53.lineWidth=this.options.strokeWidth; | |
1880 | var _76=-1; | |
1881 | var _77=[-1,-1]; | |
1882 | var _78=0; | |
1883 | var _79=this.layout.yscale; | |
1884 | var _80=_74.colorWithAlpha(0.15); | |
1885 | ctx.fillStyle=_80.toRGBString(); | |
5fb1199a DV |
1886 | ctx.beginPath(); |
1887 | for(var j=0;j<this.layout.points.length;j++){ | |
bd597afc DV |
1888 | var _81=this.layout.points[j]; |
1889 | _78++; | |
1890 | if(_81.name==_73){ | |
1891 | if(!_81.y||isNaN(_81.y)){ | |
1892 | _76=-1; | |
648acd28 DV |
1893 | return; |
1894 | } | |
bd597afc DV |
1895 | var _82=[_81.y-_81.errorPlus*_79,_81.y+_81.errorMinus*_79]; |
1896 | _82[0]=this.area.h*_82[0]+this.area.y; | |
1897 | _82[1]=this.area.h*_82[1]+this.area.y; | |
1898 | if(_76>=0){ | |
1899 | ctx.moveTo(_76,_77[0]); | |
1900 | ctx.lineTo(_81.canvasx,_82[0]); | |
1901 | ctx.lineTo(_81.canvasx,_82[1]); | |
1902 | ctx.lineTo(_76,_77[1]); | |
5fb1199a DV |
1903 | ctx.closePath(); |
1904 | } | |
bd597afc DV |
1905 | _77[0]=_82[0]; |
1906 | _77[1]=_82[1]; | |
1907 | _76=_81.canvasx; | |
b2a516b8 | 1908 | } |
b2a516b8 | 1909 | } |
b2a516b8 DV |
1910 | ctx.fill(); |
1911 | } | |
6a1aa64f | 1912 | }; |
bd597afc DV |
1913 | if(_57){ |
1914 | _59(_72,this)(_53); | |
b2a516b8 | 1915 | } |
bd597afc DV |
1916 | _59(_63,this)(_53); |
1917 | _53.restore(); | |
6a1aa64f | 1918 | }; |
bd597afc | 1919 | Dygraph=function(div,_83,_84){ |
b2a516b8 | 1920 | if(arguments.length>0){ |
285a6bda DV |
1921 | if(arguments.length==4){ |
1922 | this.warn("Using deprecated four-argument dygraph constructor"); | |
bd597afc | 1923 | this.__old_init__(div,_83,arguments[2],arguments[3]); |
285a6bda | 1924 | }else{ |
bd597afc | 1925 | this.__init__(div,_83,_84); |
285a6bda | 1926 | } |
b2a516b8 | 1927 | } |
6a1aa64f | 1928 | }; |
285a6bda DV |
1929 | Dygraph.NAME="Dygraph"; |
1930 | Dygraph.VERSION="1.2"; | |
1931 | Dygraph.__repr__=function(){ | |
b2a516b8 | 1932 | return "["+this.NAME+" "+this.VERSION+"]"; |
6a1aa64f | 1933 | }; |
285a6bda | 1934 | Dygraph.toString=function(){ |
b2a516b8 | 1935 | return this.__repr__(); |
6a1aa64f | 1936 | }; |
285a6bda DV |
1937 | Dygraph.DEFAULT_ROLL_PERIOD=1; |
1938 | Dygraph.DEFAULT_WIDTH=480; | |
1939 | Dygraph.DEFAULT_HEIGHT=320; | |
1940 | Dygraph.AXIS_LINE_WIDTH=0.3; | |
8846615a | 1941 | Dygraph.DEFAULT_ATTRS={highlightCircleSize:3,pixelsPerXLabel:60,pixelsPerYLabel:30,labelsDivWidth:250,labelsDivStyles:{},labelsSeparateLines:false,labelsKMB:false,strokeWidth:1,axisTickSize:3,axisLabelFontSize:14,xAxisLabelWidth:50,yAxisLabelWidth:50,rightGap:5,showRoller:false,xValueFormatter:Dygraph.dateString_,xValueParser:Dygraph.dateParser,xTicker:Dygraph.dateTicker,sigma:2,errorBars:false,fractions:false,wilsonInterval:true,customBars:false}; |
285a6bda DV |
1942 | Dygraph.DEBUG=1; |
1943 | Dygraph.INFO=2; | |
1944 | Dygraph.WARNING=3; | |
1945 | Dygraph.ERROR=3; | |
bd597afc DV |
1946 | Dygraph.prototype.__old_init__=function(div,_85,_86,_87){ |
1947 | if(_86!=null){ | |
1948 | var _88=["Date"]; | |
1949 | for(var i=0;i<_86.length;i++){ | |
1950 | _88.push(_86[i]); | |
285a6bda | 1951 | } |
bd597afc | 1952 | MochiKit.Base.update(_87,{"labels":_88}); |
285a6bda | 1953 | } |
bd597afc | 1954 | this.__init__(div,_85,_87); |
285a6bda | 1955 | }; |
bd597afc DV |
1956 | Dygraph.prototype.__init__=function(div,_89,_90){ |
1957 | if(_90==null){ | |
1958 | _90={}; | |
285a6bda | 1959 | } |
b2a516b8 | 1960 | this.maindiv_=div; |
bd597afc DV |
1961 | this.file_=_89; |
1962 | this.rollPeriod_=_90.rollPeriod||Dygraph.DEFAULT_ROLL_PERIOD; | |
b2a516b8 | 1963 | this.previousVerticalX_=-1; |
bd597afc DV |
1964 | this.fractions_=_90.fractions||false; |
1965 | this.dateWindow_=_90.dateWindow||null; | |
1966 | this.valueRange_=_90.valueRange||null; | |
1967 | this.wilsonInterval_=_90.wilsonInterval||true; | |
caf49918 | 1968 | div.innerHTML=""; |
285a6bda DV |
1969 | if(div.style.width==""){ |
1970 | div.style.width=Dygraph.DEFAULT_WIDTH+"px"; | |
1971 | } | |
1972 | if(div.style.height==""){ | |
1973 | div.style.height=Dygraph.DEFAULT_HEIGHT+"px"; | |
1974 | } | |
b2a516b8 DV |
1975 | this.width_=parseInt(div.style.width,10); |
1976 | this.height_=parseInt(div.style.height,10); | |
285a6bda | 1977 | this.user_attrs_={}; |
bd597afc | 1978 | MochiKit.Base.update(this.user_attrs_,_90); |
b8339f6e | 1979 | this.attrs_={}; |
285a6bda DV |
1980 | MochiKit.Base.update(this.attrs_,Dygraph.DEFAULT_ATTRS); |
1981 | this.labelsFromCSV_=(this.attr_("labels")==null); | |
b2a516b8 | 1982 | this.createInterface_(); |
b64a4f1a | 1983 | this.layoutOptions_={"errorBars":(this.attr_("errorBars")||this.attr_("customBars")),"xOriginIsZero":false}; |
285a6bda DV |
1984 | MochiKit.Base.update(this.layoutOptions_,this.attrs_); |
1985 | MochiKit.Base.update(this.layoutOptions_,this.user_attrs_); | |
efe0829a | 1986 | this.layout_=new DygraphLayout(this,this.layoutOptions_); |
8846615a | 1987 | this.renderOptions_={colorScheme:this.colors_,strokeColor:null,axisLineWidth:Dygraph.AXIS_LINE_WIDTH}; |
285a6bda DV |
1988 | MochiKit.Base.update(this.renderOptions_,this.attrs_); |
1989 | MochiKit.Base.update(this.renderOptions_,this.user_attrs_); | |
9317362d | 1990 | this.plotter_=new DygraphCanvasRenderer(this,this.hidden_,this.layout_,this.renderOptions_); |
b2a516b8 DV |
1991 | this.createStatusMessage_(); |
1992 | this.createRollInterface_(); | |
1993 | this.createDragInterface_(); | |
b2a516b8 | 1994 | this.start_(); |
6a1aa64f | 1995 | }; |
bd597afc DV |
1996 | Dygraph.prototype.attr_=function(_91){ |
1997 | if(typeof (this.user_attrs_[_91])!="undefined"){ | |
1998 | return this.user_attrs_[_91]; | |
285a6bda | 1999 | }else{ |
bd597afc DV |
2000 | if(typeof (this.attrs_[_91])!="undefined"){ |
2001 | return this.attrs_[_91]; | |
285a6bda DV |
2002 | }else{ |
2003 | return null; | |
2004 | } | |
2005 | } | |
2006 | }; | |
bd597afc | 2007 | Dygraph.prototype.log=function(_92,_93){ |
285a6bda | 2008 | if(typeof (console)!="undefined"){ |
bd597afc | 2009 | switch(_92){ |
285a6bda | 2010 | case Dygraph.DEBUG: |
bd597afc | 2011 | console.debug("dygraphs: "+_93); |
285a6bda DV |
2012 | break; |
2013 | case Dygraph.INFO: | |
bd597afc | 2014 | console.info("dygraphs: "+_93); |
285a6bda DV |
2015 | break; |
2016 | case Dygraph.WARNING: | |
bd597afc | 2017 | console.warn("dygraphs: "+_93); |
285a6bda DV |
2018 | break; |
2019 | case Dygraph.ERROR: | |
bd597afc | 2020 | console.error("dygraphs: "+_93); |
285a6bda DV |
2021 | break; |
2022 | } | |
2023 | } | |
2024 | }; | |
bd597afc DV |
2025 | Dygraph.prototype.info=function(_94){ |
2026 | this.log(Dygraph.INFO,_94); | |
285a6bda | 2027 | }; |
bd597afc DV |
2028 | Dygraph.prototype.warn=function(_95){ |
2029 | this.log(Dygraph.WARNING,_95); | |
285a6bda | 2030 | }; |
bd597afc DV |
2031 | Dygraph.prototype.error=function(_96){ |
2032 | this.log(Dygraph.ERROR,_96); | |
285a6bda DV |
2033 | }; |
2034 | Dygraph.prototype.rollPeriod=function(){ | |
b2a516b8 DV |
2035 | return this.rollPeriod_; |
2036 | }; | |
76171648 | 2037 | Dygraph.addEvent=function(el,evt,fn){ |
bd597afc | 2038 | var _99=function(e){ |
76171648 DV |
2039 | if(!e){ |
2040 | var e=window.event; | |
2041 | } | |
2042 | fn(e); | |
2043 | }; | |
2044 | if(window.addEventListener){ | |
bd597afc | 2045 | el.addEventListener(evt,_99,false); |
76171648 | 2046 | }else{ |
bd597afc | 2047 | el.attachEvent("on"+evt,_99); |
76171648 DV |
2048 | } |
2049 | }; | |
285a6bda | 2050 | Dygraph.prototype.createInterface_=function(){ |
bd597afc | 2051 | var _101=this.maindiv_; |
b0c3b730 DV |
2052 | this.graphDiv=document.createElement("div"); |
2053 | this.graphDiv.style.width=this.width_+"px"; | |
2054 | this.graphDiv.style.height=this.height_+"px"; | |
bd597afc | 2055 | _101.appendChild(this.graphDiv); |
b0c3b730 DV |
2056 | this.canvas_=document.createElement("canvas"); |
2057 | this.canvas_.style.position="absolute"; | |
2058 | this.canvas_.width=this.width_; | |
2059 | this.canvas_.height=this.height_; | |
2060 | this.graphDiv.appendChild(this.canvas_); | |
b2a516b8 | 2061 | this.hidden_=this.createPlotKitCanvas_(this.canvas_); |
bd597afc | 2062 | var _102=this; |
76171648 | 2063 | Dygraph.addEvent(this.hidden_,"mousemove",function(e){ |
bd597afc | 2064 | _102.mouseMove_(e); |
b2a516b8 | 2065 | }); |
76171648 | 2066 | Dygraph.addEvent(this.hidden_,"mouseout",function(e){ |
bd597afc | 2067 | _102.mouseOut_(e); |
b2a516b8 | 2068 | }); |
6a1aa64f | 2069 | }; |
bd597afc | 2070 | Dygraph.prototype.createPlotKitCanvas_=function(_103){ |
b2a516b8 DV |
2071 | var h=document.createElement("canvas"); |
2072 | h.style.position="absolute"; | |
bd597afc DV |
2073 | h.style.top=_103.style.top; |
2074 | h.style.left=_103.style.left; | |
b2a516b8 DV |
2075 | h.width=this.width_; |
2076 | h.height=this.height_; | |
b0c3b730 | 2077 | this.graphDiv.appendChild(h); |
b2a516b8 DV |
2078 | return h; |
2079 | }; | |
285a6bda DV |
2080 | Dygraph.prototype.setColors_=function(){ |
2081 | var num=this.attr_("labels").length-1; | |
b2a516b8 | 2082 | this.colors_=[]; |
bd597afc DV |
2083 | var _106=this.attr_("colors"); |
2084 | if(!_106){ | |
285a6bda DV |
2085 | var sat=this.attr_("colorSaturation")||1; |
2086 | var val=this.attr_("colorValue")||0.5; | |
b2a516b8 DV |
2087 | for(var i=1;i<=num;i++){ |
2088 | var hue=(1*i/(1+num)); | |
2089 | this.colors_.push(MochiKit.Color.Color.fromHSV(hue,sat,val)); | |
2090 | } | |
2091 | }else{ | |
2092 | for(var i=0;i<num;i++){ | |
bd597afc DV |
2093 | var _110=_106[i%_106.length]; |
2094 | this.colors_.push(MochiKit.Color.Color.fromString(_110)); | |
b2a516b8 | 2095 | } |
b2a516b8 | 2096 | } |
285a6bda DV |
2097 | this.renderOptions_.colorScheme=this.colors_; |
2098 | MochiKit.Base.update(this.plotter_.options,this.renderOptions_); | |
2099 | MochiKit.Base.update(this.layoutOptions_,this.user_attrs_); | |
2100 | MochiKit.Base.update(this.layoutOptions_,this.attrs_); | |
b2a516b8 | 2101 | }; |
3df0ccf0 | 2102 | Dygraph.findPosX=function(obj){ |
bd597afc | 2103 | var _112=0; |
3df0ccf0 DV |
2104 | if(obj.offsetParent){ |
2105 | while(obj.offsetParent){ | |
bd597afc | 2106 | _112+=obj.offsetLeft; |
3df0ccf0 DV |
2107 | obj=obj.offsetParent; |
2108 | } | |
2109 | }else{ | |
2110 | if(obj.x){ | |
bd597afc | 2111 | _112+=obj.x; |
3df0ccf0 DV |
2112 | } |
2113 | } | |
bd597afc | 2114 | return _112; |
3df0ccf0 DV |
2115 | }; |
2116 | Dygraph.findPosY=function(obj){ | |
bd597afc | 2117 | var _113=0; |
3df0ccf0 DV |
2118 | if(obj.offsetParent){ |
2119 | while(obj.offsetParent){ | |
bd597afc | 2120 | _113+=obj.offsetTop; |
3df0ccf0 DV |
2121 | obj=obj.offsetParent; |
2122 | } | |
2123 | }else{ | |
2124 | if(obj.y){ | |
bd597afc | 2125 | _113+=obj.y; |
3df0ccf0 DV |
2126 | } |
2127 | } | |
bd597afc | 2128 | return _113; |
3df0ccf0 | 2129 | }; |
285a6bda DV |
2130 | Dygraph.prototype.createStatusMessage_=function(){ |
2131 | if(!this.attr_("labelsDiv")){ | |
bd597afc DV |
2132 | var _114=this.attr_("labelsDivWidth"); |
2133 | var _115={"position":"absolute","fontSize":"14px","zIndex":10,"width":_114+"px","top":"0px","left":(this.width_-_114-2)+"px","background":"white","textAlign":"left","overflow":"hidden"}; | |
2134 | MochiKit.Base.update(_115,this.attr_("labelsDivStyles")); | |
b0c3b730 | 2135 | var div=document.createElement("div"); |
bd597afc DV |
2136 | for(var name in _115){ |
2137 | div.style[name]=_115[name]; | |
b0c3b730 DV |
2138 | } |
2139 | this.graphDiv.appendChild(div); | |
285a6bda DV |
2140 | this.attrs_.labelsDiv=div; |
2141 | } | |
2142 | }; | |
2143 | Dygraph.prototype.createRollInterface_=function(){ | |
bd597afc DV |
2144 | var _117=this.attr_("showRoller")?"block":"none"; |
2145 | var _118={"position":"absolute","zIndex":10,"top":(this.plotter_.area.h-25)+"px","left":(this.plotter_.area.x+1)+"px","display":_117}; | |
2146 | var _119=document.createElement("input"); | |
2147 | _119.type="text"; | |
2148 | _119.size="2"; | |
2149 | _119.value=this.rollPeriod_; | |
2150 | for(var name in _118){ | |
2151 | _119.style[name]=_118[name]; | |
b0c3b730 | 2152 | } |
b2a516b8 | 2153 | var pa=this.graphDiv; |
bd597afc DV |
2154 | pa.appendChild(_119); |
2155 | var _121=this; | |
2156 | _119.onchange=function(){ | |
2157 | _121.adjustRoll(_119.value); | |
76171648 | 2158 | }; |
bd597afc | 2159 | return _119; |
76171648 DV |
2160 | }; |
2161 | Dygraph.pageX=function(e){ | |
2162 | if(e.pageX){ | |
2163 | return (!e.pageX||e.pageX<0)?0:e.pageX; | |
2164 | }else{ | |
2165 | var de=document; | |
2166 | var b=document.body; | |
2167 | return e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0); | |
2168 | } | |
2169 | }; | |
2170 | Dygraph.pageY=function(e){ | |
2171 | if(e.pageY){ | |
2172 | return (!e.pageY||e.pageY<0)?0:e.pageY; | |
2173 | }else{ | |
2174 | var de=document; | |
2175 | var b=document.body; | |
2176 | return e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); | |
2177 | } | |
285a6bda DV |
2178 | }; |
2179 | Dygraph.prototype.createDragInterface_=function(){ | |
fbe31dc8 | 2180 | var self=this; |
bd597afc | 2181 | var _125=false; |
76171648 DV |
2182 | var _126=null; |
2183 | var _127=null; | |
bd597afc DV |
2184 | var _128=null; |
2185 | var _129=null; | |
2186 | var _130=null; | |
353a0294 DV |
2187 | var px=0; |
2188 | var py=0; | |
efe0829a | 2189 | var getX=function(e){ |
76171648 | 2190 | return Dygraph.pageX(e)-px; |
b2a516b8 | 2191 | }; |
efe0829a | 2192 | var getY=function(e){ |
76171648 | 2193 | return Dygraph.pageX(e)-py; |
b2a516b8 | 2194 | }; |
bd597afc DV |
2195 | Dygraph.addEvent(this.hidden_,"mousemove",function(_135){ |
2196 | if(_125){ | |
2197 | _128=getX(_135); | |
2198 | _129=getY(_135); | |
2199 | self.drawZoomRect_(_126,_128,_130); | |
2200 | _130=_128; | |
6a1aa64f | 2201 | } |
b2a516b8 | 2202 | }); |
bd597afc DV |
2203 | Dygraph.addEvent(this.hidden_,"mousedown",function(_136){ |
2204 | _125=true; | |
3df0ccf0 DV |
2205 | px=Dygraph.findPosX(self.canvas_); |
2206 | py=Dygraph.findPosY(self.canvas_); | |
bd597afc DV |
2207 | _126=getX(_136); |
2208 | _127=getY(_136); | |
b2a516b8 | 2209 | }); |
bd597afc DV |
2210 | Dygraph.addEvent(document,"mouseup",function(_137){ |
2211 | if(_125){ | |
2212 | _125=false; | |
2213 | _126=null; | |
2214 | _127=null; | |
6a1aa64f | 2215 | } |
b2a516b8 | 2216 | }); |
bd597afc DV |
2217 | Dygraph.addEvent(this.hidden_,"mouseout",function(_138){ |
2218 | if(_125){ | |
2219 | _128=null; | |
2220 | _129=null; | |
6a1aa64f | 2221 | } |
b2a516b8 | 2222 | }); |
bd597afc DV |
2223 | Dygraph.addEvent(this.hidden_,"mouseup",function(_139){ |
2224 | if(_125){ | |
2225 | _125=false; | |
2226 | _128=getX(_139); | |
2227 | _129=getY(_139); | |
2228 | var _140=Math.abs(_128-_126); | |
2229 | var _141=Math.abs(_129-_127); | |
2230 | if(_140<2&&_141<2&&self.attr_("clickCallback")!=null&&self.lastx_!=undefined){ | |
2231 | self.attr_("clickCallback")(_139,new Date(self.lastx_)); | |
2232 | } | |
2233 | if(_140>=10){ | |
2234 | self.doZoom_(Math.min(_126,_128),Math.max(_126,_128)); | |
b2a516b8 | 2235 | }else{ |
fbe31dc8 | 2236 | self.canvas_.getContext("2d").clearRect(0,0,self.canvas_.width,self.canvas_.height); |
b2a516b8 | 2237 | } |
bd597afc DV |
2238 | _126=null; |
2239 | _127=null; | |
b2a516b8 DV |
2240 | } |
2241 | }); | |
bd597afc | 2242 | Dygraph.addEvent(this.hidden_,"dblclick",function(_142){ |
fbe31dc8 DV |
2243 | self.dateWindow_=null; |
2244 | self.drawGraph_(self.rawData_); | |
bd597afc DV |
2245 | var _143=self.rawData_[0][0]; |
2246 | var _144=self.rawData_[self.rawData_.length-1][0]; | |
fbe31dc8 | 2247 | if(self.attr_("zoomCallback")){ |
bd597afc | 2248 | self.attr_("zoomCallback")(_143,_144); |
67e650dc | 2249 | } |
b2a516b8 | 2250 | }); |
6a1aa64f | 2251 | }; |
bd597afc | 2252 | Dygraph.prototype.drawZoomRect_=function(_145,endX,_147){ |
b2a516b8 | 2253 | var ctx=this.canvas_.getContext("2d"); |
bd597afc DV |
2254 | if(_147){ |
2255 | ctx.clearRect(Math.min(_145,_147),0,Math.abs(_145-_147),this.height_); | |
b2a516b8 | 2256 | } |
bd597afc | 2257 | if(endX&&_145){ |
b2a516b8 | 2258 | ctx.fillStyle="rgba(128,128,128,0.33)"; |
bd597afc | 2259 | ctx.fillRect(Math.min(_145,endX),0,Math.abs(endX-_145),this.height_); |
b2a516b8 DV |
2260 | } |
2261 | }; | |
bd597afc DV |
2262 | Dygraph.prototype.doZoom_=function(lowX,_149){ |
2263 | var _150=this.layout_.points; | |
2264 | var _151=null; | |
2265 | var _152=null; | |
2266 | for(var i=0;i<_150.length;i++){ | |
2267 | var cx=_150[i].canvasx; | |
2268 | var x=_150[i].xval; | |
2269 | if(cx<lowX&&(_151==null||x>_151)){ | |
2270 | _151=x; | |
b2a516b8 | 2271 | } |
bd597afc DV |
2272 | if(cx>_149&&(_152==null||x<_152)){ |
2273 | _152=x; | |
b2a516b8 | 2274 | } |
b2a516b8 | 2275 | } |
bd597afc DV |
2276 | if(_151==null){ |
2277 | _151=_150[0].xval; | |
b2a516b8 | 2278 | } |
bd597afc DV |
2279 | if(_152==null){ |
2280 | _152=_150[_150.length-1].xval; | |
b0c3b730 | 2281 | } |
bd597afc | 2282 | this.dateWindow_=[_151,_152]; |
b2a516b8 | 2283 | this.drawGraph_(this.rawData_); |
285a6bda | 2284 | if(this.attr_("zoomCallback")){ |
bd597afc | 2285 | this.attr_("zoomCallback")(_151,_152); |
67e650dc | 2286 | } |
b2a516b8 | 2287 | }; |
bd597afc DV |
2288 | Dygraph.prototype.mouseMove_=function(_154){ |
2289 | var _155=Dygraph.pageX(_154)-Dygraph.findPosX(this.hidden_); | |
2290 | var _156=this.layout_.points; | |
2291 | var _157=-1; | |
2292 | var _158=-1; | |
2293 | var _159=1e+100; | |
b2a516b8 | 2294 | var idx=-1; |
bd597afc DV |
2295 | for(var i=0;i<_156.length;i++){ |
2296 | var dist=Math.abs(_156[i].canvasx-_155); | |
2297 | if(dist>_159){ | |
b2a516b8 DV |
2298 | break; |
2299 | } | |
bd597afc | 2300 | _159=dist; |
b2a516b8 DV |
2301 | idx=i; |
2302 | } | |
2303 | if(idx>=0){ | |
bd597afc | 2304 | _157=_156[idx].xval; |
b2a516b8 | 2305 | } |
bd597afc DV |
2306 | if(_155>_156[_156.length-1].canvasx){ |
2307 | _157=_156[_156.length-1].xval; | |
b2a516b8 | 2308 | } |
bd597afc DV |
2309 | var _162=[]; |
2310 | for(var i=0;i<_156.length;i++){ | |
2311 | if(_156[i].xval==_157){ | |
2312 | _162.push(_156[i]); | |
b2a516b8 DV |
2313 | } |
2314 | } | |
bd597afc | 2315 | var _163=this.attr_("highlightCircleSize"); |
b2a516b8 DV |
2316 | var ctx=this.canvas_.getContext("2d"); |
2317 | if(this.previousVerticalX_>=0){ | |
2318 | var px=this.previousVerticalX_; | |
bd597afc | 2319 | ctx.clearRect(px-_163-1,0,2*_163+2,this.height_); |
b2a516b8 | 2320 | } |
648acd28 DV |
2321 | var isOK=function(x){ |
2322 | return x&&!isNaN(x); | |
2323 | }; | |
bd597afc DV |
2324 | if(_162.length>0){ |
2325 | var _155=_162[0].canvasx; | |
2326 | var _165=this.attr_("xValueFormatter")(_157,this)+":"; | |
b2a516b8 | 2327 | var clen=this.colors_.length; |
bd597afc DV |
2328 | for(var i=0;i<_162.length;i++){ |
2329 | if(!isOK(_162[i].canvasy)){ | |
648acd28 DV |
2330 | continue; |
2331 | } | |
285a6bda | 2332 | if(this.attr_("labelsSeparateLines")){ |
bd597afc | 2333 | _165+="<br/>"; |
b2a516b8 | 2334 | } |
bd597afc DV |
2335 | var _167=_162[i]; |
2336 | _165+=" <b><font color='"+this.colors_[i%clen].toHexString()+"'>"+_167.name+"</font></b>:"+this.round_(_167.yval,2); | |
b2a516b8 | 2337 | } |
bd597afc DV |
2338 | this.attr_("labelsDiv").innerHTML=_165; |
2339 | this.lastx_=_157; | |
b2a516b8 | 2340 | ctx.save(); |
bd597afc DV |
2341 | for(var i=0;i<_162.length;i++){ |
2342 | if(!isOK(_162[i%clen].canvasy)){ | |
648acd28 DV |
2343 | continue; |
2344 | } | |
b2a516b8 DV |
2345 | ctx.beginPath(); |
2346 | ctx.fillStyle=this.colors_[i%clen].toRGBString(); | |
bd597afc | 2347 | ctx.arc(_155,_162[i%clen].canvasy,_163,0,360,false); |
b2a516b8 DV |
2348 | ctx.fill(); |
2349 | } | |
2350 | ctx.restore(); | |
bd597afc | 2351 | this.previousVerticalX_=_155; |
b2a516b8 | 2352 | } |
6a1aa64f | 2353 | }; |
bd597afc | 2354 | Dygraph.prototype.mouseOut_=function(_168){ |
b2a516b8 DV |
2355 | var ctx=this.canvas_.getContext("2d"); |
2356 | ctx.clearRect(0,0,this.width_,this.height_); | |
285a6bda | 2357 | this.attr_("labelsDiv").innerHTML=""; |
6a1aa64f | 2358 | }; |
285a6bda | 2359 | Dygraph.zeropad=function(x){ |
6372d433 DV |
2360 | if(x<10){ |
2361 | return "0"+x; | |
2362 | }else{ | |
2363 | return ""+x; | |
2364 | } | |
2365 | }; | |
285a6bda | 2366 | Dygraph.prototype.hmsString_=function(date){ |
bd597afc | 2367 | var _170=Dygraph.zeropad; |
6372d433 DV |
2368 | var d=new Date(date); |
2369 | if(d.getSeconds()){ | |
bd597afc | 2370 | return _170(d.getHours())+":"+_170(d.getMinutes())+":"+_170(d.getSeconds()); |
6372d433 DV |
2371 | }else{ |
2372 | if(d.getMinutes()){ | |
bd597afc | 2373 | return _170(d.getHours())+":"+_170(d.getMinutes()); |
6372d433 | 2374 | }else{ |
bd597afc | 2375 | return _170(d.getHours()); |
6372d433 DV |
2376 | } |
2377 | } | |
2378 | }; | |
285a6bda | 2379 | Dygraph.dateString_=function(date,self){ |
bd597afc | 2380 | var _172=Dygraph.zeropad; |
b2a516b8 DV |
2381 | var d=new Date(date); |
2382 | var year=""+d.getFullYear(); | |
bd597afc DV |
2383 | var _174=_172(d.getMonth()+1); |
2384 | var day=_172(d.getDate()); | |
6372d433 DV |
2385 | var ret=""; |
2386 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
2387 | if(frac){ | |
285a6bda | 2388 | ret=" "+self.hmsString_(date); |
b2a516b8 | 2389 | } |
bd597afc | 2390 | return year+"/"+_174+"/"+day+ret; |
6a1aa64f | 2391 | }; |
bd597afc DV |
2392 | Dygraph.prototype.round_=function(num,_178){ |
2393 | var _179=Math.pow(10,_178); | |
2394 | return Math.round(num*_179)/_179; | |
6a1aa64f | 2395 | }; |
285a6bda | 2396 | Dygraph.prototype.loadedEvent_=function(data){ |
b2a516b8 DV |
2397 | this.rawData_=this.parseCSV_(data); |
2398 | this.drawGraph_(this.rawData_); | |
6a1aa64f | 2399 | }; |
285a6bda DV |
2400 | Dygraph.prototype.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; |
2401 | Dygraph.prototype.quarters=["Jan","Apr","Jul","Oct"]; | |
2402 | Dygraph.prototype.addXTicks_=function(){ | |
bd597afc | 2403 | var _181,endDate; |
b2a516b8 | 2404 | if(this.dateWindow_){ |
bd597afc | 2405 | _181=this.dateWindow_[0]; |
b2a516b8 DV |
2406 | endDate=this.dateWindow_[1]; |
2407 | }else{ | |
bd597afc | 2408 | _181=this.rawData_[0][0]; |
b2a516b8 DV |
2409 | endDate=this.rawData_[this.rawData_.length-1][0]; |
2410 | } | |
bd597afc DV |
2411 | var _182=this.attr_("xTicker")(_181,endDate,this); |
2412 | this.layout_.updateOptions({xTicks:_182}); | |
285a6bda DV |
2413 | }; |
2414 | Dygraph.SECONDLY=0; | |
2415 | Dygraph.TEN_SECONDLY=1; | |
2416 | Dygraph.THIRTY_SECONDLY=2; | |
2417 | Dygraph.MINUTELY=3; | |
2418 | Dygraph.TEN_MINUTELY=4; | |
2419 | Dygraph.THIRTY_MINUTELY=5; | |
2420 | Dygraph.HOURLY=6; | |
2421 | Dygraph.SIX_HOURLY=7; | |
2422 | Dygraph.DAILY=8; | |
2423 | Dygraph.WEEKLY=9; | |
2424 | Dygraph.MONTHLY=10; | |
2425 | Dygraph.QUARTERLY=11; | |
2426 | Dygraph.BIANNUAL=12; | |
2427 | Dygraph.ANNUAL=13; | |
2428 | Dygraph.DECADAL=14; | |
2429 | Dygraph.NUM_GRANULARITIES=15; | |
2430 | Dygraph.SHORT_SPACINGS=[]; | |
2431 | Dygraph.SHORT_SPACINGS[Dygraph.SECONDLY]=1000*1; | |
2432 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_SECONDLY]=1000*10; | |
2433 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_SECONDLY]=1000*30; | |
2434 | Dygraph.SHORT_SPACINGS[Dygraph.MINUTELY]=1000*60; | |
2435 | Dygraph.SHORT_SPACINGS[Dygraph.TEN_MINUTELY]=1000*60*10; | |
2436 | Dygraph.SHORT_SPACINGS[Dygraph.THIRTY_MINUTELY]=1000*60*30; | |
2437 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600; | |
2438 | Dygraph.SHORT_SPACINGS[Dygraph.HOURLY]=1000*3600*6; | |
2439 | Dygraph.SHORT_SPACINGS[Dygraph.DAILY]=1000*86400; | |
2440 | Dygraph.SHORT_SPACINGS[Dygraph.WEEKLY]=1000*604800; | |
bd597afc DV |
2441 | Dygraph.prototype.NumXTicks=function(_183,_184,_185){ |
2442 | if(_185<Dygraph.MONTHLY){ | |
2443 | var _186=Dygraph.SHORT_SPACINGS[_185]; | |
2444 | return Math.floor(0.5+1*(_184-_183)/_186); | |
285a6bda | 2445 | }else{ |
bd597afc DV |
2446 | var _187=1; |
2447 | var _188=12; | |
2448 | if(_185==Dygraph.QUARTERLY){ | |
2449 | _188=3; | |
285a6bda | 2450 | } |
bd597afc DV |
2451 | if(_185==Dygraph.BIANNUAL){ |
2452 | _188=2; | |
285a6bda | 2453 | } |
bd597afc DV |
2454 | if(_185==Dygraph.ANNUAL){ |
2455 | _188=1; | |
285a6bda | 2456 | } |
bd597afc DV |
2457 | if(_185==Dygraph.DECADAL){ |
2458 | _188=1; | |
2459 | _187=10; | |
285a6bda | 2460 | } |
bd597afc DV |
2461 | var _189=365.2524*24*3600*1000; |
2462 | var _190=1*(_184-_183)/_189; | |
2463 | return Math.floor(0.5+1*_190*_188/_187); | |
285a6bda DV |
2464 | } |
2465 | }; | |
bd597afc DV |
2466 | Dygraph.prototype.GetXAxis=function(_191,_192,_193){ |
2467 | var _194=[]; | |
2468 | if(_193<Dygraph.MONTHLY){ | |
2469 | var _195=Dygraph.SHORT_SPACINGS[_193]; | |
2470 | var _196="%d%b"; | |
2471 | if(_193<Dygraph.HOURLY){ | |
2472 | _191=_195*Math.floor(0.5+_191/_195); | |
2473 | } | |
2474 | for(var t=_191;t<=_192;t+=_195){ | |
36615faf DV |
2475 | var d=new Date(t); |
2476 | var frac=d.getHours()*3600+d.getMinutes()*60+d.getSeconds(); | |
bd597afc DV |
2477 | if(frac==0||_193>=Dygraph.DAILY){ |
2478 | _194.push({v:t,label:new Date(t+3600*1000).strftime(_196)}); | |
b2a516b8 | 2479 | }else{ |
bd597afc | 2480 | _194.push({v:t,label:this.hmsString_(t)}); |
36615faf DV |
2481 | } |
2482 | } | |
b2a516b8 | 2483 | }else{ |
bd597afc DV |
2484 | var _198; |
2485 | var _199=1; | |
2486 | if(_193==Dygraph.MONTHLY){ | |
2487 | _198=[0,1,2,3,4,5,6,7,8,9,10,11,12]; | |
b2a516b8 | 2488 | }else{ |
bd597afc DV |
2489 | if(_193==Dygraph.QUARTERLY){ |
2490 | _198=[0,3,6,9]; | |
b2a516b8 | 2491 | }else{ |
bd597afc DV |
2492 | if(_193==Dygraph.BIANNUAL){ |
2493 | _198=[0,6]; | |
b2a516b8 | 2494 | }else{ |
bd597afc DV |
2495 | if(_193==Dygraph.ANNUAL){ |
2496 | _198=[0]; | |
6372d433 | 2497 | }else{ |
bd597afc DV |
2498 | if(_193==Dygraph.DECADAL){ |
2499 | _198=[0]; | |
2500 | _199=10; | |
b2a516b8 DV |
2501 | } |
2502 | } | |
2503 | } | |
2504 | } | |
6372d433 | 2505 | } |
bd597afc DV |
2506 | var _200=new Date(_191).getFullYear(); |
2507 | var _201=new Date(_192).getFullYear(); | |
2508 | var _202=Dygraph.zeropad; | |
2509 | for(var i=_200;i<=_201;i++){ | |
2510 | if(i%_199!=0){ | |
36615faf | 2511 | continue; |
6372d433 | 2512 | } |
bd597afc DV |
2513 | for(var j=0;j<_198.length;j++){ |
2514 | var _203=i+"/"+_202(1+_198[j])+"/01"; | |
2515 | var t=Date.parse(_203); | |
2516 | if(t<_191||t>_192){ | |
b2a516b8 DV |
2517 | continue; |
2518 | } | |
bd597afc | 2519 | _194.push({v:t,label:new Date(t).strftime("%b %y")}); |
b2a516b8 DV |
2520 | } |
2521 | } | |
b2a516b8 | 2522 | } |
bd597afc | 2523 | return _194; |
36615faf | 2524 | }; |
bd597afc DV |
2525 | Dygraph.dateTicker=function(_204,_205,self){ |
2526 | var _206=-1; | |
285a6bda | 2527 | for(var i=0;i<Dygraph.NUM_GRANULARITIES;i++){ |
bd597afc DV |
2528 | var _207=self.NumXTicks(_204,_205,i); |
2529 | if(self.width_/_207>=self.attr_("pixelsPerXLabel")){ | |
2530 | _206=i; | |
36615faf DV |
2531 | break; |
2532 | } | |
b2a516b8 | 2533 | } |
bd597afc DV |
2534 | if(_206>=0){ |
2535 | return self.GetXAxis(_204,_205,_206); | |
36615faf | 2536 | }else{ |
6372d433 | 2537 | } |
6a1aa64f | 2538 | }; |
285a6bda | 2539 | Dygraph.numericTicks=function(minV,maxV,self){ |
bd597afc DV |
2540 | var _210=[1,2,5]; |
2541 | var _211,low_val,high_val,nTicks; | |
2542 | var _212=self.attr_("pixelsPerYLabel"); | |
2ce09b19 | 2543 | for(var i=-10;i<50;i++){ |
bd597afc DV |
2544 | var _213=Math.pow(10,i); |
2545 | for(var j=0;j<_210.length;j++){ | |
2546 | _211=_213*_210[j]; | |
2547 | low_val=Math.floor(minV/_211)*_211; | |
2548 | high_val=Math.ceil(maxV/_211)*_211; | |
2549 | nTicks=(high_val-low_val)/_211; | |
2550 | var _214=self.height_/nTicks; | |
2551 | if(_214>_212){ | |
2ce09b19 | 2552 | break; |
6a1aa64f | 2553 | } |
b2a516b8 | 2554 | } |
bd597afc | 2555 | if(_214>_212){ |
2ce09b19 | 2556 | break; |
b2a516b8 | 2557 | } |
2ce09b19 | 2558 | } |
bd597afc | 2559 | var _215=[]; |
2ce09b19 | 2560 | for(var i=0;i<nTicks;i++){ |
bd597afc DV |
2561 | var _216=low_val+i*_211; |
2562 | var _217=self.round_(_216,2); | |
285a6bda | 2563 | if(self.attr_("labelsKMB")){ |
b2a516b8 | 2564 | var k=1000; |
bd597afc DV |
2565 | if(_216>=k*k*k){ |
2566 | _217=self.round_(_216/(k*k*k),1)+"B"; | |
b2a516b8 | 2567 | }else{ |
bd597afc DV |
2568 | if(_216>=k*k){ |
2569 | _217=self.round_(_216/(k*k),1)+"M"; | |
b2a516b8 | 2570 | }else{ |
bd597afc DV |
2571 | if(_216>=k){ |
2572 | _217=self.round_(_216/k,1)+"K"; | |
b2a516b8 DV |
2573 | } |
2574 | } | |
2575 | } | |
2576 | } | |
bd597afc | 2577 | _215.push({label:_217,v:_216}); |
b2a516b8 | 2578 | } |
bd597afc | 2579 | return _215; |
6a1aa64f | 2580 | }; |
285a6bda | 2581 | Dygraph.prototype.addYTicks_=function(minY,maxY){ |
bd597afc DV |
2582 | var _221=Dygraph.numericTicks(minY,maxY,this); |
2583 | this.layout_.updateOptions({yAxis:[minY,maxY],yTicks:_221}); | |
6a1aa64f | 2584 | }; |
bd597afc | 2585 | Dygraph.prototype.extremeValues_=function(_222){ |
e4007107 | 2586 | var minY=null,maxY=null; |
b64a4f1a | 2587 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
648acd28 | 2588 | if(bars){ |
bd597afc DV |
2589 | for(var j=0;j<_222.length;j++){ |
2590 | var y=_222[j][1][0]; | |
648acd28 DV |
2591 | if(!y){ |
2592 | continue; | |
e4007107 | 2593 | } |
bd597afc DV |
2594 | var low=y-_222[j][1][1]; |
2595 | var high=y+_222[j][1][2]; | |
648acd28 DV |
2596 | if(low>y){ |
2597 | low=y; | |
b2a516b8 | 2598 | } |
648acd28 DV |
2599 | if(high<y){ |
2600 | high=y; | |
b2a516b8 | 2601 | } |
648acd28 DV |
2602 | if(maxY==null||high>maxY){ |
2603 | maxY=high; | |
285a6bda | 2604 | } |
648acd28 DV |
2605 | if(minY==null||low<minY){ |
2606 | minY=low; | |
e4007107 | 2607 | } |
285a6bda | 2608 | } |
b2a516b8 | 2609 | }else{ |
bd597afc DV |
2610 | for(var j=0;j<_222.length;j++){ |
2611 | var y=_222[j][1]; | |
648acd28 DV |
2612 | if(!y){ |
2613 | continue; | |
285a6bda | 2614 | } |
b2a516b8 | 2615 | if(maxY==null||y>maxY){ |
285a6bda DV |
2616 | maxY=y; |
2617 | } | |
e4007107 DV |
2618 | if(minY==null||y<minY){ |
2619 | minY=y; | |
2620 | } | |
b2a516b8 DV |
2621 | } |
2622 | } | |
648acd28 DV |
2623 | return [minY,maxY]; |
2624 | }; | |
2625 | Dygraph.prototype.drawGraph_=function(data){ | |
2626 | var minY=null,maxY=null; | |
2627 | this.layout_.removeAllDatasets(); | |
2628 | this.setColors_(); | |
9317362d | 2629 | this.attrs_["pointSize"]=0.5*this.attr_("highlightCircleSize"); |
648acd28 | 2630 | for(var i=1;i<data[0].length;i++){ |
bd597afc | 2631 | var _226=[]; |
648acd28 DV |
2632 | for(var j=0;j<data.length;j++){ |
2633 | var date=data[j][0]; | |
bd597afc | 2634 | _226[j]=[date,data[j][i]]; |
648acd28 | 2635 | } |
bd597afc | 2636 | _226=this.rollingAverage(_226,this.rollPeriod_); |
b64a4f1a | 2637 | var bars=this.attr_("errorBars")||this.attr_("customBars"); |
648acd28 DV |
2638 | if(this.dateWindow_){ |
2639 | var low=this.dateWindow_[0]; | |
2640 | var high=this.dateWindow_[1]; | |
bd597afc DV |
2641 | var _227=[]; |
2642 | for(var k=0;k<_226.length;k++){ | |
2643 | if(_226[k][0]>=low&&_226[k][0]<=high){ | |
2644 | _227.push(_226[k]); | |
648acd28 DV |
2645 | } |
2646 | } | |
bd597afc | 2647 | _226=_227; |
648acd28 | 2648 | } |
bd597afc DV |
2649 | var _228=this.extremeValues_(_226); |
2650 | var _229=_228[0]; | |
2651 | var _230=_228[1]; | |
2652 | if(!minY||_229<minY){ | |
2653 | minY=_229; | |
648acd28 | 2654 | } |
bd597afc DV |
2655 | if(!maxY||_230>maxY){ |
2656 | maxY=_230; | |
b2a516b8 DV |
2657 | } |
2658 | if(bars){ | |
2659 | var vals=[]; | |
bd597afc DV |
2660 | for(var j=0;j<_226.length;j++){ |
2661 | vals[j]=[_226[j][0],_226[j][1][0],_226[j][1][1],_226[j][1][2]]; | |
b2a516b8 | 2662 | } |
285a6bda | 2663 | this.layout_.addDataset(this.attr_("labels")[i],vals); |
b2a516b8 | 2664 | }else{ |
bd597afc | 2665 | this.layout_.addDataset(this.attr_("labels")[i],_226); |
b2a516b8 DV |
2666 | } |
2667 | } | |
2668 | if(this.valueRange_!=null){ | |
2669 | this.addYTicks_(this.valueRange_[0],this.valueRange_[1]); | |
2670 | }else{ | |
e4007107 | 2671 | var span=maxY-minY; |
bd597afc DV |
2672 | var _233=maxY+0.1*span; |
2673 | var _234=minY-0.1*span; | |
2674 | if(_234<0&&minY>=0){ | |
2675 | _234=0; | |
e4007107 | 2676 | } |
bd597afc DV |
2677 | if(_233>0&&maxY<=0){ |
2678 | _233=0; | |
e4007107 DV |
2679 | } |
2680 | if(this.attr_("includeZero")){ | |
2681 | if(maxY<0){ | |
bd597afc | 2682 | _233=0; |
e4007107 DV |
2683 | } |
2684 | if(minY>0){ | |
bd597afc | 2685 | _234=0; |
e4007107 | 2686 | } |
b2a516b8 | 2687 | } |
bd597afc | 2688 | this.addYTicks_(_234,_233); |
b2a516b8 DV |
2689 | } |
2690 | this.addXTicks_(); | |
2691 | this.layout_.evaluateWithError(); | |
2692 | this.plotter_.clear(); | |
2693 | this.plotter_.render(); | |
2694 | this.canvas_.getContext("2d").clearRect(0,0,this.canvas_.width,this.canvas_.height); | |
6a1aa64f | 2695 | }; |
bd597afc DV |
2696 | Dygraph.prototype.rollingAverage=function(_235,_236){ |
2697 | if(_235.length<2){ | |
2698 | return _235; | |
b2a516b8 | 2699 | } |
bd597afc DV |
2700 | var _236=Math.min(_236,_235.length-1); |
2701 | var _237=[]; | |
2702 | var _238=this.attr_("sigma"); | |
b2a516b8 DV |
2703 | if(this.fractions_){ |
2704 | var num=0; | |
2705 | var den=0; | |
2706 | var mult=100; | |
bd597afc DV |
2707 | for(var i=0;i<_235.length;i++){ |
2708 | num+=_235[i][1][0]; | |
2709 | den+=_235[i][1][1]; | |
2710 | if(i-_236>=0){ | |
2711 | num-=_235[i-_236][1][0]; | |
2712 | den-=_235[i-_236][1][1]; | |
2713 | } | |
2714 | var date=_235[i][0]; | |
2715 | var _241=den?num/den:0; | |
285a6bda | 2716 | if(this.attr_("errorBars")){ |
b2a516b8 DV |
2717 | if(this.wilsonInterval_){ |
2718 | if(den){ | |
bd597afc DV |
2719 | var p=_241<0?0:_241,n=den; |
2720 | var pm=_238*Math.sqrt(p*(1-p)/n+_238*_238/(4*n*n)); | |
2721 | var _244=1+_238*_238/den; | |
2722 | var low=(p+_238*_238/(2*den)-pm)/_244; | |
2723 | var high=(p+_238*_238/(2*den)+pm)/_244; | |
2724 | _237[i]=[date,[p*mult,(p-low)*mult,(high-p)*mult]]; | |
b2a516b8 | 2725 | }else{ |
bd597afc | 2726 | _237[i]=[date,[0,0,0]]; |
b2a516b8 DV |
2727 | } |
2728 | }else{ | |
bd597afc DV |
2729 | var _245=den?_238*Math.sqrt(_241*(1-_241)/den):1; |
2730 | _237[i]=[date,[mult*_241,mult*_245,mult*_245]]; | |
b2a516b8 DV |
2731 | } |
2732 | }else{ | |
bd597afc | 2733 | _237[i]=[date,mult*_241]; |
b2a516b8 DV |
2734 | } |
2735 | } | |
2736 | }else{ | |
b64a4f1a | 2737 | if(this.attr_("customBars")){ |
6372d433 DV |
2738 | var low=0; |
2739 | var mid=0; | |
2740 | var high=0; | |
bd597afc DV |
2741 | var _247=0; |
2742 | for(var i=0;i<_235.length;i++){ | |
2743 | var data=_235[i][1]; | |
b2a516b8 | 2744 | var y=data[1]; |
bd597afc | 2745 | _237[i]=[_235[i][0],[y,y-data[0],data[2]-y]]; |
6372d433 DV |
2746 | low+=data[0]; |
2747 | mid+=y; | |
2748 | high+=data[2]; | |
bd597afc DV |
2749 | _247+=1; |
2750 | if(i-_236>=0){ | |
2751 | var prev=_235[i-_236]; | |
6372d433 DV |
2752 | low-=prev[1][0]; |
2753 | mid-=prev[1][1]; | |
2754 | high-=prev[1][2]; | |
bd597afc | 2755 | _247-=1; |
6372d433 | 2756 | } |
bd597afc | 2757 | _237[i]=[_235[i][0],[1*mid/_247,1*(mid-low)/_247,1*(high-mid)/_247]]; |
6372d433 DV |
2758 | } |
2759 | }else{ | |
bd597afc | 2760 | var _249=Math.min(_236-1,_235.length-2); |
285a6bda | 2761 | if(!this.attr_("errorBars")){ |
bd597afc DV |
2762 | if(_236==1){ |
2763 | return _235; | |
648acd28 | 2764 | } |
bd597afc | 2765 | for(var i=0;i<_235.length;i++){ |
b2a516b8 | 2766 | var sum=0; |
bd597afc DV |
2767 | var _251=0; |
2768 | for(var j=Math.max(0,i-_236+1);j<i+1;j++){ | |
2769 | var y=_235[j][1]; | |
648acd28 DV |
2770 | if(!y||isNaN(y)){ |
2771 | continue; | |
b2a516b8 | 2772 | } |
bd597afc DV |
2773 | _251++; |
2774 | sum+=_235[j][1]; | |
648acd28 | 2775 | } |
bd597afc DV |
2776 | if(_251){ |
2777 | _237[i]=[_235[i][0],sum/_251]; | |
648acd28 | 2778 | }else{ |
bd597afc | 2779 | _237[i]=[_235[i][0],null]; |
b2a516b8 | 2780 | } |
648acd28 | 2781 | } |
2847c1cf | 2782 | }else{ |
bd597afc | 2783 | for(var i=0;i<_235.length;i++){ |
b2a516b8 | 2784 | var sum=0; |
bd597afc DV |
2785 | var _252=0; |
2786 | var _251=0; | |
2787 | for(var j=Math.max(0,i-_236+1);j<i+1;j++){ | |
2788 | var y=_235[j][1][0]; | |
648acd28 DV |
2789 | if(!y||isNaN(y)){ |
2790 | continue; | |
b2a516b8 | 2791 | } |
bd597afc DV |
2792 | _251++; |
2793 | sum+=_235[j][1][0]; | |
2794 | _252+=Math.pow(_235[j][1][1],2); | |
b2a516b8 | 2795 | } |
bd597afc DV |
2796 | if(_251){ |
2797 | var _245=Math.sqrt(_252)/_251; | |
2798 | _237[i]=[_235[i][0],[sum/_251,_238*_245,_238*_245]]; | |
648acd28 | 2799 | }else{ |
bd597afc | 2800 | _237[i]=[_235[i][0],[null,null,null]]; |
b2a516b8 DV |
2801 | } |
2802 | } | |
2803 | } | |
648acd28 DV |
2804 | } |
2805 | } | |
bd597afc | 2806 | return _237; |
6a1aa64f | 2807 | }; |
bd597afc DV |
2808 | Dygraph.dateParser=function(_253,self){ |
2809 | var _254; | |
285a6bda | 2810 | var d; |
bd597afc DV |
2811 | if(_253.length==10&&_253.search("-")!=-1){ |
2812 | _254=_253.replace("-","/","g"); | |
2813 | while(_254.search("-")!=-1){ | |
2814 | _254=_254.replace("-","/"); | |
353a0294 | 2815 | } |
bd597afc | 2816 | d=Date.parse(_254); |
b2a516b8 | 2817 | }else{ |
bd597afc DV |
2818 | if(_253.length==8){ |
2819 | _254=_253.substr(0,4)+"/"+_253.substr(4,2)+"/"+_253.substr(6,2); | |
2820 | d=Date.parse(_254); | |
8846615a | 2821 | }else{ |
bd597afc | 2822 | d=Date.parse(_253); |
285a6bda | 2823 | } |
b2a516b8 | 2824 | } |
285a6bda | 2825 | if(!d||isNaN(d)){ |
bd597afc | 2826 | self.error("Couldn't parse "+_253+" as a date"); |
b2a516b8 | 2827 | } |
285a6bda | 2828 | return d; |
6a1aa64f | 2829 | }; |
285a6bda | 2830 | Dygraph.prototype.detectTypeFromString_=function(str){ |
bd597afc | 2831 | var _256=false; |
285a6bda | 2832 | if(str.indexOf("-")>=0||str.indexOf("/")>=0||isNaN(parseFloat(str))){ |
bd597afc | 2833 | _256=true; |
285a6bda DV |
2834 | }else{ |
2835 | if(str.length==8&&str>"19700101"&&str<"20371231"){ | |
bd597afc | 2836 | _256=true; |
285a6bda DV |
2837 | } |
2838 | } | |
bd597afc | 2839 | if(_256){ |
285a6bda DV |
2840 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
2841 | this.attrs_.xValueParser=Dygraph.dateParser; | |
2842 | this.attrs_.xTicker=Dygraph.dateTicker; | |
2843 | }else{ | |
2844 | this.attrs_.xValueFormatter=function(x){ | |
2845 | return x; | |
2846 | }; | |
2847 | this.attrs_.xValueParser=function(x){ | |
2848 | return parseFloat(x); | |
2849 | }; | |
2850 | this.attrs_.xTicker=Dygraph.numericTicks; | |
2851 | } | |
2852 | }; | |
2853 | Dygraph.prototype.parseCSV_=function(data){ | |
b2a516b8 | 2854 | var ret=[]; |
bd597afc DV |
2855 | var _257=data.split("\n"); |
2856 | var _258=0; | |
b2a516b8 | 2857 | if(this.labelsFromCSV_){ |
bd597afc DV |
2858 | _258=1; |
2859 | this.attrs_.labels=_257[0].split(","); | |
2860 | } | |
2861 | var _259; | |
2862 | var _260=false; | |
2863 | var _261=this.attr_("labels").length; | |
2864 | for(var i=_258;i<_257.length;i++){ | |
2865 | var line=_257[i]; | |
b2a516b8 DV |
2866 | if(line.length==0){ |
2867 | continue; | |
2868 | } | |
bd597afc DV |
2869 | var _263=line.split(","); |
2870 | if(_263.length<2){ | |
b2a516b8 DV |
2871 | continue; |
2872 | } | |
bd597afc DV |
2873 | var _264=[]; |
2874 | if(!_260){ | |
2875 | this.detectTypeFromString_(_263[0]); | |
2876 | _259=this.attr_("xValueParser"); | |
2877 | _260=true; | |
285a6bda | 2878 | } |
bd597afc | 2879 | _264[0]=_259(_263[0],this); |
b2a516b8 | 2880 | if(this.fractions_){ |
bd597afc DV |
2881 | for(var j=1;j<_263.length;j++){ |
2882 | var vals=_263[j].split("/"); | |
2883 | _264[j]=[parseFloat(vals[0]),parseFloat(vals[1])]; | |
b2a516b8 DV |
2884 | } |
2885 | }else{ | |
285a6bda | 2886 | if(this.attr_("errorBars")){ |
bd597afc DV |
2887 | for(var j=1;j<_263.length;j+=2){ |
2888 | _264[(j+1)/2]=[parseFloat(_263[j]),parseFloat(_263[j+1])]; | |
b2a516b8 DV |
2889 | } |
2890 | }else{ | |
b64a4f1a | 2891 | if(this.attr_("customBars")){ |
bd597afc DV |
2892 | for(var j=1;j<_263.length;j++){ |
2893 | var vals=_263[j].split(";"); | |
2894 | _264[j]=[parseFloat(vals[0]),parseFloat(vals[1]),parseFloat(vals[2])]; | |
b2a516b8 DV |
2895 | } |
2896 | }else{ | |
bd597afc DV |
2897 | for(var j=1;j<_263.length;j++){ |
2898 | _264[j]=parseFloat(_263[j]); | |
285a6bda | 2899 | } |
b2a516b8 DV |
2900 | } |
2901 | } | |
2902 | } | |
bd597afc DV |
2903 | ret.push(_264); |
2904 | if(_264.length!=_261){ | |
2905 | this.error("Number of columns in line "+i+" ("+_264.length+") does not agree with number of labels ("+_261+") "+line); | |
b2a516b8 | 2906 | } |
b2a516b8 DV |
2907 | } |
2908 | return ret; | |
6a1aa64f | 2909 | }; |
285a6bda DV |
2910 | Dygraph.prototype.parseArray_=function(data){ |
2911 | if(data.length==0){ | |
2912 | this.error("Can't plot empty data set"); | |
2913 | return null; | |
2914 | } | |
2915 | if(data[0].length==0){ | |
2916 | this.error("Data set cannot contain an empty row"); | |
2917 | return null; | |
2918 | } | |
2919 | if(this.attr_("labels")==null){ | |
2920 | this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter"); | |
2921 | this.attrs_.labels=["X"]; | |
2922 | for(var i=1;i<data[0].length;i++){ | |
2923 | this.attrs_.labels.push("Y"+i); | |
2924 | } | |
2925 | } | |
2926 | if(MochiKit.Base.isDateLike(data[0][0])){ | |
2927 | this.attrs_.xValueFormatter=Dygraph.dateString_; | |
2928 | this.attrs_.xTicker=Dygraph.dateTicker; | |
bd597afc | 2929 | var _265=MochiKit.Base.clone(data); |
285a6bda | 2930 | for(var i=0;i<data.length;i++){ |
bd597afc | 2931 | if(_265[i].length==0){ |
285a6bda DV |
2932 | this.error("Row "<<(1+i)<<" of data is empty"); |
2933 | return null; | |
2934 | } | |
bd597afc | 2935 | if(_265[i][0]==null||typeof (_265[i][0].getTime)!="function"){ |
285a6bda DV |
2936 | this.error("x value in row "<<(1+i)<<" is not a Date"); |
2937 | return null; | |
2938 | } | |
bd597afc | 2939 | _265[i][0]=_265[i][0].getTime(); |
285a6bda | 2940 | } |
bd597afc | 2941 | return _265; |
285a6bda DV |
2942 | }else{ |
2943 | this.attrs_.xValueFormatter=function(x){ | |
2944 | return x; | |
2945 | }; | |
2946 | this.attrs_.xTicker=Dygraph.numericTicks; | |
2947 | return data; | |
2948 | } | |
2949 | }; | |
2950 | Dygraph.prototype.parseDataTable_=function(data){ | |
6219c9d6 DV |
2951 | var cols=data.getNumberOfColumns(); |
2952 | var rows=data.getNumberOfRows(); | |
bd597afc | 2953 | var _268=[]; |
6219c9d6 | 2954 | for(var i=0;i<cols;i++){ |
bd597afc | 2955 | _268.push(data.getColumnLabel(i)); |
6219c9d6 | 2956 | } |
bd597afc DV |
2957 | this.attrs_.labels=_268; |
2958 | var _269=data.getColumnType(0); | |
2959 | if(_269=="date"){ | |
285a6bda DV |
2960 | this.attrs_.xValueFormatter=Dygraph.dateString_; |
2961 | this.attrs_.xValueParser=Dygraph.dateParser; | |
2962 | this.attrs_.xTicker=Dygraph.dateTicker; | |
2963 | }else{ | |
bd597afc | 2964 | if(_269=="number"){ |
285a6bda DV |
2965 | this.attrs_.xValueFormatter=function(x){ |
2966 | return x; | |
2967 | }; | |
2968 | this.attrs_.xValueParser=function(x){ | |
2969 | return parseFloat(x); | |
2970 | }; | |
2971 | this.attrs_.xTicker=Dygraph.numericTicks; | |
2972 | }else{ | |
bd597afc | 2973 | this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_269+"')"); |
6219c9d6 DV |
2974 | return null; |
2975 | } | |
285a6bda | 2976 | } |
6219c9d6 DV |
2977 | var ret=[]; |
2978 | for(var i=0;i<rows;i++){ | |
2979 | var row=[]; | |
b3b20e24 DV |
2980 | if(!data.getValue(i,0)){ |
2981 | continue; | |
2982 | } | |
bd597afc | 2983 | if(_269=="date"){ |
6219c9d6 | 2984 | row.push(data.getValue(i,0).getTime()); |
36615faf DV |
2985 | }else{ |
2986 | row.push(data.getValue(i,0)); | |
2987 | } | |
6219c9d6 DV |
2988 | for(var j=1;j<cols;j++){ |
2989 | row.push(data.getValue(i,j)); | |
2990 | } | |
2991 | ret.push(row); | |
2992 | } | |
2993 | return ret; | |
2994 | }; | |
285a6bda | 2995 | Dygraph.prototype.start_=function(){ |
b2a516b8 DV |
2996 | if(typeof this.file_=="function"){ |
2997 | this.loadedEvent_(this.file_()); | |
2998 | }else{ | |
285a6bda DV |
2999 | if(MochiKit.Base.isArrayLike(this.file_)){ |
3000 | this.rawData_=this.parseArray_(this.file_); | |
3001 | this.drawGraph_(this.rawData_); | |
3002 | }else{ | |
6219c9d6 DV |
3003 | if(typeof this.file_=="object"&&typeof this.file_.getColumnRange=="function"){ |
3004 | this.rawData_=this.parseDataTable_(this.file_); | |
3005 | this.drawGraph_(this.rawData_); | |
3006 | }else{ | |
285a6bda DV |
3007 | if(typeof this.file_=="string"){ |
3008 | if(this.file_.indexOf("\n")>=0){ | |
3009 | this.loadedEvent_(this.file_); | |
3010 | }else{ | |
b2a516b8 | 3011 | var req=new XMLHttpRequest(); |
bd597afc | 3012 | var _272=this; |
b2a516b8 DV |
3013 | req.onreadystatechange=function(){ |
3014 | if(req.readyState==4){ | |
3015 | if(req.status==200){ | |
bd597afc | 3016 | _272.loadedEvent_(req.responseText); |
b2a516b8 DV |
3017 | } |
3018 | } | |
6a1aa64f | 3019 | }; |
b2a516b8 DV |
3020 | req.open("GET",this.file_,true); |
3021 | req.send(null); | |
3022 | } | |
285a6bda DV |
3023 | }else{ |
3024 | this.error("Unknown data format: "+(typeof this.file_)); | |
6219c9d6 | 3025 | } |
b2a516b8 | 3026 | } |
b2a516b8 | 3027 | } |
b2a516b8 | 3028 | } |
285a6bda | 3029 | }; |
bd597afc DV |
3030 | Dygraph.prototype.updateOptions=function(_273){ |
3031 | if(_273.rollPeriod){ | |
3032 | this.rollPeriod_=_273.rollPeriod; | |
b2a516b8 | 3033 | } |
bd597afc DV |
3034 | if(_273.dateWindow){ |
3035 | this.dateWindow_=_273.dateWindow; | |
b2a516b8 | 3036 | } |
bd597afc DV |
3037 | if(_273.valueRange){ |
3038 | this.valueRange_=_273.valueRange; | |
b2a516b8 | 3039 | } |
bd597afc | 3040 | MochiKit.Base.update(this.user_attrs_,_273); |
285a6bda DV |
3041 | this.labelsFromCSV_=(this.attr_("labels")==null); |
3042 | this.layout_.updateOptions({"errorBars":this.attr_("errorBars")}); | |
bd597afc DV |
3043 | if(_273["file"]&&_273["file"]!=this.file_){ |
3044 | this.file_=_273["file"]; | |
b2a516b8 DV |
3045 | this.start_(); |
3046 | }else{ | |
3047 | this.drawGraph_(this.rawData_); | |
3048 | } | |
6a1aa64f | 3049 | }; |
bd597afc DV |
3050 | Dygraph.prototype.adjustRoll=function(_274){ |
3051 | this.rollPeriod_=_274; | |
b2a516b8 | 3052 | this.drawGraph_(this.rawData_); |
6a1aa64f | 3053 | }; |
bd597afc DV |
3054 | Dygraph.GVizChart=function(_275){ |
3055 | this.container=_275; | |
6219c9d6 | 3056 | }; |
bd597afc | 3057 | Dygraph.GVizChart.prototype.draw=function(data,_276){ |
6219c9d6 | 3058 | this.container.innerHTML=""; |
bd597afc | 3059 | this.date_graph=new Dygraph(this.container,data,_276); |
6219c9d6 | 3060 | }; |
285a6bda | 3061 | DateGraph=Dygraph; |
b2a516b8 | 3062 |