Skip to content

Commit

Permalink
FIX: Add all curves on the multi axis plot to the list of items. Fixe…
Browse files Browse the repository at this point in the history
…s these items not being removed on plot clear, as well as various options in the plot context menu.
  • Loading branch information
jbellister-slac committed Jul 5, 2022
1 parent a746b1a commit 14e7581
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pydm/tests/widgets/test_waveform_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,42 @@ def test_mismatched_shapes(qtbot):
# Opposite case: the x-waveform was longer than the y one, so it gets truncated to match the length of y
assert np.array_equal(data_item_1.x_waveform, np.array([1, 5, 10]))
assert np.array_equal(data_item_1.y_waveform, np.array([10, 11, 12]))


def test_clear_curves(qtbot):
""" Verify that all curves are removed from a waveform plot when clearCurves() is called """
# Create a plot with two curves added to it
waveform_plot = PyDMWaveformPlot()
qtbot.addWidget(waveform_plot)
data_one = WaveformCurveItem()
data_two = WaveformCurveItem()
waveform_plot.addCurve(data_one)
waveform_plot.addCurve(data_two)

assert len(waveform_plot.plotItem.curves) == 2 # Confirm that the curves were added properly

waveform_plot.clearCurves()
assert len(waveform_plot.plotItem.curves) == 0 # Now they should be gone


def test_clear_axes(qtbot):
""" Verify that when multiple y-axes are added to a plot, clearing out the curves and axes cleans up everything """
# Create a plot with two separate y axes on it, each with its own associated view box
waveform_plot = PyDMWaveformPlot()
qtbot.addWidget(waveform_plot)
data_one = WaveformCurveItem()
data_two = WaveformCurveItem()
waveform_plot.addCurve(data_one, y_axis_name='Axis 1')
waveform_plot.addCurve(data_two, y_axis_name='Axis 2')

# Ensure both axes were properly added
assert 'Axis 1' in waveform_plot.plotItem.axes
assert 'Axis 2' in waveform_plot.plotItem.axes
assert len(waveform_plot.plotItem.stackedViews) == 3 # There is a main top level view in addition to the 2 we added

waveform_plot.clearAxes()

# After the call to clear both axes should be removed, and the stacked views are also empty until more data is added
assert 'Axis 1' not in waveform_plot.plotItem.axes
assert 'Axis 2' not in waveform_plot.plotItem.axes
assert len(waveform_plot.plotItem.stackedViews) == 0
2 changes: 2 additions & 0 deletions pydm/widgets/multi_axis_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def linkDataToAxis(self, plotDataItem: PlotDataItem, axisName: str) -> None:
if self.legend is not None and plotDataItem.name():
self.legend.addItem(plotDataItem, name=plotDataItem.name())

# pyqtgraph expects data items on plots to be added to both the list of curves and items to function properly
self.curves.append(plotDataItem)
self.items.append(plotDataItem)
self.curvesPerAxis[axisName] += 1

def removeAxis(self, axisName):
Expand Down

0 comments on commit 14e7581

Please sign in to comment.