Skip to content

Commit 28d2fe9

Browse files
committed
fixes
1 parent cdb3abb commit 28d2fe9

File tree

3 files changed

+79
-89
lines changed

3 files changed

+79
-89
lines changed

docs/enterprise/react_flow/edges.md

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,38 +106,14 @@ import reflex as rx
106106
import reflex_enterprise as rxe
107107
from reflex_enterprise.components.flow.types import Node, Edge
108108

109-
class EdgeExampleState(rx.State):
109+
class FlowState(rx.State):
110110
nodes: list[Node] = [
111-
{"id": "1", "type": "input", "position": {"x": 100, "y": 50}, "data": {"label": "Input"}},
112-
{"id": "2", "type": "default", "position": {"x": 300, "y": 150}, "data": {"label": "Process"}},
113-
{"id": "3", "type": "output", "position": {"x": 500, "y": 50}, "data": {"label": "Output"}},
114-
{"id": "4", "type": "default", "position": {"x": 300, "y": 300}, "data": {"label": "Branch"}},
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"}},
115113
]
116114

117115
edges: list[Edge] = [
118-
{
119-
"id": "e1-2",
120-
"source": "1",
121-
"target": "2",
122-
"type": "bezier",
123-
"animated": True,
124-
"label": "Input Flow"
125-
},
126-
{
127-
"id": "e2-3",
128-
"source": "2",
129-
"target": "3",
130-
"type": "straight",
131-
"style": {"stroke": "#ff6b6b", "strokeWidth": 3}
132-
},
133-
{
134-
"id": "e2-4",
135-
"source": "2",
136-
"target": "4",
137-
"type": "step",
138-
"label": "Branch",
139-
"style": {"stroke": "#4dabf7"}
140-
},
116+
{"id": "e1-2", "source": "1", "target": "2", "animated": True, "type": "buttonedge"},
141117
]
142118

143119
@rx.event
@@ -152,37 +128,95 @@ class EdgeExampleState(rx.State):
152128
def on_connect(self, connection: dict):
153129
self.edges = rxe.flow.util.add_edge(connection, self.edges)
154130

155-
def edge_example_flow():
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():
156167
return rx.box(
157168
rxe.flow(
158169
rxe.flow.controls(),
159170
rxe.flow.background(),
160171
rxe.flow.mini_map(),
161172

162-
nodes=EdgeExampleState.nodes,
163-
edges=EdgeExampleState.edges,
164-
165-
on_nodes_change=lambda node_changes: EdgeExampleState.set_nodes(
166-
rxe.flow.util.apply_node_changes(EdgeExampleState.nodes, node_changes)
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)
167177
),
168-
on_edges_change=lambda edge_changes: EdgeExampleState.set_edges(
169-
rxe.flow.util.apply_edge_changes(EdgeExampleState.edges, edge_changes)
178+
on_edges_change=lambda changes: FlowState.set_edges(
179+
rxe.flow.util.apply_edge_changes(FlowState.edges, changes)
170180
),
171-
on_connect=lambda connection: EdgeExampleState.set_edges(
172-
rxe.flow.util.add_edge(connection, EdgeExampleState.edges)
181+
on_connect=lambda connection: FlowState.set_edges(
182+
rxe.flow.util.add_edge(connection, FlowState.edges)
173183
),
174184

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+
},
175215
fit_view=True,
176216
color_mode="light",
217+
attribution_position="bottom-right",
177218
),
178219
height="100vh",
179220
width="100vw",
180221
)
181222
```
182-
183-
This example demonstrates:
184-
- Multiple edge types (bezier, straight, step)
185-
- Animated edges
186-
- Styled edges with custom colors
187-
- Edge labels
188-
- Interactive edge creation and modification

docs/enterprise/react_flow/hooks.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,3 @@ The `rxe.flow.api` module provides hooks to interact with the Flow instance. The
3131
- `get_intersecting_nodes(node, partially=True, nodes=None)`: Find all the nodes currently intersecting with a given node or rectangle.
3232
- `get_node_connections(id=None, handle_type=None, handle_id=None)`: This hook returns an array of connections on a specific node, handle type ("source", "target") or handle ID.
3333
- `get_connection()`: Returns the current connection state when there is an active connection interaction.
34-
35-
## Example
36-
37-
Here is an example of how to use the `screen_to_flow_position` hook to add a node at the position of a drop event.
38-
39-
```python
40-
import reflex as rx
41-
import reflex_enterprise as rxe
42-
from reflex_enterprise.components.flow.types import Node, XYPosition
43-
44-
class AddNodeOnDropState(rx.State):
45-
nodes: list[Node] = []
46-
47-
def handle_drop(self, event: rx.event.Event, flow_position: XYPosition):
48-
# Logic to add a new node at flow_position
49-
new_node = {
50-
"id": f"node_{len(self.nodes) + 1}",
51-
"position": flow_position,
52-
"data": {"label": "New Node"},
53-
}
54-
self.nodes.append(new_node)
55-
56-
def add_node_on_drop_example():
57-
return rxe.flow.provider(
58-
rxe.flow(
59-
nodes=AddNodeOnDropState.nodes,
60-
on_drop=lambda event: AddNodeOnDropState.handle_drop(
61-
event,
62-
rxe.flow.api.screen_to_flow_position(
63-
x=event.client_x,
64-
y=event.client_y,
65-
),
66-
),
67-
# ... other props
68-
)
69-
)
70-
```

docs/enterprise/react_flow/nodes.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,3 @@ def custom_node():
275275
)
276276

277277
```
278-
279-
This example demonstrates:
280-
- Built-in node types (input, output)
281-
- Custom calculator node with multiple handles
282-
- Handle positioning and IDs
283-
- Node data management
284-
- Complete flow with interactive connections

0 commit comments

Comments
 (0)