1 | define([ |
---|
2 | "dojo/_base/lang", |
---|
3 | "./common" |
---|
4 | ], function(lang, common){ |
---|
5 | |
---|
6 | var commonStacked = lang.getObject("dojox.charting.plot2d.commonStacked", true); |
---|
7 | return lang.mixin(commonStacked, { |
---|
8 | collectStats: function(series){ |
---|
9 | var stats = lang.delegate(common.defaultStats); |
---|
10 | for(var i = 0; i < series.length; ++i){ |
---|
11 | var run = series[i]; |
---|
12 | for(var j = 0; j < run.data.length; j++){ |
---|
13 | var x, y; |
---|
14 | if(run.data[j] !== null){ |
---|
15 | if(typeof run.data[j] == "number" || !run.data[j].hasOwnProperty("x")){ |
---|
16 | y = commonStacked.getIndexValue(series, i, j)[0]; |
---|
17 | x = j+1; |
---|
18 | }else{ |
---|
19 | x = run.data[j].x; |
---|
20 | if(x !== null){ |
---|
21 | y = commonStacked.getValue(series, i, x)[0]; |
---|
22 | y = y != null && y.y ? y.y:null; |
---|
23 | } |
---|
24 | } |
---|
25 | stats.hmin = Math.min(stats.hmin, x); |
---|
26 | stats.hmax = Math.max(stats.hmax, x); |
---|
27 | stats.vmin = Math.min(stats.vmin, y); |
---|
28 | stats.vmax = Math.max(stats.vmax, y); |
---|
29 | } |
---|
30 | } |
---|
31 | } |
---|
32 | return stats; |
---|
33 | }, |
---|
34 | getIndexValue: function(series, i, index){ |
---|
35 | var value = 0, v, j, pvalue; |
---|
36 | for(j = 0; j <= i; ++j){ |
---|
37 | pvalue = value; |
---|
38 | v = series[j].data[index]; |
---|
39 | if(v != null){ |
---|
40 | if(isNaN(v)){ v = v.y || 0; } |
---|
41 | value += v; |
---|
42 | } |
---|
43 | } |
---|
44 | return [value , pvalue]; |
---|
45 | }, |
---|
46 | getValue: function(series, i, x){ |
---|
47 | var value = null, j, z, v, pvalue; |
---|
48 | for(j = 0; j <= i; ++j){ |
---|
49 | for(z = 0; z < series[j].data.length; z++){ |
---|
50 | pvalue = value; |
---|
51 | v = series[j].data[z]; |
---|
52 | if(v !== null){ |
---|
53 | if(v.x == x){ |
---|
54 | if(!value){ |
---|
55 | value = {x: x}; |
---|
56 | } |
---|
57 | if(v.y != null){ |
---|
58 | if(value.y == null){ |
---|
59 | value.y = 0; |
---|
60 | } |
---|
61 | value.y += v.y; |
---|
62 | } |
---|
63 | break; |
---|
64 | }else if(v.x > x){break;} |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | return [value, pvalue]; |
---|
69 | } |
---|
70 | }); |
---|
71 | }); |
---|