Custom Graph: Difference between revisions

No edit summary
No edit summary
Line 10: Line 10:
<pre>
<pre>
  CUSTOM_GRAPH == rec(layout:"dot", rankdir:"TB",
  CUSTOM_GRAPH == rec(layout:"dot", rankdir:"TB",
                     nodes:ran( %j.(j:NODES |
                     nodes: {j•j:NODES |
                               rec(value:j, style:"filled",
                               rec(value:j, style:"filled",
                                 fillcolor:IF ice(j)=TRUE THEN "mistyrose" ELSE "white" END
                                 fillcolor:IF ice(j)=TRUE THEN "mistyrose" ELSE "white" END
                              ))),
                                  )},
                     edges:rec(color:"gray", arrowhead:"odot",
                     edges:rec(color:"gray", arrowhead:"odot",
                               arrowtail:"odot", dir:"both",
                               arrowtail:"odot", dir:"both",
Line 21: Line 21:
</pre>
</pre>


Here layout and rankdir are GraphViz attributes for the entire graph.
Other values, e.g., for layout are: neato, circo, fdp, sfdp, twopi, patchwork, nop, nop2.
Values for rankdir are: TB, BT, LR, RL. More graph attributes can be found here: [https://graphviz.org/docs/graph/].


The nodes field specifies the nodes of our graph. Here nodes evaluates to a set of records with the value field specifying the B identity of the node and the other fields style and fillcolor being GraphViz attributes.
Supported attributes for nodes can be found here: [https://graphviz.org/docs/nodes/].
Note that there can be other nodes fields, called nodes0, nodes1, ..., nodes9.
The edges field here is itself a record with GraphViz attributes.
These are default attributes for the edges field, which here is a straightforward B relation (but it could again be a set of records with attributes).
We could have used a similar record with default attributes in the nodes description above.
Supported attributes for edges can be found here: [https://graphviz.org/docs/edges/].
Note that there can be other edges fields, called edges0, ..., edges9.
The resulting visualisation can be seen here:
[[File:IceCream_Generic.pdf]]
[[File:IceCream_Generic.pdf]]

Revision as of 12:49, 6 January 2024

You can visualise the state of an individual B, Z, TLA+ or Alloy model using custom graph definitions which are laid out using GraphViz.

Thereby it is possible to specify general graph attributes, the nodes and the edges of the graph.

There are various ways such a custom graph can be defined. The most powerful is providing a single DEFINITION called CUSTOM_GRAPH which defines global graph properties as well as defines nodes and edges.

Suppose we have a B model with a binary relation edge and a set NODES as well as a total function ice from these nodes to BOOL. Here is an example custom graph definition:

 CUSTOM_GRAPH == rec(layout:"dot", rankdir:"TB",
                     nodes: {j•j:NODES |
                               rec(value:j, style:"filled",
                                fillcolor:IF ice(j)=TRUE THEN "mistyrose" ELSE "white" END
                                  )},
                    edges:rec(color:"gray", arrowhead:"odot",
                              arrowtail:"odot", dir:"both",
                              label:"edge",
                              edges: edge)
                    );

Here layout and rankdir are GraphViz attributes for the entire graph. Other values, e.g., for layout are: neato, circo, fdp, sfdp, twopi, patchwork, nop, nop2. Values for rankdir are: TB, BT, LR, RL. More graph attributes can be found here: [1].

The nodes field specifies the nodes of our graph. Here nodes evaluates to a set of records with the value field specifying the B identity of the node and the other fields style and fillcolor being GraphViz attributes. Supported attributes for nodes can be found here: [2]. Note that there can be other nodes fields, called nodes0, nodes1, ..., nodes9.

The edges field here is itself a record with GraphViz attributes. These are default attributes for the edges field, which here is a straightforward B relation (but it could again be a set of records with attributes). We could have used a similar record with default attributes in the nodes description above. Supported attributes for edges can be found here: [3]. Note that there can be other edges fields, called edges0, ..., edges9.


The resulting visualisation can be seen here: File:IceCream Generic.pdf