Skip to content

Commit

Permalink
Fixing tooltips in heatmap viz
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jun 6, 2017
1 parent 9c58511 commit 894b1cc
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions superset/assets/visualizations/heatmap.js
@@ -1,11 +1,11 @@
import d3 from 'd3';
import $ from 'jquery';
import d3tip from 'd3-tip';

import { colorScalerFactory } from '../javascripts/modules/colors';
import '../stylesheets/d3tip.css';
import './heatmap.css';

const $ = require('jquery');
d3.tip = require('d3-tip');


// Inspired from http://bl.ocks.org/mbostock/3074470
// https://jsfiddle.net/cyril123/h0reyumq/
Expand Down Expand Up @@ -106,15 +106,7 @@ function heatmapVis(slice, payload) {
.style('top', headerHeight + 'px')
.style('position', 'absolute');

const rect = svg.append('g')
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.append('rect')
.style('fill-opacity', 0)
.attr('stroke', 'black')
.attr('width', hmWidth)
.attr('height', hmHeight);

const tip = d3.tip()
const tip = d3tip()
.attr('class', 'd3-tip')
.offset(function () {
const k = d3.mouse(this);
Expand All @@ -141,6 +133,17 @@ function heatmapVis(slice, payload) {
return s;
});

const rect = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`)
.append('rect')
.attr('pointer-events', 'all')
.on('mousemove', tip.show)
.on('mouseout', tip.hide)
.style('fill-opacity', 0)
.attr('stroke', 'black')
.attr('width', hmWidth)
.attr('height', hmHeight);

rect.call(tip);

const xAxis = d3.svg.axis()
Expand Down Expand Up @@ -172,8 +175,6 @@ function heatmapVis(slice, payload) {
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.call(yAxis);

rect.on('mousemove', tip.show);
rect.on('mouseout', tip.hide);

const context = canvas.node().getContext('2d');
context.imageSmoothingEnabled = false;
Expand Down

0 comments on commit 894b1cc

Please sign in to comment.