Skip to content

Commit

Permalink
Merge pull request #222 from cds-astro/fix-circle-opacity-not-working
Browse files Browse the repository at this point in the history
Fix circle opacity not working
  • Loading branch information
tboch authored Jan 16, 2025
2 parents cc8becb + bbd5848 commit 921d395
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Editable examples showing the API can also be found [here](https://aladin.cds.un

## Embed it into your projects

**Terms of use**: you are welcome to integrate Aladin Lite in your web pages and to customize its GUI to your needs, but **please leave the Aladin logo and link intact** at the bottom right of the view.

You can embed Aladin Lite it into your webpages in two ways

### The vanilla way
Expand Down
16 changes: 9 additions & 7 deletions src/js/shapes/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export let Circle = (function() {
* @param {number[]} centerRaDec - right-ascension/declination 2-tuple of the circle's center in degrees
* @param {number} radius - radius in degrees
* @param {ShapeOptions} options - Configuration options for the circle
*
*
* @returns {Circle} - The circle shape object
*/
let Circle = function(centerRaDec, radius, options) {
Expand All @@ -51,16 +51,17 @@ export let Circle = (function() {
this.lineWidth = options["lineWidth"] || 2;
this.selectionColor = options["selectionColor"] || '#00ff00';
this.hoverColor = options["hoverColor"] || undefined;
this.opacity = options['opacity'] || 1;

// TODO : all graphic overlays should have an id
this.id = 'circle-' + Utils.uuidv4();

this.setCenter(centerRaDec);
this.setRadius(radius);
this.overlay = null;
this.overlay = null;

this.isShowing = true;
this.isSelected = false;
this.isShowing = true;
this.isSelected = false;
this.isHovered = false;
this.frame = options.frame || "icrs";
};
Expand Down Expand Up @@ -223,7 +224,7 @@ export let Circle = (function() {

var ra, dec, vertOnCircle, dx, dy;
this.radius = Number.NEGATIVE_INFINITY;

// Project 4 points lying on the circle and take the minimal dist with the center as radius
[[-1, 0], [1, 0], [0, -1], [0, 1]].forEach(([cardDirRa, cardDirDec]) => {
ra = this.centerRaDec[0] + cardDirRa * this.radiusDegrees;
Expand All @@ -238,7 +239,7 @@ export let Circle = (function() {
this.radius = Math.max(Math.sqrt(dx*dx + dy*dy), this.radius);

hidden = false;
}
}
});

if (hidden) {
Expand Down Expand Up @@ -267,6 +268,7 @@ export let Circle = (function() {
}

ctx.lineWidth = this.lineWidth;
ctx.globalAlpha = this.opacity;
ctx.beginPath();
ctx.arc(this.center.x, this.center.y, this.radius, 0, 2*Math.PI, false);
if (!noStroke) {
Expand Down Expand Up @@ -295,7 +297,7 @@ export let Circle = (function() {
if (circleDistance.x > (w/2 + this.radius)) { return false; }
if (circleDistance.y > (h/2 + this.radius)) { return false; }

if (circleDistance.x <= (w/2)) { return true; }
if (circleDistance.x <= (w/2)) { return true; }
if (circleDistance.y <= (h/2)) { return true; }

const dx = circleDistance.x - w/2;
Expand Down

0 comments on commit 921d395

Please sign in to comment.