2f18ca47289b99ccf5ef98f9516ee5fbb2b4d469
1 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
};
2 DygraphLayout
=function(_1
,_2
){
5 MochiKit
.Base
.update(this.options
,_2
?_2
:{});
6 this.datasets
=new Array();
8 DygraphLayout
.prototype.attr_
=function(_3
){
9 return this.dygraph_
.attr_(_3
);
11 DygraphLayout
.prototype.addDataset
=function(_4
,_5
){
14 DygraphLayout
.prototype.evaluate
=function(){
15 this._evaluateLimits();
16 this._evaluateLineCharts();
17 this._evaluateLineTicks();
19 DygraphLayout
.prototype._evaluateLimits
=function(){
20 this.minxval
=this.maxxval
=null;
21 for(var _6
in this.datasets
){
22 var _7
=this.datasets
[_6
];
24 if(!this.minxval
||x1
<this.minxval
){
27 var x2
=_7
[_7
.length
-1][0];
28 if(!this.maxxval
||x2
>this.maxxval
){
32 this.xrange
=this.maxxval
-this.minxval
;
33 this.xscale
=(this.xrange
!=0?1/this.xrange
:1);
34 this.minyval
=this.options
.yAxis
[0];
35 this.maxyval
=this.options
.yAxis
[1];
36 this.yrange
=this.maxyval
-this.minyval
;
37 this.yscale
=(this.yrange
!=0?1/this.yrange
:1);
39 DygraphLayout
.prototype._evaluateLineCharts
=function(){
40 this.points
=new Array();
41 for(var _10
in this.datasets
){
42 var _11
=this.datasets
[_10
];
43 for(var j
=0;j
<_11
.length
;j
++){
45 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
};
52 if((_14
.x
>=0)&&(_14
.x
<=1)){
53 this.points
.push(_14
);
58 DygraphLayout
.prototype._evaluateLineTicks
=function(){
59 this.xticks
=new Array();
60 for(var i
=0;i
<this.options
.xTicks
.length
;i
++){
61 var _16
=this.options
.xTicks
[i
];
63 var pos
=this.xscale
*(_16
.v
-this.minxval
);
64 if((pos
>=0)&&(pos
<=1)){
65 this.xticks
.push([pos
,_17
]);
68 this.yticks
=new Array();
69 for(var i
=0;i
<this.options
.yTicks
.length
;i
++){
70 var _16
=this.options
.yTicks
[i
];
72 var pos
=1-(this.yscale
*(_16
.v
-this.minyval
));
73 if((pos
>=0)&&(pos
<=1)){
74 this.yticks
.push([pos
,_17
]);
78 DygraphLayout
.prototype.evaluateWithError
=function(){
80 if(!this.options
.errorBars
){
84 for(var _19
in this.datasets
){
86 var _20
=this.datasets
[_19
];
87 for(var j
=0;j
<_20
.length
;j
++,i
++){
89 var xv
=parseFloat(_21
[0]);
90 var yv
=parseFloat(_21
[1]);
91 if(xv
==this.points
[i
].xval
&&yv
==this.points
[i
].yval
){
92 this.points
[i
].errorMinus
=parseFloat(_21
[2]);
93 this.points
[i
].errorPlus
=parseFloat(_21
[3]);
98 DygraphLayout
.prototype.removeAllDatasets
=function(){
100 this.datasets
=new Array();
102 DygraphLayout
.prototype.updateOptions
=function(_24
){
103 MochiKit
.Base
.update(this.options
,_24
?_24
:{});
105 DygraphCanvasRenderer
=function(_25
,_26
,_27
,_28
){
107 this.options
={"strokeWidth":0.5,"drawXAxis":true,"drawYAxis":true,"axisLineColor":"black","axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":"black","axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"drawYGrid":true,"drawXGrid":true,"gridLineColor":"rgb(128,128,128)"};
108 MochiKit
.Base
.update(this.options
,_28
);
111 this.container
=this.element
.parentNode
;
112 this.isIE
=(/MSIE/.test(navigator
.userAgent
)&&!window
.opera
);
113 if(this.isIE
&&!isNil(G_vmlCanvasManager
)){
116 this.renderDelay
=null;
117 this.clearDelay
=null;
118 this.element
=G_vmlCanvasManager
.initElement(this.element
);
120 this.height
=this.element
.height
;
121 this.width
=this.element
.width
;
122 if(!this.isIE
&&!(DygraphCanvasRenderer
.isSupported(this.element
))){
123 throw "Canvas is not supported.";
125 this.xlabels
=new Array();
126 this.ylabels
=new Array();
127 this.area
={x
:this.options
.yAxisLabelWidth
+2*this.options
.axisTickSize
,y
:0};
128 this.area
.w
=this.width
-this.area
.x
-this.options
.rightGap
;
129 this.area
.h
=this.height
-this.options
.axisLabelFontSize
-2*this.options
.axisTickSize
;
130 this.container
.style
.position
="relative";
131 this.container
.style
.width
=this.width
+"px";
133 DygraphCanvasRenderer
.prototype.clear
=function(){
137 this.clearDelay
.cancel();
138 this.clearDelay
=null;
140 var _29
=this.element
.getContext("2d");
143 this.clearDelay
=MochiKit
.Async
.wait(this.IEDelay
);
144 this.clearDelay
.addCallback(bind(this.clear
,this));
148 var _29
=this.element
.getContext("2d");
149 _29
.clearRect(0,0,this.width
,this.height
);
150 for(var i
=0;i
<this.xlabels
.length
;i
++){
151 var el
=this.xlabels
[i
];
152 el
.parentNode
.removeChild(el
);
154 for(var i
=0;i
<this.ylabels
.length
;i
++){
155 var el
=this.ylabels
[i
];
156 el
.parentNode
.removeChild(el
);
158 this.xlabels
=new Array();
159 this.ylabels
=new Array();
161 DygraphCanvasRenderer
.isSupported
=function(_31
){
164 if(MochiKit
.Base
.isUndefinedOrNull(_31
)){
165 _32
=document
.createElement("canvas");
169 var _33
=_32
.getContext("2d");
172 var ie
=navigator
.appVersion
.match(/MSIE (\d\.\d)/);
173 var _35
=(navigator
.userAgent
.toLowerCase().indexOf("opera")!=-1);
174 if((!ie
)||(ie
[1]<6)||(_35
)){
181 DygraphCanvasRenderer
.prototype.render
=function(){
182 var ctx
=this.element
.getContext("2d");
183 if(this.options
.drawYGrid
){
184 var _37
=this.layout
.yticks
;
186 ctx
.strokeStyle
=this.options
.gridLineColor
;
187 ctx
.lineWidth
=this.options
.axisLineWidth
;
188 for(var i
=0;i
<_37
.length
;i
++){
190 var y
=this.area
.y
+_37
[i
][0]*this.area
.h
;
193 ctx
.lineTo(x
+this.area
.w
,y
);
198 if(this.options
.drawXGrid
){
199 var _37
=this.layout
.xticks
;
201 ctx
.strokeStyle
=this.options
.gridLineColor
;
202 ctx
.lineWidth
=this.options
.axisLineWidth
;
203 for(var i
=0;i
<_37
.length
;i
++){
204 var x
=this.area
.x
+_37
[i
][0]*this.area
.w
;
205 var y
=this.area
.y
+this.area
.h
;
208 ctx
.lineTo(x
,this.area
.y
);
213 this._renderLineChart();
216 DygraphCanvasRenderer
.prototype._renderAxis
=function(){
217 if(!this.options
.drawXAxis
&&!this.options
.drawYAxis
){
220 var _40
=this.element
.getContext("2d");
221 var _41
={"position":"absolute","fontSize":this.options
.axisLabelFontSize
+"px","zIndex":10,"color":this.options
.axisLabelColor
,"width":this.options
.axisLabelWidth
+"px","overflow":"hidden"};
222 var _42
=function(txt
){
223 var div
=document
.createElement("div");
225 div
.style
[_45
]=_41
[_45
];
227 div
.appendChild(document
.createTextNode(txt
));
231 _40
.strokeStyle
=this.options
.axisLineColor
;
232 _40
.lineWidth
=this.options
.axisLineWidth
;
233 if(this.options
.drawYAxis
){
234 if(this.layout
.yticks
){
235 for(var i
=0;i
<this.layout
.yticks
.length
;i
++){
236 var _46
=this.layout
.yticks
[i
];
237 if(typeof (_46
)=="function"){
241 var y
=this.area
.y
+_46
[0]*this.area
.h
;
244 _40
.lineTo(x
-this.options
.axisTickSize
,y
);
248 var top
=(y
-this.options
.axisLabelFontSize
/2);
252 if(top
+this.options
.axisLabelFontSize
+3>this.height
){
253 _47
.style
.bottom
="0px";
255 _47
.style
.top
=top
+"px";
257 _47
.style
.left
="0px";
258 _47
.style
.textAlign
="right";
259 _47
.style
.width
=this.options
.yAxisLabelWidth
+"px";
260 this.container
.appendChild(_47
);
261 this.ylabels
.push(_47
);
263 var _49
=this.ylabels
[0];
264 var _50
=this.options
.axisLabelFontSize
;
265 var _51
=parseInt(_49
.style
.top
)+_50
;
266 if(_51
>this.height
-_50
){
267 _49
.style
.top
=(parseInt(_49
.style
.top
)-_50
/2)+"px";
271 _40
.moveTo(this.area
.x
,this.area
.y
);
272 _40
.lineTo(this.area
.x
,this.area
.y
+this.area
.h
);
276 if(this.options
.drawXAxis
){
277 if(this.layout
.xticks
){
278 for(var i
=0;i
<this.layout
.xticks
.length
;i
++){
279 var _46
=this.layout
.xticks
[i
];
280 if(typeof (dataset
)=="function"){
283 var x
=this.area
.x
+_46
[0]*this.area
.w
;
284 var y
=this.area
.y
+this.area
.h
;
287 _40
.lineTo(x
,y
+this.options
.axisTickSize
);
291 _47
.style
.textAlign
="center";
292 _47
.style
.bottom
="0px";
293 var _52
=(x
-this.options
.axisLabelWidth
/2);
294 if(_52
+this.options
.axisLabelWidth
>this.width
){
295 _52
=this.width
-this.options
.xAxisLabelWidth
;
296 _47
.style
.textAlign
="right";
300 _47
.style
.textAlign
="left";
302 _47
.style
.left
=_52
+"px";
303 _47
.style
.width
=this.options
.xAxisLabelWidth
+"px";
304 this.container
.appendChild(_47
);
305 this.xlabels
.push(_47
);
309 _40
.moveTo(this.area
.x
,this.area
.y
+this.area
.h
);
310 _40
.lineTo(this.area
.x
+this.area
.w
,this.area
.y
+this.area
.h
);
316 DygraphCanvasRenderer
.prototype._renderLineChart
=function(){
317 var _53
=this.element
.getContext("2d");
318 var _54
=this.options
.colorScheme
.length
;
319 var _55
=this.options
.colorScheme
;
320 var _56
=MochiKit
.Base
.keys(this.layout
.datasets
);
321 var _57
=this.layout
.options
.errorBars
;
323 var _59
=MochiKit
.Base
.bind
;
324 var _60
=MochiKit
.Base
.partial
;
325 for(var i
=0;i
<this.layout
.points
.length
;i
++){
326 var _61
=this.layout
.points
[i
];
327 _61
.canvasx
=this.area
.w
*_61
.x
+this.area
.x
;
328 _61
.canvasy
=this.area
.h
*_61
.y
+this.area
.y
;
333 var _63
=function(ctx
){
334 for(var i
=0;i
<_58
;i
++){
338 var _61
=this.layout
.points
[0];
339 var _66
=this.dygraph_
.attr_("pointSize");
340 var _67
=null,prevY
=null;
341 var _68
=this.dygraph_
.attr_("drawPoints");
342 var _69
=this.layout
.points
;
343 for(var j
=0;j
<_69
.length
;j
++){
346 if(!_62(_61
.canvasy
)){
349 var _70
=(!_67
&&(j
==_69
.length
-1||!_62(_69
[j
+1].canvasy
)));
356 ctx
.lineWidth
=this.options
.strokeWidth
;
357 ctx
.moveTo(_67
,prevY
);
360 ctx
.lineTo(_67
,prevY
);
366 ctx
.arc(_61
.canvasx
,_61
.canvasy
,_66
,0,360,false);
374 var _71
=function(ctx
){
375 for(var i
=0;i
<_58
;i
++){
380 _53
.lineWidth
=this.options
.strokeWidth
;
384 var _77
=this.layout
.yscale
;
385 var rgb
=new RGBColor(_73
);
386 var _79
="rgba("+rgb
.r
+","+rgb
.g
+","+rgb
.b
+",0.15)";
389 for(var j
=0;j
<this.layout
.points
.length
;j
++){
390 var _80
=this.layout
.points
[j
];
393 if(!_80
.y
||isNaN(_80
.y
)){
397 var _81
=[_80
.y
-_80
.errorPlus
*_77
,_80
.y
+_80
.errorMinus
*_77
];
398 _81
[0]=this.area
.h
*_81
[0]+this.area
.y
;
399 _81
[1]=this.area
.h
*_81
[1]+this.area
.y
;
401 ctx
.moveTo(_74
,_75
[0]);
402 ctx
.lineTo(_80
.canvasx
,_81
[0]);
403 ctx
.lineTo(_80
.canvasx
,_81
[1]);
404 ctx
.lineTo(_74
,_75
[1]);
421 Dygraph
=function(div
,_82
,_83
){
422 if(arguments
.length
>0){
423 if(arguments
.length
==4){
424 this.warn("Using deprecated four-argument dygraph constructor");
425 this.__old_init__(div
,_82
,arguments
[2],arguments
[3]);
427 this.__init__(div
,_82
,_83
);
431 Dygraph
.NAME
="Dygraph";
432 Dygraph
.VERSION
="1.2";
433 Dygraph
.__repr__
=function(){
434 return "["+this.NAME
+" "+this.VERSION
+"]";
436 Dygraph
.toString
=function(){
437 return this.__repr__();
439 Dygraph
.DEFAULT_ROLL_PERIOD
=1;
440 Dygraph
.DEFAULT_WIDTH
=480;
441 Dygraph
.DEFAULT_HEIGHT
=320;
442 Dygraph
.AXIS_LINE_WIDTH
=0.3;
443 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};
448 Dygraph
.prototype.__old_init__
=function(div
,_84
,_85
,_86
){
451 for(var i
=0;i
<_85
.length
;i
++){
454 MochiKit
.Base
.update(_86
,{"labels":_87
});
456 this.__init__(div
,_84
,_86
);
458 Dygraph
.prototype.__init__
=function(div
,_88
,_89
){
464 this.rollPeriod_
=_89
.rollPeriod
||Dygraph
.DEFAULT_ROLL_PERIOD
;
465 this.previousVerticalX_
=-1;
466 this.fractions_
=_89
.fractions
||false;
467 this.dateWindow_
=_89
.dateWindow
||null;
468 this.valueRange_
=_89
.valueRange
||null;
469 this.wilsonInterval_
=_89
.wilsonInterval
||true;
471 if(div
.style
.width
==""){
472 div
.style
.width
=Dygraph
.DEFAULT_WIDTH
+"px";
474 if(div
.style
.height
==""){
475 div
.style
.height
=Dygraph
.DEFAULT_HEIGHT
+"px";
477 this.width_
=parseInt(div
.style
.width
,10);
478 this.height_
=parseInt(div
.style
.height
,10);
480 MochiKit
.Base
.update(this.user_attrs_
,_89
);
482 MochiKit
.Base
.update(this.attrs_
,Dygraph
.DEFAULT_ATTRS
);
483 this.labelsFromCSV_
=(this.attr_("labels")==null);
484 this.createInterface_();
485 this.layoutOptions_
={"errorBars":(this.attr_("errorBars")||this.attr_("customBars")),"xOriginIsZero":false};
486 MochiKit
.Base
.update(this.layoutOptions_
,this.attrs_
);
487 MochiKit
.Base
.update(this.layoutOptions_
,this.user_attrs_
);
488 this.layout_
=new DygraphLayout(this,this.layoutOptions_
);
489 this.renderOptions_
={colorScheme
:this.colors_
,strokeColor
:null,axisLineWidth
:Dygraph
.AXIS_LINE_WIDTH
};
490 MochiKit
.Base
.update(this.renderOptions_
,this.attrs_
);
491 MochiKit
.Base
.update(this.renderOptions_
,this.user_attrs_
);
492 this.plotter_
=new DygraphCanvasRenderer(this,this.hidden_
,this.layout_
,this.renderOptions_
);
493 this.createStatusMessage_();
494 this.createRollInterface_();
495 this.createDragInterface_();
498 Dygraph
.prototype.attr_
=function(_90
){
499 if(typeof (this.user_attrs_
[_90
])!="undefined"){
500 return this.user_attrs_
[_90
];
502 if(typeof (this.attrs_
[_90
])!="undefined"){
503 return this.attrs_
[_90
];
509 Dygraph
.prototype.log
=function(_91
,_92
){
510 if(typeof (console
)!="undefined"){
513 console
.debug("dygraphs: "+_92
);
516 console
.info("dygraphs: "+_92
);
518 case Dygraph
.WARNING
:
519 console
.warn("dygraphs: "+_92
);
522 console
.error("dygraphs: "+_92
);
527 Dygraph
.prototype.info
=function(_93
){
528 this.log(Dygraph
.INFO
,_93
);
530 Dygraph
.prototype.warn
=function(_94
){
531 this.log(Dygraph
.WARNING
,_94
);
533 Dygraph
.prototype.error
=function(_95
){
534 this.log(Dygraph
.ERROR
,_95
);
536 Dygraph
.prototype.rollPeriod
=function(){
537 return this.rollPeriod_
;
539 Dygraph
.addEvent
=function(el
,evt
,fn
){
546 if(window
.addEventListener
){
547 el
.addEventListener(evt
,_98
,false);
549 el
.attachEvent("on"+evt
,_98
);
552 Dygraph
.prototype.createInterface_
=function(){
553 var _100
=this.maindiv_
;
554 this.graphDiv
=document
.createElement("div");
555 this.graphDiv
.style
.width
=this.width_
+"px";
556 this.graphDiv
.style
.height
=this.height_
+"px";
557 _100
.appendChild(this.graphDiv
);
558 this.canvas_
=document
.createElement("canvas");
559 this.canvas_
.style
.position
="absolute";
560 this.canvas_
.width
=this.width_
;
561 this.canvas_
.height
=this.height_
;
562 this.graphDiv
.appendChild(this.canvas_
);
563 this.hidden_
=this.createPlotKitCanvas_(this.canvas_
);
565 Dygraph
.addEvent(this.hidden_
,"mousemove",function(e
){
568 Dygraph
.addEvent(this.hidden_
,"mouseout",function(e
){
572 Dygraph
.prototype.createPlotKitCanvas_
=function(_102
){
573 var h
=document
.createElement("canvas");
574 h
.style
.position
="absolute";
575 h
.style
.top
=_102
.style
.top
;
576 h
.style
.left
=_102
.style
.left
;
578 h
.height
=this.height_
;
579 this.graphDiv
.appendChild(h
);
582 Dygraph
.hsvToRGB
=function(hue
,_105
,_106
){
591 var i
=Math
.floor(hue
*6);
594 var q
=_106
*(1-(_105
*f
));
595 var t
=_106
*(1-(_105
*(1-f
)));
630 red
=Math
.floor(255*red
+0.5);
631 _108
=Math
.floor(255*_108
+0.5);
632 blue
=Math
.floor(255*blue
+0.5);
633 return "rgb("+red
+","+_108
+","+blue
+")";
635 Dygraph
.prototype.setColors_
=function(){
636 var num
=this.attr_("labels").length
-1;
638 var _115
=this.attr_("colors");
640 var sat
=this.attr_("colorSaturation")||1;
641 var val
=this.attr_("colorValue")||0.5;
642 for(var i
=1;i
<=num
;i
++){
643 var hue
=(1*i
/(1+num
));
644 this.colors_
.push(Dygraph
.hsvToRGB(hue
,sat
,val
));
647 for(var i
=0;i
<num
;i
++){
648 var _118
=_115
[i
%_115
.length
];
649 this.colors_
.push(_118
);
652 this.renderOptions_
.colorScheme
=this.colors_
;
653 MochiKit
.Base
.update(this.plotter_
.options
,this.renderOptions_
);
654 MochiKit
.Base
.update(this.layoutOptions_
,this.user_attrs_
);
655 MochiKit
.Base
.update(this.layoutOptions_
,this.attrs_
);
657 Dygraph
.findPosX
=function(obj
){
659 if(obj
.offsetParent
){
660 while(obj
.offsetParent
){
661 _120
+=obj
.offsetLeft
;
662 obj
=obj
.offsetParent
;
671 Dygraph
.findPosY
=function(obj
){
673 if(obj
.offsetParent
){
674 while(obj
.offsetParent
){
676 obj
=obj
.offsetParent
;
685 Dygraph
.prototype.createStatusMessage_
=function(){
686 if(!this.attr_("labelsDiv")){
687 var _122
=this.attr_("labelsDivWidth");
688 var _123
={"position":"absolute","fontSize":"14px","zIndex":10,"width":_122
+"px","top":"0px","left":(this.width_
-_122
-2)+"px","background":"white","textAlign":"left","overflow":"hidden"};
689 MochiKit
.Base
.update(_123
,this.attr_("labelsDivStyles"));
690 var div
=document
.createElement("div");
691 for(var name
in _123
){
692 div
.style
[name
]=_123
[name
];
694 this.graphDiv
.appendChild(div
);
695 this.attrs_
.labelsDiv
=div
;
698 Dygraph
.prototype.createRollInterface_
=function(){
699 var _125
=this.attr_("showRoller")?"block":"none";
700 var _126
={"position":"absolute","zIndex":10,"top":(this.plotter_
.area
.h
-25)+"px","left":(this.plotter_
.area
.x
+1)+"px","display":_125
};
701 var _127
=document
.createElement("input");
704 _127
.value
=this.rollPeriod_
;
705 for(var name
in _126
){
706 _127
.style
[name
]=_126
[name
];
708 var pa
=this.graphDiv
;
709 pa
.appendChild(_127
);
711 _127
.onchange
=function(){
712 _129
.adjustRoll(_127
.value
);
716 Dygraph
.pageX
=function(e
){
718 return (!e
.pageX
||e
.pageX
<0)?0:e
.pageX
;
722 return e
.clientX
+(de
.scrollLeft
||b
.scrollLeft
)-(de
.clientLeft
||0);
725 Dygraph
.pageY
=function(e
){
727 return (!e
.pageY
||e
.pageY
<0)?0:e
.pageY
;
731 return e
.clientY
+(de
.scrollTop
||b
.scrollTop
)-(de
.clientTop
||0);
734 Dygraph
.prototype.createDragInterface_
=function(){
744 var getX
=function(e
){
745 return Dygraph
.pageX(e
)-px
;
747 var getY
=function(e
){
748 return Dygraph
.pageX(e
)-py
;
750 Dygraph
.addEvent(this.hidden_
,"mousemove",function(_143
){
754 self
.drawZoomRect_(_134
,_136
,_138
);
758 Dygraph
.addEvent(this.hidden_
,"mousedown",function(_144
){
760 px
=Dygraph
.findPosX(self
.canvas_
);
761 py
=Dygraph
.findPosY(self
.canvas_
);
765 Dygraph
.addEvent(document
,"mouseup",function(_145
){
772 Dygraph
.addEvent(this.hidden_
,"mouseout",function(_146
){
778 Dygraph
.addEvent(this.hidden_
,"mouseup",function(_147
){
783 var _148
=Math
.abs(_136
-_134
);
784 var _149
=Math
.abs(_137
-_135
);
785 if(_148
<2&&_149
<2&&self
.attr_("clickCallback")!=null&&self
.lastx_
!=undefined
){
786 self
.attr_("clickCallback")(_147
,new Date(self
.lastx_
));
789 self
.doZoom_(Math
.min(_134
,_136
),Math
.max(_134
,_136
));
791 self
.canvas_
.getContext("2d").clearRect(0,0,self
.canvas_
.width
,self
.canvas_
.height
);
797 Dygraph
.addEvent(this.hidden_
,"dblclick",function(_150
){
798 self
.dateWindow_
=null;
799 self
.drawGraph_(self
.rawData_
);
800 var _151
=self
.rawData_
[0][0];
801 var _152
=self
.rawData_
[self
.rawData_
.length
-1][0];
802 if(self
.attr_("zoomCallback")){
803 self
.attr_("zoomCallback")(_151
,_152
);
807 Dygraph
.prototype.drawZoomRect_
=function(_153
,endX
,_155
){
808 var ctx
=this.canvas_
.getContext("2d");
810 ctx
.clearRect(Math
.min(_153
,_155
),0,Math
.abs(_153
-_155
),this.height_
);
813 ctx
.fillStyle
="rgba(128,128,128,0.33)";
814 ctx
.fillRect(Math
.min(_153
,endX
),0,Math
.abs(endX
-_153
),this.height_
);
817 Dygraph
.prototype.doZoom_
=function(lowX
,_157
){
818 var _158
=this.layout_
.points
;
821 for(var i
=0;i
<_158
.length
;i
++){
822 var cx
=_158
[i
].canvasx
;
824 if(cx
<lowX
&&(_159
==null||x
>_159
)){
827 if(cx
>_157
&&(_160
==null||x
<_160
)){
835 _160
=_158
[_158
.length
-1].xval
;
837 this.dateWindow_
=[_159
,_160
];
838 this.drawGraph_(this.rawData_
);
839 if(this.attr_("zoomCallback")){
840 this.attr_("zoomCallback")(_159
,_160
);
843 Dygraph
.prototype.mouseMove_
=function(_162
){
844 var _163
=Dygraph
.pageX(_162
)-Dygraph
.findPosX(this.hidden_
);
845 var _164
=this.layout_
.points
;
850 for(var i
=0;i
<_164
.length
;i
++){
851 var dist
=Math
.abs(_164
[i
].canvasx
-_163
);
861 if(_163
>_164
[_164
.length
-1].canvasx
){
862 _165
=_164
[_164
.length
-1].xval
;
865 for(var i
=0;i
<_164
.length
;i
++){
866 if(_164
[i
].xval
==_165
){
870 var _171
=this.attr_("highlightCircleSize");
871 var ctx
=this.canvas_
.getContext("2d");
872 if(this.previousVerticalX_
>=0){
873 var px
=this.previousVerticalX_
;
874 ctx
.clearRect(px
-_171
-1,0,2*_171
+2,this.height_
);
876 var isOK
=function(x
){
880 var _163
=_170
[0].canvasx
;
881 var _173
=this.attr_("xValueFormatter")(_165
,this)+":";
882 var clen
=this.colors_
.length
;
883 for(var i
=0;i
<_170
.length
;i
++){
884 if(!isOK(_170
[i
].canvasy
)){
887 if(this.attr_("labelsSeparateLines")){
891 var c
=new RGBColor(this.colors_
[i
%clen
]);
892 _173
+=" <b><font color='"+c
.toHex()+"'>"+_175
.name
+"</font></b>:"+this.round_(_175
.yval
,2);
894 this.attr_("labelsDiv").innerHTML
=_173
;
897 for(var i
=0;i
<_170
.length
;i
++){
898 if(!isOK(_170
[i
%clen
].canvasy
)){
902 ctx
.fillStyle
=this.colors_
[i
%clen
];
903 ctx
.arc(_163
,_170
[i
%clen
].canvasy
,_171
,0,360,false);
907 this.previousVerticalX_
=_163
;
910 Dygraph
.prototype.mouseOut_
=function(_177
){
911 var ctx
=this.canvas_
.getContext("2d");
912 ctx
.clearRect(0,0,this.width_
,this.height_
);
913 this.attr_("labelsDiv").innerHTML
="";
915 Dygraph
.zeropad
=function(x
){
922 Dygraph
.prototype.hmsString_
=function(date
){
923 var _179
=Dygraph
.zeropad
;
924 var d
=new Date(date
);
926 return _179(d
.getHours())+":"+_179(d
.getMinutes())+":"+_179(d
.getSeconds());
929 return _179(d
.getHours())+":"+_179(d
.getMinutes());
931 return _179(d
.getHours());
935 Dygraph
.dateString_
=function(date
,self
){
936 var _181
=Dygraph
.zeropad
;
937 var d
=new Date(date
);
938 var year
=""+d
.getFullYear();
939 var _183
=_181(d
.getMonth()+1);
940 var day
=_181(d
.getDate());
942 var frac
=d
.getHours()*3600+d
.getMinutes()*60+d
.getSeconds();
944 ret
=" "+self
.hmsString_(date
);
946 return year
+"/"+_183+"/"+day
+ret
;
948 Dygraph
.prototype.round_
=function(num
,_187
){
949 var _188
=Math
.pow(10,_187
);
950 return Math
.round(num
*_188
)/_188
;
952 Dygraph
.prototype.loadedEvent_
=function(data
){
953 this.rawData_
=this.parseCSV_(data
);
954 this.drawGraph_(this.rawData_
);
956 Dygraph
.prototype.months
=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
957 Dygraph
.prototype.quarters
=["Jan","Apr","Jul","Oct"];
958 Dygraph
.prototype.addXTicks_
=function(){
960 if(this.dateWindow_
){
961 _190
=this.dateWindow_
[0];
962 endDate
=this.dateWindow_
[1];
964 _190
=this.rawData_
[0][0];
965 endDate
=this.rawData_
[this.rawData_
.length
-1][0];
967 var _191
=this.attr_("xTicker")(_190
,endDate
,this);
968 this.layout_
.updateOptions({xTicks
:_191
});
971 Dygraph
.TEN_SECONDLY
=1;
972 Dygraph
.THIRTY_SECONDLY
=2;
974 Dygraph
.TEN_MINUTELY
=4;
975 Dygraph
.THIRTY_MINUTELY
=5;
977 Dygraph
.SIX_HOURLY
=7;
981 Dygraph
.QUARTERLY
=11;
985 Dygraph
.NUM_GRANULARITIES
=15;
986 Dygraph
.SHORT_SPACINGS
=[];
987 Dygraph
.SHORT_SPACINGS
[Dygraph
.SECONDLY
]=1000*1;
988 Dygraph
.SHORT_SPACINGS
[Dygraph
.TEN_SECONDLY
]=1000*10;
989 Dygraph
.SHORT_SPACINGS
[Dygraph
.THIRTY_SECONDLY
]=1000*30;
990 Dygraph
.SHORT_SPACINGS
[Dygraph
.MINUTELY
]=1000*60;
991 Dygraph
.SHORT_SPACINGS
[Dygraph
.TEN_MINUTELY
]=1000*60*10;
992 Dygraph
.SHORT_SPACINGS
[Dygraph
.THIRTY_MINUTELY
]=1000*60*30;
993 Dygraph
.SHORT_SPACINGS
[Dygraph
.HOURLY
]=1000*3600;
994 Dygraph
.SHORT_SPACINGS
[Dygraph
.HOURLY
]=1000*3600*6;
995 Dygraph
.SHORT_SPACINGS
[Dygraph
.DAILY
]=1000*86400;
996 Dygraph
.SHORT_SPACINGS
[Dygraph
.WEEKLY
]=1000*604800;
997 Dygraph
.prototype.NumXTicks
=function(_192
,_193
,_194
){
998 if(_194
<Dygraph
.MONTHLY
){
999 var _195
=Dygraph
.SHORT_SPACINGS
[_194
];
1000 return Math
.floor(0.5+1*(_193
-_192
)/_195
);
1004 if(_194
==Dygraph
.QUARTERLY
){
1007 if(_194
==Dygraph
.BIANNUAL
){
1010 if(_194
==Dygraph
.ANNUAL
){
1013 if(_194
==Dygraph
.DECADAL
){
1017 var _198
=365.2524*24*3600*1000;
1018 var _199
=1*(_193
-_192
)/_198
;
1019 return Math
.floor(0.5+1*_199
*_197
/_196
);
1022 Dygraph
.prototype.GetXAxis
=function(_200
,_201
,_202
){
1024 if(_202
<Dygraph
.MONTHLY
){
1025 var _204
=Dygraph
.SHORT_SPACINGS
[_202
];
1027 if(_202
<Dygraph
.HOURLY
){
1028 _200
=_204
*Math
.floor(0.5+_200
/_204
);
1030 for(var t
=_200
;t
<=_201
;t
+=_204
){
1032 var frac
=d
.getHours()*3600+d
.getMinutes()*60+d
.getSeconds();
1033 if(frac
==0||_202
>=Dygraph
.DAILY
){
1034 _203
.push({v
:t
,label
:new Date(t
+3600*1000).strftime(_205
)});
1036 _203
.push({v
:t
,label
:this.hmsString_(t
)});
1042 if(_202
==Dygraph
.MONTHLY
){
1043 _206
=[0,1,2,3,4,5,6,7,8,9,10,11,12];
1045 if(_202
==Dygraph
.QUARTERLY
){
1048 if(_202
==Dygraph
.BIANNUAL
){
1051 if(_202
==Dygraph
.ANNUAL
){
1054 if(_202
==Dygraph
.DECADAL
){
1062 var _208
=new Date(_200
).getFullYear();
1063 var _209
=new Date(_201
).getFullYear();
1064 var _210
=Dygraph
.zeropad
;
1065 for(var i
=_208
;i
<=_209
;i
++){
1069 for(var j
=0;j
<_206
.length
;j
++){
1070 var _211
=i
+"/"+_210(1+_206[j])+"/01";
1071 var t
=Date
.parse(_211
);
1075 _203
.push({v
:t
,label
:new Date(t
).strftime("%b %y")});
1081 Dygraph
.dateTicker
=function(_212
,_213
,self
){
1083 for(var i
=0;i
<Dygraph
.NUM_GRANULARITIES
;i
++){
1084 var _215
=self
.NumXTicks(_212
,_213
,i
);
1085 if(self
.width_
/_215
>=self
.attr_("pixelsPerXLabel")){
1091 return self
.GetXAxis(_212
,_213
,_214
);
1095 Dygraph
.numericTicks
=function(minV
,maxV
,self
){
1097 var _219
,low_val
,high_val
,nTicks
;
1098 var _220
=self
.attr_("pixelsPerYLabel");
1099 for(var i
=-10;i
<50;i
++){
1100 var _221
=Math
.pow(10,i
);
1101 for(var j
=0;j
<_218
.length
;j
++){
1103 low_val
=Math
.floor(minV
/_219
)*_219
;
1104 high_val
=Math
.ceil(maxV
/_219
)*_219
;
1105 nTicks
=(high_val
-low_val
)/_219
;
1106 var _222
=self
.height_
/nTicks
;
1116 for(var i
=0;i
<nTicks
;i
++){
1117 var _224
=low_val
+i
*_219
;
1118 var _225
=self
.round_(_224
,2);
1119 if(self
.attr_("labelsKMB")){
1122 _225
=self
.round_(_224
/(k
*k
*k
),1)+"B";
1125 _225
=self
.round_(_224
/(k
*k
),1)+"M";
1128 _225
=self
.round_(_224
/k
,1)+"K";
1133 _223
.push({label
:_225
,v
:_224
});
1137 Dygraph
.prototype.addYTicks_
=function(minY
,maxY
){
1138 var _229
=Dygraph
.numericTicks(minY
,maxY
,this);
1139 this.layout_
.updateOptions({yAxis
:[minY
,maxY
],yTicks
:_229
});
1141 Dygraph
.prototype.extremeValues_
=function(_230
){
1142 var minY
=null,maxY
=null;
1143 var bars
=this.attr_("errorBars")||this.attr_("customBars");
1145 for(var j
=0;j
<_230
.length
;j
++){
1146 var y
=_230
[j
][1][0];
1150 var low
=y
-_230
[j
][1][1];
1151 var high
=y
+_230
[j
][1][2];
1158 if(maxY
==null||high
>maxY
){
1161 if(minY
==null||low
<minY
){
1166 for(var j
=0;j
<_230
.length
;j
++){
1171 if(maxY
==null||y
>maxY
){
1174 if(minY
==null||y
<minY
){
1181 Dygraph
.prototype.drawGraph_
=function(data
){
1182 var minY
=null,maxY
=null;
1183 this.layout_
.removeAllDatasets();
1185 this.attrs_
["pointSize"]=0.5*this.attr_("highlightCircleSize");
1186 for(var i
=1;i
<data
[0].length
;i
++){
1188 for(var j
=0;j
<data
.length
;j
++){
1189 var date
=data
[j
][0];
1190 _234
[j
]=[date
,data
[j
][i
]];
1192 _234
=this.rollingAverage(_234
,this.rollPeriod_
);
1193 var bars
=this.attr_("errorBars")||this.attr_("customBars");
1194 if(this.dateWindow_
){
1195 var low
=this.dateWindow_
[0];
1196 var high
=this.dateWindow_
[1];
1198 for(var k
=0;k
<_234
.length
;k
++){
1199 if(_234
[k
][0]>=low
&&_234
[k
][0]<=high
){
1205 var _236
=this.extremeValues_(_234
);
1208 if(!minY
||_237
<minY
){
1211 if(!maxY
||_238
>maxY
){
1216 for(var j
=0;j
<_234
.length
;j
++){
1217 vals
[j
]=[_234
[j
][0],_234
[j
][1][0],_234
[j
][1][1],_234
[j
][1][2]];
1219 this.layout_
.addDataset(this.attr_("labels")[i
],vals
);
1221 this.layout_
.addDataset(this.attr_("labels")[i
],_234
);
1224 if(this.valueRange_
!=null){
1225 this.addYTicks_(this.valueRange_
[0],this.valueRange_
[1]);
1228 var _241
=maxY
+0.1*span
;
1229 var _242
=minY
-0.1*span
;
1230 if(_242
<0&&minY
>=0){
1233 if(_241
>0&&maxY
<=0){
1236 if(this.attr_("includeZero")){
1244 this.addYTicks_(_242
,_241
);
1247 this.layout_
.evaluateWithError();
1248 this.plotter_
.clear();
1249 this.plotter_
.render();
1250 this.canvas_
.getContext("2d").clearRect(0,0,this.canvas_
.width
,this.canvas_
.height
);
1252 Dygraph
.prototype.rollingAverage
=function(_243
,_244
){
1256 var _244
=Math
.min(_244
,_243
.length
-1);
1258 var _246
=this.attr_("sigma");
1259 if(this.fractions_
){
1263 for(var i
=0;i
<_243
.length
;i
++){
1267 num
-=_243
[i
-_244
][1][0];
1268 den
-=_243
[i
-_244
][1][1];
1270 var date
=_243
[i
][0];
1271 var _249
=den
?num
/den
:0;
1272 if(this.attr_("errorBars")){
1273 if(this.wilsonInterval_
){
1275 var p
=_249
<0?0:_249
,n
=den
;
1276 var pm
=_246
*Math
.sqrt(p
*(1-p
)/n+_246*_246/(4*n
*n
));
1277 var _251
=1+_246
*_246
/den
;
1278 var low
=(p
+_246
*_246
/(2*den)-pm)/_251
;
1279 var high
=(p
+_246
*_246
/(2*den)+pm)/_251
;
1280 _245
[i
]=[date
,[p
*mult
,(p
-low
)*mult
,(high
-p
)*mult
]];
1282 _245
[i
]=[date
,[0,0,0]];
1285 var _252
=den
?_246
*Math
.sqrt(_249
*(1-_249
)/den
):1;
1286 _245
[i
]=[date
,[mult
*_249
,mult
*_252
,mult
*_252
]];
1289 _245
[i
]=[date
,mult
*_249
];
1293 if(this.attr_("customBars")){
1298 for(var i
=0;i
<_243
.length
;i
++){
1299 var data
=_243
[i
][1];
1301 _245
[i
]=[_243
[i
][0],[y
,y
-data
[0],data
[2]-y
]];
1307 var prev
=_243
[i
-_244
];
1313 _245
[i
]=[_243
[i
][0],[1*mid
/_254,1*(mid-low)/_254
,1*(high
-mid
)/_254
]];
1316 var _256
=Math
.min(_244
-1,_243
.length
-2);
1317 if(!this.attr_("errorBars")){
1321 for(var i
=0;i
<_243
.length
;i
++){
1324 for(var j
=Math
.max(0,i
-_244
+1);j
<i
+1;j
++){
1333 _245
[i
]=[_243
[i
][0],sum
/_258
];
1335 _245
[i
]=[_243
[i
][0],null];
1339 for(var i
=0;i
<_243
.length
;i
++){
1343 for(var j
=Math
.max(0,i
-_244
+1);j
<i
+1;j
++){
1344 var y
=_243
[j
][1][0];
1350 _259
+=Math
.pow(_243
[j
][1][1],2);
1353 var _252
=Math
.sqrt(_259
)/_258
;
1354 _245
[i
]=[_243
[i
][0],[sum
/_258
,_246
*_252
,_246
*_252
]];
1356 _245
[i
]=[_243
[i
][0],[null,null,null]];
1364 Dygraph
.dateParser
=function(_260
,self
){
1367 if(_260
.length
==10&&_260
.search("-")!=-1){
1368 _261
=_260
.replace("-","/","g");
1369 while(_261
.search("-")!=-1){
1370 _261
=_261
.replace("-","/");
1375 _261
=_260
.substr(0,4)+"/"+_260.substr(4,2)+"/"+_260
.substr(6,2);
1382 self
.error("Couldn't parse "+_260
+" as a date");
1386 Dygraph
.prototype.detectTypeFromString_
=function(str
){
1388 if(str
.indexOf("-")>=0||str
.indexOf("/")>=0||isNaN(parseFloat(str
))){
1391 if(str
.length
==8&&str
>"19700101"&&str
<"20371231"){
1396 this.attrs_
.xValueFormatter
=Dygraph
.dateString_
;
1397 this.attrs_
.xValueParser
=Dygraph
.dateParser
;
1398 this.attrs_
.xTicker
=Dygraph
.dateTicker
;
1400 this.attrs_
.xValueFormatter
=function(x
){
1403 this.attrs_
.xValueParser
=function(x
){
1404 return parseFloat(x
);
1406 this.attrs_
.xTicker
=Dygraph
.numericTicks
;
1409 Dygraph
.prototype.parseCSV_
=function(data
){
1411 var _264
=data
.split("\n");
1413 if(this.labelsFromCSV_
){
1415 this.attrs_
.labels
=_264
[0].split(",");
1419 var _268
=this.attr_("labels").length
;
1420 for(var i
=_265
;i
<_264
.length
;i
++){
1425 var _270
=line
.split(",");
1431 this.detectTypeFromString_(_270
[0]);
1432 _266
=this.attr_("xValueParser");
1435 _271
[0]=_266(_270
[0],this);
1436 if(this.fractions_
){
1437 for(var j
=1;j
<_270
.length
;j
++){
1438 var vals
=_270
[j
].split("/");
1439 _271
[j
]=[parseFloat(vals
[0]),parseFloat(vals
[1])];
1442 if(this.attr_("errorBars")){
1443 for(var j
=1;j
<_270
.length
;j
+=2){
1444 _271
[(j
+1)/2]=[parseFloat(_270
[j
]),parseFloat(_270
[j
+1])];
1447 if(this.attr_("customBars")){
1448 for(var j
=1;j
<_270
.length
;j
++){
1449 var vals
=_270
[j
].split(";");
1450 _271
[j
]=[parseFloat(vals
[0]),parseFloat(vals
[1]),parseFloat(vals
[2])];
1453 for(var j
=1;j
<_270
.length
;j
++){
1454 _271
[j
]=parseFloat(_270
[j
]);
1460 if(_271
.length
!=_268
){
1461 this.error("Number of columns in line "+i
+" ("+_271
.length
+") does not agree with number of labels ("+_268
+") "+line
);
1466 Dygraph
.prototype.parseArray_
=function(data
){
1468 this.error("Can't plot empty data set");
1471 if(data
[0].length
==0){
1472 this.error("Data set cannot contain an empty row");
1475 if(this.attr_("labels")==null){
1476 this.warn("Using default labels. Set labels explicitly via 'labels' "+"in the options parameter");
1477 this.attrs_
.labels
=["X"];
1478 for(var i
=1;i
<data
[0].length
;i
++){
1479 this.attrs_
.labels
.push("Y"+i
);
1482 if(MochiKit
.Base
.isDateLike(data
[0][0])){
1483 this.attrs_
.xValueFormatter
=Dygraph
.dateString_
;
1484 this.attrs_
.xTicker
=Dygraph
.dateTicker
;
1485 var _272
=MochiKit
.Base
.clone(data
);
1486 for(var i
=0;i
<data
.length
;i
++){
1487 if(_272
[i
].length
==0){
1488 this.error("Row "<<(1+i
)<<" of data is empty");
1491 if(_272
[i
][0]==null||typeof (_272
[i
][0].getTime
)!="function"){
1492 this.error("x value in row "<<(1+i
)<<" is not a Date");
1495 _272
[i
][0]=_272
[i
][0].getTime();
1499 this.attrs_
.xValueFormatter
=function(x
){
1502 this.attrs_
.xTicker
=Dygraph
.numericTicks
;
1506 Dygraph
.prototype.parseDataTable_
=function(data
){
1507 var cols
=data
.getNumberOfColumns();
1508 var rows
=data
.getNumberOfRows();
1510 for(var i
=0;i
<cols
;i
++){
1511 _275
.push(data
.getColumnLabel(i
));
1513 this.attrs_
.labels
=_275
;
1514 var _276
=data
.getColumnType(0);
1516 this.attrs_
.xValueFormatter
=Dygraph
.dateString_
;
1517 this.attrs_
.xValueParser
=Dygraph
.dateParser
;
1518 this.attrs_
.xTicker
=Dygraph
.dateTicker
;
1521 this.attrs_
.xValueFormatter
=function(x
){
1524 this.attrs_
.xValueParser
=function(x
){
1525 return parseFloat(x
);
1527 this.attrs_
.xTicker
=Dygraph
.numericTicks
;
1529 this.error("only 'date' and 'number' types are supported for column 1 "+"of DataTable input (Got '"+_276
+"')");
1534 for(var i
=0;i
<rows
;i
++){
1536 if(!data
.getValue(i
,0)){
1540 row
.push(data
.getValue(i
,0).getTime());
1542 row
.push(data
.getValue(i
,0));
1544 for(var j
=1;j
<cols
;j
++){
1545 row
.push(data
.getValue(i
,j
));
1551 Dygraph
.prototype.start_
=function(){
1552 if(typeof this.file_
=="function"){
1553 this.loadedEvent_(this.file_());
1555 if(MochiKit
.Base
.isArrayLike(this.file_
)){
1556 this.rawData_
=this.parseArray_(this.file_
);
1557 this.drawGraph_(this.rawData_
);
1559 if(typeof this.file_
=="object"&&typeof this.file_
.getColumnRange
=="function"){
1560 this.rawData_
=this.parseDataTable_(this.file_
);
1561 this.drawGraph_(this.rawData_
);
1563 if(typeof this.file_
=="string"){
1564 if(this.file_
.indexOf("\n")>=0){
1565 this.loadedEvent_(this.file_
);
1567 var req
=new XMLHttpRequest();
1569 req
.onreadystatechange
=function(){
1570 if(req
.readyState
==4){
1571 if(req
.status
==200){
1572 _279
.loadedEvent_(req
.responseText
);
1576 req
.open("GET",this.file_
,true);
1580 this.error("Unknown data format: "+(typeof this.file_
));
1586 Dygraph
.prototype.updateOptions
=function(_280
){
1587 if(_280
.rollPeriod
){
1588 this.rollPeriod_
=_280
.rollPeriod
;
1590 if(_280
.dateWindow
){
1591 this.dateWindow_
=_280
.dateWindow
;
1593 if(_280
.valueRange
){
1594 this.valueRange_
=_280
.valueRange
;
1596 MochiKit
.Base
.update(this.user_attrs_
,_280
);
1597 this.labelsFromCSV_
=(this.attr_("labels")==null);
1598 this.layout_
.updateOptions({"errorBars":this.attr_("errorBars")});
1599 if(_280
["file"]&&_280
["file"]!=this.file_
){
1600 this.file_
=_280
["file"];
1603 this.drawGraph_(this.rawData_
);
1606 Dygraph
.prototype.adjustRoll
=function(_281
){
1607 this.rollPeriod_
=_281
;
1608 this.drawGraph_(this.rawData_
);
1610 Dygraph
.GVizChart
=function(_282
){
1611 this.container
=_282
;
1613 Dygraph
.GVizChart
.prototype.draw
=function(data
,_283
){
1614 this.container
.innerHTML
="";
1615 this.date_graph
=new Dygraph(this.container
,data
,_283
);
1618 function RGBColor(_284
){
1620 if(_284
.charAt(0)=="#"){
1621 _284
=_284
.substr(1,6);
1623 _284
=_284
.replace(/ /g,"");
1624 _284
=_284
.toLowerCase();
1625 var _285
={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",darkkhaki
:"bdb76b",darkmagenta
:"8b008b",darkolivegreen
:"556b2f",darkorange
:"ff8c00",darkorchid
:"9932cc",darkred
:"8b0000",darksalmon
:"e9967a",darkseagreen
:"8fbc8f",darkslateblue
:"483d8b",darkslategray
:"2f4f4f",darkturquoise
:"00ced1",darkviolet
:"9400d3",deeppink
:"ff1493",deepskyblue
:"00bfff",dimgray
:"696969",dodgerblue
:"1e90ff",feldspar
:"d19275",firebrick
:"b22222",floralwhite
:"fffaf0",forestgreen
:"228b22",fuchsia
:"ff00ff",gainsboro
:"dcdcdc",ghostwhite
:"f8f8ff",gold
:"ffd700",goldenrod
:"daa520",gray
:"808080",green
:"008000",greenyellow
:"adff2f",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",lightgrey
:"d3d3d3",lightgreen
:"90ee90",lightpink
:"ffb6c1",lightsalmon
:"ffa07a",lightseagreen
:"20b2aa",lightskyblue
:"87cefa",lightslateblue
:"8470ff",lightslategray
:"778899",lightsteelblue
:"b0c4de",lightyellow
:"ffffe0",lime
:"00ff00",limegreen
:"32cd32",linen
:"faf0e6",magenta
:"ff00ff",maroon
:"800000",mediumaquamarine
:"66cdaa",mediumblue
:"0000cd",mediumorchid
:"ba55d3",mediumpurple
:"9370d8",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
:"d87093",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",snow
:"fffafa",springgreen
:"00ff7f",steelblue
:"4682b4",tan
:"d2b48c",teal
:"008080",thistle
:"d8bfd8",tomato
:"ff6347",turquoise
:"40e0d0",violet
:"ee82ee",violetred
:"d02090",wheat
:"f5deb3",white
:"ffffff",whitesmoke
:"f5f5f5",yellow
:"ffff00",yellowgreen
:"9acd32"};
1626 for(var key
in _285
){
1631 var _287
=[{re
:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example
:["rgb(123, 234, 45)","rgb(255,234,245)"],process
:function(bits
){
1632 return [parseInt(bits
[1]),parseInt(bits
[2]),parseInt(bits
[3])];
1633 }},{re
:/^(\w{2})(\w{2})(\w{2})$/,example
:["#00ff00","336699"],process
:function(bits
){
1634 return [parseInt(bits
[1],16),parseInt(bits
[2],16),parseInt(bits
[3],16)];
1635 }},{re
:/^(\w{1})(\w{1})(\w{1})$/,example
:["#fb0","f0f"],process
:function(bits
){
1636 return [parseInt(bits
[1]+bits
[1],16),parseInt(bits
[2]+bits
[2],16),parseInt(bits
[3]+bits
[3],16)];
1638 for(var i
=0;i
<_287
.length
;i
++){
1640 var _290
=_287
[i
].process
;
1641 var bits
=re
.exec(_284
);
1643 channels
=_290(bits
);
1650 this.r
=(this.r
<0||isNaN(this.r
))?0:((this.r
>255)?255:this.r
);
1651 this.g
=(this.g
<0||isNaN(this.g
))?0:((this.g
>255)?255:this.g
);
1652 this.b
=(this.b
<0||isNaN(this.b
))?0:((this.b
>255)?255:this.b
);
1653 this.toRGB
=function(){
1654 return "rgb("+this.r
+", "+this.g
+", "+this.b
+")";
1656 this.toHex
=function(){
1657 var r
=this.r
.toString(16);
1658 var g
=this.g
.toString(16);
1659 var b
=this.b
.toString(16);