Skip to content

Commit

Permalink
BUG #143 added try except for plot and calculate basicmaths
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolakis committed Jun 12, 2024
1 parent c38d649 commit 124dc0e
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions mdaviz/chartview.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ def onCurveAdded(self, curveID):
ds = curveData["ds"]
ds_options = curveData["ds_options"]
# Plot and store the plot object associated with curveID:
plot_obj = self.main_axes.plot(*ds, **ds_options)[0]
self.plotObjects[curveID] = plot_obj
try:
plot_obj = self.main_axes.plot(*ds, **ds_options)[0]
self.plotObjects[curveID] = plot_obj
except Exception as exc:
print(str(exc))
# Update plot
self.updatePlot(update_title=True)
# Add to the comboBox
Expand Down Expand Up @@ -382,19 +385,24 @@ def onFactorUpdated(self):

def updateBasicMathInfo(self, curveID):
if curveID and curveID in self.curveManager.curves():
curve_data = self.curveManager.getCurveData(curveID)
x = curve_data["ds"][0]
y = curve_data["ds"][1]
stats = self.calculateBasicMath(x, y)
for i, txt in zip(stats, ["min_text", "max_text", "com_text", "mean_text"]):
if isinstance(i, tuple):
result = f"({utils.num2fstr(i[0])}, {utils.num2fstr(i[1])})"
else:
result = f"{utils.num2fstr(i)}" if i else "n/a"
self.mda_mvc.findChild(QtWidgets.QLabel, txt).setText(result)
try:
curve_data = self.curveManager.getCurveData(curveID)
x = curve_data["ds"][0]
y = curve_data["ds"][1]
stats = self.calculateBasicMath(x, y)
for i, txt in zip(
stats, ["min_text", "max_text", "com_text", "mean_text"]
):
if isinstance(i, tuple):
result = f"({utils.num2fstr(i[0])}, {utils.num2fstr(i[1])})"
else:
result = f"{utils.num2fstr(i)}" if i else "n/a"
self.mda_mvc.findChild(QtWidgets.QLabel, txt).setText(result)
except Exception as exc:
print(str(exc))
self.clearBasicMath()
else:
for txt in ["min_text", "max_text", "com_text", "mean_text"]:
self.mda_mvc.findChild(QtWidgets.QLabel, txt).setText("n/a")
self.clearBasicMath()

def clearBasicMath(self):
for txt in ["min_text", "max_text", "com_text", "mean_text"]:
Expand Down

0 comments on commit 124dc0e

Please sign in to comment.