added optional parameters to topic chip to get the correct hue for hsl conversion (required by ECharts). Changed components to adapt the new color
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
+40
-17
@@ -8,7 +8,10 @@ import { CommonModule } from '@angular/common';
|
||||
import { EChartsOption } from 'echarts';
|
||||
import { NgxEchartsDirective } from 'ngx-echarts';
|
||||
import { TrendResponse } from '../../../api';
|
||||
import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors';
|
||||
import {
|
||||
topicHierarchyColor,
|
||||
TopicColorVariant,
|
||||
} from '../../../resolvers/utils/topic-colors';
|
||||
|
||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
||||
|
||||
@@ -25,7 +28,8 @@ export class UniPieChartComponent {
|
||||
readonly entityName = input<string | null>(null);
|
||||
readonly startYear = input<number>(2010);
|
||||
readonly endYear = input<number>(2025);
|
||||
readonly getTopicColor = input<(topic: string) => string>();
|
||||
readonly getTopicColor =
|
||||
input<(topic: string, variant?: TopicColorVariant) => string>();
|
||||
|
||||
// Inputs for direct rendering (useful for overall top 10 topics chart)
|
||||
readonly titleText = input<string | null>(null);
|
||||
@@ -33,15 +37,18 @@ export class UniPieChartComponent {
|
||||
readonly loading = input<boolean>(false);
|
||||
readonly error = input<boolean>(false);
|
||||
|
||||
private resolveTopicColor(topic: string): string {
|
||||
private resolveTopicColorTokens(topic: string) {
|
||||
if (topic === 'Andere Themen') {
|
||||
return '#9ca3af'; // gray for "Other" topics
|
||||
return { color: 'hsl(214, 20%, 93%)', border: 'hsl(214, 20%, 80%)' };
|
||||
}
|
||||
const customResolver = this.getTopicColor();
|
||||
if (customResolver) {
|
||||
return customResolver(topic);
|
||||
}
|
||||
return topicHierarchyColor({ name: topic });
|
||||
const bgColor = customResolver
|
||||
? customResolver(topic, 'bg')
|
||||
: topicHierarchyColor({ name: topic }, 'bg');
|
||||
const border = customResolver
|
||||
? customResolver(topic, 'border')
|
||||
: topicHierarchyColor({ name: topic }, 'border');
|
||||
return { color: bgColor, border };
|
||||
}
|
||||
|
||||
readonly chartOptions = computed<EChartsOption>(() => {
|
||||
@@ -79,13 +86,19 @@ export class UniPieChartComponent {
|
||||
// 3. If direct pieData input is provided, use it
|
||||
const directData = this.pieData();
|
||||
if (directData !== null) {
|
||||
pieDataList = directData.map((item) => ({
|
||||
value: item.value,
|
||||
name: item.name,
|
||||
itemStyle: {
|
||||
color: this.resolveTopicColor(item.name),
|
||||
},
|
||||
}));
|
||||
pieDataList = directData.map((item) => {
|
||||
const tokens = this.resolveTopicColorTokens(item.name);
|
||||
return {
|
||||
value: item.value,
|
||||
name: item.name,
|
||||
itemStyle: {
|
||||
color: tokens.color,
|
||||
opacity: 0.95,
|
||||
borderColor: tokens.border,
|
||||
borderWidth: 1.5,
|
||||
},
|
||||
};
|
||||
});
|
||||
title = this.titleText() ?? 'Themenverteilung';
|
||||
} else {
|
||||
// Otherwise, filter and extract from TrendResponse
|
||||
@@ -125,11 +138,15 @@ export class UniPieChartComponent {
|
||||
const totalRaw = filtered.reduce((sum, item) => sum + item.raw, 0);
|
||||
|
||||
if (totalRaw > 0) {
|
||||
const tokens = this.resolveTopicColorTokens(topicName);
|
||||
pieDataList.push({
|
||||
value: totalRaw,
|
||||
name: topicName,
|
||||
itemStyle: {
|
||||
color: this.resolveTopicColor(topicName),
|
||||
color: tokens.color,
|
||||
opacity: 0.95,
|
||||
borderColor: tokens.border,
|
||||
borderWidth: 1.5,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -199,11 +216,17 @@ export class UniPieChartComponent {
|
||||
smooth: true,
|
||||
},
|
||||
emphasis: {
|
||||
scale: true,
|
||||
scaleSize: 6,
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.2)',
|
||||
},
|
||||
label: {
|
||||
show: true,
|
||||
fontSize: 10,
|
||||
fontWeight: 'bold',
|
||||
formatter: '{b}\n{c} ({d}%)',
|
||||
},
|
||||
},
|
||||
data: pieDataList,
|
||||
|
||||
+12
-7
@@ -79,9 +79,13 @@ export class UniTrendChartComponent {
|
||||
|
||||
// Build series: Line in top grid, growth volume bars and S-Curve in bottom grid
|
||||
trendData.series.forEach((entity, entityIdx) => {
|
||||
const color = getFn
|
||||
const rawColor = getFn
|
||||
? getFn(entity.entity_id)
|
||||
: entityColors[entityIdx % entityColors.length];
|
||||
const color = rawColor.replace(
|
||||
/hsl\(\s*([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)%\s+([+-]?\d+(?:\.\d+)?)%\s*\)/gi,
|
||||
'hsl($1, $2%, $3%)',
|
||||
);
|
||||
if ((entity as any).visible === false) {
|
||||
return;
|
||||
}
|
||||
@@ -97,16 +101,13 @@ export class UniTrendChartComponent {
|
||||
return currentMode === 'normalized' ? yrData.normalized : yrData.raw;
|
||||
});
|
||||
|
||||
const isStacked = currentMode === 'total' || currentMode === 'cumulative';
|
||||
|
||||
series.push({
|
||||
name: `${entity.entity_name}`,
|
||||
type: 'line',
|
||||
xAxisIndex: 0,
|
||||
yAxisIndex: 0,
|
||||
stack: isStacked ? 'Total' : undefined,
|
||||
areaStyle: {
|
||||
opacity: isStacked ? 0.3 : 0.12,
|
||||
opacity: 0.12,
|
||||
},
|
||||
data: lineData,
|
||||
smooth: true,
|
||||
@@ -142,7 +143,7 @@ export class UniTrendChartComponent {
|
||||
yAxisIndex: 1,
|
||||
data: bars,
|
||||
itemStyle: {
|
||||
color: color, // Takes the color of the institution!
|
||||
color: color,
|
||||
},
|
||||
markLine:
|
||||
entityIdx === 0
|
||||
@@ -202,9 +203,13 @@ export class UniTrendChartComponent {
|
||||
res += `<div style="max-height: 280px; overflow-y: auto; padding-right: 6px;">`;
|
||||
|
||||
trendData.series.forEach((entity: TrendSeries, entityIdx: number) => {
|
||||
const color = getFn
|
||||
const rawColor = getFn
|
||||
? getFn(entity.entity_id)
|
||||
: entityColors[entityIdx % entityColors.length];
|
||||
const color = rawColor.replace(
|
||||
/hsl\(\s*([+-]?\d+(?:\.\d+)?)\s+([+-]?\d+(?:\.\d+)?)%\s+([+-]?\d+(?:\.\d+)?)%\s*\)/gi,
|
||||
'hsl($1, $2%, $3%)',
|
||||
);
|
||||
if ((entity as any).visible === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
+50
-14
@@ -48,7 +48,10 @@ import {
|
||||
} from '../../../api';
|
||||
import { CredentialService } from '../../../shared/services/credential.service';
|
||||
import { TopicChipComponent } from '../../../shared/ui/topic-chip/topic-chip.component';
|
||||
import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors';
|
||||
import {
|
||||
topicHierarchyColor,
|
||||
TopicColorVariant,
|
||||
} from '../../../resolvers/utils/topic-colors';
|
||||
import { YearRangeSliderComponent } from '../../../shared/ui/year-range-slider/year-range-slider.component';
|
||||
import { LocationSelectorComponent } from '../../../shared/ui/location-selector/location-selector.component';
|
||||
import { InstitutionSelectorComponent } from '../../../shared/ui/institution-selector/institution-selector.component';
|
||||
@@ -260,36 +263,61 @@ export class UniTrendParentComponent implements OnInit {
|
||||
return topicOrKeyword;
|
||||
}
|
||||
|
||||
getTopicColor(topic: string): string {
|
||||
getTopicColor(topic: string, variant: TopicColorVariant = 'base'): string {
|
||||
const mapped = this.getMappedTopic(topic);
|
||||
const entries = this.state?.selectedKeywordEntries() ?? [];
|
||||
const ext = this.state?.extractedKeywords() ?? [];
|
||||
const man = this.state?.manualKeywords() ?? [];
|
||||
const topicsList = this.state?.topics() ?? [];
|
||||
const all = [...entries, ...ext, ...man];
|
||||
|
||||
const targetLower = topic.toLowerCase().trim();
|
||||
const mappedLower = mapped.toLowerCase().trim();
|
||||
|
||||
const topicObj = topicsList.find(
|
||||
(t) =>
|
||||
t.display_name?.toLowerCase().trim() === mappedLower ||
|
||||
t.display_name?.toLowerCase().trim() === targetLower ||
|
||||
t.id?.toLowerCase().trim() === targetLower,
|
||||
);
|
||||
if (topicObj) {
|
||||
return topicHierarchyColor(
|
||||
{
|
||||
name: topicObj.display_name,
|
||||
field_name: topicObj.field?.display_name,
|
||||
domain_name: topicObj.domain?.display_name,
|
||||
field_id: topicObj.field?.id,
|
||||
domain_id: topicObj.domain?.id,
|
||||
id: topicObj.id,
|
||||
},
|
||||
variant,
|
||||
);
|
||||
}
|
||||
|
||||
const match = all.find(
|
||||
(e) =>
|
||||
e.topic_mapping?.topic?.display_name?.toLowerCase().trim() ===
|
||||
mappedLower ||
|
||||
e.topic_mapping?.topic?.display_name?.toLowerCase().trim() ===
|
||||
targetLower ||
|
||||
e.llm_keyword?.keyword?.toLowerCase().trim() === targetLower,
|
||||
e.llm_keyword?.keyword?.toLowerCase().trim() === targetLower ||
|
||||
e.llm_keyword?.keyword?.toLowerCase().trim() === mappedLower,
|
||||
);
|
||||
|
||||
if (match && match.topic_mapping?.topic) {
|
||||
return topicHierarchyColor({
|
||||
name: match.topic_mapping.topic.display_name,
|
||||
field_name: match.topic_mapping.topic.field?.display_name,
|
||||
domain_name: match.topic_mapping.topic.domain?.display_name,
|
||||
field_id: match.topic_mapping.topic.field?.id,
|
||||
domain_id: match.topic_mapping.topic.domain?.id,
|
||||
id: match.topic_mapping.topic.id,
|
||||
});
|
||||
return topicHierarchyColor(
|
||||
{
|
||||
name: match.topic_mapping.topic.display_name,
|
||||
field_name: match.topic_mapping.topic.field?.display_name,
|
||||
domain_name: match.topic_mapping.topic.domain?.display_name,
|
||||
field_id: match.topic_mapping.topic.field?.id,
|
||||
domain_id: match.topic_mapping.topic.domain?.id,
|
||||
id: match.topic_mapping.topic.id,
|
||||
},
|
||||
variant,
|
||||
);
|
||||
}
|
||||
return topicHierarchyColor({ name: mapped });
|
||||
return topicHierarchyColor({ name: mapped }, variant);
|
||||
}
|
||||
|
||||
readonly boundGetTopicColor = this.getTopicColor.bind(this);
|
||||
@@ -788,8 +816,16 @@ export class UniTrendParentComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
|
||||
// Preserve existing keys as well
|
||||
Object.assign(newTopicData, s.topic_data);
|
||||
// Preserve extra keys only if they are not raw URIs
|
||||
Object.entries(s.topic_data).forEach(([rk, val]) => {
|
||||
if (
|
||||
!rk.startsWith('http://') &&
|
||||
!rk.startsWith('https://') &&
|
||||
!newTopicData[rk]
|
||||
) {
|
||||
newTopicData[rk] = val;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
...s,
|
||||
|
||||
@@ -78,10 +78,15 @@ export function classificationSectionColor(
|
||||
return `hsl(${normalizeHue(hue)} ${FIELD_COLOR_SATURATION}% ${FIELD_COLOR_LIGHTNESS}%)`;
|
||||
}
|
||||
|
||||
export type TopicColorVariant = 'base' | 'bg' | 'border';
|
||||
|
||||
export function topicHierarchyColor(
|
||||
topic: TopicHierarchyColorInput | undefined | null,
|
||||
variant: TopicColorVariant = 'base',
|
||||
): string {
|
||||
if (!topic) {
|
||||
if (variant === 'bg') return 'hsl(214, 80%, 95%)';
|
||||
if (variant === 'border') return 'hsl(214, 60%, 85%)';
|
||||
return 'hsl(214 82% 42%)';
|
||||
}
|
||||
|
||||
@@ -102,7 +107,14 @@ export function topicHierarchyColor(
|
||||
stableHue(fallbackIdentity);
|
||||
const hue = normalizeHue(baseHue);
|
||||
|
||||
return `hsl(${hue} ${FIELD_COLOR_SATURATION}% ${FIELD_COLOR_LIGHTNESS}%)`;
|
||||
if (variant === 'bg') {
|
||||
return `hsl(${hue}, 75%, 80%)`;
|
||||
}
|
||||
if (variant === 'border') {
|
||||
return `hsl(${hue}, 60%, 65%)`;
|
||||
}
|
||||
|
||||
return `hsl(${hue}, ${FIELD_COLOR_SATURATION}%, ${FIELD_COLOR_LIGHTNESS}%)`;
|
||||
}
|
||||
|
||||
function normalizeColorKey(
|
||||
|
||||
@@ -36,7 +36,7 @@ interface TreemapBreadcrumb {
|
||||
styleUrl: './topic-treemap.component.scss',
|
||||
})
|
||||
export class TopicTreemapComponent implements OnChanges {
|
||||
private readonly fieldColorOpacity = 0.78;
|
||||
private readonly fieldColorOpacity = 0.95;
|
||||
@Input() data?: TopicTreemapData;
|
||||
@Input() loading = false;
|
||||
@Input() selectedNodeId?: string;
|
||||
@@ -103,10 +103,13 @@ export class TopicTreemapComponent implements OnChanges {
|
||||
private buildOptions(): EChartsOption {
|
||||
const fields = this.data?.fields ?? [];
|
||||
const hierarchyData = fields.map((field) => {
|
||||
const fieldColor = topicHierarchyColor({
|
||||
field_id: field.id,
|
||||
field_name: field.name,
|
||||
});
|
||||
const fieldColor = topicHierarchyColor(
|
||||
{
|
||||
field_id: field.id,
|
||||
field_name: field.name,
|
||||
},
|
||||
'bg',
|
||||
);
|
||||
|
||||
return {
|
||||
id: `field:${field.id}`,
|
||||
|
||||
Reference in New Issue
Block a user