Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add height to 100% #125

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- it is now possible to extend the widget's height to 100% of its container. To do so,
do `Aladin(height=-1)`. This is implemented to support use in dashboard
applications, this cannot work in a notebook.

### Fixed

- remove `requests` from mandatory dependencies (accident in version 0.5.0)
Expand Down
5 changes: 2 additions & 3 deletions js/models/event_handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MessageHandler from "./message_handler";
import { divNumber, setDivNumber, Lock } from "../utils";
import { divNumber, setDivNumber, Lock, setDivHeight } from "../utils";

export default class EventHandler {
/**
Expand Down Expand Up @@ -131,8 +131,7 @@ export default class EventHandler {

/* Div control */
this.model.on("change:_height", () => {
let height = this.model.get("_height");
this.aladinDiv.style.height = `${height}px`;
setDivHeight(this.model.get("_height"), this.aladinDiv);
// Update WCS and FoV only if this is the last div
this.updateWCS();
this.update2AxisFoV();
Expand Down
9 changes: 9 additions & 0 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ function setDivNumber(num) {
divNumber = num;
}

function setDivHeight(height, div) {
if (height == -1) {
div.style.height = "100%";
} else {
div.style.height = `${height}px`;
}
}

export {
snakeCaseToCamelCase,
convertOptionNamesToCamelCase,
Lock,
divNumber,
setDivNumber,
setDivHeight,
};
10 changes: 7 additions & 3 deletions js/widget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import "./widget.css";
import EventHandler from "./models/event_handler";
import { divNumber, setDivNumber, snakeCaseToCamelCase } from "./utils";
import {
divNumber,
setDivHeight,
setDivNumber,
snakeCaseToCamelCase,
} from "./utils";
import A from "./aladin_lite";

function initAladinLite(model, el) {
Expand All @@ -13,8 +18,7 @@ function initAladinLite(model, el) {

let aladinDiv = document.createElement("div");
aladinDiv.classList.add("aladin-widget");
aladinDiv.style.height = `${model.get("_height")}px`;

setDivHeight(model.get("_height"), aladinDiv);
aladinDiv.id = `aladin-lite-div-${divNumber}`;
let aladin = new A.aladin(aladinDiv, initOptions);
el.appendChild(aladinDiv);
Expand Down
7 changes: 5 additions & 2 deletions src/ipyaladin/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,16 @@ def selected_objects(self) -> List[Table]:

@property
def height(self) -> int:
"""The height of the Aladin Lite widget.
"""The height of the widget.

Returns
-------
int
The height of the widget in pixels.

Setting the height to -1 will expand the widget at 100% height of its
container. This is generally a bad idea in a notebook but can be usefull
for dashbord applications.
The default height is 400 pixels.
"""
return self._height

Expand Down
Loading