2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('series-column-stacked', function (Y, NAME) {
11 * Provides functionality for creating a stacked column series.
14 * @submodule series-column-stacked
19 * The StackedColumnSeries renders column chart in which series are stacked vertically to show
20 * their contribution to the cumulative total.
22 * @class StackedColumnSeries
23 * @extends ColumnSeries
26 * @param {Object} config (optional) Configuration parameters.
27 * @submodule series-column-stacked
29 Y.StackedColumnSeries = Y.Base.create("stackedColumnSeries", Y.ColumnSeries, [Y.StackingUtil], {
36 drawSeries: function()
38 if(this.get("xcoords").length < 1)
42 var isNumber = Y_Lang.isNumber,
43 style = Y.clone(this.get("styles").marker),
46 xcoords = this.get("xcoords"),
47 ycoords = this.get("ycoords"),
51 seriesCollection = this.get("seriesTypeCollection"),
53 order = this.get("order"),
54 graphOrder = this.get("graphOrder"),
62 useOrigin = order === 0,
70 groupMarkers = this.get("groupMarkers");
71 if(Y_Lang.isArray(style.fill.color))
73 fillColors = style.fill.color.concat();
75 if(Y_Lang.isArray(style.border.color))
77 borderColors = style.border.color.concat();
79 this._createMarkerCache();
80 if(totalWidth > this.get("width"))
82 ratio = this.get("width")/totalWidth;
88 lastCollection = seriesCollection[order - 1];
89 negativeBaseValues = lastCollection.get("negativeBaseValues");
90 positiveBaseValues = lastCollection.get("positiveBaseValues");
91 if(!negativeBaseValues || !positiveBaseValues)
94 positiveBaseValues = [];
95 negativeBaseValues = [];
100 negativeBaseValues = [];
101 positiveBaseValues = [];
103 this.set("negativeBaseValues", negativeBaseValues);
104 this.set("positiveBaseValues", positiveBaseValues);
105 for(i = 0; i < len; ++i)
110 if(!isNumber(top) || !isNumber(left))
114 negativeBaseValues[i] = this._bottomOrigin;
115 positiveBaseValues[i] = this._bottomOrigin;
117 this._markers.push(null);
122 h = Math.abs(this._bottomOrigin - top);
123 if(top < this._bottomOrigin)
125 positiveBaseValues[i] = top;
126 negativeBaseValues[i] = this._bottomOrigin;
128 else if(top > this._bottomOrigin)
130 positiveBaseValues[i] = this._bottomOrigin;
131 negativeBaseValues[i] = top;
136 positiveBaseValues[i] = top;
137 negativeBaseValues[i] = top;
142 if(top > this._bottomOrigin)
144 top += (negativeBaseValues[i] - this._bottomOrigin);
145 h = top - negativeBaseValues[i];
146 negativeBaseValues[i] = top;
149 else if(top <= this._bottomOrigin)
151 top = positiveBaseValues[i] - (this._bottomOrigin - top);
152 h = positiveBaseValues[i] - top;
153 positiveBaseValues[i] = top;
156 if(!isNaN(h) && h > 0)
161 dimensions.width[i] = w;
162 dimensions.height[i] = h;
174 style.fill.color = fillColors[i % fillColors.length];
178 style.border.color = borderColors[i % borderColors.length];
180 marker = this.getMarker(style, graphOrder, i);
183 else if(!groupMarkers)
185 this._markers.push(null);
190 this._createGroupMarker({
192 border: style.border,
193 dimensions: dimensions,
201 this._clearMarkerCache();
206 * Resizes and positions markers based on a mouse interaction.
208 * @method updateMarkerState
209 * @param {String} type state of the marker
210 * @param {Number} i index of the marker
213 updateMarkerState: function(type, i)
215 if(this._markers && this._markers[i])
219 state = this._getState(type),
220 xcoords = this.get("xcoords"),
221 marker = this._markers[i],
225 styles = this.get("styles").marker;
226 offset = styles.width * 0.5;
227 markerStyles = state === "off" || !styles[state] ? Y.clone(styles) : Y.clone(styles[state]);
228 markerStyles.height = marker.get("height");
229 markerStyles.x = (xcoords[i] - offset);
230 markerStyles.y = marker.get("y");
231 markerStyles.id = marker.get("id");
232 fillColor = markerStyles.fill.color;
233 borderColor = markerStyles.border.color;
234 if(Y_Lang.isArray(fillColor))
236 markerStyles.fill.color = fillColor[i % fillColor.length];
240 markerStyles.fill.color = this._getItemColor(markerStyles.fill.color, i);
242 if(Y_Lang.isArray(borderColor))
244 markerStyles.border.color = borderColor[i % borderColor.length];
248 markerStyles.border.color = this._getItemColor(markerStyles.border.color, i);
250 marker.set(markerStyles);
255 * Gets the default values for the markers.
257 * @method _getPlotDefaults
261 _getPlotDefaults: function()
286 defs.fill.color = this._getDefaultColor(this.get("graphOrder"), "fill");
287 defs.border.color = this._getDefaultColor(this.get("graphOrder"), "border");
293 * Read-only attribute indicating the type of series.
297 * @default stackedColumn
300 value: "stackedColumn"
304 * @attribute negativeBaseValues
309 negativeBaseValues: {
314 * @attribute positiveBaseValues
319 positiveBaseValues: {
324 * Style properties used for drawing markers. This attribute is inherited from `ColumnSeries`. Below are the default values:
326 * <dt>fill</dt><dd>A hash containing the following values:
328 * <dt>color</dt><dd>Color of the fill. The default value is determined by the order of the series on the graph. The color
329 * will be retrieved from the below array:<br/>
330 * `["#66007f", "#a86f41", "#295454", "#996ab2", "#e8cdb7", "#90bdbd","#000000","#c3b8ca", "#968373", "#678585"]`
332 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd>
335 * <dt>border</dt><dd>A hash containing the following values:
337 * <dt>color</dt><dd>Color of the border. The default value is determined by the order of the series on the graph. The color
338 * will be retrieved from the below array:<br/>
339 * `["#205096", "#b38206", "#000000", "#94001e", "#9d6fa0", "#e55b00", "#5e85c9", "#adab9e", "#6ac291", "#006457"]`
340 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd>
341 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 1.</dd>
344 * <dt>width</dt><dd>indicates the width of the marker. The default value is 24.</dd>
345 * <dt>over</dt><dd>hash containing styles for markers when highlighted by a `mouseover` event. The default
346 * values for each style is null. When an over style is not set, the non-over value will be used. For example,
347 * the default value for `marker.over.fill.color` is equivalent to `marker.fill.color`.</dd>
358 }, '3.13.0', {"requires": ["series-stacked", "series-column"]});