-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example how to load netlistsvg json #26
- Loading branch information
Showing
4 changed files
with
827 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
This involves: | ||
* creating of hwMeta property | ||
* elkjs 0.7.1 -> 0.7.0 conversion | ||
* "properties" vs "layoutOptions" | ||
* edge source/target format ([node.id, port.id] vs port.id only) | ||
*/ | ||
|
||
|
||
function netlistsvgToD3HwschematicCollectParentsOfPorts(netlistsvgJson, res) { | ||
(netlistsvgJson.ports || []).forEach(p => { | ||
res[p.id] = netlistsvgJson.id; | ||
}); | ||
(netlistsvgJson.children || []).forEach(c => { | ||
netlistsvgToD3HwschematicCollectParentsOfPorts(c, res); | ||
}); | ||
} | ||
|
||
function netlistsvgToD3HwschematicPort(netlistsvgPort) { | ||
netlistsvgPort.children = []; | ||
netlistsvgPort.direction = netlistsvgPort.x <= 0 ? "INPUT" : "OUTPUT"; | ||
var name = netlistsvgPort.id; | ||
var labels = netlistsvgPort.labels; | ||
if (labels && labels.length) { | ||
name = labels[0].text | ||
} | ||
netlistsvgPort.hwMeta = { | ||
"connectedAsParent": false, | ||
"level": 0, | ||
"name": name, | ||
}; | ||
netlistsvgPort.properties = netlistsvgPort.layoutOptions || {}; | ||
netlistsvgPort.properties.side = netlistsvgPort.x <= 0 ? "WEST" : "EAST"; | ||
|
||
delete netlistsvgPort["labels"]; | ||
|
||
return netlistsvgPort; | ||
} | ||
|
||
function netlistsvgToD3HwschematicEdge(netlistsvgEdge, parentsOfPorts) { | ||
netlistsvgEdge.sources = netlistsvgEdge.sources.map(s => [parentsOfPorts[s], s]); | ||
netlistsvgEdge.targets = netlistsvgEdge.targets.map(t => [parentsOfPorts[t], t]); | ||
return netlistsvgEdge; | ||
} | ||
|
||
function _netlistsvgToD3Hwschematic(netlistsvgJson, parentsOfPorts) { | ||
netlistsvgJson.properties = netlistsvgJson.layoutOptions || {}; | ||
var children = netlistsvgJson.children; | ||
if (children) { | ||
netlistsvgJson.children = children.map(c => _netlistsvgToD3Hwschematic(c, parentsOfPorts)); | ||
} | ||
|
||
var name = netlistsvgJson.id; | ||
var labels = netlistsvgJson.labels; | ||
if (labels && labels.length) | ||
labels = labels[0].text; | ||
|
||
netlistsvgJson.hwMeta = { | ||
"name": name, | ||
"maxId": 0, | ||
}; | ||
|
||
var ports = netlistsvgJson.ports; | ||
if (ports && ports.length) { | ||
netlistsvgJson.ports = ports.map(netlistsvgToD3HwschematicPort); | ||
} | ||
var edges = netlistsvgJson.edges; | ||
if (edges && edges.length) { | ||
netlistsvgJson.edges = edges.map(e => netlistsvgToD3HwschematicEdge(e, parentsOfPorts)); | ||
} | ||
|
||
|
||
delete netlistsvgJson["labels"]; | ||
|
||
return netlistsvgJson; | ||
} | ||
|
||
|
||
function netlistsvgToD3Hwschematic(netlistsvgJson) { | ||
var parentsOfPorts = {}; | ||
netlistsvgToD3HwschematicCollectParentsOfPorts(netlistsvgJson, parentsOfPorts); | ||
return _netlistsvgToD3Hwschematic(netlistsvgJson, parentsOfPorts); | ||
} |
Oops, something went wrong.