Moving spaceHorizontally and spaceVertically to util.js

This commit is contained in:
Jeff Avallone
2014-12-19 12:11:44 -05:00
parent 870b2e6ed4
commit a50ba68a21
8 changed files with 122 additions and 119 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
import { spaceVertically } from '../../util.js';
import _ from 'lodash';
import Q from 'q';
export default {
@@ -25,7 +26,7 @@ export default {
return part.render(this.partContainer.group());
}))
.then(() => {
this.spaceVertically(this.elements, {
spaceVertically(this.elements, {
padding: 5
});
+2 -1
View File
@@ -1,3 +1,4 @@
import { spaceHorizontally } from '../../util.js';
import _ from 'lodash';
import Q from 'q';
@@ -16,7 +17,7 @@ export default {
this.first.render(this.container.group()),
this.last.render(this.container.group())
])
.then(this.spaceHorizontally.bind(this, contents, {
.then(spaceHorizontally.bind(this, contents, {
padding: 5
}));
},
+2 -2
View File
@@ -1,4 +1,4 @@
import { normalizeBBox } from '../../util.js';
import { normalizeBBox, spaceHorizontally } from '../../util.js';
import _ from 'lodash';
import Q from 'q';
@@ -44,7 +44,7 @@ export default {
var prev, next, paths;
this.items = items;
this.spaceHorizontally(items, {
spaceHorizontally(items, {
padding: 10
});
-55
View File
@@ -129,61 +129,6 @@ export default class Node {
}
}
spaceHorizontally(items, options) {
var verticalCenter = 0;
options = _.defaults(options || {}, {
padding: 0
});
_.reduce(items, (offset, item) => {
var box;
item.transform(Snap.matrix()
.translate(offset, 0));
box = normalizeBBox(item.getBBox());
verticalCenter = Math.max(verticalCenter, box.ay);
return offset + options.padding + box.width;
}, 0);
for (var item of items) {
let box = normalizeBBox(item.getBBox());
item.transform(Snap.matrix()
.add(item.transform().localMatrix)
.translate(0, verticalCenter - box.ay));
}
}
spaceVertically(items, options) {
var horizontalCenter = 0;
options = _.defaults(options || {}, {
padding: 0
});
_.reduce(items, (offset, item) => {
var box;
item.transform(Snap.matrix()
.translate(0, offset));
box = item.getBBox();
horizontalCenter = Math.max(horizontalCenter, box.cx);
return offset + options.padding + box.height;
}, 0);
for (var item of items) {
item.transform(Snap.matrix()
.add(item.transform().localMatrix)
.translate(horizontalCenter - item.getBBox().cx, 0));
}
}
renderLabeledBox(label, content, options) {
var label = this.container.text(0, 0, label)
.addClass([this.type, 'label'].join('-')),
+2 -1
View File
@@ -1,3 +1,4 @@
import { spaceVertically } from '../../util.js';
import _ from 'lodash';
import Q from 'q';
@@ -19,7 +20,7 @@ export default {
var containerBox,
paths;
this.spaceVertically(this.matches, {
spaceVertically(this.matches, {
padding: 5
});
+55
View File
@@ -15,3 +15,58 @@ export function normalizeBBox(box) {
ay: box.cy
}, box);
}
export function spaceHorizontally(items, options) {
var verticalCenter = 0;
options = _.defaults(options || {}, {
padding: 0
});
_.reduce(items, (offset, item) => {
var box;
item.transform(Snap.matrix()
.translate(offset, 0));
box = normalizeBBox(item.getBBox());
verticalCenter = Math.max(verticalCenter, box.ay);
return offset + options.padding + box.width;
}, 0);
for (var item of items) {
let box = normalizeBBox(item.getBBox());
item.transform(Snap.matrix()
.add(item.transform().localMatrix)
.translate(0, verticalCenter - box.ay));
}
}
export function spaceVertically(items, options) {
var horizontalCenter = 0;
options = _.defaults(options || {}, {
padding: 0
});
_.reduce(items, (offset, item) => {
var box;
item.transform(Snap.matrix()
.translate(0, offset));
box = item.getBBox();
horizontalCenter = Math.max(horizontalCenter, box.cx);
return offset + options.padding + box.height;
}, 0);
for (var item of items) {
item.transform(Snap.matrix()
.add(item.transform().localMatrix)
.translate(horizontalCenter - item.getBBox().cx, 0));
}
}