diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py index 509fb61877b287dffa265e1992cbf999d587610f..1ed59748369541159477765dff94dd068eed9768 100755 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py @@ -303,52 +303,62 @@ class PlottingWidget(QtWidgets.QScrollArea): """ self.is_button_press_event_triggered_pick_event = True artist = event.artist - if isinstance(artist, pl.Line2D): - ax = artist.axes - chan_id = ax.chan + if not isinstance(artist, pl.Line2D): + return + ax = artist.axes + chan_id = ax.chan + try: + chan_data = self.plotting_data1[chan_id] + except KeyError: + # in case of mass position + chan_data = self.plotting_data2[chan_id] + # list of x values of the plot + x_list = artist.get_xdata() + # list of y values of the plot + y_list = artist.get_ydata() + + # index of the clicked point on the plot + click_plot_index = event.ind[0] + + # time, val of the clicked point + clicked_time = x_list[click_plot_index] + clicked_val = y_list[click_plot_index] + + real_idxes = get_index_from_data_picked( + chan_data, clicked_time, clicked_val) + if len(real_idxes) == 0: + display_tracking_info(self.tracking_box, "Point not found.") + return + + clicked_data = chan_data['data'][0][real_idxes[0]] + if hasattr(ax, 'unit_bw'): + clicked_data = ax.unit_bw.format(clicked_data) + formatted_clicked_time = format_time( + clicked_time, self.date_mode, 'HH:MM:SS') + info_str = (f"<pre>Channel: {chan_id} " + f"Point:{click_plot_index + 1} " + f"Time: {formatted_clicked_time} " + f"Value: {clicked_data}</pre>") + if self.log_data is not None: + log_idxes = [chan_data['logIdx'][0][idx] + for idx in real_idxes] + if len(real_idxes) > 1: + info_str = info_str.replace( + "</pre>", f" ({len(real_idxes)} lines)") + for idx in real_idxes: + info_str += ( + "<pre> " + self.log_data[log_idxes[idx]] + "</pre>") + display_tracking_info(self.tracking_box, info_str) + if 'logIdx' in chan_data.keys(): + # For Reftek, need to hightlight the corresponding + # SOH message lines based on the log_idxes of the clicked point + self.parent.search_message_dialog.show() try: - chan_data = self.plotting_data1[chan_id] - except KeyError: - # in case of mass position - chan_data = self.plotting_data2[chan_id] - # list of x values of the plot - x_list = artist.get_xdata() - # list of y values of the plot - y_list = artist.get_ydata() - - # index of the clicked point on the plot - click_plot_index = event.ind[0] - - # time, val of the clicked point - clicked_time = x_list[click_plot_index] - clicked_val = y_list[click_plot_index] - - real_idx = get_index_from_data_picked( - chan_data, clicked_time, clicked_val) - if real_idx is None: - display_tracking_info(self.tracking_box, "Point not found.") - return - clicked_data = chan_data['data'][0][real_idx] - if hasattr(ax, 'unit_bw'): - clicked_data = ax.unit_bw.format(clicked_data) - formatted_clicked_time = format_time( - clicked_time, self.date_mode, 'HH:MM:SS') - info_str = (f"<pre>Channel: {chan_id} " - f"Point:{click_plot_index + 1} " - f"Time: {formatted_clicked_time} " - f"Value: {clicked_data}</pre>") - display_tracking_info(self.tracking_box, info_str) - if 'logIdx' in chan_data.keys(): - # For Reftek, need to hightlight the corresponding - # SOH message line based on the log_idx of the clicked point - self.parent.search_message_dialog.show() - clicked_log_idx = chan_data['logIdx'][0][real_idx] - try: - self.parent.search_message_dialog. \ - show_log_entry_from_data_index(clicked_log_idx) - except ValueError as e: - QtWidgets.QMessageBox.warning(self, "Not found", - str(e)) + self.parent.search_message_dialog. \ + show_log_entry_from_log_indexes(log_idxes) + except ValueError as e: + QtWidgets.QMessageBox.warning(self, "Not found", + str(e)) def on_button_press_event(self, event): """