From 9ce4f684734c9c3000aa9fa30f5e953971410f6a Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 23 Jul 2015 05:20:10 +0000 Subject: [PATCH 1/2] New Charts --- TODO.md | 5 +- app.db | Bin 78848 -> 79872 bytes app/highchart.py | 156 +++++++++++++++++++++++++++++++++++++++++++++++ app/viz.py | 32 +++++----- requirements.txt | 1 - 5 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 app/highchart.py diff --git a/TODO.md b/TODO.md index f6a28803fd803..6bbbfc32a7f9e 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,8 @@ # TODO +* in/notin filters autocomplete +* Highstock, sort legend based on y value: ![stackoverflow](http://stackoverflow.com/questions/6867607/want-to-sort-highcharts-tooltip-results) * compare time ranges -* Label +* Add verbose_name and label method to metrics and columns * CSV * Save / bookmark / url shortener +* on save, process metadata / generate metrics diff --git a/app.db b/app.db index f0bf7ecb2de2cd533b5beba7407a282c854ff14d..5c4db1afcfce9dbcc9c4894efe7b7036c4fd6565 100644 GIT binary patch delta 498 zcmY*TK}!Nb7~ORZElBWCmk8!i8zH2w6(kJerJ%qLUAj%o7vewY z4}?L7euRIaJax>Amk1gxB~Rb`zW2WOUh5;?`i$Q%&GaqHsyu*_-G4fH+)Fvmz#OcK z^W_YkK{uW2JF)UYcX*I`c4lqRN!Y!(;rH9=`0fj^?Kf|3-t2ZPVZ{>Nbn@Fy-8L3e z<+8P$Ox~343Y~X*{kl-}c8dAUjqTiaZZlu=H9C)|8c*O0t}*2bV8F1J^b&{~C{tPG z)ini}P})cs6C5yNXkP&XMO{u&0cC_MD!AInMwknU8NJK~SYvf$v_8p>^RlG|y+XPf z5g1ZV+&@#O>I@-<8aS*I_f%qD53!`W3G Date: Thu, 23 Jul 2015 06:11:51 +0000 Subject: [PATCH 2/2] Implementing my own highcharts wrapper --- app/highchart.py | 18 ++++++++------- app/templates/panoramix/viz_highcharts.html | 2 +- app/viz.py | 25 ++++++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/highchart.py b/app/highchart.py index a872bb9274ff5..00df150106d49 100644 --- a/app/highchart.py +++ b/app/highchart.py @@ -12,7 +12,7 @@ def __init__( width=None, height=None, show_legend=True, - stockchart=True, + stockchart=False, title=None, tooltip=None, sort_columns=False, @@ -41,6 +41,7 @@ def __init__( self.zoom = zoom self.polar = polar self.grid = grid + self.stacked = stacked chart['chart'] = {} chart['chart']["type"] = chart_type @@ -56,8 +57,8 @@ def __init__( chart["legend"] = { "enabled": show_legend } - if title: - chart["title"] = {"text": title} + chart["title"] = {"text": title} + if tooltip: chart['tooltip'] = tooltip if self.zoom: @@ -89,7 +90,7 @@ def serialize_series(self): d['data'] = [v for k, v in d['data']] if self.compare: d['compare'] = self.compare # either `value` or `percent` - if self.chart_type in ("area", "bar") and self.stacked: + if self.chart_type in ("area", "column", "bar") and self.stacked: d["stacking"] = 'normal' #if kwargs.get("style"): # d["dashStyle"] = pd2hc_linestyle(kwargs["style"].get(name, "-")) @@ -103,7 +104,8 @@ def serialize_xaxis(self): if df.index.dtype.kind in "M": x_axis["type"] = "datetime" if df.index.dtype.kind == 'O': - chart['xAxis']['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 x_axis["gridLineDashStyle"] = "Dot" @@ -120,7 +122,7 @@ def serialize_xaxis(self): if "xticks" in kwargs: x_axis["tickPositions"] = kwargs["xticks"] ''' - self.x_axis = x_axis + self.chart['xAxis'] = x_axis def serialize_yaxis(self): yAxis = {} @@ -152,5 +154,5 @@ def serialize_yaxis(self): def javascript_cmd(self): js = dumps(self.chart) if self.stockchart: - return "new Highcharts.StockChart({});".format(js) - return "new Highcharts.Chart({});".format(js) + return "new Highcharts.StockChart(%s);" % js + return "new Highcharts.Chart(%s);" %js diff --git a/app/templates/panoramix/viz_highcharts.html b/app/templates/panoramix/viz_highcharts.html index c3940726b9e2c..efb4d19276a79 100644 --- a/app/templates/panoramix/viz_highcharts.html +++ b/app/templates/panoramix/viz_highcharts.html @@ -17,7 +17,7 @@ {% block tail %} {{ super() }} -{% if viz.chart_type == "stock" %} +{% if viz.stockchart %} {% else %} diff --git a/app/viz.py b/app/viz.py index 433ec3c0c9203..4cc1ccb0a1fcd 100644 --- a/app/viz.py +++ b/app/viz.py @@ -220,7 +220,7 @@ class HighchartsViz(BaseViz): class TimeSeriesViz(HighchartsViz): verbose_name = "Time Series - Line Chart" chart_type = "spline" - highstock = True + stockchart = True def render(self): metrics = self.metrics @@ -241,6 +241,7 @@ def render(self): compare=self.compare, chart_type=self.chart_type, stacked=self.stacked, + stockchart=self.stockchart, **CHART_ARGS) return super(TimeSeriesViz, self).render(chart_js=chart.javascript_cmd) @@ -302,18 +303,18 @@ class TimeSeriesAreaViz(TimeSeriesViz): class TimeSeriesBarViz(TimeSeriesViz): verbose_name = "Time Series - Bar Chart" - chart_type = "bar" + chart_type = "column" class TimeSeriesStackedBarViz(TimeSeriesViz): verbose_name = "Time Series - Stacked Bar Chart" - chart_type = "bar" + chart_type = "column" stacked = True class DistributionBarViz(HighchartsViz): verbose_name = "Distribution - Bar Chart" - chart_type = "bar" + chart_type = "column" def query_obj(self): d = super(DistributionBarViz, self).query_obj() @@ -326,14 +327,15 @@ def render(self): index=self.groupby, values=self.metrics) df = df.sort(self.metrics[0], ascending=False) - chart_js = serialize( - df, kind=self.chart_kind, **CHART_ARGS) - return super(DistributionBarViz, self).render(chart_js=chart_js) + chart = Highchart( + df, chart_type=self.chart_type, **CHART_ARGS) + return super(DistributionBarViz, self).render( + chart_js=chart.javascript_cmd) class DistributionPieViz(HighchartsViz): verbose_name = "Distribution - Pie Chart" - chart_kind = "pie" + chart_type = "pie" def query_obj(self): d = super(DistributionPieViz, self).query_obj() @@ -346,9 +348,10 @@ def render(self): index=self.groupby, values=[self.metrics[0]]) df = df.sort(self.metrics[0], ascending=False) - chart_js = serialize( - df, kind=self.chart_kind, **CHART_ARGS) - return super(DistributionPieViz, self).render(chart_js=chart_js) + chart = Highchart( + df, chart_type=self.chart_type, **CHART_ARGS) + return super(DistributionPieViz, self).render( + chart_js=chart.javascript_cmd) viz_types = OrderedDict([ ['table', TableViz],