Skip to content

Commit e868cb3

Browse files
committed
more updates to flow docs
1 parent e915e85 commit e868cb3

File tree

7 files changed

+261
-358
lines changed

7 files changed

+261
-358
lines changed

docs/enterprise/react_flow/basic_flow.md

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,41 @@ This example demonstrates a simple flow diagram with three nodes and two edges,
2828

2929
### Example Flow
3030

31-
```python
31+
```python demo exec
3232
import reflex as rx
3333
import reflex_enterprise as rxe
3434
from reflex_enterprise.components.flow.types import Node, Edge
3535

36+
# Common style for all nodes
37+
node_style = {
38+
"backgroundColor": "#ffcc00", # Background color
39+
"color": "#000000", # Text color
40+
"padding": "10px",
41+
"borderRadius": "5px"
42+
}
43+
3644
class FlowState(rx.State):
3745
nodes: list[Node] = [
3846
{
3947
"id": "1",
4048
"type": "input",
4149
"position": {"x": 100, "y": 100},
42-
"data": {"label": "Input Node"}
50+
"data": {"label": "Input Node"},
51+
"style": node_style
4352
},
4453
{
4554
"id": "2",
4655
"type": "default",
4756
"position": {"x": 300, "y": 200},
48-
"data": {"label": "Default Node"}
57+
"data": {"label": "Default Node"},
58+
"style": node_style
4959
},
5060
{
5161
"id": "3",
5262
"type": "output",
5363
"position": {"x": 500, "y": 100},
54-
"data": {"label": "Output Node"}
64+
"data": {"label": "Output Node"},
65+
"style": node_style
5566
},
5667
]
5768

@@ -89,38 +100,12 @@ def flow_example():
89100
on_edges_change=lambda edge_changes: FlowState.set_edges(
90101
rxe.flow.util.apply_edge_changes(FlowState.edges, edge_changes)
91102
),
92-
fit_view=True,
93103

94104
# Visual settings
95-
color_mode="light",
105+
fit_view=True,
96106
attribution_position="bottom-right",
97107
),
98108
height="100vh",
99109
width="100vw",
100110
)
101111
```
102-
103-
104-
```python exec
105-
import reflex as rx
106-
from reflex_image_zoom import image_zoom
107-
108-
def render_image():
109-
return rx.el.div(
110-
image_zoom(
111-
rx.image(
112-
src="/enterprise/flow-simple.gif",
113-
class_name="p-2 rounded-md h-auto",
114-
border=f"0.81px solid {rx.color('slate', 5)}",
115-
),
116-
class_name="rounded-md overflow-hidden",
117-
),
118-
class_name="w-full flex flex-col rounded-md cursor-pointer",
119-
)
120-
```
121-
122-
```python eval
123-
124-
rx.el.div(render_image(), class_name="py-4")
125-
126-
```

docs/enterprise/react_flow/edges.md

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)