Skip to content
Snippets Groups Projects
Commit 8bc7db76 authored by Lan Dam's avatar Lan Dam
Browse files

calling get_data_point_info() instead of very complicated code to calculate for data point's info

parent 4ec0c2c2
No related branches found
No related tags found
1 merge request!159Correct clicking data point for info
Pipeline #2879 failed with stage
in 3 minutes and 14 seconds
...@@ -5,6 +5,7 @@ from typing import List, Optional, Union ...@@ -5,6 +5,7 @@ from typing import List, Optional, Union
import numpy as np import numpy as np
import matplotlib.text import matplotlib.text
from matplotlib import pyplot as pl from matplotlib import pyplot as pl
from matplotlib.collections import PathCollection
from matplotlib.transforms import Bbox from matplotlib.transforms import Bbox
from PySide6.QtCore import QTimer, Qt from PySide6.QtCore import QTimer, Qt
from PySide6 import QtCore, QtWidgets from PySide6 import QtCore, QtWidgets
...@@ -12,9 +13,9 @@ from PySide6.QtWidgets import QWidget, QApplication, QTextBrowser ...@@ -12,9 +13,9 @@ from PySide6.QtWidgets import QWidget, QApplication, QTextBrowser
from sohstationviewer.conf import constants from sohstationviewer.conf import constants
from sohstationviewer.view.util.color import set_color_mode from sohstationviewer.view.util.color import set_color_mode
from sohstationviewer.view.util.functions import (
get_total_miny_maxy, get_index_from_time from sohstationviewer.view.plotting.plotting_widget.plotting_widget_helper \
) import get_data_point_info, get_total_miny_maxy
from sohstationviewer.view.plotting.plotting_widget.plotting_axes import ( from sohstationviewer.view.plotting.plotting_widget.plotting_axes import (
PlottingAxes PlottingAxes
) )
...@@ -296,50 +297,32 @@ class PlottingWidget(QtWidgets.QScrollArea): ...@@ -296,50 +297,32 @@ class PlottingWidget(QtWidgets.QScrollArea):
focus SOH tab, roll to the corresponding line. focus SOH tab, roll to the corresponding line.
""" """
artist = event.artist artist = event.artist
if isinstance(artist, pl.Line2D): ax = artist.axes
ax = artist.axes
chan_id = ax.chan
chan_data = self.plotting_data1[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]
list_idx, section_idx = get_index_from_time(
chan_data, clicked_time, clicked_val)
if list_idx is None:
display_tracking_info(self.tracking_box, "Point not found.")
return
clicked_data = chan_data['data'][list_idx][section_idx] if isinstance(artist, pl.Line2D):
if hasattr(ax, 'unit_bw'): # normal channels
clicked_data = ax.unit_bw.format(clicked_data) click_index = event.ind[0]
formatted_clicked_time = format_time( chan_data = self.plotting_data1[ax.chan]
clicked_time, self.date_mode, 'HH:MM:SS') elif isinstance(artist, PathCollection):
info_str = (f"<pre>Channel: {chan_id} " # mass position channels
f"Point:{click_plot_index + 1} " click_index = event.ind[0]
f"Time: {formatted_clicked_time} " chan_data = self.plotting_data2[ax.chan]
f"Value: {clicked_data}</pre>") else:
display_tracking_info(self.tracking_box, info_str) return
if 'logIdx' in chan_data.keys(): info_str = get_data_point_info(
# For Reftek, need to hightlight the corresponding click_index, ax, chan_data, self.date_mode)
# SOH message line based on the log_idx of the clicked point display_tracking_info(self.tracking_box, info_str)
self.parent.search_message_dialog.show() if 'logIdx' in chan_data.keys():
clicked_log_idx = chan_data['logIdx'][0][section_idx] # For Reftek, need to hightlight the corresponding
try: # SOH message line based on the log_idx of the clicked point
self.parent.search_message_dialog. \ self.parent.search_message_dialog.show()
show_log_entry_from_data_index(clicked_log_idx) clicked_log_idx = chan_data['logIdx'][0][click_index]
except ValueError as e: try:
QtWidgets.QMessageBox.warning(self, "Not found", self.parent.search_message_dialog. \
str(e)) 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): def on_button_press_event(self, event):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment