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
1 file
+ 65
2
Compare changes
  • Side-by-side
  • Inline
from typing import List, Optional
import numpy as np
def get_index_from_data_picked(
chan_data: List[np.ndarray], tm: float, val: float) -> Optional[int]:
"""
Get index of data picked
:param chan_data: dict of data to plot that includes 'times', 'data' key
:param tm: epoch time of a clicked point
:param val: data value of a clicked point
:return section_idx: index of tm inside np.ndarray found
"""
if chan_data['chan_db_info']['plotType'] == 'upDownDots':
# actual plotting has value -0.5 or 0.5;
# the value need to be convert to 0 or 1
val = 1 if val == 0.5 else 0
if (chan_data['chan_db_info']['plotType']
in ["multiColorDots", "dotForTime"]):
# don't check val because the plot's data don't affect the position
# of the data point and overlap isn't an issue.
real_indexes = np.where(chan_data['times'][0] == tm)[0]
else:
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(
x: np.ndarray, y: Optional[np.ndarray],
min_x: float, max_x: float) -> (int, Optional[float], Optional[float]):
"""
Identify total points in channel and y_min, y_max to reset the info and
ylim
:param x: x list of the plot
:param y: y list of the plot
:param min_x: Under limit of x
:param max_x: Upper limit of x
:return: total points, new under limit of y, new upper limit of y
"""
new_x_indexes = np.where((x >= min_x) & (x <= max_x))[0]
new_x = x[new_x_indexes]
if new_x.size == 0:
return 0, None, None
new_min_x_index = min(new_x_indexes)
new_max_x_index = max(new_x_indexes)
new_y = y[new_min_x_index:new_max_x_index + 1]
new_min_y = min(new_y)
new_max_y = max(new_y)
return new_x_indexes.size, new_min_y, new_max_y
Loading