Skip to content

Commit

Permalink
Added support for compare and compareBase
Browse files Browse the repository at this point in the history
issue gtnx#45
  • Loading branch information
Jordan Platts committed Apr 10, 2018
1 parent bf449b7 commit 951563a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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

0 comments on commit 951563a

Please sign in to comment.