Skip to content

Commit 0db9d62

Browse files
cppartsbmatthieu3
authored andcommitted
initial changes
1 parent 56ce69b commit 0db9d62

4 files changed

Lines changed: 55 additions & 1 deletion

File tree

js/models/event_handler.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ export default class EventHandler {
4646
this.model.set("_wcs", this.aladin.getViewWCS());
4747
}
4848

49+
/**
50+
* Updates the view center rotation in the model.
51+
* WARNING: This method don't call model.save_changes()!
52+
*/
53+
updateRotation() {
54+
if (!this.isLastDiv()) return;
55+
this.model.set("_rotation", this.aladin.getRotation());
56+
}
57+
4958
/**
5059
* Updates the 2-axis FoV in the model.
5160
* WARNING: This method don't call model.save_changes()!
@@ -138,6 +147,15 @@ export default class EventHandler {
138147
this.model.save_changes();
139148
});
140149

150+
/* Rotation control */
151+
this.model.on("change:_rotation", () => {
152+
setRotation(this.model.get("_rotation"), this.aladinDiv);
153+
// Update WCS and FoV only if this is the last div
154+
this.updateWCS();
155+
this.update2AxisFoV();
156+
this.model.save_changes();
157+
});
158+
141159
/* Aladin callbacks */
142160

143161
this.aladin.on("cooFrameChanged", () => {
@@ -273,6 +291,7 @@ export default class EventHandler {
273291
this.eventHandlers = {
274292
add_marker: this.messageHandler.handleAddMarker,
275293
change_fov: this.messageHandler.handleChangeFoV,
294+
change_rotation: this.messageHandler.handleChangeRotation,
276295
goto_ra_dec: this.messageHandler.handleGotoRaDec,
277296
save_view_as_image: this.messageHandler.handleSaveViewAsImage,
278297
add_fits: this.messageHandler.handleAddFits,
@@ -302,6 +321,7 @@ export default class EventHandler {
302321
this.model.off("change:_target");
303322
this.model.off("change:_fov");
304323
this.model.off("change:_height");
324+
this.model.off("change:_rotation");
305325
this.model.off("change:coo_frame");
306326
this.model.off("change:survey");
307327
this.model.off("change:overlay_survey");

js/models/message_handler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default class MessageHandler {
3838
this.aladin.gotoRaDec(msg["ra"], msg["dec"]);
3939
}
4040

41+
handleChangeRotation(msg) {
42+
this.aladin.setRotation(msg["rotation"]);
43+
}
44+
4145
async handleSaveViewAsImage(msg) {
4246
const path = msg["path"];
4347
const format = msg["format"];

js/widget.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ function initAladinLite(model, el) {
3131
const raDec = model.get("_target").split(" ");
3232
aladin.gotoRaDec(raDec[0], raDec[1]);
3333

34-
// Set current FoV and WCS
34+
// Set current FoV, WCS, and rotation
3535
const twoAxisFoV = { ...aladin.getFov() };
3636
model.set("_fov_xy", {
3737
x: twoAxisFoV[0],
3838
y: twoAxisFoV[1],
3939
});
4040
const wcs = { ...aladin.getViewWCS() };
4141
model.set("_wcs", wcs);
42+
const rotation = { ...aladin.getRotation() };
43+
model.set("_rotation", rotation);
4244
model.set("_is_loaded", true);
4345
model.save_changes();
4446

src/ipyaladin/widget.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class Aladin(anywidget.AnyWidget):
143143
# Options for the view initialization
144144
_init_options = traitlets.Dict().tag(sync=True)
145145
_height = Int(400).tag(sync=True, init_option=True)
146+
_rotation = Float(0).tag(sync=True, init_option=True)
146147
_target = Unicode(
147148
"0 0",
148149
help="A private trait that stores the current target of the widget in a string."
@@ -222,6 +223,7 @@ def __init__(self, *args: any, **init_options: any) -> None:
222223
init_options.pop(key, None)
223224
# some init options are properties here
224225
self.height = init_options.get("height", self._height)
226+
self.rotation = init_options.get("rotation", self._rotation)
225227
self.target = init_options.get("target", self._target)
226228
self.fov = init_options.get("fov", self._fov)
227229
# apply different default options from Aladin-Lite
@@ -294,6 +296,32 @@ def height(self, height: int) -> None:
294296
self._fov_xy = {}
295297
self._height = height
296298

299+
@property
300+
def rotation(self) -> float:
301+
"""The center rotation of the widget.
302+
303+
This is the view center to north pole angle in degrees.
304+
This is equivalent to getting the 3rd Euler angle.
305+
Positive angles rotates the view in the counter clockwise
306+
order (or towards the east).
307+
308+
Returns
309+
-------
310+
float
311+
The center rotation of the widget in degrees.
312+
The default rotation is 0 degrees.
313+
"""
314+
return self._rotation
315+
316+
@rotation.setter
317+
def rotation(self, rotation: float) -> None:
318+
if np.isclose(self._rotation, rotation):
319+
return
320+
self._wcs = {}
321+
self._fov_xy = {}
322+
self._rotation = rotation
323+
self.send({"event_name": "change_rotation", "rotation": rotation})
324+
297325
@property
298326
def wcs(self) -> WCS:
299327
"""The world coordinate system corresponding to the current view of ipyaladin.

0 commit comments

Comments
 (0)