You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/21 18:31:35 UTC

[GitHub] mistercrunch closed pull request #5682: [bugfix] making secondary_metric optional

mistercrunch closed pull request #5682: [bugfix] making secondary_metric optional
URL: https://github.com/apache/incubator-superset/pull/5682
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/explore/controls.jsx b/superset/assets/src/explore/controls.jsx
index 8dd72a712b..66a17ee352 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: {
@@ -1430,6 +1431,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 9f3e4e069d..a287a62290 100644
--- a/superset/assets/src/explore/visTypes.jsx
+++ b/superset/assets/src/explore/visTypes.jsx
@@ -1511,6 +1511,7 @@ export const visTypes = {
           ['country_fieldtype'],
           ['metric'],
           ['adhoc_filters'],
+          ['row_limit'],
         ],
       },
       {
@@ -1590,13 +1591,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 f60904994d..8e4ff5e6cc 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 0c9c2cc5ee..a00d28b824 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 c060e19550..7728bdef75 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1724,8 +1724,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
 
@@ -1735,6 +1733,7 @@ def get_data(self, df):
         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
@@ -1742,10 +1741,14 @@ def get_data(self, df):
             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
@@ -1843,10 +1846,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
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org