Sparkline.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.charting.widget.Sparkline"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.charting.widget.Sparkline"] = true;
  8. dojo.provide("dojox.charting.widget.Sparkline");
  9. dojo.require("dojox.charting.widget.Chart2D");
  10. dojo.require("dojox.charting.themes.GreySkies");
  11. dojo.require("dojox.charting.plot2d.Lines");
  12. (function(){
  13. var d = dojo;
  14. dojo.declare("dojox.charting.widget.Sparkline",
  15. dojox.charting.widget.Chart2D,
  16. {
  17. theme: dojox.charting.themes.GreySkies,
  18. margins: { l: 0, r: 0, t: 0, b: 0 },
  19. type: "Lines",
  20. valueFn: "Number(x)",
  21. store: "",
  22. field: "",
  23. query: "",
  24. queryOptions: "",
  25. start: "0",
  26. count: "Infinity",
  27. sort: "",
  28. data: "",
  29. name: "default",
  30. buildRendering: function(){
  31. var n = this.srcNodeRef;
  32. if( !n.childNodes.length || // shortcut the query
  33. !d.query("> .axis, > .plot, > .action, > .series", n).length){
  34. var plot = document.createElement("div");
  35. d.attr(plot, {
  36. "class": "plot",
  37. "name": "default",
  38. "type": this.type
  39. });
  40. n.appendChild(plot);
  41. var series = document.createElement("div");
  42. d.attr(series, {
  43. "class": "series",
  44. plot: "default",
  45. name: this.name,
  46. start: this.start,
  47. count: this.count,
  48. valueFn: this.valueFn
  49. });
  50. d.forEach(
  51. ["store", "field", "query", "queryOptions", "sort", "data"],
  52. function(i){
  53. if(this[i].length){
  54. d.attr(series, i, this[i]);
  55. }
  56. },
  57. this
  58. );
  59. n.appendChild(series);
  60. }
  61. this.inherited(arguments);
  62. }
  63. }
  64. );
  65. })();
  66. }