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

Add autoscale button to disable automatic y-axis scaling #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions resource/plot.ui
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="autoscale_checkbox">
<property name="text">
<string>autoscale</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoscroll_checkbox">
<property name="text">
Expand Down
13 changes: 13 additions & 0 deletions src/rqt_plot/plot_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from rqt_py_common import topic_helpers

from . rosplot import ROSData, RosPlotException
from .data_plot import DataPlot

def get_plot_fields(topic_name):
topic_type, real_topic, _ = topic_helpers.get_topic_type(topic_name)
Expand Down Expand Up @@ -154,6 +155,10 @@ def switch_data_plot_widget(self, data_plot):
self.data_plot = data_plot
self.data_plot_layout.addWidget(self.data_plot)
self.data_plot.autoscroll(self.autoscroll_checkbox.isChecked())
if self.autoscale_checkbox.isChecked():
self.data_plot.set_autoscale(y=DataPlot.SCALE_EXTEND|DataPlot.SCALE_VISIBLE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value SCALE_EXTEND|SCALE_VISIBLE is currently being defined in the plot.py file. If the patch wants to make that toggle within the widget then the default value from the plot file should be removed and instead a function on the widget should be called to achieve the same behavior without duplicating these values.

else:
self.data_plot.set_autoscale(y=False)

# setup drag 'n drop
self.data_plot.dropEvent = self.dropEvent
Expand Down Expand Up @@ -230,6 +235,14 @@ def on_autoscroll_checkbox_clicked(self, checked):
if checked:
self.data_plot.redraw()

@Slot(bool)
def on_autoscale_checkbox_clicked(self, checked):
if checked:
self.data_plot.set_autoscale(y=DataPlot.SCALE_EXTEND|DataPlot.SCALE_VISIBLE)
self.data_plot.redraw()
else:
self.data_plot.set_autoscale(y=False)

@Slot()
def on_clear_button_clicked(self):
self.clear_plot()
Expand Down
7 changes: 7 additions & 0 deletions src/rqt_plot/rosplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ def _get_topic_type(topic):
val = master.getTopicTypes()
except:
raise RosPlotException("unable to get list of topics from master")

matches = [(t, t_type) for t, t_type in val if t == topic or topic.startswith(t + '/')]

# Find the longest matching topic. So if user requests /foo/bar/baz and there are two topics, /foo and /foo/bar,
# it will match /foo/bar and look for subfield .baz, instead of /foo looking for .bar.baz.
# There is still ambiguity here, but hopefully this resolves it in the correct direction more often
matches.sort(key=lambda x: len(x[0]), reverse=True)

if matches:
t, t_type = matches[0]
if t_type == roslib.names.ANYTYPE:
Expand Down