Moving normalizeBBox to util.js

This commit is contained in:
Jeff Avallone 2014-12-19 12:06:21 -05:00
parent abb5838113
commit 870b2e6ed4
5 changed files with 40 additions and 36 deletions

View File

@ -104,26 +104,6 @@ describe('parser/javascript/node.js', function() {
});
describe('#normalizeBBox', function() {
it('defaults the anchor keys to values from the bbox', function() {
expect(this.node.normalizeBBox({
x: 'bbox x',
x2: 'bbox x2',
cy: 'bbox cy',
ay: 'bbox ay'
})).toEqual({
x: 'bbox x',
x2: 'bbox x2',
cy: 'bbox cy',
ax: 'bbox x',
ax2: 'bbox x2',
ay: 'bbox ay'
});
});
});
describe('#transform', function() {
it('returns the result of calling transform on the container', function() {

View File

@ -1,4 +1,4 @@
import { customEvent } from 'src/js/util.js';
import { customEvent, normalizeBBox } from 'src/js/util.js';
describe('util.js', function() {
@ -16,4 +16,24 @@ describe('util.js', function() {
});
describe('normalizeBBox', function() {
it('defaults the anchor keys to values from the bbox', function() {
expect(normalizeBBox({
x: 'bbox x',
x2: 'bbox x2',
cy: 'bbox cy',
ay: 'bbox ay'
})).toEqual({
x: 'bbox x',
x2: 'bbox x2',
cy: 'bbox cy',
ax: 'bbox x',
ax2: 'bbox x2',
ay: 'bbox ay'
});
});
});
});

View File

@ -1,3 +1,4 @@
import { normalizeBBox } from '../../util.js';
import _ from 'lodash';
import Q from 'q';
@ -7,8 +8,8 @@ export default {
definedProperties: {
_anchor: {
get: function() {
var start = this.normalizeBBox(_.first(this.items).getBBox()),
end = this.normalizeBBox(_.last(this.items).getBBox()),
var start = normalizeBBox(_.first(this.items).getBBox()),
end = normalizeBBox(_.last(this.items).getBBox()),
matrix = this.transform().localMatrix;
return {
@ -47,11 +48,11 @@ export default {
padding: 10
});
prev = this.normalizeBBox(_.first(items).getBBox());
prev = normalizeBBox(_.first(items).getBBox());
paths = _.map(items.slice(1), item => {
var path;
next = this.normalizeBBox(item.getBBox());
next = normalizeBBox(item.getBBox());
path = `M${prev.ax2},${prev.ay}H${next.ax}`;
prev = next;

View File

@ -1,4 +1,4 @@
import { customEvent } from '../../util.js';
import { customEvent, normalizeBBox } from '../../util.js';
import _ from 'lodash';
import Q from 'q';
@ -54,14 +54,6 @@ export default class Node {
return _.extend(this.container.getBBox(), this.anchor);
}
normalizeBBox(box) {
return _.extend({
ax: box.x,
ax2: box.x2,
ay: box.cy
}, box);
}
transform(matrix) {
return this.container.transform(matrix);
}
@ -150,14 +142,14 @@ export default class Node {
item.transform(Snap.matrix()
.translate(offset, 0));
box = this.normalizeBBox(item.getBBox());
box = normalizeBBox(item.getBBox());
verticalCenter = Math.max(verticalCenter, box.ay);
return offset + options.padding + box.width;
}, 0);
for (var item of items) {
let box = this.normalizeBBox(item.getBBox());
let box = normalizeBBox(item.getBBox());
item.transform(Snap.matrix()
.add(item.transform().localMatrix)

View File

@ -1,6 +1,17 @@
import _ from 'lodash';
export function customEvent(name, detail) {
var evt = document.createEvent('Event');
evt.initEvent(name, true, true);
evt.detail = detail;
return evt;
}
export function normalizeBBox(box) {
return _.extend({
ax: box.x,
ax2: box.x2,
ay: box.cy
}, box);
}