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

Issue 46. fix mouse-over pop-up message causing unexpected window resize #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 31 additions & 7 deletions public/lib/heatmap_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,64 @@ module.controller('HeatmapController', function ($scope, Private) {

$scope.eventListeners = {
mouseover: [ mouseover ],
mouseout: [ mouseout ]
mouseout: [ mouseout ],
mousemove: [ mousemove ]
};

function mouseover(event) {
mousemove(event);
};

function mousemove(event){
var target = d3.select(event.target);
var isHeatmapCell = (target.attr("class") === "cell");
var OFFSET = 50;

if (isHeatmapCell) {
// get data bound to heatmap cell
var d = _.first(target.data());
// Custom code for tooltip functionality goes here
$scope.$apply(function () {
var params = $scope.vis.params;

$scope.tooltipItems = Object.keys(d)
.filter(function (key) { return key !== "data"; })
.map(function (key) {

var title = d3.selectAll('text.title');
var value = d[key];
if (key.toUpperCase() === 'ROW') {

if (key.toUpperCase() === 'ROW'){
key = params.columnAxis.title || 'ROW';
}
if (key.toUpperCase() === 'COL') {

if (key.toUpperCase() === 'COL'){
key = params.rowAxis.title || 'COL';
}

return {
key: key.toUpperCase(),
value: value
};
});

$scope.top = d.data.row + parseInt(params.margin.top) + OFFSET;
$scope.left = d.data.col + parseInt(params.margin.left) + OFFSET;

var svgParent = $(".parent");
var tooltip = $('.heatmap-tooltip');
var width = event.clientX + tooltip.width();
var height = event.clientY + tooltip.height();
var top = event.pageY - svgParent.offset().top;
var left = event.pageX - svgParent.offset().left;

if ($(window).width() < width){
$scope.left = left - tooltip.width() / 2;
}else{
$scope.left = left;
}

if ($(window).height() < height){
$scope.top = top - tooltip.height();
}else{
$scope.top = top;
}
});
}
};
Expand Down