Skip to content

Commit ded1b21

Browse files
committed
Add set/get methods for catalog style
1 parent 9ab9810 commit ded1b21

File tree

2 files changed

+91
-12
lines changed

2 files changed

+91
-12
lines changed

src/astro_image_display_api/interface_definition.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,57 @@ def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
124124
"""
125125
raise NotImplementedError
126126

127-
# @abstractmethod
128-
# def remove_all_markers(self):
129-
# raise NotImplementedError
127+
@abstractmethod
128+
def set_catalog_style(
129+
self,
130+
catalog_label: str | None = None,
131+
shape: str = 'circle',
132+
color: str = 'red',
133+
size: float = 5.0,
134+
**kwargs
135+
):
136+
"""
137+
Set the style of the catalog markers.
138+
139+
Parameters
140+
----------
141+
shape : str, optional
142+
The shape of the markers. Default is ``'circle'``. The set of
143+
supported shapes is listed below in the `Notes` section.
144+
color : str, optional
145+
The color of the markers. Default is ``'red'``. Permitted colors are
146+
any CSS4 color name. CSS4 also permits hex RGB or RGBA colors.
147+
size : float, optional
148+
The size of the markers. Default is ``5.0``.
149+
150+
**kwargs
151+
Additional keyword arguments to pass to the marker style.
152+
153+
Notes
154+
-----
155+
The following shapes are supported: "circle", "square", "crosshair", "plus",
156+
"diamond".
157+
"""
158+
raise NotImplementedError
159+
160+
@abstractmethod
161+
def get_catalog_style(self, catalog_label: str | None = None) -> dict:
162+
"""
163+
Get the style of the catalog markers.
164+
165+
Returns
166+
-------
167+
dict
168+
The style of the markers.
169+
170+
Raises
171+
------
172+
173+
ValueError
174+
If there are multiple catalog styles set and the user has not
175+
specified a `catalog_label` for which to get the style.
176+
"""
177+
raise NotImplementedError
130178

131179
@abstractmethod
132180
def reset_markers(self) -> None:

src/astro_image_display_api/widget_api_test.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,46 @@ def test_zoom(self):
119119
self.image.zoom(2)
120120
assert self.image.zoom_level == 6 # 3 x 2
121121

122-
def test_marker_properties(self):
123-
# Set the marker style
124-
marker_style = {'color': 'yellow', 'radius': 10, 'type': 'cross'}
125-
self.image.marker = marker_style
126-
m_str = str(self.image.marker)
127-
for key in marker_style.keys():
128-
assert key in m_str
129-
130-
# TODO: add test that checks that retrieving markers with an unknown name issues no error
122+
def test_set_get_catalog_style_no_labels(self):
123+
# Check that getting without setting returns a dict that contains
124+
# the minimum required keys
125+
required_style_keys = ['color', 'shape', 'size']
126+
marker_style = self.image.get_catalog_style()
127+
for key in required_style_keys:
128+
assert key in marker_style
129+
130+
# Check that setting a marker style works
131+
marker_settings = dict(color='red', marker='x', size=10)
132+
self.image.set_catalog_style(**marker_settings)
133+
134+
retrieved_style = self.image.get_catalog_style()
135+
# Check that the marker style is set correctly
136+
for key, value in marker_settings.items():
137+
assert retrieved_style[key] == value
138+
139+
# Check that set accepts the output of get
140+
self.image.set_catalog_style(**retrieved_style)
141+
142+
def test_set_get_catalog_style_with_single_label(self):
143+
# Check that when there is only a single catalog label it is
144+
# not necessary to provide the label on get.
145+
set_style_input = dict(catalog_label='test1', color='blue',
146+
shape='square', size=5)
147+
self.image.set_catalog_style(**set_style_input)
148+
retrieved_style = self.image.get_catalog_style()
149+
150+
assert set_style_input == retrieved_style
151+
152+
def test_get_catalog_style_with_multiple_labels_raises_error(self):
153+
# Check that when there are multiple catalog labels, the
154+
# get_catalog_style method raises an error if no label is given.
155+
self.image.set_catalog_style(catalog_label='test1', color='blue',
156+
shape='square', size=5)
157+
self.image.set_catalog_style(catalog_label='test2', color='red',
158+
shape='circle', size=10)
159+
160+
with pytest.raises(ValueError, match='Multiple catalog styles'):
161+
self.image.get_catalog_style()
131162

132163
def test_add_markers(self):
133164
data = np.arange(10).reshape(5, 2)

0 commit comments

Comments
 (0)