diff --git a/pandas_highcharts/core.py b/pandas_highcharts/core.py index f7edabc..23fabd7 100644 --- a/pandas_highcharts/core.py +++ b/pandas_highcharts/core.py @@ -85,7 +85,31 @@ def serialize_pane(df, output, *args, **kwargs): pass def serialize_plotOptions(df, output, *args, **kwargs): - pass + if "plotOptions" in kwargs: + + plotOptionsDict = {} + + for k1, v1 in kwargs["plotOptions"].items(): + # add series options + if "series" == k1: + # add safety conditions here + for k2, v2 in v1.items(): + if k2 == "compare": + if v2 not in ("percent", "value"): + raise(ValueError("compare option in plotOptions - series can only be percent or value")) + + # add series options to plotOptions + if v1: + plotOptionsDict[k1] = v1 + + # every option has not been tested yet + else: + plotOptionsDict[k1] = v1 + # raise(NotImplementedError("Other plotOptions besides series are not tested yet!")) + # I left this error commented because it is a design choice on where the error should be thrown + + if plotOptionsDict: + output["plotOptions"] = plotOptionsDict def serialize_series(df, output, *args, **kwargs): def is_secondary(c, **kwargs): diff --git a/pandas_highcharts/tests.py b/pandas_highcharts/tests.py index 55e7dde..7e34f00 100644 --- a/pandas_highcharts/tests.py +++ b/pandas_highcharts/tests.py @@ -86,6 +86,19 @@ def test_type(self): obj = serialize(df2, render_to='chart', output_type='dict') self.assertEqual(obj['series'], [{'data': [('b', 2), ('a', 1)], 'name': 's', 'yAxis': 0}]) + def test_serialize_plotOptions(self): + + # test compare and compareBase + plotOptions = { + "series": + { + "compare": "percent", + "compareBase": 100 + } + } + obj = serialize(df, render_to="chart", output_type="dict", plotOptions=plotOptions) + self.assertEqual(obj['plotOptions'], plotOptions) + def test_json_output(self): json_output = serialize(df, output_type="json") self.assertEqual(type(json_output), str)