Projet

Général

Profil

0001-workflows-adapt-graphviz-svg-postprocessing-for-2.40.patch

Frédéric Péters, 14 juillet 2019 17:27

Télécharger (3,95 ko)

Voir les différences:

Subject: [PATCH] workflows: adapt graphviz svg postprocessing for 2.40
 (#23492)

 wcs/admin/workflows.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
wcs/admin/workflows.py
63 63
        del node.attrib[att]
64 64

  
65 65

  
66
def remove_style(node, top, colours, white_text=False):
66
def adjust_style(node, top, colours, white_text=False, colour_class=None):
67 67
    remove_tag(node, TITLE)
68
    if node.get('class') and node.get('class').startswith('node '):
69
        colour_class = node.get('class').split()[-1]
68 70
    if (node.get('fill'), node.get('stroke')) in (
69 71
            ('white', 'white'), ('white', 'none')):
70 72
        # this is the general white background, reduce it to a dot
......
73 75
        node.attrib['fill'] = 'white'
74 76
    for child in node:
75 77
        remove_attribute(child, XLINK_TITLE)
78
        if child.tag == '{http://www.w3.org/2000/svg}polygon' and colour_class:
79
            # for compatibility with graphviz >= 2.40 replace fill attribute
80
            # with the original colour name.
81
            child.attrib['fill'] = colour_class
76 82
        if child.get('fill') in colours:
77 83
            matching_hexa = colours.get(child.get('fill'))
78 84
            child.attrib['fill'] = '#' + matching_hexa
......
84 90
        if child.get('font-size'):
85 91
            child.attrib['font-size'] = str(float(child.attrib['font-size'])*0.8)
86 92
        remove_attribute(child, 'style')
87
        remove_style(child, top, colours, white_text=white_text)
93
        adjust_style(child, top, colours, white_text=white_text, colour_class=colour_class)
88 94

  
89 95
def graphviz_post_treatment(content, colours, include=False):
90 96
    ''' Remove all svg:title and top-level svg:polygon nodes, remove style
......
104 110

  
105 111
    for root in tree:
106 112
        remove_tag(root, TITLE)
107
        # remove_tag(root, POLYGON)
108 113
        for child in root:
109
            remove_style(child, child, colours)
114
            adjust_style(child, child, colours)
110 115
    return ET.tostring(tree)
111 116

  
112 117
def graphviz(workflow, url_prefix='', select=None, svg=True,
113 118
        include=False):
114 119
    out = StringIO()
115 120
    # a list of colours known to graphviz, they will serve as key to get back
116
    # to the colours defined in wcs.
121
    # to the colours defined in wcs, they are used as color attributes in
122
    # graphviz (<= 2.38) then as class attribute on node elements for 2.40 and
123
    # later.
117 124
    graphviz_colours = [
118 125
        'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige',
119 126
        'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown',
......
129 136
        'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory',
130 137
        'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon',
131 138
        'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow',
132
        'lightgray', 'lightgreen', 'lightgrey', 'lightpink', ]
139
        'lightgray', 'lightgrey', 'lightpink', ]
133 140

  
134 141
    colours = {}
135 142
    revert_colours = {}
......
148 155
                colours[status.colour] = graphviz_colours.pop()
149 156
                revert_colours[colours[status.colour]] = status.colour
150 157
            print >>out, ',color=%s' % colours[status.colour]
158
            print >>out, ',class=%s' % colours[status.colour]
151 159
        print >>out, ' URL="%sstatus/%s/"];' % (url_prefix, i)
152 160

  
153 161
    for status in workflow.possible_status:
154
-