Skip to main content

edge_encoder

EdgeConstraint

from dara.components.graphs.components.edge_encoder import EdgeConstraint

class EdgeConstraint(TypedDict)

EdgeConstraint object denotes a constraint between two nodes in the graph.

It is used to build a list of constraints for VisualEdgeEncoder component.

Attributes

  • source: str
  • target: str
  • type: EdgeConstraintType

VisualEdgeEncoder

from dara.components.graphs.components.edge_encoder import VisualEdgeEncoder

class VisualEdgeEncoder(StyledComponentInstance)

EdgeEncoder

The VisualEdgeEncoder component allows the user to build a list of edge constraints using a graph editor component

A VisualEdgeEncoder component is created via:

from dara.core import Variable
from dara.components import VisualEdgeEncoder

encoder = VisualEdgeEncoder(
nodes=["First node", "Second node", "Third node"]
)

# saves results in a variable
output_constraints = Variable()
variable_encoder = VisualEdgeEncoder(
nodes=["First node", "Second node", "Third node"],
on_update=output_constraints.sync(),
)

Alternatively, you can pass in a dict of [str, Node] to the nodes parameter to use the CausalGraph.Node object:

from cai_causal_graph import CausalGraph
from dara.components import VisualEdgeEncoder
output_constraints = Variable()

VisualEdgeEncoder(
nodes={
"First node": CausalGraph.Node("First node"),
"Second node": CausalGraph.Node("Second node")
},
on_update=output_constraints.sync(),
)

You can also pass in a list of EdgeConstraint objects to the initial_constraints parameter to pre-populate the graph:

from cai_causal_graph import CausalGraph
from cai_causal_graph.type_definitions import EdgeConstraint as EdgeConstraintType
from dara.components import VisualEdgeEncoder, EdgeConstraint

output_constraints = Variable()

VisualEdgeEncoder(
nodes=["First node", "Second node", "Third node"],
initial_constraints=[
EdgeConstraint(source="First node", target="Second node", type=EdgeConstraintType.HARD_UNDIRECTED_EDGE),
EdgeConstraint(source="Second node", target="Third node", type=EdgeConstraintType.HARD_DIRECTED_EDGE)
],
on_update=output_constraints.sync(),
)

Arguments:

  • additional_legends: Optional additional legends to show
  • allow_selection_when_not_editable: Whether to allow nodes/edges to be selected even when editable=False
  • default_legends: A dict containing the default legends that should appear on the graph depending on the EditorMode selected.
  • editable: Optional flag to enable editing the graph by showing an editor frame around the graph
  • graph_layout: Optional layout configuration object
  • initial_constraints: Optional initial edge constraints. Can be passed as a list of EdgeConstraint objects or a Variable.
  • node_size: Optional parameter to force the node size to be larger
  • nodes: List of available nodes - can be passed as a list of strings or a dict of [str, Node]
  • on_click_edge: Optional Action triggered when clicking on an edge
  • on_click_node: Optional Action triggered when clicking on a node
  • on_update: Optional Action for all hierarchy changes, called with built list of constraints. Note that when updating a Variable passed into initial_constraints it will re-render the component on each update, use a different Variable for the output of the component.
  • require_focus_to_zoom: Optional flag to require focus to be on the graph for the zoom to be active. Defaults to True.
  • tooltip_size: Optional parameter to force a tooltip to use a particular font size
  • zoom_thresholds: Optional user-defined zoom thresholds. See ZoomThresholds for more details.

Attributes

  • additional_legends: Optional[List[GraphLegend]]
  • allow_selection_when_not_editable: Optional[bool]
  • default_legends: Dict[Union[EditorMode, str], List[GraphLegend]]
  • editable: Optional[bool]
  • graph_layout: Optional[GraphLayout]
  • initial_constraints: Optional[Union[List[EdgeConstraint], NonDataVariable]]
  • nodes: Union[List[str], Dict[str, Node], NonDataVariable]
  • on_click_edge: Optional[Action]
  • on_click_node: Optional[Action]
  • on_update: Optional[Action]
  • require_focus_to_zoom: Optional[bool]
  • tooltip_size: Optional[str]