Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pandas_highcharts/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions pandas_highcharts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down