Skip to content

Commit

Permalink
revise bbox positions
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Aug 25, 2021
1 parent 6078118 commit 03b22ec
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 85 deletions.
5 changes: 0 additions & 5 deletions src/components/fx/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ exports.makeEventData = function(pt, trace, cd) {
if('yVal' in pt) out.y = pt.yVal;
else if('y' in pt) out.y = pt.y;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;
if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;
Expand Down
14 changes: 8 additions & 6 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,14 @@ function _hover(gd, evt, subplot, noHoverEvent) {
pt.hovertemplate = ht || pt.trace.hovertemplate || false;
}

var bbox = {};
if('x0' in pt) bbox.x0 = pt.x0 + pt.xa._offset + gLeft;
if('x1' in pt) bbox.x1 = pt.x1 + pt.xa._offset + gLeft;
if('y0' in pt) bbox.y0 = pt.y0 + pt.ya._offset + gTop;
if('y1' in pt) bbox.y1 = pt.y1 + pt.ya._offset + gTop;
eventData.bbox = bbox;
if(pt.xa && pt.ya) {
eventData.bbox = {
x0: pt.x0 + pt.xa._offset + gLeft,
x1: pt.x1 + pt.xa._offset + gLeft,
y0: pt.y0 + pt.ya._offset + gTop,
y1: pt.y1 + pt.ya._offset + gTop
};
}

pt.eventData = [eventData];
newhoverdata.push(eventData);
Expand Down
5 changes: 0 additions & 5 deletions src/traces/bar/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ module.exports = function eventData(out, pt, trace) {
if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

if(trace.orientation === 'h') {
out.label = out.y;
out.value = out.x;
Expand Down
5 changes: 0 additions & 5 deletions src/traces/box/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@ module.exports = function eventData(out, pt) {
if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

return out;
};
5 changes: 0 additions & 5 deletions src/traces/funnel/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ module.exports = function eventData(out, pt /* , trace, cd, pointNumber */) {
if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

return out;
};
5 changes: 0 additions & 5 deletions src/traces/histogram/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ module.exports = function eventData(out, pt, trace, cd, pointNumber) {
if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

// specific to histogram - CDFs do not have pts (yet?)
if(!(trace.cumulative || {}).enabled) {
var pts = Array.isArray(pointNumber) ?
Expand Down
6 changes: 0 additions & 6 deletions src/traces/image/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
module.exports = function eventData(out, pt) {
if('xVal' in pt) out.x = pt.xVal;
if('yVal' in pt) out.y = pt.yVal;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;
out.color = pt.color;
Expand Down
11 changes: 1 addition & 10 deletions src/traces/pie/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ module.exports = function eventData(pt, trace) {
text: pt.text,

// pt.v (and pt.i below) for backward compatibility
v: pt.v,

// TODO: These coordinates aren't quite correct and don't take into account some offset
// I still haven't quite located (similar to xa._offset)
bbox: {
x0: pt.x0,
x1: pt.x1,
y0: pt.y0,
y1: pt.y1,
},
v: pt.v
};

// Only include pointNumber if it's unambiguous
Expand Down
19 changes: 6 additions & 13 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,12 @@ function attachFxHandlers(sliceTop, gd, cd) {

if(hoverinfo === 'all') hoverinfo = 'label+text+value+percent+name';

// If hoverinfo === 'none', we still want the *coordinates* of hover to be
// output, just not the hover to actually display
var rInscribed = pt.rInscribed || 0;
var hoverCenterX = cx + pt.pxmid[0] * (1 - rInscribed);
var hoverCenterY = cy + pt.pxmid[1] * (1 - rInscribed);
pt.x0 = hoverCenterX - rInscribed * cd0.r;
pt.x1 = hoverCenterX + rInscribed * cd0.r;
pt.y0 = hoverCenterY;
pt.y1 = hoverCenterY;

// in case we dragged over the pie from another subplot,
// or if hover is turned off
if(trace2.hovertemplate || (hoverinfo !== 'none' && hoverinfo !== 'skip' && hoverinfo)) {
var rInscribed = pt.rInscribed || 0;
var hoverCenterX = cx + pt.pxmid[0] * (1 - rInscribed);
var hoverCenterY = cy + pt.pxmid[1] * (1 - rInscribed);
var separators = fullLayout2.separators;
var text = [];

Expand All @@ -413,9 +406,9 @@ function attachFxHandlers(sliceTop, gd, cd) {

Fx.loneHover({
trace: trace,
x0: pt.x0,
x1: pt.x1,
y: pt.y0,
x0: hoverCenterX - rInscribed * cd0.r,
x1: hoverCenterX + rInscribed * cd0.r,
y: hoverCenterY,
text: text.join('<br>'),
name: (trace2.hovertemplate || hoverinfo.indexOf('name') !== -1) ? trace2.name : undefined,
idealAlign: pt.pxmid[0] < 0 ? 'left' : 'right',
Expand Down
5 changes: 0 additions & 5 deletions src/traces/scattercarpet/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@ module.exports = function eventData(out, pt, trace, cd, pointNumber) {
out.b = cdi.b;
out.y = cdi.y;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

return out;
};
5 changes: 0 additions & 5 deletions src/traces/scatterternary/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ module.exports = function eventData(out, pt, trace, cd, pointNumber) {
if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

if(cd[pointNumber]) {
var cdi = cd[pointNumber];

Expand Down
5 changes: 0 additions & 5 deletions src/traces/waterfall/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ module.exports = function eventData(out, pt /* , trace, cd, pointNumber */) {
if(pt.xa) out.xaxis = pt.xa;
if(pt.ya) out.yaxis = pt.ya;

if('x0' in pt) out.x0 = pt.x0;
if('x1' in pt) out.x1 = pt.x1;
if('y0' in pt) out.y0 = pt.y0;
if('y1' in pt) out.y1 = pt.y1;

return out;
};
12 changes: 6 additions & 6 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Test click interactions:', function() {
var pt = futureData.points[0];
expect(Object.keys(pt).sort()).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'bbox', 'x0', 'x1', 'y0', 'y1',
'bbox',
'x', 'y', 'xaxis', 'yaxis'
].sort());
expect(pt.curveNumber).toEqual(0);
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Test click interactions:', function() {
var pt = futureData.points[0];
expect(Object.keys(pt).sort()).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'bbox', 'x0', 'x1', 'y0', 'y1',
'bbox',
'x', 'y', 'xaxis', 'yaxis'
].sort());
expect(pt.curveNumber).toEqual(0);
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('Test click interactions:', function() {
var pt = futureData.points[0];
expect(Object.keys(pt).sort()).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'bbox', 'x0', 'x1', 'y0', 'y1',
'bbox',
'x', 'y', 'xaxis', 'yaxis'
].sort());
expect(pt.curveNumber).toEqual(0);
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Test click interactions:', function() {
var pt = futureData.points[0];
expect(Object.keys(pt).sort()).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'bbox', 'x0', 'x1', 'y0', 'y1',
'bbox',
'x', 'y', 'xaxis', 'yaxis'
].sort());
expect(pt.curveNumber).toEqual(0);
Expand Down Expand Up @@ -347,7 +347,7 @@ describe('Test click interactions:', function() {
var pt = futureData.points[0];
expect(Object.keys(pt).sort()).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'bbox', 'x0', 'x1', 'y0', 'y1',
'bbox',
'x', 'y', 'xaxis', 'yaxis'
].sort());
expect(pt.curveNumber).toEqual(0);
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('Test click interactions:', function() {
var pt = futureData.points[0];
expect(Object.keys(pt).sort()).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'bbox', 'x0', 'x1', 'y0', 'y1',
'bbox',
'x', 'y', 'xaxis', 'yaxis'
].sort());
expect(pt.curveNumber).toEqual(0);
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/funnelarea_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ describe('funnelarea hovering', function() {

var fields = [
'curveNumber', 'pointNumber', 'pointNumbers',
'data', 'fullData', 'bbox',
'data', 'fullData',
'label', 'color', 'value',
'percent', 'text'
];
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine/tests/pie_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,9 @@ describe('pie hovering', function() {

var fields = [
'curveNumber', 'pointNumber', 'pointNumbers',
'data', 'fullData', 'bbox',
'data', 'fullData',
'label', 'color', 'value',
'i', 'v', 'percent', 'text',
'i', 'v', 'percent', 'text'
];

expect(Object.keys(hoverData.points[0]).sort()).toEqual(fields.sort());
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/ternary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
var SORTED_EVENT_KEYS = [
'data', 'fullData', 'curveNumber', 'pointNumber', 'pointIndex',
'xaxis', 'yaxis', 'a', 'b', 'c',
'bbox', 'x0', 'x1', 'y0', 'y1'
'bbox'
].sort();

describe('ternary plots', function() {
Expand Down

0 comments on commit 03b22ec

Please sign in to comment.