-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Make hover label triangle optional #7451
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
base: master
Are you sure you want to change the base?
Changes from all commits
e746867
60f5718
db04896
63e44ab
d065217
579992e
b3258fc
23a8f8a
61d949e
7c75cd2
aac31fd
e382d2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add `layout.hoverlabel.showarrow` (and `trace.hoverlabel.showarrow`) attribute to allow hiding the triangular caret that appears on the hover label box [[#7451](https://github.com/plotly/plotly.js/pull/7451)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1922,20 +1922,30 @@ function alignHoverText(hoverLabels, rotateLabels, scaleX, scaleY) { | |
var offsetY = offsets.y; | ||
|
||
var isMiddle = anchor === 'middle'; | ||
// Get 'showarrow' attribute value from trace hoverlabel settings; | ||
// if trace has no hoverlabel settings, we should show the arrow by default | ||
var showArrow = 'hoverlabel' in d.trace ? d.trace.hoverlabel.showarrow : true; | ||
|
||
g.select('path') | ||
.attr('d', isMiddle ? | ||
var pathStr; | ||
if(isMiddle) { | ||
// middle aligned: rect centered on data | ||
('M-' + pX(d.bx / 2 + d.tx2width / 2) + ',' + pY(offsetY - d.by / 2) + | ||
'h' + pX(d.bx) + 'v' + pY(d.by) + 'h-' + pX(d.bx) + 'Z') : | ||
pathStr = 'M-' + pX(d.bx / 2 + d.tx2width / 2) + ',' + pY(offsetY - d.by / 2) + | ||
'h' + pX(d.bx) + 'v' + pY(d.by) + 'h-' + pX(d.bx) + 'Z'; | ||
} else if(showArrow) { | ||
// left or right aligned: side rect with arrow to data | ||
('M0,0L' + pX(horzSign * HOVERARROWSIZE + offsetX) + ',' + pY(HOVERARROWSIZE + offsetY) + | ||
'v' + pY(d.by / 2 - HOVERARROWSIZE) + | ||
'h' + pX(horzSign * d.bx) + | ||
'v-' + pY(d.by) + | ||
'H' + pX(horzSign * HOVERARROWSIZE + offsetX) + | ||
'V' + pY(offsetY - HOVERARROWSIZE) + | ||
'Z')); | ||
pathStr = 'M0,0L' + pX(horzSign * HOVERARROWSIZE + offsetX) + ',' + pY(HOVERARROWSIZE + offsetY) + | ||
'v' + pY(d.by / 2 - HOVERARROWSIZE) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OMG math There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gvwilson Coming up with the new SVG path string with no arrow was Claude Code's only helpful contribution to this PR (but it's a doozy, so, worth it) |
||
'h' + pX(horzSign * d.bx) + | ||
'v-' + pY(d.by) + | ||
'H' + pX(horzSign * HOVERARROWSIZE + offsetX) + | ||
'V' + pY(offsetY - HOVERARROWSIZE) + | ||
'Z'; | ||
} else { | ||
// left or right aligned: side rect without arrow | ||
pathStr = 'M' + pX(horzSign * HOVERARROWSIZE + offsetX) + ',' + pY(offsetY - d.by / 2) + | ||
'h' + pX(horzSign * d.bx) + 'v' + pY(d.by) + 'h' + pX(-horzSign * d.bx) + 'Z'; | ||
} | ||
g.select('path').attr('d', pathStr); | ||
|
||
var posX = offsetX + shiftX.textShiftX; | ||
var posY = offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be up for using a template literal here and elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could leave refactoring for another PR.
Template literal may run slower: https://jsperf.app/es6-string-literals-vs-string-concatenation/43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Slower in Chrome but not in Safari.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you seen any issues with this kind of calculation? I imagine that most computers are powerful enough where this isn't an issue.