From 8c46e19346339eee2ac767e3e452f5bae304ec26 Mon Sep 17 00:00:00 2001 From: Christoph Matthias Kohnen Date: Thu, 16 Nov 2023 14:32:13 +0100 Subject: [PATCH 1/4] small improvements Signed-off-by: Christoph Matthias Kohnen --- data/ui/figure_settings.blp | 5 ----- src/actions.py | 2 +- src/data.py | 21 ++++++--------------- src/figure_settings.py | 12 +++++------- src/operations.py | 3 +-- src/style_io.py | 2 +- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/data/ui/figure_settings.blp b/data/ui/figure_settings.blp index f1fe9b06c..fd0691eac 100644 --- a/data/ui/figure_settings.blp +++ b/data/ui/figure_settings.blp @@ -59,14 +59,9 @@ template $GraphsFigureSettingsWindow : Adw.Window { Adw.PreferencesGroup { title: _("Axis Limits"); - Adw.ActionRow no_data_message { - title: _("No Data"); - subtitle: _("Add data to the figure to set axis limits"); - } Box { orientation: vertical; spacing: 12; - visible: bind no_data_message.visible inverted; Box left_limits { orientation: horizontal; spacing: 6; diff --git a/src/actions.py b/src/actions.py index 20acc9772..29834e71c 100644 --- a/src/actions.py +++ b/src/actions.py @@ -156,6 +156,6 @@ def on_response(_dialog, response): def delete_selected_action(_action, _target, self): items = [item for item in self.get_data() if item.get_selected()] - names = ", ".join([item.get_name() for item in items]) + names = ", ".join(item.get_name() for item in items) self.get_data().delete_items(items) self.get_window().add_toast_string(_("Deleted {}").format(names)) diff --git a/src/data.py b/src/data.py index deb13ae73..18ee121cd 100644 --- a/src/data.py +++ b/src/data.py @@ -182,23 +182,12 @@ def add_items(self, items: misc.ItemList) -> None: style_manager = self.get_application().get_figure_style_manager() selected_style = style_manager.get_selected_style_params() color_cycle = selected_style["axes.prop_cycle"].by_key()["color"] - used_colors = [] - - def _append_used_color(color): - used_colors.append(color) - # If we've got all colors once, remove those from used_colors so we - # can loop around - if set(used_colors) == set(color_cycle): - for color in color_cycle: - used_colors.remove(color) - - for item_ in self: - _append_used_color(item_.get_color()) def _is_default(prop): return figure_settings.get_property(prop) == \ settings.get_child("figure").get_string(prop) + used_colors = set(item_.get_color() for item_ in self) for new_item in items: names = self.get_names() if new_item.get_name() in names: @@ -213,7 +202,7 @@ def _is_default(prop): index = names.index(new_item.get_name()) existing_item = self[index] self._current_batch.append( - (2, (index, existing_item.to_dict(item_))), + (2, (index, item.to_dict(existing_item))), ) new_item.set_uuid(existing_item.get_uuid()) @@ -244,10 +233,12 @@ def _is_default(prop): elif ylabel != figure_settings.get_right_label(): new_item.set_yposition(original_position) if new_item.get_color() == "": + if used_colors == set(color_cycle): + used_colors = set() for color in color_cycle: if color not in used_colors: new_item.set_color(color) - _append_used_color(color) + used_colors.add(color) break self._add_item(new_item) @@ -489,7 +480,7 @@ def load_from_project_dict(self, project_dict: dict[str, Any]) -> None: for key, value in project_dict["figure-settings"].items(): if figure_settings.get_property(key) != value: figure_settings.set_property(key, value) - self.set_items([item.new_from_dict(d) for d in project_dict["data"]]) + self.set_items(item.new_from_dict(d) for d in project_dict["data"]) self._set_data_copy() self._history_states = project_dict["history-states"] diff --git a/src/figure_settings.py b/src/figure_settings.py index ad2038f13..7171505b0 100644 --- a/src/figure_settings.py +++ b/src/figure_settings.py @@ -53,7 +53,6 @@ class FigureSettingsWindow(Adw.Window): min_top = Gtk.Template.Child() max_top = Gtk.Template.Child() - no_data_message = Gtk.Template.Child() style_overview = Gtk.Template.Child() navigation_view = Gtk.Template.Child() grid_view = Gtk.Template.Child() @@ -83,9 +82,6 @@ def __init__(self, application, highlighted=None): ui.bind_values_to_object(figure_settings, self, ignorelist=ignorelist) self.set_axes_entries() - self.no_data_message.set_visible( - self.get_application().get_data().is_empty(), - ) if highlighted is not None: getattr(self, highlighted).grab_focus() @@ -132,11 +128,13 @@ def on_select(self, model, _pos, _n_items): figure_settings.set_use_custom_style(True) def set_axes_entries(self): - used_axes = [[direction, False] for direction in _DIRECTIONS] + used_axes = [False, False, False, False] for item in self.get_application().get_data(): for i in item.get_xposition() * 2, 1 + item.get_yposition() * 2: - used_axes[i][1] = True - for (direction, visible) in used_axes: + used_axes[i] = True + if not any(used_axes): + used_axes = [True, True, False, False] + for (direction, visible) in zip(_DIRECTIONS, used_axes): if visible: for s in ("min_", "max_"): entry = getattr(self, s + direction) diff --git a/src/operations.py b/src/operations.py index 649123a3f..aba2e9c47 100644 --- a/src/operations.py +++ b/src/operations.py @@ -141,8 +141,7 @@ def multiply_y(_item, xdata, ydata, multiplier): def normalize(_item, xdata, ydata): """Normalize all selected data""" - new_ydata = [value / max(ydata) for value in ydata] - return xdata, new_ydata, False, False + return xdata, [value / max(ydata) for value in ydata], False, False def smoothen(_item, xdata, ydata): diff --git a/src/style_io.py b/src/style_io.py index db68a58b1..f78d38916 100644 --- a/src/style_io.py +++ b/src/style_io.py @@ -126,7 +126,7 @@ def generate_preview(style: RcParams) -> Gio.File: axis.spines.bottom.set_visible(True) axis.spines.left.set_visible(True) if not style["axes.spines.top"]: - axis.tick_params(which="both", **{"top": False, "right": False}) + axis.tick_params(which="both", top=False, right=False) axis.plot(_PREVIEW_XDATA, _PREVIEW_YDATA1) axis.plot(_PREVIEW_XDATA, _PREVIEW_YDATA2) axis.set_xlabel(_("X Label")) From afb5f88e8697449c450871288182b86e7bfa776f Mon Sep 17 00:00:00 2001 From: Christoph Matthias Kohnen Date: Thu, 16 Nov 2023 15:18:00 +0100 Subject: [PATCH 2/4] fix issues Signed-off-by: Christoph Matthias Kohnen --- src/data.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/data.py b/src/data.py index 18ee121cd..839f864ae 100644 --- a/src/data.py +++ b/src/data.py @@ -187,7 +187,12 @@ def _is_default(prop): return figure_settings.get_property(prop) == \ settings.get_child("figure").get_string(prop) - used_colors = set(item_.get_color() for item_ in self) + used_colors = [ + item_.get_color() for item_ in self + if item_.get_color() in color_cycle + ] + used_colors = set(used_colors[len(color_cycle):]) \ + if len(used_colors) > len(color_cycle) else set(used_colors) for new_item in items: names = self.get_names() if new_item.get_name() in names: @@ -233,7 +238,7 @@ def _is_default(prop): elif ylabel != figure_settings.get_right_label(): new_item.set_yposition(original_position) if new_item.get_color() == "": - if used_colors == set(color_cycle): + if len(used_colors) == len(color_cycle): used_colors = set() for color in color_cycle: if color not in used_colors: From 126bf5ace75c5b9d1aa742e796518357e767562f Mon Sep 17 00:00:00 2001 From: Christoph Matthias Kohnen Date: Thu, 16 Nov 2023 15:39:25 +0100 Subject: [PATCH 3/4] fix more issues Signed-off-by: Christoph Matthias Kohnen --- src/data.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/data.py b/src/data.py index 839f864ae..c7fbffcbb 100644 --- a/src/data.py +++ b/src/data.py @@ -191,8 +191,9 @@ def _is_default(prop): item_.get_color() for item_ in self if item_.get_color() in color_cycle ] - used_colors = set(used_colors[len(color_cycle):]) \ - if len(used_colors) > len(color_cycle) else set(used_colors) + while len(set(used_colors)) == len(color_cycle): + for color in color_cycle: + used_colors.remove(color) for new_item in items: names = self.get_names() if new_item.get_name() in names: @@ -238,12 +239,13 @@ def _is_default(prop): elif ylabel != figure_settings.get_right_label(): new_item.set_yposition(original_position) if new_item.get_color() == "": - if len(used_colors) == len(color_cycle): - used_colors = set() + if len(set(used_colors)) == len(color_cycle): + for color in color_cycle: + used_colors.remove(color) for color in color_cycle: if color not in used_colors: new_item.set_color(color) - used_colors.add(color) + used_colors.append(color) break self._add_item(new_item) From 7544bf5540c4b4ea737c412c107a0a19692ed682 Mon Sep 17 00:00:00 2001 From: Christoph Matthias Kohnen Date: Thu, 16 Nov 2023 15:46:34 +0100 Subject: [PATCH 4/4] revert deduplication logic and port improvements Signed-off-by: Christoph Matthias Kohnen --- src/data.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/data.py b/src/data.py index c7fbffcbb..ff13b7d89 100644 --- a/src/data.py +++ b/src/data.py @@ -182,18 +182,21 @@ def add_items(self, items: misc.ItemList) -> None: style_manager = self.get_application().get_figure_style_manager() selected_style = style_manager.get_selected_style_params() color_cycle = selected_style["axes.prop_cycle"].by_key()["color"] + used_colors = [] + + def _append_used_color(color): + if len(set(used_colors)) == len(color_cycle): + for color in color_cycle: + used_colors.remove(color) def _is_default(prop): return figure_settings.get_property(prop) == \ settings.get_child("figure").get_string(prop) - used_colors = [ - item_.get_color() for item_ in self - if item_.get_color() in color_cycle - ] - while len(set(used_colors)) == len(color_cycle): - for color in color_cycle: - used_colors.remove(color) + for item_ in self: + color = item_.get_color() + if color in color_cycle: + _append_used_color(color) for new_item in items: names = self.get_names() if new_item.get_name() in names: @@ -239,13 +242,10 @@ def _is_default(prop): elif ylabel != figure_settings.get_right_label(): new_item.set_yposition(original_position) if new_item.get_color() == "": - if len(set(used_colors)) == len(color_cycle): - for color in color_cycle: - used_colors.remove(color) for color in color_cycle: if color not in used_colors: + _append_used_color(color) new_item.set_color(color) - used_colors.append(color) break self._add_item(new_item)