diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py index 9b2a07c8dec29bc30dbab64af93bfae92637831a..92f1329afb3d129b509ca30d2c3d91692b0643b3 100644 --- a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py @@ -33,6 +33,15 @@ class LineDotDialog(EditValueColorDialog): self.dot_color_label.setFixedWidth(30) self.dot_color_label.setAutoFillBackground(True) + # check box to include zero in value_color_str or not + self.zero_include_chkbox = QtWidgets.QCheckBox('Included') + # Widget that allow user to add/edit zero's color + self.select_zero_color_btn = QtWidgets.QPushButton("Select Color") + # Widget to display dot's color + self.zero_color_label = QtWidgets.QLabel() + self.zero_color_label.setFixedWidth(30) + self.zero_color_label.setAutoFillBackground(True) + super(LineDotDialog, self).__init__(parent, value_color_str) self.setWindowTitle("Edit Line/Dot Plotting's Colors") @@ -48,7 +57,12 @@ class LineDotDialog(EditValueColorDialog): self.main_layout.addWidget(self.dot_color_label, 1, 2, 1, 1) self.main_layout.addWidget(self.select_dot_color_btn, 1, 3, 1, 1) - self.setup_complete_buttons(2) + self.main_layout.addWidget(self.zero_include_chkbox, 2, 0, 1, 1) + self.main_layout.addWidget(QtWidgets.QLabel('Zero Color'), 2, 1, 1, 1) + self.main_layout.addWidget(self.zero_color_label, 2, 2, 1, 1) + self.main_layout.addWidget(self.select_zero_color_btn, 2, 3, 1, 1) + + self.setup_complete_buttons(3) def connect_signals(self) -> None: self.select_line_color_btn.clicked.connect( @@ -56,6 +70,9 @@ class LineDotDialog(EditValueColorDialog): self.select_dot_color_btn.clicked.connect( lambda: self.on_select_color(self.dot_color_label)) self.dot_include_chkbox.clicked.connect(self.on_click_include_dot) + self.select_zero_color_btn.clicked.connect( + lambda: self.on_select_color(self.zero_color_label)) + self.zero_include_chkbox.clicked.connect(self.on_click_include_zero) super().connect_signals() def on_click_include_dot(self): @@ -67,12 +84,22 @@ class LineDotDialog(EditValueColorDialog): self.select_dot_color_btn.setEnabled(enabled) self.dot_color_label.setHidden(not enabled) + def on_click_include_zero(self): + """ + Enable/disable select color and show/hide color label according to + dot_include_chkbox is checked or unchecked. + """ + enabled = self.zero_include_chkbox.isChecked() + self.select_zero_color_btn.setEnabled(enabled) + self.zero_color_label.setHidden(not enabled) + def set_value(self): """ Change the corresponding color_labels's color according to the color from value_color_str. """ self.dot_include_chkbox.setChecked(False) + self.zero_include_chkbox.setChecked(False) if self.value_color_str == "": return vc_parts = self.value_color_str.split('|') @@ -83,6 +110,11 @@ class LineDotDialog(EditValueColorDialog): if obj_type == 'Dot': display_color(self.dot_color_label, color) self.dot_include_chkbox.setChecked(True) + if obj_type == 'Zero': + display_color(self.zero_color_label, color) + self.zero_include_chkbox.setChecked(True) + self.on_click_include_dot() + self.on_click_include_zero() def save_color(self): """ @@ -94,6 +126,10 @@ class LineDotDialog(EditValueColorDialog): if self.dot_include_chkbox.isChecked(): dot_color = self.dot_color_label.palette().window().color().name() self.value_color_str += f"|Dot:{dot_color.upper()}" + if self.zero_include_chkbox.isChecked(): + zero_color = \ + self.zero_color_label.palette().window().color().name() + self.value_color_str += f"|Zero:{zero_color.upper()}" self.accept() diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py index 0993787010acdaa337d4a6c20837c694435151ef..c8117e1c9fb6fd13fff53dbef23ab18b82720f16 100644 --- a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py @@ -384,8 +384,8 @@ class MultiColorDotDialog(EditValueColorDialog): if color == 'not plot': self.set_color_enabled(vc_idx, False) else: - self.set_color_enabled(vc_idx, True) display_color(self.color_labels[vc_idx], color) + self.set_color_enabled(vc_idx, True) def save_color(self): """ diff --git a/sohstationviewer/view/db_config/value_color_helper/value_color_edit.py b/sohstationviewer/view/db_config/value_color_helper/value_color_edit.py index becf3e1dc0a39348bf47aebb994823a5d0d299fc..791c1844c8f4eec2462fcf2b5bfcb7033c43a6fc 100644 --- a/sohstationviewer/view/db_config/value_color_helper/value_color_edit.py +++ b/sohstationviewer/view/db_config/value_color_helper/value_color_edit.py @@ -142,9 +142,10 @@ class ValueColorEdit(QTextEdit): if background == 'B': palette.setColor(QtGui.QPalette.ColorRole.Text, Qt.white) palette.setColor(QtGui.QPalette.ColorRole.Base, Qt.black) - palette.setColor(QtGui.QPalette.ColorRole.PlaceholderText, - Qt.lightGray) - self.setPalette(palette) + else: + palette.setColor(QtGui.QPalette.ColorRole.Text, Qt.black) + palette.setColor(QtGui.QPalette.ColorRole.Base, Qt.white) + self.setPalette(palette) def set_value_color(self, value_color_str: str) -> None: """ diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting.py b/sohstationviewer/view/plotting/plotting_widget/plotting.py index b44fdb5eaed98b90a0506c02f89be740cb509e8d..c7496037a3d20fb039bfd24ff8c0f4af439ccdb5 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting.py @@ -324,30 +324,41 @@ class Plotting: for cStr in color_parts: obj, c = cStr.split(':') colors[obj] = c - l_color = '#00FF00' - has_dot = False + l_color = '#00FF00' # default Line color if 'Line' in colors: l_color = colors['Line'] + + has_dot = False # Optional dot if 'Dot' in colors: d_color = colors['Dot'] has_dot = True else: d_color = l_color - if chan_id == 'GPS Lk/Unlk': + has_zero = False # Optional zero + if 'Zero' in colors: z_color = colors['Zero'] + has_zero = True + + if chan_id == 'GPS Lk/Unlk': + info = "GPS Clock Power" + + if has_zero: sample_no_list = [] - ax.x_bottom = x_list[0][np.where(y_list[0] == -1)[0]] + + # compute x_bottom, x_center, x_top for labels of total numbers on + # the left of the channel + ax.x_bottom = x_list[0][np.where(y_list[0] < 0)[0]] sample_no_list.append(ax.x_bottom.size) ax.x_center = x_list[0][np.where(y_list[0] == 0)[0]] sample_no_list.append(ax.x_center.size) - ax.x_top = x_list[0][np.where(y_list[0] == 1)[0]] + ax.x_top = x_list[0][np.where(y_list[0] > 0)[0]] sample_no_list.append(ax.x_top.size) 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] # for plotting top & bottom + top_bottom_index = np.where(y_list[0] != 0)[0] x_list = [x_list[0][top_bottom_index]] y_list = [y_list[0][top_bottom_index]] @@ -362,7 +373,6 @@ class Plotting: 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, d_color, None] diff --git a/sohstationviewer/view/util/plot_type_info.py b/sohstationviewer/view/util/plot_type_info.py index 451ed3bf946b77568d52afc87d123168dc2288e4..ac04f2593b52acf1b43b449a38992d2e29e78528 100644 --- a/sohstationviewer/view/util/plot_type_info.py +++ b/sohstationviewer/view/util/plot_type_info.py @@ -12,11 +12,11 @@ plot_types = { " Dots are plotted with color #FF0000\n" "If Dot is not defined, dots won't be displayed.\n" "If L is not defined, lines will be plotted with color " - "#00FF00.\n" - "Optionally, a color for points with value 0 can be defined " - "This is currently only used for channel GPS Lk/Unlk.\n" - "Ex: Zero:#0000FF means points with value are plotted with " - "color #0000FF." + "#00FF00.\n\n" + "If Zero is defined, this plot type will plot a line through " + "bottom points (<0) and top points (>0). Zero points will be " + "plotted in the middle." + "Ex: Line:#00FF00|Dot:#FF0000|Zero:#0000FF" ), "plot_function": "plot_lines_dots", "value_pattern": re.compile('^(L|D|Z|Line|Dot|Zero)$'), diff --git a/tests/view/db_config/test_param_helper.py b/tests/view/db_config/test_param_helper.py index 10368a459e01faf2cc0ae2ed17bcbe149e8c3603..00f6e63feb62ffa8996c097185da027a2f7b2be5 100644 --- a/tests/view/db_config/test_param_helper.py +++ b/tests/view/db_config/test_param_helper.py @@ -37,11 +37,11 @@ class TestValidateValueColorStr(BaseTestCase): " Dots are plotted with color #FF0000\n" "If Dot is not defined, dots won't be displayed.\n" "If L is not defined, lines will be plotted with color " - "#00FF00.\n" - "Optionally, a color for points with value 0 can be defined " - "This is currently only used for channel GPS Lk/Unlk.\n" - "Ex: Zero:#0000FF means points with value are plotted with " - "color #0000FF.") + "#00FF00.\n\n" + "If Zero is defined, this plot type will plot a line through " + "bottom points (<0) and top points (>0). Zero points will be " + "plotted in the middle." + "Ex: Line:#00FF00|Dot:#FF0000|Zero:#0000FF") ) def test_up_down_dots(self):