Moving spaceHorizontally and spaceVertically to util.js
This commit is contained in:
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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('-')),
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user