@@ -47,7 +47,7 @@ module.controller('HeatmapController', function ($scope, Private) {
4747 $scope . data = null ;
4848 return ;
4949 }
50-
50+
5151 // Add row, column, and metric titles as vis parameters
5252 _ . merge ( $scope . vis . params , {
5353 rowAxis : { title : getLabel ( $scope . vis . aggs , 'rows' ) } ,
@@ -58,5 +58,53 @@ module.controller('HeatmapController', function ($scope, Private) {
5858 $scope . data = [ {
5959 cells : processTableGroups ( tabifyAggResponse ( $scope . vis , resp ) , $scope )
6060 } ] ;
61+
62+ $scope . eventListeners = {
63+ mouseover : [ mouseover ] ,
64+ mouseout : [ mouseout ]
65+ } ;
66+
67+ function mouseover ( event ) {
68+ var target = d3 . select ( event . target ) ;
69+ var isHeatmapCell = ( target . attr ( "class" ) === "cell" ) ;
70+ var OFFSET = 50 ;
71+
72+ if ( isHeatmapCell ) {
73+ // get data bound to heatmap cell
74+ var d = _ . first ( target . data ( ) ) ;
75+ // Custom code for tooltip functionality goes here
76+ $scope . $apply ( function ( ) {
77+ var params = $scope . vis . params ;
78+ $scope . tooltipItems = Object . keys ( d )
79+ . filter ( function ( key ) { return key !== "data" ; } )
80+ . map ( function ( key ) {
81+
82+ var title = d3 . selectAll ( 'text.title' ) ;
83+ var value = d [ key ] ;
84+ if ( key . toUpperCase ( ) === 'ROW' ) {
85+ key = params . columnAxis . title || 'ROW' ;
86+ }
87+ if ( key . toUpperCase ( ) === 'COL' ) {
88+ key = params . rowAxis . title || 'COL' ;
89+ }
90+ return {
91+ key : key . toUpperCase ( ) ,
92+ value : value
93+ } ;
94+ } ) ;
95+
96+ $scope . top = d . data . row + parseInt ( params . margin . top ) + OFFSET ;
97+ $scope . left = d . data . col + parseInt ( params . margin . left ) + OFFSET ;
98+ } ) ;
99+ }
100+ } ;
101+
102+ function mouseout ( event ) {
103+ $scope . $apply ( function ( ) {
104+ $scope . tooltipItems = [ ] ;
105+ $scope . top = 0 ;
106+ $scope . left = 0 ;
107+ } ) ;
108+ }
61109 } ) ;
62110} ) ;
0 commit comments