Histogram.js revision e67957db0543602abfe8be8cfc6ed03526db938c
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney/**
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney * Histogram is the base class for Column and Bar series.
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney *
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney * @module charts
70713f265d1fe28afa8033e336d69163f93dde32Matt Sweeney * @class Histogram
70713f265d1fe28afa8033e336d69163f93dde32Matt Sweeney * @constructor
70713f265d1fe28afa8033e336d69163f93dde32Matt Sweeney */
70713f265d1fe28afa8033e336d69163f93dde32Matt Sweeneyfunction Histogram(){}
70713f265d1fe28afa8033e336d69163f93dde32Matt Sweeney
70713f265d1fe28afa8033e336d69163f93dde32Matt SweeneyHistogram.prototype = {
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney /**
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney * Draws the series.
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney *
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney * @method drawSeries
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney * @protected
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney */
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney drawSeries: function()
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney {
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney if(this.get("xcoords").length < 1)
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney {
53c29b5c2e45418277bf03d6fc5dd81882abcff8Matt Sweeney return;
}
var style = Y.clone(this.get("styles").marker),
setSize,
calculatedSize,
xcoords = this.get("xcoords"),
ycoords = this.get("ycoords"),
i = 0,
len = xcoords.length,
top = ycoords[0],
type = this.get("type"),
graph = this.get("graph"),
seriesCollection = graph.seriesTypes[type],
seriesLen = seriesCollection.length,
seriesSize = 0,
totalSize = 0,
offset = 0,
ratio,
renderer,
order = this.get("order"),
graphOrder = this.get("graphOrder"),
left,
marker,
setSizeKey,
calculatedSizeKey,
config,
fillColors = null,
borderColors = null;
if(Y_Lang.isArray(style.fill.color))
{
fillColors = style.fill.color.concat();
}
if(Y_Lang.isArray(style.border.color))
{
borderColors = style.border.colors.concat();
}
if(this.get("direction") == "vertical")
{
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;
this._maxSize = graph.get(setSizeKey);
if(totalSize > this._maxSize)
{
ratio = graph.get(setSizeKey)/totalSize;
seriesSize *= ratio;
offset *= ratio;
setSize *= ratio;
setSize = Math.max(setSize, 1);
this._maxSize = setSize;
}
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;