Skip to content

Commit 43f2a78

Browse files
authored
Merge pull request #98 from GordonSmith/CLI_OPTIONS
feat: Add additional options to CLI
2 parents 9e37529 + b05598b commit 43f2a78

File tree

6 files changed

+347
-286
lines changed

6 files changed

+347
-286
lines changed

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
},
4646
{
4747
"name": "CLI",
48-
"program": "${workspaceFolder}/src/cli.js",
48+
"program": "${workspaceFolder}/bin/cli.js",
4949
"request": "launch",
5050
"args": [
51+
"-K neato",
52+
"-n 2",
5153
"./input.dot"
5254
],
5355
"skipFiles": [

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,34 @@ npm install --global @hpcc-js/wasm
3535
Usage: dot-wasm [options] fileOrDot
3636
3737
Options:
38-
--version Show version number [boolean]
39-
-K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage |
40-
patchwork | twopi). By default, dot is used.
41-
-T, --format Set output language to one of the supported formats (svg, dot,
42-
json, dot_json, xdot_json, plain, plain-ext). By default, svg
43-
is produced.
44-
-h, --help Show help [boolean]
38+
--version Show version number [boolean]
39+
-K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage
40+
| patchwork | twopi). By default, dot is used.
41+
-T, --format Set output language to one of the supported formats (svg,
42+
dot, json, dot_json, xdot_json, plain, plain-ext). By
43+
default, svg is produced.
44+
-n, --neato-no-op Sets no-op flag in neato.
45+
"-n 1" assumes neato nodes have already been positioned and
46+
all nodes have a pos attribute giving the positions. It
47+
then performs an optional adjustment to remove node-node
48+
overlap, depending on the value of the overlap attribute,
49+
computes the edge layouts, depending on the value of the
50+
splines attribute, and emits the graph in the appropriate
51+
format.
52+
"-n 2" Use node positions as specified, with no adjustment
53+
to remove node-node overlaps, and use any edge layouts
54+
already specified by the pos attribute. neato computes an
55+
edge layout for any edge that does not have a pos
56+
attribute. As usual, edge layout is guided by the splines
57+
attribute.
58+
-y, --invert-y By default, the coordinate system used in generic output
59+
formats, such as attributed dot, extended dot, plain and
60+
plain-ext, is the standard cartesian system with the origin
61+
in the lower left corner, and with increasing y coordinates
62+
as points move from bottom to top. If the -y flag is used,
63+
the coordinate system is inverted, so that increasing
64+
values of y correspond to movement from top to bottom.
65+
-h, --help Show help [boolean]
4566
4667
Examples:
4768
dot-wasm -K neato -T xdot ./input.dot Execute NEATO layout and outputs XDOT

bin/cli.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const yargs = require("yargs/yargs")(process.argv.slice(2))
1515
.alias("T", "format")
1616
.nargs("T", 1)
1717
.describe("T", "Set output language to one of the supported formats (svg, dot, json, dot_json, xdot_json, plain, plain-ext). By default, svg is produced.")
18+
.alias("n", "neato-no-op")
19+
.nargs("n", 1)
20+
.describe("n", "Sets no-op flag in neato.\n\"-n 1\" assumes neato nodes have already been positioned and all nodes have a pos attribute giving the positions. It then performs an optional adjustment to remove node-node overlap, depending on the value of the overlap attribute, computes the edge layouts, depending on the value of the splines attribute, and emits the graph in the appropriate format.\n\"-n 2\" Use node positions as specified, with no adjustment to remove node-node overlaps, and use any edge layouts already specified by the pos attribute. neato computes an edge layout for any edge that does not have a pos attribute. As usual, edge layout is guided by the splines attribute.")
21+
.alias("y", "invert-y")
22+
.nargs("y", 0)
23+
.describe("y", "By default, the coordinate system used in generic output formats, such as attributed dot, extended dot, plain and plain-ext, is the standard cartesian system with the origin in the lower left corner, and with increasing y coordinates as points move from bottom to top. If the -y flag is used, the coordinate system is inverted, so that increasing values of y correspond to movement from top to bottom.")
1824
.help("h")
1925
.alias("h", "help")
2026
.epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
@@ -29,7 +35,21 @@ try {
2935
} else {
3036
dot = argv._[0];
3137
}
32-
gvMod.graphviz.layout(dot, argv.format ?? "svg", argv.layout ?? "dot").then(response => {
38+
39+
if (argv.n && argv.layout.trim() !== "neato") {
40+
throw new Error("-n option is only supported with -T neato");
41+
}
42+
43+
const ext = {
44+
};
45+
if (argv.n) {
46+
ext.nop = parseInt(argv.n);
47+
}
48+
if (argv.y) {
49+
ext.yInvert = true;
50+
}
51+
52+
gvMod.graphviz.layout(dot, argv.format?.trim() ?? "svg", argv.layout?.trim() ?? "dot", ext).then(response => {
3353
console.log(response);
3454
}).catch(e => {
3555
console.error(e.message);

0 commit comments

Comments
 (0)