fix(echarts): align research and company charts with dark mode
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Roman
2026-08-02 00:34:31 +02:00
parent 9ef1ce7ce1
commit 4f116d3ca2
11 changed files with 274 additions and 236 deletions
@@ -16,11 +16,10 @@ NO_STORE_PATH_PREFIXES = (
"/api/background-jobs",
"/api/bookmarks",
"/api/organizations",
"/api/dashboard",
"/api/rank/rank-author",
"/api/rank/orientation-profiles",
"/api/works/v2/classification/",
)
"/api/dashboard",
"/api/rank/orientation-profiles",
"/api/works/v2/classification/",
)
NO_STORE_PATH_FRAGMENTS = (
"/company-connections",
@@ -3,7 +3,6 @@ import { EChartsOption } from 'echarts';
import { NgxEchartsDirective } from 'ngx-echarts';
import { WorkPrimaryCategory } from '../../../api';
import { ChartThemeService } from '../../../shared/services/chart-theme.service';
import { SUBFIELD_COLORS } from '../compare-authors-colors';
export interface AuthorCategoryLegendItem {
category: WorkPrimaryCategory;
@@ -11,44 +10,49 @@ export interface AuthorCategoryLegendItem {
color: string;
}
const categoryLegendItem = (
category: WorkPrimaryCategory,
label: string,
color: string,
): AuthorCategoryLegendItem => ({
category,
label,
color,
});
interface AuthorCategoryDefinition {
category: WorkPrimaryCategory;
label: string;
colorIndex: number;
}
export const AUTHOR_CATEGORY_LEGEND: readonly AuthorCategoryLegendItem[] = [
categoryLegendItem(
WorkPrimaryCategory.BasicResearch,
'Grundlagenforschung',
SUBFIELD_COLORS[0],
),
categoryLegendItem(
WorkPrimaryCategory.AppliedResearch,
'Anwendungsbasierte Forschung',
SUBFIELD_COLORS[1],
),
categoryLegendItem(
WorkPrimaryCategory.ExperimentalDevelopment,
'Experimentelle Entwicklung',
SUBFIELD_COLORS[2],
),
categoryLegendItem(
WorkPrimaryCategory.NonResearch,
'Nicht-forschende Tätigkeit',
SUBFIELD_COLORS[3],
),
categoryLegendItem(
WorkPrimaryCategory.NotClassified,
'Nicht klassifiziert',
SUBFIELD_COLORS[4],
),
const CATEGORY_DEFINITIONS: readonly AuthorCategoryDefinition[] = [
{
category: WorkPrimaryCategory.BasicResearch,
label: 'Grundlagenforschung',
colorIndex: 0,
},
{
category: WorkPrimaryCategory.AppliedResearch,
label: 'Anwendungsbasierte Forschung',
colorIndex: 1,
},
{
category: WorkPrimaryCategory.ExperimentalDevelopment,
label: 'Experimentelle Entwicklung',
colorIndex: 2,
},
{
category: WorkPrimaryCategory.NonResearch,
label: 'Nicht-forschende Tätigkeit',
colorIndex: 3,
},
{
category: WorkPrimaryCategory.NotClassified,
label: 'Nicht klassifiziert',
colorIndex: 4,
},
];
export const buildAuthorCategoryLegend = (
palette: readonly string[],
): readonly AuthorCategoryLegendItem[] =>
CATEGORY_DEFINITIONS.map(({ category, label, colorIndex }) => ({
category,
label,
color: palette[colorIndex],
}));
@Component({
selector: 'app-author-category-pie',
standalone: true,
@@ -85,46 +89,18 @@ export class AuthorCategoryPieComponent {
const colors = this.chartTheme.colors();
const textColor = colors.text;
const mutedColor = colors.mutedTextColor;
const tooltipBg = colors.cardBg;
const tooltipBorder = colors.splitLine;
const palette = colors.subfieldColors;
const categoryLegend: readonly AuthorCategoryLegendItem[] = [
categoryLegendItem(
WorkPrimaryCategory.BasicResearch,
'Grundlagenforschung',
palette[0],
),
categoryLegendItem(
WorkPrimaryCategory.AppliedResearch,
'Anwendungsbasierte Forschung',
palette[1],
),
categoryLegendItem(
WorkPrimaryCategory.ExperimentalDevelopment,
'Experimentelle Entwicklung',
palette[2],
),
categoryLegendItem(
WorkPrimaryCategory.NonResearch,
'Nicht-forschende Tätigkeit',
palette[3],
),
categoryLegendItem(
WorkPrimaryCategory.NotClassified,
'Nicht klassifiziert',
palette[4],
),
];
const categoryLegend = buildAuthorCategoryLegend(palette);
return {
animation: false,
tooltip: {
trigger: 'item',
confine: true,
formatter: '{b}: {c} Publikationen ({d} %)',
backgroundColor: tooltipBg,
borderColor: tooltipBorder,
textStyle: { color: textColor },
backgroundColor: colors.tooltipBg,
borderColor: colors.tooltipBorder,
textStyle: { color: colors.tooltipTextColor },
},
graphic: {
type: 'text',
@@ -43,7 +43,7 @@
</div>
<mat-chip-set class="category-legend" aria-label="Forschungskategorien">
@for (item of categoryLegend; track item.category) {
@for (item of categoryLegend(); track item.category) {
<mat-chip class="legend-chip" [style.--legend-color]="item.color">
<span class="legend-color" [style.background]="item.color"></span>
{{ item.label }}
@@ -76,12 +76,7 @@
[score]="view.profile.orientation_score ?? null" />
@if (hasLowScoreSample(view.profile)) {
<mat-card
appearance="outlined"
class="warning-note"
[style.--warning-border]="lowSampleTokens.border"
[style.--warning-background]="lowSampleTokens.background"
[style.--warning-text]="lowSampleTokens.color">
<mat-card appearance="outlined" class="warning-note">
<span>Geringe Datengrundlage</span>
<mat-icon
class="info-icon"
@@ -166,10 +166,10 @@ section {
min-height: 42px;
margin-top: 12px;
padding: 9px 12px;
border-color: var(--warning-border);
border-color: var(--sg-banner-warning-border);
border-radius: 12px;
background: var(--warning-background);
color: var(--warning-text);
background: var(--sg-banner-warning-bg);
color: var(--sg-banner-warning-text);
box-shadow: none;
font-size: 13px;
line-height: 1.4;
@@ -1,4 +1,4 @@
import { Component, computed, input } from '@angular/core';
import { Component, computed, inject, input } from '@angular/core';
import { MatCardModule } from '@angular/material/card';
import { MatChipsModule } from '@angular/material/chips';
import { MatDividerModule } from '@angular/material/divider';
@@ -8,11 +8,11 @@ import {
AuthorOrientationProfile,
AuthorOrientationProfileStatus,
} from '../../../api';
import { ChartThemeService } from '../../../shared/services/chart-theme.service';
import { OrientationGaugeComponent } from '../../../shared/ui/orientation-gauge/orientation-gauge.component';
import { topicChipColorTokens } from '../../../shared/ui/topic-chip/topic-chip.component';
import {
AUTHOR_CATEGORY_LEGEND,
AuthorCategoryPieComponent,
buildAuthorCategoryLegend,
} from './author-category-pie.component';
export interface ResearchProfileAuthor {
@@ -27,7 +27,6 @@ interface AuthorOrientationView {
}
const LOW_SAMPLE_MAX_WORKS = 4;
const LOW_SAMPLE_TOKENS = topicChipColorTokens('orange');
@Component({
selector: 'app-author-research-profile',
@@ -45,11 +44,14 @@ const LOW_SAMPLE_TOKENS = topicChipColorTokens('orange');
styleUrl: './author-research-profile.component.scss',
})
export class AuthorResearchProfileComponent {
private readonly chartTheme = inject(ChartThemeService);
authors = input.required<ResearchProfileAuthor[]>();
profiles = input.required<AuthorOrientationProfile[]>();
loading = input(false);
readonly categoryLegend = AUTHOR_CATEGORY_LEGEND;
readonly lowSampleTokens = LOW_SAMPLE_TOKENS;
readonly categoryLegend = computed(() =>
buildAuthorCategoryLegend(this.chartTheme.colors().subfieldColors),
);
readonly views = computed<AuthorOrientationView[]>(() => {
const profilesById = new Map(
@@ -1,11 +1,14 @@
$marked-color: var(--sg-blue-highlight);
$related-person-color: var(--sg-primary);
$timeline-purple: var(--sg-warning);
$timeline-purple-bg: var(--sg-warning-soft);
$timeline-orange-bg: var(--sg-warning-soft);
$timeline-orange-border: var(--sg-warning);
$timeline-orange-text: var(--sg-warning);
$related-person-color: var(--sg-blue-highlight);
$info-color: var(--sg-blue-highlight);
$info-bg: color-mix(
in srgb,
var(--sg-blue-highlight) 8%,
var(--sg-color-mix-base)
);
$warning-bg: var(--sg-banner-warning-bg);
$warning-border: var(--sg-banner-warning-border);
$warning-text: var(--sg-banner-warning-text);
$card-border: var(--sg-border);
$text-main: var(--sg-text);
@@ -79,10 +82,10 @@ $text-muted: var(--sg-text-muted);
.warning-box {
padding: 12px 14px;
border: 1px solid $timeline-orange-border;
border: 1px solid $warning-border;
border-radius: 12px;
background: $timeline-orange-bg;
color: $timeline-orange-text;
background: $warning-bg;
color: $warning-text;
font-size: 14px;
line-height: 1.45;
}
@@ -142,7 +145,11 @@ $text-muted: var(--sg-text-muted);
}
.graph-related-persons-button:hover {
background: var(--sg-primary-soft);
background: color-mix(
in srgb,
var(--sg-blue-highlight) 10%,
var(--sg-color-mix-base)
);
}
.graph-related-persons-icon {
@@ -222,9 +229,9 @@ $text-muted: var(--sg-text-muted);
flex: 0 0 auto;
margin: 14px 0 0;
padding: 12px 14px;
border-left: 3px solid $timeline-purple;
border-left: 3px solid $info-color;
border-radius: 8px;
background: $timeline-purple-bg;
background: $info-bg;
color: $text-muted;
font-size: 13px;
line-height: 1.45;
@@ -6,6 +6,7 @@ import {
OnInit,
QueryList,
ViewChildren,
effect,
inject,
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
@@ -25,12 +26,20 @@ import {
MatchedOfficer,
} from '../../api';
import { PersonDataResolved } from '../../resolvers/person.resolver';
import { ChartThemeService } from '../../shared/services/chart-theme.service';
interface RoleLegendItem {
role: string;
color: string;
}
interface GraphSymbols {
person: string;
activeCompany: string;
removedCompany: string;
registerPerson: string;
}
@Component({
selector: 'app-person-company-connections',
imports: [
@@ -53,6 +62,7 @@ export class PersonCompanyConnectionsComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
private readonly locationStrategy = inject(LocationStrategy);
private readonly companyConnectionsApi = inject(CompanyConnectionsService);
private readonly chartTheme = inject(ChartThemeService);
private readonly graphCompanyLimit = 10;
@@ -66,35 +76,13 @@ export class PersonCompanyConnectionsComponent implements OnInit {
private readonly removedCompanyCategoryName = 'Gelöschtes Unternehmen';
private readonly registerPersonCategoryName = 'Registerperson';
private readonly authorColor = '#7255d9';
private readonly companyActiveColor = '#39a96b';
private readonly companyRemovedColor = '#8a95b3';
private readonly relatedPersonColor = '#4f8df5';
private readonly fallbackRoleColor = '#8a95b3';
private readonly personIconSymbol = this.createAccountCircleSymbol(
this.authorColor,
);
private readonly registerPersonIconSymbol = this.createAccountCircleSymbol(
this.relatedPersonColor,
);
private readonly activeCompanyIconSymbol = this.createApartmentSymbol(
this.companyActiveColor,
);
private readonly removedCompanyIconSymbol = this.createApartmentSymbol(
this.companyRemovedColor,
);
private readonly roleColors: Record<string, string> = {
Geschäftsführer: '#2678e8',
Prokurist: '#39a96b',
'Persönlich haftender Gesellschafter': '#7255d9',
Liquidator: '#f59e0b',
Inhaber: '#e0527c',
Vorstand: '#0f766e',
private readonly roleColorIndexes: Record<string, number> = {
Geschäftsführer: 0,
Prokurist: 1,
'Persönlich haftender Gesellschafter': 3,
Liquidator: 2,
Inhaber: 5,
Vorstand: 4,
};
readonly disclaimer =
@@ -114,6 +102,15 @@ export class PersonCompanyConnectionsComponent implements OnInit {
@ViewChildren('connectionRow', { read: ElementRef })
private connectionRows!: QueryList<ElementRef<HTMLElement>>;
constructor() {
effect(() => {
this.chartTheme.colors();
if (this.data) {
this.refreshGraph();
}
});
}
get connections(): CompanyConnection[] {
return this.data?.connections ?? [];
}
@@ -222,11 +219,11 @@ export class PersonCompanyConnectionsComponent implements OnInit {
}
getRoleColor(role?: string | null): string {
if (!role) {
return this.fallbackRoleColor;
}
return this.roleColors[role] ?? this.fallbackRoleColor;
const theme = this.chartTheme.colors();
const colorIndex = role ? this.roleColorIndexes[role] : undefined;
return colorIndex === undefined
? theme.mutedTextColor
: theme.subfieldColors[colorIndex % theme.subfieldColors.length];
}
isCompanySelected(connection: CompanyConnection): boolean {
@@ -351,6 +348,26 @@ export class PersonCompanyConnectionsComponent implements OnInit {
return null;
}
const theme = this.chartTheme.colors();
const authorColor = theme.subfieldColors[3];
const companyActiveColor = theme.success;
const companyRemovedColor = theme.mutedTextColor;
const relatedPersonColor = theme.blueHighlight;
const graphSymbols: GraphSymbols = {
person: this.createAccountCircleSymbol(authorColor, theme.cardBg),
activeCompany: this.createApartmentSymbol(
companyActiveColor,
theme.cardBg,
),
removedCompany: this.createApartmentSymbol(
companyRemovedColor,
theme.cardBg,
),
registerPerson: this.createAccountCircleSymbol(
relatedPersonColor,
theme.cardBg,
),
};
const graphConnections = connections.slice(0, this.graphCompanyLimit);
this.roleLegendItems = this.createRoleLegendItems(graphConnections);
@@ -362,17 +379,17 @@ export class PersonCompanyConnectionsComponent implements OnInit {
id: personNodeId,
name: response.display_name || 'Person',
category: this.personCategoryIndex,
symbol: this.personIconSymbol,
symbol: graphSymbols.person,
symbolSize: 42,
symbolKeepAspect: true,
itemStyle: {
color: this.authorColor,
color: authorColor,
},
label: {
show: true,
position: 'bottom',
fontWeight: 700,
color: 'var(--sg-text)',
color: theme.text,
},
},
];
@@ -390,17 +407,17 @@ export class PersonCompanyConnectionsComponent implements OnInit {
? this.removedCompanyCategoryIndex
: this.activeCompanyCategoryIndex,
symbol: isRemoved
? this.removedCompanyIconSymbol
: this.activeCompanyIconSymbol,
? graphSymbols.removedCompany
: graphSymbols.activeCompany,
symbolSize: 44,
symbolKeepAspect: true,
itemStyle: {
color: isRemoved ? this.companyRemovedColor : this.companyActiveColor,
color: isRemoved ? companyRemovedColor : companyActiveColor,
},
label: {
show: true,
position: 'bottom',
color: 'var(--sg-text)',
color: theme.text,
width: 125,
overflow: 'truncate',
},
@@ -434,16 +451,16 @@ export class PersonCompanyConnectionsComponent implements OnInit {
searchName: relatedOfficer.name,
role: relatedRole,
category: this.registerPersonCategoryIndex,
symbol: this.registerPersonIconSymbol,
symbol: graphSymbols.registerPerson,
symbolSize: 30,
symbolKeepAspect: true,
itemStyle: {
color: this.relatedPersonColor,
color: relatedPersonColor,
},
label: {
show: true,
position: 'bottom',
color: 'var(--sg-text)',
color: theme.text,
width: 110,
overflow: 'truncate',
fontSize: 11,
@@ -476,7 +493,7 @@ export class PersonCompanyConnectionsComponent implements OnInit {
bottom: 64,
data: nodes,
links,
categories: this.createGraphCategories(),
categories: this.createGraphCategories(graphSymbols),
force: {
repulsion: this.showRelatedPersons ? 760 : 620,
edgeLength: this.showRelatedPersons ? 145 : 170,
@@ -497,7 +514,7 @@ export class PersonCompanyConnectionsComponent implements OnInit {
return {
legend: {
data: this.createNodeLegendData(graphConnections),
data: this.createNodeLegendData(graphConnections, graphSymbols),
bottom: 8,
left: 'center',
orient: 'horizontal',
@@ -506,13 +523,17 @@ export class PersonCompanyConnectionsComponent implements OnInit {
itemHeight: 20,
selectedMode: false,
textStyle: {
color: 'var(--sg-text-muted)',
color: theme.mutedTextColor,
fontSize: 13,
fontWeight: 500,
},
},
tooltip: {
trigger: 'item',
confine: true,
backgroundColor: theme.tooltipBg,
borderColor: theme.tooltipBorder,
textStyle: { color: theme.tooltipTextColor },
formatter: (params: any) => {
if (params.dataType === 'node') {
if (params.data?.category === this.registerPersonCategoryIndex) {
@@ -537,28 +558,31 @@ export class PersonCompanyConnectionsComponent implements OnInit {
} as EChartsOption;
}
private createGraphCategories(): any[] {
private createGraphCategories(symbols: GraphSymbols): any[] {
return [
{
name: this.personCategoryName,
symbol: this.personIconSymbol,
symbol: symbols.person,
},
{
name: this.activeCompanyCategoryName,
symbol: this.activeCompanyIconSymbol,
symbol: symbols.activeCompany,
},
{
name: this.removedCompanyCategoryName,
symbol: this.removedCompanyIconSymbol,
symbol: symbols.removedCompany,
},
{
name: this.registerPersonCategoryName,
symbol: this.registerPersonIconSymbol,
symbol: symbols.registerPerson,
},
];
}
private createNodeLegendData(connections: CompanyConnection[]): any[] {
private createNodeLegendData(
connections: CompanyConnection[],
symbols: GraphSymbols,
): any[] {
const hasActiveCompany = connections.some(
(connection) => connection.company_status !== 'removed',
);
@@ -569,28 +593,28 @@ export class PersonCompanyConnectionsComponent implements OnInit {
const legendData = [
{
name: this.personCategoryName,
icon: this.personIconSymbol,
icon: symbols.person,
},
];
if (hasActiveCompany) {
legendData.push({
name: this.activeCompanyCategoryName,
icon: this.activeCompanyIconSymbol,
icon: symbols.activeCompany,
});
}
if (hasRemovedCompany) {
legendData.push({
name: this.removedCompanyCategoryName,
icon: this.removedCompanyIconSymbol,
icon: symbols.removedCompany,
});
}
if (this.showRelatedPersons) {
legendData.push({
name: this.registerPersonCategoryName,
icon: this.registerPersonIconSymbol,
icon: symbols.registerPerson,
});
}
@@ -681,7 +705,10 @@ export class PersonCompanyConnectionsComponent implements OnInit {
});
}
private createAccountCircleSymbol(color: string): string {
private createAccountCircleSymbol(
color: string,
backgroundColor: string,
): string {
const backgroundPath =
'M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z';
@@ -690,7 +717,7 @@ export class PersonCompanyConnectionsComponent implements OnInit {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="${backgroundPath}" fill="#fff"/>
<path d="${backgroundPath}" fill="${backgroundColor}"/>
<path d="${foregroundPath}" fill="${color}"/>
</svg>
`;
@@ -698,7 +725,10 @@ export class PersonCompanyConnectionsComponent implements OnInit {
return this.toSvgImageSymbol(svg);
}
private createApartmentSymbol(color: string): string {
private createApartmentSymbol(
color: string,
backgroundColor: string,
): string {
const backgroundPath = 'M17 11V3H7v4H3v14h18V11h-4z';
const foregroundPath =
@@ -706,7 +736,7 @@ export class PersonCompanyConnectionsComponent implements OnInit {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="${backgroundPath}" fill="#fff"/>
<path d="${backgroundPath}" fill="${backgroundColor}"/>
<path d="${foregroundPath}" fill="${color}"/>
</svg>
`;
@@ -57,14 +57,8 @@
<mat-card
appearance="outlined"
class="warning-note"
[style.--warning-border]="
confidenceWarningTokens(profile.confidence).border
"
[style.--warning-background]="
confidenceWarningTokens(profile.confidence).background
"
[style.--warning-text]="
confidenceWarningTokens(profile.confidence).color
[class.warning-note--low-confidence]="
profile.confidence === 'low'
">
<span>{{ confidenceLabel(profile.confidence) }}</span>
<mat-icon
@@ -79,12 +73,7 @@
}
@if (profile.insufficient_context) {
<mat-card
appearance="outlined"
class="warning-note"
[style.--warning-border]="warningTokens.border"
[style.--warning-background]="warningTokens.background"
[style.--warning-text]="warningTokens.color">
<mat-card appearance="outlined" class="warning-note">
<span>Begrenzte Informationsgrundlage</span>
<mat-icon
class="info-icon"
@@ -120,15 +120,21 @@ mat-card-content {
gap: 10px;
min-height: 42px;
padding: 9px 12px;
border-color: var(--warning-border);
border-color: var(--sg-banner-warning-border);
border-radius: 12px;
background: var(--warning-background);
color: var(--warning-text);
background: var(--sg-banner-warning-bg);
color: var(--sg-banner-warning-text);
box-shadow: none;
font-size: 13px;
line-height: 1.4;
}
.warning-note--low-confidence {
border-color: var(--sg-error);
background: var(--sg-error-soft);
color: var(--sg-error);
}
.warning-note .info-icon {
flex: 0 0 auto;
width: 16px;
@@ -18,12 +18,9 @@ import {
WorkPrimaryCategory,
} from '../../../api';
import { WorkPrimaryCategoryPipe } from '../../../shared/pipes/work-primary-category.pipe';
import { ChartThemeService } from '../../../shared/services/chart-theme.service';
import { OrientationGaugeComponent } from '../../../shared/ui/orientation-gauge/orientation-gauge.component';
import {
TopicChipComponent,
TopicChipPaletteColor,
topicChipColorTokens,
} from '../../../shared/ui/topic-chip/topic-chip.component';
import { TopicChipComponent } from '../../../shared/ui/topic-chip/topic-chip.component';
type PasteurQuadrant =
| 'pure_basic'
@@ -69,10 +66,6 @@ const QUADRANTS: readonly QuadrantDefinition[] = [
},
];
const BLUE_TOKENS = topicChipColorTokens('blue');
const WARNING_TOKENS = topicChipColorTokens('orange');
const LOW_CONFIDENCE_TOKENS = topicChipColorTokens('pink');
@Component({
selector: 'app-research-profile',
standalone: true,
@@ -91,11 +84,11 @@ const LOW_CONFIDENCE_TOKENS = topicChipColorTokens('pink');
})
export class ResearchProfileComponent {
private readonly destroyRef = inject(DestroyRef);
private readonly chartTheme = inject(ChartThemeService);
private readonly quadrantChartSize = signal({ width: 640, height: 320 });
private quadrantResizeObserver?: ResizeObserver;
workClassification = input.required<WorkClassification | null>();
readonly warningTokens = WARNING_TOKENS;
details = computed<WorkClassificationDetails | null>(() => {
const details = this.workClassification()?.classification;
@@ -112,16 +105,17 @@ export class ResearchProfileComponent {
this.buildQuadrantOptions(this.details()?.pasteur_quadrant),
);
primaryCategoryChipColor = computed<TopicChipPaletteColor>(() => {
primaryCategoryChipColor = computed<string>(() => {
const colors = this.chartTheme.colors();
switch (this.details()?.primary_category) {
case WorkPrimaryCategory.BasicResearch:
return 'green';
return colors.subfieldColors[1];
case WorkPrimaryCategory.AppliedResearch:
return 'pink';
return colors.subfieldColors[5];
case WorkPrimaryCategory.ExperimentalDevelopment:
return 'purple';
return colors.subfieldColors[4];
default:
return 'orange';
return colors.mutedTextColor;
}
});
@@ -135,10 +129,6 @@ export class ResearchProfileComponent {
: 'Das Klassifikationsergebnis wurde mit mittlerer Konfidenz bestimmt.';
}
confidenceWarningTokens(confidence: string | null | undefined) {
return confidence === 'low' ? LOW_CONFIDENCE_TOKENS : WARNING_TOKENS;
}
onQuadrantChartInit(chart: EChartsType): void {
const updateSize = (width: number, height: number) => {
const current = this.quadrantChartSize();
@@ -165,14 +155,26 @@ export class ResearchProfileComponent {
private buildQuadrantOptions(
activeQuadrant: string | null | undefined,
): EChartsOption {
const textColor = this.cssColor('--sg-text-muted', BLUE_TOKENS.color);
const inactiveColor = this.cssColor(
'--sg-surface-muted',
BLUE_TOKENS.background,
const theme = this.chartTheme.colors();
const textColor = theme.mutedTextColor;
const inactiveColor = theme.tooltipBg;
const surfaceColor = theme.cardBg;
const axisColor = theme.text;
const quadrantColors = {
blue: theme.subfieldColors[0],
purple: theme.subfieldColors[3],
green: theme.subfieldColors[1],
} as const;
const activeBackgrounds = {
blue: this.mixHexColors(quadrantColors.blue, surfaceColor, 0.28),
purple: this.mixHexColors(quadrantColors.purple, surfaceColor, 0.28),
green: this.mixHexColors(quadrantColors.green, surfaceColor, 0.28),
} as const;
const neutralActiveColor = this.mixHexColors(
theme.mutedTextColor,
surfaceColor,
0.22,
);
const neutralActiveColor = this.cssColor('--sg-border', BLUE_TOKENS.border);
const surfaceColor = this.cssColor('--sg-surface', 'white');
const axisColor = this.cssColor('--sg-text', BLUE_TOKENS.color);
const { width: chartWidth, height: chartHeight } = this.quadrantChartSize();
const axisLeft = 59;
const axisTop = 12;
@@ -189,12 +191,9 @@ export class ResearchProfileComponent {
dimension: 2,
pieces: [
{ value: 0, color: inactiveColor },
{ value: 1, color: topicChipColorTokens('blue').activeBackground },
{
value: 2,
color: topicChipColorTokens('purple').activeBackground,
},
{ value: 3, color: topicChipColorTokens('green').activeBackground },
{ value: 1, color: activeBackgrounds.blue },
{ value: 2, color: activeBackgrounds.purple },
{ value: 3, color: activeBackgrounds.green },
{ value: 4, color: neutralActiveColor },
],
},
@@ -306,9 +305,9 @@ export class ResearchProfileComponent {
emphasis: { disabled: true },
data: QUADRANTS.map((quadrant) => {
const active = quadrant.key === activeQuadrant;
const activeTokens = quadrant.color
? topicChipColorTokens(quadrant.color)
: BLUE_TOKENS;
const activeColor = quadrant.color
? quadrantColors[quadrant.color]
: theme.mutedTextColor;
const activeColorValue = quadrant.color
? ({ blue: 1, purple: 2, green: 3 } as const)[quadrant.color]
: 4;
@@ -321,7 +320,7 @@ export class ResearchProfileComponent {
},
label: {
show: true,
color: active ? activeTokens.color : textColor,
color: active ? activeColor : textColor,
fontSize: 11,
lineHeight: 16,
fontWeight: 400,
@@ -332,21 +331,21 @@ export class ResearchProfileComponent {
].join('\n'),
rich: {
title: {
color: active ? activeTokens.color : textColor,
color: active ? activeColor : textColor,
fontSize: 13,
fontWeight: 700,
lineHeight: 19,
},
description: {
color: active ? activeTokens.color : textColor,
color: active ? activeColor : textColor,
fontSize: 11,
fontWeight: 400,
lineHeight: 16,
},
active: {
color: activeTokens.color,
color: activeColor,
backgroundColor: surfaceColor,
borderColor: activeTokens.color,
borderColor: activeColor,
borderWidth: 1,
borderRadius: 11,
padding: [5, 10, 2, 10],
@@ -365,14 +364,25 @@ export class ResearchProfileComponent {
};
}
private cssColor(variable: string, fallback: string): string {
if (typeof getComputedStyle !== 'function') {
return fallback;
}
return (
getComputedStyle(document.documentElement)
.getPropertyValue(variable)
.trim() || fallback
private mixHexColors(
foreground: string,
background: string,
foregroundWeight: number,
): string {
const parse = (color: string) => {
const hex = color.replace('#', '');
return [0, 2, 4].map((offset) =>
Number.parseInt(hex.slice(offset, offset + 2), 16),
);
};
const foregroundRgb = parse(foreground);
const backgroundRgb = parse(background);
const mixed = foregroundRgb.map((channel, index) =>
Math.round(
channel * foregroundWeight +
backgroundRgb[index] * (1 - foregroundWeight),
),
);
return `#${mixed.map((channel) => channel.toString(16).padStart(2, '0')).join('')}`;
}
}
@@ -2,9 +2,6 @@ import { Component, computed, inject, input } from '@angular/core';
import { EChartsOption } from 'echarts';
import { NgxEchartsDirective } from 'ngx-echarts';
import { ChartThemeService } from '../../services/chart-theme.service';
import { topicChipColorTokens } from '../topic-chip/topic-chip.component';
const BLUE_TOKENS = topicChipColorTokens('blue');
@Component({
selector: 'app-orientation-gauge',
@@ -21,8 +18,13 @@ export class OrientationGaugeComponent {
readonly options = computed<EChartsOption>(() => {
const score = this.score();
const boundedScore = score === null ? 0 : Math.max(0, Math.min(100, score));
const textColor = this.chartTheme.colors().text;
const trackColor = BLUE_TOKENS.background;
const theme = this.chartTheme.colors();
const progressColor = theme.blueHighlight;
const trackColor = this.mixHexColors(
progressColor,
theme.cardBg,
this.chartTheme.isDark() ? 0.14 : 0.09,
);
return {
animation: false,
@@ -38,7 +40,7 @@ export class OrientationGaugeComponent {
progress: {
show: score !== null,
width: 13,
itemStyle: { color: BLUE_TOKENS.color },
itemStyle: { color: progressColor },
},
axisLine: {
lineStyle: { width: 13, color: [[1, trackColor]] },
@@ -52,7 +54,7 @@ export class OrientationGaugeComponent {
detail: {
valueAnimation: false,
offsetCenter: [0, '-8%'],
color: textColor,
color: theme.text,
fontSize: 25,
fontWeight: 700,
formatter: score === null ? '–' : '{value}',
@@ -62,4 +64,26 @@ export class OrientationGaugeComponent {
],
};
});
private mixHexColors(
foreground: string,
background: string,
foregroundWeight: number,
): string {
const parse = (color: string) => {
const hex = color.replace('#', '');
return [0, 2, 4].map((offset) =>
Number.parseInt(hex.slice(offset, offset + 2), 16),
);
};
const foregroundRgb = parse(foreground);
const backgroundRgb = parse(background);
const mixed = foregroundRgb.map((channel, index) =>
Math.round(
channel * foregroundWeight +
backgroundRgb[index] * (1 - foregroundWeight),
),
);
return `#${mixed.map((channel) => channel.toString(16).padStart(2, '0')).join('')}`;
}
}