Moving skip and loop line calculation into Repeat nodes

This code seems more at home in Repeat instead of MatchFragment since
Repeat knows about the dimensions of the lines for the contentPosition
value.
This commit is contained in:
Jeff Avallone
2015-04-23 20:03:25 -04:00
parent ff9e84f20e
commit 06a7ffc110
4 changed files with 120 additions and 125 deletions
+2 -41
View File
@@ -38,8 +38,8 @@ export default {
// Add skip or repeat paths to the container.
paths = _.flatten([
this.skipPath(box),
this.loopPath(box)
this.repeat.skipPath(box),
this.repeat.loopPath(box)
]);
this.container.prepend(
@@ -49,45 +49,6 @@ export default {
});
},
// Returns the path spec to render the line that skips over the content for
// fragments that are optionally matched.
skipPath(box) {
var paths = [];
if (this.repeat.hasSkip) {
let vert = Math.max(0, box.ay - box.y - 10),
horiz = box.width - 10;
paths.push(`M0,${box.ay}q10,0 10,-10v${-vert}q0,-10 10,-10h${horiz}q10,0 10,10v${vert}q0,10 10,10`);
// When the repeat is not greedy, the skip path gets a preference arrow.
if (!this.repeat.greedy) {
paths.push(`M10,${box.ay - 15}l5,5m-5,-5l-5,5`);
}
}
return paths;
},
// Returns the path spec to render the line that repeats the content for
// fragments that are matched more than once.
loopPath(box) {
var paths = [];
if (this.repeat.hasLoop) {
let vert = box.y2 - box.ay - 10;
paths.push(`M${box.x},${box.ay}q-10,0 -10,10v${vert}q0,10 10,10h${box.width}q10,0 10,-10v${-vert}q0,-10 -10,-10`);
// When the repeat is greedy, the loop path gets the preference arrow.
if (this.repeat.greedy) {
paths.push(`M${box.x2 + 10},${box.ay + 15}l5,-5m-5,5l-5,-5`);
}
}
return paths;
},
// Renders label for the loop path indicating how many times the content may
// be matched.
loopLabel() {
+39
View File
@@ -47,6 +47,45 @@ export default {
}
},
// Returns the path spec to render the line that skips over the content for
// fragments that are optionally matched.
skipPath(box) {
var paths = [];
if (this.hasSkip) {
let vert = Math.max(0, box.ay - box.y - 10),
horiz = box.width - 10;
paths.push(`M0,${box.ay}q10,0 10,-10v${-vert}q0,-10 10,-10h${horiz}q10,0 10,10v${vert}q0,10 10,10`);
// When the repeat is not greedy, the skip path gets a preference arrow.
if (!this.greedy) {
paths.push(`M10,${box.ay - 15}l5,5m-5,-5l-5,5`);
}
}
return paths;
},
// Returns the path spec to render the line that repeats the content for
// fragments that are matched more than once.
loopPath(box) {
var paths = [];
if (this.hasLoop) {
let vert = box.y2 - box.ay - 10;
paths.push(`M${box.x},${box.ay}q-10,0 -10,10v${vert}q0,10 10,10h${box.width}q10,0 10,-10v${-vert}q0,-10 -10,-10`);
// When the repeat is greedy, the loop path gets the preference arrow.
if (this.greedy) {
paths.push(`M${box.x2 + 10},${box.ay + 15}l5,-5m-5,5l-5,-5`);
}
}
return paths;
},
setup() {
this.minimum = this.properties.spec.minimum;
this.maximum = this.properties.spec.maximum;