mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
[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)
This commit is contained in:
committed by
GitHub
parent
8dfa565c22
commit
71e0c07904
@@ -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'),
|
||||
},
|
||||
|
||||
|
||||
@@ -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'],
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user