@@ -94,129 +94,3 @@ edges: list[Edge] = [
9494 }
9595]
9696```
97-
98- ## Custom Edges
99-
100- For advanced use cases, you can create custom edge components that render additional controls or styling.
101-
102- Here's a complete example showing various edge types and interactions:
103-
104- ``` python
105- import reflex as rx
106- import reflex_enterprise as rxe
107- from reflex_enterprise.components.flow.types import Node, Edge
108-
109- class FlowState (rx .State ):
110- nodes: list[Node] = [
111- {" id" : " 1" , " type" : " input" , " position" : {" x" : 100 , " y" : 100 }, " data" : {" label" : " Edge 1" }},
112- {" id" : " 2" , " type" : " default" , " position" : {" x" : 300 , " y" : 200 }, " data" : {" label" : " Edge 2" }},
113- ]
114-
115- edges: list[Edge] = [
116- {" id" : " e1-2" , " source" : " 1" , " target" : " 2" , " animated" : True , " type" : " buttonedge" },
117- ]
118-
119- @rx.event
120- def on_nodes_change (self , changes : list[dict ]):
121- self .nodes = rxe.flow.util.apply_node_changes(self .nodes, changes)
122-
123- @rx.event
124- def on_edges_change (self , changes : list[dict ]):
125- self .edges = rxe.flow.util.apply_edge_changes(self .edges, changes)
126-
127- @rx.event
128- def on_connect (self , connection : dict ):
129- self .edges = rxe.flow.util.add_edge(connection, self .edges)
130-
131- @rx.event
132- def remove_edge (self , edge_id : str ):
133- self .edges = [e for e in self .edges if e[" id" ] != edge_id]
134-
135- @rx.memo
136- def button_edge (
137- id : rx.Var[str ],
138- sourceX : rx.Var[float ],
139- sourceY : rx.Var[float ],
140- targetX : rx.Var[float ],
141- targetY : rx.Var[float ],
142- sourcePosition : rx.Var[str ],
143- targetPosition : rx.Var[str ],
144- style : rx.Var[dict ] = {},
145- markerEnd : rx.Var[str ] = None ,
146- ):
147-
148- edge_path, labelX, labelY = rxe.flow.util.get_bezier_path(
149- sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition
150- )
151-
152- return rx.fragment(
153- rxe.flow.edge(path = edge_path, marker_end = markerEnd, style = style),
154- rxe.flow.edge_label(
155- x = labelX,
156- y = labelY,
157- child = rx.button(
158- " ×" ,
159- on_click = lambda : FlowState.remove_edge(id ),
160- class_name = " nodrag nopan" ,
161- ),
162- ),
163- )
164-
165-
166- def flow_with_button_edge ():
167- return rx.box(
168- rxe.flow(
169- rxe.flow.controls(),
170- rxe.flow.background(),
171- rxe.flow.mini_map(),
172-
173- nodes = FlowState.nodes,
174- edges = FlowState.edges,
175- on_nodes_change = lambda changes : FlowState.set_nodes(
176- rxe.flow.util.apply_node_changes(FlowState.nodes, changes)
177- ),
178- on_edges_change = lambda changes : FlowState.set_edges(
179- rxe.flow.util.apply_edge_changes(FlowState.edges, changes)
180- ),
181- on_connect = lambda connection : FlowState.set_edges(
182- rxe.flow.util.add_edge(connection, FlowState.edges)
183- ),
184-
185- edge_types = {
186- " buttonedge" : rx.vars.function.ArgsFunctionOperation.create(
187- (
188- rx.vars.function.DestructuredArg(
189- fields = (
190- " id" ,
191- " sourceX" ,
192- " sourceY" ,
193- " targetX" ,
194- " targetY" ,
195- " sourcePosition" ,
196- " targetPosition" ,
197- " style" ,
198- " markerEnd" ,
199- )
200- ),
201- ),
202- button_edge(
203- id = rx.Var(" id" ),
204- sourceX = rx.Var(" sourceX" ),
205- sourceY = rx.Var(" sourceY" ),
206- targetX = rx.Var(" targetX" ),
207- targetY = rx.Var(" targetY" ),
208- sourcePosition = rx.Var(" sourcePosition" ),
209- targetPosition = rx.Var(" targetPosition" ),
210- style = rx.Var(" style" ),
211- markerEnd = rx.Var(" markerEnd" ),
212- ),
213- )
214- },
215- fit_view = True ,
216- color_mode = " light" ,
217- attribution_position = " bottom-right" ,
218- ),
219- height = " 100vh" ,
220- width = " 100vw" ,
221- )
222- ```
0 commit comments