Skip to content

feat: replace map _height with height #816

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ATL2001
Copy link
Contributor

@ATL2001 ATL2001 commented Jun 22, 2025

per what we discussed in #781 I believe I've come up with a good solution here. I had to add some CSS to the data-overlay-container which appears to be generated by the typescript which the lonboard div is housed in. and then I needed to make some tweaks to the map div which lives inside the lonboard one as well. then I changed _height to height and tweaked the way the default was setup so as to not make the default functionality of the creation of the map change.

but now if the user knows they want to put the map into an IFrame or some other container that has a fixed height, they can specify height="100%" and the map will fill the container's height.

I also checked in an example notebook so you can check the behavior yourself. I do not intend to keep that in there (unless you think it would be a benefit for others, if so I should probably retool it to make it a little nicer)

If this looks good let me know and I can find some time to update the docs so they match the behavior 👍

ATL2001 added 5 commits June 22, 2025 15:20
…string for the height of the lonboard div.

set the map div inside the lonboard div to be 100% height/width always
…not an integer so we can pass values like '300px' or '100%'

set the height/width of the layout of the widget to 100%

mark the body overflow to hidden so if it's inside a smaller container, it wont overrun it or make some scroll bars show up
shows the behavior of the height functionality
@ATL2001 ATL2001 changed the title replace map _height with height feat: replace map _height with height Jun 22, 2025
@github-actions github-actions bot added the feat label Jun 22, 2025
lonboard/_map.py Outdated
@@ -177,7 +179,7 @@ def on_click(self, callback: Callable, *, remove: bool = False) -> None:
Indicates if a click handler has been registered.
"""

_height = t.Int(default_value=DEFAULT_HEIGHT, allow_none=True).tag(sync=True)
height = t.Unicode(default_value=DEFAULT_HEIGHT).tag(sync=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want to have a breaking change here, so if we allow strings here, it should be a t.Union of strings and integers (or at least we need to validate that we can pass in an integer and it'll get converted to a string, but we probably want to add a px suffix?)

@kylebarron
Copy link
Member

kylebarron commented Jun 24, 2025

It would be really nice if the HTML export automatically filled the entire window:

Map([]).to_html("test.html")

gives:
image

@ATL2001
Copy link
Contributor Author

ATL2001 commented Jun 25, 2025

oh yeah, this exporting as height 100% looks really sharp! you want a map, you get a map! 💥

lonboard/_map.py Outdated
)
original_height = self.height
try:
self.height = "100%"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause the JS side to be janky? Is there a way to set this without causing a JS side re-render?

Like maybe use hold_trait_notifications to avoid sending any new events while temporarily setting .height? https://traitlets.readthedocs.io/en/stable/using_traitlets.html#holding-trait-cross-validation-and-notifications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, I didn't notice that re-rendering happening

src/index.tsx Outdated
Comment on lines 217 to 221
let height = String(mapHeight);
if (typeof mapHeight === "number") {
// if a number is used for height, assume pixels
height = height + "px";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of suggesting this validation be done on the Python side, so the Python side is always sending a string to the JS side. There are several places that we already use custom validators

ATL2001 added 2 commits June 28, 2025 07:32
…ck when going to html.

convert height to string on python side
@kylebarron
Copy link
Member

kylebarron commented Jun 30, 2025

To fix CI you can run uv run --group dev pre-commit run --all-files and then commit the output. The formatter is failing on the notebook

@ATL2001
Copy link
Contributor Author

ATL2001 commented Jul 1, 2025

I was planning on deleting that notebook eventually, but i went ahead and fixed it up, but I'm not sure what this new error means :(

@kylebarron
Copy link
Member

If you look at the git diff, you did something to change the symlinks. And so the docs website build isn't able to find the index.md (pointing to the top-level README)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants