Skip to content

Commit

Permalink
ENH: Simplify using CurveItem subclasses in Plot subclasses
Browse files Browse the repository at this point in the history
This mirrors for all the other Plot classes what was already done with
PyDMTimePlot: Have a `createCurveItem` method that returns the relevant
object for that plot, which can be overriden in the plot's subclasses
for customized CurveItem implementations.

Signed-off-by: flowln <[email protected]>
  • Loading branch information
flowln committed Oct 19, 2023
1 parent 4354f30 commit 92a1268
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 13 additions & 1 deletion pydm/widgets/eventplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def addChannel(
plot_opts["lineStyle"] = lineStyle
if lineWidth is not None:
plot_opts["lineWidth"] = lineWidth
curve = EventPlotCurveItem(
curve = self.createCurveItem(
addr=channel,
y_idx=y_idx,
x_idx=x_idx,
Expand All @@ -359,6 +359,18 @@ def addChannel(
self.addCurve(curve, curve_color=color, y_axis_name=yAxisName)
curve.data_changed.connect(self.set_needs_redraw)

def createCurveItem(self, channel, y_idx, x_idx, name, color, yAxisName, bufferSizeChannelAddress, **plot_opts):
return EventPlotCurveItem(
addr=channel,
y_idx=y_idx,
x_idx=x_idx,
name=name,
color=color,
yAxisName=yAxisName,
bufferSizeChannelAddress=bufferSizeChannelAddress,
**plot_opts
)

def removeChannel(self, curve):
"""
Remove a curve from the plot.
Expand Down
13 changes: 12 additions & 1 deletion pydm/widgets/scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def addChannel(
plot_opts["lineWidth"] = lineWidth
if redraw_mode is not None:
plot_opts["redraw_mode"] = redraw_mode
curve = ScatterPlotCurveItem(
curve = self.createCurveItem(
y_addr=y_channel,
x_addr=x_channel,
name=name,
Expand All @@ -448,6 +448,17 @@ def addChannel(
self.addCurve(curve, curve_color=color, y_axis_name=yAxisName)
curve.data_changed.connect(self.set_needs_redraw)

def createCurveItem(self, y_addr, x_addr, name, color, yAxisName, bufferSizeChannelAddress, **plot_opts):
return ScatterPlotCurveItem(
y_addr,
x_addr,
name=name,
color=color,
yAxisName=yAxisName,
bufferSizeChannelAddress=bufferSizeChannelAddress,
**plot_opts
)

def removeChannel(self, curve):
"""
Remove a curve from the plot.
Expand Down
7 changes: 6 additions & 1 deletion pydm/widgets/waveformplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def addChannel(
if redraw_mode is not None:
plot_opts["redraw_mode"] = redraw_mode
self._needs_redraw = False
curve = WaveformCurveItem(
curve = self.createCurveItem(
y_addr=y_channel,
x_addr=x_channel,
plot_style=plot_style,
Expand All @@ -457,6 +457,11 @@ def addChannel(
curve.getViewBox().addItem(curve.bar_graph_item)
curve.data_changed.connect(self.set_needs_redraw)

def createCurveItem(self, y_addr, x_addr, plot_style, name, color, yAxisName, **plot_opts):
return WaveformCurveItem(
y_addr, x_addr, plot_style=plot_style, name=name, color=color, yAxisName=yAxisName, **plot_opts
)

def removeChannel(self, curve):
"""
Remove a curve from the plot.
Expand Down

0 comments on commit 92a1268

Please sign in to comment.