From 3f5d45a340845aaf5c8e70b4abcb48cd0af40f4b Mon Sep 17 00:00:00 2001 From: Awolstrup Date: Wed, 30 Sep 2026 08:37:58 +0100 Subject: [PATCH 1/4] Removed fig.show from plot function, cicd testing still present --- fullcontrol/visualize/plotly.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fullcontrol/visualize/plotly.py b/fullcontrol/visualize/plotly.py index 14a9d98..a923a10 100644 --- a/fullcontrol/visualize/plotly.py +++ b/fullcontrol/visualize/plotly.py @@ -153,9 +153,7 @@ def plot(data: PlotData, controls: PlotControls): fig.update_layout(width=500, height=500) # cicd_testing is a flag set by the CICD testing script (as a temporary environmental variable) to save the plot as a .png file - if not cicd_testing: - fig.show() - else: + if cicd_testing: import plotly.io as pio from datetime import datetime pio.write_image(fig, datetime.now().strftime("figure__%d-%m-%Y__%H-%M-%S.png")) From 7ee92ebb7ea33584c21a014689a253eef69b5dbd Mon Sep 17 00:00:00 2001 From: Awolstrup Date: Wed, 30 Sep 2026 08:50:48 +0100 Subject: [PATCH 2/4] Tentative fix to double show bug. Added new plot_control called return_fig to allow for selective figure return or legacy fig show behaviour. --- fullcontrol/visualize/controls.py | 2 ++ fullcontrol/visualize/steps2visualization.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fullcontrol/visualize/controls.py b/fullcontrol/visualize/controls.py index 9453e39..26e19a4 100644 --- a/fullcontrol/visualize/controls.py +++ b/fullcontrol/visualize/controls.py @@ -19,6 +19,7 @@ class PlotControls(BaseModel): hide_axes (Optional[bool]): Whether to hide axes in the plot. Default is False. neat_for_publishing (Optional[bool]): Whether to optimize the plot for publishing. Default is False. raw_data (Optional[bool]): Whether to show raw data in the plot. Default is False. + return_fig (Optional[bool]): Whether to return the plotly figure object (True) or show it with returning (False). Defaults to False to match backwards compatability. printer_name (Optional[str]): The name of the printer. Default is 'generic'. initialization_data (Optional[dict]): Information about initial printing conditions. Default is an empty dictionary. Values passed for initialization_data overwrite the default initialization_data of the printer. """ @@ -33,6 +34,7 @@ class PlotControls(BaseModel): hide_axes: Optional[bool] = False neat_for_publishing: Optional[bool] = False raw_data: Optional[bool] = False + return_fig: Optional[bool] = False printer_name: Optional[str] = 'generic' # initialization_data is information about initial printing conditions, which may be changed by the fullcontrol 'design', whereas the above attributes are never changed by the 'design' initialization_data: Optional[dict] = {} # values passed for initialization_data overwrite the default initialization_data of the printer diff --git a/fullcontrol/visualize/steps2visualization.py b/fullcontrol/visualize/steps2visualization.py index 6d35a7e..23d26f1 100644 --- a/fullcontrol/visualize/steps2visualization.py +++ b/fullcontrol/visualize/steps2visualization.py @@ -14,7 +14,7 @@ def visualize(steps: list, plot_controls: PlotControls, show_tips: bool): - plot_controls (PlotControls, optional): The style of the plot can be adjusted by passing a PlotControls instance. Returns: - - PlotData if `plot_controls.raw_data` is True, otherwise the Plotly Figure. + - PlotData if `plot_controls.raw_data` is True. Or return Plotly figure object of `plot_controls.return_fig` is True. Otherwise return nothing and show figure (matches legacy behaviour). ''' plot_controls.initialize() if show_tips: tips(plot_controls) @@ -29,4 +29,9 @@ def visualize(steps: list, plot_controls: PlotControls, show_tips: bool): return plot_data else: from fullcontrol.visualize.plotly import plot - return plot(plot_data, plot_controls) + fig = plot(plot_data, plot_controls) + + if plot_controls.return_fig == True: + return fig + else: + fig.show() From 50a756f538bdb40f280e3e335e402fa4bc000e02 Mon Sep 17 00:00:00 2001 From: Awolstrup Date: Wed, 30 Sep 2026 09:03:16 +0100 Subject: [PATCH 3/4] Tentative update to to tutorial notebook. --- tutorials/plot_controls.ipynb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tutorials/plot_controls.ipynb b/tutorials/plot_controls.ipynb index 41545eb..0225485 100644 --- a/tutorials/plot_controls.ipynb +++ b/tutorials/plot_controls.ipynb @@ -16,6 +16,7 @@ "- `hide_axes` - True/False\n", "- `neat_for_publishing` - True/False (square format for consistent png creation)\n", "- `raw_data` - True/False (output data instead of creating a plot)\n", + "- `return_fig` - True/False (output figure object instead of showing plot immediatly)\n", "- `style` - options: 'tube'/'line' - preview 3D real-printed-volume lines or simple lines with non-representative widths\n", " - if `style == 'tube'`:\n", " - `tube_type` - options: 'flow'/'cylinders' - adjust how the plot transitions from line to line\n", @@ -313,7 +314,7 @@ "source": [ "#### edit the returned figure\n", "\n", - "`fc.transform` displays and returns a Plotly figure, which can be edited and shown again with updated formatting" + "`fc.transform` displays or returns a Plotly figure depending on `plot_controls.return_fig`. If `return_fig` is True it can be edited and shown again with updated formatting." ] }, { @@ -323,7 +324,9 @@ "outputs": [], "source": [ "print('Original figure:')\n", - "fig = fc.transform(steps, 'plot', show_tips=False)\n", + "plot_controls = fc.PlotControls(return_fig=True)\n", + "fig = fc.transform(steps, 'plot', plot_controls, show_tips=False)\n", + "fig.show()\n", "\n", "# Update the template and override the explicitly set background colors.\n", "fig.update_layout(\n", From c933544a77fddc30ba4054b6b09618513dbcc271 Mon Sep 17 00:00:00 2001 From: Awolstrup Date: Wed, 30 Sep 2026 09:15:10 +0100 Subject: [PATCH 4/4] Tested changes in local copy of plot_controls tutorial, and updated colab tutorial to match. Should be ready for PR --- tutorials/colab/plot_controls_colab.ipynb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tutorials/colab/plot_controls_colab.ipynb b/tutorials/colab/plot_controls_colab.ipynb index 81696c2..eb9cd59 100644 --- a/tutorials/colab/plot_controls_colab.ipynb +++ b/tutorials/colab/plot_controls_colab.ipynb @@ -16,6 +16,7 @@ "- `hide_axes` - True/False\n", "- `neat_for_publishing` - True/False (square format for consistent png creation)\n", "- `raw_data` - True/False (output data instead of creating a plot)\n", + "- `return_fig` - True/False (output figure object instead of showing plot immediatly)\n", "- `style` - options: 'tube'/'line' - preview 3D real-printed-volume lines or simple lines with non-representative widths\n", " - if `style == 'tube'`:\n", " - `tube_type` - options: 'flow'/'cylinders' - adjust how the plot transitions from line to line\n", @@ -313,7 +314,7 @@ "source": [ "#### edit the returned figure\n", "\n", - "`fc.transform` displays and returns a Plotly figure, which can be edited and shown again with updated formatting" + "`fc.transform` displays or returns a Plotly figure depending on `plot_controls.return_fig`. If `return_fig` is True it can be edited and shown again with updated formatting." ] }, { @@ -323,7 +324,9 @@ "outputs": [], "source": [ "print('Original figure:')\n", - "fig = fc.transform(steps, 'plot', show_tips=False)\n", + "plot_controls = fc.PlotControls(return_fig=True)\n", + "fig = fc.transform(steps, 'plot', plot_controls, show_tips=False)\n", + "fig.show()\n", "\n", "# Update the template and override the explicitly set background colors.\n", "fig.update_layout(\n",