fix(patents): color IPC/CPC classification section chips by a fixed per-section hue instead of hashing the raw section title

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 17:24:41 +02:00
co-authored by Claude Sonnet 5
parent afeff33ea7
commit df9c102e54
3 changed files with 33 additions and 4 deletions
@@ -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 {
@@ -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): {
@@ -53,6 +53,29 @@ const DOMAIN_FALLBACK_HUES: Record<string, number> = {
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<string, number> = {
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 {