Skip to content

Commit

Permalink
🎨 Improve parsing support for region#Visual
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys authored and ManonMarchand committed May 27, 2024
1 parent 5136e35 commit 4ce7edb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/ipyaladin/aladin.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,14 @@ def add_graphic_overlay_from_region(
`~regions.LineSkyRegion`,`~regions.PolygonSkyRegion`,
`~regions.RectangleSkyRegion`, `~regions.Regions`
The region to add in Aladin Lite. It can be given
as a supported region or a list of regions from the regions package
as a supported region or a list of regions from the regions package.
Region Visual object is mapped to graphic options with the following
mapping:
- edgecolor -> color
- facecolor -> fillColor
- color -> color & fillColor
- alpha -> opacity
- linewidth -> lineWidth
graphic_options: keyword arguments
The options for the graphic overlay. Use Region visual for region options.
See graphicOverlay options here https://cds-astro.github.io/aladin-lite/A.html
Expand Down
11 changes: 9 additions & 2 deletions src/ipyaladin/region_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ def _from_rectangle_sky_region(self, region: RectangleSkyRegion) -> None:

def _parse_visuals(self, region: Region) -> None:
visual = dict(region.visual)
if "linewidth" in visual:
visual["line_width"] = visual.pop("linewidth")
# Color parsing
if "facecolor" in visual:
visual["fill_color"] = visual.pop("facecolor")
if "edgecolor" in visual:
visual["color"] = visual.pop("edgecolor")
if "color" in visual:
visual["fill_color"] = visual["color"]

# Other parsing
if "alpha" in visual:
visual["opacity"] = visual.pop("alpha")
if "linewidth" in visual:
visual["line_width"] = visual.pop("linewidth")
self.options = visual

def to_clean_dict(self) -> dict:
Expand Down

0 comments on commit 4ce7edb

Please sign in to comment.