Updating getBBox and anchor code to improve performance

This change will reduce the number of calls to this.container.getBBox
when calculating the bounding box of a node
This commit is contained in:
Jeff Avallone
2015-04-16 17:13:12 -04:00
parent 5601c6a398
commit 5917d2b035
8 changed files with 30 additions and 45 deletions
-8
View File
@@ -67,19 +67,11 @@ describe('parser/javascript/charset.js', function() {
cy: 20
});
node.container = jasmine.createSpyObj('container', ['addClass', 'getBBox']);
node.container.getBBox.and.returnValue({
x: 10,
x2: 15
});
spyOn(node, 'transform').and.returnValue({
localMatrix: Snap.matrix().translate(3, 8)
});
expect(node._anchor).toEqual({
ax: 10,
ax2: 15,
ay: 28
});
});
@@ -31,10 +31,12 @@ describe('parser/javascript/match_fragment.js', function() {
this.node = new javascript.Parser('a').__consume__match_fragment();
this.node.content = {
anchor: {
ax: 1,
ax2: 2,
ay: 3
getBBox() {
return {
ax: 1,
ax2: 2,
ay: 3
};
}
};
spyOn(this.node, 'transform').and.returnValue({
+13 -13
View File
@@ -63,18 +63,9 @@ describe('parser/javascript/node.js', function() {
describe('when a proxy node is not used', function() {
it('returns anchor data from the bbox of the container merged _anchor of the node', function() {
it('returns _anchor of the node', function() {
this.node._anchor = { example: 'value' };
this.node.container = jasmine.createSpyObj('container', ['addClass', 'getBBox']);
this.node.container.getBBox.and.returnValue({
x: 'bbox x',
x2: 'bbox x2',
cy: 'bbox cy'
});
expect(this.node.anchor).toEqual({
ax: 'bbox x',
ax2: 'bbox x2',
ay: 'bbox cy',
example: 'value'
});
});
@@ -85,7 +76,7 @@ describe('parser/javascript/node.js', function() {
describe('#getBBox', function() {
it('returns the bbox of the container merged with the anchor', function() {
it('returns the normalized bbox of the container merged with the anchor', function() {
this.node.proxy = {
anchor: {
anchor: 'example anchor'
@@ -93,11 +84,20 @@ describe('parser/javascript/node.js', function() {
};
this.node.container = jasmine.createSpyObj('container', ['addClass', 'getBBox']);
this.node.container.getBBox.and.returnValue({
bbox: 'example bbox'
bbox: 'example bbox',
x: 'left',
x2: 'right',
cy: 'center'
});
expect(this.node.getBBox()).toEqual({
bbox: 'example bbox',
anchor: 'example anchor'
anchor: 'example anchor',
x: 'left',
x2: 'right',
cy: 'center',
ax: 'left',
ax2: 'right',
ay: 'center'
});
});
+6 -4
View File
@@ -36,10 +36,12 @@ describe('parser/javascript/subexp.js', function() {
var node = new javascript.Parser('(test)').__consume__subexp();
node.regexp = {
anchor: {
ax: 10,
ax2: 15,
ay: 20
getBBox() {
return {
ax: 10,
ax2: 15,
ay: 20
};
}
};