Skip to content

Commit

Permalink
over/ under feature (experimantal)
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Apr 26, 2020
1 parent f4ece18 commit b925c5d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 79 deletions.
40 changes: 20 additions & 20 deletions lib/parse-wave-lanes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ function data_extract (e, num_unseen_markers) {
}

function parseWaveLanes (sig, lane) {
var x,
sigx,
content = [],
content_wave,
parsed_wave_lane,
num_unseen_markers,
var content = [],
tmp0 = [];

for (x in sig) {
// sigx is each signal in the array of signals being iterated over
sigx = sig[x];
lane.period = sigx.period ? sigx.period : 1;
sig.map(function (sigx) {
var content_wave = null,
parsed_wave_lane,
num_unseen_markers,
current = [];

content.push(current);

lane.period = sigx.period || 1;
// xmin_cfg is min. brick of hbounds, add to lane.phase of all signals
lane.phase = (sigx.phase ? sigx.phase * 2 : 0) + lane.xmin_cfg;
content.push([]);
tmp0[0] = sigx.name || ' ';
lane.phase = (sigx.phase ? sigx.phase * 2 : 0) + lane.xmin_cfg;
tmp0[0] = sigx.name || ' ';
// xmin_cfg is min. brick of hbounds, add 1/2 to sigx.phase of all sigs
tmp0[1] = (sigx.phase || 0) + lane.xmin_cfg/2;
if ( sigx.wave ) {
if (sigx.wave) {
parsed_wave_lane = parseWaveLane(sigx.wave, lane.period * lane.hscale - 1, lane);
content_wave = parsed_wave_lane[0] ;
num_unseen_markers = parsed_wave_lane[1];
} else {
content_wave = null;
}
content[content.length - 1][0] = tmp0.slice(0);
content[content.length - 1][1] = content_wave;
content[content.length - 1][2] = data_extract(sigx, num_unseen_markers);
}
current.push(
tmp0.slice(0),
content_wave,
data_extract(sigx, num_unseen_markers),
sigx
);
});
// content is an array of arrays, representing the list of signals using
// the same order:
// content[0] = [ [name,phase], parsedwavelaneobj, dataextracted ]
Expand Down
46 changes: 46 additions & 0 deletions lib/render-over-under.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

function renderOverUnder (el, key, lane) {
var xs = lane.xs;
var ys = lane.ys;
var period = (el.period || 1) * 2 * xs;
var xoffset = -(el.phase || 0) * 2 * xs;
var gap1 = 12;

var y = (key === 'under') ? ys : 0;

if (el[key]) {
var res = ['g', {
transform: 'translate(' + xoffset + ',' + y + ')',
style: 'stroke:#000;stroke-width:3'
}];

let start = undefined;
const arr = el[key].split('');
arr.map(function (dot, i) {
if ((dot === '0' || dot === '1') && start !== undefined) {
res.push(['line', {
x1: period * start + gap1,
x2: period * i // + gap2
}]);
}
if (dot === '1') {
start = i;
} else
if (dot === '0') {
start = undefined;
}
});
const last = arr[arr.length - 1];
if (last !== '0' && last !== '1') {
res.push(['line', {
x1: period * start + gap1,
x2: period * arr.length // + gap2
}]);
}
return [res];
}
return [];
}

module.exports = renderOverUnder;
77 changes: 40 additions & 37 deletions lib/render-wave-lane.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,81 @@
var tspan = require('tspan');
var textWidth = require('./text-width.js');
var findLaneMarkers = require('./find-lane-markers.js');
var renderOverUnder = require('./render-over-under.js');

function renderLaneUses (cont, lane) {
var i, k;
var res = [];
var labels = [];

if (cont[1]) {
for (i = 0; i < cont[1].length; i += 1) {
cont[1].map(function (ref, i) {
res.push(['use', {
'xlink:href': '#' + cont[1][i],
'xlink:href': '#' + ref,
transform: 'translate(' + (i * lane.xs) + ')'
}]);
}
});
if (cont[2] && cont[2].length) {
labels = findLaneMarkers(cont[1]);
if (labels.length) {
for (k in labels) {
if (cont[2] && (cont[2][k] !== undefined)) {
labels.map(function (label, i) {
if (cont[2] && (cont[2][i] !== undefined)) {
res.push(['text', {
x: labels[k] * lane.xs + lane.xlabel,
x: label * lane.xs + lane.xlabel,
y: lane.ym,
'text-anchor': 'middle',
'xml:space': 'preserve'
}].concat(tspan.parse(cont[2][k])));
}].concat(tspan.parse(cont[2][i])));
}
}
});
}
}
}
return res;
}

function renderWaveLane (content, index, lane) {
var // i,
j,
name,
xoffset,
xmax = 0,
xgmax = 0,
glengths = [];

var res = [];
var xmax = 0,
xgmax = 0,
glengths = [],
res = [];

for (j = 0; j < content.length; j += 1) {
name = content[j][0][0];
content.map(function (el, j) {
var name = el[0][0];
if (name) { // check name

xoffset = content[j][0][1];
var xoffset = el[0][1];
xoffset = (xoffset > 0)
? (Math.ceil(2 * xoffset) - 2 * xoffset)
: (-2 * xoffset);

res.push(['g', {
id: 'wavelane_' + j + '_' + index,
transform: 'translate(0,' + ((lane.y0) + j * lane.yo) + ')'
},
['text', {
x: lane.tgo,
y: lane.ym,
class: 'info',
'text-anchor': 'end',
'xml:space': 'preserve'
}].concat(tspan.parse(name)),
['g', {
id: 'wavelane_draw_' + j + '_' + index,
transform: 'translate(' + (xoffset * lane.xs) + ', 0)'
}].concat(renderLaneUses(content[j], lane))
]);
}]
.concat([['text', {
x: lane.tgo,
y: lane.ym,
class: 'info',
'text-anchor': 'end',
'xml:space': 'preserve'
}]
.concat(tspan.parse(name))
])
.concat([['g', {
id: 'wavelane_draw_' + j + '_' + index,
transform: 'translate(' + (xoffset * lane.xs) + ', 0)'
}]
.concat(renderLaneUses(el, lane))
])
.concat(
renderOverUnder(el[3], 'over', lane),
renderOverUnder(el[3], 'under', lane)
)
);

xmax = Math.max(xmax, (content[j][1] || []).length);
xmax = Math.max(xmax, (el[1] || []).length);
glengths.push(textWidth(name, 11));
}
}
});
// xmax if no xmax_cfg,xmin_cfg, else set to config
lane.xmax = Math.min(xmax, lane.xmax_cfg - lane.xmin_cfg);
lane.xg = xgmax + 20;
Expand Down
36 changes: 14 additions & 22 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -315,32 +315,24 @@ <h3>over-under</h3>
<script type="WaveDrom">
{signal: [
{name: 'clk', wave: 'p.PpPPPPp.P.'},

{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10'},
{name: 'FF', wave: 'x....3.4...5', data: 'D1 D2 D3'},
], head:{tick: 1}}
</script>
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', phase: .5},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', phase: 1},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', phase: 1.7},

<script type="WaveDrom">
{ signal: [
{ name: 'Reset',
wave: '01|...=...|01u', data: ['a < b'],
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 2},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 2, phase: .5},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 2, phase: 1},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 2, phase: 1.7},

node: '...........E...' },
{},
{ name: 'Input',
wave: 'x0|.1x....|.0d',
node: '....A.F.......' },
{},
{ name: 'Output',
wave: '0.|......1|0.d',
node: '.........C.F..' },
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 0.5},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 0.5, phase: .5},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 0.5, phase: 1},
{name: 'dat →', wave: 'x.3..4.5...6', data: 'D1 D2 D3', over: '0.1..1.1...1', under: '0...1010..10', period: 0.5, phase: 1.7},

{ node: '....B....D.....' },
],
edge: [
'A-B', 'C-D', 'A~>C', 'B<->D T > 45s', 'E->F'
]
}
{name: 'FF', wave: 'x....3.4...5', data: 'D1 D2 D3'},
], head:{tick: 1}}
</script>

</div>
Expand Down

0 comments on commit b925c5d

Please sign in to comment.