Skip to content

Commit

Permalink
added global gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Jan 19, 2023
1 parent 3aeb42f commit 2a61d12
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/render-arcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ const archer = (res, Events, arcFontSize) => (element) => {
}
};

function renderArcs (source, index, top, lane) {
const arcFontSize = (top && top.config && top.config.arcFontSize)
? top.config.arcFontSize
function renderArcs (lanes, index, source, lane) {
const arcFontSize = (source && source.config && source.config.arcFontSize)
? source.config.arcFontSize
: 11;

const res = ['g', {id: 'wavearcs_' + index}];
const Events = {};
if (Array.isArray(source)) {
source.map(labeler(lane, Events));
if (Array.isArray(top.edge)) {
top.edge.map(archer(res, Events, arcFontSize));
if (Array.isArray(lanes)) {
lanes.map(labeler(lane, Events));
if (Array.isArray(source.edge)) {
source.edge.map(archer(res, Events, arcFontSize));
}
Object.keys(Events).map(function (k) {
if (k === k.toLowerCase()) {
Expand Down
56 changes: 50 additions & 6 deletions lib/render-gaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,64 @@ function renderGapUses (text, lane) {
return res;
}

function renderGaps (source, index, lane) {

function renderGaps (lanes, index, source, lane) {
let res = [];
if (source) {
for (const key of Object.keys(source)) {
const val = source[key];
if (lanes) {
const lanesLen = lanes.length;

const vline = (x) => ['line', {
x1: x, x2: x,
y2: lanesLen * lane.yo,
style: 'stroke:#000;stroke-width:1px'
}];

const backDrop = ['rect', {
width: 4,
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];
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 's':
for (let idx = 0; idx < lanesLen; idx++) {
if (lanes[idx] && lanes[idx].wave && lanes[idx].wave.length > x) {
marks.push(['use', tt(2, 5 + lane.yo * idx, {'xlink:href': '#gap'})]);
}
}
break;
}


res.push(['g', tt(scale * (x + offset) - 2)].concat(marks));
}
}
for (let idx = 0; idx < lanesLen; idx++) {
const val = lanes[idx];
lane.period = val.period ? val.period : 1;
lane.phase = (val.phase ? val.phase * 2 : 0) + lane.xmin_cfg;

if (typeof val.wave === 'string') {
const gaps = renderGapUses(val.wave, lane);
res = res.concat([['g', tt(
0,
lane.y0 + key * lane.yo,
{id: 'wavegap_' + key + '_' + index}
lane.y0 + idx * lane.yo,
{id: 'wavegap_' + idx + '_' + index}
)].concat(gaps)]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/render-lanes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function renderLanes (index, content, waveLanes, ret, source, lane) {
waveLanes.res,
[
renderArcs(ret.lanes, index, source, lane),
renderGaps(ret.lanes, index, lane),
renderGaps(ret.lanes, index, source, lane),
renderPieceWise(ret.lanes, index, lane)
]
);
Expand Down

0 comments on commit 2a61d12

Please sign in to comment.