StoneCypher / fsl

Finite State Language specification
9 stars 1 forks source link

Explicit ability to mark a group as a subgraph #118

Open StoneCypher opened 5 years ago

StoneCypher commented 5 years ago

Subgraphs are for the visualization only, and would have no impact on the execution of the FSM.

When writing

&Colors = [Green Yellow Red];
&Colors => 'Proceed' +1;
&Colors ~> Off -> Red;

You will get this layout, formatting removed for clarity:

image

With subgraphs, you could get this superior layout instead:

image

This also closes everything that a person used to HSMs and HFSMs wants out of groups.

StoneCypher commented 5 years ago

Notably, this only makes sense as the source of a spread, not as the target - you can't just draw an arrow to a subgraph and expect people to infer "oh, there's one of these to each subnode."

This can lead to much simpler graphs, but also suggests the following surprising rendering to be correct, which will need to be pointed out in the docs, which isn't exactly ideal.

[a b c].{subgraph: true} -> [x y z].{subgraph: true};

image

Instead of, as one might expect,

image

StoneCypher commented 5 years ago

this also leads to a remarkably aesthetic representation of neural networks

image

StoneCypher commented 5 years ago

The supporting DOT for that last graph.

# http://www.graphviz.org/content/cluster

digraph G {

    compound = true;

    subgraph cluster_0 {
        { rank = same; a; b; c; }
        color=black;
        fillcolor=gray93;
        style=filled;
    }

    subgraph cluster_1 {
        { rank = same; m; n; o; }
        color=black;
        fillcolor=gray93;
        style=filled;
    }

    subgraph cluster_2 {
        { rank = same; x; y; z; }
        color=black;
        fillcolor=gray93;
        style=filled;
    }

    a [ style=filled; fillcolor=white; ];
    b [ style=filled; fillcolor=white; ];
    c [ style=filled; fillcolor=white; ];
    m [ style=filled; fillcolor=white; ];
    n [ style=filled; fillcolor=white; ];
    o [ style=filled; fillcolor=white; ];
    x [ style=filled; fillcolor=white; ];
    y [ style=filled; fillcolor=white; ];
    z [ style=filled; fillcolor=white; ];

    b -> m [ ltail=cluster_0; ];
    b -> n [ ltail=cluster_0; ]; 
    b -> o [ ltail=cluster_0; ];

    n -> x [ ltail=cluster_1; ]; 
    n -> y [ ltail=cluster_1; ]; 
    n -> z [ ltail=cluster_1; ];

}

Won't work without that compound=true; at the beginning

StoneCypher commented 5 years ago

The comparable FSL:

&_subgraph.{ backgroundColor: #eee; };
&_node    .{ backgroundColor: white; };

[a b c].{subgraph: true} ->
[m n o].{subgraph: true} ->
[x y z].{subgraph: true};
StoneCypher commented 5 years ago

actually, if it's

&foo.{subgraph: 'subgraph'};

then we can use html/js-style key-name repetition and just say

&foo.{ subgraph; };
StoneCypher commented 5 years ago

Traffic light looks much better with styled subgraphs

image

Better still with faint coloring and direction control:

image

Controlling DOT:

# http://www.graphviz.org/content/cluster

digraph G {

    compound = true;

    rankdir = BT;

    subgraph cluster_0 {
        Green -> Yellow -> Red -> Green;
        color=black;
        fillcolor=gray93;
        style=filled;
    }

    Green  [ style=filled; fillcolor="#ddffdd"; ];
    Yellow [ style=filled; fillcolor="#ffffbb"; ];
    Red    [ style=filled; fillcolor="#ffdddd"; ];

    Yellow -> Off [ ltail=cluster_0; ];
    Off -> Red;

}
StoneCypher commented 2 years ago

https://graphviz.org/docs/layouts/patchwork/

StoneCypher commented 2 years ago

https://graphviz.org/docs/attrs/compound/