2014-11-30 19:10:27 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
|
|
|
export default _.extend({}, Base, {
|
2014-12-03 01:10:56 +00:00
|
|
|
type: 'regexp',
|
|
|
|
|
2014-12-03 23:59:59 +00:00
|
|
|
render() {
|
|
|
|
var self = this;
|
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
this.matchContainer = this.container.group();
|
|
|
|
|
2014-12-03 23:59:59 +00:00
|
|
|
_.each(this.matches(), match => {
|
2014-12-10 01:08:34 +00:00
|
|
|
match.container = self.matchContainer.group();
|
2014-12-03 23:59:59 +00:00
|
|
|
match.render();
|
|
|
|
return match.container;
|
2014-11-30 22:54:12 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
position() {
|
2014-12-10 01:08:34 +00:00
|
|
|
var matches = this.matches(),
|
2014-12-04 01:35:26 +00:00
|
|
|
includeLines = (matches.length > 1),
|
2014-12-10 01:08:34 +00:00
|
|
|
containerBox,
|
|
|
|
paths;
|
2014-11-30 22:54:12 +00:00
|
|
|
|
2014-12-03 23:59:59 +00:00
|
|
|
_.invoke(matches, 'position');
|
2014-11-30 22:54:12 +00:00
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
this.spaceVertically(matches, {
|
|
|
|
padding: 5
|
|
|
|
});
|
2014-12-01 02:20:03 +00:00
|
|
|
|
2014-12-03 23:46:48 +00:00
|
|
|
if (includeLines) {
|
2014-12-10 01:08:34 +00:00
|
|
|
this.matchContainer.transform(Snap.matrix()
|
|
|
|
.translate(20, 0));
|
|
|
|
|
|
|
|
containerBox = this.getBBox();
|
|
|
|
paths = _.map(matches, match => {
|
|
|
|
var box = match.getBBox(),
|
|
|
|
direction = box.cy > containerBox.cy ? 1 : -1,
|
|
|
|
distance = Math.abs(box.cy - containerBox.cy),
|
2014-12-04 01:35:26 +00:00
|
|
|
pathStr;
|
2014-12-01 02:20:03 +00:00
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
if (distance >= 15) {
|
|
|
|
pathStr = 'M10,{box.cy}m0,{shift}q0,{curve} 10,{curve}h{box.x}';
|
|
|
|
} else {
|
|
|
|
pathStr = 'M0,{containerBox.cy}c20,0 20,{anchor.y} {anchor.x},{anchor.y}';
|
|
|
|
}
|
2014-12-01 02:20:03 +00:00
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
return Snap.format(pathStr, {
|
|
|
|
containerBox,
|
|
|
|
box,
|
|
|
|
shift: -10 * direction,
|
|
|
|
curve: 10 * direction,
|
|
|
|
anchor: {
|
|
|
|
x: box.x + 20,
|
|
|
|
y: box.cy - containerBox.cy
|
|
|
|
}
|
|
|
|
});
|
2014-12-04 01:35:26 +00:00
|
|
|
});
|
2014-12-01 02:20:03 +00:00
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
paths.push(Snap.format('M0,{box.cy}q10,0 10,-10V{top}M0,{box.cy}q10,0 10,10V{bottom}', {
|
|
|
|
box: containerBox,
|
|
|
|
top: _.first(matches).getBBox().cy + 10,
|
|
|
|
bottom: _.last(matches).getBBox().cy - 10
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.container.prepend(this.container.path(paths.join('')));
|
|
|
|
this.container.prepend(this.container.path(paths.join(''))
|
|
|
|
.transform(Snap.matrix().scale(-1, 1, containerBox.cx, 0)));
|
2014-12-03 23:46:48 +00:00
|
|
|
}
|
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
|
|
|
});
|