superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [bugfix] making secondary_metric optional (#5682)
Date Tue, 21 Aug 2018 18:31:35 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 71e0c07  [bugfix] making secondary_metric optional (#5682)
71e0c07 is described below

commit 71e0c079041c4f955e8529349baa17058e70d256
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Tue Aug 21 11:31:33 2018 -0700

    [bugfix] making secondary_metric optional (#5682)
    
    I noticed that `secondary_metric` was required in the chart that users
    it, namely sunburst, parallel coordinates, and world_map.
    
    I set the control as allowing null, and found related bugs in the
    process:
    * parallel coordinates did not have support for the new MetricControl
    * added color scheme support for parallel coordinates
    * added option to set row_limit on these viz types
    * sunburst to support numeric columns (number would show as blank)
---
 superset/assets/src/explore/controls.jsx           |  2 ++
 superset/assets/src/explore/visTypes.jsx           |  5 ++++-
 .../src/visualizations/parallel_coordinates.js     | 26 +++++++++-------------
 superset/assets/src/visualizations/sunburst.js     |  4 ++--
 superset/viz.py                                    | 15 ++++++-------
 5 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/superset/assets/src/explore/controls.jsx b/superset/assets/src/explore/controls.jsx
index 56bb950..a392c61 100644
--- a/superset/assets/src/explore/controls.jsx
+++ b/superset/assets/src/explore/controls.jsx
@@ -533,6 +533,7 @@ export const controls = {
     ...metric,
     label: t('Color Metric'),
     default: null,
+    validators: [],
     description: t('A metric to use for color'),
   },
   select_country: {
@@ -1437,6 +1438,7 @@ export const controls = {
     type: 'CheckboxControl',
     label: t('Data Table'),
     default: false,
+    renderTrigger: true,
     description: t('Whether to display the interactive data table'),
   },
 
diff --git a/superset/assets/src/explore/visTypes.jsx b/superset/assets/src/explore/visTypes.jsx
index f5caae7..f070096 100644
--- a/superset/assets/src/explore/visTypes.jsx
+++ b/superset/assets/src/explore/visTypes.jsx
@@ -1513,6 +1513,7 @@ export const visTypes = {
           ['country_fieldtype'],
           ['metric'],
           ['adhoc_filters'],
+          ['row_limit'],
         ],
       },
       {
@@ -1592,13 +1593,15 @@ export const visTypes = {
           ['metrics'],
           ['secondary_metric'],
           ['adhoc_filters'],
-          ['limit'],
+          ['limit', 'row_limit'],
         ],
       },
       {
         label: t('Options'),
+        expanded: true,
         controlSetRows: [
           ['show_datatable', 'include_series'],
+          ['linear_color_scheme'],
         ],
       },
     ],
diff --git a/superset/assets/src/visualizations/parallel_coordinates.js b/superset/assets/src/visualizations/parallel_coordinates.js
index f609049..8e4ff5e 100644
--- a/superset/assets/src/visualizations/parallel_coordinates.js
+++ b/superset/assets/src/visualizations/parallel_coordinates.js
@@ -1,6 +1,7 @@
 import d3 from 'd3';
 import '../../vendor/parallel_coordinates/d3.parcoords.css';
 import './parallel_coordinates.css';
+import { colorScalerFactory } from '../modules/colors';
 
 d3.parcoords = require('../../vendor/parallel_coordinates/d3.parcoords.js');
 d3.divgrid = require('../../vendor/parallel_coordinates/divgrid.js');
@@ -12,29 +13,24 @@ function parallelCoordVis(slice, payload) {
   const fd = slice.formData;
   const data = payload.data;
 
-  let cols = fd.metrics;
+  const metrics = fd.metrics.map(m => m.label || m);
+
+  let cols = metrics;
   if (fd.include_series) {
-    cols = [fd.series].concat(fd.metrics);
+    cols = [fd.series].concat(metrics);
   }
 
   const ttypes = {};
   ttypes[fd.series] = 'string';
-  fd.metrics.forEach(function (v) {
+  metrics.forEach(function (v) {
     ttypes[v] = 'number';
   });
 
-  let ext = d3.extent(data, function (d) {
-    return d[fd.secondary_metric];
-  });
-  ext = [ext[0], (ext[1] - ext[0]) / 2, ext[1]];
-  const cScale = d3.scale.linear()
-    .domain(ext)
-    .range(['red', 'grey', 'blue'])
-    .interpolate(d3.interpolateLab);
-
-  const color = function (d) {
-    return cScale(d[fd.secondary_metric]);
-  };
+  const secondaryMetric = fd.secondary_metric ? fd.secondary_metric.label : fd.secondary_metric;
+  const colorScaler = fd.secondary_metric ?
+    colorScalerFactory(fd.linear_color_scheme, data, d => d[secondaryMetric]) :
+    () => 'grey';
+  const color = d => colorScaler(d[secondaryMetric]);
   const container = d3.select(slice.selector);
   container.selectAll('*').remove();
   const effHeight = fd.show_datatable ? (slice.height() / 2) : slice.height();
diff --git a/superset/assets/src/visualizations/sunburst.js b/superset/assets/src/visualizations/sunburst.js
index 0c9c2cc..a00d28b 100644
--- a/superset/assets/src/visualizations/sunburst.js
+++ b/superset/assets/src/visualizations/sunburst.js
@@ -3,7 +3,7 @@ import d3 from 'd3';
 import { getColorFromScheme } from '../modules/colors';
 import { wrapSvgText } from '../modules/utils';
 
-require('./sunburst.css');
+import './sunburst.css';
 
 // Modified from http://bl.ocks.org/kerryrodden/7090426
 function sunburstVis(slice, payload) {
@@ -250,7 +250,7 @@ function sunburstVis(slice, payload) {
       let currentNode = root;
       for (let level = 0; level < levels.length; level++) {
         const children = currentNode.children || [];
-        const nodeName = levels[level];
+        const nodeName = levels[level].toString();
         // If the next node has the name '0', it will
         const isLeafNode = (level >= levels.length - 1) || levels[level + 1] === 0;
         let childNode;
diff --git a/superset/viz.py b/superset/viz.py
index dcd51ed..4c2490c 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1727,8 +1727,6 @@ class WorldMapViz(BaseViz):
 
     def query_obj(self):
         qry = super(WorldMapViz, self).query_obj()
-        qry['metrics'] = [
-            self.form_data['metric'], self.form_data['secondary_metric']]
         qry['groupby'] = [self.form_data['entity']]
         return qry
 
@@ -1738,6 +1736,7 @@ class WorldMapViz(BaseViz):
         cols = [fd.get('entity')]
         metric = self.get_metric_label(fd.get('metric'))
         secondary_metric = self.get_metric_label(fd.get('secondary_metric'))
+        columns = ['country', 'm1', 'm2']
         if metric == secondary_metric:
             ndf = df[cols]
             # df[metric] will be a DataFrame
@@ -1745,10 +1744,14 @@ class WorldMapViz(BaseViz):
             ndf['m1'] = df[metric].iloc[:, 0]
             ndf['m2'] = ndf['m1']
         else:
-            cols += [metric, secondary_metric]
+            if secondary_metric:
+                cols += [metric, secondary_metric]
+            else:
+                cols += [metric]
+                columns = ['country', 'm1']
             ndf = df[cols]
         df = ndf
-        df.columns = ['country', 'm1', 'm2']
+        df.columns = columns
         d = df.to_dict(orient='records')
         for row in d:
             country = None
@@ -1846,10 +1849,6 @@ class ParallelCoordinatesViz(BaseViz):
     def query_obj(self):
         d = super(ParallelCoordinatesViz, self).query_obj()
         fd = self.form_data
-        d['metrics'] = copy.copy(fd.get('metrics'))
-        second = fd.get('secondary_metric')
-        if second not in d['metrics']:
-            d['metrics'] += [second]
         d['groupby'] = [fd.get('series')]
         return d
 


Mime
View raw message