diff --git a/taipy/common/config/ScenarioConfig.py b/taipy/common/config/ScenarioConfig.py new file mode 100644 index 0000000000..a6c8d10f61 --- /dev/null +++ b/taipy/common/config/ScenarioConfig.py @@ -0,0 +1,46 @@ +import matplotlib.pyplot as plt +import networkx as nx + + +class ScenarioConfig: + def __init__(self): + self.graph = nx.DiGraph() # Create a directed graph + + def add_node(self, node): + """Add a node to the graph.""" + self.graph.add_node(node) + + def add_edge(self, from_node, to_node): + """Add an edge between two nodes.""" + self.graph.add_edge(from_node, to_node) + + def export_graph_as_image(self, file_path): + """Export the graph as an image.""" + plt.figure(figsize=(10, 6)) + pos = nx.spring_layout(self.graph) # Positioning the nodes + nx.draw(self.graph, pos, with_labels=True, node_size=3000, node_color='lightblue', font_size=10, + font_weight='bold') + + # Save the graph as an image + plt.savefig(file_path) + plt.close() # Close the plot to avoid display + print(f"Graph exported as image: {file_path}") + + +if __name__ == "__main__": + config = ScenarioConfig() + + # Add vertices (nodes) + config.add_node("Node1") + config.add_node("Node2") + config.add_node("Node3") + config.add_node("Node4") + + # Add edges (connections) + config.add_edge("Node1", "Node2") + config.add_edge("Node1", "Node3") + config.add_edge("Node2", "Node4") + config.add_edge("Node3", "Node4") + + # Export the graph as an image + config.export_graph_as_image("scenario_graph.png") diff --git a/taipy/common/config/graph_visualizer.py b/taipy/common/config/graph_visualizer.py deleted file mode 100644 index 00761734c9..0000000000 --- a/taipy/common/config/graph_visualizer.py +++ /dev/null @@ -1,17 +0,0 @@ -import matplotlib.pyplot as plt -import networkx as nx - -def visualize_scenario_graph(config): - G = nx.DiGraph() - - for node in config['nodes']: - G.add_node(node['id'], label=node['label']) - for edge in config['edges']: - G.add_edge(edge['from'], edge['to'], label=edge['label']) - - pos = nx.spring_layout(G) - nx.draw(G, pos, with_labels=True) - labels = nx.get_edge_attributes(G, 'label') - nx.draw_networkx_edge_labels(G, pos, edge_labels=labels) - - plt.show() diff --git a/taipy/common/config/scenario_graph.png b/taipy/common/config/scenario_graph.png new file mode 100644 index 0000000000..0e3f61339d Binary files /dev/null and b/taipy/common/config/scenario_graph.png differ diff --git a/taipy/common/config/scenario_grph.png b/taipy/common/config/scenario_grph.png new file mode 100644 index 0000000000..016078717a Binary files /dev/null and b/taipy/common/config/scenario_grph.png differ