Skip to content

Commit

Permalink
ECharts depends on sliders fix (#1875)
Browse files Browse the repository at this point in the history
* fixed

* Simplify ECharts updates

* Simplify further

* Fix flake

Co-authored-by: Marc Skov Madsen <[email protected]>
Co-authored-by: Philipp Rudiger <[email protected]>
  • Loading branch information
3 people committed Jan 14, 2021
1 parent 2bce2bb commit ba157ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
21 changes: 7 additions & 14 deletions panel/pane/echarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

from pyviz_comms import JupyterComm

from ..viewable import Layoutable
from .base import PaneBase



class ECharts(PaneBase):
"""
ECharts panes allow rendering echarts.js plots.
"""

object = param.Parameter(default=None, doc="""
The Echarts object being wrapped. Can be an Echarts dictionary or a pyecharts chart""")

Expand Down Expand Up @@ -71,24 +70,18 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
self._models[root.ref['id']] = (model, parent)
return model

def _update(self, ref=None, model=None):
props = {p : getattr(self, p) for p in list(Layoutable.param)
if getattr(self, p) is not None}
echart = self._get_echart_dict(self.object)
self._get_dimensions(echart, props)
props['data'] = echart
model.update(**props)
def _process_param_change(self, msg):
msg = super()._process_param_change(msg)
if 'data' in msg:
msg['data'] = self._get_echart_dict(msg['data'])
return msg

@classmethod
def _get_echart_dict(cls, object):
if object is None:
return {}
if isinstance(object, dict):
return dict(object)
if "pyecharts" in sys.modules:
elif "pyecharts" in sys.modules:
import pyecharts # pylint: disable=import-outside-toplevel,import-error

if isinstance(object, pyecharts.charts.chart.Chart):
return json.loads(object.dump_options())

return {}
18 changes: 17 additions & 1 deletion panel/tests/pane/test_echart.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,25 @@ def get_pyechart():
assert pane.object == bar
return pane

def get_pyechart2():
from pyecharts.charts import Bar
import panel as pn

bar1 = pn.widgets.IntSlider(start=1, end=100, value=50)
bar2 = pn.widgets.IntSlider(start=1, end=100, value=50)

@pn.depends(bar1.param.value, bar2.param.value)
def plot(bar1, bar2):
my_plot= (Bar()
.add_xaxis(['Bar1', 'Bar2'])
.add_yaxis('Values', [bar1, bar2])
)
return pn.pane.ECharts(my_plot, width=500, height=250)
return pn.Row(pn.Column(bar1, bar2), plot)

if __name__.startswith("bokeh"):
# test_echart().servable()
get_pyechart().servable()
get_pyechart2().servable()
if __name__.startswith("__main__"):
test_echart().show(port=5007)
get_pyechart().show(port=5007)

0 comments on commit ba157ee

Please sign in to comment.