Skip to content

Commit

Permalink
✨ Add support for Regions object for add_overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed May 16, 2024
1 parent b85d55a commit 3d66a68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 11 additions & 2 deletions js/models/message_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export default class MessageHandler {
msg["graphic_options"] || {},
);
if (!graphic_options["color"]) graphic_options["color"] = "red";
console.log(graphic_options);
const overlay = A.graphicOverlay(graphic_options);
this.aladin.addOverlay(overlay);
console.log(regions);
for (const region of regions) {
const infos = region["infos"];
switch (region["region_type"]) {
Expand All @@ -52,8 +54,14 @@ export default class MessageHandler {
break;
case "ellipse":
overlay.add(
A.ellipse(infos.ra, infos.dec, infos.a, infos.b, infos.theta),
region.options,
A.ellipse(
infos.ra,
infos.dec,
infos.a,
infos.b,
infos.theta,
region.options,
),
);
break;
case "line":
Expand All @@ -63,6 +71,7 @@ export default class MessageHandler {
infos.dec1,
infos.ra2,
infos.dec2,
"ICRS",
region.options,
),
);
Expand Down
13 changes: 10 additions & 3 deletions src/ipyaladin/aladin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
PolygonSkyRegion,
RectangleSkyRegion,
Region,
Regions,
)
except ImportError:
CircleSkyRegion = None
Expand All @@ -32,6 +33,7 @@
PolygonSkyRegion = None
RectangleSkyRegion = None
Region = None
Regions = None
from traitlets import (
Float,
Int,
Expand Down Expand Up @@ -372,6 +374,7 @@ def add_overlay(
LineSkyRegion,
PolygonSkyRegion,
RectangleSkyRegion,
Regions,
],
**graphic_options: any,
) -> None:
Expand All @@ -387,11 +390,15 @@ def add_overlay(
The options for the graphic overlay. Use Region visual for region options.
"""
if not isinstance(region, list):
region = [region]
if isinstance(region, Regions):
region_list = region.regions
elif not isinstance(region, list):
region_list = [region]
else:
region_list = region

regions_infos = []
for region_element in region:
for region_element in region_list:
# Check if the regions library is installed and raise an error if not
if (
not isinstance(region_element, str) and Region is None
Expand Down

0 comments on commit 3d66a68

Please sign in to comment.