Skip to content

Instantly share code, notes, and snippets.

@tripp
Created December 9, 2013 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripp/7876703 to your computer and use it in GitHub Desktop.
Save tripp/7876703 to your computer and use it in GitHub Desktop.
yuichartsissue1475.js
var histogramDrawSeries = function() {
if(this.get("xcoords").length < 1)
{
return;
}
var style = this._copyObject(this.get("styles").marker),
graphic = this.get("graphic"),
setSize,
calculatedSize,
xcoords = this.get("xcoords"),
ycoords = this.get("ycoords"),
i = 0,
len = xcoords.length,
top = ycoords[0],
seriesTypeCollection = this.get("seriesTypeCollection"),
seriesLen = seriesTypeCollection ? seriesTypeCollection.length : 0,
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,
xMarkerPlane = [],
yMarkerPlane = [],
xMarkerPlaneLeft,
xMarkerPlaneRight,
yMarkerPlaneTop,
yMarkerPlaneBottom,
dimensions = {
width: [],
height: []
},
xvalues = [],
yvalues = [],
groupMarkers = this.get("groupMarkers");
if(Y.Lang.isArray(style.fill.color))
{
fillColors = style.fill.color.concat();
}
if(Y.Lang.isArray(style.border.color))
{
borderColors = style.border.color.concat();
}
if(this.get("direction") === "vertical")
{
setSizeKey = "height";
calculatedSizeKey = "width";
}
else
{
setSizeKey = "width";
calculatedSizeKey = "height";
}
setSize = style[setSizeKey];
calculatedSize = style[calculatedSizeKey];
this._createMarkerCache();
if(seriesTypeCollection && seriesLen > 1)
{
for(; i < seriesLen; ++i)
{
renderer = seriesTypeCollection[i];
seriesSize += renderer.get("styles").marker[setSizeKey];
if(order > i)
{
offset = seriesSize;
}
}
totalSize = len * seriesSize;
this._maxSize = graphic.get(setSizeKey);
if(totalSize > this._maxSize)
{
ratio = graphic.get(setSizeKey)/totalSize;
seriesSize *= ratio;
offset *= ratio;
setSize *= ratio;
setSize = Math.max(setSize, 1);
this._maxSize = setSize;
}
}
else
{
seriesSize = style[setSizeKey];
this._maxSize = graphic.get(setSizeKey)/len;
}
offset -= seriesSize/2;
for(i = 0; i < len; ++i)
{
xMarkerPlaneLeft = xcoords[i] - seriesSize/2;
xMarkerPlaneRight = xMarkerPlaneLeft + seriesSize;
yMarkerPlaneTop = ycoords[i] - seriesSize/2;
yMarkerPlaneBottom = yMarkerPlaneTop + seriesSize;
xMarkerPlane.push({start: xMarkerPlaneLeft, end: xMarkerPlaneRight});
yMarkerPlane.push({start: yMarkerPlaneTop, end: yMarkerPlaneBottom});
if(!groupMarkers && (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;
if(groupMarkers)
{
dimensions[setSizeKey][i] = setSize;
dimensions[calculatedSizeKey][i] = config.calculatedSize;
xvalues.push(left);
yvalues.push(top);
}
else
{
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.color = borderColors[i % borderColors.length];
}
marker = this.getMarker(style, graphOrder, i);
}
}
else if(!groupMarkers)
{
this._markers.push(null);
}
}
this.set("xMarkerPlane", xMarkerPlane);
this.set("yMarkerPlane", yMarkerPlane);
if(groupMarkers)
{
this._createGroupMarker({
fill: style.fill,
border: style.border,
dimensions: dimensions,
xvalues: xvalues,
yvalues: yvalues,
shape: style.shape
});
}
else
{
this._clearMarkerCache();
}
};
Y.ColumnSeries.prototype.drawSeries = histogramDrawSeries;
Y.BarSeries.prototype.drawSeries = histogramDrawSeries;
@tripp
Copy link
Author

tripp commented Dec 9, 2013

Place this in application inside before the chart's instantiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment