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");
5 dojo.require("dojox.charting.plot2d.common");
6 dojo.require("dojox.charting.plot2d.Base");
8 dojo.require("dojox.lang.utils");
9 dojo.require("dojox.lang.functional");
10 dojo.require("dojox.lang.functional.reversed");
13 var df = dojox.lang.functional, du = dojox.lang.utils,
14 dc = dojox.charting.plot2d.common,
15 purgeGroup = df.lambda("item.purgeGroup()");
17 dojo.declare("dojox.charting.plot2d.Default", dojox.charting.plot2d.Base, {
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)
27 optionalParams: {}, // no optional parameters
29 constructor: function(chart, kwArgs){
30 this.opt = dojo.clone(this.defaultParams);
31 du.updateWithObject(this.opt, kwArgs);
33 this.hAxis = this.opt.hAxis;
34 this.vAxis = this.opt.vAxis;
37 calculateAxes: function(dim){
38 this._calc(dim, dc.collectSimpleStats(this.series));
41 render: function(dim, offsets){
43 dojo.forEach(this.series, purgeGroup);
46 df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
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; }
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;
68 var s = run.group, lpoly;
69 if(typeof run.data[0] == "number"){
70 lpoly = dojo.map(run.data, function(v, i){
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)
77 lpoly = dojo.map(run.data, function(v, i){
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)
84 if(!run.fill || !run.stroke){
85 // need autogenerated color
86 color = run.dyn.color = new dojo.Color(t.next("color"));
91 var lpath=curve(lpoly, this.opt.tension);
95 var fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
96 var apoly = dojo.clone(lpoly);
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();
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();
109 if(this.opt.lines || this.opt.markers){
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;
117 if(this.opt.markers){
119 marker = run.dyn.marker = run.marker ? run.marker : t.next("marker");
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};
126 shadowStroke = dojo.clone(outline ? outline : stroke);
127 shadowStroke.color = shadowColor;
128 shadowStroke.width += sh.dw ? sh.dw : 0;
130 if(this.opt.tension){
131 s.createPath(curve(spoly, this.opt.tension)).setStroke(shadowStroke);
133 s.createPolyline(spoly).setStroke(shadowStroke);
136 if(this.opt.markers){
137 dojo.forEach(spoly, function(c){
138 s.createPath("M" + c.x + " " + c.y + " " + marker).setStroke(shadowStroke).setFill(shadowColor);
144 if(this.opt.tension){
145 run.dyn.outline = s.createPath(lpath).setStroke(outline).getStroke();
147 run.dyn.outline = s.createPolyline(lpoly).setStroke(outline).getStroke();
150 if(this.opt.tension){
151 run.dyn.stroke = s.createPath(lpath).setStroke(stroke).getStroke();
153 run.dyn.stroke = s.createPolyline(lpoly).setStroke(stroke).getStroke();
156 if(this.opt.markers){
157 dojo.forEach(lpoly, function(c){
158 var path = "M" + c.x + " " + c.y + " " + marker;
160 s.createPath(path).setStroke(outline);
162 s.createPath(path).setStroke(stroke).setFill(stroke.color);