File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ module . exports = function eventData ( out , pt ) {
4+ if ( 'index' in pt ) {
5+ out . pointNumber = pt . index ;
6+ out . pointIndex = pt . index ;
7+ }
8+
9+ if ( 'zLabelVal' in pt ) {
10+ out . z = pt . zLabelVal ;
11+ } else if ( 'z' in pt ) {
12+ out . z = pt . z ;
13+ }
14+
15+ return out ;
16+ } ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports = {
88 colorbar : require ( './colorbar' ) ,
99 style : require ( './style' ) ,
1010 hoverPoints : require ( './hover' ) ,
11+ eventData : require ( './event_data' ) ,
1112
1213 moduleType : 'trace' ,
1314 name : 'heatmap' ,
Original file line number Diff line number Diff line change @@ -1114,4 +1114,48 @@ describe('heatmap hover', function() {
11141114 expect ( pt ) . toEqual ( undefined ) ;
11151115 } ) ;
11161116 } ) ;
1117+
1118+ describe ( 'heatmap event data' , function ( ) {
1119+ var gd ;
1120+
1121+ beforeEach ( function ( ) {
1122+ gd = createGraphDiv ( ) ;
1123+ } ) ;
1124+
1125+ afterEach ( destroyGraphDiv ) ;
1126+
1127+ it ( 'should include 2D pointNumber and z value in plotly_click payload' , function ( done ) {
1128+ var mockData = [ {
1129+ type : 'heatmap' ,
1130+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ] ,
1131+ x : [ 'A' , 'B' ] ,
1132+ y : [ 'Row1' , 'Row2' ]
1133+ } ] ;
1134+
1135+ Plotly . newPlot ( gd , mockData ) . then ( function ( ) {
1136+ var clickData = null ;
1137+
1138+ gd . on ( 'plotly_click' , function ( data ) {
1139+ clickData = data ;
1140+ } ) ;
1141+
1142+ var mockClick = require ( '../assets/click' ) ;
1143+ var bBox = gd . getBoundingClientRect ( ) ;
1144+
1145+ mockClick ( bBox . left + 100 , bBox . top + 300 ) ;
1146+
1147+ expect ( clickData ) . not . toBeNull ( ) ;
1148+ expect ( clickData . points . length ) . toBe ( 1 ) ;
1149+
1150+ var pt = clickData . points [ 0 ] ;
1151+
1152+ expect ( Array . isArray ( pt . pointNumber ) ) . toBe ( true , 'pointNumber should be an array' ) ;
1153+ expect ( pt . pointNumber ) . toEqual ( [ 0 , 0 ] , 'should point to the first row and col' ) ;
1154+ expect ( pt . z ) . toBe ( 1 , 'should extract the correct z value' ) ;
1155+
1156+ done ( ) ;
1157+ } ) . catch ( done . fail ) ;
1158+ } ) ;
1159+ } ) ;
11171160} ) ;
1161+
You can’t perform that action at this time.
0 commit comments