Skip to content

Commit

Permalink
Return default text color if bgcolor is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverroick committed Jan 24, 2024
1 parent 9b4ae82 commit 8f0bcee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export const inViewportTopHalf = (domElement) => {
* returns a text color with high contrast relative to a given background color
*/
export const getTextColor = (bgColor) => {
if (!bgColor) {
return '$textDark';
}

const threshold = 0.6
const [red, green, blue] = [0, 2, 4].map((i) => parseInt(bgColor.slice(i + 1, i + 3), 16));
const l = (red * 0.299 + green * 0.587 + blue * 0.114) / 255;
Expand Down
2 changes: 1 addition & 1 deletion src/features/loupe/BoundingBoxLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const BoundingBoxLabel = forwardRef(({
handleCategorySelectorBlur={handleCategorySelectorBlur}
menuPlacement='bottom'
/>
<LabelDisplay css={{ display: catSelectorOpen ? 'none' : 'block', color: getTextColor(displayLabel.color) }}>
<LabelDisplay css={{ display: catSelectorOpen ? 'none' : 'block', color: getTextColor(displayLabel?.color) }}>
<Category>{displayLabel?.name || "ERROR FINDING LABEL"}</Category>
{!object.locked && <Confidence>{conf}%</Confidence>}
</LabelDisplay>
Expand Down

0 comments on commit 8f0bcee

Please sign in to comment.