|
602
|
1 |
YUI.add('series-histogram-base', function (Y, NAME) { |
|
|
2 |
|
|
|
3 |
/** |
|
|
4 |
* Provides core functionality for creating a bar or column series. |
|
|
5 |
* |
|
|
6 |
* @module charts |
|
|
7 |
* @submodule series-histogram |
|
|
8 |
*/ |
|
|
9 |
var Y_Lang = Y.Lang; |
|
|
10 |
|
|
|
11 |
/** |
|
|
12 |
* Histogram is the base class for Column and Bar series. |
|
|
13 |
* |
|
|
14 |
* @class Histogram |
|
|
15 |
* @constructor |
|
|
16 |
* @param {Object} config (optional) Configuration parameters. |
|
|
17 |
* @submodule series-histogram |
|
|
18 |
*/ |
|
|
19 |
function Histogram(){} |
|
|
20 |
|
|
|
21 |
Histogram.prototype = { |
|
|
22 |
/** |
|
|
23 |
* Draws the series. |
|
|
24 |
* |
|
|
25 |
* @method drawSeries |
|
|
26 |
* @protected |
|
|
27 |
*/ |
|
|
28 |
drawSeries: function() |
|
|
29 |
{ |
|
|
30 |
if(this.get("xcoords").length < 1) |
|
|
31 |
{ |
|
|
32 |
return; |
|
|
33 |
} |
|
|
34 |
var style = this._copyObject(this.get("styles").marker), |
|
|
35 |
graphic = this.get("graphic"), |
|
|
36 |
setSize, |
|
|
37 |
calculatedSize, |
|
|
38 |
xcoords = this.get("xcoords"), |
|
|
39 |
ycoords = this.get("ycoords"), |
|
|
40 |
i = 0, |
|
|
41 |
len = xcoords.length, |
|
|
42 |
top = ycoords[0], |
|
|
43 |
seriesTypeCollection = this.get("seriesTypeCollection"), |
|
|
44 |
seriesLen = seriesTypeCollection ? seriesTypeCollection.length : 0, |
|
|
45 |
seriesSize = 0, |
|
|
46 |
totalSize = 0, |
|
|
47 |
offset = 0, |
|
|
48 |
ratio, |
|
|
49 |
renderer, |
|
|
50 |
order = this.get("order"), |
|
|
51 |
graphOrder = this.get("graphOrder"), |
|
|
52 |
left, |
|
|
53 |
marker, |
|
|
54 |
setSizeKey, |
|
|
55 |
calculatedSizeKey, |
|
|
56 |
config, |
|
|
57 |
fillColors = null, |
|
|
58 |
borderColors = null, |
|
|
59 |
xMarkerPlane = [], |
|
|
60 |
yMarkerPlane = [], |
|
|
61 |
xMarkerPlaneLeft, |
|
|
62 |
xMarkerPlaneRight, |
|
|
63 |
yMarkerPlaneTop, |
|
|
64 |
yMarkerPlaneBottom, |
|
|
65 |
dimensions = { |
|
|
66 |
width: [], |
|
|
67 |
height: [] |
|
|
68 |
}, |
|
|
69 |
xvalues = [], |
|
|
70 |
yvalues = [], |
|
|
71 |
groupMarkers = this.get("groupMarkers"); |
|
|
72 |
if(Y_Lang.isArray(style.fill.color)) |
|
|
73 |
{ |
|
|
74 |
fillColors = style.fill.color.concat(); |
|
|
75 |
} |
|
|
76 |
if(Y_Lang.isArray(style.border.color)) |
|
|
77 |
{ |
|
|
78 |
borderColors = style.border.color.concat(); |
|
|
79 |
} |
|
|
80 |
if(this.get("direction") === "vertical") |
|
|
81 |
{ |
|
|
82 |
setSizeKey = "height"; |
|
|
83 |
calculatedSizeKey = "width"; |
|
|
84 |
} |
|
|
85 |
else |
|
|
86 |
{ |
|
|
87 |
setSizeKey = "width"; |
|
|
88 |
calculatedSizeKey = "height"; |
|
|
89 |
} |
|
|
90 |
setSize = style[setSizeKey]; |
|
|
91 |
calculatedSize = style[calculatedSizeKey]; |
|
|
92 |
this._createMarkerCache(); |
|
|
93 |
this._maxSize = graphic.get(setSizeKey); |
|
|
94 |
if(seriesTypeCollection && seriesLen > 1) |
|
|
95 |
{ |
|
|
96 |
for(; i < seriesLen; ++i) |
|
|
97 |
{ |
|
|
98 |
renderer = seriesTypeCollection[i]; |
|
|
99 |
seriesSize += renderer.get("styles").marker[setSizeKey]; |
|
|
100 |
if(order > i) |
|
|
101 |
{ |
|
|
102 |
offset = seriesSize; |
|
|
103 |
} |
|
|
104 |
} |
|
|
105 |
totalSize = len * seriesSize; |
|
|
106 |
if(totalSize > this._maxSize) |
|
|
107 |
{ |
|
|
108 |
ratio = graphic.get(setSizeKey)/totalSize; |
|
|
109 |
seriesSize *= ratio; |
|
|
110 |
offset *= ratio; |
|
|
111 |
setSize *= ratio; |
|
|
112 |
setSize = Math.max(setSize, 1); |
|
|
113 |
this._maxSize = setSize; |
|
|
114 |
} |
|
|
115 |
} |
|
|
116 |
else |
|
|
117 |
{ |
|
|
118 |
seriesSize = style[setSizeKey]; |
|
|
119 |
totalSize = len * seriesSize; |
|
|
120 |
if(totalSize > this._maxSize) |
|
|
121 |
{ |
|
|
122 |
seriesSize = this._maxSize/len; |
|
|
123 |
this._maxSize = seriesSize; |
|
|
124 |
} |
|
|
125 |
} |
|
|
126 |
offset -= seriesSize/2; |
|
|
127 |
for(i = 0; i < len; ++i) |
|
|
128 |
{ |
|
|
129 |
xMarkerPlaneLeft = xcoords[i] - seriesSize/2; |
|
|
130 |
xMarkerPlaneRight = xMarkerPlaneLeft + seriesSize; |
|
|
131 |
yMarkerPlaneTop = ycoords[i] - seriesSize/2; |
|
|
132 |
yMarkerPlaneBottom = yMarkerPlaneTop + seriesSize; |
|
|
133 |
xMarkerPlane.push({start: xMarkerPlaneLeft, end: xMarkerPlaneRight}); |
|
|
134 |
yMarkerPlane.push({start: yMarkerPlaneTop, end: yMarkerPlaneBottom}); |
|
|
135 |
if(!groupMarkers && (isNaN(xcoords[i]) || isNaN(ycoords[i]))) |
|
|
136 |
{ |
|
|
137 |
this._markers.push(null); |
|
|
138 |
continue; |
|
|
139 |
} |
|
|
140 |
config = this._getMarkerDimensions(xcoords[i], ycoords[i], calculatedSize, offset); |
|
|
141 |
if(!isNaN(config.calculatedSize) && config.calculatedSize > 0) |
|
|
142 |
{ |
|
|
143 |
top = config.top; |
|
|
144 |
left = config.left; |
|
|
145 |
|
|
|
146 |
if(groupMarkers) |
|
|
147 |
{ |
|
|
148 |
dimensions[setSizeKey][i] = setSize; |
|
|
149 |
dimensions[calculatedSizeKey][i] = config.calculatedSize; |
|
|
150 |
xvalues.push(left); |
|
|
151 |
yvalues.push(top); |
|
|
152 |
} |
|
|
153 |
else |
|
|
154 |
{ |
|
|
155 |
style[setSizeKey] = setSize; |
|
|
156 |
style[calculatedSizeKey] = config.calculatedSize; |
|
|
157 |
style.x = left; |
|
|
158 |
style.y = top; |
|
|
159 |
if(fillColors) |
|
|
160 |
{ |
|
|
161 |
style.fill.color = fillColors[i % fillColors.length]; |
|
|
162 |
} |
|
|
163 |
if(borderColors) |
|
|
164 |
{ |
|
|
165 |
style.border.color = borderColors[i % borderColors.length]; |
|
|
166 |
} |
|
|
167 |
marker = this.getMarker(style, graphOrder, i); |
|
|
168 |
} |
|
|
169 |
|
|
|
170 |
} |
|
|
171 |
else if(!groupMarkers) |
|
|
172 |
{ |
|
|
173 |
this._markers.push(null); |
|
|
174 |
} |
|
|
175 |
} |
|
|
176 |
this.set("xMarkerPlane", xMarkerPlane); |
|
|
177 |
this.set("yMarkerPlane", yMarkerPlane); |
|
|
178 |
if(groupMarkers) |
|
|
179 |
{ |
|
|
180 |
this._createGroupMarker({ |
|
|
181 |
fill: style.fill, |
|
|
182 |
border: style.border, |
|
|
183 |
dimensions: dimensions, |
|
|
184 |
xvalues: xvalues, |
|
|
185 |
yvalues: yvalues, |
|
|
186 |
shape: style.shape |
|
|
187 |
}); |
|
|
188 |
} |
|
|
189 |
else |
|
|
190 |
{ |
|
|
191 |
this._clearMarkerCache(); |
|
|
192 |
} |
|
|
193 |
}, |
|
|
194 |
|
|
|
195 |
/** |
|
|
196 |
* Collection of default colors used for marker fills in a series when not specified by user. |
|
|
197 |
* |
|
|
198 |
* @property _defaultFillColors |
|
|
199 |
* @type Array |
|
|
200 |
* @protected |
|
|
201 |
*/ |
|
|
202 |
_defaultFillColors: ["#66007f", "#a86f41", "#295454", "#996ab2", "#e8cdb7", "#90bdbd","#000000","#c3b8ca", "#968373", "#678585"], |
|
|
203 |
|
|
|
204 |
/** |
|
|
205 |
* Gets the default style values for the markers. |
|
|
206 |
* |
|
|
207 |
* @method _getPlotDefaults |
|
|
208 |
* @return Object |
|
|
209 |
* @private |
|
|
210 |
*/ |
|
|
211 |
_getPlotDefaults: function() |
|
|
212 |
{ |
|
|
213 |
var defs = { |
|
|
214 |
fill:{ |
|
|
215 |
type: "solid", |
|
|
216 |
alpha: 1, |
|
|
217 |
colors:null, |
|
|
218 |
alphas: null, |
|
|
219 |
ratios: null |
|
|
220 |
}, |
|
|
221 |
border:{ |
|
|
222 |
weight: 0, |
|
|
223 |
alpha: 1 |
|
|
224 |
}, |
|
|
225 |
width: 12, |
|
|
226 |
height: 12, |
|
|
227 |
shape: "rect", |
|
|
228 |
|
|
|
229 |
padding:{ |
|
|
230 |
top: 0, |
|
|
231 |
left: 0, |
|
|
232 |
right: 0, |
|
|
233 |
bottom: 0 |
|
|
234 |
} |
|
|
235 |
}; |
|
|
236 |
defs.fill.color = this._getDefaultColor(this.get("graphOrder"), "fill"); |
|
|
237 |
defs.border.color = this._getDefaultColor(this.get("graphOrder"), "border"); |
|
|
238 |
return defs; |
|
|
239 |
} |
|
|
240 |
}; |
|
|
241 |
|
|
|
242 |
Y.Histogram = Histogram; |
|
|
243 |
|
|
|
244 |
|
|
|
245 |
}, '@VERSION@', {"requires": ["series-cartesian", "series-plot-util"]}); |