Skip to main content

graph_layout

GraphLayout

from dara.components.graphs.graph_layout import GraphLayout

class GraphLayout(BaseModel, abc.ABC)

Base graph layout class

Arguments:

  • node_size: node size in pixels
  • node_font_size: node font size in pixels

Attributes

  • node_size: Optional[int]
  • node_font_size: Optional[int]

TieringLayout

from dara.components.graphs.graph_layout import TieringLayout

class TieringLayout(BaseModel)

TieringLayout provides a tiering layout for a graph. It can be used to define tiers for a graph.

A way of setting tiers is to pass it as an array of array of nodes:

from dara.components import CausalGraphViewer, FcoseLayout
from cai_causal_graph import CausalGraph

cg = CausalGraph()
cg.add_edge('A', 'C')
cg.add_edge('B', 'D')
cg.add_edge('C', 'E')
cg.add_edge('D', 'E')

tiers = [['A', 'B'], ['C', 'D'], ['E']]

CausalGraphViewer(
causal_graph=cg,
graph_layout=FcoseLayout(
tiers=tiers,
orientation='vertical'
),
)

Alternatively you can pass the tiers based on some node property with the use of TiersConfig:

from dara.components import CausalGraphViewer, FcoseLayout, TiersConfig
from cai_causal_graph import CausalGraph

cg = CausalGraph()
cg.add_node(identifier='A', meta={'group': 'first', order: 2})
cg.add_node(identifier='B', meta={'group': 'first', order: 1})
cg.add_node(identifier='C', meta={'group': 'second'})
cg.add_node(identifier='D', meta={'group': 'second'})
cg.add_node(identifier='E', meta={'group': 'third'})
cg.add_edge('A', 'C')
cg.add_edge('B', 'D')
cg.add_edge('C', 'E')
cg.add_edge('D', 'E')

CausalGraphViewer(
causal_graph=cg,
graph_layout=FcoseLayout(
tiers=TiersConfig(group='meta.group', rank=['first', 'second', 'third'], order_nodes_by='meta.order'),
),
)

Arguments:

  • tiers: A TiersConfig object or an array of arrays of node ids outlining the tier structure
  • orientation: Orientation the tiers are displayed in default is horizontal

Attributes

  • tiers:
  • orientation: Optional[DirectionType]

GroupingLayout

from dara.components.graphs.graph_layout import GroupingLayout

class GroupingLayout(BaseModel)

GroupingLayout provides a grouping or cluster layout for a graph. It can be used to represent nodes within groups or cluster which are collapsible.

You can set the group on the meta of a node and then define the path to this property on the layout:

from dara.components import CausalGraphViewer, FcoseLayout
from cai_causal_graph import CausalGraph

cg = CausalGraph()
cg.add_node(identifier='A', meta={'group': 'group1'})
cg.add_node(identifier='B', meta={'group': 'group1'})
cg.add_node(identifier='C', meta={'group': 'group2'})
cg.add_node(identifier='D', meta={'group': 'group2'})
cg.add_node(identifier='E', meta={'group': 'group3'})
cg.add_edge('A', 'C')
cg.add_edge('B', 'D')
cg.add_edge('C', 'E')
cg.add_edge('D', 'E')

CausalGraphViewer(
causal_graph=cg,
graph_layout=FcoseLayout(
group='meta.group',
),
)

Arguments:

  • group: Path within node to group property which defines the group it belong to,

Attributes

  • group: Optional[str]

CircularLayout

from dara.components.graphs.graph_layout import CircularLayout

class CircularLayout(GraphLayout)

CircularLayout provides a circular layout where nodes are aligned on a circle. The circle's radius scales

automatically with node size and number of nodes.

Arguments:

  • node_size: node size in pixels

Attributes

  • layout_type: GraphLayoutType

CustomLayout

from dara.components.graphs.graph_layout import CustomLayout

class CustomLayout(GraphLayout)

CustomLayout provides a custom layout for the graph. The layout is defined by the user.

This layout can be used if all nodes have coordinates defined in the metadata, e.g.:

{
'nodes': {
'a': {
'meta': {
'rendering_properties': {
'x': 0,
'y': 0,
}
}
}
}
}

If not all nodes have coordinates defined, the graph editor will fall back to a default layout.

Attributes

  • layout_type: GraphLayoutType

FcoseLayout

from dara.components.graphs.graph_layout import FcoseLayout

class FcoseLayout(GraphLayout, TieringLayout, GroupingLayout)

FcoseLayout utilizes fCoSE (fast Compound Spring Embedder) algorithm to compute the layout.

It works well in most circumstances and is highly configurable.

See https://github.com/iVis-at-Bilkent/cytoscape.js-fcose for more details and interactive demos.

Arguments:

  • edge_elasticity: Divisor to compute edge forces (default value: 0.45)
  • edge_length: Ideal edge length multiplier, the layout's idealEdgeLength = avgNodeSize * edgeLength (default value: 3)
  • energy: Initial cooling factor for incremental layout (default value: 0.1)
  • gravity: Gravity force multiplier (default value: 35)
  • gravity_range: Gravity range (default value: 80)
  • high_quality: Whether to produce high-quality layout a slight performance cost, lowers cooling rate so might require more iterations (default value: True)
  • iterations: Number of iterations to run the layout for, per computation (default value: 2500)
  • node_repulsion: Non-overlapping node force multiplier (default value: 6500)
  • node_separation: Separation force between nodes (default value: 75)
  • tier_separation: Separation force between tiers (default value: 200)

Attributes

  • layout_type: GraphLayoutType
  • edge_elasticity: Optional[Number]
  • edge_length: Optional[Number]
  • energy: Optional[Number]
  • gravity: Optional[Number]
  • gravity_range: Optional[Number]
  • high_quality: Optional[bool]
  • iterations: Optional[int]
  • node_repulsion: Optional[Number]
  • node_separation: Optional[Number]
  • tier_separation: Optional[Number]

ForceAtlasLayout

from dara.components.graphs.graph_layout import ForceAtlasLayout

class ForceAtlasLayout(GraphLayout)

ForceAtlas utilizes the ForceAtlas2 algorithm to compute the layout. It is a force-directed layout

which integrates various optimizations and is highly configurable.

See https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0098679 for more details and in-depth explanations of the parameters.

Arguments:

  • barnes_hut_optimize: Whether to use the Barnes-Hut approximation to calculate repulsive forces. Enabling it improves the performance at cost of accuracy. (default value: False)
  • edge_weight_influence: Influence of edge weights on the layout. If set to 0, edge weights are ignored. Higher values emphasize the weight effects. This parameter is used to modify the attraction force between nodes. (default value: 1)
  • gravity: This force prevents disconnected components from drifting away, attracting nodes towards the center of the space. Its main purpose is to compensate repulsion for nodes that are far away from the center. (default value:0.2)
  • iterations: Number of iterations to run the layout for, per computation (default value: 10_000)
  • lin_log_mode: Whether to use LinLog energy model, using logarithmic attraction force. Enabling it makes clusters tighter but converges slower. (default value: True)
  • outbound_attraction_distribution: Whether to scale the attraction force between nodes according to their degree. (default value: True)
  • scaling_ratio: Parameter to adjust the size of the produced graph (default value: 8)
  • strong_gravity_mode: Whether to use strong gravity mode, which sets a force that attracts the nodes that are distant from the center more. This force has the drawback of being so strong that it is sometimes stronger than the other forces. It may result in a biased placement of the nodes. However, its advantage is to force a very compact layout, which may be useful for certain purposes. (default value: False)

Attributes

  • layout_type: GraphLayoutType
  • barnes_hut_optimize: Optional[bool]
  • edge_weight_influence: Optional[Number]
  • gravity: Optional[Number]
  • iterations: Optional[int]
  • lin_log_mode: Optional[bool]
  • outbound_attraction_distribution: Optional[bool]
  • scaling_ratio: Optional[Number]
  • strong_gravity_mode: Optional[bool]

MarketingLayout

from dara.components.graphs.graph_layout import MarketingLayout

class MarketingLayout(GraphLayout, TieringLayout)

MarketingLayout provides the default graph layout which works well for smaller

number of nodes, although it does not offer any protection against excessive edge crossings.

Arguments:

  • node_size: node size in pixels
  • target_location: Location of the target node
  • tier_separation: Separation force between tiers (default value: 300)

Attributes

  • layout_type: GraphLayoutType
  • target_location: Optional[TargetLocation]
  • tier_separation: Optional[Number]

PlanarLayout

from dara.components.graphs.graph_layout import PlanarLayout

class PlanarLayout(GraphLayout, TieringLayout)

PlanarLayout provides a planar layout similar to the layout offered in low-level editor. The implementation

uses d3-dag's sugiyama layout under the hood to minimize edge crossings.

Arguments:

  • orientation: Orientation of target node relative to other nodes (horizontal or vertical). (default value: horizontal)
  • layering_algorithm: Algorithm to use for the layering step of sugyiama algorithm. Can chosen between simplex which optimizes for minimum edge length or long path which optimizes for minimum graph height. Do note that if tiers are passed in conjunction to this prop, its value will revert to simplex as tiers are only supported by it (defaults to: simplex)

Attributes

  • layout_type: GraphLayoutType
  • layering_algorithm: Optional[LayeringAlgorithm]
  • orientation: Optional[DirectionType]

SpringLayout

from dara.components.graphs.graph_layout import SpringLayout

class SpringLayout(GraphLayout, TieringLayout, GroupingLayout)

SpringLayout provides a simple force-directed graph layout which produces the "spring" behavior of edges.

This is a 'live' layout, which means a simulation keeps running in the background to compute the layout.

Arguments:

  • collision_force: Multiplier for collision force between nodes (default value: 2)
  • gravity: Gravity strength; negative values pull nodes together, positive values push them apart (default value: -50)
  • link_force: Multiplier for link force between nodes, higher values produce shorter links (default value: 5)
  • warmup_ticks: Number of ticks to run the simulation for before displaying the layout. Increasing it should make the initial render of the graph more stable (i.e. nodes won't move by themselves) but it comes at a small performance cost. (default value: 100)
  • tier_separation: Separation force between tiers (default value: 300)
  • group_repel_strength: Strength of repulsion force between groups (default value: 2000)

Attributes

  • layout_type: GraphLayoutType
  • collision_force: Optional[Number]
  • gravity: Optional[Number]
  • link_force: Optional[Number]
  • warmup_ticks: Optional[Number]
  • tier_separation: Optional[Number]
  • group_repel_strength: Optional[Number]