Skip to content

Instantly share code, notes, and snippets.

@davidjgraph
Created July 23, 2013 21:30
Show Gist options
  • Save davidjgraph/6066353 to your computer and use it in GitHub Desktop.
Save davidjgraph/6066353 to your computer and use it in GitHub Desktop.
Patch for edge bounds calculation in mxGraph.getBoundingBoxFromGeometry
mxGraph.prototype.getBoundingBoxFromGeometry = function(cells, includeEdges)
{
includeEdges = (includeEdges != null) ? includeEdges : false;
var result = null;
if (cells != null)
{
for (var i = 0; i < cells.length; i++)
{
if (includeEdges || this.model.isVertex(cells[i]))
{
// Computes the bounding box for the points in the geometry
var geo = this.getCellGeometry(cells[i]);
if (geo != null)
{
var pts = geo.points;
if (pts != null && pts.length > 0)
{
var tmp = new mxRectangle(pts[0].x, pts[0].y, 0, 0);
var addPoint = function(pt)
{
if (pt != null)
{
tmp.add(new mxRectangle(pt.x, pt.y, 0, 0));
}
};
for (var j = 1; j < pts.length; j++)
{
addPoint(pts[j]);
}
addPoint(geo.getTerminalPoint(true));
addPoint(geo.getTerminalPoint(false));
geo = tmp;
}
if (result == null)
{
result = new mxRectangle(geo.x, geo.y, geo.width, geo.height);
}
else
{
result.add(geo);
}
}
}
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment