hpcc-systems / hpcc-js-wasm

HPCC-Systems Web-Assembly (JavaScript)
https://hpcc-systems.github.io/hpcc-js-wasm/
Apache License 2.0
316 stars 23 forks source link

trailing commas issue with Graphviz json output #117

Closed phodal closed 2 years ago

phodal commented 2 years ago

When only have subgraph with fdp layout with cause the trailing commas issue.

  1. here is Graphviz source code
digraph TicketBooking {
  component=true;layout=fdp;
  node [shape=box style=filled];
  cluster_reservation -> cluster_cinema;
  cluster_reservation -> cluster_movie;
  cluster_reservation -> cluster_user;

  subgraph cluster_cinema {
    label="Cinema(Context)";
  }

  subgraph cluster_movie {
    label="Movie(Context)";
  }

  subgraph cluster_reservation {
    label="Reservation(Context)";
  }

  subgraph cluster_user {
    label="User(Context)";
  }
}
  1. test code:
let output = await graphvizSync().then(async (graph) => {
  return graph.layout(this.content, "json");
});

try {
  fs.writeFileSync("output.json", output);
  output = JSON.parse(output.trim());
} catch (e) {
  console.log(e);
}
  1. output error in edges:
      "_gvid": 3
    },

  ],
  "edges": [
    {
      "_gvid": 0,
      "tail": 0,
      "head": 1,
      "_draw_": 
GordonSmith commented 2 years ago

@phodal did you get a chance to test with the official dot tool?

phodal commented 2 years ago

I just test it with dot -Tjson demo.dot -o demo.json, it seems official dot tool has same problem...

created: https://gitlab.com/graphviz/graphviz/-/issues/2282

GordonSmith commented 2 years ago

@phodal - thanks for testing, that is what I would expect - if you want to move forward, you could use the json5 package: https://json5.org/ which allows trailing commas (as well as some other quality of life improvements).