8000 Add `layout.subplots` to enable (x|y) hover effects across multiple cartesian and splom suplots sharing one axis by archmoj · Pull Request #6947 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Add layout.subplots to enable (x|y) hover effects across multiple cartesian and splom suplots sharing one axis #6947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename attribute
  • Loading branch information
archmoj committed Apr 5, 2024
commit ed065172a0537ef6ce8bcde1cc6dca0bd3b28ca7
2 changes: 1 addition & 1 deletion draftlogs/6947_add.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add `layout.hoversameaxis` to enable hover effects across multiple cartesian suplots sharing one axis [[#6947](https://github.com/plotly/plotly.js/pull/6947)]
- Add `layout.hoverthrough` to enable hover effects across multiple cartesian suplots sharing one axis [[#6947](https://github.com/plotly/plotly.js/pull/6947)]
6 changes: 3 additions & 3 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
var spId;

var fullLayout = gd._fullLayout;
var hoversameaxis = fullLayout.hoversameaxis;
var hoverthrough = fullLayout.hoverthrough;
var plots = fullLayout._plots || [];
var plotinfo = plots[subplot];
var hasCartesian = fullLayout._has('cartesian');
Expand All @@ -270,7 +270,7 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
var hovermodeHasX = (hovermode || '').charAt(0) === 'x';
var hovermodeHasY = (hovermode || '').charAt(0) === 'y';

if(hoversameaxis && hasCartesian && (hovermodeHasX || hovermodeHasY)) {
if(hoverthrough && hasCartesian && (hovermodeHasX || hovermodeHasY)) {
var subplotsLength = subplots.length;
for(var p = 0; p < subplotsLength; p++) {
spId = subplots[p];
Expand Down Expand Up @@ -570,7 +570,7 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
hoverLayer: fullLayout._hoverlayer,

// options for splom when hovering on same axis
hoversameaxis: hoversameaxis,
hoverthrough: hoverthrough,
gd: gd
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/fx/hovermode_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ module.exports = function handleHoverModeDefaults(layoutIn, layoutOut) {
}

coerce('clickmode');
coerce('hoversameaxis');
coerce('hoverthrough');
return coerce('hovermode');
};
2 changes: 1 addition & 1 deletion src/components/fx/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
'If false, hover interactions are disabled.'
].join(' ')
},
hoversameaxis: {
hoverthrough: {
valType: 'boolean',
dflt: false,
editType: 'none',
Expand Down
8 changes: 4 additions & 4 deletions src/traces/splom/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function hoverPoints(pointData, xval, yval, hovermode, opts) {

var points = _hoverPoints(pointData, xpx, ypx);

if(opts.hoversameaxis && (hovermodeHasX || hovermodeHasY)) {
if(opts.hoverthrough && (hovermodeHasX || hovermodeHasY)) {
var _xpx = points[0]._xpx;
var _ypx = points[0]._ypx;

Expand Down Expand Up @@ -53,7 +53,7 @@ function hoverPoints(pointData, xval, yval, hovermode, opts) {
return points;
}

function _hoverPoints(pointData, xpx, ypx, hoversameaxisX, hoversameaxisY) {
function _hoverPoints(pointData, xpx, ypx, hoverthroughX, hoverthroughY) {
var cd = pointData.cd;
var trace = cd[0].trace;
var scene = pointData.scene;
Expand Down Expand Up @@ -83,9 +83,9 @@ function _hoverPoints(pointData, xpx, ypx, hoversameaxisX, hoversameaxisY) {
var dist = 0;

var pick = false;
if(hoversameaxisX) {
if(hoverthroughX) {
if(dx === 0) pick = true;
} else if(hoversameaxisY) {
} else if(hoverthroughY) {
if(dy === 0) pick = true;
} else {
dist = Math.sqrt(dx * dx + dy * dy);
Expand Down
18 changes: 9 additions & 9 deletions test/jasmine/tests/hover_label_test.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2380,12 +2380,12 @@ describe('hover info on stacked subplots', function() {
});
});

describe('hover on subplots when hoversameaxis is set to true and x hovermodes', function() {
describe('hover on subplots when hoverthrough is set to true and x hovermodes', function() {
'use strict';

var mock = {
layout: {
hoversameaxis: true,
hoverthrough: true,
hovermode: 'x',
grid: {
rows: 3,
Expand Down Expand Up @@ -2423,7 +2423,7 @@ describe('hover on subplots when hoversameaxis is set to true and x hovermodes',

afterEach(destroyGraphDiv);

it('hovermode: *x* | *x unified* with hoversameaxis: true', function() {
it('hovermode: *x* | *x unified* with hoverthrough: true', function() {
var pos = 0;
var subplot = 'xy';
Lib.clearThrottle();
Expand Down Expand Up @@ -2468,12 +2468,12 @@ describe('hover on subplots when hoversameaxis is set to true and x hovermodes',
});
});

describe('hover on subplots when hoversameaxis is set to true and y hovermodes', function() {
describe('hover on subplots when hoverthrough is set to true and y hovermodes', function() {
'use strict';

var mock = {
layout: {
hoversameaxis: true,
hoverthrough: true,
hovermode: 'y',
grid: {
rows: 2,
Expand Down Expand Up @@ -2511,7 +2511,7 @@ describe('hover on subplots when hoversameaxis is set to true and y hovermodes',

afterEach(destroyGraphDiv);

it('hovermode: *y* | *y unified* with hoversameaxis: true', function() {
it('hovermode: *y* | *y unified* with hoverthrough: true', function() {
var pos = 0;
var subplot = 'xy';
Lib.clearThrottle();
Expand Down Expand Up @@ -2556,12 +2556,12 @@ describe('hover on subplots when hoversameaxis is set to true and y hovermodes',
});
});

describe('splom hover on subplots when hoversameaxis is set to true and (x|y) hovermodes', function() {
describe('splom hover on subplots when hoverthrough is set to true and (x|y) hovermodes', function() {
'use strict';

var mock = Lib.extendDeep({}, splomLogMock);
mock.layout.hovermode = 'x';
mock.layout.hoversameaxis = true;
mock.layout.hoverthrough = true;

var gd;

Expand All @@ -2572,7 +2572,7 @@ describe('splom hover on subplots when hoversameaxis is set to true and (x|y) ho

afterEach(destroyGraphDiv);

it('splom hoversameaxis: true', function() {
it('splom hoverthrough: true', function() {
Lib.clearThrottle();
Plotly.Fx.hover(gd, {x: 200, y: 200}, 'xy');
expect(gd._hoverdata.length).toBe(3);
Expand Down
2 changes: 1 addition & 1 deletion test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2634,7 +2634,7 @@
"y unified"
]
},
"hoversameaxis": {
"hoverthrough": {
"description": "Determines expansion of hover effects to other subplots in case of sharing an axis. Has an effect only when `hovermode` is set to *x*, *x unified*, *y* or *y unified*.",
"dflt": false,
"editType": "none",
Expand Down
0