-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix the issue of labels in centre will overlap when alignLabels switc… #1702
Open
yuchuny
wants to merge
1
commit into
tradingview:master
Choose a base branch
from
GondorCapital:fix-some-labels-overlapping-when-align-labels-on
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.
+90
−0
Open
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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
85 changes: 85 additions & 0 deletions
85
tests/e2e/graphics/test-cases/price-scale/fix-labels-overlapping-when-align-labels-on.js
This file contains 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,85 @@ | ||
function runTestCase(container) { | ||
const chartOptions = { | ||
height: 500, | ||
width: 600, | ||
rightPriceScale: { | ||
scaleMargins: { | ||
top: 0, | ||
bottom: 0, | ||
}, | ||
entireTextOnly: true, | ||
alignLabels: true, | ||
}, | ||
layout: { attributionLogo: false }, | ||
}; | ||
|
||
const chart = (window.chart = LightweightCharts.createChart( | ||
container, | ||
chartOptions | ||
)); | ||
|
||
const levels = [ | ||
7.9, | ||
5.44, | ||
4.23, | ||
4.08, | ||
3.42, | ||
3.09, | ||
2.78, | ||
2.24, | ||
2.14, | ||
2.13, | ||
2.12, | ||
2.05, | ||
2.04, | ||
1.92, | ||
1.69, | ||
1.67, | ||
1.47, | ||
1.32, | ||
1.11, | ||
0.90712, | ||
0.63113, | ||
0.40527, | ||
0.20527, | ||
0.10527, | ||
0.00527, | ||
0.00027, | ||
0.00007, | ||
0.00001, | ||
].map(price => ({ price })); | ||
|
||
const colorByIndex = index => { | ||
const r = index & 0b10000 >> 4; | ||
const g = index & 0b01100 >> 2; | ||
const b = index & 0b00011; | ||
return `rgb(${Math.floor(r * 255)}, ${Math.floor(g * 255 / 4)}, ${Math.floor(b * 255 / 4)})`; | ||
}; | ||
|
||
for (let i = 0; i < levels.length; i++) { | ||
const s = chart.addLineSeries({ | ||
color: colorByIndex(i), | ||
}); | ||
s.setData([ | ||
{ time: 10000, value: levels[i].price }, | ||
{ time: 20000, value: levels[i].price }, | ||
]); | ||
levels[i].series = s; | ||
} | ||
|
||
for (let i = 0; i < 4; i++) { | ||
chart.removeSeries(levels[i].series); | ||
delete levels[i].series; | ||
} | ||
|
||
for (let i = 3; i >= 2; i--) { | ||
const s = chart.addLineSeries({ | ||
color: colorByIndex(i), | ||
}); | ||
s.setData([ | ||
{ time: 10000, value: levels[i].price }, | ||
{ time: 20000, value: levels[i].price }, | ||
]); | ||
levels[i].series = s; | ||
} | ||
} |
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.
I would prefer an implementation which isn't performing splice operations on two arrays. It should be more efficient to rather pass the item from the top array (as a reference without a splice) into the
recalculateOverlapping
function as a parameter and have therecalculateOverlapping
function know how to handle this extra parameter. This might add more complexity.Or alternatively. Earlier in the current function, we could create the
top
array, and then sort it. Then create thebottom
array and push the desired item into that, and then sort thebottom
array.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.
Well, as I remember we already had such string before. There is a risk it brokes the desired behavior on some cases