Skip to content

Commit

Permalink
Add "reduce" option
Browse files Browse the repository at this point in the history
This addresses issue #185.
  • Loading branch information
mdaines committed Aug 21, 2023
1 parent 584550e commit 5c9cbdc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/viz/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions packages/viz/src/module/viz.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <emscripten.h>

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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/viz/src/viz.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
14 changes: 14 additions & 0 deletions packages/viz/test/standalone.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/viz/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type RenderOptions = {
format?: string;
engine?: string;
yInvert?: boolean;
reduce?: boolean;
defaultAttributes?: DefaultAttributes
};

Expand Down

0 comments on commit 5c9cbdc

Please sign in to comment.