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
20 changes: 17 additions & 3 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,24 @@ function createHoverText(hoverData, opts, gd) {
}
}

var xLetter = 'x';
var yLetter = 'y';
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';
}
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';
}

if(d.zLabel !== undefined) {
if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '<br>';
if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '<br>';
text += (text ? 'z: ' : '') + d.zLabel;
if(d.xLabel !== undefined) text += xLetter + ': ' + d.xLabel + '<br>';
if(d.yLabel !== undefined) text += yLetter + ': ' + d.yLabel + '<br>';
text += (text ? zLetter + ': ' : '') + d.zLabel;
}
else if(showCommonLabel && d[hovermode + 'Label'] === t0) {
text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || '';
Expand Down
5 changes: 4 additions & 1 deletion src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,

handleCategoryOrderDefaults(containerIn, containerOut, coerce, options);

if(axType !== 'category' && !options.noHover) coerce('hoverformat');
if(axType !== 'category' && !options.noHover) {
coerce('hoverformat');
coerce('hovertitle');
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we give this a default value? By implementing something like:

coerce('hovertitle', options.dfltHoverTitle);

Each handleAxisDefaults caller would have to pass another options key, but this would make the chart editor devs (aka RCE) much happier (as the default value will be automatically filled in the RCE panels) and the logic in Fx.hover simpler.

}

if(!visible) return containerOut;

Expand Down
9 changes: 9 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,15 @@ module.exports = {
'*%H~%M~%S.%2f* would display *09~15~23.46*'
].join(' ')
},
hovertitle: {
valType: 'boolean',
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not what I had in mind.

I was thinking of making hovertitle a string that defaults to the current behavior (in v1.x, and potentially default to the axis title value in v2.x).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hovertitle is now a string instead of a boolean.
Other axis types have _hovertitle attribute. Wondering if we should change them to hovertitle?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like those _hovertitle are now obsolete. Would you mind 🔪 ing them? Thanks!

dflt: false,
role: 'info',
editType: 'none',
description: [
'Enable axis title(s) to be displayed in the hovering popup'
].join(' ')
},
// lines and grids
showline: {
valType: 'boolean',
Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/layout/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports = overrideAll({
tickformat: axesAttrs.tickformat,
tickformatstops: axesAttrs.tickformatstops,
hoverformat: axesAttrs.hoverformat,
hovertitle: axesAttrs.hovertitle,
// lines and grids
showline: axesAttrs.showline,
linecolor: axesAttrs.linecolor,
Expand Down
2 changes: 2 additions & 0 deletions src/plots/polar/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ var radialAxisAttrs = {
// might need a 'titleside' and even 'titledirection' down the road

hoverformat: axesAttrs.hoverformat,
hovertitle: axesAttrs.hovertitle,

uirevision: {
valType: 'any',
Expand Down Expand Up @@ -232,6 +233,7 @@ var angularAxisAttrs = {
},

hoverformat: axesAttrs.hoverformat,
hovertitle: axesAttrs.hovertitle,

uirevision: {
valType: 'any',
Expand Down
1 change: 1 addition & 0 deletions src/plots/ternary/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var ternaryAxesAttrs = {
tickformat: axesAttrs.tickformat,
tickformatstops: axesAttrs.tickformatstops,
hoverformat: axesAttrs.hoverformat,
hovertitle: axesAttrs.hovertitle,
// lines and grids
showline: extendFlat({}, axesAttrs.showline, {dflt: true}),
linecolor: axesAttrs.linecolor,
Expand Down
1 change: 1 addition & 0 deletions src/plots/ternary/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,6 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut
});

coerce('hoverformat');
coerce('hovertitle');
coerce('layer');
}