Sparkline.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. define("dojox/charting/widget/Sparkline", ["dojo/_base/lang", "dojo/_base/array", "dojo/_base/declare", "dojo/_base/html", "dojo/query",
  2. "./Chart", "../themes/GreySkies", "../plot2d/Lines", "dojo/dom-prop"],
  3. function(lang, arrayUtil, declare, html, query, Chart, GreySkies, Lines, domProp){
  4. /*=====
  5. var Chart = dojox.charting.widget.Chart;
  6. =====*/
  7. declare("dojox.charting.widget.Sparkline", Chart, {
  8. theme: GreySkies,
  9. margins: { l: 0, r: 0, t: 0, b: 0 },
  10. type: "Lines",
  11. valueFn: "Number(x)",
  12. store: "",
  13. field: "",
  14. query: "",
  15. queryOptions: "",
  16. start: "0",
  17. count: "Infinity",
  18. sort: "",
  19. data: "",
  20. name: "default",
  21. buildRendering: function(){
  22. var n = this.srcNodeRef;
  23. if( !n.childNodes.length || // shortcut the query
  24. !query("> .axis, > .plot, > .action, > .series", n).length){
  25. var plot = document.createElement("div");
  26. domProp.set(plot, {
  27. "class": "plot",
  28. "name": "default",
  29. "type": this.type
  30. });
  31. n.appendChild(plot);
  32. var series = document.createElement("div");
  33. domProp.set(series, {
  34. "class": "series",
  35. plot: "default",
  36. name: this.name,
  37. start: this.start,
  38. count: this.count,
  39. valueFn: this.valueFn
  40. });
  41. arrayUtil.forEach(
  42. ["store", "field", "query", "queryOptions", "sort", "data"],
  43. function(i){
  44. if(this[i].length){
  45. domProp.set(series, i, this[i]);
  46. }
  47. },
  48. this
  49. );
  50. n.appendChild(series);
  51. }
  52. this.inherited(arguments);
  53. }
  54. }
  55. );
  56. });