Skip to content

Commit

Permalink
fix-plotly-mapbox-relayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Skov Madsen committed Sep 5, 2021
1 parent 788b454 commit 13a820c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
13 changes: 10 additions & 3 deletions panel/pane/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Plotly(PaneBase):
* "mouseup": updates are synchronized when mouse button is
released after panning
* "continuous": updates are synchronized continually while panning
* "throttle": updates are synchronized while panning, at
* "throttle": updates are synchronized while panning, at
intervals determined by the viewport_update_throttle parameter
""", objects=["mouseup", "continuous", "throttle"])

Expand Down Expand Up @@ -150,7 +150,14 @@ def _update_figure_style(self):
def _update_figure_layout(self):
if self._figure is None or self.relayout_data is None:
return
self._figure.plotly_relayout(self.relayout_data)
relayout_data = self._clean_relayout_data(self.relayout_data)
self._figure.plotly_relayout(relayout_data)

@staticmethod
def _clean_relayout_data(relayout_data):
return {
key: val for key, val in relayout_data.items() if not key.endswith("._derived")
}

def _send_update_msg(
self, restyle_data, relayout_data, trace_indexes=None, source_view_id=None
Expand Down Expand Up @@ -210,7 +217,7 @@ def _plotly_json_wrapper(fig):
if isdatetime(data[idx][key]):
arr = data[idx][key]
if isinstance(arr, np.ndarray):
arr = arr.astype(str)
arr = arr.astype(str)
else:
arr = [str(v) for v in arr]
data[idx][key] = arr
Expand Down
30 changes: 27 additions & 3 deletions panel/tests/pane/test_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_plotly_pane_numpy_to_cds_traces(document, comm):
@plotly_available
def test_plotly_autosize(document, comm):
trace = go.Scatter(x=[0, 1], y=[2, 3])

pane = Plotly(dict(data=[trace], layout={'autosize': True}))

model = pane.get_root(document, comm=comm)
Expand All @@ -187,7 +187,7 @@ def test_plotly_autosize(document, comm):
@plotly_available
def test_plotly_tabs(document, comm):
trace = go.Scatter(x=[0, 1], y=[2, 3])

pane1 = Plotly(dict(data=[trace], layout={'autosize': True}))
pane2 = Plotly(dict(data=[trace], layout={'autosize': True}))

Expand All @@ -207,7 +207,31 @@ def test_plotly_tabs(document, comm):
assert not model2.visible
assert cb2.args['model'] is model2
assert cb2.code == 'model.visible = (cb_obj.active == 1);'

tabs.insert(0, 'Blah')
assert cb1.code == 'model.visible = (cb_obj.active == 1);'
assert cb2.code == 'model.visible = (cb_obj.active == 2);'

@plotly_available
def test_clean_relayout_data():
relayout_data = {
"mapbox.center": {"lon": -73.59183434290809, "lat": 45.52341668343991},
"mapbox.zoom": 10,
"mapbox.bearing": 0,
"mapbox.pitch": 0,
"mapbox._derived": {
"coordinates": [
[-73.92279747767401, 45.597934047192865],
[-73.26087120814279, 45.597934047192865],
[-73.26087120814279, 45.44880048640681],
[-73.92279747767401, 45.44880048640681],
]
},
}
result = Plotly._clean_relayout_data(relayout_data)
assert result == {
"mapbox.center": {"lon": -73.59183434290809, "lat": 45.52341668343991},
"mapbox.zoom": 10,
"mapbox.bearing": 0,
"mapbox.pitch": 0,
}

0 comments on commit 13a820c

Please sign in to comment.