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

Commit

Permalink
fix: only remove tooltips relating to a single vis (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Ritter authored Aug 6, 2019
1 parent ecd5744 commit 8059485
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"@superset-ui/build-config": "^0.1.0",
"@superset-ui/commit-config": "^0.0.9",
"@superset-ui/chart": "^0.11.13",
"@superset-ui/chart": "^0.11.14",
"@superset-ui/chart-composition": "^0.11.9",
"@superset-ui/color": "^0.11.9",
"@superset-ui/connection": "^0.11.10",
Expand Down
24 changes: 23 additions & 1 deletion packages/superset-ui-legacy-preset-chart-nvd3/src/NVD3Vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ import {
generateMultiLineTooltipContent,
generateRichLineTooltipContent,
generateTimePivotTooltip,
generateTooltipClassName,
generateAreaChartTooltipContent,
getMaxLabelSize,
getTimeOrNumberFormatter,
hideTooltips,
tipFactory,
tryNumify,
removeTooltip,
setAxisShowMaxMin,
stringifyTimeRange,
wrapTooltip,
Expand Down Expand Up @@ -254,6 +256,10 @@ function nvd3Vis(element, props) {
const container = element;
container.innerHTML = '';
const activeAnnotationLayers = annotationLayers.filter(layer => layer.show);
const chartId =
container.parentElement && container.parentElement.id !== ''
? container.parentElement.id
: null;

let chart;
let width = maxWidth;
Expand Down Expand Up @@ -803,6 +809,18 @@ function nvd3Vis(element, props) {
data.push(...timeSeriesAnnotations);
}

// Uniquely identify tooltips based on chartId so this chart instance only
// controls its own tooltips
if (chartId) {
if (chart && chart.interactiveLayer && chart.interactiveLayer.tooltip) {
chart.interactiveLayer.tooltip.classes([generateTooltipClassName(chartId)]);
}

if (chart && chart.tooltip) {
chart.tooltip.classes([generateTooltipClassName(chartId)]);
}
}

// render chart
svg
.datum(data)
Expand Down Expand Up @@ -1080,7 +1098,11 @@ function nvd3Vis(element, props) {
// Remove tooltips before rendering chart, if the chart is being re-rendered sometimes
// there are left over tooltips in the dom,
// this will clear them before rendering the chart again.
hideTooltips(true);
if (chartId) {
removeTooltip(chartId);
} else {
hideTooltips(true);
}

nv.addGraph(drawGraph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
*/
import { reactify } from '@superset-ui/chart';
import Component from './NVD3Vis';
import { hideTooltips } from './utils';
import { hideTooltips, removeTooltip } from './utils';

function componentWillUnmount() {
hideTooltips(true);
const { id } = this.props; // eslint-disable-line babel/no-invalid-this
if (id !== null && id !== undefined) {
removeTooltip(id);
} else {
hideTooltips(true);
}
}

export default reactify(Component, { componentWillUnmount });
12 changes: 12 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 @@ -267,6 +267,18 @@ export function hideTooltips(shouldRemove) {
}
}

export function generateTooltipClassName(uuid) {
return `tooltip-${uuid}`;
}

export function removeTooltip(uuid) {
const classSelector = `.${generateTooltipClassName(uuid)}`;
const target = document.querySelector(classSelector);
if (target) {
target.remove();
}
}

export function wrapTooltip(chart, maxWidth) {
const tooltipLayer =
chart.useInteractiveGuideline && chart.useInteractiveGuideline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default [
{
renderStory: () => (
<SuperChart
id="stacked-area-chart"
chartType="area"
datasource={dummyDatasource}
width={400}
Expand Down

0 comments on commit 8059485

Please sign in to comment.