]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/charting/plot2d/Default.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojox / charting / plot2d / Default.js
1 if(!dojo._hasResource["dojox.charting.plot2d.Default"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.charting.plot2d.Default"] = true;
3 dojo.provide("dojox.charting.plot2d.Default");
4
5 dojo.require("dojox.charting.plot2d.common");
6 dojo.require("dojox.charting.plot2d.Base");
7
8 dojo.require("dojox.lang.utils");
9 dojo.require("dojox.lang.functional");
10 dojo.require("dojox.lang.functional.reversed");
11
12 (function(){
13         var df = dojox.lang.functional, du = dojox.lang.utils,
14                 dc = dojox.charting.plot2d.common,
15                 purgeGroup = df.lambda("item.purgeGroup()");
16
17         dojo.declare("dojox.charting.plot2d.Default", dojox.charting.plot2d.Base, {
18                 defaultParams: {
19                         hAxis: "x",             // use a horizontal axis named "x"
20                         vAxis: "y",             // use a vertical axis named "y"
21                         lines:   true,  // draw lines
22                         areas:   false, // draw areas
23                         markers: false, // draw markers
24                         shadows: 0,             // draw shadows
25                         tension: 0              // draw curved lines (tension>0)
26                 },
27                 optionalParams: {},     // no optional parameters
28                 
29                 constructor: function(chart, kwArgs){
30                         this.opt = dojo.clone(this.defaultParams);
31                         du.updateWithObject(this.opt, kwArgs);
32                         this.series = [];
33                         this.hAxis = this.opt.hAxis;
34                         this.vAxis = this.opt.vAxis;
35                 },
36                 
37                 calculateAxes: function(dim){
38                         this._calc(dim, dc.collectSimpleStats(this.series));
39                         return this;
40                 },
41                 render: function(dim, offsets){
42                         if(this.dirty){
43                                 dojo.forEach(this.series, purgeGroup);
44                                 this.cleanGroup();
45                                 var s = this.group;
46                                 df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
47                         }
48                         var t = this.chart.theme, stroke, outline, color, marker;
49                         for(var i = this.series.length - 1; i >= 0; --i){
50                                 var run = this.series[i];
51                                 if(!this.dirty && !run.dirty){ continue; }
52                                 run.cleanGroup();
53                                 if(!run.data.length){
54                                         run.dirty = false;
55                                         continue;
56                                 }
57
58                                 //      inner function for translating polylines to curves with tension
59                                 function curve(arr, tension){
60                                         var p=dojo.map(arr, function(item, i){
61                                                 if(i==0){ return "M" + item.x + "," + item.y; }
62                                                 var dx=item.x-arr[i-1].x, dy=arr[i-1].y;
63                                                 return "C"+(item.x-(tension-1)*(dx/tension))+","+dy+" "+(item.x-(dx/tension))+","+item.y+" "+item.x+","+item.y;
64                                         });
65                                         return p.join(" ");
66                                 }
67                                 
68                                 var s = run.group, lpoly;
69                                 if(typeof run.data[0] == "number"){
70                                         lpoly = dojo.map(run.data, function(v, i){
71                                                 return {
72                                                         x: this._hScaler.scale * (i + 1 - this._hScaler.bounds.lower) + offsets.l,
73                                                         y: dim.height - offsets.b - this._vScaler.scale * (v - this._vScaler.bounds.lower)
74                                                 };
75                                         }, this);
76                                 }else{
77                                         lpoly = dojo.map(run.data, function(v, i){
78                                                 return {
79                                                         x: this._hScaler.scale * (v.x - this._hScaler.bounds.lower) + offsets.l,
80                                                         y: dim.height - offsets.b - this._vScaler.scale * (v.y - this._vScaler.bounds.lower)
81                                                 };
82                                         }, this);
83                                 }
84                                 if(!run.fill || !run.stroke){
85                                         // need autogenerated color
86                                         color = run.dyn.color = new dojo.Color(t.next("color"));
87                                 }
88
89                                 var lpath="";
90                                 if(this.opt.tension){
91                                         var lpath=curve(lpoly, this.opt.tension);
92                                 }
93
94                                 if(this.opt.areas){
95                                         var fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
96                                         var apoly = dojo.clone(lpoly);
97                                         if(this.opt.tension){
98                                                 var apath="L" + (apoly[apoly.length-1].x) + "," + (dim.height-offsets.b) + " "
99                                                         + "L"+apoly[0].x+","+(dim.height-offsets.b)+" "
100                                                         + "L"+apoly[0].x+","+apoly[0].y;
101                                                 run.dyn.fill = s.createPath(lpath+" "+apath).setFill(fill).getFill();
102                                         } else {
103                                                 apoly.push({x: lpoly[lpoly.length - 1].x, y: dim.height - offsets.b});
104                                                 apoly.push({x: lpoly[0].x, y: dim.height - offsets.b});
105                                                 apoly.push(lpoly[0]);
106                                                 run.dyn.fill = s.createPolyline(apoly).setFill(fill).getFill();
107                                         }
108                                 }
109                                 if(this.opt.lines || this.opt.markers){
110                                         // need a stroke
111                                         stroke = run.stroke ? dc.makeStroke(run.stroke) : dc.augmentStroke(t.series.stroke, color);
112                                         if(run.outline || t.series.outline){
113                                                 outline = dc.makeStroke(run.outline ? run.outline : t.series.outline);
114                                                 outline.width = 2 * outline.width + stroke.width;
115                                         }
116                                 }
117                                 if(this.opt.markers){
118                                         // need a marker
119                                         marker = run.dyn.marker = run.marker ? run.marker : t.next("marker");
120                                 }
121                                 if(this.opt.shadows && stroke){
122                                         var sh = this.opt.shadows, shadowColor = new dojo.Color([0, 0, 0, 0.3]),
123                                                 spoly = dojo.map(lpoly, function(c){
124                                                         return {x: c.x + sh.dx, y: c.y + sh.dy};
125                                                 }),
126                                                 shadowStroke = dojo.clone(outline ? outline : stroke);
127                                         shadowStroke.color = shadowColor;
128                                         shadowStroke.width += sh.dw ? sh.dw : 0;
129                                         if(this.opt.lines){
130                                                 if(this.opt.tension){
131                                                         s.createPath(curve(spoly, this.opt.tension)).setStroke(shadowStroke);
132                                                 } else {
133                                                         s.createPolyline(spoly).setStroke(shadowStroke);
134                                                 }
135                                         }
136                                         if(this.opt.markers){
137                                                 dojo.forEach(spoly, function(c){
138                                                         s.createPath("M" + c.x + " " + c.y + " " + marker).setStroke(shadowStroke).setFill(shadowColor);
139                                                 }, this);
140                                         }
141                                 }
142                                 if(this.opt.lines){
143                                         if(outline){
144                                                 if(this.opt.tension){
145                                                         run.dyn.outline = s.createPath(lpath).setStroke(outline).getStroke();
146                                                 } else {
147                                                         run.dyn.outline = s.createPolyline(lpoly).setStroke(outline).getStroke();
148                                                 }
149                                         }
150                                         if(this.opt.tension){
151                                                 run.dyn.stroke = s.createPath(lpath).setStroke(stroke).getStroke();
152                                         } else {
153                                                 run.dyn.stroke = s.createPolyline(lpoly).setStroke(stroke).getStroke();
154                                         }
155                                 }
156                                 if(this.opt.markers){
157                                         dojo.forEach(lpoly, function(c){
158                                                 var path = "M" + c.x + " " + c.y + " " + marker;
159                                                 if(outline){
160                                                         s.createPath(path).setStroke(outline);
161                                                 }
162                                                 s.createPath(path).setStroke(stroke).setFill(stroke.color);
163                                         }, this);
164                                 }
165                                 run.dirty = false;
166                         }
167                         this.dirty = false;
168                         return this;
169                 }
170         });
171 })();
172
173 }