lotas / contentful-graph

Visual representation of contentful content models in form of graphs
https://www.contentful.com/blog/2017/08/08/how-to-quickly-visualize-your-content-model/
MIT License
59 stars 6 forks source link

Use content type id's as dot node id's and escape labels #7

Closed axe312ger closed 3 years ago

axe312ger commented 6 years ago

Hey there,

great tool, we love it here at Contentful and use it a lot internally :)

I discovered a few problems with more complex data models, just want to list them here, hoping to find time to file a pull request on my own.

The actual problem:

When having complex content type names with special chars like Layout > Image, the id of the dot-node or the label might be invalid:

digraph obj {
  "Layout > Image" [label="{Layout > Image ... }"];
  "Layout > Text" [label="{Layout > Text ... }"];

  "Layout > Image" -> "Layout > Text"
}

(This actually works but in more complex tests, this broke the graphviz rendering)

I'd love to see output like this, it might also be more readable:

digraph obj {
  layout_image [label="{Layout \> Image ... }"];
  layout_text [label="{Layout \> Text ... }"];

  layout_image -> layout_text
}
  1. Instead of content type name I took the content type id as dot node id
  2. I escaped the label text to avoid problems with special chars.

Thanks a lot, Benedikt

lotas commented 6 years ago

Hey Benedikt, thanks a lot for sharing this. I'm currently on vacations, so please excuse delayed response.

Would you mind providing a sample output to see how graphviz behaves? Thank you!

Swissbite commented 3 years ago

I was digging into this issue a bit and there was a change in the Contentful behavior with the id's.

Some time ago, the ID in the field sys.id for a given model was some random hash. Now, they are using the same value as they use in the API, which is a readable name.

We could use this ID for internal representation, which solves several problems:

Swissbite commented 3 years ago

I could also identify an example with issues rendering: Labels with an unescaped > are reporting issues on dot - graphviz version 2.43.0 (0)

The content model of the Contentful example app has these labels.

My first attempt would be to escape the characters <>\| because they have a "meaning" in the dot syntax in the label field.