|
1 YUI.add('series-bar', function (Y, NAME) { |
|
2 |
|
3 /** |
|
4 * Provides functionality for creating a bar series. |
|
5 * |
|
6 * @module charts |
|
7 * @submodule series-bar |
|
8 */ |
|
9 /** |
|
10 * The BarSeries class renders bars positioned vertically along a category or time axis. The bars' |
|
11 * lengths are proportional to the values they represent along a horizontal axis. |
|
12 * and the relevant data points. |
|
13 * |
|
14 * @class BarSeries |
|
15 * @extends MarkerSeries |
|
16 * @uses Histogram |
|
17 * @constructor |
|
18 * @param {Object} config (optional) Configuration parameters. |
|
19 * @submodule series-bar |
|
20 */ |
|
21 Y.BarSeries = Y.Base.create("barSeries", Y.MarkerSeries, [Y.Histogram], { |
|
22 /** |
|
23 * Helper method for calculating the size of markers. |
|
24 * |
|
25 * @method _getMarkerDimensions |
|
26 * @param {Number} xcoord The x-coordinate representing the data point for the marker. |
|
27 * @param {Number} ycoord The y-coordinate representing the data point for the marker. |
|
28 * @param {Number} calculatedSize The calculated size for the marker. For a `BarSeries` is it the width. For a `ColumnSeries` it is the height. |
|
29 * @param {Number} offset Distance of position offset dictated by other marker series in the same graph. |
|
30 * @return Object |
|
31 * @private |
|
32 */ |
|
33 _getMarkerDimensions: function(xcoord, ycoord, calculatedSize, offset) |
|
34 { |
|
35 var config = { |
|
36 top: ycoord + offset |
|
37 }; |
|
38 if(xcoord >= this._leftOrigin) |
|
39 { |
|
40 config.left = this._leftOrigin; |
|
41 config.calculatedSize = xcoord - config.left; |
|
42 } |
|
43 else |
|
44 { |
|
45 config.left = xcoord; |
|
46 config.calculatedSize = this._leftOrigin - xcoord; |
|
47 } |
|
48 return config; |
|
49 }, |
|
50 |
|
51 /** |
|
52 * Resizes and positions markers based on a mouse interaction. |
|
53 * |
|
54 * @method updateMarkerState |
|
55 * @param {String} type state of the marker |
|
56 * @param {Number} i index of the marker |
|
57 * @protected |
|
58 */ |
|
59 updateMarkerState: function(type, i) |
|
60 { |
|
61 if(this._markers && this._markers[i]) |
|
62 { |
|
63 var styles = this._copyObject(this.get("styles").marker), |
|
64 markerStyles, |
|
65 state = this._getState(type), |
|
66 xcoords = this.get("xcoords"), |
|
67 ycoords = this.get("ycoords"), |
|
68 marker = this._markers[i], |
|
69 markers, |
|
70 seriesCollection = this.get("seriesTypeCollection"), |
|
71 seriesLen = seriesCollection ? seriesCollection.length : 0, |
|
72 seriesStyles, |
|
73 seriesSize = 0, |
|
74 offset = 0, |
|
75 renderer, |
|
76 n = 0, |
|
77 ys = [], |
|
78 order = this.get("order"), |
|
79 config; |
|
80 markerStyles = state === "off" || !styles[state] ? styles : styles[state]; |
|
81 markerStyles.fill.color = this._getItemColor(markerStyles.fill.color, i); |
|
82 markerStyles.border.color = this._getItemColor(markerStyles.border.color, i); |
|
83 config = this._getMarkerDimensions(xcoords[i], ycoords[i], styles.height, offset); |
|
84 markerStyles.width = config.calculatedSize; |
|
85 markerStyles.height = Math.min(this._maxSize, markerStyles.height); |
|
86 marker.set(markerStyles); |
|
87 for(; n < seriesLen; ++n) |
|
88 { |
|
89 ys[n] = ycoords[i] + seriesSize; |
|
90 seriesStyles = seriesCollection[n].get("styles").marker; |
|
91 seriesSize += Math.min(this._maxSize, seriesStyles.height); |
|
92 if(order > n) |
|
93 { |
|
94 offset = seriesSize; |
|
95 } |
|
96 offset -= seriesSize/2; |
|
97 } |
|
98 for(n = 0; n < seriesLen; ++n) |
|
99 { |
|
100 markers = seriesCollection[n].get("markers"); |
|
101 if(markers) |
|
102 { |
|
103 renderer = markers[i]; |
|
104 if(renderer && renderer !== undefined) |
|
105 { |
|
106 renderer.set("y", (ys[n] - seriesSize/2)); |
|
107 } |
|
108 } |
|
109 } |
|
110 } |
|
111 } |
|
112 }, { |
|
113 ATTRS: { |
|
114 /** |
|
115 * Read-only attribute indicating the type of series. |
|
116 * |
|
117 * @attribute type |
|
118 * @type String |
|
119 * @default bar |
|
120 */ |
|
121 type: { |
|
122 value: "bar" |
|
123 }, |
|
124 |
|
125 /** |
|
126 * Indicates the direction of the category axis that the bars are plotted against. |
|
127 * |
|
128 * @attribute direction |
|
129 * @type String |
|
130 */ |
|
131 direction: { |
|
132 value: "vertical" |
|
133 } |
|
134 |
|
135 /** |
|
136 * Style properties used for drawing markers. This attribute is inherited from `MarkerSeries`. Below are the default values: |
|
137 * <dl> |
|
138 * <dt>fill</dt><dd>A hash containing the following values: |
|
139 * <dl> |
|
140 * <dt>color</dt><dd>Color of the fill. The default value is determined by the order of the series on the graph. The color |
|
141 * will be retrieved from the below array:<br/> |
|
142 * `["#66007f", "#a86f41", "#295454", "#996ab2", "#e8cdb7", "#90bdbd","#000000","#c3b8ca", "#968373", "#678585"]` |
|
143 * </dd> |
|
144 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd> |
|
145 * </dl> |
|
146 * </dd> |
|
147 * <dt>border</dt><dd>A hash containing the following values: |
|
148 * <dl> |
|
149 * <dt>color</dt><dd>Color of the border. The default value is determined by the order of the series on the graph. The color |
|
150 * will be retrieved from the below array:<br/> |
|
151 * `["#205096", "#b38206", "#000000", "#94001e", "#9d6fa0", "#e55b00", "#5e85c9", "#adab9e", "#6ac291", "#006457"]` |
|
152 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd> |
|
153 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 1.</dd> |
|
154 * </dl> |
|
155 * </dd> |
|
156 * <dt>height</dt><dd>indicates the width of the marker. The default value is 12.</dd> |
|
157 * <dt>over</dt><dd>hash containing styles for markers when highlighted by a `mouseover` event. The default |
|
158 * values for each style is null. When an over style is not set, the non-over value will be used. For example, |
|
159 * the default value for `marker.over.fill.color` is equivalent to `marker.fill.color`.</dd> |
|
160 * </dl> |
|
161 * |
|
162 * @attribute styles |
|
163 * @type Object |
|
164 */ |
|
165 } |
|
166 }); |
|
167 |
|
168 |
|
169 }, '@VERSION@', {"requires": ["series-marker", "series-histogram-base"]}); |