Histogram.js revision 2a322140e93579c14e2037ff2eb3e62eaa86c9df
6643N/A/**
6643N/A * Histogram is the base class for Column and Bar series.
6643N/A *
6643N/A * @module charts
6643N/A * @class Histogram
6643N/A * @constructor
6643N/A */
6643N/Afunction Histogram(){}
6643N/A
6643N/AHistogram.prototype = {
6643N/A /**
6643N/A * Draws the series.
6643N/A *
6643N/A * @method drawSeries
6643N/A * @protected
6643N/A */
6643N/A drawSeries: function()
6643N/A {
6643N/A if(this.get("xcoords").length < 1)
6643N/A {
6643N/A return;
6643N/A }
6643N/A var style = Y.clone(this.get("styles").marker),
6643N/A setSize,
6643N/A calculatedSize,
6643N/A xcoords = this.get("xcoords"),
6643N/A ycoords = this.get("ycoords"),
6643N/A i = 0,
6643N/A len = xcoords.length,
6643N/A top = ycoords[0],
6643N/A type = this.get("type"),
6643N/A graph = this.get("graph"),
6643N/A seriesCollection = graph.seriesTypes[type],
6643N/A seriesLen = seriesCollection.length,
6643N/A seriesSize = 0,
6643N/A totalSize = 0,
6643N/A offset = 0,
6643N/A ratio,
6643N/A renderer,
6643N/A order = this.get("order"),
6643N/A graphOrder = this.get("graphOrder"),
6643N/A left,
6643N/A marker,
6643N/A setSizeKey,
6643N/A calculatedSizeKey,
6643N/A config,
6643N/A fillColors = null,
6643N/A borderColors = null;
6643N/A if(Y_Lang.isArray(style.fill.color))
6643N/A {
6643N/A fillColors = style.fill.color.concat();
6643N/A }
6643N/A if(Y_Lang.isArray(style.border.color))
6643N/A {
6643N/A borderColors = style.border.colors.concat();
6643N/A }
6643N/A if(this.get("direction") == "vertical")
6643N/A {
6643N/A setSizeKey = "height";
calculatedSizeKey = "width";
}
else
{
setSizeKey = "width";
calculatedSizeKey = "height";
}
setSize = style[setSizeKey];
calculatedSize = style[calculatedSizeKey];
this._createMarkerCache();
for(; i < seriesLen; ++i)
{
renderer = seriesCollection[i];
seriesSize += renderer.get("styles").marker[setSizeKey];
if(order > i)
{
offset = seriesSize;
}
}
totalSize = len * seriesSize;
if(totalSize > graph.get(setSizeKey))
{
ratio = graph.get(setSizeKey)/totalSize;
seriesSize *= ratio;
offset *= ratio;
setSize *= ratio;
setSize = Math.max(setSize, 1);
}
offset -= seriesSize/2;
for(i = 0; i < len; ++i)
{
if(isNaN(xcoords[i]) || isNaN(ycoords[i]))
{
this._markers.push(null);
continue;
}
config = this._getMarkerDimensions(xcoords[i], ycoords[i], calculatedSize, offset);
if(!isNaN(config.calculatedSize) && config.calculatedSize > 0)
{
top = config.top;
left = config.left;
style[setSizeKey] = setSize;
style[calculatedSizeKey] = config.calculatedSize;
style.x = left;
style.y = top;
if(fillColors)
{
style.fill.color = fillColors[i % fillColors.length];
}
if(borderColors)
{
style.border.colors = borderColors[i % borderColors.length];
}
marker = this.getMarker(style, graphOrder, i);
}
else
{
this._markers.push(null);
}
}
this._clearMarkerCache();
},
/**
* Collection of default colors used for marker fills in a series when not specified by user.
*
* @property _defaultFillColors
* @type Array
* @protected
*/
_defaultFillColors: ["#66007f", "#a86f41", "#295454", "#996ab2", "#e8cdb7", "#90bdbd","#000000","#c3b8ca", "#968373", "#678585"],
/**
* Gets the default style values for the markers.
*
* @method _getPlotDefaults
* @return Object
* @private
*/
_getPlotDefaults: function()
{
var defs = {
fill:{
type: "solid",
alpha: 1,
colors:null,
alphas: null,
ratios: null
},
border:{
weight: 0,
alpha: 1
},
width: 12,
height: 12,
shape: "rect",
padding:{
top: 0,
left: 0,
right: 0,
bottom: 0
}
};
defs.fill.color = this._getDefaultColor(this.get("graphOrder"), "fill");
defs.border.color = this._getDefaultColor(this.get("graphOrder"), "border");
return defs;
}
};
Y.Histogram = Histogram;