Docs: save inheritance diagrams as svg and small design changes

This commit is contained in:
neofelis2X
2025-02-14 17:17:26 +01:00
parent 38d27c62b4
commit 86944f5dbb

View File

@@ -10,22 +10,19 @@
#---------------------------------------------------------------------------
# Standard library imports
import os
import sys
import errno
from subprocess import Popen, PIPE
# Phoenix-specific imports
from .utilities import wx2Sphinx, formatExternalLink
from .utilities import formatExternalLink
from .constants import INHERITANCEROOT
ENOENT = getattr(errno, 'ENOENT', 0)
EPIPE = getattr(errno, 'EPIPE', 0)
class InheritanceDiagram:
"""
Given a list of classes, determines the set of classes that they inherit
@@ -123,7 +120,8 @@ class InheritanceDiagram:
def _format_graph_attrs(self, attrs):
return ''.join(['%s=%s;\n' % x for x in list(attrs.items())])
def generate_dot(self, class_summary, name="dummy", graph_attrs={}, node_attrs={}, edge_attrs={}):
def generate_dot(self, class_summary, name="dummy",
graph_attrs={}, node_attrs={}, edge_attrs={}):
"""Generate a graphviz dot graph from the classes that were passed in
to __init__.
@@ -133,18 +131,21 @@ class InheritanceDiagram:
key/value pairs to pass on as graphviz properties.
"""
inheritance_graph_attrs = dict(fontsize=9, ratio='auto', size='""', rankdir="TB")
inheritance_node_attrs = {"align": "center", 'shape': 'box',
'fontsize': 10, 'height': 0.3,
'fontname': '"Vera Sans, DejaVu Sans, Liberation Sans, '
'Arial, Helvetica, sans"', 'style': '"setlinewidth(0.5)"',
'labelloc': 'c', 'fontcolor': 'grey45'}
inheritance_graph_attrs = {"fontsize": 9, "ratio": 'auto',
"size": '""', "rankdir": "TB"}
inheritance_edge_attrs = {'arrowsize': 0.5,
'style': '"setlinewidth(0.5)"',
'color': '"#23238E"',
inheritance_node_attrs = {"align": "center", 'shape': 'box',
'fontsize': 12, 'height': 0.3,
'fontname': '"Vera Sans, DejaVu Sans, Liberation Sans, '
'Arial, Helvetica, sans"', 'style': '"setlinewidth(0.8), rounded"',
'labelloc': 'c', 'fontcolor': 'grey45',
"color": "dodgerblue4"}
inheritance_edge_attrs = {'arrowsize': 0.6,
'style': '"setlinewidth(0.8)"',
'color': 'dodgerblue4',
'dir': 'back',
'arrowtail': 'open',
'arrowtail': 'normal',
}
g_attrs = self.default_graph_attrs.copy()
@@ -163,9 +164,9 @@ class InheritanceDiagram:
this_node_attrs = n_attrs.copy()
if fullname in self.specials:
this_node_attrs['fontcolor'] = 'black'
this_node_attrs['color'] = 'blue'
this_node_attrs['style'] = 'bold'
this_node_attrs['fontcolor'] = 'dodgerblue4'
this_node_attrs['color'] = 'dodgerblue2'
this_node_attrs['style'] = '"bold, rounded"'
if class_summary is None:
# Phoenix base classes, assume there is always a link
@@ -185,7 +186,7 @@ class InheritanceDiagram:
for base_name in bases:
this_edge_attrs = e_attrs.copy()
if fullname in self.specials:
this_edge_attrs['color'] = 'red'
this_edge_attrs['color'] = 'darkorange1'
res.append(' "%s" -> "%s" [%s];\n' %
(base_name, fullname,
@@ -198,7 +199,7 @@ class InheritanceDiagram:
def makeInheritanceDiagram(self, class_summary=None):
"""
Actually generates the inheritance diagram as a PNG file plus the corresponding
Actually generates the inheritance diagram as a SVG file plus the corresponding
MAP file for mouse navigation over the inheritance boxes.
These two files are saved into the ``INHERITANCEROOT`` folder (see `sphinxtools/constants.py`
@@ -209,7 +210,7 @@ class InheritanceDiagram:
:rtype: `tuple`
:returns: a tuple containing the PNG file name and a string representing the content
:returns: a tuple containing the SVG file name and a string representing the content
of the MAP file (with newlines stripped away).
.. note:: The MAP file is deleted as soon as its content has been read.
@@ -224,13 +225,13 @@ class InheritanceDiagram:
else:
filename = self.specials[0]
outfn = os.path.join(static_root, filename + '_inheritance.png')
outfn = os.path.join(static_root, filename + '_inheritance.svg')
mapfile = outfn + '.map'
if os.path.isfile(outfn) and os.path.isfile(mapfile):
with open(mapfile, 'rt') as fid:
map = fid.read()
return os.path.split(outfn)[1], map.replace('\n', ' ')
with open(mapfile, 'rt', encoding="utf-8") as fid:
mp = fid.read()
return os.path.split(outfn)[1], mp.replace('\n', ' ')
code = self.generate_dot(class_summary)
@@ -245,7 +246,7 @@ class InheritanceDiagram:
if os.path.isfile(mapfile):
os.remove(mapfile)
dot_args.extend(['-Tpng', '-o' + outfn])
dot_args.extend(['-Tsvg', '-o' + outfn])
dot_args.extend(['-Tcmapx', '-o' + mapfile])
popen_args = {
@@ -283,7 +284,7 @@ class InheritanceDiagram:
if p.returncode != 0:
print(('\nERROR: Graphviz `dot` command exited with error:\n[stderr]\n%s\n[stdout]\n%s\n\n' % (stderr, stdout)))
with open(mapfile, 'rt') as fid:
map = fid.read()
with open(mapfile, 'rt', encoding="utf-8") as fid:
mp = fid.read()
return os.path.split(outfn)[1], map.replace('\n', ' ')
return os.path.split(outfn)[1], mp.replace('\n', ' ')