Skip to content

Axis labels could be applied in the hovering popup #3317

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

Closed
wants to merge 12 commits into from
28 changes: 23 additions & 5 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var Registry = require('../../registry');
var helpers = require('./helpers');
var constants = require('./constants');

var majorVerion = require('../../core').version.split('.')[0];

// hover labels for multiple horizontal bars get tilted by some angle,
// then need to be offset differently if they overlap
var YANGLE = constants.YANGLE;
Expand Down Expand Up @@ -939,13 +941,29 @@ function createHoverText(hoverData, opts, gd) {
var zLetter = 'z';

if(gd._fullLayout.scene) {
if(gd._fullLayout.scene.xaxis.hovertitle) xLetter = gd._fullLayout.scene.xaxis.title.text || 'x';
if(gd._fullLayout.scene.yaxis.hovertitle) yLetter = gd._fullLayout.scene.yaxis.title.text || 'y';
if(gd._fullLayout.scene.zaxis.hovertitle) zLetter = gd._fullLayout.scene.zaxis.title.text || 'z';
xLetter = (majorVerion < 2) ? 'x' :
gd._fullLayout.scene.xaxis.title.text || 'x';
yLetter = (majorVerion < 2) ? 'y' :
gd._fullLayout.scene.yaxis.title.text || 'y';
zLetter = (majorVerion < 2) ? 'z' :
gd._fullLayout.scene.zaxis.title.text || 'z';
xLetter = (gd._fullLayout.scene.xaxis.hovertitle === '') ? xLetter :
gd._fullLayout.scene.xaxis.hovertitle || xLetter;
yLetter = (gd._fullLayout.scene.yaxis.hovertitle === '') ? yLetter :
gd._fullLayout.scene.yaxis.hovertitle || yLetter;
zLetter = (gd._fullLayout.scene.zaxis.hovertitle === '') ? zLetter :
gd._fullLayout.scene.zaxis.hovertitle || zLetter;
}
else if(!gd._fullLayout.ternary && !gd._fullLayout.title) {
if(gd._fullLayout.xaxis.hovertitle) xLetter = gd._fullLayout.xaxis.title.text || 'x';
if(gd._fullLayout.yaxis.hovertitle) yLetter = gd._fullLayout.yaxis.title.text || 'y';
xLetter = (majorVerion < 2) ? 'x' :
gd._fullLayout.xaxis.title.text || 'x';
yLetter = (majorVerion < 2) ? 'y' :
gd._fullLayout.yaxis.title.text || 'y';

xLetter = (gd._fullLayout.xaxis.hovertitle === '') ? xLetter :
gd._fullLayout.xaxis.hovertitle || xLetter;
yLetter = (gd._fullLayout.yaxis.hovertitle === '') ? yLetter :
gd._fullLayout.yaxis.hovertitle || yLetter;
}

if(d.zLabel !== undefined) {
Expand Down
6 changes: 3 additions & 3 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,12 @@ module.exports = {
].join(' ')
},
hovertitle: {
valType: 'boolean',
dflt: false,
valType: 'string',
dflt: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line. The hovertitle default isn't blank. As it depends on which axis where coercing, we can't declare a default value here, so the best thing we can do is to not declare any default value.

role: 'info',
editType: 'none',
description: [
'Enable axis title(s) to be displayed in the hovering popup'
'Sets axis title(s) to be displayed in the hovering popup'
].join(' ')
},
// lines and grids
Expand Down
53 changes: 42 additions & 11 deletions test/image/mocks/gl3d_surface_after_heatmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,59 @@
"data": [
{
"type": "heatmap",
"x": [0, 1, 2],
"y": [0, 1, 2],
"x": [0, 1, 2, 3, 4],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you patch this mock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a new mock added quite recently. I thought we could expand a bit to allow interactivelytesting hovertitle on gl3d & gl2d.

"y": [0, 1, 2, 3, 4],
"z": [
[0, 1, 0],
[1, 0, 1],
[0, 1, 0]
[0, 1, 0, 1, 0],
[1, 0.25, 0.75, 0.25, 1],
[0, 0.75, 0.25, 0.75, 0],
[1, 0.25, 0.75, 0.25, 1],
[0, 1, 0, 1, 0]
]
},
{
"type": "surface",
"x": [0, 1, 2],
"y": [0, 1, 2],
"x": [0, 1, 2, 3, 4],
"y": [0, 1, 2, 3, 4],
"z": [
[0, 1, 0],
[1, 0, 1],
[0, 1, 0]
[0, 1, 0, 1, 0],
[1, 0.25, 0.75, 0.25, 1],
[0, 0.75, 0.25, 0.75, 0],
[1, 0.25, 0.75, 0.25, 1],
[0, 1, 0, 1, 0]
]
}
],
"layout": {
"title": "Surface 3d plot on top of 2d heatmap!",
"width": 600,
"height": 400
"height": 400,
"scene": {
"xaxis": {
"hovertitle": "lon",
"title": {
"text": "Longitude"
}
},
"yaxis": {
"hovertitle": "lat",
"title": {
"text": "Latitiue"
}
},
"zaxis": {
"hovertitle": "alt",
"title": {
"text": "Altitude"
}
},
"camera": {
"eye": {
"x": 2,
"y": 2,
"z": 2
}
}
}
}
}