refine semantic topic color
This commit is contained in:
@@ -10,32 +10,39 @@ export interface TopicHierarchyColorInput {
|
||||
}
|
||||
|
||||
const FIELD_HUES: Record<string, number> = {
|
||||
'agricultural and biological sciences': 127,
|
||||
'arts and humanities': 28,
|
||||
'biochemistry, genetics and molecular biology': 154,
|
||||
'business, management and accounting': 44,
|
||||
'chemical engineering': 188,
|
||||
chemistry: 174,
|
||||
'computer science': 214,
|
||||
'decision sciences': 202,
|
||||
dentistry: 348,
|
||||
'earth and planetary sciences': 112,
|
||||
'economics, econometrics and finance': 52,
|
||||
// Life Sciences: green to teal.
|
||||
'agricultural and biological sciences': 116,
|
||||
'biochemistry, genetics and molecular biology': 172,
|
||||
'immunology and microbiology': 152,
|
||||
neuroscience: 190,
|
||||
veterinary: 132,
|
||||
|
||||
// Physical Sciences: cool blues plus distinct earth/environment tones.
|
||||
'chemical engineering': 194,
|
||||
chemistry: 184,
|
||||
'computer science': 222,
|
||||
'earth and planetary sciences': 66,
|
||||
energy: 88,
|
||||
engineering: 199,
|
||||
'environmental science': 142,
|
||||
'health professions': 334,
|
||||
'immunology and microbiology': 163,
|
||||
'materials science': 258,
|
||||
mathematics: 233,
|
||||
medicine: 348,
|
||||
neuroscience: 282,
|
||||
nursing: 326,
|
||||
'pharmacology, toxicology and pharmaceutics': 5,
|
||||
'physics and astronomy': 246,
|
||||
psychology: 302,
|
||||
'social sciences': 20,
|
||||
veterinary: 135,
|
||||
engineering: 204,
|
||||
'environmental science': 96,
|
||||
'materials science': 262,
|
||||
mathematics: 238,
|
||||
'physics and astronomy': 250,
|
||||
|
||||
// Health Sciences: red, pink, and magenta.
|
||||
dentistry: 352,
|
||||
'health professions': 326,
|
||||
medicine: 342,
|
||||
nursing: 314,
|
||||
'pharmacology, toxicology and pharmaceutics': 6,
|
||||
|
||||
// Social Sciences: orange, amber, and violet.
|
||||
'arts and humanities': 282,
|
||||
'business, management and accounting': 38,
|
||||
'decision sciences': 24,
|
||||
'economics, econometrics and finance': 52,
|
||||
psychology: 296,
|
||||
'social sciences': 14,
|
||||
};
|
||||
|
||||
const DOMAIN_FALLBACK_HUES: Record<string, number> = {
|
||||
@@ -45,7 +52,30 @@ const DOMAIN_FALLBACK_HUES: Record<string, number> = {
|
||||
'social sciences': 24,
|
||||
};
|
||||
|
||||
const SUBFIELD_HUE_OFFSETS = [-18, -12, -7, -3, 3, 7, 12, 18];
|
||||
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 },
|
||||
];
|
||||
|
||||
export function topicHierarchyColor(
|
||||
topic: TopicHierarchyColorInput | undefined | null,
|
||||
@@ -72,11 +102,11 @@ export function topicHierarchyColor(
|
||||
stableHue(fieldIdentity ?? subfieldIdentity);
|
||||
|
||||
const variantHash = stableHash(subfieldIdentity);
|
||||
const offset =
|
||||
SUBFIELD_HUE_OFFSETS[variantHash % SUBFIELD_HUE_OFFSETS.length];
|
||||
const hue = normalizeHue(baseHue + offset);
|
||||
const saturation = 76 + ((variantHash >> 3) % 16);
|
||||
const lightness = 34 + ((variantHash >> 7) % 9);
|
||||
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}%)`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user