Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fullcontrol/visualize/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions fullcontrol/visualize/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 7 additions & 2 deletions fullcontrol/visualize/steps2visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
7 changes: 5 additions & 2 deletions tutorials/colab/plot_controls_colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."
]
},
{
Expand All @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions tutorials/plot_controls.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."
]
},
{
Expand All @@ -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",
Expand Down