Improving dot state machine presentation

Hi everyone.
I am currently doing some sphinx documentation and I am using dot to document our state machine.
For the simple state machine, it seems pretty good, but as things get more complex, I have some difficulties to have a proper render
I would really much enjoy some tips and tricks to improve the readibility if it is possible.
Thank you !

Here the rendered state machine:

And here the code:

digraph G {

    # Init 
    init-> stopped [color=aquamarine4,style=bold,label=<<B>INIT</B><br/> <I>init(0)</I>>, fontcolor=aquamarine4];
   
    # stopped
	stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>START</B><br/> <I>cmd_start(1)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>STOP</B><br/> <I>cmd_stop(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_CLEAR_COUNTERS</B><br/> <I>clear_counters(0)</I>>,fontcolor=aquamarine4];
   
    Con_start -> stopped [color=deeppink4,style=bold];
    Con_start -> w_ptp_time[color = crimson, style=bold,label=<<B>CND_START</B><br/> <I>start(0)</I>>, fontcolor=crimson];
    
    # w_ptp_time
    w_ptp_time-> stopped [color=aquamarine4,style=bold,label=<<B>STOP</B><br/> <I>cmd_stop(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> running [color=aquamarine4,style=bold,label=<<B>PTP_TIME_GOT</B><br/> <I>start_alarm(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_SET_SOURCE</B><br/> <I>set_source(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>, fontcolor=aquamarine4];

    # Running
	running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>STOP</B><br/> <I>cmd_stop(1)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_SET_SOURCE</B><br/> <I>cmd_set_source(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_PTP_ALARM</B><br/> <I>alarm(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>,fontcolor=aquamarine4];

    running -> restarting [color=aquamarine4, style=bold,label=bold, label=<<B>TMR_ALARM</B><br/> <I>stop(0)</I>>,fontcolor=aquamarine4];
    
    Con_stop -> stopping[color = crimson, style=bold,label=<<B>CND_STOP</B><br/> <I>stop(0)</I>>, fontcolor=crimson];
    Con_stop -> running [color=deeppink4,style=bold];
   
    # STOPPING
    stopping-> restarting [color=aquamarine4,style=bold,label=<<B>START</B><br/> <I>cmd_start(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopped [color=aquamarine4,style=bold,label=<<B>CLEAR_ALARM</B><br/> <I>rt_nothing(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopping [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopping [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopping [color=aquamarine4,style=bold,label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>, fontcolor=aquamarine4];
   
    # restarting
    restarting-> stopping [color=aquamarine4,style=bold,label=<<B>STOP</B><br/> <I>cmd_stop(0)</I>>, fontcolor=aquamarine4];
    restarting-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>EVT_CLEAR_ALARM</B><br/> <I>start(0)</I>>, fontcolor=aquamarine4];
    restarting-> restarting [color=aquamarine4,style=bold,label=<<B>REQ_SET_SOURCE</B><br/> <I>set_source(0)</I>>, fontcolor=aquamarine4];
    restarting-> restarting [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>, fontcolor=aquamarine4];
    restarting-> restarting [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>, fontcolor=aquamarine4];
    restarting-> restarting [color=aquamarine4,style=bold,label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>, fontcolor=aquamarine4];
    
	# Declare state
	init [shape=polygon,sides=5, color=lightblue,style=filled, label="Init"];
	w_ptp_time [color=lightblue,style=filled, label="W PTPtime"];
	running [color=lightblue,style=filled, label="Running"];
    stopped [color=lightblue,style=filled, label="Stopped"];
    stopping [color=lightblue,style=filled, label="Stopping"];
    restarting [color=lightblue,style=filled, label="Restarting"];
    
    Con_start [style=filled, shape=point, color=deeppink4];
    Con_stop [style=filled, shape=point, color=deeppink4];	

}

Would you help us understand what specifically you don’t like and what better would look like.

Sure !
The main problem here is about “W PTP time” and “Rotating”, where there is several event that can make the state machine state loop on itself, and for each of these loop, as the other, I write the event that triggered and the function called.
But here, as there is like 5 way to loop, I cannot read correctly all the names. If there was a way to have something like for the state “Stopped” it would be great.
Thanks for the reply !

An “obvious” answer is to use ports (see p.18 of https://www.graphviz.org/pdf/dotguide.pdf). But the loop/port combination is twitchy at best and useless at worst. Here is an example of port-based loops that works pretty well, but I had to add invisible loops to add some size to the visible loops. Look at “restarting”:

digraph G {

    # Init 
    init-> stopped [color=aquamarine4,style=bold,label=<<B>INIT</B><br/> <I>init(0)</I>>, fontcolor=aquamarine4];
   
    # stopped
	stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>START</B><br/> <I>cmd_start(1)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>STOP</B><br/> <I>cmd_stop(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>,fontcolor=aquamarine4];
    stopped -> Con_start [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_CLEAR_COUNTERS</B><br/> <I>clear_counters(0)</I>>,fontcolor=aquamarine4];
   
    Con_start -> stopped [color=deeppink4,style=bold];
    Con_start -> w_ptp_time[color = crimson, style=bold,label=<<B>CND_START</B><br/> <I>start(0)</I>>, fontcolor=crimson];
    
    # w_ptp_time
    w_ptp_time-> stopped [color=aquamarine4,style=bold,label=<<B>STOP</B><br/> <I>cmd_stop(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> running [color=aquamarine4,style=bold,label=<<B>PTP_TIME_GOT</B><br/> <I>start_alarm(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_SET_SOURCE</B><br/> <I>set_source(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>, fontcolor=aquamarine4];
    w_ptp_time-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>, fontcolor=aquamarine4];

    # Running
	running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>STOP</B><br/> <I>cmd_stop(1)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_SET_SOURCE</B><br/> <I>cmd_set_source(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_PTP_ALARM</B><br/> <I>alarm(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>,fontcolor=aquamarine4];
    running -> Con_stop [color=aquamarine4, style=bold,label=bold, label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>,fontcolor=aquamarine4];

    running -> restarting [color=aquamarine4, style=bold,label=bold, label=<<B>TMR_ALARM</B><br/> <I>stop(0)</I>>,fontcolor=aquamarine4];
    
    Con_stop -> stopping[color = crimson, style=bold,label=<<B>CND_STOP</B><br/> <I>stop(0)</I>>, fontcolor=crimson];
    Con_stop -> running [color=deeppink4,style=bold];
   
    # STOPPING
    stopping-> restarting [color=aquamarine4,style=bold,label=<<B>START</B><br/> <I>cmd_start(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopped [color=aquamarine4,style=bold,label=<<B>CLEAR_ALARM</B><br/> <I>rt_nothing(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopping [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopping [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>, fontcolor=aquamarine4];
    stopping-> stopping [color=aquamarine4,style=bold,label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>, fontcolor=aquamarine4];

    # restarting
    restarting-> stopping [color=aquamarine4,style=bold,label=<<B>STOP</B><br/> <I>cmd_stop(0)</I>>, fontcolor=aquamarine4];
    restarting-> w_ptp_time [color=aquamarine4,style=bold,label=<<B>EVT_CLEAR_ALARM</B><br/> <I>start(0)</I>>, fontcolor=aquamarine4];
    
    restarting:n-> restarting:n [style=invis,label=" "];
    restarting:n-> restarting:n [color=aquamarine4,style=bold,label=<<B>REQ_SET_SOURCE</B><br/> <I>set_source(0)</I>>, fontcolor=aquamarine4];

    restarting:e-> restarting:e [style=invis,label=" "]
    restarting:e-> restarting:e [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATUS</B><br/> <I>get_status(0)</I>>, fontcolor=aquamarine4];

    restarting:s-> restarting:s [style=invis,label=" "]
    restarting:s-> restarting:s [color=aquamarine4,style=bold,label=<<B>REQ_GET_STATS</B><br/> <I>get_stats(0)</I>>, fontcolor=aquamarine4];

    restarting:w-> restarting:w [style=invis,label=" "]
    restarting:w-> restarting:w [color=aquamarine4,style=bold,label=<<B>REQ_GET_COUNTERS</B><br/> <I>get_counters(0)</I>>, fontcolor=aquamarine4];
    
	# Declare state
	init [shape=polygon,sides=5, color=lightblue,style=filled, label="Init"];
	w_ptp_time [color=lightblue,style=filled, label="W PTPtime"];
	running [color=lightblue,style=filled, label="Running"];
    stopped [color=lightblue,style=filled, label="Stopped"];
    stopping [color=lightblue,style=filled, label="Stopping"];
    restarting [color=lightblue,style=filled, label="Restarting"];
    
    Con_start [style=filled, shape=point, color=deeppink4];
    Con_stop [style=filled, shape=point, color=deeppink4];	
}

Giving:
anotherfsm1