Created
April 23, 2015 07:28
-
-
Save mountainstorm/e459b8ddb39b0b494ba2 to your computer and use it in GitHub Desktop.
Pretty Graphviz charts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import xml.etree.ElementTree as ET | |
| GRAPHVIZ_PT_2SVG = 3.5 # conversion from gv pt size to svg units | |
| namespaces = { | |
| u'svg': u'http://www.w3.org/2000/svg', | |
| u'xlink': u'http://www.w3.org/1999/xlink' | |
| } | |
| if __name__ == u'__main__': | |
| # digraph world { | |
| # bgcolor="#2e3e56" | |
| # pad="0.5" /* add padding round the edge of the graph */ | |
| # /* | |
| # rankdir="LR" make graph layout left->right rather than top->bottom | |
| # graph [fontname="Helvetica Neue", fontcolor="#fcfcfc"] | |
| # labelloc="t" label at top | |
| # label="Test Setup" | |
| # dark blue (background): #2e3e56 | |
| # white (text/lines): #fcfcfc | |
| # dark line (hidden lines): #445773 | |
| # red: #ea555b - crashes | |
| # yellow: #edad56 - nodes in target | |
| # gold: #AB6D16 - static libs | |
| # dark green: #29b89d | |
| # purple: #9362a8 | |
| # pink: #f2688d - buckets | |
| # green: #a5cf80 - 3rd party library | |
| # blue: #8eabd9 - start | |
| # */ | |
| # node [shape="circle", width="0.625", style="solid", fillcolor="#edad56", color="#edad56", penwidth="3", label=""] | |
| # edge [color="#fcfcfc", penwidth="2", fontname="helvetica Neue Ultra Light"] | |
| ellipse_pad = 1.5 | |
| tree = ET.parse(u'test.svg') | |
| root = tree.getroot() | |
| # [optional] remove titles | |
| xtitle = u'svg:title' | |
| for titleparent in root.findall(u'.//%s/..' % xtitle, namespaces): | |
| for title in titleparent.findall(xtitle, namespaces): | |
| titleparent.remove(title) | |
| # remove the extra padding around ellipses | |
| r = ellipse_pad * GRAPHVIZ_PT_2SVG | |
| for ellipse in root.findall(u'.//svg:ellipse', namespaces): | |
| ellipse.attrib[u'rx'] = str(float(ellipse.attrib[u'rx']) - r) | |
| ellipse.attrib[u'ry'] = str(float(ellipse.attrib[u'ry']) - r) | |
| tree.write('test1.svg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment