I wonder if we have any example for using a template language to generate the dot files. I’m trying to rewrite my plugin Graphvidian (importing data from Obsidian).
Good question. This is an on-going need.
Here are some answers from the forum & from stackoverflow:
- Using node attributes in HTML style label
- graphviz - Set pre-defined node styles? - Stack Overflow
- How can I create named edge "types" in Graphviz/dot/neato? - Stack Overflow
-
flowchart - Can you build reusable styles in GraphViz? - Stack Overflow
And future solutions: - [Other] [New Feature Request] Add a CSS-like "class" attribute (#694) · Issues · graphviz / graphviz · GitLab
- Styles for GraphViz (#1566) · Issues · graphviz / graphviz · GitLab
- [Other] Classes for more layout less code (#673) · Issues · graphviz / graphviz · GitLab
Not entirely sure if this is what the OP is after, but the Graphviz language is partly designed such that the C pre-processor can be used on sources. So you can do some creative things with C macros.
For something more advanced you might want to use something like Jinja.
Are there any project that already use template language for graphviz so that I can use and don’t have to reinvent the wheel?
You might search github & gitlab, otherwise reinventing the wheel.
The tricky bit in templating is usually the string-escaping for different contexts. So you probably can’t just use (say) an HTML templating engine and use that for Graphviz; Graphviz probably has different escaping rules for strings.
Without knowing much about your problem you’re trying to solve, usually instead of templating, I’d encourage using Graphviz libraries/APIs to build up a dot-string then output that. Less likely to screw up the string-escaping.
if there is no problem from string-escaping, would there be any other advantages of using the API to build up the dot string?
Depends what problem you’re trying to solve?
Well I just want to auto generate graphs with data from Obsidian API (Javascript)