Adding documentation to repeat.js and some logic simplification
This commit is contained in:
parent
6beeddb83a
commit
c6af61659f
@ -1,3 +1,7 @@
|
|||||||
|
// Repeat nodes are for the various repetition syntaxes (`a*`, `a+`, `a?`, and
|
||||||
|
// `a{1,3}`). It is not rendered directly, but contains data used for the
|
||||||
|
// rendering of [MatchFragment](./match_fragment.html) nodes.
|
||||||
|
|
||||||
function formatTimes(times) {
|
function formatTimes(times) {
|
||||||
if (times === 1) {
|
if (times === 1) {
|
||||||
return 'once';
|
return 'once';
|
||||||
@ -8,32 +12,33 @@ function formatTimes(times) {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
definedProperties: {
|
definedProperties: {
|
||||||
|
// Translation to apply to content to be repeated to account for the loop
|
||||||
|
// and skip lines.
|
||||||
contentPosition: {
|
contentPosition: {
|
||||||
get: function() {
|
get: function() {
|
||||||
var x = 0, y = 0;
|
var matrix = Snap.matrix();
|
||||||
|
|
||||||
if (this.hasLoop) {
|
|
||||||
x = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.hasSkip) {
|
if (this.hasSkip) {
|
||||||
y = 10;
|
return matrix.translate(15, 10);
|
||||||
x = 15;
|
} else if (this.hasLoop) {
|
||||||
|
return matrix.translate(10, 0);
|
||||||
|
} else {
|
||||||
|
return matrix.translate(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Snap.matrix().translate(x, y);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Label to place of loop path to indicate the number of times that path
|
||||||
|
// may be followed.
|
||||||
label: {
|
label: {
|
||||||
get: function() {
|
get: function() {
|
||||||
if (this.minimum >= 2 && this.maximum === -1) {
|
if (this.minimum === this.maximum) {
|
||||||
return `${this.minimum - 1}+ times`;
|
return formatTimes(this.minimum - 1);
|
||||||
} else if (this.minimum <= 1 && this.maximum >= 2) {
|
} else if (this.minimum <= 1 && this.maximum >= 2) {
|
||||||
return `at most ${formatTimes(this.maximum - 1)}`;
|
return `at most ${formatTimes(this.maximum - 1)}`;
|
||||||
} else if (this.minimum >= 2 && this.maximum >= 2) {
|
} else if (this.minimum >= 2) {
|
||||||
if (this.minimum === this.maximum) {
|
if (this.maximum === -1) {
|
||||||
return formatTimes(this.minimum - 1);
|
return `${this.minimum - 1}+ times`;
|
||||||
} else {
|
} else {
|
||||||
return `${this.minimum - 1}\u2026${formatTimes(this.maximum - 1)}`;
|
return `${this.minimum - 1}\u2026${formatTimes(this.maximum - 1)}`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user