Skip to content

Commit

Permalink
wrap to_plotly_json and turn datetimes into strings (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-recknagel authored and philippjfr committed Oct 12, 2019
1 parent ba6c7db commit ba25047
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions panel/pane/plotly.py
Expand Up @@ -13,6 +13,7 @@
import param

from .base import PaneBase
from ..util import isdatetime


class Plotly(PaneBase):
Expand Down Expand Up @@ -153,6 +154,21 @@ def _update_data_sources(self, cds, trace):

return update_sources

@staticmethod
def _plotly_json_wrapper(fig):
"""Wraps around to_plotly_json and applies necessary fixes.
For #382: Map datetime elements to strings.
"""
json = fig.to_plotly_json()
data = json['data']

for idx in range(len(data)):
for key in data[idx]:
if isdatetime(data[idx][key]):
data[idx][key].astype(str)
return json

def _get_model(self, doc, root=None, parent=None, comm=None):
"""
Should return the bokeh model to be rendered.
Expand All @@ -172,7 +188,7 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
json, sources = {}, []
else:
fig = self._to_figure(self.object)
json = fig.to_plotly_json()
json = self._plotly_json_wrapper(fig)
sources = Plotly._get_sources(json)
model = PlotlyPlot(data=json.get('data', []),
layout=json.get('layout', {}),
Expand Down Expand Up @@ -209,7 +225,7 @@ def _update(self, model):
return

fig = self._to_figure(self.object)
json = fig.to_plotly_json()
json = self._plotly_json_wrapper(fig)

traces = json['data']
new_sources = []
Expand Down

0 comments on commit ba25047

Please sign in to comment.