Skip to content

Commit

Permalink
groups late rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Dec 12, 2015
1 parent cf0141e commit 0c27384
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 115 deletions.
4 changes: 2 additions & 2 deletions WaveDrom.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions lib/insert-svg-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ function insertSVGTemplate (index, parent, source, lane) {
lane.xlabel = Number(e[3][1][2][1].x);
lane.ym = Number(e[3][1][2][1].y);
} else {
e = [
'svg',
e = ['svg',
{
id: 'svg',
xmlns: w3.svg,
'xmlns:xlink': w3.xlink,
height: '0'
},
[
'g',
['g',
{
id: 'waves'
},
Expand Down
12 changes: 4 additions & 8 deletions lib/render-arcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,15 @@ var jsonmlParse = require('./create-element'),
t1();
if (from && to) {
if (Edge.label) {
label = jsonmlParse([
'text',
label = jsonmlParse(['text',
{
style: 'font-size:10px;',
'text-anchor': 'middle'
},
Edge.label + ''
]);
label.setAttributeNS(w3.xmlns, 'xml:space', 'preserve');
underlabel = jsonmlParse([
'rect',
underlabel = jsonmlParse(['rect',
{
height: 9,
style: 'fill:#FFF;'
Expand Down Expand Up @@ -209,17 +207,15 @@ var jsonmlParse = require('./create-element'),
for (k in Events) {
if (k === k.toLowerCase()) {
if (Events[k].x > 0) {
underlabel = jsonmlParse([
'rect',
underlabel = jsonmlParse(['rect',
{
y: Events[k].y - 4,
height: 8,
style: 'fill:#FFF;'
}
]);
gg.insertBefore(underlabel, null);
label = jsonmlParse([
'text',
label = jsonmlParse(['text',
{
style: 'font-size:8px;',
x: Events[k].x,
Expand Down
59 changes: 28 additions & 31 deletions lib/render-groups.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
'use strict';

var jsonmlParse = require('./create-element'),
w3 = require('./w3');
function renderGroups (groups, index, lane) {
var x, y, res = ['g'];

function renderGroups (root, groups, index, lane) {
var i, group, label, x, y, name;
groups.forEach(function (e, i) {
res.push(['path',
{
id: 'group_' + i + '_' + index,
d: ('m ' + (e.x + 0.5) + ',' + (e.y * lane.yo + 3.5 + lane.yh0 + lane.yh1)
+ ' c -3,0 -5,2 -5,5 l 0,' + (e.height * lane.yo - 16)
+ ' c 0,3 2,5 5,5'),
style: 'stroke:#0041c4;stroke-width:1;fill:none'
}
]);

for (i in groups) {
group = document.createElementNS(w3.svg, 'path');
group.id = ('group_' + i + '_' + index);
group.setAttribute('d', 'm ' + (groups[i].x + 0.5) + ',' + (groups[i].y * lane.yo + 3.5 + lane.yh0 + lane.yh1) + ' c -3,0 -5,2 -5,5 l 0,' + (groups[i].height * lane.yo - 16) + ' c 0,3 2,5 5,5');
group.setAttribute('style', 'stroke:#0041c4;stroke-width:1;fill:none');
root.insertBefore(group, null);
if (e.name === undefined) { return; }

name = groups[i].name;
if (typeof name !== 'undefined') {
if (typeof name === 'number') { name += ''; }
x = (groups[i].x - 10);
y = (lane.yo * (groups[i].y + (groups[i].height / 2)) + lane.yh0 + lane.yh1);
label = jsonmlParse([
'text',
{
x: x,
y: y,
'text-anchor': 'middle',
// fill: '#0041c4',
class: 'info',
transform: 'rotate(270,' + x + ',' + y + ')'
},
name
]);
label.setAttributeNS(w3.xmlns, 'xml:space', 'preserve');
root.insertBefore(label, null);
}
}
x = (e.x - 10);
y = (lane.yo * (e.y + (e.height / 2)) + lane.yh0 + lane.yh1);
res.push(['text',
{
x: x,
y: y,
'text-anchor': 'middle',
class: 'info',
transform: 'rotate(270,' + x + ',' + y + ')',
'xml:space': 'preserve'
},
e.name.toString()
]);
});
return res;
}

module.exports = renderGroups;
Expand Down
7 changes: 4 additions & 3 deletions lib/render-wave-form.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var rec = require('./rec'),
onmlStringify = require('onml/lib/stringify'),
parseConfig = require('./parse-config'),
parseWaveLanes = require('./parse-wave-lanes'),
renderMarks = require('./render-marks'),
Expand All @@ -21,8 +22,8 @@ function renderWaveForm (index, source, output, lane) {
insertSVGTemplate(index, document.getElementById(output + index), source, lane);
parseConfig(source, lane);
ret = rec(source.signal, {'x':0, 'y':0, 'xmax':0, 'width':[], 'lanes':[], 'groups':[]});
root = document.getElementById('lanes_' + index);
groups = document.getElementById('groups_' + index);
root = document.getElementById('lanes_' + index);
groups = document.getElementById('groups_' + index);
content = parseWaveLanes(ret.lanes, lane);
glengths = renderWaveLane(root, content, index, lane);
for (i in glengths) {
Expand All @@ -31,7 +32,7 @@ function renderWaveForm (index, source, output, lane) {
renderMarks(root, content, index, lane);
renderArcs(root, ret.lanes, index, source, lane);
renderGaps(root, ret.lanes, index, lane);
renderGroups(groups, ret.groups, index, lane);
groups.innerHTML = onmlStringify(renderGroups(ret.groups, index, lane));
lane.xg = Math.ceil((xmax - lane.tgo) / lane.xs) * lane.xs;
width = (lane.xg + (lane.xs * (lane.xmax + 1)));
height = (content.length * lane.yo +
Expand Down
12 changes: 4 additions & 8 deletions lib/render-wave-lane.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ function renderWaveLane (root, content, index, lane) {
for (j = 0; j < content.length; j += 1) {
name = content[j][0][0];
if (name) { // check name
g = jsonmlParse([
'g',
g = jsonmlParse(['g',
{
id: 'wavelane_' + j + '_' + index,
transform: 'translate(0,' + ((lane.y0) + j * lane.yo) + ')'
Expand All @@ -33,8 +32,7 @@ function renderWaveLane (root, content, index, lane) {

if (typeof name === 'number') { name += ''; }

title = jsonmlParse([
'text',
title = jsonmlParse(['text',
{
x: lane.tgo,
y: lane.ym,
Expand All @@ -53,8 +51,7 @@ function renderWaveLane (root, content, index, lane) {
xoffset = content[j][0][1];
xoffset = (xoffset > 0) ? (Math.ceil(2 * xoffset) - 2 * xoffset) :
(-2 * xoffset);
gg = jsonmlParse([
'g',
gg = jsonmlParse(['g',
{
id: 'wavelane_draw_' + j + '_' + index,
transform: 'translate(' + (xoffset * lane.xs) + ', 0)'
Expand All @@ -77,8 +74,7 @@ function renderWaveLane (root, content, index, lane) {
if (labels.length !== 0) {
for (k in labels) {
if (content[j][2] && (typeof content[j][2][k] !== 'undefined')) {
title = jsonmlParse([
'text',
title = jsonmlParse(['text',
{
x: labels[k] * lane.xs + lane.xlabel,
y: lane.ym,
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
"RTL"
],
"devDependencies": {
"eslint": "^1.9.0",
"eslint": "^1.10.3",
"grunt": "^0.4.5",
"grunt-browserify": "^4.0.1",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-uglify": "^0.10.1",
"grunt-contrib-uglify": "^0.11.0",
"grunt-eslint": "^17.3.1",
"sax": "^1.1.4"
},
"dependencies": {
"onml": "^0.2.0"
}
}
Loading

0 comments on commit 0c27384

Please sign in to comment.