diff --git a/packages/viz/CHANGELOG.md b/packages/viz/CHANGELOG.md index fd03b17f..e732d3fc 100644 --- a/packages/viz/CHANGELOG.md +++ b/packages/viz/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +* Accept a "reduce" option. This has the same effect as using the -x Graphviz command-line option. When using the neato layout engine, it prunes isolated nodes. + * Accept default attributes for graphs, nodes, and edges in render options. This is similar to the -G, -N, -E options provided by the Graphviz command-line. Setting the default shape for nodes: diff --git a/packages/viz/src/module/viz.c b/packages/viz/src/module/viz.c index c0930318..a52ea760 100644 --- a/packages/viz/src/module/viz.c +++ b/packages/viz/src/module/viz.c @@ -2,6 +2,7 @@ #include extern int Y_invert; +extern unsigned char Reduce; extern gvplugin_library_t gvplugin_core_LTX_library; extern gvplugin_library_t gvplugin_dot_layout_LTX_library; @@ -19,6 +20,11 @@ void viz_set_y_invert(int value) { Y_invert = value; } +EMSCRIPTEN_KEEPALIVE +void viz_set_reduce(int value) { + Reduce = value; +} + EMSCRIPTEN_KEEPALIVE char *viz_get_graphviz_version() { GVC_t *context = NULL; diff --git a/packages/viz/src/viz.mjs b/packages/viz/src/viz.mjs index 4773bff7..027290f0 100644 --- a/packages/viz/src/viz.mjs +++ b/packages/viz/src/viz.mjs @@ -158,6 +158,7 @@ function renderInput(module, input, options) { } module.ccall("viz_set_y_invert", "number", ["number"], [options.yInvert ? 1 : 0]); + module.ccall("viz_set_reduce", "number", ["number"], [options.reduce ? 1 : 0]); resultPointer = module.ccall("viz_render_graph", "number", ["number", "string", "string"], [graphPointer, options.format, options.engine]); diff --git a/packages/viz/test/standalone.test.mjs b/packages/viz/test/standalone.test.mjs index 77c344bf..5dd894af 100644 --- a/packages/viz/test/standalone.test.mjs +++ b/packages/viz/test/standalone.test.mjs @@ -135,6 +135,20 @@ describe("standalone", function() { }); }); + it("accepts reduce option", function() { + const result = viz.render("graph { a }", { engine: "neato", reduce: true }); + + assert.deepStrictEqual(result, { + status: "success", + output: `graph { + graph [bb="0,0,0,0"]; + node [label="\\N"]; +} +`, + errors: [] + }); + }); + it("accepts default attributes", function() { const result = viz.render("graph {}", { defaultAttributes: { diff --git a/packages/viz/types/index.d.ts b/packages/viz/types/index.d.ts index 2cb556d5..0784f3e1 100644 --- a/packages/viz/types/index.d.ts +++ b/packages/viz/types/index.d.ts @@ -37,6 +37,7 @@ export type RenderOptions = { format?: string; engine?: string; yInvert?: boolean; + reduce?: boolean; defaultAttributes?: DefaultAttributes };