Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting refactor integration #3111

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
28 changes: 20 additions & 8 deletions src/sas/qtgui/MainWindow/DataExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,14 +1076,14 @@ def displayDataByName(self, name=None, is_data=True, id=None):
# Residuals get their own plot
if plot.plot_role in [DataRole.ROLE_RESIDUAL, DataRole.ROLE_STAND_ALONE]:
plot.yscale = 'linear'
self.plotData([(item, plot)])
self.plotData([(item, plot)], id)
else:
new_plots.append((item, plot))

if new_plots:
self.plotData(new_plots)
self.plotData(new_plots, id)

def displayData(self, data_list, id=None):
def displayData(self, data_list, id):
"""
Forces display of charts for the given data set
"""
Expand All @@ -1109,7 +1109,7 @@ def displayData(self, data_list, id=None):
if self.isPlotShown(main_data):
self.active_plots[main_data.name].showNormal()
else:
self.plotData([(plot_item, main_data)])
self.plotData([(plot_item, main_data)], id)

append = False
plot_to_append_to = None
Expand All @@ -1134,7 +1134,7 @@ def displayData(self, data_list, id=None):
continue
elif role in stand_alone_types:
# Stand-alone plots should always be separate
self.plotData([(plot_item, plot_to_show)])
self.plotData([(plot_item, plot_to_show)], id)
elif append:
# Assume all other plots sent together should be on the same chart if a previous plot exists
if not plot_to_append_to:
Expand All @@ -1156,7 +1156,9 @@ def displayData(self, data_list, id=None):
new_plots = []

if new_plots:
self.plotData(new_plots)
self.plotData(new_plots, id)

self.parent.tabbedPlotWidget.show_or_activate()

def isPlotShown(self, plot):
"""
Expand Down Expand Up @@ -1192,17 +1194,25 @@ def addDataPlot2D(self, plot_set, item):
# sv.show()
# ============================================

def plotData(self, plots, transform=True):
def plotData(self, plots, tab_id, transform=True):
"""
Takes 1D/2D data and generates a single plot (1D) or multiple plots (2D)
"""
tab_index = self.parent.tabbedPlotWidget.tab_fitpage_dict[tab_id]
print("plotData")
# Call show on requested plots
# All same-type charts in one plot
for item, plot_set in plots:
if isinstance(plot_set, Data1D):
if 'new_plot' not in locals():
new_plot = PlotterWidget(manager=self, parent=self)
# Create only one PlotterWidget(QWidget) for a number of datasets that are supposed to be shown in
# the same Widget
self.parent.tabbedPlotWidget.widget(tab_index).add_more_axes()
tpw_ax = self.parent.tabbedPlotWidget.widget(tab_index).last_axes()

new_plot = PlotterWidget(manager=self, parent=self, tpw_ax=tpw_ax)
new_plot.item = item
print("plotted plot for:", item)
new_plot.plot(plot_set, transform=transform)
# active_plots may contain multiple charts
self.active_plots[plot_set.name] = new_plot
Expand All @@ -1212,6 +1222,7 @@ def plotData(self, plots, transform=True):
msg = "Incorrect data type passed to Plotting"
raise AttributeError(msg)


if 'new_plot' in locals() and \
hasattr(new_plot, 'data') and \
isinstance(new_plot.data[0], Data1D):
Expand Down Expand Up @@ -1286,6 +1297,7 @@ def appendPlot(self):
@staticmethod
def appendOrUpdatePlot(self, data, plot):
name = data.name
print("append or update plot")
if isinstance(plot, Plotter2DWidget) or name in plot.plot_dict.keys():
plot.replacePlot(name, data)
else:
Expand Down
4 changes: 4 additions & 0 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
from sas.qtgui.Utilities.FileConverter import FileConverterWidget
from sas.qtgui.Utilities.WhatsNew.WhatsNew import WhatsNew

from sas.qtgui.Plotting.TabbedPlotWidget import TabbedPlotWidget

import sas
from sas import config
from sas.system import web
Expand Down Expand Up @@ -212,6 +214,8 @@ def addWidgets(self):
self.WhatsNew = WhatsNew(self)
self.regenProgress = DocRegenProgress(self)

self.tabbedPlotWidget = TabbedPlotWidget(self)

def loadAllPerspectives(self):
""" Load all the perspectives"""
# Close any existing perspectives to prevent multiple open instances
Expand Down
15 changes: 13 additions & 2 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, parent=None, data=None, tab_id=1):
super(FittingWidget, self).__init__()

# Necessary globals
self.parent = parent
self.parent = parent
self.process = None # Default empty value

# Which tab is this widget displayed in?
Expand Down Expand Up @@ -2507,16 +2507,27 @@ def _requestPlots(self, item_name, item_model):
"""
Emits plotRequestedSignal for all plots found in the given model under the provided item name.
"""
# send this information to the TabbedPlotWidget so that it can unpack and show the plots as well
self.parent.tabbedPlotWidget.add_tab(item_name, item_model, self.tab_id)

# tab_index = self.parent.tabbedPlotWidget.tab_fitpage_dict[self.tab_id]
# self.parent.tabbedPlotWidget.widget(tab_index).add_more_axes
# tpw_axes = self.parent.tabbedPlotWidget.widget(tab_index).ax


fitpage_name = self.kernel_module.name
plots = GuiUtils.plotsFromDisplayName(item_name, item_model)
# Has the fitted data been shown?
data_shown = False
item = None
for item, plot in plots.items():
for i, item_plot in enumerate(plots.items()):
item, plot = item_plot
if plot.plot_role != DataRole.ROLE_DATA and fitpage_name in plot.name:
data_shown = True
self.communicate.plotRequestedSignal.emit([item, plot], self.tab_id)
# return the last data item seen, if nothing was plotted; supposed to be just data)
tab_index = self.parent.tabbedPlotWidget.tab_fitpage_dict[self.tab_id]
self.parent.tabbedPlotWidget.widget(tab_index).rearrange_plots()
return None if data_shown else item

def onOptionsUpdate(self):
Expand Down
Loading
Loading