Skip to content
Snippets Groups Projects

Correct clicking data point for info

Merged Lan Dam requested to merge i134_mass_pos_not_show_datapoint_info into master
2 files
+ 69
53
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,7 +5,6 @@ from typing import List, Optional, Union
import numpy as np
import matplotlib.text
from matplotlib import pyplot as pl
from matplotlib.collections import PathCollection
from matplotlib.transforms import Bbox
from PySide6.QtCore import QTimer, Qt
from PySide6 import QtCore, QtWidgets
@@ -15,7 +14,7 @@ from sohstationviewer.conf import constants
from sohstationviewer.view.util.color import set_color_mode
from sohstationviewer.view.plotting.plotting_widget.plotting_widget_helper \
import get_data_point_info, get_total_miny_maxy
import get_index_from_data_picked, get_total_miny_maxy
from sohstationviewer.view.plotting.plotting_widget.plotting_axes import (
PlottingAxes
)
@@ -304,32 +303,52 @@ class PlottingWidget(QtWidgets.QScrollArea):
"""
self.is_button_press_event_triggered_pick_event = True
artist = event.artist
ax = artist.axes
if isinstance(artist, pl.Line2D):
# normal channels
click_index = event.ind[0]
chan_data = self.plotting_data1[ax.chan]
elif isinstance(artist, PathCollection):
# mass position channels
click_index = event.ind[0]
chan_data = self.plotting_data2[ax.chan]
else:
return
info_str = get_data_point_info(
click_index, ax, chan_data, self.date_mode)
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][click_index]
ax = artist.axes
chan_id = ax.chan
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))
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))
def on_button_press_event(self, event):
"""
Loading