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

change the way of getting index of data picked to be more accurate on...

change the way of getting index of data picked to be more accurate on upDownDots and return real_idx instead of list_idx and section_idx; return old code for plotting widget which including getting plotting_data2 for mass_position;
parent e4a7e49e
No related branches found
No related tags found
1 merge request!159Correct clicking data point for info
...@@ -5,7 +5,6 @@ from typing import List, Optional, Union ...@@ -5,7 +5,6 @@ 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
...@@ -15,7 +14,7 @@ from sohstationviewer.conf import constants ...@@ -15,7 +14,7 @@ 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.plotting.plotting_widget.plotting_widget_helper \ 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 ( from sohstationviewer.view.plotting.plotting_widget.plotting_axes import (
PlottingAxes PlottingAxes
) )
...@@ -304,32 +303,52 @@ class PlottingWidget(QtWidgets.QScrollArea): ...@@ -304,32 +303,52 @@ class PlottingWidget(QtWidgets.QScrollArea):
""" """
self.is_button_press_event_triggered_pick_event = True self.is_button_press_event_triggered_pick_event = True
artist = event.artist artist = event.artist
ax = artist.axes
if isinstance(artist, pl.Line2D): if isinstance(artist, pl.Line2D):
# normal channels ax = artist.axes
click_index = event.ind[0] chan_id = ax.chan
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]
try: try:
self.parent.search_message_dialog. \ chan_data = self.plotting_data1[chan_id]
show_log_entry_from_data_index(clicked_log_idx) except KeyError:
except ValueError as e: # in case of mass position
QtWidgets.QMessageBox.warning(self, "Not found", chan_data = self.plotting_data2[chan_id]
str(e)) # 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): def on_button_press_event(self, event):
""" """
......
from typing import Dict, Optional from typing import List, Optional
import numpy as np import numpy as np
from matplotlib.axes import Axes
from sohstationviewer.controller.plotting_data import format_time def get_index_from_data_picked(chan_data: List[np.ndarray], tm: float, val: float) \
-> Optional[int]:
def get_data_point_info(click_index: int,
ax: Axes,
chan_data: Dict,
date_mode: str) -> str:
""" """
Get info of the clicked data point to display Get index of data picked
:param click_index: index of data point being clicked :param chan_data: dict of data to plot that includes 'times', 'data' key
:param ax: axes of channel's plot :param tm: epoch time of a clicked point
:param chan_data: data info of a channel as a dict :param val: data value of a clicked point
:param date_mode: the format of date, time :return section_idx: index of tm inside np.ndarray found
:return info_str: info of data point as text
""" """
if chan_data['chan_db_info']['plotType'] == 'upDownDots':
clicked_time = chan_data['times'][0][click_index] # actual plotting has value -0.5 or 0.5;
clicked_data = chan_data['data'][0][click_index] # the value need to be convert to 0 or 1
if hasattr(ax, 'unit_bw'): val = 1 if val == 0.5 else 0
clicked_data = ax.unit_bw.format(clicked_data)
formatted_clicked_time = format_time( if (chan_data['chan_db_info']['plotType']
clicked_time, date_mode, 'HH:MM:SS') in ["multiColorDots", "dotForTime"]):
info_str = (f"<pre>Channel: {ax.chan} " # don't check val because the plot's data don't affect the position
f"Point:{click_index + 1} " # of the data point and overlap isn't an issue.
f"Time: {formatted_clicked_time} " real_indexes = np.where(chan_data['times'][0] == tm)[0]
f"Value: {clicked_data}</pre>") else:
return info_str real_indexes = np.where((chan_data['times'][0] == tm) &
(chan_data['data'][0] == val))[0]
if len(real_indexes) != 1:
return
return real_indexes[0]
def get_total_miny_maxy( def get_total_miny_maxy(
......
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