workflows: adapt graphviz svg postprocessing for 2.40 (#23492)
This commit is contained in:
parent
28a1fdae17
commit
e1d2d38ce4
|
@ -63,8 +63,10 @@ def remove_attribute(node, att):
|
|||
del node.attrib[att]
|
||||
|
||||
|
||||
def remove_style(node, top, colours, white_text=False):
|
||||
def adjust_style(node, top, colours, white_text=False, colour_class=None):
|
||||
remove_tag(node, TITLE)
|
||||
if node.get('class') and node.get('class').startswith('node '):
|
||||
colour_class = node.get('class').split()[-1]
|
||||
if (node.get('fill'), node.get('stroke')) in (
|
||||
('white', 'white'), ('white', 'none')):
|
||||
# this is the general white background, reduce it to a dot
|
||||
|
@ -73,6 +75,10 @@ def remove_style(node, top, colours, white_text=False):
|
|||
node.attrib['fill'] = 'white'
|
||||
for child in node:
|
||||
remove_attribute(child, XLINK_TITLE)
|
||||
if child.tag == '{http://www.w3.org/2000/svg}polygon' and colour_class:
|
||||
# for compatibility with graphviz >= 2.40 replace fill attribute
|
||||
# with the original colour name.
|
||||
child.attrib['fill'] = colour_class
|
||||
if child.get('fill') in colours:
|
||||
matching_hexa = colours.get(child.get('fill'))
|
||||
child.attrib['fill'] = '#' + matching_hexa
|
||||
|
@ -84,7 +90,7 @@ def remove_style(node, top, colours, white_text=False):
|
|||
if child.get('font-size'):
|
||||
child.attrib['font-size'] = str(float(child.attrib['font-size'])*0.8)
|
||||
remove_attribute(child, 'style')
|
||||
remove_style(child, top, colours, white_text=white_text)
|
||||
adjust_style(child, top, colours, white_text=white_text, colour_class=colour_class)
|
||||
|
||||
def graphviz_post_treatment(content, colours, include=False):
|
||||
''' Remove all svg:title and top-level svg:polygon nodes, remove style
|
||||
|
@ -104,16 +110,17 @@ def graphviz_post_treatment(content, colours, include=False):
|
|||
|
||||
for root in tree:
|
||||
remove_tag(root, TITLE)
|
||||
# remove_tag(root, POLYGON)
|
||||
for child in root:
|
||||
remove_style(child, child, colours)
|
||||
adjust_style(child, child, colours)
|
||||
return ET.tostring(tree)
|
||||
|
||||
def graphviz(workflow, url_prefix='', select=None, svg=True,
|
||||
include=False):
|
||||
out = StringIO()
|
||||
# a list of colours known to graphviz, they will serve as key to get back
|
||||
# to the colours defined in wcs.
|
||||
# to the colours defined in wcs, they are used as color attributes in
|
||||
# graphviz (<= 2.38) then as class attribute on node elements for 2.40 and
|
||||
# later.
|
||||
graphviz_colours = [
|
||||
'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige',
|
||||
'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown',
|
||||
|
@ -129,7 +136,7 @@ def graphviz(workflow, url_prefix='', select=None, svg=True,
|
|||
'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory',
|
||||
'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon',
|
||||
'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow',
|
||||
'lightgray', 'lightgreen', 'lightgrey', 'lightpink', ]
|
||||
'lightgray', 'lightgrey', 'lightpink', ]
|
||||
|
||||
colours = {}
|
||||
revert_colours = {}
|
||||
|
@ -148,6 +155,7 @@ def graphviz(workflow, url_prefix='', select=None, svg=True,
|
|||
colours[status.colour] = graphviz_colours.pop()
|
||||
revert_colours[colours[status.colour]] = status.colour
|
||||
print >>out, ',color=%s' % colours[status.colour]
|
||||
print >>out, ',class=%s' % colours[status.colour]
|
||||
print >>out, ' URL="%sstatus/%s/"];' % (url_prefix, i)
|
||||
|
||||
for status in workflow.possible_status:
|
||||
|
|
Loading…
Reference in New Issue