API Docs for: 3.10.3
Show:

File: charts/js/SeriesBase.js

  1. /**
  2. * Provides functionality for creating a chart series.
  3. *
  4. * @module charts
  5. * @submodule series-base
  6. */
  7.  
  8. /**
  9. * An abstract class for creating series instances.
  10. * SeriesBase is used by the following classes:
  11. * <ul>
  12. * <li>{{#crossLink "CartesianSeries"}}{{/crossLink}}</li>
  13. * <li>{{#crossLink "PieSeries"}}{{/crossLink}}</li>
  14. * </ul>
  15. *
  16. * @class SeriesBase
  17. * @extends Base
  18. * @uses Renderer
  19. * @constructor
  20. * @param {Object} config (optional) Configuration parameters.
  21. * @submodule series-base
  22. */
  23. Y.SeriesBase = Y.Base.create("seriesBase", Y.Base, [Y.Renderer], {
  24. /**
  25. * @method render
  26. * @private
  27. */
  28. render: function()
  29. {
  30. this._setCanvas();
  31. this.addListeners();
  32. this.validate();
  33. },
  34.  
  35. /**
  36. * Creates a `Graphic` instance.
  37. *
  38. * @method _setCanvas
  39. * @protected
  40. */
  41. _setCanvas: function()
  42. {
  43. var graph = this.get("graph"),
  44. graphic = graph.get("graphic");
  45. this.set("graphic", graphic);
  46. },
  47.  
  48. /**
  49. * Returns a reference to the parent container to which all chart elements are contained.
  50. * When the series is bound to a `Chart` instance, the `Chart` instance is the reference.
  51. * If nothing is set as the `chart` attribute, the `_getChart` method will return a reference
  52. * to the `graphic` attribute.
  53. *
  54. * @method _getChart
  55. * @return {Object}
  56. * @private
  57. */
  58. _getChart:function() {
  59. var chart,
  60. graph = this.get("graph");
  61. if(graph)
  62. {
  63. chart = graph.get("chart");
  64. }
  65. if(!chart)
  66. {
  67. chart = this.get("graphic");
  68. }
  69. return chart;
  70. },
  71.  
  72. /**
  73. * Returns the sum of all values for the series.
  74. *
  75. * @method getTotalValues
  76. * @return Number
  77. */
  78. getTotalValues: function()
  79. {
  80. var valueCoord = this.get("direction") === "vertical" ? "x" : "y",
  81. total = this.get(valueCoord + "Axis").getTotalByKey(this.get(valueCoord + "Key"));
  82. return total;
  83. },
  84.  
  85. /**
  86. * Gets the default value for the `styles` attribute. Overrides
  87. * base implementation.
  88. *
  89. * @method _getDefaultStyles
  90. * @return Object
  91. * @protected
  92. */
  93. _getDefaultStyles: function()
  94. {
  95. return {padding:{
  96. top: 0,
  97. left: 0,
  98. right: 0,
  99. bottom: 0
  100. }};
  101. },
  102.  
  103. /**
  104. * Shows/hides contents of the series.
  105. *
  106. * @method _handleVisibleChange
  107. * @param {Object} e Event object.
  108. * @protected
  109. */
  110. _handleVisibleChange: function()
  111. {
  112. this._toggleVisible(this.get("visible"));
  113. },
  114.  
  115. /**
  116. * Destructor implementation for the CartesianSeries class. Calls destroy on all Graphic instances.
  117. *
  118. * @method destructor
  119. * @protected
  120. */
  121. destructor: function()
  122. {
  123. var marker,
  124. markers = this.get("markers");
  125. if(this.get("rendered"))
  126. {
  127. this._stylesChangeHandle.detach();
  128. this._widthChangeHandle.detach();
  129. this._heightChangeHandle.detach();
  130. this._visibleChangeHandle.detach();
  131. }
  132. while(markers && markers.length > 0)
  133. {
  134. marker = markers.shift();
  135. if(marker && marker instanceof Y.Shape)
  136. {
  137. marker.destroy();
  138. }
  139. }
  140. if(this._path)
  141. {
  142. this._path.destroy();
  143. this._path = null;
  144. }
  145. if(this._lineGraphic)
  146. {
  147. this._lineGraphic.destroy();
  148. this._lineGraphic = null;
  149. }
  150. if(this._groupMarker)
  151. {
  152. this._groupMarker.destroy();
  153. this._groupMarker = null;
  154. }
  155. },
  156.  
  157. /**
  158. * Collection of default colors used for lines in a series when not specified by user.
  159. *
  160. * @property _defaultLineColors
  161. * @type Array
  162. * @protected
  163. */
  164. _defaultLineColors:[
  165. "#426ab3",
  166. "#d09b2c",
  167. "#000000",
  168. "#b82837",
  169. "#b384b5",
  170. "#ff7200",
  171. "#779de3",
  172. "#cbc8ba",
  173. "#7ed7a6",
  174. "#007a6c"
  175. ],
  176.  
  177. /**
  178. * Collection of default colors used for marker fills in a series when not specified by user.
  179. *
  180. * @property _defaultFillColors
  181. * @type Array
  182. * @protected
  183. */
  184. _defaultFillColors:[
  185. "#6084d0",
  186. "#eeb647",
  187. "#6c6b5f",
  188. "#d6484f",
  189. "#ce9ed1",
  190. "#ff9f3b",
  191. "#93b7ff",
  192. "#e0ddd0",
  193. "#94ecba",
  194. "#309687"
  195. ],
  196.  
  197. /**
  198. * Collection of default colors used for marker borders in a series when not specified by user.
  199. *
  200. * @property _defaultBorderColors
  201. * @type Array
  202. * @protected
  203. */
  204. _defaultBorderColors:[
  205. "#205096",
  206. "#b38206",
  207. "#000000",
  208. "#94001e",
  209. "#9d6fa0",
  210. "#e55b00",
  211. "#5e85c9",
  212. "#adab9e",
  213. "#6ac291",
  214. "#006457"
  215. ],
  216.  
  217. /**
  218. * Collection of default colors used for area fills, histogram fills and pie fills in a series when not specified by user.
  219. *
  220. * @property _defaultSliceColors
  221. * @type Array
  222. * @protected
  223. */
  224. _defaultSliceColors: [
  225. "#66007f",
  226. "#a86f41",
  227. "#295454",
  228. "#996ab2",
  229. "#e8cdb7",
  230. "#90bdbd",
  231. "#000000",
  232. "#c3b8ca",
  233. "#968373",
  234. "#678585"
  235. ],
  236.  
  237. /**
  238. * Parses a color based on a series order and type.
  239. *
  240. * @method _getDefaultColor
  241. * @param {Number} index Index indicating the series order.
  242. * @param {String} type Indicates which type of object needs the color.
  243. * @return String
  244. * @protected
  245. */
  246. _getDefaultColor: function(index, type)
  247. {
  248. var colors = {
  249. line: this._defaultLineColors,
  250. fill: this._defaultFillColors,
  251. border: this._defaultBorderColors,
  252. slice: this._defaultSliceColors
  253. },
  254. col = colors[type] || colors.fill,
  255. l = col.length;
  256. index = index || 0;
  257. if(index >= l)
  258. {
  259. index = index % l;
  260. }
  261. type = type || "fill";
  262. return colors[type][index];
  263. }
  264. }, {
  265. ATTRS: {
  266. /*
  267. * Returns the width of the parent graph
  268. *
  269. * @attribute width
  270. * @type Number
  271. */
  272. width: {
  273. readOnly: true,
  274.  
  275. getter: function()
  276. {
  277. return this.get("graphic").get("width");
  278. }
  279. },
  280.  
  281. /**
  282. * Returns the height of the parent graph
  283. *
  284. * @attribute height
  285. * @type Number
  286. */
  287. height: {
  288. readOnly: true,
  289.  
  290. getter: function()
  291. {
  292. return this.get("graphic").get("height");
  293. }
  294. },
  295.  
  296. /**
  297. * The graphic in which drawings will be rendered.
  298. *
  299. * @attribute graphic
  300. * @type Graphic
  301. */
  302. graphic: {
  303. lazyAdd: false,
  304.  
  305. setter: function(val) {
  306. //woraround for Attribute order of operations bug
  307. if(!this.get("rendered")) {
  308. this.set("rendered", true);
  309. }
  310. return val;
  311. }
  312. },
  313.  
  314. /**
  315. * Reference to the `Chart` application. If no `Chart` application is present,
  316. * a reference to the `Graphic` instance that the series is drawn into will be returned.
  317. *
  318. * @attribute chart
  319. * @type ChartBase
  320. */
  321. chart: {
  322. getter: function()
  323. {
  324. var chart,
  325. graph = this.get("graph");
  326. if(graph)
  327. {
  328. chart = graph.get("chart");
  329. }
  330. return chart;
  331. }
  332. },
  333.  
  334. /**
  335. * Reference to the `Graph` in which the series is drawn into.
  336. *
  337. * @attribute graph
  338. * @type Graph
  339. */
  340. graph: {},
  341.  
  342. /**
  343. * Indicates whether the Series has been through its initial set up.
  344. *
  345. * @attribute rendered
  346. * @type Boolean
  347. */
  348. rendered: {
  349. value: false
  350. },
  351.  
  352. /**
  353. * Indicates whether to show the series
  354. *
  355. * @attribute visible
  356. * @type Boolean
  357. * @default true
  358. */
  359. visible: {
  360. value: true
  361. },
  362.  
  363. /**
  364. * Indicates whether or not markers for a series will be grouped and rendered in a single complex shape instance.
  365. *
  366. * @attribute groupMarkers
  367. * @type Boolean
  368. */
  369. groupMarkers: {
  370. getter: function()
  371. {
  372. var graph,
  373. groupMarkers = this._groupMarkers;
  374. if(!groupMarkers) {
  375. graph = this.get("graph");
  376. if(graph)
  377. {
  378. groupMarkers = graph.get("groupMarkers");
  379. }
  380. }
  381. return groupMarkers;
  382. },
  383.  
  384. setter: function(val)
  385. {
  386. this._groupMarkers = val;
  387. return val;
  388. }
  389. }
  390. }
  391. });
  392.