API Docs for: 3.10.3
Show:

File: charts/js/Renderer.js

  1. /**
  2. * The Charts widget provides an api for displaying data
  3. * graphically.
  4. *
  5. * @module charts
  6. * @main charts
  7. */
  8.  
  9. /**
  10. * Provides functionality for the handling of axis data in a chart.
  11. *
  12. * @module charts
  13. * @submodule axis-base
  14. */
  15. var Y_Lang = Y.Lang;
  16.  
  17. /**
  18. * The Renderer class is a base class for chart components that use the `styles`
  19. * attribute.
  20. *
  21. * @module charts
  22. * @class Renderer
  23. * @constructor
  24. */
  25. function Renderer(){}
  26.  
  27. Renderer.ATTRS = {
  28. /**
  29. * Style properties for class
  30. *
  31. * @attribute styles
  32. * @type Object
  33. */
  34. styles:
  35. {
  36. getter: function()
  37. {
  38. this._styles = this._styles || this._getDefaultStyles();
  39. return this._styles;
  40. },
  41.  
  42. setter: function(val)
  43. {
  44. this._styles = this._setStyles(val);
  45. }
  46. },
  47.  
  48. /**
  49. * The graphic in which drawings will be rendered.
  50. *
  51. * @attribute graphic
  52. * @type Graphic
  53. */
  54. graphic: {}
  55. };
  56. Renderer.NAME = "renderer";
  57.  
  58. Renderer.prototype = {
  59. /**
  60. * Storage for `styles` attribute.
  61. *
  62. * @property _styles
  63. * @type Object
  64. * @private
  65. */
  66. _styles: null,
  67.  
  68. /**
  69. * Method used by `styles` setter.
  70. *
  71. * @method _setStyles
  72. * @param {Object} newStyles Hash of properties to update.
  73. * @return Object
  74. * @protected
  75. */
  76. _setStyles: function(newstyles)
  77. {
  78. var styles = this.get("styles");
  79. return this._mergeStyles(newstyles, styles);
  80. },
  81.  
  82. /**
  83. * Merges to object literals so that only specified properties are
  84. * overwritten.
  85. *
  86. * @method _mergeStyles
  87. * @param {Object} a Hash of new styles
  88. * @param {Object} b Hash of original styles
  89. * @return Object
  90. * @protected
  91. */
  92. _mergeStyles: function(a, b)
  93. {
  94. if(!b)
  95. {
  96. b = {};
  97. }
  98. var newstyles = Y.merge(b, {});
  99. Y.Object.each(a, function(value, key)
  100. {
  101. if(b.hasOwnProperty(key) && Y_Lang.isObject(value) && !Y_Lang.isFunction(value) && !Y_Lang.isArray(value))
  102. {
  103. newstyles[key] = this._mergeStyles(value, b[key]);
  104. }
  105. else
  106. {
  107. newstyles[key] = value;
  108. }
  109. }, this);
  110. return newstyles;
  111. },
  112.  
  113. /**
  114. * Gets the default value for the `styles` attribute.
  115. *
  116. * @method _getDefaultStyles
  117. * @return Object
  118. * @protected
  119. */
  120. _getDefaultStyles: function()
  121. {
  122. return {padding:{
  123. top:0,
  124. right: 0,
  125. bottom: 0,
  126. left: 0
  127. }};
  128. }
  129. };
  130.  
  131. Y.augment(Renderer, Y.Attribute);
  132. Y.Renderer = Renderer;
  133.  
  134.