Passing arbitrary data to nodes or edges

Is there a proposal or ongoing discussion to add a data attribute to Graphviz elements (nodes and edges)?

For example:

digraph G {
  a[data="{m: 1, n: 2}"]
  a -> b[data="{x: 1, y: 2}" class="blah"]
}

I think you could do this:

digraph G {
a[data-m=“1” data-n=“2”]
a → b [data-x=“1” data-y=“2” class=“blah”]
}

Graphviz ignores attributes it doesn’t understand. They’ll be preserved during graph processing I think, but they won’t be used by any output format.

Is there a broader goal you’re trying to achieve? That might help come up with ideas.

To be clear, there’s nothing special about “data-”, it’s just an attribute that Graphviz doesn’t do anything with.

In the Before Time, we used to emit some attributes inline with generated code, but I believe there was concern that this would open certain potential exploits, like, draw a graph and it does something unexpected with your .ssh credentials.

Sorry I’m a year late on this thread.
Thanks for the suggestions.

My end goal is to build an architecture diagramming tool that’s based on Graphviz - similar to Mermaidjs but with a more “standard” DSL such as Graphviz. The language is powerful and the only thing I’m struggling with at the moment is figuring out how to “extend” it without introducing any “custom” decorations.

HTML “data” is probably the best route to use at this point.

I’ll keep you posted as I discover more.

Thanks once again for maintaining this forum and helping others :pray:

I tried using data-stuff and it breaks most parsers as they don’t like the hyphen.
dataStuff works fine but it’s obviously “non-standard” in the HTML context.

What html parser can’t deal with data-stuff?

Or is it breaking javascript parsers? There is another way to access the attributes in JS

Sorry, I was not clear earlier.
Parsers that are built to parse Graphviz documents. Example:

Or the online editor which uses viz.js I think

Forgive me if I’m being dense, but if you want to pass arbitrary data attached to nodes/edges but also are using a third-party not-Graphviz parser, how will any changes in Graphviz itself help you?

@smattr - very valid question and apologies if I was not clear.
You are absolutely right - I think I was conflating these concerns.

The dot language specification itself is open to adding anything in a a_list

A lot of the new type-safe parsers try to restrict what can be passed through which is where I assumed the dot specification might be restrictive - but it’s not.

However, I still think there’s still merit in considering a “blessed” way for passing data to graphviz.

What I have ended up with in my implementation is a “superset” of graphviz.

digraph Frontend {
  browser -> frontendApp [label="Web Request/Response" dir="both" fminit="source"];
  frontendApp -> apiGateway [label="API Request/Response" dir="both" fminit="source"];
}

Thanks once again.