Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix text position in centered tooltips #2154 #1

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,6 @@ function alignHoverText(hoverLabels, rotateLabels) {
tx2x = txx + alignShift * (d.txwidth + HOVERTEXTPAD),
offsetX = 0,
offsetY = d.offset;
if(d.anchor === 'middle') {
txx -= d.tx2width / 2;
tx2x -= d.tx2width / 2;
}
if(rotateLabels) {
offsetY *= -YSHIFTY;
offsetX = d.offset * YSHIFTX;
Expand Down
58 changes: 58 additions & 0 deletions test/image/mocks/centered-tooltips.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"data": [
{
"y": [
1,
2,
6,
3,
5,
6
],
"x": [
0,
1,
2,
3,
4,
5
],
"text": [
"short label",
"short label",
"Very long label named San Francisco",
"Very long label named San Francisco",
"Very long label named San Francisco"

Choose a reason for hiding this comment

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

Yep, this is one of the situations that trigger a centered label, when the text to be displayed is extra long. The other common one is a single-bar bar chart filling the whole plot area. I'm not sure we need a mock for this though, as image tests won't show hover labels - I think better would be to just generate these conditions as jasmine tests in https://github.com/plotly/plotly.js/blob/master/test/jasmine/tests/hover_label_test.js, and verify something about the label positioning/shape.

]
},
{
"y": [
6,
5,
1,
4,
1,
0
],
"x": [
0,
1,
2,
3,
4,
5
],
"text": [
"short label",
"short label",
"Very long label named San Francisco",
"Very long label named San Francisco",
"Very long label named San Francisco"
]
}
],
"layout": {
"width": 400,
"height": 300
}
}