Skip to content

Commit

Permalink
XYDomainModel: Consistently set map_x/map_y at the top if both available
Browse files Browse the repository at this point in the history
  • Loading branch information
stuart-cls committed Nov 29, 2024
1 parent 76a4403 commit 4744a06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
25 changes: 24 additions & 1 deletion orangecontrib/spectroscopy/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np

from Orange.data import Domain, Table
from Orange.data import Domain, Table, ContinuousVariable
from Orange.widgets.utils.itemmodels import DomainModel
from orangewidget.utils.itemmodels import PyListModel

MAP_X_VAR = "map_x"
MAP_Y_VAR = "map_y"
Expand Down Expand Up @@ -148,3 +150,24 @@ def split_to_size(size, interval):
intervals.append(slice(pos, pos + min(size - pos, interval)))
pos += min(size, interval)
return intervals


class XYDomainModel(DomainModel):
XY = (DomainModel.METAS, PyListModel.Separator,
DomainModel.CLASSES)

def __init__(self, order=XY, valid_types=ContinuousVariable, **kwargs):
super().__init__(order=order, valid_types=valid_types, **kwargs)

def set_domain(self, domain):
restore_order = False
if domain is not None and self.order == self.XY:
attr_x = [domain[var] for var in domain if var.name == MAP_X_VAR]
attr_y = [domain[var] for var in domain if var.name == MAP_Y_VAR]
xy = attr_x + attr_y
if len(xy) == 2:
self.order = (xy, PyListModel.Separator) + self.order
restore_order = True
super().set_domain(domain)
if restore_order:
self.order = self.order[2:]
5 changes: 2 additions & 3 deletions orangecontrib/spectroscopy/widgets/owhyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from orangewidget.utils.visual_settings_dlg import VisualSettingsDialog

from orangecontrib.spectroscopy.preprocess import Integrate
from orangecontrib.spectroscopy.utils import values_to_linspace, index_values_nan, split_to_size
from orangecontrib.spectroscopy.utils import values_to_linspace, index_values_nan, split_to_size, XYDomainModel

from orangecontrib.spectroscopy.widgets.owspectra import InteractiveViewBox, \
MenuFocus, CurvePlot, SELECTONE, SELECTMANY, INDIVIDUAL, AVERAGE, \
Expand Down Expand Up @@ -287,8 +287,7 @@ def color_palette_model(palettes, iconsize=QSize(64, 16)):
class AxesSettingsMixin:

def __init__(self):
self.xy_model = DomainModel(DomainModel.METAS | DomainModel.CLASSES,
valid_types=DomainModel.PRIMITIVE)
self.xy_model = XYDomainModel()

def setup_axes_settings_box(self):
box = gui.vBox(self)
Expand Down

0 comments on commit 4744a06

Please sign in to comment.