From 50c78463c0d1c1f86aeec3a2d1ae8840bbf785e1 Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Fri, 28 Jul 2023 17:09:07 +0800 Subject: [PATCH] `NetRenderer` -- format to simple text --- .../diff-list.inet.one-two-soles.finial.txt | 22 +++++++++- .../diff-list.inet.one-two-soles.initial.txt | 31 ++++++++++++- .../diff-list.inet.two-two-soles.finial.txt | 28 +++++++++++- .../diff-list.inet.two-two-soles.initial.txt | 37 +++++++++++++++- docs/tests/list.inet.six-soles.finial.txt | 37 +++++++++++++++- docs/tests/list.inet.six-soles.initial.txt | 43 ++++++++++++++++++- docs/tests/nat.inet.four.finial.txt | 13 +++++- docs/tests/nat.inet.four.initial.txt | 31 ++++++++++++- docs/tests/nat.inet.two.finial.txt | 7 ++- docs/tests/nat.inet.two.initial.txt | 13 +++++- src/renderers/NetRenderer.ts | 22 +++++----- 11 files changed, 262 insertions(+), 22 deletions(-) diff --git a/docs/tests/diff-list.inet.one-two-soles.finial.txt b/docs/tests/diff-list.inet.one-two-soles.finial.txt index 3cbc8e2a..cdea0451 100644 --- a/docs/tests/diff-list.inet.one-two-soles.finial.txt +++ b/docs/tests/diff-list.inet.one-two-soles.finial.txt @@ -1 +1,21 @@ -graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#8" -- "sole#7" [label="1-0"]; "sole#7"; "cons#8"; "cons#8" -- "cons#6" [label="0-2"]; "cons#6"; "cons#8"; "diff#13" -- "cons#8" [label="1-2"]; "cons#8"; "diff#13"; "cons#6" -- "cons#2" [label="0-0"]; "cons#2"; "cons#6"; "diff#13" -- "cons#2" [label="0-2"]; "cons#2"; "diff#13"; "diff#13(2)" -- "diff#13"; "diff#13"; "diff#13(2)"; } \ No newline at end of file +cons#2 -- sole#1 [label="1-0"] +sole#1 +cons#2 +cons#6 -- sole#5 [label="1-0"] +sole#5 +cons#6 +cons#8 -- sole#7 [label="1-0"] +sole#7 +cons#8 +cons#8 -- cons#6 [label="0-2"] +cons#6 +cons#8 +diff#13 -- cons#8 [label="1-2"] +cons#8 +diff#13 +cons#6 -- cons#2 [label="0-0"] +cons#2 +cons#6 +diff#13 -- cons#2 [label="0-2"] +cons#2 +diff#13 \ No newline at end of file diff --git a/docs/tests/diff-list.inet.one-two-soles.initial.txt b/docs/tests/diff-list.inet.one-two-soles.initial.txt index af1481aa..92fc9549 100644 --- a/docs/tests/diff-list.inet.one-two-soles.initial.txt +++ b/docs/tests/diff-list.inet.one-two-soles.initial.txt @@ -1 +1,30 @@ -graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "diff#3" -- "cons#2" [label="1-2"]; "cons#2"; "diff#3"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#8" -- "sole#7" [label="1-0"]; "sole#7"; "cons#8"; "cons#8" -- "cons#6" [label="0-2"]; "cons#6"; "cons#8"; "diff#9" -- "cons#8" [label="1-2"]; "cons#8"; "diff#9"; "diff-append#10" -- "diff#3" [label="0-2"]; "diff#3"; "diff-append#10"; "cons#2" -- "diff#3" [label="0-0"]; "diff#3"; "cons#2"; "cons#6" -- "diff#9" [label="0-0"]; "diff#9"; "cons#6"; "diff-append#10" -- "diff#9" [label="1-2" color=red]; "diff#9"; "diff-append#10"; "diff-append#10(2)" -- "diff-append#10"; "diff-append#10"; "diff-append#10(2)"; } \ No newline at end of file +cons#2 -- sole#1 [label="1-0"] +sole#1 +cons#2 +diff#3 -- cons#2 [label="1-2"] +cons#2 +diff#3 +cons#6 -- sole#5 [label="1-0"] +sole#5 +cons#6 +cons#8 -- sole#7 [label="1-0"] +sole#7 +cons#8 +cons#8 -- cons#6 [label="0-2"] +cons#6 +cons#8 +diff#9 -- cons#8 [label="1-2"] +cons#8 +diff#9 +diff-append#10 -- diff#3 [label="0-2"] +diff#3 +diff-append#10 +cons#2 -- diff#3 [label="0-0"] +diff#3 +cons#2 +cons#6 -- diff#9 [label="0-0"] +diff#9 +cons#6 +diff-append#10 -- diff#9 [label="1-2" color=red] +diff#9 +diff-append#10 \ No newline at end of file diff --git a/docs/tests/diff-list.inet.two-two-soles.finial.txt b/docs/tests/diff-list.inet.two-two-soles.finial.txt index cf546d8e..01b360d7 100644 --- a/docs/tests/diff-list.inet.two-two-soles.finial.txt +++ b/docs/tests/diff-list.inet.two-two-soles.finial.txt @@ -1 +1,27 @@ -graph { "cons#16" -- "sole#15" [label="1-0"]; "sole#15"; "cons#16"; "cons#18" -- "sole#17" [label="1-0"]; "sole#17"; "cons#18"; "cons#18" -- "cons#16" [label="0-2"]; "cons#16"; "cons#18"; "cons#22" -- "sole#21" [label="1-0"]; "sole#21"; "cons#22"; "cons#24" -- "sole#23" [label="1-0"]; "sole#23"; "cons#24"; "cons#24" -- "cons#22" [label="0-2"]; "cons#22"; "cons#24"; "diff#29" -- "cons#24" [label="1-2"]; "cons#24"; "diff#29"; "cons#22" -- "cons#16" [label="0-0"]; "cons#16"; "cons#22"; "diff#29" -- "cons#18" [label="0-2"]; "cons#18"; "diff#29"; "diff#29(2)" -- "diff#29"; "diff#29"; "diff#29(2)"; } \ No newline at end of file +cons#16 -- sole#15 [label="1-0"] +sole#15 +cons#16 +cons#18 -- sole#17 [label="1-0"] +sole#17 +cons#18 +cons#18 -- cons#16 [label="0-2"] +cons#16 +cons#18 +cons#22 -- sole#21 [label="1-0"] +sole#21 +cons#22 +cons#24 -- sole#23 [label="1-0"] +sole#23 +cons#24 +cons#24 -- cons#22 [label="0-2"] +cons#22 +cons#24 +diff#29 -- cons#24 [label="1-2"] +cons#24 +diff#29 +cons#22 -- cons#16 [label="0-0"] +cons#16 +cons#22 +diff#29 -- cons#18 [label="0-2"] +cons#18 +diff#29 \ No newline at end of file diff --git a/docs/tests/diff-list.inet.two-two-soles.initial.txt b/docs/tests/diff-list.inet.two-two-soles.initial.txt index 7273b295..651ff2ba 100644 --- a/docs/tests/diff-list.inet.two-two-soles.initial.txt +++ b/docs/tests/diff-list.inet.two-two-soles.initial.txt @@ -1 +1,36 @@ -graph { "cons#16" -- "sole#15" [label="1-0"]; "sole#15"; "cons#16"; "cons#18" -- "sole#17" [label="1-0"]; "sole#17"; "cons#18"; "cons#18" -- "cons#16" [label="0-2"]; "cons#16"; "cons#18"; "diff#19" -- "cons#18" [label="1-2"]; "cons#18"; "diff#19"; "cons#22" -- "sole#21" [label="1-0"]; "sole#21"; "cons#22"; "cons#24" -- "sole#23" [label="1-0"]; "sole#23"; "cons#24"; "cons#24" -- "cons#22" [label="0-2"]; "cons#22"; "cons#24"; "diff#25" -- "cons#24" [label="1-2"]; "cons#24"; "diff#25"; "diff-append#26" -- "diff#19" [label="0-2"]; "diff#19"; "diff-append#26"; "cons#16" -- "diff#19" [label="0-0"]; "diff#19"; "cons#16"; "cons#22" -- "diff#25" [label="0-0"]; "diff#25"; "cons#22"; "diff-append#26" -- "diff#25" [label="1-2" color=red]; "diff#25"; "diff-append#26"; "diff-append#26(2)" -- "diff-append#26"; "diff-append#26"; "diff-append#26(2)"; } \ No newline at end of file +cons#16 -- sole#15 [label="1-0"] +sole#15 +cons#16 +cons#18 -- sole#17 [label="1-0"] +sole#17 +cons#18 +cons#18 -- cons#16 [label="0-2"] +cons#16 +cons#18 +diff#19 -- cons#18 [label="1-2"] +cons#18 +diff#19 +cons#22 -- sole#21 [label="1-0"] +sole#21 +cons#22 +cons#24 -- sole#23 [label="1-0"] +sole#23 +cons#24 +cons#24 -- cons#22 [label="0-2"] +cons#22 +cons#24 +diff#25 -- cons#24 [label="1-2"] +cons#24 +diff#25 +diff-append#26 -- diff#19 [label="0-2"] +diff#19 +diff-append#26 +cons#16 -- diff#19 [label="0-0"] +diff#19 +cons#16 +cons#22 -- diff#25 [label="0-0"] +diff#25 +cons#22 +diff-append#26 -- diff#25 [label="1-2" color=red] +diff#25 +diff-append#26 \ No newline at end of file diff --git a/docs/tests/list.inet.six-soles.finial.txt b/docs/tests/list.inet.six-soles.finial.txt index 9c1fdd64..48ecc4a1 100644 --- a/docs/tests/list.inet.six-soles.finial.txt +++ b/docs/tests/list.inet.six-soles.finial.txt @@ -1 +1,36 @@ -graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "cons#2" -- "null#0" [label="0-0"]; "null#0"; "cons#2"; "cons#4" -- "sole#3" [label="1-0"]; "sole#3"; "cons#4"; "cons#4" -- "cons#2" [label="0-2"]; "cons#2"; "cons#4"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#6" -- "cons#4" [label="0-2"]; "cons#4"; "cons#6"; "cons#17" -- "sole#12" [label="1-0"]; "sole#12"; "cons#17"; "cons#19" -- "sole#10" [label="1-0"]; "sole#10"; "cons#19"; "cons#17" -- "cons#19" [label="0-2"]; "cons#19"; "cons#17"; "cons#21" -- "sole#8" [label="1-0"]; "sole#8"; "cons#21"; "cons#19" -- "cons#21" [label="0-2"]; "cons#21"; "cons#19"; "cons#21" -- "cons#6" [label="0-2"]; "cons#6"; "cons#21"; "cons#17(2)" -- "cons#17"; "cons#17"; "cons#17(2)"; } \ No newline at end of file +cons#2 -- sole#1 [label="1-0"] +sole#1 +cons#2 +cons#2 -- null#0 [label="0-0"] +null#0 +cons#2 +cons#4 -- sole#3 [label="1-0"] +sole#3 +cons#4 +cons#4 -- cons#2 [label="0-2"] +cons#2 +cons#4 +cons#6 -- sole#5 [label="1-0"] +sole#5 +cons#6 +cons#6 -- cons#4 [label="0-2"] +cons#4 +cons#6 +cons#17 -- sole#12 [label="1-0"] +sole#12 +cons#17 +cons#19 -- sole#10 [label="1-0"] +sole#10 +cons#19 +cons#17 -- cons#19 [label="0-2"] +cons#19 +cons#17 +cons#21 -- sole#8 [label="1-0"] +sole#8 +cons#21 +cons#19 -- cons#21 [label="0-2"] +cons#21 +cons#19 +cons#21 -- cons#6 [label="0-2"] +cons#6 +cons#21 \ No newline at end of file diff --git a/docs/tests/list.inet.six-soles.initial.txt b/docs/tests/list.inet.six-soles.initial.txt index 8c017911..2d08404f 100644 --- a/docs/tests/list.inet.six-soles.initial.txt +++ b/docs/tests/list.inet.six-soles.initial.txt @@ -1 +1,42 @@ -graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "cons#2" -- "null#0" [label="0-0"]; "null#0"; "cons#2"; "cons#4" -- "sole#3" [label="1-0"]; "sole#3"; "cons#4"; "cons#4" -- "cons#2" [label="0-2"]; "cons#2"; "cons#4"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#6" -- "cons#4" [label="0-2"]; "cons#4"; "cons#6"; "cons#9" -- "sole#8" [label="1-0"]; "sole#8"; "cons#9"; "cons#9" -- "null#7" [label="0-0"]; "null#7"; "cons#9"; "cons#11" -- "sole#10" [label="1-0"]; "sole#10"; "cons#11"; "cons#11" -- "cons#9" [label="0-2"]; "cons#9"; "cons#11"; "cons#13" -- "sole#12" [label="1-0"]; "sole#12"; "cons#13"; "cons#13" -- "cons#11" [label="0-2"]; "cons#11"; "cons#13"; "append#14" -- "cons#6" [label="0-2"]; "cons#6"; "append#14"; "append#14" -- "cons#13" [label="1-2" color=red]; "cons#13"; "append#14"; "append#14(2)" -- "append#14"; "append#14"; "append#14(2)"; } \ No newline at end of file +cons#2 -- sole#1 [label="1-0"] +sole#1 +cons#2 +cons#2 -- null#0 [label="0-0"] +null#0 +cons#2 +cons#4 -- sole#3 [label="1-0"] +sole#3 +cons#4 +cons#4 -- cons#2 [label="0-2"] +cons#2 +cons#4 +cons#6 -- sole#5 [label="1-0"] +sole#5 +cons#6 +cons#6 -- cons#4 [label="0-2"] +cons#4 +cons#6 +cons#9 -- sole#8 [label="1-0"] +sole#8 +cons#9 +cons#9 -- null#7 [label="0-0"] +null#7 +cons#9 +cons#11 -- sole#10 [label="1-0"] +sole#10 +cons#11 +cons#11 -- cons#9 [label="0-2"] +cons#9 +cons#11 +cons#13 -- sole#12 [label="1-0"] +sole#12 +cons#13 +cons#13 -- cons#11 [label="0-2"] +cons#11 +cons#13 +append#14 -- cons#6 [label="0-2"] +cons#6 +append#14 +append#14 -- cons#13 [label="1-2" color=red] +cons#13 +append#14 \ No newline at end of file diff --git a/docs/tests/nat.inet.four.finial.txt b/docs/tests/nat.inet.four.finial.txt index 598fc468..8de95830 100644 --- a/docs/tests/nat.inet.four.finial.txt +++ b/docs/tests/nat.inet.four.finial.txt @@ -1 +1,12 @@ -graph { "add1#9" -- "zero#8" [label="0-0"]; "zero#8"; "add1#9"; "add1#23" -- "add1#25" [label="0-1"]; "add1#25"; "add1#23"; "add1#25" -- "add1#27" [label="0-1"]; "add1#27"; "add1#25"; "add1#27" -- "add1#9" [label="0-1"]; "add1#9"; "add1#27"; "add1#23(1)" -- "add1#23"; "add1#23"; "add1#23(1)"; } \ No newline at end of file +add1#9 -- zero#8 [label="0-0"] +zero#8 +add1#9 +add1#23 -- add1#25 [label="0-1"] +add1#25 +add1#23 +add1#25 -- add1#27 [label="0-1"] +add1#27 +add1#25 +add1#27 -- add1#9 [label="0-1"] +add1#9 +add1#27 \ No newline at end of file diff --git a/docs/tests/nat.inet.four.initial.txt b/docs/tests/nat.inet.four.initial.txt index e6b1dc8b..496a2596 100644 --- a/docs/tests/nat.inet.four.initial.txt +++ b/docs/tests/nat.inet.four.initial.txt @@ -1 +1,30 @@ -graph { "add1#9" -- "zero#8" [label="0-0"]; "zero#8"; "add1#9"; "add1#11" -- "zero#10" [label="0-0"]; "zero#10"; "add1#11"; "add#12" -- "add1#9" [label="0-1"]; "add1#9"; "add#12"; "add1#14" -- "zero#13" [label="0-0"]; "zero#13"; "add1#14"; "add1#16" -- "zero#15" [label="0-0"]; "zero#15"; "add1#16"; "add#17" -- "add1#14" [label="0-1"]; "add1#14"; "add#17"; "add#18" -- "add#17" [label="1-2"]; "add#17"; "add#18"; "add#18" -- "add#12" [label="0-2"]; "add#12"; "add#18"; "add#12" -- "add1#11" [label="1-1" color=red]; "add1#11"; "add#12"; "add#17" -- "add1#16" [label="1-1" color=red]; "add1#16"; "add#17"; "add#18(2)" -- "add#18"; "add#18"; "add#18(2)"; } \ No newline at end of file +add1#9 -- zero#8 [label="0-0"] +zero#8 +add1#9 +add1#11 -- zero#10 [label="0-0"] +zero#10 +add1#11 +add#12 -- add1#9 [label="0-1"] +add1#9 +add#12 +add1#14 -- zero#13 [label="0-0"] +zero#13 +add1#14 +add1#16 -- zero#15 [label="0-0"] +zero#15 +add1#16 +add#17 -- add1#14 [label="0-1"] +add1#14 +add#17 +add#18 -- add#17 [label="1-2"] +add#17 +add#18 +add#18 -- add#12 [label="0-2"] +add#12 +add#18 +add#12 -- add1#11 [label="1-1" color=red] +add1#11 +add#12 +add#17 -- add1#16 [label="1-1" color=red] +add1#16 +add#17 \ No newline at end of file diff --git a/docs/tests/nat.inet.two.finial.txt b/docs/tests/nat.inet.two.finial.txt index 197b15f1..d437902c 100644 --- a/docs/tests/nat.inet.two.finial.txt +++ b/docs/tests/nat.inet.two.finial.txt @@ -1 +1,6 @@ -graph { "add1#1" -- "zero#0" [label="0-0"]; "zero#0"; "add1#1"; "add1#7" -- "add1#1" [label="0-1"]; "add1#1"; "add1#7"; "add1#7(1)" -- "add1#7"; "add1#7"; "add1#7(1)"; } \ No newline at end of file +add1#1 -- zero#0 [label="0-0"] +zero#0 +add1#1 +add1#7 -- add1#1 [label="0-1"] +add1#1 +add1#7 \ No newline at end of file diff --git a/docs/tests/nat.inet.two.initial.txt b/docs/tests/nat.inet.two.initial.txt index 71a727ba..3ac6c6f4 100644 --- a/docs/tests/nat.inet.two.initial.txt +++ b/docs/tests/nat.inet.two.initial.txt @@ -1 +1,12 @@ -graph { "add1#1" -- "zero#0" [label="0-0"]; "zero#0"; "add1#1"; "add1#3" -- "zero#2" [label="0-0"]; "zero#2"; "add1#3"; "add#4" -- "add1#1" [label="0-1"]; "add1#1"; "add#4"; "add#4" -- "add1#3" [label="1-1" color=red]; "add1#3"; "add#4"; "add#4(2)" -- "add#4"; "add#4"; "add#4(2)"; } \ No newline at end of file +add1#1 -- zero#0 [label="0-0"] +zero#0 +add1#1 +add1#3 -- zero#2 [label="0-0"] +zero#2 +add1#3 +add#4 -- add1#1 [label="0-1"] +add1#1 +add#4 +add#4 -- add1#3 [label="1-1" color=red] +add1#3 +add#4 \ No newline at end of file diff --git a/src/renderers/NetRenderer.ts b/src/renderers/NetRenderer.ts index 447d7782..aec558d1 100644 --- a/src/renderers/NetRenderer.ts +++ b/src/renderers/NetRenderer.ts @@ -14,30 +14,28 @@ export class NetRenderer { const start = formatNode(edge.start.node) const end = formatNode(edge.end.node) const indexes = `${edge.end.index}-${edge.start.index}` - lines.push(`"${end}" -- "${start}" [label="${indexes}"];`) - lines.push(`"${start}";`) - lines.push(`"${end}";`) + lines.push(`${end} -- ${start} [label="${indexes}"]`) + lines.push(`${start}`) + lines.push(`${end}`) } for (const edge of net.actions) { const start = formatNode(edge.start.node) const end = formatNode(edge.end.node) const indexes = `${edge.end.index}-${edge.start.index}` - lines.push(`"${end}" -- "${start}" [label="${indexes}" color=red];`) - lines.push(`"${start}";`) - lines.push(`"${end}";`) + lines.push(`${end} -- ${start} [label="${indexes}" color=red]`) + lines.push(`${start}`) + lines.push(`${end}`) } for (const port of net.portStack) { const start = formatNode(port.node) const end = `${formatNode(port.node)}(${port.index})` - lines.push(`"${end}" -- "${start}";`) - lines.push(`"${start}";`) - lines.push(`"${end}";`) + lines.push(`${end} -- ${start}`) + lines.push(`${start}`) + lines.push(`${end}`) } - const body = lines.join(" ") - - return `graph { ${body} }` + return lines.join("\n") } }