Skip to content

Commit

Permalink
experimental gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Jan 25, 2023
1 parent 4fb510a commit 735efc5
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions lib/render-gaps.js
Expand Up @@ -45,28 +45,66 @@ function renderGaps (lanes, index, source, lane) {
style: 'stroke:#000;stroke-width:1px'
}];

const backDrop = ['rect', {
width: 4,
const lineStyle = 'fill:none;stroke:#000;stroke-width:1px';
const bracket = {
square: {
left: ['path', {d: 'M 2 0 h -4 v ' + (lanesLen * lane.yo - 1) + ' h 4', style: lineStyle}],
right: ['path', {d: 'M -2 0 h 4 v ' + (lanesLen * lane.yo - 1) + ' h -4', style: lineStyle}]
},
round: {
left: ['path', {d: 'M 2 0 a 4 4 0 0 0 -4 4 v ' + (lanesLen * lane.yo - 9) + ' a 4 4 0 0 0 4 4', style: lineStyle}],
right: ['path', {d: 'M -2 0 a 4 4 1 0 1 4 4 v ' + (lanesLen * lane.yo - 9) + ' a 4 4 1 0 1 -4 4', style: lineStyle}],
rightLeft: ['path', {
d: 'M -5 0 a 4 4 1 0 1 4 4 v ' + (lanesLen * lane.yo - 9) + ' a 4 4 1 0 1 -4 4' +
'M 5 0 a 4 4 0 0 0 -4 4 v ' + (lanesLen * lane.yo - 9) + ' a 4 4 0 0 0 4 4',
style: lineStyle
}],
leftLeft: ['path', {
d: 'M 2 0 a 4 4 0 0 0 -4 4 v ' + (lanesLen * lane.yo - 9) + ' a 4 4 0 0 0 4 4' +
'M 5 1 a 3 3 0 0 0 -3 3 v ' + (lanesLen * lane.yo - 9) + ' a 3 3 0 0 0 3 3',
style: lineStyle
}],
rightRight: ['path', {
d: 'M -5 1 a 3 3 1 0 1 3 3 v ' + (lanesLen * lane.yo - 9) + ' a 3 3 1 0 1 -3 3' +
'M -2 0 a 4 4 1 0 1 4 4 v ' + (lanesLen * lane.yo - 9) + ' a 4 4 1 0 1 -4 4',
style: lineStyle
}]
}
};

const backDrop = (w) => ['rect', {
x: -w / 2,
width: w,
height: lanesLen * lane.yo,
style: 'fill:#ffffffcc;stroke:none'
}];

if (source && typeof source.gaps === 'string') {
const scale = lane.hscale * lane.xs * 2;

for (let x = 0; x < source.gaps.length; x++) {
const c = source.gaps[x];
const gaps = source.gaps.trim().split(/\s+/);

for (let x = 0; x < gaps.length; x++) {
const c = gaps[x];
if (c.match(/^[.]$/)) {
continue;
}
const offset = (c === c.toLowerCase()) ? 0.5 : 0;

let marks = [];
switch(c) {
case '0': marks = [backDrop]; break;
case '1': marks = [backDrop, vline(2)]; break;
case '2': marks = [backDrop, vline(0), vline(4)]; break;
case '3': marks = [backDrop, vline(0), vline(2), vline(4)]; break;
case '0': marks = [backDrop(4)]; break;
case '1': marks = [backDrop(4), vline(0)]; break;
case '|': marks = [backDrop(4), vline(0)]; break;
case '2': marks = [backDrop(4), vline(-2), vline(2)]; break;
case '3': marks = [backDrop(6), vline(-3), vline(0), vline(3)]; break;
case '[': marks = [backDrop(4), bracket.square.left]; break;
case ']': marks = [backDrop(4), bracket.square.right]; break;
case '(': marks = [backDrop(4), bracket.round.left]; break;
case ')': marks = [backDrop(4), bracket.round.right]; break;
case ')(': marks = [backDrop(8), bracket.round.rightLeft]; break;
case '((': marks = [backDrop(8), bracket.round.leftLeft]; break;
case '))': marks = [backDrop(8), bracket.round.rightRight]; break;
case 's':
for (let idx = 0; idx < lanesLen; idx++) {
if (lanes[idx] && lanes[idx].wave && lanes[idx].wave.length > x) {
Expand All @@ -77,7 +115,7 @@ function renderGaps (lanes, index, source, lane) {
}


res.push(['g', tt(scale * (x + offset) - 2)].concat(marks));
res.push(['g', tt(scale * (x + offset))].concat(marks));
}
}
for (let idx = 0; idx < lanesLen; idx++) {
Expand All @@ -96,6 +134,6 @@ function renderGaps (lanes, index, source, lane) {
}
}
return ['g', {id: 'wavegaps_' + index}].concat(res);
}
} /* eslint complexity: [1, 100] */

module.exports = renderGaps;

0 comments on commit 735efc5

Please sign in to comment.