-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(bar): prevent outside text labels from overlapping tilted axis ticks #7872
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
Open
vizansh
wants to merge
9
commits into
plotly:master
Choose a base branch
from
vizansh:fix-bar-label-overlap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+71
−4
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dbc9a51
fix(bar): prevent outside text labels from overlapping tilted axis ticks
vizansh 8c78dd6
chore: add draftlog for bar text overlap fix
vizansh 9ea39bc
fix: add required PR link formatting to draftlog
vizansh 6b1363e
fix(bar): keep zero-value outside labels on one side
vizansh 73c8ab5
fix: export toMoveOutsideBar
vizansh a61530b
fix: rename draftlog file to match PR 7872
vizansh f291d70
refactor: apply reviewer suggestions for zeroBarDir
vizansh 33e4357
Apply suggestions from code review
vizansh a318a80
fix: remove trailing comma in export object
vizansh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Prevent outside bar text for zero-length bars from overlapping axis tick labels [[#7872](https://github.com/plotly/plotly.js/pull/7872)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -554,6 +554,7 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, op | |||||||||||||||||||
| // get trace attributes | ||||||||||||||||||||
| var trace = cd[0].trace; | ||||||||||||||||||||
| var isHorizontal = trace.orientation === 'h'; | ||||||||||||||||||||
| var zeroBarDir = getZeroBarDir(cd, isHorizontal, xa, ya); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var text = getText(fullLayout, cd, i, xa, ya); | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -707,7 +708,7 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, op | |||||||||||||||||||
| transform = toMoveOutsideBar(x0, x1, y0, y1, textBB, { | ||||||||||||||||||||
| isHorizontal: isHorizontal, | ||||||||||||||||||||
| constrained: constrained, | ||||||||||||||||||||
| angle: angle | ||||||||||||||||||||
| zeroBarDir: zeroBarDir | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| constrained = trace.constraintext === 'both' || trace.constraintext === 'inside'; | ||||||||||||||||||||
|
|
@@ -957,12 +958,17 @@ function toMoveOutsideBar(x0, x1, y0, y1, textBB, opts) { | |||||||||||||||||||
| var anchorX = 0; | ||||||||||||||||||||
| var anchorY = 0; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var dir = isHorizontal ? dirSign(x1, x0) : dirSign(y0, y1); | ||||||||||||||||||||
| var dir; | ||||||||||||||||||||
| if ((isHorizontal ? x0 === x1 : y0 === y1) && opts.zeroBarDir) { | ||||||||||||||||||||
| dir = opts.zeroBarDir; | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| dir = isHorizontal ? dirSign(x1, x0) : dirSign(y0, y1); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (isHorizontal) { | ||||||||||||||||||||
| targetX = x1 - dir * textpad; | ||||||||||||||||||||
| targetX = x1 - dir * (textpad + axisPad); | ||||||||||||||||||||
| anchorX = dir * extrapad; | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| targetY = y1 + dir * textpad; | ||||||||||||||||||||
| targetY = y1 + dir * (textpad + axisPad); | ||||||||||||||||||||
|
vizansh marked this conversation as resolved.
Comment on lines
+968
to
+971
Contributor
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.
Suggested change
Contributor
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. @vizansh I've added a new comment with the suggestion, could you apply it? The reference to |
||||||||||||||||||||
| anchorY = -dir * extrapad; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -999,6 +1005,38 @@ function getTextPosition(trace, index) { | |||||||||||||||||||
| return helpers.coerceEnumerated(attributeTextPosition, value); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function getZeroBarDir(cd, isHorizontal, xa, ya) { | ||||||||||||||||||||
| var hasPositive = false; | ||||||||||||||||||||
| var hasNegative = false; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| for (var i = 0; i < cd.length; i++) { | ||||||||||||||||||||
| var s = cd[i].s; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (s > 0) { | ||||||||||||||||||||
| hasPositive = true; | ||||||||||||||||||||
| } else if (s < 0) { | ||||||||||||||||||||
| hasNegative = true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (hasPositive && hasNegative) { | ||||||||||||||||||||
| return 0; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var axis = isHorizontal ? xa : ya; | ||||||||||||||||||||
| var positiveDir = -dirSign(axis.range[0], axis.range[1]); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!hasNegative) { | ||||||||||||||||||||
| return positiveDir; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!hasPositive) { | ||||||||||||||||||||
| return -positiveDir; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return 0; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function calcTexttemplate(fullLayout, cd, index, xa, ya) { | ||||||||||||||||||||
| var trace = cd[0].trace; | ||||||||||||||||||||
| var texttemplate = Lib.castOption(trace, index, 'texttemplate'); | ||||||||||||||||||||
|
|
||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
angleshould be added back in here. My fault, I mistakenly suggested deleting it.