pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.68k stars 530 forks source link

Example (not an issue) #367

Closed dan-bar-dov closed 5 years ago

dan-bar-dov commented 5 years ago

Thought I'd share. I wanted to make visual modifications to the graphs, this is a working example of what I came up with. Probably this can be added to an example.

def create_graph():
    class Model:
        pass

    m = Model()
    CustomGraphMachine.machine_attributes['ratio'] = '0.471'
    machine = CustomGraphMachine(m, states=session_states, transitions=session_trans, initial='INITIAL',
                                 show_conditions=True, show_state_attributes=True)

    machine.style_attributes['node']['fail'] = {'fillcolor': 'brown1'}
    machine.style_attributes['node']['transient'] = {'fillcolor': 'gold'}
    machine.style_attributes['node']['target'] = {'fillcolor': 'chartreuse'}

    for s in transient_states:
        machine.model_graphs[m].set_node_style(s['name'], 'transient')
    for s in target_states:
        machine.model_graphs[m].set_node_style(s['name'], 'target')
    for s in fail_states:
        machine.model_graphs[m].set_node_style(s['name'], 'fail')

    # draw the whole graph ...
    m.get_graph().draw('state_diagram.png', prog='dot')
aleneum commented 5 years ago

Hi @dan-bar-dov,

Probably this can be added to an example.

it surely can. I added it to the example GraphMachine notebook here (unfortunately, anchor links don't work on Github). Thanks for the input. Much appreciated!