diff --git a/webapp/src/app/shared/utils/topic-colors.ts b/webapp/src/app/shared/utils/topic-colors.ts index 7dfbfc9d..1d2b69d9 100644 --- a/webapp/src/app/shared/utils/topic-colors.ts +++ b/webapp/src/app/shared/utils/topic-colors.ts @@ -1,8 +1,6 @@ export interface TopicHierarchyColorInput { id?: string | null; name?: string | null; - subfield_id?: string | null; - subfield_name?: string | null; field_id?: string | null; field_name?: string | null; domain_id?: string | null; @@ -52,30 +50,8 @@ const DOMAIN_FALLBACK_HUES: Record = { 'social sciences': 24, }; -interface SubfieldColorVariant { - hueOffset: number; - saturation: number; - lightness: number; -} - -const SUBFIELD_COLOR_VARIANTS: readonly SubfieldColorVariant[] = [ - { hueOffset: -6, saturation: 92, lightness: 27 }, - { hueOffset: 6, saturation: 82, lightness: 48 }, - { hueOffset: -2, saturation: 90, lightness: 35 }, - { hueOffset: 7, saturation: 78, lightness: 42 }, - { hueOffset: -8, saturation: 86, lightness: 31 }, - { hueOffset: 3, saturation: 94, lightness: 24 }, - { hueOffset: 8, saturation: 84, lightness: 38 }, - { hueOffset: -4, saturation: 80, lightness: 45 }, - { hueOffset: 0, saturation: 92, lightness: 30 }, - { hueOffset: 8, saturation: 76, lightness: 50 }, - { hueOffset: -7, saturation: 88, lightness: 40 }, - { hueOffset: 4, saturation: 80, lightness: 33 }, - { hueOffset: -8, saturation: 82, lightness: 47 }, - { hueOffset: 2, saturation: 96, lightness: 26 }, - { hueOffset: 8, saturation: 86, lightness: 36 }, - { hueOffset: -2, saturation: 78, lightness: 43 }, -]; +const FIELD_COLOR_SATURATION = 86; +const FIELD_COLOR_LIGHTNESS = 36; export function topicHierarchyColor( topic: TopicHierarchyColorInput | undefined | null, @@ -86,29 +62,22 @@ export function topicHierarchyColor( const fieldKey = normalizeColorKey(topic.field_name); const domainKey = normalizeColorKey(topic.domain_name); - const fieldIdentity = - topic.field_id ?? fieldKey ?? topic.domain_id ?? domainKey; - const subfieldIdentity = - topic.subfield_id ?? - normalizeColorKey(topic.subfield_name) ?? + const fieldIdentity = topic.field_id ?? fieldKey; + const fallbackIdentity = + fieldIdentity ?? + topic.domain_id ?? + domainKey ?? topic.id ?? normalizeColorKey(topic.name) ?? - fieldIdentity ?? 'topic'; const baseHue = (fieldKey ? FIELD_HUES[fieldKey] : undefined) ?? (domainKey ? DOMAIN_FALLBACK_HUES[domainKey] : undefined) ?? - stableHue(fieldIdentity ?? subfieldIdentity); + stableHue(fallbackIdentity); + const hue = normalizeHue(baseHue); - const variantHash = stableHash(subfieldIdentity); - const variant = - SUBFIELD_COLOR_VARIANTS[variantHash % SUBFIELD_COLOR_VARIANTS.length]; - const hue = normalizeHue(baseHue + variant.hueOffset); - const saturation = variant.saturation; - const lightness = variant.lightness; - - return `hsl(${hue} ${saturation}% ${lightness}%)`; + return `hsl(${hue} ${FIELD_COLOR_SATURATION}% ${FIELD_COLOR_LIGHTNESS}%)`; } function normalizeColorKey(