Skip to content

Commit 3024aef

Browse files
committed
Fix more bugs in dummy viewer catalog styling
1 parent 8ceab65 commit 3024aef

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/astro_image_display_api/dummy_viewer.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ class ImageViewer:
5151
def __post_init__(self):
5252
# This is a dictionary of marker sets. The keys are the names of the
5353
# marker sets, and the values are the tables containing the markers.
54-
self._default_marker_style = dict(shape="circle", color="yellow", size=10)
5554
self._catalogs = defaultdict(CatalogInfo)
5655
self._catalogs[None].data = None
57-
self._catalogs[None].style = self._default_marker_style.copy()
56+
self._catalogs[None].style = self._default_catalog_style.copy()
5857

5958
def _user_catalog_labels(self) -> list[str]:
6059
"""
@@ -86,6 +85,17 @@ def _resolve_catalog_label(self, catalog_label: str | None) -> str:
8685

8786
return catalog_label
8887

88+
@property
89+
def _default_catalog_style(self) -> dict[str, Any]:
90+
"""
91+
The default style for the catalog markers.
92+
"""
93+
return {
94+
"shape": "circle",
95+
"color": "red",
96+
"size": 5,
97+
}
98+
8999
def get_stretch(self) -> BaseStretch:
90100
return self._stretch
91101

@@ -117,7 +127,7 @@ def cursor(self, value: str) -> None:
117127

118128
# The methods, grouped loosely by purpose
119129

120-
def get_catalog_style(self, catalog_label=None) -> dict[str, dict[str, Any]]:
130+
def get_catalog_style(self, catalog_label=None) -> dict[str, Any]:
121131
"""
122132
Get the style for the catalog.
123133
@@ -140,9 +150,9 @@ def get_catalog_style(self, catalog_label=None) -> dict[str, dict[str, Any]]:
140150
def set_catalog_style(
141151
self,
142152
catalog_label: str | None = None,
143-
shape: str = "",
144-
color: str = "",
145-
size: float = 0,
153+
shape: str = "circle",
154+
color: str = "red",
155+
size: float = 5,
146156
**kwargs
147157
) -> None:
148158
"""
@@ -161,9 +171,9 @@ def set_catalog_style(
161171
**kwargs
162172
Additional keyword arguments to pass to the marker style.
163173
"""
164-
shape = shape if shape else self._default_marker_style["shape"]
165-
color = color if color else self._default_marker_style["color"]
166-
size = size if size else self._default_marker_style["size"]
174+
shape = shape
175+
color = color
176+
size = size
167177

168178
catalog_label = self._resolve_catalog_label(catalog_label)
169179

@@ -174,7 +184,6 @@ def set_catalog_style(
174184
"shape": shape,
175185
"color": color,
176186
"size": size,
177-
**kwargs,
178187
}
179188

180189
# Methods for loading data
@@ -308,17 +317,22 @@ def load_catalog(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
308317

309318
catalog_label = self._resolve_catalog_label(catalog_label)
310319

320+
# Either set new data or append to existing data
311321
if (
312322
catalog_label in self._catalogs
313323
and self._catalogs[catalog_label].data is not None
314324
):
325+
# If the catalog already exists, we append to it
315326
old_table = self._catalogs[catalog_label].data
316327
self._catalogs[catalog_label].data = vstack([old_table, to_add])
317328
else:
329+
# If the catalog does not exist, we create a new one
318330
self._catalogs[catalog_label].data = to_add
319331

332+
# Ensure a catalog always has a style
320333
if catalog_style is None:
321-
catalog_style = self._default_marker_style.copy()
334+
if not self._catalogs[catalog_label].style:
335+
catalog_style = self._default_catalog_style.copy()
322336

323337
self._catalogs[catalog_label].style = catalog_style
324338

0 commit comments

Comments
 (0)