shukdevdatta123 commited on
Commit
35916b9
·
verified ·
1 Parent(s): 72f2a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -48
app.py CHANGED
@@ -120,54 +120,19 @@ def display_simple_directed_graph(G, pos=None):
120
  # Function to display Custom Node Position Graphs for Drawing: Custom Node Position
121
  def display_custom_node_position():
122
  st.title("Drawing: Custom Node Position")
123
- option = st.radio("Choose a graph type:", ("Default Example", "Create your own"))
124
-
125
- if option == "Default Example":
126
- # Default example graph (path graph with custom node position)
127
- G = nx.path_graph(20)
128
- center_node = 5
129
- edge_nodes = set(G) - {center_node}
130
-
131
- # Ensure the nodes around the circle are evenly distributed
132
- pos = nx.circular_layout(G.subgraph(edge_nodes))
133
- pos[center_node] = np.array([0, 0]) # Manually specify node position
134
-
135
- # Draw the graph
136
- nx.draw(G, pos, with_labels=True)
137
- st.pyplot(plt)
138
-
139
- elif option == "Create your own":
140
- # Let the user define a graph with custom edges
141
- st.write("Enter the edges (as pairs of nodes) separated by commas. For example, 1,2 or 3,4.")
142
- edge_input = st.text_area("Edges:", value="0,1\n1,2\n2,3")
143
-
144
- edges = []
145
- if edge_input:
146
- edge_list = edge_input.split("\n")
147
- for edge in edge_list:
148
- u, v = map(int, edge.split(","))
149
- edges.append((u, v))
150
-
151
- # Create the graph and allow user to input custom node positions
152
- if st.button("Generate"):
153
- G_custom = nx.Graph()
154
- G_custom.add_edges_from(edges)
155
-
156
- # Let user define node positions
157
- st.write("Enter custom positions for nodes (format: node: x,y). For example, 0: 0,0 or 1: 1,2.")
158
- pos_input = st.text_area("Node positions:", value="0: 0,0\n1: 1,1\n2: 2,0")
159
-
160
- pos = {}
161
- if pos_input:
162
- pos_list = pos_input.split("\n")
163
- for position in pos_list:
164
- node, coordinates = position.split(":")
165
- x, y = map(float, coordinates.split(","))
166
- pos[int(node)] = np.array([x, y])
167
-
168
- # Draw the graph with custom node positions
169
- nx.draw(G_custom, pos, with_labels=True)
170
- st.pyplot(plt)
171
 
172
  # Display Basic: Properties if selected
173
  if sidebar_option == "Basic: Properties":
 
120
  # Function to display Custom Node Position Graphs for Drawing: Custom Node Position
121
  def display_custom_node_position():
122
  st.title("Drawing: Custom Node Position")
123
+
124
+ # Default example graph (path graph with custom node position)
125
+ G = nx.path_graph(20)
126
+ center_node = 5
127
+ edge_nodes = set(G) - {center_node}
128
+
129
+ # Ensure the nodes around the circle are evenly distributed
130
+ pos = nx.circular_layout(G.subgraph(edge_nodes))
131
+ pos[center_node] = np.array([0, 0]) # Manually specify node position
132
+
133
+ # Draw the graph
134
+ nx.draw(G, pos, with_labels=True)
135
+ st.pyplot(plt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
  # Display Basic: Properties if selected
138
  if sidebar_option == "Basic: Properties":