From eea835d6027bc6302b1ef70c588cf3f46ff5dc08 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Fri, 20 Dec 2024 02:20:10 +0100 Subject: [PATCH 1/2] Improved file handling in code --- flixOpt/plotting.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/flixOpt/plotting.py b/flixOpt/plotting.py index c1d48d077..d12969757 100644 --- a/flixOpt/plotting.py +++ b/flixOpt/plotting.py @@ -581,7 +581,7 @@ def heat_map_data_from_df(df: pd.DataFrame, def visualize_network(node_infos: dict, edge_infos: dict, - path: Union[bool, str, pathlib.Path] = 'results/network.html', + path: Optional[Union[str, pathlib.Path]] = None, controls: Union[bool, List[Literal[ 'nodes', 'edges', 'layout', 'interaction', 'manipulation', 'physics', 'selection', 'renderer']]] = True, @@ -607,6 +607,7 @@ def visualize_network(node_infos: dict, - show (bool, default=True): Whether to open the visualization in the web browser. + The calculation must be saved to show it. If no path is given, it defaults to 'network.html'. Returns: - Optional[pyvis.network.Network]: The `Network` instance representing the visualization, or `None` if `pyvis` is not installed. @@ -654,11 +655,15 @@ def visualize_network(node_infos: dict, if controls: net.show_buttons(filter_=controls) # Adds UI buttons to control physics settings + if not show and not path: + return net + elif path: + path = pathlib.Path(path).resolve().as_posix() if isinstance(path, str) else path.resolve().as_posix() + net.write_html(path) + elif show: + path = pathlib.Path('network.html').resolve().as_posix() + net.write_html(path) - if isinstance(path, str): - path = pathlib.Path(path) - path = path.resolve().as_posix() - net.write_html(path) if show: try: import webbrowser @@ -666,5 +671,3 @@ def visualize_network(node_infos: dict, except Exception: logger.warning(f'Showing the network in the Browser went wrong. Open it manually. ' f'Its saved under {path}') - - return net From 876eaf0fe1d07ecaf360c14e4a391df52e19f772 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Fri, 20 Dec 2024 02:39:00 +0100 Subject: [PATCH 2/2] Changing default values to make network plot more compact --- flixOpt/plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixOpt/plotting.py b/flixOpt/plotting.py index d12969757..1d2d21c1d 100644 --- a/flixOpt/plotting.py +++ b/flixOpt/plotting.py @@ -651,7 +651,7 @@ def visualize_network(node_infos: dict, color="#222831") # Enhanced physics settings - net.barnes_hut(central_gravity=0.8, spring_length=50, spring_strength=0.2) + net.barnes_hut(central_gravity=0.8, spring_length=50, spring_strength=0.05, gravity=-10000) if controls: net.show_buttons(filter_=controls) # Adds UI buttons to control physics settings