tracevis_adds_legends_to_graph_and_refactors / scripts /

# Create the legend
import Image, ImageDraw, ImageFont
import acts

font=ImageFont.truetype('LiberationSans-Bold.ttf', 22)

SIZE = (32, 32)
BLACK = (0, 0, 0)

def _draw_legend(d, fill_color, outline_color, pos_x, pos_y, name):
    d.rectangle((pos_x, pos_y, pos_x+SIZE[0], pos_y+SIZE[1]), fill_color, outline_color)
    w,h = font.getsize(name)
    d.text((pos_x + SIZE[0] + 5, pos_y+SIZE[1]/2-h/2), name, fill=BLACK, font=font)

def draw_lengends(d, fill_colors, outline_color, pos_x, pos_y, names):      
    for i, (name, fill_color) in enumerate(zip(names, fill_colors)):
        _draw_legend(d, fill_color, outline_color, i*(pos_x+SIZE[0]+80) , pos_y, name)

if __name__ == '__main__':
    import vis
    im ='RGBA', SIZE)
    d = ImageDraw.Draw(im)

    states = vis.states
    outline_color = BLACK
    for i, c in list(enumerate(states))[1:]:
        draw_legend(d, c, outline_color, 0, 0)'img/%s.png'%acts.states[i])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.