aboutsummaryrefslogtreecommitdiffstats
path: root/src/layout.js
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2021-02-05 18:32:12 +0000
committers-ol <s-ol@users.noreply.github.com>2021-02-05 18:42:02 +0000
commit464174b7e5e4e5c389c896173e8c7ab21badda8a (patch)
tree0f88ffc3db86026f86cb2941e4a05bd8a2753903 /src/layout.js
parentlinks leave shadow (diff)
downloadfedidag-464174b7e5e4e5c389c896173e8c7ab21badda8a.tar.gz
fedidag-464174b7e5e4e5c389c896173e8c7ab21badda8a.zip
clean up UI code
Diffstat (limited to 'src/layout.js')
-rw-r--r--src/layout.js62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/layout.js b/src/layout.js
index b774c31..000d22c 100644
--- a/src/layout.js
+++ b/src/layout.js
@@ -6,41 +6,41 @@ const gv = new Viz({ workerURL: 'lib/lite.render.js' });
export default class Layout {
constructor() {
this.src = 'digraph { node [shape="rectangle"];\n';
- }
+ }
- addNode(id, width, height) {
- this.src += ` "${id}" [fixedsize=true; width=${width / 72}; height=${height / 72}];\n`;
- }
+ addNode(id, width, height) {
+ this.src += ` "${id}" [fixedsize=true; width=${width / 72}; height=${height / 72}];\n`;
+ }
- addLink(from, to) {
- this.src += ` "${from}" -> "${to}";\n`;
- }
+ addLink(from, to) {
+ this.src += ` "${from}" -> "${to}";\n`;
+ }
- async render() {
- this.src += '}';
+ async render() {
+ this.src += '}';
- const info = await gv.renderJSONObject(this.src, { format: 'json0' });
- const [width, height] = info.bb.split(',').map(toNumber).slice(2);
+ const info = await gv.renderJSONObject(this.src, { format: 'json0' });
+ const [width, height] = info.bb.split(',').map(toNumber).slice(2);
const positions = {};
- for (const object of info.objects) {
- const [x, y] = object.pos.split(',').map(toNumber);
- positions[object.name] = [ x, height - y ];
- }
-
- const links = info.edges.map((edge) => {
- const pos = edge.pos.slice(2);
- return pos.split(' ').map(p => {
- const [x, y] = p.split(',');
- return [toNumber(x), height - toNumber(y)];
- });
-
- });
-
- return {
- width, height,
- positions,
- links,
- };
- }
+ for (const object of info.objects) {
+ const [x, y] = object.pos.split(',').map(toNumber);
+ positions[object.name] = [ x, height - y ];
+ }
+
+ const links = info.edges.map((edge) => {
+ const pos = edge.pos.slice(2);
+ return pos.split(' ').map(p => {
+ const [x, y] = p.split(',');
+ return [toNumber(x), height - toNumber(y)];
+ });
+
+ });
+
+ return {
+ width, height,
+ positions,
+ links,
+ };
+ }
}