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

Showing info when click on a clickable data point

parent cfd1d720
No related branches found
No related tags found
1 merge request!37Showing info when click on a clickable data point
No preview for this file type
......@@ -33,6 +33,8 @@ class PlottingAxes:
self.fig = pl.Figure(facecolor='white', figsize=(50, 100))
self.fig.canvas.mpl_connect('button_press_event',
parent.on_button_press_event)
self.fig.canvas.mpl_connect('pick_event',
parent.on_pick_event)
"""
canvas: matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg - the
......
......@@ -2,7 +2,7 @@
Class of which object is used to plot data
"""
import numpy as np
from matplotlib import pyplot as pl
from PySide2 import QtCore, QtWidgets
from sohstationviewer.conf import constants
......@@ -12,6 +12,9 @@ from sohstationviewer.view.plotting.plotting_widget.plotting_axes import (
PlottingAxes)
from sohstationviewer.view.plotting.plotting_widget.plotting import Plotting
from sohstationviewer.controller.plottingData import formatTime
from sohstationviewer.controller.util import displayTrackingInfo
class PlottingWidget(QtWidgets.QScrollArea):
"""
......@@ -258,6 +261,43 @@ class PlottingWidget(QtWidgets.QScrollArea):
self.zoom_marker1.set_visible(False)
self.zoom_marker2.set_visible(False)
def on_pick_event(self, event):
"""
When click mouse on a clickable data point (dot with picker=True in
Plotting),
+ Point's info will be displayed in tracking_box
+ If the chan_data has key 'logIdx', raise the Search Messages dialog,
focus SOH tab, roll to the corresponding line.
"""
artist = event.artist
ax = artist.axes
chan_id = ax.chan
if isinstance(artist, pl.Line2D):
chan_data = self.plotting_data1[chan_id]
# list of x values of the plot
x_list = artist.get_xdata()
# index of the clicked point on the plot
click_plot_index = event.ind[0]
# time value of the clicked point
clicked_time = x_list[click_plot_index]
# indexes of the clicked time in data (one value only)
clicked_indexes = np.where(chan_data['times'] == clicked_time)
"""
clicked_indexes and click_plot_index can be different if there
are different plots for a channel.
"""
clicked_data = chan_data['data'][clicked_indexes][0]
if hasattr(ax, 'unit_bw'):
clicked_data = ax.unit_bw.format(clicked_data)
formatted_clicked_time = formatTime(
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>")
displayTrackingInfo(self.tracking_box, info_str)
def on_button_press_event(self, event):
"""
When click mouse on the current plottingWidget, SOHView will loop
......
"""
Drawing State-Of-Health channels
Drawing State-Of-Health channels and mass position
"""
from sohstationviewer.view.util.plot_func_names import plot_functions
from sohstationviewer.view.plotting.plotting_widget import plotting_widget
......
# UI and connectSignals for MainWindow
# Display time-power-squared values for waveform data
from math import sqrt
import numpy as np
......@@ -55,8 +55,6 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
self.tps_t = 0
super().__init__(*args, **kwarg)
self.plotting_axes.fig.canvas.mpl_connect(
'pick_event', self.on_pick_event)
def plot_channels(self, start_tm=None, end_tm=None, key=None,
data_time=None, waveform_data=None):
......@@ -107,9 +105,19 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
def get_plot_data(self, c_data, chan_id):
"""
Trim data to minx, max_x and calculate time-power-square for each 5
minute into c_data['tps_data'] then draw each 5 minute with the
color corresponding to value
TPS is plotted in lines of small rectangular, so called bars.
Each line is a day so - y value is the order of days
Each bar is data represent for 5 minutes so x value is the order of
five minute in a day
If there is no data in a portion of a day, the bars in the portion
will have grey color.
For the five minutes that have data, the color of the bars will be
based on mapping between tps value of the five minutes against
the selected color range.
This function trim data to minx, max_x and calculate time-power-square
for each 5 minute into c_data['tps_data'] then draw each 5 minute
with the color corresponding to value.
Create ruler, zoom_marker1, zoom_marker2 for the channel.
:param c_data: dict - data of the channel which includes down-sampled
......@@ -157,6 +165,7 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
square_counts = self.parent.sel_square_counts # square counts range
color_codes = self.parent.color_def # colordef
# --------------------------- PLOT TPS -----------------------------#
for dayIdx, y in enumerate(c_data['tps_data']):
# not draw data out of day range
color_set = self.get_color_set(y, square_counts, color_codes)
......@@ -266,27 +275,34 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget):
xdata = event.mouseevent.xdata
if xdata is None:
return
xdata = round(xdata)
xdata = round(xdata) # x value on the plot
# when click on outside xrange that close to edge, adjust to edge
if xdata in [-2, -1]:
xdata = 0
if xdata in [288, 289]:
xdata = 287
ydata = round(event.mouseevent.ydata)
y_idx = - ydata
x_idx = xdata
# identify time for rulers on other plotting widget
self.tps_t = self.each_day5_min_list[y_idx, x_idx]
format_t = formatTime(self.tps_t, self.date_mode, 'HH:MM:SS')
info_str += f"{format_t}:"
for chan_id in self.plotting_data1:
c_data = self.plotting_data1[chan_id]
data = c_data['tps_data'][y_idx, x_idx]
info_str += f" {chan_id}:{fmti(sqrt(data))}"
info_str += " (counts)"
displayTrackingInfo(self.tracking_box, info_str)
self.draw()
ydata = round(event.mouseevent.ydata) # y value on the plot
# refer to description in get_plot_data to understand x,y vs
# day_index, five_min_index
day_index = - ydata
five_min_index = xdata
try:
# identify time for rulers on other plotting widget
self.tps_t = self.each_day5_min_list[day_index, five_min_index]
format_t = formatTime(self.tps_t, self.date_mode, 'HH:MM:SS')
info_str += f"<pre>{format_t}:"
for chan_id in self.plotting_data1:
c_data = self.plotting_data1[chan_id]
data = c_data['tps_data'][day_index, five_min_index]
info_str += f" {chan_id}:{fmti(sqrt(data))}"
info_str += " (counts)</pre>"
displayTrackingInfo(self.tracking_box, info_str)
self.draw()
except IndexError:
# exclude the extra points added to the 2 sides of x axis to
# show the entire highlight box
pass
def on_ctrl_cmd_click(self, xdata):
"""
......@@ -446,6 +462,7 @@ class TimePowerSquaredDialog(QtWidgets.QWidget):
def resizeEvent(self, event):
"""
OVERRIDE Qt method.
When TimePowerDialog is resized, its plotting_widget need to initialize
its size to fit the viewport.
......
......@@ -193,6 +193,7 @@ class WaveformDialog(QtWidgets.QWidget):
def resizeEvent(self, event):
"""
OVERRIDE Qt method.
When WaveformDialog is resized, its plotting_widget need to initialize
its size to fit the viewport.
......
......@@ -55,7 +55,7 @@ class TestExtractData(unittest.TestCase):
'convertFactor': 1,
'label': 'LCE-PhaseError',
'fixPoint': 0,
'valueColors': 'L:W'}
'valueColors': 'L:W|D:Y'}
self.assertDictEqual(getChanPlotInfo('LCE', 'Unknown'),
expected_result)
......
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