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

[Fix]: Label generation for grouped by, single metric time series charts #3566

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 25 additions & 9 deletions superset/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,22 @@ function getMaxLabelSize(container, axisClass) {
}

/* eslint-disable camelcase */
function formatLabel(column, verbose_map) {
function formatLabel(column, verbose_map, removeMostSignificant) {
let label;
if (verbose_map) {
if (Array.isArray(column) && column.length) {
label = verbose_map[column[0]];
if (Array.isArray(column) && column.length) {
if (removeMostSignificant && column.length > 1) {
label = '';
} else {
label = verbose_map[column[0]] || column[0];
if (column.length > 1) {
label += `, ${column.slice(1).join(', ')}`;
label += ', ';
}
} else {
label = verbose_map[column];
}
label += column.slice(1).join(', ');
} else {
label = verbose_map[column] || column;
}
return label || column;
return label;
}
/* eslint-enable camelcase */

Expand All @@ -97,9 +100,22 @@ function nvd3Vis(slice, payload) {
const isExplore = $('#explore-container').length === 1;

let data;
// Get the most significant part of the series name (key)
const mostSignificant = payload.data
.filter(x => Array.isArray(x.key) && x.key.length > 1)
.map(x => x.key[0]);
// # of distinct most significant keys
const distinctMostSignificant = mostSignificant
.reduce((distinct, v) => distinct.add(v), new Set()).size;
// remove the msg key from the label if these conditions are true
const removeMostSignificant = mostSignificant.length === payload.data.length &&
distinctMostSignificant === 1;
Copy link
Contributor Author

@fabianmenges fabianmenges Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of this (complicated) logic in line 103 to 112 we could simplify how we set the removeMostSignificant flag to:

const removeMostSignificant = slice.formData.metrics.length === 1;

However that would make the label generation depend on the fromData and it would therefore be less generic. Let me know what you think...

if (payload.data) {
data = payload.data.map(x => ({
...x, key: formatLabel(x.key, slice.datasource.verbose_map),
...x,
key: formatLabel(x.key,
slice.datasource.verbose_map || {},
removeMostSignificant),
}));
} else {
data = [];
Expand Down