Skip to content

Commit

Permalink
Fixed plotly bug #160
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Jan 3, 2022
1 parent a8ddcdd commit 8ac659a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,6 +19,7 @@ docs/cache/
docs/*.html
cache/
testing/
private/
.Python
env/
build/
Expand Down
12 changes: 8 additions & 4 deletions leafmap/plotlymap.py
Expand Up @@ -113,8 +113,8 @@ def show(
else:
canvas = Canvas(
self,
min_width=map_min_width,
max_width=map_max_width,
map_min_width=map_min_width,
map_max_width=map_max_width,
map_refresh=refresh,
)
return canvas.canvas
Expand Down Expand Up @@ -663,19 +663,23 @@ def fix_widget_error():
Fix FigureWidget - 'mapbox._derived' Value Error.
Adopted from: https://github.com/plotly/plotly.py/issues/2570#issuecomment-738735816
"""
import shutil
basedatatypesPath = os.path.join(
os.path.dirname(os.__file__), "site-packages", "plotly", "basedatatypes.py"
)

backup_file = basedatatypesPath.replace(".py", "_bk.py")
shutil.copyfile(basedatatypesPath, backup_file)

# read basedatatypes.py
with open(basedatatypesPath, "r") as f:
lines = f.read()

find = "if not BaseFigure._is_key_path_compatible(key_path_str, self.layout):"

replace = """if not BaseFigure._is_key_path_compatible(key_path_str, self.layout):
if key_path_str == "mapbox._derived":
return"""
if key_path_str == "mapbox._derived":
return"""

# add new text
lines = lines.replace(find, replace)
Expand Down
10 changes: 4 additions & 6 deletions leafmap/toolbar.py
Expand Up @@ -2171,12 +2171,6 @@ def handle_interaction(**kwargs):

def plotly_toolbar(
canvas,
# m=None,
# output=None,
# map_min_width="91%",
# map_max_width="98%",
# refresh=False,
# output_widget=None,
):
"""Creates the main toolbar and adds it to the map.
Expand Down Expand Up @@ -2283,13 +2277,15 @@ def tool_callback(change):
icon="wrench",
layout=widgets.Layout(width="28px", height="28px", padding="0px 0px 0px 4px"),
)
canvas.toolbar_button = toolbar_button

layers_button = widgets.ToggleButton(
value=False,
tooltip="Layers",
icon="server",
layout=widgets.Layout(height="28px", width="72px"),
)
canvas.layers_button = layers_button

toolbar_widget = widgets.VBox(layout=widgets.Layout(overflow="hidden"))
toolbar_widget.children = [toolbar_button]
Expand All @@ -2306,6 +2302,7 @@ def handle_toolbar_event(event):

if event["type"] == "mouseenter":
toolbar_widget.children = [toolbar_header, toolbar_footer]
# map_widget.layout.width = "85%"
elif event["type"] == "mouseleave":
if not toolbar_button.value:
toolbar_widget.children = [toolbar_button]
Expand Down Expand Up @@ -2477,5 +2474,6 @@ def close_click(change):
basemap_widget.close()
map_widget.layout.width = map_max_width
canvas.toolbar_reset()
canvas.toolbar_button.value = False

close_btn.on_click(close_click)

0 comments on commit 8ac659a

Please sign in to comment.