Skip to content

Instantly share code, notes, and snippets.

@PatrickKing
Created July 27, 2014 00:33
Show Gist options
  • Save PatrickKing/dc242b7760282041d0e8 to your computer and use it in GitHub Desktop.
Save PatrickKing/dc242b7760282041d0e8 to your computer and use it in GitHub Desktop.
A patch to Raphael to fix handling of empty sets within a set.
Raphael.st.getBBox = function () {
var x = [],
y = [],
x2 = [],
y2 = [];
for (var i = this.items.length; i--;) if (!this.items[i].removed) {
var box = this.items[i].getBBox();
// For lack of a better return value, empty sets return 'infinite' bounding boxes
// But we shouldn't contaminate their parent bounds with this
// If we come across an empty set, don't include it in the current set's bounds calculation
if (box.x === Infinity &&
box.y === Infinity &&
box.x2 === -Infinity &&
box.y2 === -Infinity &&
box.width === -Infinity &&
box.height === -Infinity) {
continue;
}
x.push(box.x);
y.push(box.y);
x2.push(box.x + box.width);
y2.push(box.y + box.height);
}
x = Math.min["apply"](0, x);
y = Math.min["apply"](0, y);
x2 = Math.max["apply"](0, x2);
y2 = Math.max["apply"](0, y2);
return {
x: x,
y: y,
x2: x2,
y2: y2,
width: x2 - x,
height: y2 - y
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment