diff --git a/service/src/main/inse/dashboard/service.py b/service/src/main/inse/dashboard/service.py index 39bf6f91..5df7eb3e 100644 --- a/service/src/main/inse/dashboard/service.py +++ b/service/src/main/inse/dashboard/service.py @@ -36,18 +36,6 @@ TOPIC_HEATMAP_YEARS = 5 WorksPeriod = Literal["all_time", "last_5_years"] logger = logging.getLogger(__name__) -DFG_INSTITUTION_FIELDS = [ - "Antragstellende Institution", - "Mitantragstellende Institution", - "Beteiligte Einrichtung", - "Beteiligte Hochschule", - "Beteiligte Institution", - "IGK-Partnerinstitution", - "Partnerorganisation", - "Unternehmen", -] - - def _total(response: dict[str, Any]) -> int: total = response.get("hits", {}).get("total", 0) if isinstance(total, dict): @@ -249,7 +237,7 @@ async def get_dashboard_dfg_projects( normalized_id = _normalize_institution_id(institution_id) aliases = await _institution_aliases(normalized_id, organization_name) response = await elasticsearch.search( - index=ESIndex.PROJECTS_DFG_ALL, + index=ESIndex.DFG_PROJECTS_V2, query=_dfg_institution_query(aliases), size=0, track_total_hits=True, @@ -317,8 +305,42 @@ def _dfg_institution_query(aliases: list[str]) -> dict[str, Any]: return { "bool": { "should": [ - _alias_match_query(field, aliases) - for field in DFG_INSTITUTION_FIELDS + { + "nested": { + "path": "institutions", + "query": { + "bool": { + "should": [ + _alias_match_query( + "institutions.institute_name_de", aliases + ), + _alias_match_query( + "institutions.institute_name_en", aliases + ), + ], + "minimum_should_match": 1, + } + }, + } + }, + { + "nested": { + "path": "persons", + "query": { + "bool": { + "should": [ + _alias_match_query( + "persons.affiliation_de", aliases + ), + _alias_match_query( + "persons.affiliation_en", aliases + ), + ], + "minimum_should_match": 1, + } + }, + } + }, ], "minimum_should_match": 1, } diff --git a/service/src/main/inse/dashboard/test_service.py b/service/src/main/inse/dashboard/test_service.py index 12c74d02..cec617e8 100644 --- a/service/src/main/inse/dashboard/test_service.py +++ b/service/src/main/inse/dashboard/test_service.py @@ -58,20 +58,25 @@ async def test_dashboard_statistics_counts_organization_data_and_all_projects(): "bmbf_projects": 5, } calls = mocked_search.await_args_list - assert calls[0].kwargs["index"] == config.settings.openalex_works_search_index - assert calls[0].kwargs["query"]["nested"]["query"]["term"] == { + calls_by_index = {call.kwargs["index"]: call for call in calls} + works_call = calls_by_index[config.settings.openalex_works_search_index] + authors_call = calls_by_index[ESIndex.OPENALEX_AUTHORS] + eu_call = calls_by_index[ESIndex.CORDIS_EU_ORGANIZATIONS_WILDCARD] + bmbf_call = calls_by_index[ESIndex.PROJECTS_BUND_V1] + dfg_call = calls_by_index[ESIndex.DFG_PROJECTS_V2] + assert works_call.kwargs["query"]["nested"]["query"]["term"] == { "authorships.institutions.id": ORG_INSTITUTION_ID } - assert calls[1].kwargs["query"]["nested"]["query"]["term"] == { - "affiliations.institution.id": ORG_INSTITUTION_ID + assert authors_call.kwargs["query"]["bool"]["should"][0]["bool"]["filter"][ + 0 + ]["nested"]["query"]["match_phrase"] == { + "last_known_institutions.id": ORG_INSTITUTION_ID } - assert all(call.kwargs["cluster"] == ESCluster.INSE for call in calls[2:]) - assert [call.kwargs["index"] for call in calls[2:]] == [ - ESIndex.CORDIS_EU_ORGANIZATIONS_WILDCARD, - ESIndex.PROJECTS_BUND_V1, - ESIndex.PROJECTS_DFG_ALL, - ] - assert calls[2].kwargs["body"]["query"] == { + assert all( + call.kwargs["cluster"] == ESCluster.INSE + for call in [eu_call, bmbf_call, dfg_call] + ) + assert eu_call.kwargs["body"]["query"] == { "terms": { "name.keyword": [ "EXAMPLE ORG", @@ -80,22 +85,25 @@ async def test_dashboard_statistics_counts_organization_data_and_all_projects(): ] } } - assert calls[3].kwargs["query"]["bool"]["minimum_should_match"] == 1 - assert calls[3].kwargs["query"]["bool"]["should"][0]["match"] == { + assert bmbf_call.kwargs["query"]["bool"]["minimum_should_match"] == 1 + assert bmbf_call.kwargs["query"]["bool"]["should"][0]["match"] == { "Zuwendungsempfänger": { "query": "Example Org", "operator": "and", } } - assert calls[4].kwargs["query"]["bool"]["minimum_should_match"] == 1 - assert calls[4].kwargs["query"]["bool"]["should"][0]["bool"]["should"][0][ - "match" - ] == { - "Antragstellende Institution": { + dfg_query = dfg_call.kwargs["query"] + assert dfg_query["bool"]["minimum_should_match"] == 1 + assert dfg_query["bool"]["should"][0]["nested"]["path"] == "institutions" + assert dfg_query["bool"]["should"][0]["nested"]["query"]["bool"]["should"][ + 0 + ]["bool"]["should"][0]["match"] == { + "institutions.institute_name_de": { "query": "Example Org", "operator": "and", } } + assert dfg_query["bool"]["should"][1]["nested"]["path"] == "persons" @pytest.mark.anyio @@ -181,7 +189,7 @@ async def test_top_authors_maps_works_patents_and_news_without_project_queries() call for call in mocked_search.await_args_list if call.kwargs["index"] - in {ESIndex.PROJECTS_DFG_ALL, ESIndex.PROJECTS_BUND_V1} + in {ESIndex.DFG_PROJECTS_V2, ESIndex.PROJECTS_BUND_V1} ] assert project_calls == [] eu_calls = [ diff --git a/service/src/main/inse/integrations/elasticsearch.py b/service/src/main/inse/integrations/elasticsearch.py index b58065cf..77afd124 100644 --- a/service/src/main/inse/integrations/elasticsearch.py +++ b/service/src/main/inse/integrations/elasticsearch.py @@ -101,6 +101,7 @@ def _index_to_cluster(index: ESIndex) -> Optional[ESCluster]: ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD, ESIndex.PROJECTS_BUND_V1, ESIndex.PROJECTS_DFG_ALL, + ESIndex.DFG_PROJECTS_V2, }: return ESCluster.INSE else: diff --git a/service/src/main/inse/model.py b/service/src/main/inse/model.py index a417cb81..5265720b 100644 --- a/service/src/main/inse/model.py +++ b/service/src/main/inse/model.py @@ -61,6 +61,7 @@ class ESIndex(StrEnum): PROJECTS_BUND_V1 = "projects_bund_v1" PROJECTS_DFG_ALL = "projects_dfg_all" + DFG_PROJECTS_V2 = "dfg_projects_2.0" CORDIS_EU_ORGANIZATIONS_WILDCARD = "cordis_eu_*_organizations" CORDIS_EU_PROJECTS_WILDCARD = "cordis_eu_*_projects" diff --git a/webapp/src/app/modules/dashboard/topic-heatmap/topic-heatmap.component.ts b/webapp/src/app/modules/dashboard/topic-heatmap/topic-heatmap.component.ts index 981236db..34317472 100644 --- a/webapp/src/app/modules/dashboard/topic-heatmap/topic-heatmap.component.ts +++ b/webapp/src/app/modules/dashboard/topic-heatmap/topic-heatmap.component.ts @@ -3,6 +3,7 @@ import { MatDialog } from '@angular/material/dialog'; import { EChartsOption } from 'echarts'; import { NgxEchartsDirective } from 'ngx-echarts'; +import { topicHierarchyColor } from '../../../resolvers/utils/topic-colors'; import { TopicHeatmap } from '../dashboard-statistics.service'; import { TopicWordCloudDialogComponent, @@ -17,22 +18,11 @@ import { }) export class TopicHeatmapComponent implements OnChanges { private readonly dialog = inject(MatDialog); + private readonly fieldColorOpacity = 0.78; @Input() heatmap?: TopicHeatmap; @Input() loading = false; options: EChartsOption = {}; - private readonly colors = [ - '#2563eb', - '#059669', - '#d97706', - '#dc2626', - '#7c3aed', - '#0284c7', - '#ea580c', - '#4f46e5', - '#0f766e', - '#be123c', - ]; ngOnChanges(): void { this.options = this.buildOptions(); @@ -60,49 +50,118 @@ export class TopicHeatmapComponent implements OnChanges { private buildOptions(): EChartsOption { const fields = this.heatmap?.fields ?? []; - const data = fields.map((field) => ({ - id: field.id, - name: field.name, - value: field.total || this.totalCount(field.values), - label: { - show: true, - formatter: (params: any) => - `${params.name}\n${this.formatCount(params.value)}`, - color: '#ffffff', - fontWeight: 700, - lineHeight: 18, - overflow: 'truncate' as const, - }, - children: (field.subfields ?? []) - .filter((subfield) => subfield.total > 0) - .map((subfield) => ({ - id: subfield.id, - name: subfield.name, - value: subfield.total, - fieldName: field.name, - children: (subfield.topics ?? []) - .filter((topic) => topic.total > 0) - .map((topic) => ({ - id: topic.id, - name: topic.name, - value: topic.total, - fieldName: field.name, - subfieldName: subfield.name, - })), - })), - })); + const data = fields.map((field) => { + const fieldColor = topicHierarchyColor({ + field_id: field.id, + field_name: field.name, + }); + + return { + id: field.id, + name: field.name, + value: field.total || this.totalCount(field.values), + itemStyle: { + color: fieldColor, + opacity: this.fieldColorOpacity, + }, + emphasis: { + itemStyle: { + color: fieldColor, + opacity: this.fieldColorOpacity, + }, + }, + label: { + show: true, + formatter: (params: any) => + `${params.name}\n${this.formatCount(params.value)}`, + color: '#ffffff', + fontWeight: 700, + lineHeight: 18, + overflow: 'truncate' as const, + }, + children: (field.subfields ?? []) + .filter((subfield) => subfield.total > 0) + .map((subfield) => ({ + id: subfield.id, + name: subfield.name, + value: subfield.total, + fieldName: field.name, + itemStyle: { + color: fieldColor, + opacity: this.fieldColorOpacity, + }, + emphasis: { + itemStyle: { + color: fieldColor, + opacity: this.fieldColorOpacity, + }, + }, + children: (subfield.topics ?? []) + .filter((topic) => topic.total > 0) + .map((topic) => ({ + id: topic.id, + name: topic.name, + value: topic.total, + fieldName: field.name, + subfieldName: subfield.name, + itemStyle: { + color: fieldColor, + opacity: this.fieldColorOpacity, + }, + emphasis: { + itemStyle: { + color: fieldColor, + opacity: this.fieldColorOpacity, + }, + }, + })), + })), + }; + }); return { tooltip: { + trigger: 'item', + confine: true, + backgroundColor: '#ffffff', + borderColor: '#d8cafe', + borderWidth: 1, + padding: 0, + extraCssText: + 'max-width: 360px; border-radius: 12px; box-shadow: 0 14px 36px rgba(16, 26, 61, 0.18);', formatter: (params: any) => { const count = Number(params.value ?? 0); - const field = params.data?.fieldName - ? `
Field: ${params.data.fieldName}` + const name = this.escapeHtml(String(params.name ?? '')); + const fieldName = params.data?.fieldName + ? this.escapeHtml(String(params.data.fieldName)) : ''; - const subfield = params.data?.subfieldName - ? `
Subfield: ${params.data.subfieldName}` + const subfieldName = params.data?.subfieldName + ? this.escapeHtml(String(params.data.subfieldName)) : ''; - return `${params.name}${field}${subfield}
${count} Publikationen`; + const hierarchy = [fieldName, subfieldName] + .filter(Boolean) + .map( + (item) => + `${item}`, + ) + .join('›'); + + return ` +
+ ${ + hierarchy + ? `
${hierarchy}
` + : '' + } +
${name}
+
+ ${this.formatCount(count)} + Publikationen +
+
+ Klicken, um diesen Bereich zu vergrößern +
+
`; }, }, series: [ @@ -141,8 +200,6 @@ export class TopicHeatmapComponent implements OnChanges { }, }, }, - color: this.colors, - colorMappingBy: 'id', label: { show: true, formatter: (params: any) => @@ -166,7 +223,6 @@ export class TopicHeatmapComponent implements OnChanges { }, levels: [ { - color: this.colors, label: { show: true, position: 'inside', @@ -181,7 +237,6 @@ export class TopicHeatmapComponent implements OnChanges { }, }, { - color: this.colors, label: { show: true, position: 'inside', @@ -196,7 +251,6 @@ export class TopicHeatmapComponent implements OnChanges { }, }, { - colorSaturation: [0.45, 0.78], label: { show: true, formatter: (params: any) => @@ -224,9 +278,18 @@ export class TopicHeatmapComponent implements OnChanges { left: 8, animationDurationUpdate: 450, emphasis: { - focus: 'self', label: { color: '#ffffff', + fontSize: 15, + fontWeight: 800, + textShadowBlur: 4, + textShadowColor: 'rgba(15, 23, 42, 0.45)', + }, + itemStyle: { + borderColor: '#ffffff', + borderWidth: 5, + shadowBlur: 18, + shadowColor: 'rgba(15, 23, 42, 0.35)', }, }, itemStyle: { @@ -247,4 +310,18 @@ export class TopicHeatmapComponent implements OnChanges { private formatCount(value: unknown): string { return Number(value ?? 0).toLocaleString('de-DE'); } + + private escapeHtml(value: string): string { + return value.replace( + /[&<>'"]/g, + (character) => + ({ + '&': '&', + '<': '<', + '>': '>', + "'": ''', + '"': '"', + })[character] ?? character, + ); + } } diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html index 23304379..8351d069 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html +++ b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.html @@ -1,37 +1,98 @@
-
-

{{ data.topicName }}

-

- {{ data.fieldName }} - @if (data.subfieldName) { - · {{ data.subfieldName }} - } -

+
+
+ Topic Insights +

Keyword Wordcloud

+

Die wichtigsten Begriffe zum ausgewählten Forschungsthema

+
-
- @if (loading) { -
Verwandte Themen werden geladen ...
- } @else if (loadFailed) { -
Wordcloud konnte nicht geladen werden.
- } @else if (words.length) { -
- @for (word of words; track word.id) { - - {{ word.name }} - +
+
+ + + Field + {{ data.fieldName || '–' }} + +
+ +
+ + + Subfield + {{ data.subfieldName || '–' }} + +
+ +
+ + + Topic + {{ data.topicName }} + +
+
+ +
+
+
+

Top Keywords

+

Die Schriftgröße entspricht der Anzahl der Publikationen.

+
+ @if (!loading && !loadFailed && words.length) { + {{ words.length }} Begriffe }
- } @else { -
Keine verwandten Themen gefunden.
- } + + @if (loading) { +
+ + Wordcloud wird erstellt + Die wichtigsten Keywords werden geladen … +
+ } @else if (loadFailed) { +
+ + Wordcloud nicht verfügbar + Die Keywords konnten nicht geladen werden. +
+ } @else if (words.length) { +
+ @for (word of words; track word.id) { + + {{ word.name }} + + } +
+ } @else { +
+ + Keine Keywords gefunden + Für dieses Topic sind im gewählten Zeitraum keine Daten vorhanden. +
+ } +
diff --git a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss index ad055bd2..1b66b75b 100644 --- a/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss +++ b/webapp/src/app/modules/dashboard/topic-wordcloud-dialog/topic-wordcloud-dialog.component.scss @@ -2,48 +2,307 @@ display: flex; align-items: flex-start; justify-content: space-between; - gap: 16px; + gap: 24px; + padding: 24px 28px 20px; + border-bottom: 1px solid var(--sg-border, #dde5f2); + background: linear-gradient(135deg, #ffffff 52%, #f6f0ff 100%); h2 { - margin: 0; + margin: 1px 0 3px; + color: var(--sg-text, #101a3d); + font-family: 'Montserrat', sans-serif; + font-size: 1.375rem; + font-weight: 700; + line-height: 1.25; } p { - margin: 4px 0 0; - color: #64748b; - font-size: 0.875rem; + margin: 0; + color: var(--sg-text-muted, #64708f); + font-size: 0.8125rem; + font-weight: 400; + } +} + +.dialog-heading { + display: flex; + align-items: center; +} + +.dialog-eyebrow { + display: block; + color: #7255d9; + font-size: 0.6875rem; + font-weight: 700; + letter-spacing: 0.08em; + line-height: 1.2; + text-transform: uppercase; +} + +.dialog-close { + flex: 0 0 auto; + color: var(--sg-text-muted, #64708f); + + &:hover { + background: #f1f3f7; + color: var(--sg-text, #101a3d); } } mat-dialog-content { - min-height: 330px; + min-height: 410px; + padding: 20px 28px 28px !important; + background: #ffffff; +} + +.topic-context-card { + display: grid; + grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); + align-items: center; + gap: 12px; + margin-bottom: 18px; + padding: 12px; + border: 1px solid var(--sg-border, #dde5f2); + border-radius: 12px; + background: var(--sg-surface-muted, #f7f9ff); +} + +.topic-context-item { + display: flex; + min-width: 0; + align-items: center; + gap: 10px; + padding: 5px 6px; +} + +.topic-context-icon { + display: grid; + width: 34px; + height: 34px; + flex: 0 0 34px; + place-items: center; + border-radius: 9px; + + mat-icon { + width: 18px; + height: 18px; + font-size: 18px; + } +} + +.topic-context-icon--field { + border: 1px solid #bdd4ff; + background: #f0f6ff; + color: #0b63ce; +} + +.topic-context-icon--subfield { + border: 1px solid #bdebcf; + background: #effaf3; + color: #24834f; +} + +.topic-context-icon--topic { + border: 1px solid #d8cafe; + background: #f6f0ff; + color: #7255d9; +} + +.topic-context-copy { + display: flex; + min-width: 0; + flex-direction: column; + gap: 2px; + + strong { + overflow: hidden; + color: #334155; + font-size: 0.8125rem; + font-weight: 600; + line-height: 1.35; + text-overflow: ellipsis; + white-space: nowrap; + } +} + +.topic-context-item--topic strong { + color: #7255d9; +} + +.topic-context-label { + color: var(--sg-text-soft, #8a95b3); + font-size: 0.625rem; + font-weight: 700; + letter-spacing: 0.07em; + line-height: 1.2; + text-transform: uppercase; +} + +.topic-context-arrow { + width: 18px; + height: 18px; + color: #a8b2c8; + font-size: 18px; +} + +.word-cloud-panel { + overflow: hidden; + border: 1px solid var(--sg-border, #dde5f2); + border-radius: 16px; + background: #ffffff; + box-shadow: var(--sg-shadow-sm); +} + +.word-cloud-panel-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + padding: 14px 18px; + border-bottom: 1px solid #e8edf5; + + h3 { + margin: 0 0 2px; + color: var(--sg-text, #101a3d); + font-family: 'Montserrat', sans-serif; + font-size: 0.9375rem; + font-weight: 700; + } + + p { + margin: 0; + color: var(--sg-text-muted, #64708f); + font-size: 0.75rem; + } +} + +.word-count { + flex: 0 0 auto; + padding: 5px 9px; + border: 1px solid #d8cafe; + border-radius: 999px; + background: #f6f0ff; + color: #7255d9; + font-size: 0.6875rem; + font-weight: 700; } .word-cloud-chart { - min-height: 300px; display: flex; + min-height: 280px; flex-wrap: wrap; align-content: center; align-items: baseline; justify-content: center; - gap: 12px 18px; - padding: 24px; - border-radius: 12px; - background: linear-gradient(145deg, #f8fafc, #ffffff); + gap: 14px 20px; + padding: 30px 34px; + background: + radial-gradient(circle at 15% 20%, rgba(114, 85, 217, 0.06), transparent 28%), + radial-gradient(circle at 85% 75%, rgba(11, 99, 206, 0.05), transparent 30%), + #ffffff; } .word-cloud-word { + padding: 3px 5px; + border-radius: 6px; + cursor: help; line-height: 1.1; text-align: center; + transition: + transform 150ms ease, + background-color 150ms ease; + + &:hover { + background: rgba(241, 243, 247, 0.9); + transform: translateY(-2px); + } } .word-cloud-state { - min-height: 300px; - display: grid; - place-items: center; - color: #64748b; + display: flex; + min-height: 280px; + align-items: center; + justify-content: center; + flex-direction: column; + gap: 6px; + padding: 24px; + color: var(--sg-text-muted, #64708f); + text-align: center; - &.error { - color: #b91c1c; + strong { + margin-top: 4px; + color: var(--sg-text, #101a3d); + font-size: 0.9375rem; + } + + > span:last-child { + font-size: 0.8125rem; + } +} + +.state-icon { + display: grid; + width: 46px; + height: 46px; + place-items: center; + border-radius: 50%; + background: #f1f3f7; + color: #64708f; +} + +.state-icon--loading { + background: #f6f0ff; + color: #7255d9; + animation: state-pulse 1.4s ease-in-out infinite; +} + +.word-cloud-state--error .state-icon { + background: #fff1f5; + color: #d12f61; +} + +@keyframes state-pulse { + 50% { + box-shadow: 0 0 0 8px rgba(114, 85, 217, 0.08); + transform: scale(1.04); + } +} + +@media (max-width: 700px) { + .dialog-title { + padding: 20px; + } + + mat-dialog-content { + padding: 16px 20px 20px !important; + } + + .topic-context-card { + grid-template-columns: 1fr; + gap: 4px; + } + + .topic-context-arrow { + display: none; + } + + .topic-context-copy strong { + white-space: normal; + } + + .word-cloud-chart { + min-height: 240px; + gap: 10px 14px; + padding: 24px 18px; + } +} + +@media (prefers-reduced-motion: reduce) { + .state-icon--loading { + animation: none; + } + + .word-cloud-word { + transition: none; } } diff --git a/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts b/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts index 54f5060c..896b0aca 100644 --- a/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts +++ b/webapp/src/app/shared/ui/topic-chip/topic-chip.component.ts @@ -22,13 +22,16 @@ export type TopicChipColor = TopicChipPaletteColor | string; export type TopicChipSize = 'normal' | 'mini'; export type TopicChipTooltipTarget = 'label' | 'button'; -interface TopicChipColorTokens { +export interface TopicChipColorTokens { border: string; background: string; color: string; } -const TOPIC_CHIP_COLORS: Record = { +export const TOPIC_CHIP_COLORS: Record< + TopicChipPaletteColor, + TopicChipColorTokens +> = { purple: { border: '#d8cafe', background: '#f6f0ff',