From cd2d2337ac315fe5709d34ed5503e2f0efb682b0 Mon Sep 17 00:00:00 2001 From: Michael Daines <1383+mdaines@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:16:33 -0400 Subject: [PATCH] Add workaround for #218 --- packages/viz/CHANGELOG.md | 2 ++ packages/viz/src/module/viz.c | 4 ++++ packages/viz/test/render.test.mjs | 23 ++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/viz/CHANGELOG.md b/packages/viz/CHANGELOG.md index c13b5e54..858e56e4 100644 --- a/packages/viz/CHANGELOG.md +++ b/packages/viz/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +* Add a workaround for node names not being used as labels (#218) + ## 3.2.2 * Include types condition in exports diff --git a/packages/viz/src/module/viz.c b/packages/viz/src/module/viz.c index 1622adaf..fc335dbd 100644 --- a/packages/viz/src/module/viz.c +++ b/packages/viz/src/module/viz.c @@ -73,6 +73,10 @@ Agraph_t *viz_read_one_graph(char *string) { Agraph_t *graph = NULL; Agraph_t *other_graph = NULL; + // Workaround for #218. Set the global default node label. + + agattr(NULL, AGNODE, "label", "\\N"); + // Reset errors agseterrf(viz_errorf); diff --git a/packages/viz/test/render.test.mjs b/packages/viz/test/render.test.mjs index 516ab005..43858acf 100644 --- a/packages/viz/test/render.test.mjs +++ b/packages/viz/test/render.test.mjs @@ -290,7 +290,7 @@ stop status: "success", output: "graph {\n\tgraph [_background=123,\n\t\tbb=\"0,0,0,0\"\n\t];\n\tnode [label=\"\\N\"];\n}\n", errors: [ - { level: "warning", message: "Could not parse \"_background\" attribute in graph %1" }, + { level: "warning", message: "Could not parse \"_background\" attribute in graph %3" }, { level: "warning", message: " \"123\"" } ] }); @@ -308,5 +308,26 @@ stop ] }); }); + + it("the graph is read with the default node label set", function() { + const result = viz.render("graph { a; b[label=test] }"); + + assert.deepStrictEqual(result, { + status: "success", + output: `graph { + graph [bb="0,0,126,36"]; + node [label="\\N"]; + a [height=0.5, + pos="27,18", + width=0.75]; + b [height=0.5, + label=test, + pos="99,18", + width=0.75]; +} +`, + errors: [] + }); + }); }); });