From c3624d1a14e96c25bbfce3d6816f1f828d503aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 17 Jan 2019 10:21:04 -0500 Subject: [PATCH] show box/violin position when hovering over pts ... instead of showing the point's position. --- src/traces/box/hover.js | 18 ++++++++++++++---- test/jasmine/tests/box_test.js | 15 +++++++++++++++ test/jasmine/tests/violin_test.js | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/traces/box/hover.js b/src/traces/box/hover.js index 05ca7310261..e2cc11969a6 100644 --- a/src/traces/box/hover.js +++ b/src/traces/box/hover.js @@ -240,15 +240,25 @@ function hoverOnPoints(pointData, xval, yval) { name: trace.name, x0: xc - rad, x1: xc + rad, - xLabelVal: pt.x, y0: yc - rad, y1: yc + rad, - yLabelVal: pt.y, spikeDistance: pointData.distance }); - var pLetter = trace.orientation === 'h' ? 'y' : 'x'; - var pa = trace.orientation === 'h' ? ya : xa; + + var pa; + if(trace.orientation === 'h') { + pa = ya; + closePtData.xLabelVal = pt.x; + closePtData.yLabelVal = di.pos; + } else { + pa = xa; + closePtData.xLabelVal = di.pos; + closePtData.yLabelVal = pt.y; + } + + var pLetter = pa._id.charAt(0); closePtData[pLetter + 'Spike'] = pa.c2p(di.pos, true); + fillHoverText(pt, trace, closePtData); return closePtData; diff --git a/test/jasmine/tests/box_test.js b/test/jasmine/tests/box_test.js index 5d15f42e0de..84c9d45c4d0 100644 --- a/test/jasmine/tests/box_test.js +++ b/test/jasmine/tests/box_test.js @@ -335,6 +335,21 @@ describe('Test box hover:', function() { '(q1: 0.5, day 2)', '(q3: 0.9, day 2)', '(median: 0.7, day 2)'], name: ['', '', '', '', '', 'carrots'], hOrder: [0, 4, 5, 1, 3, 2] + }, { + desc: 'on boxpoints with numeric positions | hovermode:closest', + mock: { + data: [{ + type: 'box', + boxpoints: 'all', + jitter: 0, + x: [2, 2, 2, 2, 2], + y: [13.1, 14.2, 14, 13, 13.3] + }], + layout: {hovermode: 'closest'} + }, + pos: [202, 335], + nums: '(2, 13.1)', + name: '' }].forEach(function(specs) { it('should generate correct hover labels ' + specs.desc, function(done) { run(specs).catch(failTest).then(done); diff --git a/test/jasmine/tests/violin_test.js b/test/jasmine/tests/violin_test.js index d4149927eb4..19d4580b74b 100644 --- a/test/jasmine/tests/violin_test.js +++ b/test/jasmine/tests/violin_test.js @@ -523,6 +523,22 @@ describe('Test violin hover:', function() { ], name: ['', '', '', '', 'kale'], hOrder: [0, 3, 4, 2, 1] + }, { + desc: 'on points with numeric positions | orientation:h | hovermode:closest', + mock: { + data: [{ + type: 'violin', + points: 'all', + jitter: 0, + orientation: 'h', + y: [2, 2, 2, 2, 2], + x: [13.1, 14.2, 14, 13, 13.3] + }], + layout: {hovermode: 'closest'} + }, + pos: [417, 309], + nums: '(14, 2)', + name: '' }] .forEach(function(specs) { it('should generate correct hover labels ' + specs.desc, function(done) {