Skip to content

Commit

Permalink
[dashboard] fix nvd3 tooltips (#2096)
Browse files Browse the repository at this point in the history
* hide tooltips on scroll

* hide tooltips on render/re-render of the chart

* move function above vis function, fixes linter
  • Loading branch information
Alanna Scott authored Feb 2, 2017
1 parent 07e067c commit 543c22b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"immutable": "^3.8.1",
"jquery": "^2.2.1",
"jquery-ui": "1.10.5",
"lodash.throttle": "^4.1.1",
"mapbox-gl": "^0.26.0",
"moment": "^2.14.1",
"moments": "0.0.2",
Expand Down
6 changes: 6 additions & 0 deletions superset/assets/stylesheets/superset.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ span.title-block {
.nvtooltip {
//position: relative !important;
z-index: 888;
transition: opacity 0ms linear;
-moz-transition: opacity 0ms linear;
-webkit-transition: opacity 0ms linear;
transition-delay: 0ms;
-moz-transition-delay: 0ms;
-webkit-transition-delay: 0ms;
}
.nvtooltip table td{
font-size: 11px !important;
Expand Down
13 changes: 13 additions & 0 deletions superset/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import $ from 'jquery';
import { category21 } from '../javascripts/modules/colors';
import { timeFormatFactory, formatDate } from '../javascripts/modules/dates';
import { customizeToolTip } from '../javascripts/modules/utils';
import throttle from 'lodash.throttle';

const d3 = require('d3');
const nv = require('nvd3');
Expand Down Expand Up @@ -58,6 +59,10 @@ const addTotalBarValues = function (chart, data, stacked) {
});
};

function hideTooltips() {
$('.nvtooltip').css({ opacity: 0 });
}

function nvd3Vis(slice, payload) {
let chart;
let colorKey = 'key';
Expand Down Expand Up @@ -402,9 +407,17 @@ function nvd3Vis(slice, payload) {
.call(chart);
}

// on scroll, hide tooltips. throttle to only 4x/second.
$(window).scroll(throttle(hideTooltips, 250));

return chart;
};

// hide 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();

const graph = drawGraph();
nv.addGraph(graph);
}
Expand Down

0 comments on commit 543c22b

Please sign in to comment.