From b88f2825ea92103fb011a81b70a284823cc62426 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 23 Dec 2015 07:53:21 -0800 Subject: [PATCH] Improvements to bubble chart --- panoramix/data/__init__.py | 2 +- panoramix/static/widgets/viz_nvd3.js | 19 ++++++++++++++++++- panoramix/viz.py | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/panoramix/data/__init__.py b/panoramix/data/__init__.py index 1c1eb3cf0e..a6090e2c46 100644 --- a/panoramix/data/__init__.py +++ b/panoramix/data/__init__.py @@ -75,7 +75,7 @@ def load_world_bank_health_n_pop(): obj = db.session.query(TBL).filter_by(table_name=tbl).first() if not obj: obj = TBL(table_name='wb_health_population') - obj.main_dttm_col = 'ds' + obj.main_dttm_col = 'year' obj.database = get_or_create_db(db.session) models.Table db.session.add(obj) diff --git a/panoramix/static/widgets/viz_nvd3.js b/panoramix/static/widgets/viz_nvd3.js index d6a3cf7502..ce7f3db2e3 100644 --- a/panoramix/static/widgets/viz_nvd3.js +++ b/panoramix/static/widgets/viz_nvd3.js @@ -28,6 +28,8 @@ function viz_nvd3(slice) { var data = payload.data; var viz = payload; var viz_type = viz.form_data.viz_type; + var fd = viz.form_data; + var f = d3.format('.4s'); nv.addGraph(function() { if (viz_type === 'line') { if (viz.form_data.show_brush) { @@ -106,10 +108,25 @@ function viz_nvd3(slice) { chart.yAxis.tickFormat(d3.format('.3p')); } else if (viz_type === 'bubble') { + var row = function(col1, col2){ + return "" + col1 + "" + col2 + "" + } chart = nv.models.scatterChart(); + chart.showDistX(true); + chart.showDistY(true); chart.xAxis.tickFormat(d3.format('.3s')); chart.yAxis.tickFormat(d3.format('.3s')); - chart.showLegend(viz.form_data.show_legend); + chart.showLegend(fd.show_legend); + chart.tooltip.contentGenerator(function (obj) { + p = obj.point; + var s = "" + s += ''; + s += row(fd.x, f(p.x)); + s += row(fd.y, f(p.y)); + s += row(fd.size, f(p.size)); + s += "
' + p[fd.entity] + ' (' + p.group + ')
"; + return s; + }); chart.pointRange([5, 5000]); } else if (viz_type === 'area') { diff --git a/panoramix/viz.py b/panoramix/viz.py index 27f5b5c190..1c25b01618 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -472,8 +472,8 @@ class BubbleViz(NVD3Viz): 'fields': ( ('since', 'until'), ('series', 'entity'), - ('x', 'y'), - ('size', 'limit'), + 'x', 'y', 'size', + 'limit', ('x_log_scale', 'y_log_scale'), ('show_legend', None), )