Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
feat: improve the tooltip for the time pivot chart (#30)
Browse files Browse the repository at this point in the history
* style: improve the tooltip for the time pivot chart

* fix: lint errors
  • Loading branch information
datability-io authored and kristw committed Mar 29, 2019
1 parent c9b8195 commit ad6ab28
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
generateBubbleTooltipContent,
generateMultiLineTooltipContent,
generateRichLineTooltipContent,
generateTimePivotTooltip,
getMaxLabelSize,
getTimeOrNumberFormatter,
hideTooltips,
Expand Down Expand Up @@ -539,6 +540,11 @@ function nvd3Vis(element, props) {
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
});
}

chart.useInteractiveGuideline(true);
chart.interactiveLayer.tooltip.contentGenerator(d =>
generateTimePivotTooltip(d, xAxisFormatter, yAxisFormatter),
);
} else if (vizType !== 'bullet') {
const colorFn = getScale(colorScheme);
chart.color(d => d.color || colorFn(cleanColorInput(d[colorKey])));
Expand Down
30 changes: 30 additions & 0 deletions packages/superset-ui-legacy-preset-chart-nvd3/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,36 @@ export function generateMultiLineTooltipContent(d, xFormatter, yFormatters) {
return tooltip;
}

export function generateTimePivotTooltip(d, xFormatter, yFormatter) {
const tooltipTitle = xFormatter(d.value);
let tooltip = '';

tooltip +=
"<table><thead><tr><td colspan='3'>" +
`<strong class='x-value'>${tooltipTitle}</strong>` +
'</td></tr></thead><tbody>';

d.series.forEach(series => {
if (series.highlight) {
let label = '';
if (series.key === 'current') {
label = series.key;
} else {
label = `${series.key} of the selected frequence`;
}
tooltip +=
"<tr><td class='legend-color-guide'>" +
`<div style="background-color: ${series.color};"></div></td>` +
`<td class='key'>${label}</td>` +
`<td class='value'>${yFormatter(series.value)}</td></tr>`;
}
});

tooltip += '</tbody></table>';

return dompurify.sanitize(tooltip);
}

function getLabel(stringOrObjectWithLabel) {
return stringOrObjectWithLabel.label || stringOrObjectWithLabel;
}
Expand Down

0 comments on commit ad6ab28

Please sign in to comment.