Adding tests for Regexp nodes
This commit is contained in:
@@ -6,9 +6,7 @@ export default {
|
||||
type: 'regexp',
|
||||
|
||||
_render() {
|
||||
var matchContainer;
|
||||
|
||||
matchContainer = this.container.group()
|
||||
var matchContainer = this.container.group()
|
||||
.addClass('regexp-matches')
|
||||
.transform(Snap.matrix()
|
||||
.translate(20, 0));
|
||||
@@ -25,72 +23,75 @@ export default {
|
||||
});
|
||||
|
||||
containerBox = this.getBBox();
|
||||
paths = _.map(this.matches, this.makeConnectorLine.bind(this, containerBox));
|
||||
paths = _.map(this.matches, match => {
|
||||
return this.makeCurve(containerBox, match)
|
||||
});
|
||||
|
||||
paths.push(this.makeSideLine(containerBox, _.first(this.matches)));
|
||||
paths.push(this.makeSideLine(containerBox, _.last(this.matches)));
|
||||
paths.push(this.makeSide(containerBox, _.first(this.matches)));
|
||||
paths.push(this.makeSide(containerBox, _.last(this.matches)));
|
||||
|
||||
this.container.prepend(
|
||||
this.container.path(paths.join('')));
|
||||
this.container.path(_(paths).flatten().compact().values().join('')));
|
||||
|
||||
containerBox = matchContainer.getBBox();
|
||||
paths = _.map(this.matches, match => {
|
||||
return this.makeConnector(containerBox, match);
|
||||
});
|
||||
matchContainer.prepend(
|
||||
matchContainer.path(_.map(this.matches, match => {
|
||||
var box = match.getBBox(),
|
||||
container = matchContainer.getBBox();
|
||||
|
||||
return `M0,${box.ay}h${box.ax}M${box.ax2},${box.ay}H${container.width}`;
|
||||
}).join('')));
|
||||
matchContainer.path(paths.join('')));
|
||||
});
|
||||
},
|
||||
|
||||
makeSideLine(containerBox, match) {
|
||||
makeSide(containerBox, match) {
|
||||
var box = match.getBBox(),
|
||||
direction = box.ay > containerBox.cy ? 1 : -1,
|
||||
distance = Math.abs(box.ay - containerBox.cy);
|
||||
|
||||
if (distance >= 15) {
|
||||
let edge = box.ay - 10 * direction,
|
||||
shift = 10 * direction;
|
||||
let shift = (box.ay > containerBox.cy) ? 10 : -10,
|
||||
edge = box.ay - shift;
|
||||
|
||||
return [
|
||||
`M0,${containerBox.cy}q10,0 10,${shift}V${edge}`,
|
||||
`M${containerBox.width + 40},${containerBox.cy}q-10,0 -10,${shift}V${edge}`
|
||||
].join('');
|
||||
} else {
|
||||
return '';
|
||||
];
|
||||
}
|
||||
},
|
||||
|
||||
makeConnectorLine(containerBox, match) {
|
||||
makeCurve(containerBox, match) {
|
||||
var box = match.getBBox(),
|
||||
direction = box.ay > containerBox.cy ? 1 : -1,
|
||||
distance = Math.abs(box.ay - containerBox.cy);
|
||||
|
||||
if (distance >= 15) {
|
||||
let curve = 10 * direction;
|
||||
let curve = (box.ay > containerBox.cy) ? 10 : -10;
|
||||
|
||||
return [
|
||||
`M10,${box.ay - curve}q0,${curve} 10,${curve}`,
|
||||
`M${containerBox.width + 30},${box.ay - curve}q0,${curve} -10,${curve}`
|
||||
].join('');
|
||||
];
|
||||
} else {
|
||||
let anchor = box.ay - containerBox.cy;
|
||||
|
||||
return [
|
||||
`M0,${containerBox.cy}c10,0 10,${anchor} 20,${anchor}`,
|
||||
`M${containerBox.width + 40},${containerBox.cy}c-10,0 -10,${anchor} -20,${anchor}`
|
||||
].join('');
|
||||
];
|
||||
}
|
||||
},
|
||||
|
||||
setup() {
|
||||
this.matches = [this.properties.match]
|
||||
.concat(_.map(this.properties.alternates.elements, element => {
|
||||
return element.properties.match;
|
||||
}));
|
||||
makeConnector(containerBox, match) {
|
||||
var box = match.getBBox();
|
||||
|
||||
if (this.matches.length === 1) {
|
||||
return this.proxy = this.matches[0];
|
||||
return `M0,${box.ay}h${box.ax}M${box.ax2},${box.ay}H${containerBox.width}`;
|
||||
},
|
||||
|
||||
setup() {
|
||||
if (this.properties.alternates.elements.length === 0) {
|
||||
this.proxy = this.properties.match;
|
||||
} else {
|
||||
this.matches = [this.properties.match]
|
||||
.concat(_.map(this.properties.alternates.elements, element => {
|
||||
return element.properties.match;
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user