diff --git a/resource/plot.ui b/resource/plot.ui index 8419a72..224c864 100644 --- a/resource/plot.ui +++ b/resource/plot.ui @@ -90,6 +90,16 @@ + + + + autoscale + + + true + + + diff --git a/src/rqt_plot/plot_widget.py b/src/rqt_plot/plot_widget.py index 5160f55..9b80dcc 100644 --- a/src/rqt_plot/plot_widget.py +++ b/src/rqt_plot/plot_widget.py @@ -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) @@ -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) + else: + self.data_plot.set_autoscale(y=False) # setup drag 'n drop self.data_plot.dropEvent = self.dropEvent @@ -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() diff --git a/src/rqt_plot/rosplot.py b/src/rqt_plot/rosplot.py index 34783e4..7d2206f 100644 --- a/src/rqt_plot/rosplot.py +++ b/src/rqt_plot/rosplot.py @@ -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: