Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/GAP/pkg/jupyterviz/examples/   (Algebra von RWTH Aachen Version 4.15.1©)  Datei vom 16.7.2022 mit Größe 3 kB image not shown  

Quelle  09creategraph.md   Sprache: unbekannt

 
Spracherkennung für: .md vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]


# Greater graph control with the low-level API

The high-level graph API provides convenience functions, but there
are many options you can access in the underlying graph-drawing
tool (cytoscape, by default) through only the low-level API.  If
you need them, you will need to produce the parameters for
`CreateVisualization` yourself.

You can find out what kind of data `PlotGraph` is passing, under
the hood, as follows.  Your graph will need to be in the following
format.

```
# Assume the GAP variable vertices contains a GAP list of
# your graph's vertices.
vertices := [ 1, 2, 3, 4 ];
# Assume the GAP variable edges contains a GAP list of
# your graph's edges, each of which is a length-2 list,
# a pair of elements from vertices, the first connected
# to the second by the edge.
edges := [ [ 1, 2 ], [ 2, 3 ], [ 2, 4 ] ];
```

You can then convert your graph into the format used by cytoscape
as follows.

```
big := ConvertGraphForTool.cytoscape( rec(
    vertices := vertices,
    edges := edges,
    options := rec() # or any options you like here
) );
# yields:
# rec(
#     elements := [
#         rec( data := rec( id := "1" ) ),
#         rec( data := rec( id := "2" ) ),
#         rec( data := rec( id := "3" ) ),
#         rec( data := rec( id := "4" ) ),
#         rec( data := rec( source := "1", target := "2" ) ),
#         rec( data := rec( source := "2", target := "3" ) ),
#         rec( data := rec( source := "2", target := "4" ) )
#     ],
#     layout := rec( name := "cose" ),
#     style := [
#         rec(
#             selector := "node",
#             style := rec( content := "data(id)" )
#         )
#     ]
# )
```

That record is passed to `CreateVisualization` as follows.  Note
the inclusion of a default height, if you don't provide one.

```
CreateVisualization( rec(
    tool := "cytoscape", data := big, height := 400
) );
```

If you wanted to change any of the internal options, including
creating elements not supported by the simple high-level API,
you could alter or recreate the contents of the `big` record.

Here is an example.

```
CreateVisualization( rec(
    tool := "cytoscape",
    height := 400,
    data := rec(
        elements := [
            rec( # node 1
                group := "nodes",
                data := rec( id := "Child1", parent := "Parent" ),
                position := rec( x := 100, y := 100 ),
                selected := false,
                selectable := true,
                locked := false,
                grabbable := true
            ),
            rec( # node 2
                data := rec( id := "Friend" ),
                renderedPosition := rec( x := 200, y := 200 )
            ),
            rec( # node 3
                data := rec( id := "Child2", parent := "Parent" ),
                position := rec( x := 123, y := 234 )
            ),
            rec( # node parent
                data := rec(
                    id := "Parent",
                    position := rec( x := 200, y := 100 )
                )
            ),
            rec( # edge 1
                data := rec(
                    id := "Edge1",
                    source := "Child1",
                    target := "Friend"
                )
            )
        ],
        layout := rec( name := "preset" ),
        style := [
            rec(
                selector := "node",
                style := rec( content := "data(id)" )
            )
        ]
    )
) );
```


[ Dauer der Verarbeitung: 0.37 Sekunden  ]