7f6471e272b8a7d33c640fd6f4d76668188cf797.svn-base 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. if (!dojo._hasResource["dojox.charting.widget.Chart2D"]) { // _hasResource
  2. // checks added by
  3. // build. Do not use
  4. // _hasResource
  5. // directly in your
  6. // code.
  7. dojo._hasResource["dojox.charting.widget.Chart2D"] = true;
  8. dojo.provide("dojox.charting.widget.Chart2D");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dojox.charting.Chart2D");
  11. dojo.require("dojox.lang.functional");
  12. (function() {
  13. var collectAxisParams, collectPlotParams, collectDataParams, notNull = function(
  14. o) {
  15. return o;
  16. }, df = dojox.lang.functional, du = dojox.lang.utils;
  17. dojo.declare("dojox.charting.widget.Chart2D", dijit._Widget, {
  18. // parameters for the markup
  19. // theme for the chart
  20. theme : null,
  21. // margins for the chart: {l: 10, r: 10, t: 10, b: 10}
  22. margins : null,
  23. // chart area
  24. stroke : null,
  25. fill : null,
  26. // methods
  27. buildRendering : function() {
  28. var n = this.domNode = this.srcNodeRef;
  29. // collect chart parameters
  30. var axes = dojo.filter(dojo.query("> .axis", n)
  31. .map(collectAxisParams), notNull);
  32. var plots = dojo.filter(dojo.query("> .plot", n)
  33. .map(collectPlotParams), notNull);
  34. var series = dojo.filter(dojo.query("> .series", n)
  35. .map(collectDataParams), notNull);
  36. // build the chart
  37. n.innerHTML = "";
  38. var c = this.chart = new dojox.charting.Chart2D(n, {
  39. margins : this.margins,
  40. stroke : this.stroke,
  41. fill : this.fill
  42. });
  43. // add collected parameters
  44. if (this.theme) {
  45. c.setTheme(this.theme);
  46. }
  47. dojo.forEach(axes, function(axis) {
  48. c.addAxis(axis.name, axis.kwArgs);
  49. });
  50. dojo.forEach(plots, function(plot) {
  51. c.addPlot(plot.name, plot.kwArgs);
  52. });
  53. var render = df.foldl(series, function(render, series) {
  54. if (series.type == "data") {
  55. c.addSeries(series.name, series.data, series.kwArgs);
  56. render = true;
  57. } else {
  58. c.addSeries(series.name, [0], series.kwArgs);
  59. var kw = {};
  60. du.updateWithPattern(kw, series.kwArgs, {
  61. "query" : "",
  62. "queryOptions" : null,
  63. "start" : 0,
  64. "count" : 1,
  65. "sort" : []
  66. }, true);
  67. dojo.mixin(kw, {
  68. onComplete : function(data) {
  69. var values;
  70. if ("valueFn" in series.kwArgs) {
  71. var fn = series.kwArgs.valueFn;
  72. values = dojo.map(data,
  73. function(x) {
  74. return fn(series.data
  75. .getValue(
  76. x,
  77. series.field,
  78. 0));
  79. });
  80. } else {
  81. values = dojo.map(data,
  82. function(x) {
  83. return series.data
  84. .getValue(
  85. x,
  86. series.field,
  87. 0);
  88. });
  89. }
  90. c.addSeries(series.name, values,
  91. series.kwArgs).render();
  92. }
  93. });
  94. series.data.fetch(kw);
  95. }
  96. return render;
  97. }, false);
  98. if (render) {
  99. c.render();
  100. }
  101. },
  102. resize : function(box) {
  103. dojo.marginBox(this.domNode, box);
  104. this.chart.resize();
  105. }
  106. });
  107. collectAxisParams = function(node) {
  108. var name = node.getAttribute("name"), type = node
  109. .getAttribute("type");
  110. if (!name) {
  111. return null;
  112. }
  113. var o = {
  114. name : name,
  115. kwArgs : {}
  116. }, kw = o.kwArgs;
  117. if (type) {
  118. if (dojox.charting.axis2d[type]) {
  119. type = "dojox.charting.axis2d." + type;
  120. }
  121. var axis = eval("(" + type + ")");
  122. if (axis) {
  123. kw.type = axis;
  124. }
  125. } else {
  126. type = "dojox.charting.axis2d.Default";
  127. }
  128. var dp = eval("(" + type + ".prototype.defaultParams)");
  129. for (var x in dp) {
  130. if (x in kw) {
  131. continue;
  132. }
  133. var attr = node.getAttribute(x);
  134. kw[x] = du.coerceType(dp[x], attr == null ? dp[x] : attr);
  135. }
  136. var op = eval("(" + type + ".prototype.optionalParams)");
  137. for (var x in op) {
  138. if (x in kw) {
  139. continue;
  140. }
  141. var attr = node.getAttribute(x);
  142. if (attr != null) {
  143. kw[x] = du.coerceType(op[x], attr);
  144. }
  145. }
  146. return o;
  147. };
  148. collectPlotParams = function(node) {
  149. var name = node.getAttribute("name"), type = node
  150. .getAttribute("type");
  151. if (!name) {
  152. return null;
  153. }
  154. var o = {
  155. name : name,
  156. kwArgs : {}
  157. }, kw = o.kwArgs;
  158. if (type) {
  159. if (dojox.charting.plot2d[type]) {
  160. type = "dojox.charting.plot2d." + type;
  161. }
  162. var plot = eval("(" + type + ")");
  163. if (plot) {
  164. kw.type = plot;
  165. }
  166. } else {
  167. type = "dojox.charting.plot2d.Default";
  168. }
  169. var dp = eval("(" + type + ".prototype.defaultParams)");
  170. for (var x in dp) {
  171. if (x in kw) {
  172. continue;
  173. }
  174. var attr = node.getAttribute(x);
  175. kw[x] = du.coerceType(dp[x], attr == null ? dp[x] : attr);
  176. }
  177. var op = eval("(" + type + ".prototype.optionalParams)");
  178. for (var x in op) {
  179. if (x in kw) {
  180. continue;
  181. }
  182. var attr = node.getAttribute(x);
  183. if (attr != null) {
  184. kw[x] = du.coerceType(op[x], attr);
  185. }
  186. }
  187. return o;
  188. };
  189. collectDataParams = function(node) {
  190. var name = node.getAttribute("name");
  191. if (!name) {
  192. return null;
  193. }
  194. var o = {
  195. name : name,
  196. kwArgs : {}
  197. }, kw = o.kwArgs, t;
  198. t = node.getAttribute("plot");
  199. if (t != null) {
  200. kw.plot = t;
  201. }
  202. t = node.getAttribute("marker");
  203. if (t != null) {
  204. kw.marker = t;
  205. }
  206. t = node.getAttribute("stroke");
  207. if (t != null) {
  208. kw.stroke = eval("(" + t + ")");
  209. }
  210. t = node.getAttribute("fill");
  211. if (t != null) {
  212. kw.fill = eval("(" + t + ")");
  213. }
  214. t = node.getAttribute("data");
  215. if (t != null) {
  216. o.type = "data";
  217. o.data = dojo.map(String(t).split(','), Number);
  218. return o;
  219. }
  220. t = node.getAttribute("array");
  221. if (t != null) {
  222. o.type = "data";
  223. o.data = eval("(" + t + ")");
  224. return o;
  225. }
  226. t = node.getAttribute("store");
  227. if (t != null) {
  228. o.type = "store";
  229. o.data = eval("(" + t + ")");
  230. t = node.getAttribute("field");
  231. o.field = t != null ? t : "value";
  232. t = node.getAttribute("query");
  233. if (t != null) {
  234. kw.query = t;
  235. }
  236. t = node.getAttribute("queryOptions");
  237. if (t != null) {
  238. kw.queryOptions = eval("(" + t + ")");
  239. }
  240. t = node.getAttribute("start");
  241. if (t != null) {
  242. kw.start = Number(t);
  243. }
  244. t = node.getAttribute("count");
  245. if (t != null) {
  246. kw.count = Number(t);
  247. }
  248. t = node.getAttribute("sort");
  249. if (t != null) {
  250. kw.sort = eval("(" + t + ")");
  251. }
  252. t = node.getAttribute("valueFn");
  253. if (t != null) {
  254. kw.valueFn = df.lambda(t);
  255. }
  256. return o;
  257. }
  258. return null;
  259. };
  260. })();
  261. }