Skip to content

Commit 10177f9

Browse files
Bus width labels (#101)
* Update built/ to latest version of Typescript code * Bus wires have double width, also added width_* classes to every wire for more customization * Add inline bus width numbers with a class busLabel_* for customization
1 parent eb9dc54 commit 10177f9

11 files changed

+974
-463
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,20 @@ The elkjs layout properties are also defined in the skin file.
475475
```
476476
Any properties specified here will get passed along to the layout engine. Node and edge properties aren't configurable (yet).
477477

478+
Using the classes `.busLabel_*` and `.width_*` (where * indicates the bus width) in the `<style>` tag at the top of the skin file (or the resulting svg), styling based on bus width can be added to lines and labels.
479+
480+
For instance, to turn off bus width labels for buses of two wires, simply add:
481+
```svg
482+
.busLabel_2 {
483+
fill-opacity: 0;
484+
}
485+
```
486+
To change the color of all lines of width 4 to red, simply add:
487+
```svg
488+
line.width_4 {
489+
stroke: red;
490+
}
491+
```
478492
## Input JSON
479493
Yosys JSON includes more information than we need. We only render one module (either the first or the module with an attribute "top"). If the cell name matches one of the aliases of a template from the skin, then it will use it as a template for the SVG file. Port directions are optional for cells that are defined in the skin (not generic cells).
480494

built/Cell.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ var Cell = /** @class */ (function () {
9090
get: function () {
9191
return this.type;
9292
},
93-
enumerable: true,
93+
enumerable: false,
9494
configurable: true
9595
});
9696
Object.defineProperty(Cell.prototype, "Key", {
9797
get: function () {
9898
return this.key;
9999
},
100-
enumerable: true,
100+
enumerable: false,
101101
configurable: true
102102
});
103103
Object.defineProperty(Cell.prototype, "InputPorts", {
104104
get: function () {
105105
return this.inputPorts;
106106
},
107-
enumerable: true,
107+
enumerable: false,
108108
configurable: true
109109
});
110110
Object.defineProperty(Cell.prototype, "OutputPorts", {
111111
get: function () {
112112
return this.outputPorts;
113113
},
114-
enumerable: true,
114+
enumerable: false,
115115
configurable: true
116116
});
117117
Cell.prototype.maxOutVal = function (atLeast) {
@@ -242,7 +242,8 @@ var Cell = /** @class */ (function () {
242242
var tempclone = clone(template);
243243
for (var _i = 0, _a = cell.labels; _i < _a.length; _i++) {
244244
var label = _a[_i];
245-
var attrName = label.id.split('.')[2];
245+
var labelIDSplit = label.id.split('.');
246+
var attrName = labelIDSplit[labelIDSplit.length - 1];
246247
setTextAttribute(tempclone, attrName, label.text);
247248
}
248249
for (var i = 2; i < tempclone.length; i++) {

built/FlatModule.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.removeDups = exports.addToDefaultDict = exports.arrayToBitstring = exports.FlatModule = void 0;
34
var Skin_1 = require("./Skin");
45
var Cell_1 = require("./Cell");
56
var _ = require("lodash");

built/Port.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.Port = void 0;
34
var Cell_1 = require("./Cell");
45
var _ = require("lodash");
56
var Port = /** @class */ (function () {
@@ -11,7 +12,7 @@ var Port = /** @class */ (function () {
1112
get: function () {
1213
return this.key;
1314
},
14-
enumerable: true,
15+
enumerable: false,
1516
configurable: true
1617
});
1718
Port.prototype.keyIn = function (pids) {

built/Skin.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.Skin = void 0;
34
var onml = require("onml");
45
var _ = require("lodash");
56
var Skin;

built/drawModule.js

+50-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
77
return r;
88
};
99
Object.defineProperty(exports, "__esModule", { value: true });
10+
exports.removeDummyEdges = void 0;
1011
var elkGraph_1 = require("./elkGraph");
1112
var Skin_1 = require("./Skin");
1213
var _ = require("lodash");
@@ -26,7 +27,9 @@ function drawModule(g, module) {
2627
removeDummyEdges(g);
2728
var lines = _.flatMap(g.edges, function (e) {
2829
var netId = elkGraph_1.ElkModel.wireNameLookup[e.id];
29-
var netName = 'net_' + netId.slice(1, netId.length - 1);
30+
var numWires = netId.split(',').length - 2;
31+
var lineStyle = 'stroke-width: ' + (numWires > 1 ? 2 : 1);
32+
var netName = 'net_' + netId.slice(1, netId.length - 1) + ' width_' + numWires;
3033
return _.flatMap(e.sections, function (s) {
3134
var startPoint = s.startPoint;
3235
s.bendPoints = s.bendPoints || [];
@@ -37,6 +40,7 @@ function drawModule(g, module) {
3740
y1: startPoint.y,
3841
y2: b.y,
3942
class: netName,
43+
style: lineStyle,
4044
}];
4145
startPoint = b;
4246
return l;
@@ -46,7 +50,7 @@ function drawModule(g, module) {
4650
return ['circle', {
4751
cx: j.x,
4852
cy: j.y,
49-
r: 2,
53+
r: (numWires > 1 ? 3 : 2),
5054
style: 'fill:#000',
5155
class: netName,
5256
}];
@@ -59,10 +63,54 @@ function drawModule(g, module) {
5963
y1: startPoint.y,
6064
y2: s.endPoint.y,
6165
class: netName,
66+
style: lineStyle,
6267
}]];
6368
return bends.concat(line);
6469
});
6570
});
71+
var labels;
72+
for (var index in g.edges) {
73+
if (g.edges.hasOwnProperty(index)) {
74+
var e = g.edges[index];
75+
var netId = elkGraph_1.ElkModel.wireNameLookup[e.id];
76+
var numWires = netId.split(',').length - 2;
77+
var netName = 'net_' + netId.slice(1, netId.length - 1) +
78+
' width_' + numWires +
79+
' busLabel_' + numWires;
80+
if (e.labels !== undefined &&
81+
e.labels[0] !== undefined &&
82+
e.labels[0].text !== undefined) {
83+
var label = [
84+
['rect',
85+
{
86+
x: e.labels[0].x + 1,
87+
y: e.labels[0].y - 1,
88+
width: (e.labels[0].text.length + 2) * 6 - 2,
89+
height: 9,
90+
class: netName,
91+
style: 'fill: white; stroke: none',
92+
},
93+
], ['text',
94+
{
95+
x: e.labels[0].x,
96+
y: e.labels[0].y + 7,
97+
class: netName,
98+
},
99+
'/' + e.labels[0].text + '/',
100+
],
101+
];
102+
if (labels !== undefined) {
103+
labels = labels.concat(label);
104+
}
105+
else {
106+
labels = label;
107+
}
108+
}
109+
}
110+
}
111+
if (labels !== undefined && labels.length > 0) {
112+
lines = lines.concat(labels);
113+
}
66114
var svgAttrs = Skin_1.default.skin[1];
67115
svgAttrs.width = g.width.toString();
68116
svgAttrs.height = g.height.toString();

built/elkGraph.js

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.buildElkGraph = exports.ElkModel = void 0;
34
var _ = require("lodash");
45
var ElkModel;
56
(function (ElkModel) {
@@ -14,17 +15,18 @@ function buildElkGraph(module) {
1415
ElkModel.edgeIndex = 0;
1516
ElkModel.dummyNum = 0;
1617
var edges = _.flatMap(module.wires, function (w) {
18+
var numWires = w.netName.split(',').length - 2;
1719
// at least one driver and at least one rider and no laterals
1820
if (w.drivers.length > 0 && w.riders.length > 0 && w.laterals.length === 0) {
1921
var ret = [];
20-
route(w.drivers, w.riders, ret);
22+
route(w.drivers, w.riders, ret, numWires);
2123
return ret;
2224
// at least one driver or rider and at least one lateral
2325
}
2426
else if (w.drivers.concat(w.riders).length > 0 && w.laterals.length > 0) {
2527
var ret = [];
26-
route(w.drivers, w.laterals, ret);
27-
route(w.laterals, w.riders, ret);
28+
route(w.drivers, w.laterals, ret, numWires);
29+
route(w.laterals, w.riders, ret, numWires);
2830
return ret;
2931
// at least two drivers and no riders
3032
}
@@ -114,22 +116,41 @@ function addDummy(children) {
114116
children.push(child);
115117
return dummyId;
116118
}
117-
function route(sourcePorts, targetPorts, edges) {
119+
function route(sourcePorts, targetPorts, edges, numWires) {
118120
var newEdges = (_.flatMap(sourcePorts, function (sourcePort) {
119121
var sourceParentKey = sourcePort.parentNode.key;
120122
var sourceKey = sourceParentKey + '.' + sourcePort.key;
123+
var edgeLabel;
124+
if (numWires > 1) {
125+
edgeLabel = [{
126+
id: '',
127+
text: String(numWires),
128+
width: 4,
129+
height: 6,
130+
x: 0,
131+
y: 0,
132+
layoutOptions: {
133+
'org.eclipse.elk.edgeLabels.inline': true,
134+
},
135+
}];
136+
}
121137
return targetPorts.map(function (targetPort) {
122138
var targetParentKey = targetPort.parentNode.key;
123139
var targetKey = targetParentKey + '.' + targetPort.key;
124140
var id = 'e' + ElkModel.edgeIndex;
125141
var edge = {
126142
id: id,
143+
labels: edgeLabel,
127144
sources: [sourceKey],
128145
targets: [targetKey],
129146
};
130147
ElkModel.wireNameLookup[id] = targetPort.wire.netName;
131148
if (sourcePort.parentNode.type !== '$dff') {
132-
edge.layoutOptions = { 'org.eclipse.elk.layered.priority.direction': 10 };
149+
edge.layoutOptions = { 'org.eclipse.elk.layered.priority.direction': 10,
150+
'org.eclipse.elk.edge.thickness': (numWires > 1 ? 2 : 1) };
151+
}
152+
else {
153+
edge.layoutOptions = { 'org.eclipse.elk.edge.thickness': (numWires > 1 ? 2 : 1) };
133154
}
134155
ElkModel.edgeIndex += 1;
135156
return edge;

built/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.render = exports.dumpLayout = void 0;
34
var ELK = require("elkjs");
45
var onml = require("onml");
56
var FlatModule_1 = require("./FlatModule");

0 commit comments

Comments
 (0)