diff --git a/webapp/src/app/modules/patent-detail/patent-detail.component.ts b/webapp/src/app/modules/patent-detail/patent-detail.component.ts index 013f39a4..fb314d3a 100644 --- a/webapp/src/app/modules/patent-detail/patent-detail.component.ts +++ b/webapp/src/app/modules/patent-detail/patent-detail.component.ts @@ -11,7 +11,10 @@ import { PatentsService } from '../../api/api/patents.service'; import { PatentEntry } from '../../api/model/patentEntry'; import { OpenAlexTopicTag } from '../../api/model/openAlexTopicTag'; import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component'; -import { topicHierarchyColor } from '../../resolvers/utils/topic-colors'; +import { + classificationSectionColor, + topicHierarchyColor, +} from '../../resolvers/utils/topic-colors'; import { ClassificationCard, ClassificationSystem, @@ -107,7 +110,7 @@ export class PatentDetailComponent implements OnInit { } sectionColor(card: ClassificationCard): string { - return topicHierarchyColor({ field_name: card.sectionName }); + return classificationSectionColor(card.sectionName ?? card.symbols[0]); } toggleClassificationExpanded(key: string): void { diff --git a/webapp/src/app/modules/patents/patents.component.ts b/webapp/src/app/modules/patents/patents.component.ts index d1c99016..bbf90d41 100644 --- a/webapp/src/app/modules/patents/patents.component.ts +++ b/webapp/src/app/modules/patents/patents.component.ts @@ -17,7 +17,10 @@ import { IpcClassification } from '../../api'; import { OpenAlexTopicTag } from '../../api/model/openAlexTopicTag'; import { TopicChipComponent } from '../../shared/ui/topic-chip/topic-chip.component'; import { LoadingComponent } from '../../shared/ui/loading/loading.component'; -import { topicHierarchyColor } from '../../resolvers/utils/topic-colors'; +import { + classificationSectionColor, + topicHierarchyColor, +} from '../../resolvers/utils/topic-colors'; type SourceFilter = 'all' | 'EPO' | 'USPTO'; @@ -404,7 +407,7 @@ export class PatentsComponent implements OnInit { } sectionColor(card: ClassificationCard): string { - return topicHierarchyColor({ field_name: card.sectionName }); + return classificationSectionColor(card.sectionName ?? card.symbols[0]); } private getClassificationLevel(entry: IpcClassification): { diff --git a/webapp/src/app/resolvers/utils/topic-colors.ts b/webapp/src/app/resolvers/utils/topic-colors.ts index 1d2b69d9..eb9b97bb 100644 --- a/webapp/src/app/resolvers/utils/topic-colors.ts +++ b/webapp/src/app/resolvers/utils/topic-colors.ts @@ -53,6 +53,29 @@ const DOMAIN_FALLBACK_HUES: Record = { const FIELD_COLOR_SATURATION = 86; const FIELD_COLOR_LIGHTNESS = 36; +// IPC/CPC section titles (e.g. "F - Mechanical engineering; Lighting; ...") +// never match the academic FIELD_HUES keys above, so they need their own +// fixed hue per section letter to avoid an effectively random hash color. +const IPC_SECTION_HUES: Record = { + A: 342, // Human Necessities (agriculture, foodstuffs, health) + B: 204, // Performing Operations; Transporting + C: 184, // Chemistry; Metallurgy + D: 262, // Textiles; Paper + E: 96, // Fixed Constructions + F: 88, // Mechanical Engineering; Lighting; Heating; Weapons; Blasting + G: 250, // Physics + H: 222, // Electricity +}; + +export function classificationSectionColor( + section: string | null | undefined, +): string { + const letter = section?.trim().charAt(0).toUpperCase(); + const hue = (letter ? IPC_SECTION_HUES[letter] : undefined) ?? stableHue(section ?? 'section'); + + return `hsl(${normalizeHue(hue)} ${FIELD_COLOR_SATURATION}% ${FIELD_COLOR_LIGHTNESS}%)`; +} + export function topicHierarchyColor( topic: TopicHierarchyColorInput | undefined | null, ): string {