Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to sunburst #4349

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions superset/assets/javascripts/explore/stores/visTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,10 @@ export const visTypes = {
},
secondary_metric: {
label: t('Secondary Metric'),
description: t('This secondary metric is used to ' +
default: null,
description: t('[optional] this secondary metric is used to ' +
'define the color as a ratio against the primary metric. ' +
'If the two metrics match, color is mapped level groups'),
'When omitted, the color is categorical and based on labels'),
},
groupby: {
label: t('Hierarchy'),
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/visualizations/sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function sunburstVis(slice, payload) {
let ext;
const fd = slice.formData;

if (fd.metric !== fd.secondary_metric) {
if (fd.metric !== fd.secondary_metric && fd.secondary_metric) {
colorByCategory = false;
ext = d3.extent(nodes, d => d.m2 / d.m1);
colorScale = d3.scale.linear()
Expand Down
28 changes: 13 additions & 15 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,24 +1346,22 @@ class SunburstViz(BaseViz):
'@<a href="https://bl.ocks.org/kerryrodden/7090426">bl.ocks.org</a>')

def get_data(self, df):

# if m1 == m2 duplicate the metric column
cols = self.form_data.get('groupby')
metric = self.form_data.get('metric')
secondary_metric = self.form_data.get('secondary_metric')
if metric == secondary_metric:
ndf = df
ndf.columns = [cols + ['m1', 'm2']]
else:
cols += [
self.form_data['metric'], self.form_data['secondary_metric']]
ndf = df[cols]
return json.loads(ndf.to_json(orient='values')) # TODO fix this nonsense
fd = self.form_data
cols = fd.get('groupby')
metric = fd.get('metric')
secondary_metric = fd.get('secondary_metric')
if metric == secondary_metric or secondary_metric is None:
df.columns = cols + ['m1']
df['m2'] = df['m1']
return json.loads(df.to_json(orient='values'))

def query_obj(self):
qry = super(SunburstViz, self).query_obj()
qry['metrics'] = [
self.form_data['metric'], self.form_data['secondary_metric']]
fd = self.form_data
qry['metrics'] = [fd['metric']]
secondary_metric = fd.get('secondary_metric')
if secondary_metric and secondary_metric != fd['metric']:
qry['metrics'].append(secondary_metric)
return qry


Expand Down