Skip to content

Instantly share code, notes, and snippets.

@tripp
Created May 16, 2012 18:02
Show Gist options
  • Select an option

  • Save tripp/2712659 to your computer and use it in GitHub Desktop.

Select an option

Save tripp/2712659 to your computer and use it in GitHub Desktop.
chartsbug2532327Patch.js
var setAreaData = function()
{
var isNumber = Y.Lang.isNumber,
nextX, nextY,
graph = this.get("graph"),
w = graph.get("width"),
h = graph.get("height"),
xAxis = this.get("xAxis"),
yAxis = this.get("yAxis"),
xData = this.get("xData").concat(),
yData = this.get("yData").concat(),
xValue,
yValue,
xOffset = xAxis.getEdgeOffset(xData.length, w),
yOffset = yAxis.getEdgeOffset(yData.length, h),
padding = this.get("styles").padding,
leftPadding = padding.left,
topPadding = padding.top,
dataWidth = w - (leftPadding + padding.right + xOffset),
dataHeight = h - (topPadding + padding.bottom + yOffset),
xcoords = [],
ycoords = [],
xMax = xAxis.get("maximum"),
xMin = xAxis.get("minimum"),
yMax = yAxis.get("maximum"),
yMin = yAxis.get("minimum"),
xScaleFactor = dataWidth / (xMax - xMin),
yScaleFactor = dataHeight / (yMax - yMin),
dataLength,
direction = this.get("direction"),
i = 0,
xMarkerPlane = [],
yMarkerPlane = [],
xMarkerPlaneOffset = this.get("xMarkerPlaneOffset"),
yMarkerPlaneOffset = this.get("yMarkerPlaneOffset"),
graphic = this.get("graphic");
graphic.set("width", w);
graphic.set("height", h);
dataLength = xData.length;
xOffset *= 0.5;
yOffset *= 0.5;
//Assuming a vertical graph has a range/category for its vertical axis.
if(direction === "vertical")
{
yData = yData.reverse();
}
this._leftOrigin = Math.round(((0 - xMin) * xScaleFactor) + leftPadding + xOffset);
this._bottomOrigin = Math.round((dataHeight + topPadding + yOffset));
if(yMin < 0)
{
this._bottomOrigin = this._bottomOrigin - ((0 - yMin) * yScaleFactor);
}
for (; i < dataLength; ++i)
{
xValue = parseFloat(xData[i]);
yValue = parseFloat(yData[i]);
if(isNumber(xValue))
{
nextX = (((xValue - xMin) * xScaleFactor) + leftPadding + xOffset);
}
else
{
nextX = NaN;
}
if(isNumber(yValue))
{
nextY = ((dataHeight + topPadding + yOffset) - (yValue - yMin) * yScaleFactor);
}
else
{
nextY = NaN;
}
xcoords.push(nextX);
ycoords.push(nextY);
xMarkerPlane.push({start:nextX - xMarkerPlaneOffset, end: nextX + xMarkerPlaneOffset});
yMarkerPlane.push({start:nextY - yMarkerPlaneOffset, end: nextY + yMarkerPlaneOffset});
}
this.set("xcoords", xcoords);
this.set("ycoords", ycoords);
this.set("xMarkerPlane", xMarkerPlane);
this.set("yMarkerPlane", yMarkerPlane);
this._dataLength = dataLength;
};
Y.ColumnSeries.prototype.setAreaData = setAreaData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment