fix(ColorbarCanvas): Fix colorbar rendering issue on small window widths #1649
+3
−6
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.
Context
When the window width is small, the colorbar doesn't render properly, with the top part appearing gray instead of white.
2024-12-02.13.06.54.mov
Changes & Results
This issue seems to be caused by an incorrect
tVoiRange
value, which is calculated usingwindowWidth
. To fix this, I replaced thewindowWidth
value with a different calculation:Math.abs(voiRange.upper - voiRange.lower)
, instead of relying on thewindowWidth
provided by thetoWindowLevel
function.Initially, I suspected that the issue might originate in the
toWindowLevel
function itself, because it calculateswindowWidth
using the formulaMath.abs(high - low) + 1
. My assumption was that it should useMath.abs(high - low)
instead. However, I found this PR #736 that says this formula aligns with the DICOM standard. While I don't fully understand why the DICOM standard is like this - since it goes against my intuition - it is clear that this calculation doesn't work well for colorbar rendering.As a result, I only replaced the
windowWidth
variable with the value calculated byMath.abs(high - low)
for this specific issue.Testing
I visually confirmed that this issue has been resolved using
examples/colorbar/index.ts
.Checklist
PR
semantic-release format and guidelines.
Code
My code has been well-documented (function documentation, inline comments,
etc.)
I have run the
yarn build:update-api
to update the API documentation, and havecommitted the changes to this PR. (Read more here https://www.cornerstonejs.org/docs/contribute/update-api)
Public Documentation Updates
additions or removals.
Tested Environment