diff --git a/app/highchart.py b/app/highchart.py
index dc8d73e1c0ccb..6a599b318b028 100644
--- a/app/highchart.py
+++ b/app/highchart.py
@@ -1,9 +1,27 @@
import pandas
+from collections import defaultdict
import copy
+import json
from pandas.io.json import dumps
-class Highchart(object):
+class BaseHighchart(object):
+ stockchart = False
+ tooltip_formatter = ""
+ target_div = 'chart'
+ @property
+ def javascript_cmd(self):
+ js = dumps(self.chart)
+ js = (
+ js.replace('"{{TOOLTIP_FORMATTER}}"', self.tooltip_formatter)
+ .replace("\n", " ")
+ )
+ if self.stockchart:
+ return "new Highcharts.StockChart(%s);" % js
+ return "new Highcharts.Chart(%s);" %js
+
+
+class Highchart(BaseHighchart):
def __init__(
self, df,
chart_type="spline",
@@ -144,7 +162,8 @@ def serialize_xaxis(self):
if df.index.dtype.kind in "M":
x_axis["type"] = "datetime"
if df.index.dtype.kind == 'O':
- x_axis['categories'] = sorted(list(df.index)) if self.sort_columns else list(df.index)
+ x_axis['categories'] = sorted(
+ list(df.index)) if self.sort_columns else list(df.index)
print list(df.index)
if self.grid:
x_axis["gridLineWidth"] = 1
@@ -174,10 +193,38 @@ def serialize_yaxis(self):
chart["yAxis"].append(yAxis2)
- @property
- def javascript_cmd(self):
- js = dumps(self.chart)
- js = js.replace('"{{TOOLTIP_FORMATTER}}"', self.tooltip_formatter).replace("\n", " ")
- if self.stockchart:
- return "new Highcharts.StockChart(%s);" % js
- return "new Highcharts.Chart(%s);" %js
+class HighchartBubble(BaseHighchart):
+ def __init__(self, df, target_div='chart', height=800):
+ self.df = df
+ self.chart = {
+ 'chart': {
+ 'type': 'bubble',
+ 'zoomType': 'xy'
+ },
+ 'title': {'text': None},
+ 'plotOptions': {
+ 'bubble': {
+ 'tooltip': {
+ 'headerFormat': '{series.name}
',
+ 'pointFormat': '{point.name}: {point.x}, {point.y}, {point.z}'
+ }
+ }
+ },
+ }
+ chart = self.chart
+ chart['series'] = self.series()
+ chart['chart']['renderTo'] = target_div
+ if height:
+ chart['chart']["height"] = height
+
+ def series(self):
+ #df = self.df[['name', 'x', 'y', 'z']]
+ df = self.df
+ series = defaultdict(list)
+ for row in df.to_dict(orient='records'):
+ series[row['group']].append(row)
+ l = []
+ for k, v in series.items():
+ l.append({'data': v, 'name': k})
+ print(json.dumps(l, indent=2))
+ return l
diff --git a/app/templates/panoramix/datasource.html b/app/templates/panoramix/datasource.html
index 1a33ffbba2f91..b2f3150356c0d 100644
--- a/app/templates/panoramix/datasource.html
+++ b/app/templates/panoramix/datasource.html
@@ -39,12 +39,16 @@