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)
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 showallow_selection_when_not_editable
: Whether to allow nodes/edges to be selected even wheneditable=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 graphgraph_layout
: Optional layout configuration objectinitial_constraints
: Optional initial edge constraints. Can be passed as a list ofEdgeConstraint
objects or a Variable.node_size
: Optional parameter to force the node size to be largernodes
: List of available nodes - can be passed as a list of strings or a dict of [str, Node]on_click_edge
: OptionalAction
triggered when clicking on an edgeon_click_node
: OptionalAction
triggered when clicking on a nodeon_update
: OptionalAction
for all hierarchy changes, called with built list of constraints. Note that when updating a Variable passed intoinitial_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 sizezoom_thresholds
: Optional user-defined zoom thresholds. SeeZoomThresholds
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]