Updating major positioning code to use anchor position

This commit is contained in:
Jeff Avallone 2014-12-14 17:56:33 -05:00
parent 56927dd7fa
commit 9ba2b8579e
2 changed files with 24 additions and 12 deletions

View File

@ -30,6 +30,15 @@ export default {
return _.extend(this.container.getBBox(), this.getAnchor()); return _.extend(this.container.getBBox(), this.getAnchor());
}, },
normalizeBBox(box) {
return _.extend({
atype: 'normalize',
ax: box.x,
ax2: box.x2,
ay: box.cy
}, box);
},
transform(matrix) { transform(matrix) {
return this.container.transform(matrix); return this.container.transform(matrix);
}, },
@ -94,6 +103,7 @@ export default {
proxy(node) { proxy(node) {
this.anchorDebug = false; this.anchorDebug = false;
this._proxy = node;
return node.render(this.container); return node.render(this.container);
}, },
@ -111,7 +121,8 @@ export default {
}, },
spaceHorizontally(items, options) { spaceHorizontally(items, options) {
var verticalCenter = 0; var verticalCenter = 0,
normalize = this.normalizeBBox;
_.defaults(options, { _.defaults(options, {
padding: 0 padding: 0
@ -123,17 +134,18 @@ export default {
item.transform(Snap.matrix() item.transform(Snap.matrix()
.translate(offset, 0)); .translate(offset, 0));
box = item.getBBox(); box = normalize(item.getBBox());
verticalCenter = Math.max(verticalCenter, box.ay);
verticalCenter = Math.max(verticalCenter, box.cy);
return offset + options.padding + box.width; return offset + options.padding + box.width;
}, 0); }, 0);
_.each(items, item => { _.each(items, item => {
var box = normalize(item.getBBox());
item.transform(Snap.matrix() item.transform(Snap.matrix()
.add(item.transform().localMatrix) .add(item.transform().localMatrix)
.translate(0, verticalCenter - item.getBBox().cy)); .translate(0, verticalCenter - box.ay));
}); });
}, },

View File

@ -38,8 +38,8 @@ export default _.extend({}, Base, {
'M{box.width},{box.cy}m40,0q-10,0 -10,10V{bottom}' 'M{box.width},{box.cy}m40,0q-10,0 -10,10V{bottom}'
].join(''), { ].join(''), {
box: containerBox, box: containerBox,
top: _.first(matches).getBBox().cy + 10, top: _.first(matches).getBBox().ay + 10,
bottom: _.last(matches).getBBox().cy - 10 bottom: _.last(matches).getBBox().ay - 10
})); }));
this.container.prepend( this.container.prepend(
@ -50,14 +50,14 @@ export default _.extend({}, Base, {
makeConnectorLine(containerBox, match) { makeConnectorLine(containerBox, match) {
var box = match.getBBox(), var box = match.getBBox(),
direction = box.cy > containerBox.cy ? 1 : -1, direction = box.ay > containerBox.cy ? 1 : -1,
distance = Math.abs(box.cy - containerBox.cy), distance = Math.abs(box.ay - containerBox.cy),
pathStr; pathStr;
if (distance >= 15) { if (distance >= 15) {
pathStr = [ pathStr = [
'M10,{box.cy}m0,{shift}q0,{curve} 10,{curve}', 'M10,{box.ay}m0,{shift}q0,{curve} 10,{curve}',
'M{containerBox.width},{box.cy}m30,{shift}q0,{curve} -10,{curve}' 'M{containerBox.width},{box.ay}m30,{shift}q0,{curve} -10,{curve}'
].join(''); ].join('');
} else { } else {
pathStr = [ pathStr = [
@ -73,7 +73,7 @@ export default _.extend({}, Base, {
curve: 10 * direction, curve: 10 * direction,
anchor: { anchor: {
x: box.x + 20, x: box.x + 20,
y: box.cy - containerBox.cy y: box.ay - containerBox.cy
} }
}); });
}, },