3 PlotKit.PlotKit 0.9.1 : PACKED VERSION
5 THIS FILE IS AUTOMATICALLY GENERATED. If creating patches, please
6 diff against the source tree, not this file.
8 For more information, <http://www.liquidx.net/plotkit/>.
10 Copyright (c) 2006. Alastair Tse.
15 if(typeof (MochiKit
.Base
)=="undefined"||typeof (MochiKit
.DOM
)=="undefined"||typeof (MochiKit
.Color
)=="undefined"||typeof (MochiKit
.Format
)=="undefined"){
20 throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format}";
22 MochiKit
.Base
.update(MochiKit
.Color
.Color
.prototype,{asFillColor
:function(){
23 return this.lighterColorWithLevel(0.3);
24 },asStrokeColor
:function(){
25 return this.darkerColorWithLevel(0.1);
26 },asPointColor
:function(){
27 return this.lighterColorWithLevel(0.1);
29 if(typeof (PlotKit
)=="undefined"){
32 PlotKit
.NAME
="PlotKit";
33 PlotKit
.VERSION
="0.8";
34 PlotKit
.__repr__
=function(){
35 return "["+this.NAME
+" "+this.VERSION
+"]";
37 PlotKit
.toString
=function(){
38 return this.__repr__();
40 if(typeof (PlotKit
.Base
)=="undefined"){
43 PlotKit
.Base
.NAME
="PlotKit.Base";
44 PlotKit
.Base
.VERSION
=PlotKit
.VERSION
;
45 PlotKit
.Base
.__repr__
=function(){
46 return "["+this.NAME
+" "+this.VERSION
+"]";
48 PlotKit
.Base
.toString
=function(){
49 return this.__repr__();
51 PlotKit
.Base
.usingPrototype
=function(){
53 return (typeof (Object
.extend
)=="function");
59 MochiKit
.Base
.update(PlotKit
.Base
,{roundInterval
:function(_1
,_2
,_3
){
60 var _4
=MochiKit
.Format
.roundToFixed
;
62 return parseFloat(_4(_5
,_3
));
63 },collapse
:function(_6
){
66 for(var i
=0;i
<_6
.length
;i
++){
67 _8
=m
.concat(_8
,_6
[i
]);
69 if(PlotKit
.Base
.usingPrototype()){
77 if(!m
.isArrayLike(_10
)||(_10
.length
<1)){
83 for(var i
=1;i
<_10
.length
;i
++){
84 if(m
.compare(_10
[i
],_12
)!=0){
90 },colorScheme
:function(){
92 var mc
=MochiKit
.Color
;
93 var _15
=["red","orange","yellow","green","cyan","blue","purple","magenta"];
94 var _16
=function(_17
){
95 return mc
.Color
[_17
+"Color"]();
97 return mb
.map(_16
,_15
);
98 },baseDarkPrimaryColors
:function(){
99 var _18
=MochiKit
.Color
.Color
.fromHexString
;
100 return [_18("#ad3f40"),_18("#ddac2c"),_18("#dfdd0c"),_18("#5276c4"),_18("#739c5a")];
101 },basePrimaryColors
:function(){
102 var _19
=MochiKit
.Color
.Color
.fromHexString
;
103 return [_19("#d24c4d"),_19("#f2b32f"),_19("#ece90e"),_19("#5d83da"),_19("#78a15d")];
104 },baseBlueColors
:function(){
105 var _20
=MochiKit
.Color
.Color
.fromHexString
;
106 return [_20("#4b6b94"),_20("#5d81b4"),_20("#acbad2")];
107 },palette
:function(_21
,_22
,_23
,_24
){
108 var _25
=MochiKit
.Base
.isUndefinedOrNull
;
124 var _28
=function(_29
,_30
){
125 return _29
.lighterColorWithLevel(_30
);
127 return MochiKit
.Base
.map(partial(_28
,_21
),_26
);
128 },excanvasSupported
:function(){
129 if(/MSIE/.test(navigator
.userAgent
)&&!window
.opera
){
133 },findPosX
:function(obj
){
135 if(obj
.offsetParent
){
136 while(obj
.offsetParent
){
138 obj
=obj
.offsetParent
;
146 },findPosY
:function(obj
){
148 if(obj
.offsetParent
){
149 while(obj
.offsetParent
){
151 obj
=obj
.offsetParent
;
159 },isFuncLike
:function(obj
){
160 return (typeof (obj
)=="function");
162 PlotKit
.Base
.map
=function(fn
,lst
){
163 if(PlotKit
.Base
.usingPrototype()){
166 if(typeof (lst
[x
])=="function"){
169 _36
.push(fn(lst
[x
]));
173 return MochiKit
.Base
.map(fn
,lst
);
176 PlotKit
.Base
.items
=function(lst
){
177 if(PlotKit
.Base
.usingPrototype()){
180 if(typeof (lst
[x
])=="function"){
183 _38
.push([x
,lst
[x
]]);
187 return MochiKit
.Base
.items(lst
);
190 PlotKit
.Base
.keys
=function(lst
){
191 if(PlotKit
.Base
.usingPrototype()){
194 if(typeof (lst
[x
])=="function"){
201 return MochiKit
.Base
.keys(lst
);
204 PlotKit
.Base
.baseColors
=function(){
205 var _40
=MochiKit
.Color
.Color
.fromHexString
;
206 return [_40("#476fb2"),_40("#be2c2b"),_40("#85b730"),_40("#734a99"),_40("#26a1c5"),_40("#fb8707"),_40("#000000")];
208 PlotKit
.Base
.officeBaseStyle
={"axisLineWidth":2,"axisLabelColor":Color
.grayColor(),"axisLineColor":Color
.whiteColor(),"padding":{top
:5,bottom
:10,left
:30,right
:30}};
209 MochiKit
.Base
.update(PlotKit
.Base
,{officeBlue
:function(){
210 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[0]),"backgroundColor":PlotKit
.Base
.baseColors()[0].lighterColorWithLevel(0.45)};
211 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
213 },officeRed
:function(){
214 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[1]),"backgroundColor":PlotKit
.Base
.baseColors()[1].lighterColorWithLevel(0.5)};
215 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
217 },officeGreen
:function(){
218 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[2]),"backgroundColor":PlotKit
.Base
.baseColors()[2].lighterColorWithLevel(0.5)};
219 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
221 },officePurple
:function(){
222 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[3]),"backgroundColor":PlotKit
.Base
.baseColors()[3].lighterColorWithLevel(0.5)};
223 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
225 },officeCyan
:function(){
226 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[4]),"backgroundColor":PlotKit
.Base
.baseColors()[4].lighterColorWithLevel(0.5)};
227 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
229 },officeOrange
:function(){
230 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[5]),"backgroundColor":PlotKit
.Base
.baseColors()[5].lighterColorWithLevel(0.4)};
231 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
233 },officeBlack
:function(){
234 var r
={"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[6],0,0.6),"backgroundColor":PlotKit
.Base
.baseColors()[6].lighterColorWithLevel(0.9)};
235 MochiKit
.Base
.update(r
,PlotKit
.Base
.officeBaseStyle
);
238 PlotKit
.Base
.EXPORT
=["baseColors","collapse","colorScheme","findPosX","findPosY","officeBaseStyle","officeBlue","officeRed","officeGreen","officePurple","officeCyan","officeOrange","officeBlack","roundInterval","uniq","isFuncLike","excanvasSupported"];
239 PlotKit
.Base
.EXPORT_OK
=[];
240 PlotKit
.Base
.__new__
=function(){
242 m
.nameFunctions(this);
243 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
245 PlotKit
.Base
.__new__();
246 MochiKit
.Base
._exportSymbols(this,PlotKit
.Base
);
248 if(typeof (PlotKit
.Base
)=="undefined"){
253 throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.Base";
255 if(typeof (PlotKit
.Layout
)=="undefined"){
258 PlotKit
.Layout
.NAME
="PlotKit.Layout";
259 PlotKit
.Layout
.VERSION
=PlotKit
.VERSION
;
260 PlotKit
.Layout
.__repr__
=function(){
261 return "["+this.NAME
+" "+this.VERSION
+"]";
263 PlotKit
.Layout
.toString
=function(){
264 return this.__repr__();
266 PlotKit
.Layout
.valid_styles
=["bar","line","pie","point"];
267 PlotKit
.Layout
=function(_42
,_43
){
268 this.options
={"barWidthFillFraction":0.75,"barOrientation":"vertical","xOriginIsZero":true,"yOriginIsZero":true,"xAxis":null,"yAxis":null,"xTicks":null,"yTicks":null,"xNumberOfTicks":10,"yNumberOfTicks":5,"xTickPrecision":1,"yTickPrecision":1,"pieRadius":0.4};
270 MochiKit
.Base
.update(this.options
,_43
?_43
:{});
271 if(!MochiKit
.Base
.isUndefinedOrNull(this.options
.xAxis
)){
272 this.minxval
=this.options
.xAxis
[0];
273 this.maxxval
=this.options
.xAxis
[1];
274 this.xscale
=this.maxxval
-this.minxval
;
280 if(!MochiKit
.Base
.isUndefinedOrNull(this.options
.yAxis
)){
281 this.minyval
=this.options
.yAxis
[0];
282 this.maxyval
=this.options
.yAxis
[1];
283 this.yscale
=this.maxyval
-this.minyval
;
289 this.bars
=new Array();
290 this.points
=new Array();
291 this.slices
=new Array();
292 this.xticks
=new Array();
293 this.yticks
=new Array();
294 this.datasets
=new Array();
298 this.hitTestCache
={x2maxy
:null};
300 PlotKit
.Layout
.prototype.addDataset
=function(_44
,_45
){
301 this.datasets
[_44
]=_45
;
303 PlotKit
.Layout
.prototype.removeDataset
=function(_46
,_47
){
304 delete this.datasets
[_46
];
306 PlotKit
.Layout
.prototype.addDatasetFromTable
=function(_48
,_49
,_50
,_51
,_52
){
307 var _53
=MochiKit
.Base
.isUndefinedOrNull
;
308 var _54
=MochiKit
.DOM
.scrapeText
;
309 var _55
=MochiKit
.Format
.strip
;
319 var _56
=_49
.tBodies
[0].rows
;
323 for(var i
=0;i
<_56
.length
;i
++){
324 _57
.push([parseFloat(_55(_54(_56
[i
].cells
[_50
]))),parseFloat(_55(_54(_56
[i
].cells
[_51
])))]);
326 _58
.push({v
:parseFloat(_55(_54(_56
[i
].cells
[_50
]))),label
:_55(_54(_56
[i
].cells
[_52
]))});
329 this.addDataset(_48
,_57
);
331 this.options
.xTicks
=_58
;
337 PlotKit
.Layout
.prototype.evaluate
=function(){
338 this._evaluateLimits();
339 this._evaluateScales();
340 if(this.style
=="bar"){
341 if(this.options
.barOrientation
=="horizontal"){
342 this._evaluateHorizBarCharts();
344 this._evaluateBarCharts();
346 this._evaluateBarTicks();
348 if(this.style
=="line"){
349 this._evaluateLineCharts();
350 this._evaluateLineTicks();
352 if(this.style
=="pie"){
353 this._evaluatePieCharts();
354 this._evaluatePieTicks();
359 PlotKit
.Layout
.prototype.hitTest
=function(x
,y
){
360 var f
=MochiKit
.Format
.twoDigitFloat
;
361 if((this.style
=="bar")&&this.bars
&&(this.bars
.length
>0)){
362 for(var i
=0;i
<this.bars
.length
;i
++){
363 var bar
=this.bars
[i
];
364 if((x
>=bar
.x
)&&(x
<=bar
.x
+bar
.w
)&&(y
>=bar
.y
)&&(y
-bar
.y
<=bar
.h
)){
369 if(this.style
=="line"){
370 if(this.hitTestCache
.x2maxy
==null){
371 this._regenerateHitTestCache();
373 var _62
=x
/this.xscale
;
374 var _63
=this.hitTestCache
.xvalues
;
377 for(var i
=1;i
<_63
.length
;i
++){
385 var _66
=this.hitTestCache
.x2maxy
[_64
];
386 var _67
=this.hitTestCache
.x2maxy
[_65
];
387 var _68
=(1-y
)/this.yscale
;
388 var _69
=(_67
-_66
)/(_65
-_64
);
389 var _70
=_66
+_69
*(_62
-_64
);
391 var obj
={xval
:_62
,yval
:_68
,xafter
:_65
,yafter
:_67
,xbefore
:_64
,ybefore
:_66
,yprojected
:_70
};
396 if(this.style
=="pie"){
397 var _71
=Math
.sqrt((y
-0.5)*(y
-0.5)+(x
-0.5)*(x
-0.5));
398 if(_71
>this.options
.pieRadius
){
401 var _72
=Math
.atan2(y
-0.5,x
-0.5)-Math
.PI
/2;
402 for(var i
=0;i
<this.slices
.length
;i
++){
403 var _73
=this.slices
[i
];
404 if(_73
.startAngle
<_72
&&_73
.endAngle
>=_72
){
413 PlotKit
.Layout
.prototype.rectForX
=function(x
){
416 PlotKit
.Layout
.prototype.angleRangeForX
=function(x
){
419 PlotKit
.Layout
.prototype._evaluateLimits
=function(){
420 var map
=PlotKit
.Base
.map
;
421 var _75
=PlotKit
.Base
.items
;
422 var _76
=MochiKit
.Base
.itemgetter
;
423 var _77
=PlotKit
.Base
.collapse
;
424 var _78
=MochiKit
.Base
.listMin
;
425 var _79
=MochiKit
.Base
.listMax
;
426 var _80
=MochiKit
.Base
.isUndefinedOrNull
;
427 var all
=_77(map(_76(1),_75(this.datasets
)));
428 if(_80(this.options
.xAxis
)){
429 if(this.options
.xOriginIsZero
){
432 this.minxval
=_78(map(parseFloat
,map(_76(0),all
)));
434 this.maxxval
=_79(map(parseFloat
,map(_76(0),all
)));
436 this.minxval
=this.options
.xAxis
[0];
437 this.maxxval
=this.options
.xAxis
[1];
438 this.xscale
=this.maxval
-this.minxval
;
440 if(_80(this.options
.yAxis
)){
441 if(this.options
.yOriginIsZero
){
444 this.minyval
=_78(map(parseFloat
,map(_76(1),all
)));
446 this.maxyval
=_79(map(parseFloat
,map(_76(1),all
)));
448 this.minyval
=this.options
.yAxis
[0];
449 this.maxyval
=this.options
.yAxis
[1];
450 this.yscale
=this.maxyval
-this.minyval
;
453 PlotKit
.Layout
.prototype._evaluateScales
=function(){
454 var _82
=MochiKit
.Base
.isUndefinedOrNull
;
455 this.xrange
=this.maxxval
-this.minxval
;
459 this.xscale
=1/this.xrange
;
461 this.yrange
=this.maxyval
-this.minyval
;
465 this.yscale
=1/this.yrange
;
468 PlotKit
.Layout
.prototype._uniqueXValues
=function(){
469 var _83
=PlotKit
.Base
.collapse
;
470 var map
=PlotKit
.Base
.map
;
471 var _84
=PlotKit
.Base
.uniq
;
472 var _85
=MochiKit
.Base
.itemgetter
;
473 var _86
=PlotKit
.Base
.items
;
474 var _87
=map(parseFloat
,map(_85(0),_83(map(_85(1),_86(this.datasets
)))));
475 _87
.sort(MochiKit
.Base
.compare
);
478 PlotKit
.Layout
.prototype._evaluateBarCharts
=function(){
479 var _88
=PlotKit
.Base
.items
;
480 var _89
=_88(this.datasets
).length
;
482 var _91
=this._uniqueXValues();
483 for(var i
=1;i
<_91
.length
;i
++){
484 _90
=Math
.min(Math
.abs(_91
[i
]-_91
[i
-1]),_90
);
493 _92
=1*this.options
.barWidthFillFraction
;
495 _94
=(1-this.options
.barWidthFillFraction
)/2;
503 this.xscale
=(1-_90
/this.xrange)/this.xrange
;
506 _92
=_90
*this.xscale
*this.options
.barWidthFillFraction
;
508 _94
=_90
*this.xscale
*(1-this.options
.barWidthFillFraction
)/2;
511 this.bars
=new Array();
513 for(var _95
in this.datasets
){
514 var _96
=this.datasets
[_95
];
515 if(PlotKit
.Base
.isFuncLike(_96
)){
518 for(var j
=0;j
<_96
.length
;j
++){
520 var _99
={x
:((parseFloat(_98
[0])-this.minxval
)*this.xscale
)+(i
*_93
)+_94
,y
:1-((parseFloat(_98
[1])-this.minyval
)*this.yscale
),w
:_93
,h
:((parseFloat(_98
[1])-this.minyval
)*this.yscale
),xval
:parseFloat(_98
[0]),yval
:parseFloat(_98
[1]),name
:_95
};
521 if((_99
.x
>=0)&&(_99
.x
<=1)&&(_99
.y
>=0)&&(_99
.y
<=1)){
528 PlotKit
.Layout
.prototype._evaluateHorizBarCharts
=function(){
529 var _100
=PlotKit
.Base
.items
;
530 var _101
=_100(this.datasets
).length
;
532 var _103
=this._uniqueXValues();
533 for(var i
=1;i
<_103
.length
;i
++){
534 _102
=Math
.min(Math
.abs(_103
[i
]-_103
[i
-1]),_102
);
542 this.minxval
=_103
[0];
543 _104
=1*this.options
.barWidthFillFraction
;
545 _106
=(1-this.options
.barWidthFillFraction
)/2;
547 this.xscale
=(1-_102
/this.xrange)/this.xrange
;
548 _104
=_102
*this.xscale
*this.options
.barWidthFillFraction
;
550 _106
=_102
*this.xscale
*(1-this.options
.barWidthFillFraction
)/2;
553 this.bars
=new Array();
555 for(var _107
in this.datasets
){
556 var _108
=this.datasets
[_107
];
557 if(PlotKit
.Base
.isFuncLike(_108
)){
560 for(var j
=0;j
<_108
.length
;j
++){
562 var rect
={y
:((parseFloat(item
[0])-this.minxval
)*this.xscale
)+(i
*_105
)+_106
,x
:0,h
:_105
,w
:((parseFloat(item
[1])-this.minyval
)*this.yscale
),xval
:parseFloat(item
[0]),yval
:parseFloat(item
[1]),name
:_107
};
569 if((rect
.x
>=0)&&(rect
.x
<=1)){
570 this.bars
.push(rect
);
576 PlotKit
.Layout
.prototype._evaluateLineCharts
=function(){
577 var _111
=PlotKit
.Base
.items
;
578 var _112
=_111(this.datasets
).length
;
579 this.points
=new Array();
581 for(var _113
in this.datasets
){
582 var _114
=this.datasets
[_113
];
583 if(PlotKit
.Base
.isFuncLike(_114
)){
586 _114
.sort(function(a
,b
){
587 return compare(parseFloat(a
[0]),parseFloat(b
[0]));
589 for(var j
=0;j
<_114
.length
;j
++){
591 var _117
={x
:((parseFloat(item
[0])-this.minxval
)*this.xscale
),y
:1-((parseFloat(item
[1])-this.minyval
)*this.yscale
),xval
:parseFloat(item
[0]),yval
:parseFloat(item
[1]),name
:_113
};
598 if((_117
.x
>=0)&&(_117
.x
<=1)){
599 this.points
.push(_117
);
605 PlotKit
.Layout
.prototype._evaluatePieCharts
=function(){
606 var _118
=PlotKit
.Base
.items
;
607 var sum
=MochiKit
.Iter
.sum
;
608 var _120
=MochiKit
.Base
.itemgetter
;
609 var _121
=_118(this.datasets
).length
;
610 var _122
=_118(this.datasets
)[0][1];
611 var _123
=sum(map(_120(1),_122
));
612 this.slices
=new Array();
614 for(var i
=0;i
<_122
.length
;i
++){
615 var _125
=_122
[i
][1]/_123
;
616 var _126
=_124
*Math
.PI
*2;
617 var _127
=(_124
+_125
)*Math
.PI
*2;
618 var _128
={fraction
:_125
,xval
:_122
[i
][0],yval
:_122
[i
][1],startAngle
:_126
,endAngle
:_127
};
620 this.slices
.push(_128
);
625 PlotKit
.Layout
.prototype._evaluateLineTicksForXAxis
=function(){
626 var _129
=MochiKit
.Base
.isUndefinedOrNull
;
627 if(this.options
.xTicks
){
628 this.xticks
=new Array();
629 var _130
=function(tick
){
632 _132
=tick
.v
.toString();
634 var pos
=this.xscale
*(tick
.v
-this.minxval
);
635 if((pos
>=0)&&(pos
<=1)){
636 this.xticks
.push([pos
,_132
]);
639 MochiKit
.Iter
.forEach(this.options
.xTicks
,bind(_130
,this));
641 if(this.options
.xNumberOfTicks
){
642 var _134
=this._uniqueXValues();
643 var _135
=this.xrange
/this.options
.xNumberOfTicks
;
645 this.xticks
=new Array();
646 for(var i
=0;i
<=_134
.length
;i
++){
647 if((_134
[i
]-this.minxval
)>=(_136
*_135
)){
648 var pos
=this.xscale
*(_134
[i
]-this.minxval
);
649 if((pos
>1)||(pos
<0)){
652 this.xticks
.push([pos
,_134
[i
]]);
655 if(_136
>this.options
.xNumberOfTicks
){
662 PlotKit
.Layout
.prototype._evaluateLineTicksForYAxis
=function(){
663 var _137
=MochiKit
.Base
.isUndefinedOrNull
;
664 if(this.options
.yTicks
){
665 this.yticks
=new Array();
666 var _138
=function(tick
){
669 _139
=tick
.v
.toString();
671 var pos
=1-(this.yscale
*(tick
.v
-this.minyval
));
672 if((pos
>=0)&&(pos
<=1)){
673 this.yticks
.push([pos
,_139
]);
676 MochiKit
.Iter
.forEach(this.options
.yTicks
,bind(_138
,this));
678 if(this.options
.yNumberOfTicks
){
679 this.yticks
=new Array();
680 var _140
=PlotKit
.Base
.roundInterval
;
681 var prec
=this.options
.yTickPrecision
;
682 var _142
=_140(this.yrange
,this.options
.yNumberOfTicks
,prec
);
683 for(var i
=0;i
<=this.options
.yNumberOfTicks
;i
++){
684 var yval
=this.minyval
+(i
*_142
);
685 var pos
=1-((yval
-this.minyval
)*this.yscale
);
686 if((pos
>1)||(pos
<0)){
689 this.yticks
.push([pos
,MochiKit
.Format
.roundToFixed(yval
,prec
)]);
694 PlotKit
.Layout
.prototype._evaluateLineTicks
=function(){
695 this._evaluateLineTicksForXAxis();
696 this._evaluateLineTicksForYAxis();
698 PlotKit
.Layout
.prototype._evaluateBarTicks
=function(){
699 this._evaluateLineTicks();
700 var _144
=function(tick
){
701 return [tick
[0]+(this.minxdelta
*this.xscale
)/2,tick
[1]];
703 this.xticks
=MochiKit
.Base
.map(bind(_144
,this),this.xticks
);
704 if(this.options
.barOrientation
=="horizontal"){
705 var _145
=this.xticks
;
706 this.xticks
=this.yticks
;
708 var _146
=function(tick
){
709 return [1-tick
[0],tick
[1]];
711 this.xticks
=MochiKit
.Base
.map(_146
,this.xticks
);
714 PlotKit
.Layout
.prototype._evaluatePieTicks
=function(){
715 var _147
=MochiKit
.Base
.isUndefinedOrNull
;
716 var _148
=MochiKit
.Format
.numberFormatter("#%");
717 this.xticks
=new Array();
718 if(this.options
.xTicks
){
719 var _149
=new Array();
720 for(var i
=0;i
<this.slices
.length
;i
++){
721 _149
[this.slices
[i
].xval
]=this.slices
[i
];
723 for(var i
=0;i
<this.options
.xTicks
.length
;i
++){
724 var tick
=this.options
.xTicks
[i
];
725 var _150
=_149
[tick
.v
];
729 _151
=tick
.v
.toString();
731 _151
+=" ("+_148(_150
.fraction
)+")";
732 this.xticks
.push([tick
.v
,_151
]);
736 for(var i
=0;i
<this.slices
.length
;i
++){
737 var _150
=this.slices
[i
];
738 var _151
=_150
.xval
+" ("+_148(_150
.fraction
)+")";
739 this.xticks
.push([_150
.xval
,_151
]);
743 PlotKit
.Layout
.prototype._regenerateHitTestCache
=function(){
744 this.hitTestCache
.xvalues
=this._uniqueXValues();
745 this.hitTestCache
.xlookup
=new Array();
746 this.hitTestCache
.x2maxy
=new Array();
747 var _152
=MochiKit
.Base
.listMax
;
748 var _153
=MochiKit
.Base
.itemgetter
;
749 var map
=MochiKit
.Base
.map
;
750 var _154
=keys(this.datasets
);
751 for(var i
=0;i
<_154
.length
;i
++){
752 var _155
=this.datasets
[_154
[i
]];
753 for(var j
=0;j
<_155
.length
;j
++){
756 if(this.hitTestCache
.xlookup
[xval
]){
757 this.hitTestCache
.xlookup
[xval
].push([yval
,_154
[i
]]);
759 this.hitTestCache
.xlookup
[xval
]=[[yval
,_154
[i
]]];
763 for(var x
in this.hitTestCache
.xlookup
){
764 var _157
=this.hitTestCache
.xlookup
[x
];
765 this.hitTestCache
.x2maxy
[x
]=_152(map(_153(0),_157
));
768 PlotKit
.LayoutModule
={};
769 PlotKit
.LayoutModule
.Layout
=PlotKit
.Layout
;
770 PlotKit
.LayoutModule
.EXPORT
=["Layout"];
771 PlotKit
.LayoutModule
.EXPORT_OK
=[];
772 PlotKit
.LayoutModule
.__new__
=function(){
774 m
.nameFunctions(this);
775 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
777 PlotKit
.LayoutModule
.__new__();
778 MochiKit
.Base
._exportSymbols(this,PlotKit
.LayoutModule
);
780 if((typeof (PlotKit
.Base
)=="undefined")||(typeof (PlotKit
.Layout
)=="undefined")){
785 throw "PlotKit.Layout depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Base,Layout}";
787 if(typeof (PlotKit
.CanvasRenderer
)=="undefined"){
788 PlotKit
.CanvasRenderer
={};
790 PlotKit
.CanvasRenderer
.NAME
="PlotKit.CanvasRenderer";
791 PlotKit
.CanvasRenderer
.VERSION
=PlotKit
.VERSION
;
792 PlotKit
.CanvasRenderer
.__repr__
=function(){
793 return "["+this.NAME
+" "+this.VERSION
+"]";
795 PlotKit
.CanvasRenderer
.toString
=function(){
796 return this.__repr__();
798 PlotKit
.CanvasRenderer
=function(_158
,_159
,_160
){
799 if(arguments
.length
>0){
800 this.__init__(_158
,_159
,_160
);
803 PlotKit
.CanvasRenderer
.prototype.__init__
=function(_161
,_162
,_163
){
804 var _164
=MochiKit
.Base
.isUndefinedOrNull
;
805 var _165
=MochiKit
.Color
.Color
;
806 this.options
={"drawBackground":true,"backgroundColor":_165
.whiteColor(),"padding":{left
:30,right
:30,top
:5,bottom
:10},"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[0]),"strokeColor":_165
.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":_165
.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":_165
.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"pieRadius":0.4,"enableEvents":true};
807 MochiKit
.Base
.update(this.options
,_163
?_163
:{});
809 this.element
=MochiKit
.DOM
.getElement(_161
);
810 this.container
=this.element
.parentNode
;
811 this.isIE
=PlotKit
.Base
.excanvasSupported();
812 if(this.isIE
&&!_164(G_vmlCanvasManager
)){
815 this.renderDelay
=null;
816 this.clearDelay
=null;
817 this.element
=G_vmlCanvasManager
.initElement(this.element
);
819 this.height
=this.element
.height
;
820 this.width
=this.element
.width
;
821 if(_164(this.element
)){
822 throw "CanvasRenderer() - passed canvas is not found";
824 if(!this.isIE
&&!(PlotKit
.CanvasRenderer
.isSupported(this.element
))){
825 throw "CanvasRenderer() - Canvas is not supported.";
827 if(_164(this.container
)||(this.container
.nodeName
.toLowerCase()!="div")){
828 throw "CanvasRenderer() - <canvas> needs to be enclosed in <div>";
830 this.xlabels
=new Array();
831 this.ylabels
=new Array();
832 this.isFirstRender
=true;
833 this.area
={x
:this.options
.padding
.left
,y
:this.options
.padding
.top
,w
:this.width
-this.options
.padding
.left
-this.options
.padding
.right
,h
:this.height
-this.options
.padding
.top
-this.options
.padding
.bottom
};
834 MochiKit
.DOM
.updateNodeAttributes(this.container
,{"style":{"position":"relative","width":this.width
+"px"}});
836 PlotKit
.CanvasRenderer
.prototype.render
=function(){
839 if(this.renderDelay
){
840 this.renderDelay
.cancel();
841 this.renderDelay
=null;
843 var _166
=this.element
.getContext("2d");
846 this.isFirstRender
=false;
847 if(this.maxTries
-->0){
848 this.renderDelay
=MochiKit
.Async
.wait(this.IEDelay
);
849 this.renderDelay
.addCallback(bind(this.render
,this));
854 if(this.options
.drawBackground
){
855 this._renderBackground();
857 if(this.layout
.style
=="bar"){
858 this._renderBarChart();
859 this._renderBarAxis();
861 if(this.layout
.style
=="pie"){
862 this._renderPieChart();
863 this._renderPieAxis();
865 if(this.layout
.style
=="line"){
866 this._renderLineChart();
867 this._renderLineAxis();
872 PlotKit
.CanvasRenderer
.prototype._renderBarChartWrap
=function(data
,_168
){
873 var _169
=this.element
.getContext("2d");
874 var _170
=this.options
.colorScheme
.length
;
875 var _171
=this.options
.colorScheme
;
876 var _172
=MochiKit
.Base
.keys(this.layout
.datasets
);
877 var _173
=_172
.length
;
878 for(var i
=0;i
<_173
;i
++){
880 var _175
=_171
[i
%_170
];
882 _169
.fillStyle
=_175
.toRGBString();
883 if(this.options
.strokeColor
){
884 _169
.strokeStyle
=this.options
.strokeColor
.toRGBString();
886 if(this.options
.strokeColorTransform
){
887 _169
.strokeStyle
=_175
[this.options
.strokeColorTransform
]().toRGBString();
890 _169
.lineWidth
=this.options
.strokeWidth
;
891 var _176
=function(obj
){
896 MochiKit
.Iter
.forEach(data
,bind(_176
,this));
900 PlotKit
.CanvasRenderer
.prototype._renderBarChart
=function(){
901 var bind
=MochiKit
.Base
.bind
;
902 var _178
=function(_179
,bar
){
903 var x
=this.area
.w
*bar
.x
+this.area
.x
;
904 var y
=this.area
.h
*bar
.y
+this.area
.y
;
905 var w
=this.area
.w
*bar
.w
;
906 var h
=this.area
.h
*bar
.h
;
910 if(this.options
.shouldFill
){
911 _179
.fillRect(x
,y
,w
,h
);
913 if(this.options
.shouldStroke
){
914 _179
.strokeRect(x
,y
,w
,h
);
917 this._renderBarChartWrap(this.layout
.bars
,bind(_178
,this));
919 PlotKit
.CanvasRenderer
.prototype._renderLineChart
=function(){
920 var _182
=this.element
.getContext("2d");
921 var _183
=this.options
.colorScheme
.length
;
922 var _184
=this.options
.colorScheme
;
923 var _185
=MochiKit
.Base
.keys(this.layout
.datasets
);
924 var _186
=_185
.length
;
925 var bind
=MochiKit
.Base
.bind
;
926 var _187
=MochiKit
.Base
.partial
;
927 for(var i
=0;i
<_186
;i
++){
929 var _189
=_184
[i
%_183
];
930 var _190
=this.options
.strokeColorTransform
;
932 _182
.fillStyle
=_189
.toRGBString();
933 if(this.options
.strokeColor
){
934 _182
.strokeStyle
=this.options
.strokeColor
.toRGBString();
936 if(this.options
.strokeColorTransform
){
937 _182
.strokeStyle
=_189
[_190
]().toRGBString();
940 _182
.lineWidth
=this.options
.strokeWidth
;
941 var _191
=function(ctx
){
943 ctx
.moveTo(this.area
.x
,this.area
.y
+this.area
.h
);
944 var _193
=function(ctx_
,_195
){
946 ctx_
.lineTo(this.area
.w
*_195
.x
+this.area
.x
,this.area
.h
*_195
.y
+this.area
.y
);
949 MochiKit
.Iter
.forEach(this.layout
.points
,_187(_193
,ctx
),this);
950 ctx
.lineTo(this.area
.w
+this.area
.x
,this.area
.h
+this.area
.y
);
951 ctx
.lineTo(this.area
.x
,this.area
.y
+this.area
.h
);
954 if(this.options
.shouldFill
){
955 bind(_191
,this)(_182
);
958 if(this.options
.shouldStroke
){
959 bind(_191
,this)(_182
);
965 PlotKit
.CanvasRenderer
.prototype._renderPieChart
=function(){
966 var _196
=this.element
.getContext("2d");
967 var _197
=this.options
.colorScheme
.length
;
968 var _198
=this.layout
.slices
;
969 var _199
=this.area
.x
+this.area
.w
*0.5;
970 var _200
=this.area
.y
+this.area
.h
*0.5;
971 var _201
=Math
.min(this.area
.w
*this.options
.pieRadius
,this.area
.h
*this.options
.pieRadius
);
977 for(var i
=0;i
<_198
.length
;i
++){
978 var _202
=this.options
.colorScheme
[i
%_197
];
980 _196
.fillStyle
=_202
.toRGBString();
983 _196
.moveTo(_199
,_200
);
984 _196
.arc(_199
,_200
,_201
,_198
[i
].startAngle
-Math
.PI
/2,_198[i].endAngle-Math.PI/2,false);
985 _196
.lineTo(_199
,_200
);
988 if(Math
.abs(_198
[i
].startAngle
-_198
[i
].endAngle
)>0.001){
989 if(this.options
.shouldFill
){
993 if(this.options
.shouldStroke
){
995 _196
.lineWidth
=this.options
.strokeWidth
;
996 if(this.options
.strokeColor
){
997 _196
.strokeStyle
=this.options
.strokeColor
.toRGBString();
999 if(this.options
.strokeColorTransform
){
1000 _196
.strokeStyle
=_202
[this.options
.strokeColorTransform
]().toRGBString();
1009 PlotKit
.CanvasRenderer
.prototype._renderBarAxis
=function(){
1012 PlotKit
.CanvasRenderer
.prototype._renderLineAxis
=function(){
1015 PlotKit
.CanvasRenderer
.prototype._renderAxis
=function(){
1016 if(!this.options
.drawXAxis
&&!this.options
.drawYAxis
){
1019 var _204
=this.element
.getContext("2d");
1020 var _205
={"style":{"position":"absolute","fontSize":this.options
.axisLabelFontSize
+"px","zIndex":10,"color":this.options
.axisLabelColor
.toRGBString(),"width":this.options
.axisLabelWidth
+"px","overflow":"hidden"}};
1022 _204
.strokeStyle
=this.options
.axisLineColor
.toRGBString();
1023 _204
.lineWidth
=this.options
.axisLineWidth
;
1024 if(this.options
.drawYAxis
){
1025 if(this.layout
.yticks
){
1026 var _206
=function(tick
){
1027 if(typeof (tick
)=="function"){
1031 var y
=this.area
.y
+tick
[0]*this.area
.h
;
1034 _204
.lineTo(x
-this.options
.axisTickSize
,y
);
1037 var _207
=DIV(_205
,tick
[1]);
1038 _207
.style
.top
=(y
-this.options
.axisLabelFontSize
)+"px";
1039 _207
.style
.left
=(x
-this.options
.padding
.left
-this.options
.axisTickSize
)+"px";
1040 _207
.style
.textAlign
="right";
1041 _207
.style
.width
=(this.options
.padding
.left
-this.options
.axisTickSize
*2)+"px";
1042 MochiKit
.DOM
.appendChildNodes(this.container
,_207
);
1043 this.ylabels
.push(_207
);
1045 MochiKit
.Iter
.forEach(this.layout
.yticks
,bind(_206
,this));
1048 _204
.moveTo(this.area
.x
,this.area
.y
);
1049 _204
.lineTo(this.area
.x
,this.area
.y
+this.area
.h
);
1053 if(this.options
.drawXAxis
){
1054 if(this.layout
.xticks
){
1055 var _206
=function(tick
){
1056 if(typeof (dataset
)=="function"){
1059 var x
=this.area
.x
+tick
[0]*this.area
.w
;
1060 var y
=this.area
.y
+this.area
.h
;
1063 _204
.lineTo(x
,y
+this.options
.axisTickSize
);
1066 var _208
=DIV(_205
,tick
[1]);
1067 _208
.style
.top
=(y
+this.options
.axisTickSize
)+"px";
1068 _208
.style
.left
=(x
-this.options
.axisLabelWidth
/2)+"px";
1069 _208
.style
.textAlign
="center";
1070 _208
.style
.width
=this.options
.axisLabelWidth
+"px";
1071 MochiKit
.DOM
.appendChildNodes(this.container
,_208
);
1072 this.xlabels
.push(_208
);
1074 MochiKit
.Iter
.forEach(this.layout
.xticks
,bind(_206
,this));
1077 _204
.moveTo(this.area
.x
,this.area
.y
+this.area
.h
);
1078 _204
.lineTo(this.area
.x
+this.area
.w
,this.area
.y
+this.area
.h
);
1084 PlotKit
.CanvasRenderer
.prototype._renderPieAxis
=function(){
1085 if(!this.options
.drawXAxis
){
1088 if(this.layout
.xticks
){
1089 var _209
=new Array();
1090 for(var i
=0;i
<this.layout
.slices
.length
;i
++){
1091 _209
[this.layout
.slices
[i
].xval
]=this.layout
.slices
[i
];
1093 var _210
=this.area
.x
+this.area
.w
*0.5;
1094 var _211
=this.area
.y
+this.area
.h
*0.5;
1095 var _212
=Math
.min(this.area
.w
*this.options
.pieRadius
,this.area
.h
*this.options
.pieRadius
);
1096 var _213
=this.options
.axisLabelWidth
;
1097 for(var i
=0;i
<this.layout
.xticks
.length
;i
++){
1098 var _214
=_209
[this.layout
.xticks
[i
][0]];
1099 if(MochiKit
.Base
.isUndefinedOrNull(_214
)){
1102 var _215
=(_214
.startAngle
+_214
.endAngle
)/2;
1105 _216
=_216
-Math
.PI
*2;
1108 _216
=_216
+Math
.PI
*2;
1111 var _217
=_210
+Math
.sin(_216
)*(_212
+10);
1112 var _218
=_211
-Math
.cos(_216
)*(_212
+10);
1113 var _219
={"position":"absolute","zIndex":11,"width":_213
+"px","fontSize":this.options
.axisLabelFontSize
+"px","overflow":"hidden","color":this.options
.axisLabelColor
.toHexString()};
1114 if(_216
<=Math
.PI
*0.5){
1115 _219
["textAlign"]="left";
1116 _219
["verticalAlign"]="top";
1117 _219
["left"]=_217
+"px";
1118 _219
["top"]=(_218
-this.options
.axisLabelFontSize
)+"px";
1120 if((_216
>Math
.PI
*0.5)&&(_216
<=Math
.PI
)){
1121 _219
["textAlign"]="left";
1122 _219
["verticalAlign"]="bottom";
1123 _219
["left"]=_217
+"px";
1124 _219
["top"]=_218
+"px";
1126 if((_216
>Math
.PI
)&&(_216
<=Math
.PI
*1.5)){
1127 _219
["textAlign"]="right";
1128 _219
["verticalAlign"]="bottom";
1129 _219
["left"]=(_217
-_213
)+"px";
1130 _219
["top"]=_218
+"px";
1132 _219
["textAlign"]="right";
1133 _219
["verticalAlign"]="bottom";
1134 _219
["left"]=(_217
-_213
)+"px";
1135 _219
["top"]=(_218
-this.options
.axisLabelFontSize
)+"px";
1139 var _220
=DIV({"style":_219
},this.layout
.xticks
[i
][1]);
1140 this.xlabels
.push(_220
);
1141 MochiKit
.DOM
.appendChildNodes(this.container
,_220
);
1145 PlotKit
.CanvasRenderer
.prototype._renderBackground
=function(){
1146 var _221
=this.element
.getContext("2d");
1148 _221
.fillStyle
=this.options
.backgroundColor
.toRGBString();
1149 _221
.fillRect(0,0,this.width
,this.height
);
1152 PlotKit
.CanvasRenderer
.prototype.clear
=function(){
1155 if(this.clearDelay
){
1156 this.clearDelay
.cancel();
1157 this.clearDelay
=null;
1159 var _222
=this.element
.getContext("2d");
1162 this.isFirstRender
=false;
1163 this.clearDelay
=MochiKit
.Async
.wait(this.IEDelay
);
1164 this.clearDelay
.addCallback(bind(this.clear
,this));
1168 var _222
=this.element
.getContext("2d");
1169 _222
.clearRect(0,0,this.width
,this.height
);
1170 MochiKit
.Iter
.forEach(this.xlabels
,MochiKit
.DOM
.removeElement
);
1171 MochiKit
.Iter
.forEach(this.ylabels
,MochiKit
.DOM
.removeElement
);
1172 this.xlabels
=new Array();
1173 this.ylabels
=new Array();
1175 PlotKit
.CanvasRenderer
.prototype._initialiseEvents
=function(){
1176 var _223
=MochiKit
.Signal
.connect
;
1177 var bind
=MochiKit
.Base
.bind
;
1178 _223(this.element
,"onclick",bind(this.onclick
,this));
1180 PlotKit
.CanvasRenderer
.prototype._resolveObject
=function(e
){
1181 var x
=(e
.mouse().page
.x
-PlotKit
.Base
.findPosX(this.element
)-this.area
.x
)/this.area
.w
;
1182 var y
=(e
.mouse().page
.y
-PlotKit
.Base
.findPosY(this.element
)-this.area
.y
)/this.area
.h
;
1183 var _225
=this.layout
.hitTest(x
,y
);
1189 PlotKit
.CanvasRenderer
.prototype._createEventObject
=function(_226
,e
){
1196 PlotKit
.CanvasRenderer
.prototype.onclick
=function(e
){
1197 var _227
=this._resolveObject(e
);
1198 var _228
=this._createEventObject(_227
,e
);
1200 MochiKit
.Signal
.signal(this,"onclick",_228
);
1203 PlotKit
.CanvasRenderer
.prototype.onmouseover
=function(e
){
1204 var _229
=this._resolveObject(e
);
1205 var _230
=this._createEventObject(_229
,e
);
1207 signal(this,"onmouseover",_230
);
1210 PlotKit
.CanvasRenderer
.prototype.onmouseout
=function(e
){
1211 var _231
=this._resolveObject(e
);
1212 var _232
=this._createEventObject(_231
,e
);
1214 signal(this,"onmouseout",e
);
1216 signal(this,"onmouseout",_232
);
1219 PlotKit
.CanvasRenderer
.prototype.onmousemove
=function(e
){
1220 var _233
=this._resolveObject(e
);
1221 var _234
=this._createEventObject(_233
,e
);
1222 if((_233
==null)&&(this.event_isinside
==null)){
1225 if((_233
!=null)&&(this.event_isinside
==null)){
1226 signal(this,"onmouseover",_234
);
1228 if((_233
==null)&&(this.event_isinside
!=null)){
1229 signal(this,"onmouseout",_234
);
1231 if((_233
!=null)&&(this.event_isinside
!=null)){
1232 signal(this,"onmousemove",_234
);
1234 this.event_isinside
=_233
;
1236 PlotKit
.CanvasRenderer
.isSupported
=function(_235
){
1239 if(MochiKit
.Base
.isUndefinedOrNull(_235
)){
1240 _236
=MochiKit
.DOM
.CANVAS({});
1242 _236
=MochiKit
.DOM
.getElement(_235
);
1244 var _237
=_236
.getContext("2d");
1247 var ie
=navigator
.appVersion
.match(/MSIE (\d\.\d)/);
1248 var _239
=(navigator
.userAgent
.toLowerCase().indexOf("opera")!=-1);
1249 if((!ie
)||(ie
[1]<6)||(_239
)){
1257 PlotKit
.Canvas
.CanvasRenderer
=PlotKit
.CanvasRenderer
;
1258 PlotKit
.Canvas
.EXPORT
=["CanvasRenderer"];
1259 PlotKit
.Canvas
.EXPORT_OK
=["CanvasRenderer"];
1260 PlotKit
.Canvas
.__new__
=function(){
1261 var m
=MochiKit
.Base
;
1262 m
.nameFunctions(this);
1263 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
1265 PlotKit
.Canvas
.__new__();
1266 MochiKit
.Base
._exportSymbols(this,PlotKit
.Canvas
);
1268 if(typeof (PlotKit
.Layout
)=="undefined"){
1273 throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.Layout";
1275 PlotKit
.SVGRenderer
=function(_240
,_241
,_242
){
1276 if(arguments
.length
>0){
1277 this.__init__(_240
,_241
,_242
);
1280 PlotKit
.SVGRenderer
.NAME
="PlotKit.SVGRenderer";
1281 PlotKit
.SVGRenderer
.VERSION
=PlotKit
.VERSION
;
1282 PlotKit
.SVGRenderer
.__repr__
=function(){
1283 return "["+this.NAME
+" "+this.VERSION
+"]";
1285 PlotKit
.SVGRenderer
.toString
=function(){
1286 return this.__repr__();
1288 PlotKit
.SVGRenderer
.SVGNS
="http://www.w3.org/2000/svg";
1289 PlotKit
.SVGRenderer
.prototype.__init__
=function(_243
,_244
,_245
){
1290 var _246
=MochiKit
.Base
.isUndefinedOrNull
;
1291 this.options
={"drawBackground":true,"backgroundColor":Color
.whiteColor(),"padding":{left
:30,right
:30,top
:5,bottom
:10},"colorScheme":PlotKit
.Base
.palette(PlotKit
.Base
.baseColors()[1]),"strokeColor":Color
.whiteColor(),"strokeColorTransform":"asStrokeColor","strokeWidth":0.5,"shouldFill":true,"shouldStroke":true,"drawXAxis":true,"drawYAxis":true,"axisLineColor":Color
.blackColor(),"axisLineWidth":0.5,"axisTickSize":3,"axisLabelColor":Color
.blackColor(),"axisLabelFont":"Arial","axisLabelFontSize":9,"axisLabelWidth":50,"axisLabelUseDiv":true,"pieRadius":0.4,"enableEvents":true};
1292 MochiKit
.Base
.update(this.options
,_245
?_245
:{});
1294 this.element
=MochiKit
.DOM
.getElement(_243
);
1295 this.container
=this.element
.parentNode
;
1296 this.height
=parseInt(this.element
.getAttribute("height"));
1297 this.width
=parseInt(this.element
.getAttribute("width"));
1298 this.document
=document
;
1299 this.root
=this.element
;
1301 this.document
=this.element
.getSVGDocument();
1302 this.root
=_246(this.document
.documentElement
)?this.element
:this.document
.documentElement
;
1306 this.element
.style
.zIndex
=1;
1307 if(_246(this.element
)){
1308 throw "SVGRenderer() - passed SVG object is not found";
1310 if(_246(this.container
)||this.container
.nodeName
.toLowerCase()!="div"){
1311 throw "SVGRenderer() - No DIV's around the SVG.";
1313 this.xlabels
=new Array();
1314 this.ylabels
=new Array();
1315 this.defs
=this.createSVGElement("defs");
1316 this.area
={x
:this.options
.padding
.left
,y
:this.options
.padding
.top
,w
:this.width
-this.options
.padding
.left
-this.options
.padding
.right
,h
:this.height
-this.options
.padding
.top
-this.options
.padding
.bottom
};
1317 MochiKit
.DOM
.updateNodeAttributes(this.container
,{"style":{"position":"relative","width":this.width
+"px"}});
1319 PlotKit
.SVGRenderer
.prototype.render
=function(){
1320 if(this.options
.drawBackground
){
1321 this._renderBackground();
1323 if(this.layout
.style
=="bar"){
1324 this._renderBarChart();
1325 this._renderBarAxis();
1327 if(this.layout
.style
=="pie"){
1328 this._renderPieChart();
1329 this._renderPieAxis();
1331 if(this.layout
.style
=="line"){
1332 this._renderLineChart();
1333 this._renderLineAxis();
1338 PlotKit
.SVGRenderer
.prototype._renderBarOrLine
=function(data
,_247
,_248
,_249
){
1339 var _250
=this.options
.colorScheme
.length
;
1340 var _251
=this.options
.colorScheme
;
1341 var _252
=MochiKit
.Base
.keys(this.layout
.datasets
);
1342 var _253
=_252
.length
;
1343 for(var i
=0;i
<_253
;i
++){
1345 var _255
=new Array();
1346 var _256
=_251
[i
%_250
];
1347 if(this.options
.shouldFill
){
1348 _255
["fill"]=_256
.toRGBString();
1350 _255
["fill"]="none";
1352 if(this.options
.shouldStroke
&&(this.options
.strokeColor
||this.options
.strokeColorTransform
)){
1353 if(this.options
.strokeColor
){
1354 _255
["stroke"]=this.options
.strokeColor
.toRGBString();
1356 if(this.options
.strokeColorTransform
){
1357 _255
["stroke"]=_256
[this.options
.strokeColorTransform
]().toRGBString();
1360 _255
["strokeWidth"]=this.options
.strokeWidth
;
1365 var _257
=function(obj
){
1370 MochiKit
.Iter
.forEach(data
,bind(_257
,this));
1376 PlotKit
.SVGRenderer
.prototype._renderBarChart
=function(){
1377 var bind
=MochiKit
.Base
.bind
;
1378 var _258
=function(_259
,bar
){
1379 var x
=this.area
.w
*bar
.x
+this.area
.x
;
1380 var y
=this.area
.h
*bar
.y
+this.area
.y
;
1381 var w
=this.area
.w
*bar
.w
;
1382 var h
=this.area
.h
*bar
.h
;
1383 this._drawRect(x
,y
,w
,h
,_259
);
1385 this._renderBarOrLine(this.layout
.bars
,bind(_258
,this));
1387 PlotKit
.SVGRenderer
.prototype._renderLineChart
=function(){
1388 var bind
=MochiKit
.Base
.bind
;
1389 var _260
=function(_261
,_262
){
1390 this._tempPointsBuffer
+=(this.area
.w
*_262
.x
+this.area
.x
)+","+(this.area
.h
*_262
.y
+this.area
.y
)+" ";
1392 var _263
=function(_264
){
1393 this._tempPointsBuffer
="";
1394 this._tempPointsBuffer
+=(this.area
.x
)+","+(this.area
.y
+this.area
.h
)+" ";
1396 var _265
=function(_266
){
1397 this._tempPointsBuffer
+=(this.area
.w
+this.area
.x
)+","+(this.area
.h
+this.area
.y
);
1398 _266
["points"]=this._tempPointsBuffer
;
1399 var elem
=this.createSVGElement("polygon",_266
);
1400 this.root
.appendChild(elem
);
1402 this._renderBarOrLine(this.layout
.points
,bind(_260
,this),bind(_263
,this),bind(_265
,this));
1404 PlotKit
.SVGRenderer
.prototype._renderPieChart
=function(){
1405 var _268
=this.options
.colorScheme
.length
;
1406 var _269
=this.layout
.slices
;
1407 var _270
=this.area
.x
+this.area
.w
*0.5;
1408 var _271
=this.area
.y
+this.area
.h
*0.5;
1409 var _272
=Math
.min(this.area
.w
*this.options
.pieRadius
,this.area
.h
*this.options
.pieRadius
);
1410 if(_269
.length
==1&&(Math
.abs(_269
[0].startAngle
)-Math
.abs(_269
[0].endAngle
)<0.1)){
1411 var _273
={"cx":_270
,"cy":_271
,"r":_272
};
1412 var _274
=this.options
.colorScheme
[0];
1413 if(this.options
.shouldFill
){
1414 _273
["fill"]=_274
.toRGBString();
1416 _273
["fill"]="none";
1418 if(this.options
.shouldStroke
&&(this.options
.strokeColor
||this.options
.strokeColorTransform
)){
1419 if(this.options
.strokeColor
){
1420 _273
["stroke"]=this.options
.strokeColor
.toRGBString();
1422 if(this.options
.strokeColorTransform
){
1423 _273
["stroke"]=_274
[this.options
.strokeColorTransform
]().toRGBString();
1426 _273
["style"]="stroke-width: "+this.options
.strokeWidth
;
1428 this.root
.appendChild(this.createSVGElement("circle",_273
));
1431 for(var i
=0;i
<_269
.length
;i
++){
1432 var _273
=new Array();
1433 var _274
=this.options
.colorScheme
[i
%_268
];
1434 if(this.options
.shouldFill
){
1435 _273
["fill"]=_274
.toRGBString();
1437 _273
["fill"]="none";
1439 if(this.options
.shouldStroke
&&(this.options
.strokeColor
||this.options
.strokeColorTransform
)){
1440 if(this.options
.strokeColor
){
1441 _273
["stroke"]=this.options
.strokeColor
.toRGBString();
1443 if(this.options
.strokeColorTransform
){
1444 _273
["stroke"]=_274
[this.options
.strokeColorTransform
]().toRGBString();
1447 _273
["style"]="stroke-width:"+this.options
.strokeWidth
;
1450 if(Math
.abs(_269
[i
].endAngle
-_269
[i
].startAngle
)>Math
.PI
){
1453 var x1
=Math
.cos(_269
[i
].startAngle
-Math
.PI
/2)*_272
;
1454 var y1
=Math
.sin(_269
[i
].startAngle
-Math
.PI
/2)*_272
;
1455 var x2
=Math
.cos(_269
[i
].endAngle
-Math
.PI
/2)*_272
;
1456 var y2
=Math
.sin(_269
[i
].endAngle
-Math
.PI
/2)*_272
;
1459 var _282
="M"+_270
+","+_271
+" ";
1460 _282
+="l"+x1
+","+y1
+" ";
1461 _282
+="a"+_272
+","+_272
+" 0 "+_275
+",1 "+rx
+","+ry
+" z";
1463 var elem
=this.createSVGElement("path",_273
);
1464 this.root
.appendChild(elem
);
1467 PlotKit
.SVGRenderer
.prototype._renderBarAxis
=function(){
1470 PlotKit
.SVGRenderer
.prototype._renderLineAxis
=function(){
1473 PlotKit
.SVGRenderer
.prototype._renderAxis
=function(){
1474 if(!this.options
.drawXAxis
&&!this.options
.drawYAxis
){
1477 var _283
={"style":{"position":"absolute","textAlign":"center","fontSize":this.options
.axisLabelFontSize
+"px","zIndex":10,"color":this.options
.axisLabelColor
.toRGBString(),"width":this.options
.axisLabelWidth
+"px","overflow":"hidden"}};
1478 var _284
={"stroke":this.options
.axisLineColor
.toRGBString(),"strokeWidth":this.options
.axisLineWidth
};
1479 if(this.options
.drawYAxis
){
1480 if(this.layout
.yticks
){
1481 var _285
=function(tick
){
1483 var y
=this.area
.y
+tick
[0]*this.area
.h
;
1484 this._drawLine(x
,y
,x
-3,y
,_284
);
1485 if(this.options
.axisLabelUseDiv
){
1486 var _286
=DIV(_283
,tick
[1]);
1487 _286
.style
.top
=(y
-this.options
.axisLabelFontSize
)+"px";
1488 _286
.style
.left
=(x
-this.options
.padding
.left
+this.options
.axisTickSize
)+"px";
1489 _286
.style
.textAlign
="left";
1490 _286
.style
.width
=(this.options
.padding
.left
-3)+"px";
1491 MochiKit
.DOM
.appendChildNodes(this.container
,_286
);
1492 this.ylabels
.push(_286
);
1494 var _287
={y
:y
+3,x
:(x
-this.options
.padding
.left
+3),width
:(this.options
.padding
.left
-this.options
.axisTickSize
)+"px",height
:(this.options
.axisLabelFontSize
+3)+"px",fontFamily
:"Arial",fontSize
:this.options
.axisLabelFontSize
+"px",fill
:this.options
.axisLabelColor
.toRGBString()};
1495 var _286
=this.createSVGElement("text",_287
);
1496 _286
.appendChild(this.document
.createTextNode(tick
[1]));
1497 this.root
.appendChild(_286
);
1500 MochiKit
.Iter
.forEach(this.layout
.yticks
,bind(_285
,this));
1502 this._drawLine(this.area
.x
,this.area
.y
,this.area
.x
,this.area
.y
+this.area
.h
,_284
);
1504 if(this.options
.drawXAxis
){
1505 if(this.layout
.xticks
){
1506 var _285
=function(tick
){
1507 var x
=this.area
.x
+tick
[0]*this.area
.w
;
1508 var y
=this.area
.y
+this.area
.h
;
1509 this._drawLine(x
,y
,x
,y
+this.options
.axisTickSize
,_284
);
1510 if(this.options
.axisLabelUseDiv
){
1511 var _288
=DIV(_283
,tick
[1]);
1512 _288
.style
.top
=(y
+this.options
.axisTickSize
)+"px";
1513 _288
.style
.left
=(x
-this.options
.axisLabelWidth
/2)+"px";
1514 _288
.style
.textAlign
="center";
1515 _288
.style
.width
=this.options
.axisLabelWidth
+"px";
1516 MochiKit
.DOM
.appendChildNodes(this.container
,_288
);
1517 this.xlabels
.push(_288
);
1519 var _289
={y
:(y
+this.options
.axisTickSize
+this.options
.axisLabelFontSize
),x
:x
-3,width
:this.options
.axisLabelWidth
+"px",height
:(this.options
.axisLabelFontSize
+3)+"px",fontFamily
:"Arial",fontSize
:this.options
.axisLabelFontSize
+"px",fill
:this.options
.axisLabelColor
.toRGBString(),textAnchor
:"middle"};
1520 var _288
=this.createSVGElement("text",_289
);
1521 _288
.appendChild(this.document
.createTextNode(tick
[1]));
1522 this.root
.appendChild(_288
);
1525 MochiKit
.Iter
.forEach(this.layout
.xticks
,bind(_285
,this));
1527 this._drawLine(this.area
.x
,this.area
.y
+this.area
.h
,this.area
.x
+this.area
.w
,this.area
.y
+this.area
.h
,_284
);
1530 PlotKit
.SVGRenderer
.prototype._renderPieAxis
=function(){
1531 if(this.layout
.xticks
){
1532 var _290
=new Array();
1533 for(var i
=0;i
<this.layout
.slices
.length
;i
++){
1534 _290
[this.layout
.slices
[i
].xval
]=this.layout
.slices
[i
];
1536 var _291
=this.area
.x
+this.area
.w
*0.5;
1537 var _292
=this.area
.y
+this.area
.h
*0.5;
1538 var _293
=Math
.min(this.area
.w
*this.options
.pieRadius
+10,this.area
.h
*this.options
.pieRadius
+10);
1539 var _294
=this.options
.axisLabelWidth
;
1540 for(var i
=0;i
<this.layout
.xticks
.length
;i
++){
1541 var _295
=_290
[this.layout
.xticks
[i
][0]];
1542 if(MochiKit
.Base
.isUndefinedOrNull(_295
)){
1545 var _296
=(_295
.startAngle
+_295
.endAngle
)/2;
1548 _297
=_297
-Math
.PI
*2;
1551 _297
=_297
+Math
.PI
*2;
1554 var _298
=_291
+Math
.sin(_297
)*(_293
+10);
1555 var _299
=_292
-Math
.cos(_297
)*(_293
+10);
1556 var _300
={"position":"absolute","zIndex":11,"width":_294
+"px","fontSize":this.options
.axisLabelFontSize
+"px","overflow":"hidden","color":this.options
.axisLabelColor
.toHexString()};
1557 var _301
={"width":_294
+"px","fontSize":this.options
.axisLabelFontSize
+"px","height":(this.options
.axisLabelFontSize
+3)+"px","fill":this.options
.axisLabelColor
.toRGBString()};
1558 if(_297
<=Math
.PI
*0.5){
1559 MochiKit
.Base
.update(_300
,{"textAlign":"left","verticalAlign":"top","left":_298
+"px","top":(_299
-this.options
.axisLabelFontSize
)+"px"});
1560 MochiKit
.Base
.update(_301
,{"x":_298
,"y":(_299
-this.options
.axisLabelFontSize
),"textAnchor":"left"});
1562 if((_297
>Math
.PI
*0.5)&&(_297
<=Math
.PI
)){
1563 MochiKit
.Base
.update(_300
,{"textAlign":"left","verticalAlign":"bottom","left":_298
+"px","top":_299
+"px"});
1564 MochiKit
.Base
.update(_301
,{"textAnchor":"left","x":_298
,"y":_299
});
1566 if((_297
>Math
.PI
)&&(_297
<=Math
.PI
*1.5)){
1567 MochiKit
.Base
.update(_300
,{"textAlign":"right","verticalAlign":"bottom","left":_298
+"px","top":_299
+"px"});
1568 MochiKit
.Base
.update(_301
,{"textAnchor":"right","x":_298
-_294
,"y":_299
});
1570 MochiKit
.Base
.update(_300
,{"textAlign":"left","verticalAlign":"bottom","left":_298
+"px","top":_299
+"px"});
1571 MochiKit
.Base
.update(_301
,{"textAnchor":"left","x":_298
-_294
,"y":_299
-this.options
.axisLabelFontSize
});
1575 if(this.options
.axisLabelUseDiv
){
1576 var _302
=DIV({"style":_300
},this.layout
.xticks
[i
][1]);
1577 this.xlabels
.push(_302
);
1578 MochiKit
.DOM
.appendChildNodes(this.container
,_302
);
1580 var _302
=this.createSVGElement("text",_301
);
1581 _302
.appendChild(this.document
.createTextNode(this.layout
.xticks
[i
][1]));
1582 this.root
.appendChild(_302
);
1587 PlotKit
.SVGRenderer
.prototype._renderBackground
=function(){
1588 var opts
={"stroke":"none","fill":this.options
.backgroundColor
.toRGBString()};
1589 this._drawRect(0,0,this.width
,this.height
,opts
);
1591 PlotKit
.SVGRenderer
.prototype._drawRect
=function(x
,y
,w
,h
,_304
){
1592 var _305
={x
:x
+"px",y
:y
+"px",width
:w
+"px",height
:h
+"px"};
1594 MochiKit
.Base
.update(_305
,_304
);
1596 var elem
=this.createSVGElement("rect",_305
);
1597 this.root
.appendChild(elem
);
1599 PlotKit
.SVGRenderer
.prototype._drawLine
=function(x1
,y1
,x2
,y2
,_306
){
1600 var _307
={x1
:x1
+"px",y1
:y1
+"px",x2
:x2
+"px",y2
:y2
+"px"};
1602 MochiKit
.Base
.update(_307
,_306
);
1604 var elem
=this.createSVGElement("line",_307
);
1605 this.root
.appendChild(elem
);
1607 PlotKit
.SVGRenderer
.prototype.clear
=function(){
1608 while(this.element
.firstChild
){
1609 this.element
.removeChild(this.element
.firstChild
);
1611 if(this.options
.axisLabelUseDiv
){
1612 for(var i
=0;i
<this.xlabels
.length
;i
++){
1613 MochiKit
.DOM
.removeElement(this.xlabels
[i
]);
1615 for(var i
=0;i
<this.ylabels
.length
;i
++){
1616 MochiKit
.DOM
.removeElement(this.ylabels
[i
]);
1619 this.xlabels
=new Array();
1620 this.ylabels
=new Array();
1622 PlotKit
.SVGRenderer
.prototype.createSVGElement
=function(name
,_309
){
1623 var _310
=MochiKit
.Base
.isUndefinedOrNull
;
1625 var doc
=_310(this.document
)?document
:this.document
;
1627 elem
=doc
.createElementNS(PlotKit
.SVGRenderer
.SVGNS
,name
);
1630 elem
=doc
.createElement(name
);
1631 elem
.setAttribute("xmlns",PlotKit
.SVGRenderer
.SVGNS
);
1634 MochiKit
.DOM
.updateNodeAttributes(elem
,_309
);
1638 PlotKit
.SVGRenderer
.SVG
=function(_312
){
1639 var ie
=navigator
.appVersion
.match(/MSIE (\d\.\d)/);
1640 var _313
=(navigator
.userAgent
.toLowerCase().indexOf("opera")!=-1);
1641 if(ie
&&(ie
[1]>=6)&&(!_313
)){
1642 var _314
=_312
["width"]?_312
["width"]:"100";
1643 var _315
=_312
["height"]?_312
["height"]:"100";
1644 var eid
=_312
["id"]?_312
["id"]:"notunique";
1645 var html
="<svg:svg width=\""+_314
+"\" height=\""+_315
+"\" ";
1646 html
+="id=\""+eid
+"\" version=\"1.1\" baseProfile=\"full\" />";
1647 var _318
=document
.createElement(html
);
1648 var _319
=_318
.getSVGDocument().createElementNS(PlotKit
.SVGRenderer
.SVGNS
,"svg");
1649 _319
.setAttribute("width",_314
);
1650 _319
.setAttribute("height",_315
);
1651 _318
.getSVGDocument().appendChild(_319
);
1654 return PlotKit
.SVGRenderer
.prototype.createSVGElement("svg",_312
);
1657 PlotKit
.SVGRenderer
.isSupported
=function(){
1658 var _320
=(navigator
.userAgent
.toLowerCase().indexOf("opera")!=-1);
1659 var _321
=navigator
.appVersion
.match(/MSIE (\d\.\d)/);
1660 var _322
=navigator
.userAgent
.match(/AppleWebKit\/(\d
+)/);
1661 var _323
=navigator
.userAgent
.match(/Opera\/(\d
*\.\d
*)/);
1662 var _324
=navigator
.userAgent
.match(/rv:(\d*\.\d*).*Gecko/);
1663 var _325
="http://www.w3.org/TR/SVG11/feature#SVG";
1664 if(_321
&&(_321
[1]>=6)&&!_320
){
1665 return document
.implementation
.hasFeature(_325
,"1.1");
1667 if(_323
&&(_323
[1]>8.9)){
1670 if(_324
&&(_324
>1.7)){
1676 PlotKit
.SVG
.SVGRenderer
=PlotKit
.SVGRenderer
;
1677 PlotKit
.SVG
.EXPORT
=["SVGRenderer"];
1678 PlotKit
.SVG
.EXPORT_OK
=["SVGRenderer"];
1679 PlotKit
.SVG
.__new__
=function(){
1680 var m
=MochiKit
.Base
;
1681 m
.nameFunctions(this);
1682 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
1684 PlotKit
.SVG
.__new__();
1685 MochiKit
.Base
._exportSymbols(this,PlotKit
.SVG
);
1687 if(typeof (PlotKit
.CanvasRenderer
)=="undefined"){
1692 throw "SweetCanvas depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Layout, Canvas}";
1694 if(typeof (PlotKit
.SweetCanvasRenderer
)=="undefined"){
1695 PlotKit
.SweetCanvasRenderer
={};
1697 PlotKit
.SweetCanvasRenderer
=function(_326
,_327
,_328
){
1698 if(arguments
.length
>0){
1699 this.__init__(_326
,_327
,_328
);
1702 PlotKit
.SweetCanvasRenderer
.NAME
="PlotKit.SweetCanvasRenderer";
1703 PlotKit
.SweetCanvasRenderer
.VERSION
=PlotKit
.VERSION
;
1704 PlotKit
.SweetCanvasRenderer
.__repr__
=function(){
1705 return "["+this.NAME
+" "+this.VERSION
+"]";
1707 PlotKit
.SweetCanvasRenderer
.toString
=function(){
1708 return this.__repr__();
1710 PlotKit
.SweetCanvasRenderer
.prototype=new PlotKit
.CanvasRenderer();
1711 PlotKit
.SweetCanvasRenderer
.prototype.constructor
=PlotKit
.SweetCanvasRenderer
;
1712 PlotKit
.SweetCanvasRenderer
.__super__
=PlotKit
.CanvasRenderer
.prototype;
1713 PlotKit
.SweetCanvasRenderer
.prototype.__init__
=function(el
,_330
,opts
){
1714 var _331
=PlotKit
.Base
.officeBlue();
1715 MochiKit
.Base
.update(_331
,opts
);
1716 PlotKit
.SweetCanvasRenderer
.__super__
.__init__
.call(this,el
,_330
,_331
);
1718 PlotKit
.SweetCanvasRenderer
.prototype._renderBarChart
=function(){
1719 var bind
=MochiKit
.Base
.bind
;
1720 var _332
=Color
.blackColor().colorWithAlpha(0.1).toRGBString();
1721 var _333
=function(_334
,x
,y
,w
,h
){
1722 _334
.fillStyle
=_332
;
1723 _334
.fillRect(x
-2,y
-2,w
+4,h
+2);
1724 _334
.fillStyle
=_332
;
1725 _334
.fillRect(x
-1,y
-1,w
+2,h
+1);
1727 var _335
=this.options
.colorScheme
.length
;
1728 var _336
=this.options
.colorScheme
;
1729 var _337
=PlotKit
.Base
.keys(this.layout
.datasets
);
1730 var _338
=_337
.length
;
1731 var _339
=function(name
){
1732 for(var i
=0;i
<_338
;i
++){
1734 return _336
[i
%_335
];
1739 var _340
=function(_341
,bar
){
1740 var x
=this.area
.w
*bar
.x
+this.area
.x
;
1741 var y
=this.area
.h
*bar
.y
+this.area
.y
;
1742 var w
=this.area
.w
*bar
.w
;
1743 var h
=this.area
.h
*bar
.h
;
1749 _341
.shadowColor
=Color
.fromHexString("#888888").toRGBString();
1752 _341
.fillStyle
="#cccccc";
1753 _341
.fillRect(x
-2,y
-2,w
+4,h
+2);
1758 if(this.options
.shouldFill
){
1759 _341
.fillStyle
=_339(bar
.name
).toRGBString();
1760 _341
.fillRect(x
,y
,w
,h
);
1763 _341
.strokeStyle
=Color
.whiteColor().toRGBString();
1765 if(this.options
.shouldStroke
){
1766 _341
.strokeRect(x
,y
,w
,h
);
1770 this._renderBarChartWrap(this.layout
.bars
,bind(_340
,this));
1772 PlotKit
.SweetCanvasRenderer
.prototype._renderLineChart
=function(){
1773 var _342
=this.element
.getContext("2d");
1774 var _343
=this.options
.colorScheme
.length
;
1775 var _344
=this.options
.colorScheme
;
1776 var _345
=PlotKit
.Base
.keys(this.layout
.datasets
);
1777 var _346
=_345
.length
;
1778 var bind
=MochiKit
.Base
.bind
;
1779 for(var i
=0;i
<_346
;i
++){
1781 var _348
=_344
[i
%_343
];
1782 var _349
=this.options
.strokeColorTransform
;
1784 var _350
=function(ctx
){
1786 ctx
.moveTo(this.area
.x
,this.area
.y
+this.area
.h
);
1787 var _351
=function(ctx_
,_352
){
1788 if(_352
.name
==_347
){
1789 ctx_
.lineTo(this.area
.w
*_352
.x
+this.area
.x
,this.area
.h
*_352
.y
+this.area
.y
);
1792 MochiKit
.Iter
.forEach(this.layout
.points
,partial(_351
,ctx
),this);
1793 ctx
.lineTo(this.area
.w
+this.area
.x
,this.area
.h
+this.area
.y
);
1794 ctx
.lineTo(this.area
.x
,this.area
.y
+this.area
.h
);
1797 if(this.options
.shouldFill
){
1800 _342
.fillStyle
="#cccccc";
1802 _342
.fillStyle
=Color
.blackColor().colorWithAlpha(0.2).toRGBString();
1804 _342
.translate(-1,-2);
1805 bind(_350
,this)(_342
);
1806 if(this.options
.shouldFill
){
1812 _342
.shadowColor
=Color
.fromHexString("#888888").toRGBString();
1813 _342
.fillStyle
=_348
.toRGBString();
1815 _342
.strokeStyle
=Color
.whiteColor().toRGBString();
1816 if(this.options
.shouldFill
){
1817 bind(_350
,this)(_342
);
1820 if(this.options
.shouldStroke
){
1821 bind(_350
,this)(_342
);
1827 PlotKit
.SweetCanvasRenderer
.prototype._renderPieChart
=function(){
1828 var _353
=this.element
.getContext("2d");
1829 var _354
=this.options
.colorScheme
.length
;
1830 var _355
=this.layout
.slices
;
1831 var _356
=this.area
.x
+this.area
.w
*0.5;
1832 var _357
=this.area
.y
+this.area
.h
*0.5;
1833 var _358
=Math
.min(this.area
.w
*this.options
.pieRadius
,this.area
.h
*this.options
.pieRadius
);
1835 _356
=parseInt(_356
);
1836 _357
=parseInt(_357
);
1837 _358
=parseInt(_358
);
1841 var _359
=Color
.blackColor().colorWithAlpha(0.2);
1842 _353
.fillStyle
=_359
.toRGBString();
1844 _353
.shadowColor
=Color
.fromHexString("#888888").toRGBString();
1845 _353
.translate(1,1);
1847 _353
.moveTo(_356
,_357
);
1848 _353
.arc(_356
,_357
,_358
+2,0,Math
.PI
*2,false);
1854 _353
.strokeStyle
=Color
.whiteColor().toRGBString();
1856 for(var i
=0;i
<_355
.length
;i
++){
1857 var _360
=this.options
.colorScheme
[i
%_354
];
1858 _353
.fillStyle
=_360
.toRGBString();
1859 var _361
=function(){
1861 _353
.moveTo(_356
,_357
);
1862 _353
.arc(_356
,_357
,_358
,_355
[i
].startAngle
-Math
.PI
/2,_355[i].endAngle-Math.PI/2,false);
1863 _353
.lineTo(_356
,_357
);
1866 if(Math
.abs(_355
[i
].startAngle
-_355
[i
].endAngle
)>0.0001){
1867 if(this.options
.shouldFill
){
1871 if(this.options
.shouldStroke
){
1879 PlotKit
.SweetCanvasRenderer
.prototype._renderBackground
=function(){
1880 var _362
=this.element
.getContext("2d");
1881 if(this.layout
.style
=="bar"||this.layout
.style
=="line"){
1883 _362
.fillStyle
=this.options
.backgroundColor
.toRGBString();
1884 _362
.fillRect(this.area
.x
,this.area
.y
,this.area
.w
,this.area
.h
);
1885 _362
.strokeStyle
=this.options
.axisLineColor
.toRGBString();
1887 var _363
=this.layout
.yticks
;
1889 if(this.layout
.style
=="bar"&&this.layout
.options
.barOrientation
=="horizontal"){
1890 _363
=this.layout
.xticks
;
1893 for(var i
=0;i
<_363
.length
;i
++){
1899 x1
=_363
[i
][0]*this.area
.w
+this.area
.x
;
1905 y1
=_363
[i
][0]*this.area
.h
+this.area
.y
;
1917 PlotKit
.SweetCanvasRenderer
.__super__
._renderBackground
.call(this);
1920 PlotKit
.SweetCanvas
={};
1921 PlotKit
.SweetCanvas
.SweetCanvasRenderer
=PlotKit
.SweetCanvasRenderer
;
1922 PlotKit
.SweetCanvas
.EXPORT
=["SweetCanvasRenderer"];
1923 PlotKit
.SweetCanvas
.EXPORT_OK
=["SweetCanvasRenderer"];
1924 PlotKit
.SweetCanvas
.__new__
=function(){
1925 var m
=MochiKit
.Base
;
1926 m
.nameFunctions(this);
1927 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
1929 PlotKit
.SweetCanvas
.__new__();
1930 MochiKit
.Base
._exportSymbols(this,PlotKit
.SweetCanvas
);
1932 if(typeof (PlotKit
.SVGRenderer
)=="undefined"){
1937 throw "SweetSVG depends on MochiKit.{Base,Color,DOM,Format} and PlotKit.{Layout, SVG}";
1939 if(typeof (PlotKit
.SweetSVGRenderer
)=="undefined"){
1940 PlotKit
.SweetSVGRenderer
={};
1942 PlotKit
.SweetSVGRenderer
=function(_365
,_366
,_367
){
1943 if(arguments
.length
>0){
1944 this.__init__(_365
,_366
,_367
);
1947 PlotKit
.SweetSVGRenderer
.NAME
="PlotKit.SweetSVGRenderer";
1948 PlotKit
.SweetSVGRenderer
.VERSION
=PlotKit
.VERSION
;
1949 PlotKit
.SweetSVGRenderer
.__repr__
=function(){
1950 return "["+this.NAME
+" "+this.VERSION
+"]";
1952 PlotKit
.SweetSVGRenderer
.toString
=function(){
1953 return this.__repr__();
1955 PlotKit
.SweetSVGRenderer
.prototype=new PlotKit
.SVGRenderer();
1956 PlotKit
.SweetSVGRenderer
.prototype.constructor
=PlotKit
.SweetSVGRenderer
;
1957 PlotKit
.SweetSVGRenderer
.__super__
=PlotKit
.SVGRenderer
.prototype;
1958 PlotKit
.SweetSVGRenderer
.prototype.__init__
=function(_368
,_369
,_370
){
1959 var _371
=PlotKit
.Base
.officeBlue();
1960 MochiKit
.Base
.update(_371
,_370
);
1961 PlotKit
.SweetSVGRenderer
.__super__
.__init__
.call(this,_368
,_369
,_371
);
1963 PlotKit
.SweetSVGRenderer
.prototype._addDropShadowFilter
=function(){
1964 var _372
=this.createSVGElement("filter",{x
:0,y
:0,"id":"dropShadow"});
1965 var _373
=this.createSVGElement("feOffset",{"in":"SourceGraphic","dx":0,"dy":0,"result":"topCopy"});
1966 var blur
=this.createSVGElement("feGaussianBlur",{"in":"SourceAlpha","StdDeviation":2,"result":"shadow"});
1967 var _375
=this.createSVGElement("feOffset",{"in":"shadow","dx":-1,"dy":-2,"result":"movedShadow"});
1968 var _376
=this.createSVGElement("feMerge");
1969 var _377
=this.createSVGElement("feMergeNode",{"in":"topCopy"});
1970 var _378
=this.createSVGElement("feMergeNode",{"in":"movedShadow"});
1971 _376
.appendChild(_377
);
1972 _376
.appendChild(_378
);
1973 _372
.appendChild(_373
);
1974 _372
.appendChild(blur
);
1975 _372
.appendChild(_375
);
1976 _372
.appendChild(_376
);
1977 this.defs
.appendChild(_372
);
1979 PlotKit
.SweetSVGRenderer
.prototype._renderBarChart
=function(){
1980 var bind
=MochiKit
.Base
.bind
;
1981 var _379
=Color
.blackColor().toRGBString();
1982 var _380
="fill:"+_379
+";fill-opacity:0.15";
1983 var _381
="stroke-width: 2.0; stroke:"+Color
.whiteColor().toRGBString();
1984 var _382
=function(_383
,bar
){
1985 var x
=this.area
.w
*bar
.x
+this.area
.x
;
1986 var y
=this.area
.h
*bar
.y
+this.area
.y
;
1987 var w
=this.area
.w
*bar
.w
;
1988 var h
=this.area
.h
*bar
.h
;
1993 this._drawRect(x
-2,y
-1,w
+4,h
+2,{"style":_380
});
1994 this._drawRect(x
,y
,w
,h
,_383
);
1996 this._renderBarOrLine(this.layout
.bars
,bind(_382
,this));
1998 PlotKit
.SweetSVGRenderer
.prototype._renderLineChart
=function(){
1999 var bind
=MochiKit
.Base
.bind
;
2000 var _384
=Color
.blackColor().toRGBString();
2001 var _385
="fill:"+_384
+";fill-opacity:0.15";
2002 var _386
="stroke-width: 2.0; stroke:"+Color
.whiteColor().toRGBString();
2003 var _387
=function(_388
,_389
){
2004 this._tempPointsBuffer
+=(this.area
.w
*_389
.x
+this.area
.x
)+","+(this.area
.h
*_389
.y
+this.area
.y
)+" ";
2006 var _390
=function(_391
){
2007 this._tempPointsBuffer
="";
2008 this._tempPointsBuffer
+=(this.area
.x
)+","+(this.area
.y
+this.area
.h
)+" ";
2010 var _392
=function(_393
){
2011 this._tempPointsBuffer
+=(this.area
.w
+this.area
.x
)+","+(this.area
.h
+this.area
.y
);
2012 _393
["points"]=this._tempPointsBuffer
;
2013 _393
["stroke"]="none";
2014 _393
["transform"]="translate(-2, -1)";
2016 var _394
=this.createSVGElement("polygon",_393
);
2017 this.root
.appendChild(_394
);
2018 _393
["transform"]="";
2020 var elem
=this.createSVGElement("polygon",_393
);
2021 this.root
.appendChild(elem
);
2023 this._renderBarOrLine(this.layout
.points
,bind(_387
,this),bind(_390
,this),bind(_392
,this));
2025 PlotKit
.SweetSVGRenderer
.prototype._renderPieChart
=function(){
2026 var _395
=this.area
.x
+this.area
.w
*0.5;
2027 var _396
=this.area
.y
+this.area
.h
*0.5;
2028 var _397
=Color
.blackColor().toRGBString();
2029 var _398
=Math
.min(this.area
.w
*this.options
.pieRadius
,this.area
.h
*this.options
.pieRadius
);
2030 var _399
="fill:"+_397
+";fill-opacity:0.15";
2031 var _400
=this.createSVGElement("circle",{"style":_399
,"cx":_395
+1,"cy":_396
+1,"r":_398
+1});
2032 this.root
.appendChild(_400
);
2033 PlotKit
.SweetSVGRenderer
.__super__
._renderPieChart
.call(this);
2035 PlotKit
.SweetSVGRenderer
.prototype._renderBackground
=function(){
2036 var _401
={"fill":this.options
.backgroundColor
.toRGBString(),"stroke":"none"};
2037 if(this.layout
.style
=="bar"||this.layout
.style
=="line"){
2038 this._drawRect(this.area
.x
,this.area
.y
,this.area
.w
,this.area
.h
,_401
);
2039 var _402
=this.layout
.yticks
;
2041 if(this.layout
.style
=="bar"&&this.layout
.options
.barOrientation
=="horizontal"){
2042 _402
=this.layout
.xticks
;
2045 for(var i
=0;i
<_402
.length
;i
++){
2051 x
=_402
[i
][0]*this.area
.w
+this.area
.x
;
2057 y
=_402
[i
][0]*this.area
.h
+this.area
.y
;
2061 this._drawRect(x
,y
,w
,h
,{"fill":this.options
.axisLineColor
.toRGBString()});
2064 PlotKit
.SweetSVGRenderer
.__super__
._renderBackground
.call(this);
2067 PlotKit
.SweetSVG
={};
2068 PlotKit
.SweetSVG
.SweetSVGRenderer
=PlotKit
.SweetSVGRenderer
;
2069 PlotKit
.SweetSVG
.EXPORT
=["SweetSVGRenderer"];
2070 PlotKit
.SweetSVG
.EXPORT_OK
=["SweetSVGRenderer"];
2071 PlotKit
.SweetSVG
.__new__
=function(){
2072 var m
=MochiKit
.Base
;
2073 m
.nameFunctions(this);
2074 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
2076 PlotKit
.SweetSVG
.__new__();
2077 MochiKit
.Base
._exportSymbols(this,PlotKit
.SweetSVG
);
2079 if(typeof (PlotKit
.CanvasRenderer
)=="undefined"){
2084 throw "PlotKit.EasyPlot depends on all of PlotKit's components";
2086 if(typeof (PlotKit
.EasyPlot
)=="undefined"){
2087 PlotKit
.EasyPlot
={};
2089 PlotKit
.EasyPlot
.NAME
="PlotKit.EasyPlot";
2090 PlotKit
.EasyPlot
.VERSION
=PlotKit
.VERSION
;
2091 PlotKit
.EasyPlot
.__repr__
=function(){
2092 return "["+this.NAME
+" "+this.VERSION
+"]";
2094 PlotKit
.EasyPlot
.toString
=function(){
2095 return this.__repr__();
2097 PlotKit
.EasyPlot
=function(_404
,_405
,_406
,_407
){
2098 this.layout
=new Layout(_404
,_405
);
2100 this.width
=parseInt(_406
.getAttribute("width"));
2101 this.height
=parseInt(_406
.getAttribute("height"));
2102 this.deferredCount
=0;
2104 this.width
=this.divElem
.width
?this.divElem
.width
:300;
2107 this.height
=this.divElem
.height
?this.divElem
.height
:300;
2109 if(isArrayLike(_407
)){
2110 for(var i
=0;i
<_407
.length
;i
++){
2111 if(typeof (_407
[i
])=="string"){
2112 this.deferredCount
++;
2113 var d
=MochiKit
.Async
.doSimpleXMLHttpRequest(_407
[i
]);
2114 d
.addCallback(MochiKit
.Base
.bind(PlotKit
.EasyPlot
.onDataLoaded
,this));
2116 if(isArrayLike(_407
[i
])){
2117 this.layout
.addDataset("data-"+i
,_407
[i
]);
2122 if(!isUndefinedOrNull(_407
)){
2123 throw "Passed datasources are not Array like";
2126 if(CanvasRenderer
.isSupported()){
2127 this.element
=CANVAS({"id":this.divElem
.getAttribute("id")+"-canvas","width":this.width
,"height":this.height
},"");
2128 this.divElem
.appendChild(this.element
);
2129 this.renderer
=new SweetCanvasRenderer(this.element
,this.layout
,_405
);
2131 if(SVGRenderer
.isSupported()){
2132 this.element
=SVGRenderer
.SVG({"id":this.divElem
.getAttribute("id")+"-svg","width":this.width
,"height":this.height
,"version":"1.1","baseProfile":"full"},"");
2133 this.divElem
.appendChild(this.element
);
2134 this.renderer
=new SweetSVGRenderer(this.element
,this.layout
,_405
);
2137 if((this.deferredCount
==0)&&(PlotKit
.Base
.keys(this.layout
.datasets
).length
>0)){
2138 this.layout
.evaluate();
2139 this.renderer
.clear();
2140 this.renderer
.render();
2143 PlotKit
.EasyPlot
.onDataLoaded
=function(_409
){
2144 var _410
=new Array();
2145 var _411
=_409
.responseText
.split("\n");
2146 for(var i
=0;i
<_411
.length
;i
++){
2147 var _412
=MochiKit
.Format
.strip(_411
[i
]);
2148 if((_412
.length
>1)&&(_412
.charAt(0)!="#")){
2149 _410
.push(_412
.split(","));
2152 this.layout
.addDataset("data-ajax-"+this.deferredCount
,_410
);
2153 this.deferredCount
--;
2154 if((this.deferredCount
==0)&&(PlotKit
.Base
.keys(this.layout
.datasets
).length
>0)){
2155 this.layout
.evaluate();
2156 this.renderer
.clear();
2157 this.renderer
.render();
2160 PlotKit
.EasyPlot
.prototype.reload
=function(){
2161 this.layout
.evaluate();
2162 this.renderer
.clear();
2163 this.renderer
.render();
2165 PlotKit
.EasyPlotModule
={};
2166 PlotKit
.EasyPlotModule
.EasyPlot
=PlotKit
.EasyPlot
;
2167 PlotKit
.EasyPlotModule
.EXPORT
=["EasyPlot"];
2168 PlotKit
.EasyPlotModule
.EXPORT_OK
=[];
2169 PlotKit
.EasyPlotModule
.__new__
=function(){
2170 var m
=MochiKit
.Base
;
2171 m
.nameFunctions(this);
2172 this.EXPORT_TAGS
={":common":this.EXPORT
,":all":m
.concat(this.EXPORT
,this.EXPORT_OK
)};
2174 PlotKit
.EasyPlotModule
.__new__();
2175 MochiKit
.Base
._exportSymbols(this,PlotKit
.EasyPlotModule
);