Skip to content
Snippets Groups Projects
Commit 09e2a977 authored by Kien Le's avatar Kien Le
Browse files

Merge branch 'bug-#246-linedots_plot_cannot_find_point_on_interaction' into 'develop'

Fix points in LineDots plots not being found when clicked on

Closes #246

See merge request !284
parents 9e6e3604 edd9a347
No related branches found
No related tags found
1 merge request!284Fix points in LineDots plots not being found when clicked on
Pipeline #3851 passed with stage
in 4 minutes and 40 seconds
......@@ -447,6 +447,9 @@ class PlottingWidget(QtWidgets.QScrollArea):
return
clicked_data = chan_data['data'][0][real_idxes[0]]
# The data stored by the data object is not converted, so we need to
# do the conversion before displaying it to the user.
clicked_data *= chan_data['chan_db_info']['convertFactor']
if chan_id.startswith('Disk Usage'):
clicked_data = get_disk_size_format(clicked_data)
if hasattr(ax, 'unit_bw'):
......
from typing import Dict, Optional
import numpy
import numpy as np
......@@ -11,6 +13,8 @@ def get_index_from_data_picked(
:param val: data value of a clicked point
:return real_indexes: list index of data point inside np.ndarray found
"""
np.set_printoptions(suppress=True)
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
......@@ -21,11 +25,29 @@ def get_index_from_data_picked(
"multiColorDotsEqualOnLowerBound", "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]
closest_point_idx = np.where(chan_data['times'][0] == tm)[0]
else:
real_indexes = np.where((chan_data['times'][0] == tm) &
(chan_data['data'][0] == val))[0]
return real_indexes
# The data is converted during plotting, so the data provided by
# matplotlib is different from the raw data. In order to fix this
# problem, we need to convert matplotlib's data back to raw data.
val = val / chan_data['chan_db_info']['convertFactor']
# Converting the data back and forth can introduce floating point
# errors, so we have to use numpy.isclose() instead of the standard
# standard comparison.
real_indexes = np.where(
(chan_data['times'][0] == tm) &
(numpy.isclose(chan_data['data'][0], val))
)[0]
if len(real_indexes) == 0:
closest_point_idx = real_indexes
else:
closest_point_idx = real_indexes[
np.argmin(np.abs(chan_data['data'][0][real_indexes] - val))
]
# We turn the index into a numpy array with one element in order to
# conform to the signature of this function.
closest_point_idx = np.array([closest_point_idx])
return closest_point_idx
def get_total_miny_maxy(
......
......@@ -12,17 +12,20 @@ class TestGetIndexFromDataPicked(BaseTestCase):
'CH1': {
'times': [np.array([1, 2, 3, 4, 5, 6, 6])],
'data': [np.array([1, 1, 0, 1, 1, 0, 0])],
'chan_db_info': {'plotType': 'upDownDots'}
'chan_db_info': {'plotType': 'upDownDots',
'convertFactor': 1}
},
'CH2': {
'times': [np.array([1, 2, 3, 3, 5, 6])],
'data': [np.array([6, 9, 7, 4, 3, 9])],
'chan_db_info': {'plotType': 'linesDots'}
'chan_db_info': {'plotType': 'linesDots',
'convertFactor': 1}
},
'CH3': {
'times': [np.array([1, 2, 3, 4, 5, 6])],
'data': [np.array([6, 9, 7, 4, 3, 9])],
'chan_db_info': {'plotType': 'dotForTime'}
'chan_db_info': {'plotType': 'dotForTime',
'convertFactor': 1}
}
}
......@@ -71,7 +74,40 @@ class TestGetIndexFromDataPicked(BaseTestCase):
def test_2_overlapped_points(self):
real_idxes = get_index_from_data_picked(
self.plotting_data['CH1'], 6, -0.5)
self.assertEqual(real_idxes.tolist(), [5, 6])
self.assertEqual(real_idxes.tolist(), [5])
def test_convert_factor_not_1(self):
# upDownDots channels always have a convert factor of 1 in practice, so
# we don't need to test them.
# multiColorDots and dotForTime channels only cares about the time,
# which is not affected by the convert factor. Thus, we don't need to
# test them.
plotting_data = {
'CH1': {
'times': [np.array([1, 2, 3, 4, 5, 6])],
'data': [np.array([6, 9, 7, 4, 3, 9])],
'chan_db_info': {'plotType': 'linesDots',
'convertFactor': 0.1}
},
}
with self.subTest('Data point can be found'):
expected = [1]
actual = list(
get_index_from_data_picked(plotting_data['CH1'], 2, 0.9)
)
self.assertEqual(expected, actual)
with self.subTest('Time not in range'):
expected = []
actual = list(
get_index_from_data_picked(plotting_data['CH1'], 20, 0.9)
)
self.assertEqual(expected, actual)
with self.subTest('Data not found'):
expected = []
actual = list(
get_index_from_data_picked(plotting_data['CH1'], 2, 9)
)
self.assertEqual(expected, actual)
class TestGetTotalMinyMaxy(BaseTestCase):
......
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