Converting getAnchor into a property

This commit is contained in:
Jeff Avallone 2014-12-17 15:24:27 -05:00
parent 155ad51d58
commit f93388dec0
5 changed files with 68 additions and 62 deletions

View File

@ -20,18 +20,6 @@ export default {
});
},
_getAnchor() {
var box = this.container.getBBox(),
matrix = this.transform().localMatrix;
return {
atype: this.type,
ax: box.x,
ax2: box.x2,
ay: matrix.y(0, this.partContainer.getBBox().cy)
};
},
setup() {
this.invert = this.properties.invert !== '';
this.elements = _.unique(this.properties.parts.elements, part => {
@ -41,5 +29,19 @@ export default {
return part.textValue;
}
});
Object.defineProperty(this, '_anchor', {
get: function() {
var box = this.container.getBBox(),
matrix = this.transform().localMatrix;
return {
atype: this.type,
ax: box.x,
ax2: box.x2,
ay: matrix.y(0, this.partContainer.getBBox().cy)
};
}
});
}
};

View File

@ -47,19 +47,6 @@ export default {
});
},
_getAnchor() {
var start = this.normalizeBBox(_.first(this.items).getBBox()),
end = this.normalizeBBox(_.last(this.items).getBBox()),
matrix = this.transform().localMatrix;
return {
atype: [start.atype, end.atype].join('/'),
ax: matrix.x(start.ax, start.ay),
ax2: matrix.x(end.ax2, end.ay),
ay: matrix.y(start.ax, start.ay)
};
},
setup() {
this.parts = _.reduce(this.properties.parts.elements, function(result, node) {
var last = _.last(result);
@ -79,5 +66,20 @@ export default {
if (!this.anchorStart && !this.anchorEnd && this.parts.length === 1) {
this.proxy = this.parts[0];
}
Object.defineProperty(this, '_anchor', {
get: function() {
var start = this.normalizeBBox(_.first(this.items).getBBox()),
end = this.normalizeBBox(_.last(this.items).getBBox()),
matrix = this.transform().localMatrix;
return {
atype: [start.atype, end.atype].join('/'),
ax: matrix.x(start.ax, start.ay),
ax2: matrix.x(end.ax2, end.ay),
ay: matrix.y(start.ax, start.ay)
};
}
});
}
};

View File

@ -55,17 +55,6 @@ export default {
});
},
_getAnchor() {
var anchor = this.content.getAnchor(),
matrix = this.transform().localMatrix;
return _.extend(anchor, {
ax: matrix.x(anchor.ax, anchor.ay),
ax2: matrix.x(anchor.ax2, anchor.ay),
ay: matrix.y(anchor.ax, anchor.ay)
});
},
setup() {
this.content = this.properties.content;
this.canMerge = (this.elements[0].type === 'literal' && this.elements[1].textValue === '');
@ -75,5 +64,18 @@ export default {
} else {
this.proxy = this.content;
}
Object.defineProperty(this, '_anchor', {
get: function() {
var anchor = this.content.anchor,
matrix = this.transform().localMatrix;
return _.extend(anchor, {
ax: matrix.x(anchor.ax, anchor.ay),
ax2: matrix.x(anchor.ax2, anchor.ay),
ay: matrix.y(anchor.ax, anchor.ay)
});
}
});
}
};

View File

@ -29,27 +29,25 @@ export default class Node {
return this._container;
}
getAnchor() {
get anchor() {
var box;
if (this.proxy) {
return this.proxy.getAnchor();
return this.proxy.anchor;
} else {
return this._getAnchor();
box = this.container.getBBox();
return _.extend({
atype: this.type,
ax: box.x,
ax2: box.x2,
ay: box.cy
}, this._anchor || {});
}
}
_getAnchor() {
var box = this.container.getBBox();
return {
atype: this.type,
ax: box.x,
ax2: box.x2,
ay: box.cy
};
}
getBBox() {
return _.extend(this.container.getBBox(), this.getAnchor());
return _.extend(this.container.getBBox(), this.anchor);
}
normalizeBBox(box) {

View File

@ -22,17 +22,6 @@ export default {
groupCounter = 1;
},
_getAnchor() {
var anchor = this.regexp.getAnchor(),
matrix = this.transform().localMatrix;
return _.extend(anchor, {
ax: matrix.x(anchor.ax, anchor.ay),
ax2: matrix.x(anchor.ax2, anchor.ay),
ay: matrix.y(anchor.ax, anchor.ay)
});
},
setup() {
if (_.has(this.labelMap, this.properties.capture.textValue)) {
this.label = this.labelMap[this.properties.capture.textValue];
@ -45,5 +34,18 @@ export default {
if (!this.label) {
this.proxy = this.regexp;
}
Object.defineProperty(this, '_anchor', {
get: function() {
var anchor = this.regexp.anchor,
matrix = this.transform().localMatrix;
return _.extend(anchor, {
ax: matrix.x(anchor.ax, anchor.ay),
ax2: matrix.x(anchor.ax2, anchor.ay),
ay: matrix.y(anchor.ax, anchor.ay)
});
}
});
}
};