|
|
|
@ -22,11 +22,26 @@ export default function ConstructorViewerItem(props: ConstructorViewerItemProps)
|
|
|
|
color, label, onUpdate, onDelete,
|
|
|
|
color, label, onUpdate, onDelete,
|
|
|
|
} = props;
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const backgroundColor = color || consts.NEW_LABEL_COLOR;
|
|
|
|
|
|
|
|
let textColor = '#ffffff';
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// convert color to grayscale and from the result get better text color
|
|
|
|
|
|
|
|
// (for darken background -> lighter text, etc.)
|
|
|
|
|
|
|
|
const [r, g, b] = [backgroundColor.slice(1, 3), backgroundColor.slice(3, 5), backgroundColor.slice(5, 7)];
|
|
|
|
|
|
|
|
const grayscale = (parseInt(r, 16) + parseInt(g, 16) + parseInt(b, 16)) / 3;
|
|
|
|
|
|
|
|
if (grayscale - 128 >= 0) {
|
|
|
|
|
|
|
|
textColor = '#000000';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (_: any) {
|
|
|
|
|
|
|
|
// nothing to do
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div style={{ background: color || consts.NEW_LABEL_COLOR }} className='cvat-constructor-viewer-item'>
|
|
|
|
<div style={{ background: backgroundColor }} className='cvat-constructor-viewer-item'>
|
|
|
|
<Text>{label.name}</Text>
|
|
|
|
<Text style={{ color: textColor }}>{label.name}</Text>
|
|
|
|
<CVATTooltip title='Update attributes'>
|
|
|
|
<CVATTooltip title='Update attributes'>
|
|
|
|
<span
|
|
|
|
<span
|
|
|
|
|
|
|
|
style={{ color: textColor }}
|
|
|
|
role='button'
|
|
|
|
role='button'
|
|
|
|
tabIndex={0}
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={(): void => onUpdate(label)}
|
|
|
|
onClick={(): void => onUpdate(label)}
|
|
|
|
@ -37,6 +52,7 @@ export default function ConstructorViewerItem(props: ConstructorViewerItemProps)
|
|
|
|
</CVATTooltip>
|
|
|
|
</CVATTooltip>
|
|
|
|
<CVATTooltip title='Delete label'>
|
|
|
|
<CVATTooltip title='Delete label'>
|
|
|
|
<span
|
|
|
|
<span
|
|
|
|
|
|
|
|
style={{ color: textColor }}
|
|
|
|
role='button'
|
|
|
|
role='button'
|
|
|
|
tabIndex={0}
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={(): void => onDelete(label)}
|
|
|
|
onClick={(): void => onDelete(label)}
|
|
|
|
|