You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
874 B

2 years ago
2 years ago
2 years ago
2 years ago
  1. export const idealColor = function (hexString) {
  2. // W3c offers a formula for calculating ideal color:
  3. // https://www.w3.org/TR/AERT/#color-contrast
  4. const r = parseInt(hexString.substr(1, 2), 16)
  5. const g = parseInt(hexString.substr(3, 2), 16)
  6. const b = parseInt(hexString.substr(5, 2), 16)
  7. return (r * 299 + g * 587 + b * 114) / 1000 < 128 ? '#ffffff' : '#000000'
  8. }
  9. export const translatedRoles = function (roles, mappings) {
  10. roles.forEach((role) => {
  11. role.translatedName = translateRole(role.name, mappings)
  12. })
  13. return roles
  14. }
  15. export const translateRole = function (role, mappings) {
  16. if (role === 'project_admin') {
  17. return mappings.projectAdmin
  18. } else if (role === 'annotator') {
  19. return mappings.annotator
  20. } else if (role === 'annotation_approver') {
  21. return mappings.annotationApprover
  22. } else {
  23. return mappings.undefined
  24. }
  25. }