2014-11-30 19:10:27 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
|
|
|
export default _.extend({}, Base, {
|
2014-11-30 22:54:12 +00:00
|
|
|
render(container) {
|
2014-12-01 02:20:03 +00:00
|
|
|
this.container = container;
|
2014-11-30 22:54:12 +00:00
|
|
|
this.contents = _.map(this.matches(), match => {
|
|
|
|
var content = container.group();
|
|
|
|
match.render(content);
|
|
|
|
return content;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
position() {
|
|
|
|
var center,
|
2014-12-01 02:20:03 +00:00
|
|
|
positions,
|
|
|
|
container = this.container,
|
|
|
|
totalHeight,
|
|
|
|
verticalCenter;
|
2014-11-30 22:54:12 +00:00
|
|
|
|
|
|
|
_.invoke(this.matches(), 'position');
|
|
|
|
|
|
|
|
positions = _.chain(this.contents)
|
|
|
|
.map(content => {
|
|
|
|
return { box: content.getBBox(), content };
|
|
|
|
});
|
|
|
|
center = positions.reduce((center, pos) => {
|
|
|
|
return Math.max(center, pos.box.cx);
|
|
|
|
}, 0).value();
|
|
|
|
|
2014-12-01 02:20:03 +00:00
|
|
|
totalHeight = positions.reduce((offset, pos) => {
|
2014-11-30 22:54:12 +00:00
|
|
|
pos.content.transform(Snap.matrix()
|
2014-12-01 02:20:03 +00:00
|
|
|
.translate(center - pos.box.cx + 20, offset));
|
2014-11-30 22:54:12 +00:00
|
|
|
|
|
|
|
return offset + pos.box.height + 5;
|
2014-12-01 02:20:03 +00:00
|
|
|
}, 0).value() - 5;
|
|
|
|
|
|
|
|
verticalCenter = totalHeight / 2
|
|
|
|
|
|
|
|
positions.each(pos => {
|
|
|
|
var box = pos.content.getBBox(),
|
|
|
|
direction = box.cy > verticalCenter ? 1 : -1,
|
|
|
|
pathStr,
|
|
|
|
path;
|
|
|
|
|
|
|
|
pathStr = (verticalCenter === box.cy) ?
|
|
|
|
'M0,{center}H{side}' :
|
|
|
|
'M0,{center}q10,0 10,{d}V{target}q0,{d} 10,{d}H{side}';
|
|
|
|
|
|
|
|
path = container.path(Snap.format(pathStr, {
|
|
|
|
center: verticalCenter,
|
|
|
|
target: box.cy - 10 * direction,
|
|
|
|
side: box.x,
|
|
|
|
d: 10 * direction
|
|
|
|
}));
|
|
|
|
|
|
|
|
path.clone().transform(Snap.matrix()
|
|
|
|
.scale(-1, 1, center + 20, 0));
|
|
|
|
});
|
2014-11-30 22:54:12 +00:00
|
|
|
},
|
|
|
|
|
2014-11-26 23:24:40 +00:00
|
|
|
matches() {
|
2014-12-03 00:59:10 +00:00
|
|
|
return [this._match].concat(_.map(this._alternates.elements, _.property('match')));
|
2014-11-26 23:24:40 +00:00
|
|
|
}
|
2014-11-30 19:10:27 +00:00
|
|
|
});
|