Zum Inhalt

layouter

dsstools.layouter

logger = get_logger(__name__) module-attribute

ForceAtlas2Layouter

Bases: Layouter

Create layouts using ForceAtlas 2 as backend.

Note: This layouter engine is quite peculiar to create good results with. Please ensure you at least read the corresponding entry in the NetworkX documentation: https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.forceatlas2_layout.html

__str__()

create_layout(graph, seed=None, pos=None, **kwargs)

name() staticmethod

read_from_file(filename, **kwargs)

Reads position from JSON file under filepath.

The following structure for the JSON is expected, where each key contains an array of length 2 containing the coordinates. Coordinates should be in the range [-1,1]:

{
    "domain1": [-0.1467271130230262, 0.25512246449304427],
    "domain2": [-0.3683594304205127, 0.34942480334119136],
}

This structure is generated through dsstools.Layouter().write_to_file().

Parameters:

Name Type Description Default
filename Union[Path]

Path to file to be read.

required
**kwargs
{}

Returns:

Type Description
dict

Dictionary of nodes and positions.

read_from_graph(graph, pos_name=('x', 'y'))

Read positions from node attributes in the graph.

This is relevant when importing from Pajek or GEXF files where the positions are already set with another tool. Imported values are normalized onto [-1,1] in all directions.

Parameters:

Name Type Description Default
graph Graph

Graph object including the node attributes.

required
pos_name tuple

Node attribute names to look for. These depend on the imported file format.

('x', 'y')

Returns:

Type Description
dict

Dictionary of positions per Node.

read_or_create_layout(filepath, graph, seed=None, overwrite=False, **kwargs)

Read positions from file. If non-existant create pos and write to file.

Parameters:

Name Type Description Default
filepath Union[str, Path]

Filename to read positions from

required
graph Graph

Graph object to update

required
seed Optional[int]

Seed to use for the layout.

None
overwrite bool

Overwrite existing file (default False)

False

Returns:

Type Description
dict

Dictionary of positions per Node. Will return an empty dict if creation

dict

failed.

write_to_file(positions, path)

GraphvizLayouter

Bases: Layouter

Create layouts using graphviz as backend.

This is rather complicated to install the proper dependencies for. Not for the faint of heart.

__str__()

create_layout(graph, seed=None, pos=None, prog='fdp', additional_args='', **kwargs)

name() staticmethod

read_from_file(filename, **kwargs)

Reads position from JSON file under filepath.

The following structure for the JSON is expected, where each key contains an array of length 2 containing the coordinates. Coordinates should be in the range [-1,1]:

{
    "domain1": [-0.1467271130230262, 0.25512246449304427],
    "domain2": [-0.3683594304205127, 0.34942480334119136],
}

This structure is generated through dsstools.Layouter().write_to_file().

Parameters:

Name Type Description Default
filename Union[Path]

Path to file to be read.

required
**kwargs
{}

Returns:

Type Description
dict

Dictionary of nodes and positions.

read_from_graph(graph, pos_name=('x', 'y'))

Read positions from node attributes in the graph.

This is relevant when importing from Pajek or GEXF files where the positions are already set with another tool. Imported values are normalized onto [-1,1] in all directions.

Parameters:

Name Type Description Default
graph Graph

Graph object including the node attributes.

required
pos_name tuple

Node attribute names to look for. These depend on the imported file format.

('x', 'y')

Returns:

Type Description
dict

Dictionary of positions per Node.

read_or_create_layout(filepath, graph, seed=None, overwrite=False, **kwargs)

Read positions from file. If non-existant create pos and write to file.

Parameters:

Name Type Description Default
filepath Union[str, Path]

Filename to read positions from

required
graph Graph

Graph object to update

required
seed Optional[int]

Seed to use for the layout.

None
overwrite bool

Overwrite existing file (default False)

False

Returns:

Type Description
dict

Dictionary of positions per Node. Will return an empty dict if creation

dict

failed.

write_to_file(positions, path)

KamadaKawaiLayouter

Bases: Layouter

Create layouts using Kamada-Kawai as backend.

__str__()

create_layout(graph, seed=None, pos=None, **kwargs)

name() staticmethod

read_from_file(filename, **kwargs)

Reads position from JSON file under filepath.

The following structure for the JSON is expected, where each key contains an array of length 2 containing the coordinates. Coordinates should be in the range [-1,1]:

{
    "domain1": [-0.1467271130230262, 0.25512246449304427],
    "domain2": [-0.3683594304205127, 0.34942480334119136],
}

This structure is generated through dsstools.Layouter().write_to_file().

Parameters:

Name Type Description Default
filename Union[Path]

Path to file to be read.

required
**kwargs
{}

Returns:

Type Description
dict

Dictionary of nodes and positions.

read_from_graph(graph, pos_name=('x', 'y'))

Read positions from node attributes in the graph.

This is relevant when importing from Pajek or GEXF files where the positions are already set with another tool. Imported values are normalized onto [-1,1] in all directions.

Parameters:

Name Type Description Default
graph Graph

Graph object including the node attributes.

required
pos_name tuple

Node attribute names to look for. These depend on the imported file format.

('x', 'y')

Returns:

Type Description
dict

Dictionary of positions per Node.

read_or_create_layout(filepath, graph, seed=None, overwrite=False, **kwargs)

Read positions from file. If non-existant create pos and write to file.

Parameters:

Name Type Description Default
filepath Union[str, Path]

Filename to read positions from

required
graph Graph

Graph object to update

required
seed Optional[int]

Seed to use for the layout.

None
overwrite bool

Overwrite existing file (default False)

False

Returns:

Type Description
dict

Dictionary of positions per Node. Will return an empty dict if creation

dict

failed.

write_to_file(positions, path)

Layouter

__str__()

create_layout(graph, seed=None, pos=None, **kwargs)

Create position dictionary according to set layout engine. Default layout is Spring.

Parameters:

Name Type Description Default
graph Graph

Graph object

required
seed Optional[int]

Set a default seed (default None)

None
pos Optional[dict]

Pre-populated positions

None

Returns:

Type Description
dict

Dictionary of node and positions.

name() staticmethod

read_from_file(filename, **kwargs)

Reads position from JSON file under filepath.

The following structure for the JSON is expected, where each key contains an array of length 2 containing the coordinates. Coordinates should be in the range [-1,1]:

{
    "domain1": [-0.1467271130230262, 0.25512246449304427],
    "domain2": [-0.3683594304205127, 0.34942480334119136],
}

This structure is generated through dsstools.Layouter().write_to_file().

Parameters:

Name Type Description Default
filename Union[Path]

Path to file to be read.

required
**kwargs
{}

Returns:

Type Description
dict

Dictionary of nodes and positions.

read_from_graph(graph, pos_name=('x', 'y'))

Read positions from node attributes in the graph.

This is relevant when importing from Pajek or GEXF files where the positions are already set with another tool. Imported values are normalized onto [-1,1] in all directions.

Parameters:

Name Type Description Default
graph Graph

Graph object including the node attributes.

required
pos_name tuple

Node attribute names to look for. These depend on the imported file format.

('x', 'y')

Returns:

Type Description
dict

Dictionary of positions per Node.

read_or_create_layout(filepath, graph, seed=None, overwrite=False, **kwargs)

Read positions from file. If non-existant create pos and write to file.

Parameters:

Name Type Description Default
filepath Union[str, Path]

Filename to read positions from

required
graph Graph

Graph object to update

required
seed Optional[int]

Seed to use for the layout.

None
overwrite bool

Overwrite existing file (default False)

False

Returns:

Type Description
dict

Dictionary of positions per Node. Will return an empty dict if creation

dict

failed.

write_to_file(positions, path)