1 if(!dojo._hasResource["dojox.charting.widget.Chart2D"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.charting.widget.Chart2D"] = true;
3 dojo.provide("dojox.charting.widget.Chart2D");
5 dojo.require("dijit._Widget");
6 dojo.require("dojox.charting.Chart2D");
7 dojo.require("dojox.lang.functional");
10 var collectAxisParams, collectPlotParams, collectDataParams,
11 notNull = function(o){ return o; },
12 df = dojox.lang.functional,
13 du = dojox.lang.utils;
15 dojo.declare("dojox.charting.widget.Chart2D", dijit._Widget, {
16 // parameters for the markup
18 // theme for the chart
21 // margins for the chart: {l: 10, r: 10, t: 10, b: 10}
30 buildRendering: function(){
31 var n = this.domNode = this.srcNodeRef;
33 // collect chart parameters
34 var axes = dojo.filter(dojo.query("> .axis", n).map(collectAxisParams), notNull);
35 var plots = dojo.filter(dojo.query("> .plot", n).map(collectPlotParams), notNull);
36 var series = dojo.filter(dojo.query("> .series", n).map(collectDataParams), notNull);
40 var c = this.chart = new dojox.charting.Chart2D(n, {
41 margins: this.margins,
46 // add collected parameters
48 c.setTheme(this.theme);
50 dojo.forEach(axes, function(axis){
51 c.addAxis(axis.name, axis.kwArgs);
53 dojo.forEach(plots, function(plot){
54 c.addPlot(plot.name, plot.kwArgs);
56 var render = df.foldl(series, function(render, series){
57 if(series.type == "data"){
58 c.addSeries(series.name, series.data, series.kwArgs);
61 c.addSeries(series.name, [0], series.kwArgs);
75 if(series.kwArgs.sort){
76 // sort is a complex object type and doesn't survive coercian
77 kw.sort = dojo.clone(series.kwArgs.sort);
80 onComplete: function(data){
82 if("valueFn" in series.kwArgs){
83 var fn = series.kwArgs.valueFn;
84 values = dojo.map(data, function(x){
85 return fn(series.data.getValue(x, series.field, 0));
88 values = dojo.map(data, function(x){
89 return series.data.getValue(x, series.field, 0);
92 c.addSeries(series.name, values, series.kwArgs).render();
95 series.data.fetch(kw);
99 if(render){ c.render(); }
101 resize: function(box){
102 dojo.marginBox(this.domNode, box);
107 collectAxisParams = function(node){
108 var name = node.getAttribute("name"), type = node.getAttribute("type");
109 if(!name){ return null; }
110 var o = {name: name, kwArgs: {}}, kw = o.kwArgs;
112 if(dojox.charting.axis2d[type]){
113 type = dojox._scopeName + ".charting.axis2d." + type;
115 var axis = eval("(" + type + ")");
116 if(axis){ kw.type = axis; }
118 type = dojox._scopeName + ".charting.axis2d.Default";
120 var dp = eval("(" + type + ".prototype.defaultParams)");
122 if(x in kw){ continue; }
123 var attr = node.getAttribute(x);
124 kw[x] = du.coerceType(dp[x], attr == null ? dp[x] : attr);
126 var op = eval("(" + type + ".prototype.optionalParams)");
128 if(x in kw){ continue; }
129 var attr = node.getAttribute(x);
131 kw[x] = du.coerceType(op[x], attr);
137 collectPlotParams = function(node){
138 var name = node.getAttribute("name"), type = node.getAttribute("type");
139 if(!name){ return null; }
140 var o = {name: name, kwArgs: {}}, kw = o.kwArgs;
142 if(dojox.charting.plot2d[type]){
143 type = dojox._scopeName + ".charting.plot2d." + type;
145 var plot = eval("(" + type + ")");
146 if(plot){ kw.type = plot; }
148 type = dojox._scopeName + ".charting.plot2d.Default";
150 var dp = eval("(" + type + ".prototype.defaultParams)");
152 if(x in kw){ continue; }
153 var attr = node.getAttribute(x);
154 kw[x] = du.coerceType(dp[x], attr == null ? dp[x] : attr);
156 var op = eval("(" + type + ".prototype.optionalParams)");
158 if(x in kw){ continue; }
159 var attr = node.getAttribute(x);
161 kw[x] = du.coerceType(op[x], attr);
167 collectDataParams = function(node){
168 var name = node.getAttribute("name");
169 if(!name){ return null; }
170 var o = {name: name, kwArgs: {}}, kw = o.kwArgs, t;
171 t = node.getAttribute("plot");
172 if(t != null){ kw.plot = t; }
173 t = node.getAttribute("marker");
174 if(t != null){ kw.marker = t; }
175 t = node.getAttribute("stroke");
176 if(t != null){ kw.stroke = eval("(" + t + ")"); }
177 t = node.getAttribute("fill");
178 if(t != null){ kw.fill = eval("(" + t + ")"); }
179 t = node.getAttribute("data");
182 o.data = dojo.map(String(t).split(','), Number);
185 t = node.getAttribute("array");
188 o.data = eval("(" + t + ")");
191 t = node.getAttribute("store");
194 o.data = eval("(" + t + ")");
195 t = node.getAttribute("field");
196 o.field = t != null ? t : "value";
197 t = node.getAttribute("query");
198 if(!!t){ kw.query = t; }
199 t = node.getAttribute("queryOptions");
200 if(!!t){ kw.queryOptions = eval("(" + t + ")"); }
201 t = node.getAttribute("start");
202 if(!!t){ kw.start = Number(t); }
203 t = node.getAttribute("count");
204 if(!!t){ kw.count = Number(t); }
205 t = node.getAttribute("sort");
206 if(!!t){ kw.sort = eval("("+t+")"); }
207 t = node.getAttribute("valueFn");
208 if(!!t){ kw.valueFn = df.lambda(t); }