From ec277a34d518f8586d96a0251d8eedeef62ca5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 24 Feb 2017 14:34:10 -0500 Subject: [PATCH 1/3] pass calc'ed text to heatmap calcdata item - and use that to determine the text label on hover - in the case of XYZ column traces calc'3d has a different structure then fullData text, so it becomes important to use calc'ed text to hover text to work after non-do-calc interaction (e.g. zoom). --- src/traces/heatmap/calc.js | 2 +- src/traces/heatmap/hover.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/traces/heatmap/calc.js b/src/traces/heatmap/calc.js index 7b38ba77620..677209698d6 100644 --- a/src/traces/heatmap/calc.js +++ b/src/traces/heatmap/calc.js @@ -121,7 +121,7 @@ module.exports = function calc(gd, trace) { Axes.expand(ya, yArray); } - var cd0 = {x: xArray, y: yArray, z: z}; + var cd0 = {x: xArray, y: yArray, z: z, text: trace.text}; // auto-z and autocolorscale if applicable colorscaleCalc(trace, z, '', 'z'); diff --git a/src/traces/heatmap/hover.js b/src/traces/heatmap/hover.js index 89a229a4e10..d9ea27f4340 100644 --- a/src/traces/heatmap/hover.js +++ b/src/traces/heatmap/hover.js @@ -96,8 +96,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, contour) if(zmask && !zmask[ny][nx]) zVal = undefined; var text; - if(Array.isArray(trace.text) && Array.isArray(trace.text[ny])) { - text = trace.text[ny][nx]; + if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) { + text = cd0.text[ny][nx]; } return [Lib.extendFlat(pointData, { From b98f0fe4b3df310a2c0d460e66e76e205d6ba868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 24 Feb 2017 14:34:38 -0500 Subject: [PATCH 2/3] package heatmap hover per mock --- test/jasmine/tests/heatmap_test.js | 46 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/test/jasmine/tests/heatmap_test.js b/test/jasmine/tests/heatmap_test.js index 9141ff5edf1..93002d70f0e 100644 --- a/test/jasmine/tests/heatmap_test.js +++ b/test/jasmine/tests/heatmap_test.js @@ -528,19 +528,10 @@ describe('heatmap hover', function() { var gd; - beforeAll(function(done) { + beforeAll(function() { jasmine.addMatchers(customMatchers); - - gd = createGraphDiv(); - - var mock = require('@mocks/heatmap_multi-trace.json'), - mockCopy = Lib.extendDeep({}, mock); - - Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done); }); - afterAll(destroyGraphDiv); - function _hover(gd, xval, yval) { var fullLayout = gd._fullLayout, calcData = gd.calcdata, @@ -563,24 +554,39 @@ describe('heatmap hover', function() { return hoverData; } - function assertLabels(hoverPoint, xLabel, yLabel, zLabel) { + function assertLabels(hoverPoint, xLabel, yLabel, zLabel, text) { expect(hoverPoint.xLabelVal).toEqual(xLabel, 'have correct x label'); expect(hoverPoint.yLabelVal).toEqual(yLabel, 'have correct y label'); expect(hoverPoint.zLabelVal).toEqual(zLabel, 'have correct z label'); + expect(hoverPoint.text).toEqual(text, 'have correct text label'); } - it('should find closest point (case 1) and should', function() { - var pt = _hover(gd, 0.5, 0.5)[0]; + describe('for `heatmap_multi-trace`', function() { - expect(pt.index).toEqual([1, 0], 'have correct index'); - assertLabels(pt, 1, 1, 4); - }); + beforeAll(function(done) { + gd = createGraphDiv(); - it('should find closest point (case 2) and should', function() { - var pt = _hover(gd, 1.5, 0.5)[0]; + var mock = require('@mocks/heatmap_multi-trace.json'), + mockCopy = Lib.extendDeep({}, mock); - expect(pt.index).toEqual([0, 0], 'have correct index'); - assertLabels(pt, 2, 0.2, 6); + Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done); + }); + + afterAll(destroyGraphDiv); + + it('should find closest point (case 1) and should', function() { + var pt = _hover(gd, 0.5, 0.5)[0]; + + expect(pt.index).toEqual([1, 0], 'have correct index'); + assertLabels(pt, 1, 1, 4); + }); + + it('should find closest point (case 2) and should', function() { + var pt = _hover(gd, 1.5, 0.5)[0]; + + expect(pt.index).toEqual([0, 0], 'have correct index'); + assertLabels(pt, 2, 0.2, 6); + }); }); }); From 04bf73178deffc620cc905d47dbd501493f44539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 24 Feb 2017 14:34:53 -0500 Subject: [PATCH 3/3] add hover test for xyz heatmap trace --- test/jasmine/tests/heatmap_test.js | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/jasmine/tests/heatmap_test.js b/test/jasmine/tests/heatmap_test.js index 93002d70f0e..f56d6dd341f 100644 --- a/test/jasmine/tests/heatmap_test.js +++ b/test/jasmine/tests/heatmap_test.js @@ -589,4 +589,38 @@ describe('heatmap hover', function() { }); }); + describe('for xyz-column traces', function() { + + beforeAll(function(done) { + gd = createGraphDiv(); + + Plotly.plot(gd, [{ + type: 'heatmap', + x: [1, 2, 3], + y: [1, 1, 1], + z: [10, 4, 20], + text: ['a', 'b', 'c'], + hoverinfo: 'text' + }]) + .then(done); + }); + + afterAll(destroyGraphDiv); + + it('should find closest point and should', function(done) { + var pt = _hover(gd, 0.5, 0.5)[0]; + + expect(pt.index).toEqual([0, 0], 'have correct index'); + assertLabels(pt, 1, 1, 10, 'a'); + + Plotly.relayout(gd, 'xaxis.range', [1, 2]).then(function() { + var pt2 = _hover(gd, 1.5, 0.5)[0]; + + expect(pt2.index).toEqual([0, 1], 'have correct index'); + assertLabels(pt2, 2, 1, 4, 'b'); + }) + .then(done); + }); + + }); });