Skip to content

Commit

Permalink
Fixed colorbar width bug (#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Jul 9, 2023
1 parent 3441c0d commit 8381d13
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def plot(
max_height (int, optional): Max height of the widget (in pixels), if None it will respect the content size. Defaults to None.
"""
if hasattr(self, '_plot_widget') and self._plot_widget is not None:
if hasattr(self, "_plot_widget") and self._plot_widget is not None:
plot_widget = self._plot_widget
else:
plot_widget = widgets.Output(layout={"border": "1px solid black"})
Expand Down Expand Up @@ -1011,6 +1011,7 @@ def add_colorbar(
layer_name=None,
font_size=9,
axis_off=False,
max_width="270px",
**kwargs,
):
"""Add a matplotlib colorbar to the map
Expand All @@ -1026,6 +1027,7 @@ def add_colorbar(
layer_name (str, optional): The layer name associated with the colorbar. Defaults to None.
font_size (int, optional): Font size for the colorbar. Defaults to 9.
axis_off (bool, optional): Whether to turn off the axis. Defaults to False.
max_width (str, optional): Maximum width of the colorbar in pixels. Defaults to "300px".
Raises:
TypeError: If the vis_params is not a dictionary.
Expand Down Expand Up @@ -1152,7 +1154,7 @@ def add_colorbar(
if transparent_bg:
fig.patch.set_alpha(0.0)

output = widgets.Output()
output = widgets.Output(layout=widgets.Layout(width=max_width))
colormap_ctrl = ipyleaflet.WidgetControl(
widget=output,
position=position,
Expand All @@ -1176,7 +1178,7 @@ def add_colorbar(

def remove_colorbar(self):
"""Remove colorbar from the map."""
if hasattr(self, '_colorbar') and self._colorbar is not None:
if hasattr(self, "_colorbar") and self._colorbar is not None:
self.remove_control(self._colorbar)

def remove_colorbars(self):
Expand All @@ -1188,7 +1190,7 @@ def remove_colorbars(self):

def remove_legend(self):
"""Remove legend from the map."""
if hasattr(self, '_legend') and self._legend is not None:
if hasattr(self, "_legend") and self._legend is not None:
if self._legend in self.controls:
self.remove_control(self._legend)

Expand Down Expand Up @@ -4217,7 +4219,7 @@ def to_image(self, filename=None, monitor=1):

def toolbar_reset(self):
"""Reset the toolbar so that no tool is selected."""
if hasattr(self, '_toolbar'):
if hasattr(self, "_toolbar"):
toolbar_grid = self._toolbar
if toolbar_grid is not None:
for tool in toolbar_grid.children:
Expand Down Expand Up @@ -6455,7 +6457,7 @@ def add_widget(
add_header=True,
opened=True,
show_close_button=True,
widget_icon='gear',
widget_icon="gear",
close_button_icon="times",
widget_args={},
close_button_args={},
Expand Down

0 comments on commit 8381d13

Please sign in to comment.