Skip to content
Snippets Groups Projects

Use new editor for valuesColor in Parameter dialog

Merged Kien Le requested to merge feature-#193-better_editor_for_valuesColor into develop
2 unresolved threads
1 file
+ 7
9
Compare changes
  • Side-by-side
  • Inline
@@ -3,13 +3,12 @@ from typing import Dict, Optional
import numpy as np
from matplotlib.axes import Axes
from sohstationviewer.controller.util import get_val
from sohstationviewer.view.plotting.plotting_widget.plotting_helper import (
get_masspos_value_colors,
get_categorized_data_from_value_color_equal_on_lower_bound,
get_categorized_data_from_value_color_equal_on_upper_bound
)
from sohstationviewer.view.util.plot_func_names import plot_functions
from sohstationviewer.view.util.plot_type_info import plot_types
from sohstationviewer.view.util.color import clr
from sohstationviewer.view.plotting.plotting_widget.plotting_helper import (
get_colors_sizes_for_abs_y_from_value_colors, apply_convert_factor
@@ -90,14 +89,14 @@ class Plotting:
points, len(points) * [0], linestyle="",
marker='s', markersize=2,
zorder=constants.Z_ORDER['DOT'],
color=clr[c], picker=True, pickradius=3)
color=c, picker=True, pickradius=3)
ax.chan_plots.append(chan_plot)
total_samples = len(x)
if len(colors) != 1:
sample_no_colors = [None, clr['W'], None]
sample_no_colors = [None, '#FFFFFF', None]
else:
sample_no_colors = [None, clr[colors[0]], None]
sample_no_colors = [None, colors[0], None]
self.plotting_axes.set_axes_info(
ax, sample_no_list=[None, total_samples, None],
@@ -135,12 +134,10 @@ class Plotting:
"""
Plot 3 different values in 3 lines with 3 different colors according
to valueColors:
Ex: -1:M|0:R|1:Y means
value = -1 => plot on line y=-1 with M color
value = 0 => plot on line y=0 with R color
value = 1 => plot on line y=1 with Y color
Color codes are defined in colorSettings and limited in 'valColRE'
in dbSettings.py
Ex: "-1:#FF0000|0:#00FF00|1:#0000FF" means
value = -1 => plot on line y=-1 with #FF0000 color
value = 0 => plot on line y=0 with #00FF00 color
value = 1 => plot on line y=1 with #0000FF color
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
@@ -161,8 +158,8 @@ class Plotting:
total_sample_list = []
for vc in value_colors:
v, c = vc.split(':')
sample_no_colors.append(clr[c])
val = get_val(v)
sample_no_colors.append(c)
val = int(v)
indexes = np.where(c_data['data'][0] == val)[0]
times = c_data['times'][0][indexes]
@@ -180,7 +177,7 @@ class Plotting:
times, len(times) * [val], linestyle="",
marker='s', markersize=2,
zorder=constants.Z_ORDER['DOT'],
color=clr[c], picker=True, pickradius=3)
color=c, picker=True, pickradius=3)
ax.chan_plots.append(dots)
total_sample_list.append(len(times))
@@ -206,10 +203,9 @@ class Plotting:
"""
Plot channel with 2 different values, one above, one under center line.
Each value has corresponding color defined in valueColors in database.
Ex: 1:Y|0:R means
value == 1 => plot above center line with Y color
value == 0 => plot under center line with R color
Color codes are defined in colorSettings.
Ex: Down:#FF0000|Up:#00FFFF means
value == 1 => plot above center line with #00FFFF color
value == 0 => plot under center line with #FF0000 color
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
@@ -227,10 +223,10 @@ class Plotting:
val_cols = chan_db_info['valueColors'].split('|')
# up/down has 2 values: 0, 1 which match with index of points_list
points_list = [[], []]
colors = [[], []]
colors = {}
for vc in val_cols:
v, c = vc.split(':')
val = int(get_val(v))
val = 0 if v == 'Down' else 1
points = []
for times, data in zip(c_data['times'], c_data['data']):
points += [times[i]
@@ -243,20 +239,20 @@ class Plotting:
down_dots, = ax.plot(
points_list[0], len(points_list[0]) * [-0.5], linestyle="",
marker='s', markersize=2, zorder=constants.Z_ORDER['DOT'],
color=clr[colors[0]], picker=True, pickradius=3)
color=colors[0], picker=True, pickradius=3)
ax.chan_plots.append(down_dots)
# up dots
up_dots, = ax.plot(
points_list[1], len(points_list[1]) * [0.5], linestyle="",
marker='s', markersize=2, zorder=constants.Z_ORDER['DOT'],
color=clr[colors[1]], picker=True, pickradius=3)
color=colors[1], picker=True, pickradius=3)
ax.chan_plots.append(up_dots)
ax.set_ylim(-2, 2)
self.plotting_axes.set_axes_info(
ax,
sample_no_list=[len(points_list[0]), None, len(points_list[1])],
sample_no_colors=[clr[colors[0]], None, clr[colors[1]]],
sample_no_colors=[colors[0], None, colors[1]],
sample_no_pos=[0.25, None, 0.75],
chan_db_info=chan_db_info)
@@ -268,11 +264,14 @@ class Plotting:
ax.chan_db_info = chan_db_info
return ax
def plot_time_dots(
def plot_dot_for_time(
self, c_data: Dict, chan_db_info: Dict,
chan_id: str, ax: Optional[Axes] = None) -> Axes:
"""
Plot times only
Plot a dot at each time point in the data. The color of the dot is
specified in the valueColors
Ex: Color:#00FF00 means the dot will have the color #00FF00
:param c_data: dict - data of the channel which includes down-sampled
data in keys 'times' and 'data'. Refer to DataTypeModel.__init__.
soh_data[data_set_id][chan_id]
@@ -289,14 +288,15 @@ class Plotting:
ax = self.plotting_axes.create_axes(
self.parent.plotting_bot, plot_h)
color = 'W'
# Set the color to white by default
color = '#000000'
if chan_db_info['valueColors'] not in [None, 'None', '']:
color = chan_db_info['valueColors'].strip()
color = chan_db_info['valueColors'].strip()[6:]
x_list = c_data['times']
total_x = sum([len(x) for x in x_list])
self.plotting_axes.set_axes_info(
ax, sample_no_list=[None, total_x, None],
sample_no_colors=[None, clr[color], None],
sample_no_colors=[None, color, None],
sample_no_pos=[None, 0.5, None],
chan_db_info=chan_db_info)
@@ -304,7 +304,7 @@ class Plotting:
chan_plot, = ax.plot(
x, [0] * len(x), marker='s', markersize=1.5,
linestyle='', zorder=constants.Z_ORDER['LINE'],
color=clr[color], picker=True,
color=color, picker=True,
pickradius=3)
ax.chan_plots.append(chan_plot)
ax.x_center = x_list[0]
@@ -318,13 +318,15 @@ class Plotting:
"""
Plot lines with dots at the data points. Colors of dot and lines are
defined in valueColors in database.
Ex: L:G|D:W|Z:C means
Lines are plotted with color G
Dots are plotted with color W
Additional dot with value Zero in color C (for channel GPS Lk/Unlk)
If D is not defined, dots won't be displayed.
If L is not defined, lines will be plotted with color G
Color codes are defined in colorSettings
Ex: Line:#00FF00|Dot:#FF0000|Zero:#0000FF means
Lines are plotted with color #00FF00
Dots are plotted with color #FF0000
Additional dot with value Zero in color #0000FF (for channel GPS
Lk/Unlk)
If Dot is not defined, dots won't be displayed.
If Line is not defined, lines will be plotted with color G.
If Zero is not defined, points with value zero will be plotted the same
as other points.
:param c_data: data of the channel which includes down-sampled
(if needed) data in keys 'times' and 'data'.
@@ -349,18 +351,18 @@ class Plotting:
for cStr in color_parts:
obj, c = cStr.split(':')
colors[obj] = c
l_color = 'G'
l_color = '#00FF00'
has_dot = False
if 'L' in colors:
l_color = colors['L']
if 'D' in colors:
d_color = colors['D']
if 'Line' in colors:
l_color = colors['Line']
if 'Dot' in colors:
d_color = colors['Dot']
has_dot = True
else:
d_color = l_color
if chan_id == 'GPS Lk/Unlk':
z_color = colors['Z']
z_color = colors['Zero']
sample_no_list = []
ax.x_bottom = x_list[0][np.where(y_list[0] == -1)[0]]
sample_no_list.append(ax.x_bottom.size)
@@ -368,7 +370,7 @@ class Plotting:
sample_no_list.append(ax.x_center.size)
ax.x_top = x_list[0][np.where(y_list[0] == 1)[0]]
sample_no_list.append(ax.x_top.size)
sample_no_colors = [clr[d_color], clr[z_color], clr[d_color]]
sample_no_colors = [d_color, z_color, d_color]
sample_no_pos = [0.05, 0.5, 0.95]
top_bottom_index = np.where(y_list[0] != 0)[0]
@@ -382,15 +384,15 @@ class Plotting:
markersize=1.5,
linestyle='',
zorder=constants.Z_ORDER['DOT'],
mfc=clr[z_color],
mec=clr[z_color],
mfc=z_color,
mec=z_color,
picker=True, pickradius=3)
ax.chan_plots.append(chan_plot)
info = "GPS Clock Power"
else:
sample_no_list = [None, sum([len(x) for x in x_list]), None]
sample_no_colors = [None, clr[d_color], None]
sample_no_colors = [None, d_color, None]
sample_no_pos = [None, 0.5, None]
ax.x_center = x_list[0]
ax.y_center = y_list[0]
@@ -412,16 +414,16 @@ class Plotting:
x, y, marker='o', markersize=0.01,
linestyle='-', linewidth=0.7,
zorder=constants.Z_ORDER['LINE'],
color=clr[l_color],
color=l_color,
picker=True, pickradius=3)
else:
chan_plot, = ax.plot(
x, y, marker='s', markersize=1.5,
linestyle='-', linewidth=0.7,
zorder=constants.Z_ORDER['LINE'],
color=clr[l_color],
mfc=clr[d_color],
mec=clr[d_color],
color=l_color,
mfc=d_color,
mec=d_color,
picker=True, pickradius=3)
ax.chan_plots.append(chan_plot)
@@ -551,6 +553,6 @@ class Plotting:
# when edit select a param that has no plot type
return self.plot_no_plot_type(c_data, chan_db_info, chan_id, ax)
ax = getattr(
self, plot_functions[plot_type]['plot_function'])(
self, plot_types[plot_type]['plot_function'])(
c_data, chan_db_info, chan_id, ax)
return ax
Loading