feat(wordcloud): apply new color scheme to wordcloud
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -5,6 +5,7 @@ import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
||||
import { combineLatest, distinctUntilChanged, map } from 'rxjs';
|
||||
|
||||
import { TopicCount, TopicsByYear, WorksService } from '../../api';
|
||||
import { topicHierarchyColor } from '../../shared/utils/topic-colors';
|
||||
import {
|
||||
ResearchTimelineComponent,
|
||||
TimelineViewMode,
|
||||
@@ -70,6 +71,10 @@ export class PersonOverviewComponent implements OnInit {
|
||||
name: string;
|
||||
topicId: string;
|
||||
year: number | undefined;
|
||||
fieldId: string | undefined;
|
||||
fieldName: string | undefined;
|
||||
domainId: string | undefined;
|
||||
domainName: string | undefined;
|
||||
}> = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -334,14 +339,6 @@ export class PersonOverviewComponent implements OnInit {
|
||||
this.timelineEarlierYearsLoadFailed = false;
|
||||
}
|
||||
|
||||
private readonly timelineColors = [
|
||||
'#7255d9',
|
||||
'#2678e8',
|
||||
'#39a96b',
|
||||
'#f59e0b',
|
||||
'#e0527c',
|
||||
];
|
||||
|
||||
private loadWordCloud(authorId: string): void {
|
||||
if (!authorId || authorId === '0') {
|
||||
this.wordCloudWords = [];
|
||||
@@ -369,6 +366,10 @@ export class PersonOverviewComponent implements OnInit {
|
||||
name: topic.display_name,
|
||||
topicId: topic.id,
|
||||
year,
|
||||
fieldId: topic.field?.id ?? undefined,
|
||||
fieldName: topic.field?.display_name ?? undefined,
|
||||
domainId: topic.domain?.id ?? undefined,
|
||||
domainName: topic.domain?.display_name ?? undefined,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -396,6 +397,10 @@ export class PersonOverviewComponent implements OnInit {
|
||||
const end = this.timelineEndYear;
|
||||
const counts = new Map<string, number>();
|
||||
const nameToId = new Map<string, string>();
|
||||
const nameToColorInput = new Map<
|
||||
string,
|
||||
Parameters<typeof topicHierarchyColor>[0]
|
||||
>();
|
||||
|
||||
for (const occ of this.rawTopicOccurrences) {
|
||||
if (start !== undefined && (occ.year === undefined || occ.year < start))
|
||||
@@ -403,7 +408,17 @@ export class PersonOverviewComponent implements OnInit {
|
||||
if (end !== undefined && (occ.year === undefined || occ.year > end))
|
||||
continue;
|
||||
counts.set(occ.name, (counts.get(occ.name) ?? 0) + 1);
|
||||
if (!nameToId.has(occ.name)) nameToId.set(occ.name, occ.topicId);
|
||||
if (!nameToId.has(occ.name)) {
|
||||
nameToId.set(occ.name, occ.topicId);
|
||||
nameToColorInput.set(occ.name, {
|
||||
id: occ.topicId,
|
||||
name: occ.name,
|
||||
field_id: occ.fieldId,
|
||||
field_name: occ.fieldName,
|
||||
domain_id: occ.domainId,
|
||||
domain_name: occ.domainName,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (counts.size === 0) {
|
||||
@@ -422,13 +437,13 @@ export class PersonOverviewComponent implements OnInit {
|
||||
|
||||
const sorted = Array.from(counts.entries()).sort((a, b) => b[1] - a[1]);
|
||||
|
||||
const words = sorted.slice(0, 30).map(([name, value], i): WordCloudWord => {
|
||||
const words = sorted.slice(0, 30).map(([name, value]): WordCloudWord => {
|
||||
const t = intensity(value);
|
||||
return {
|
||||
name,
|
||||
value,
|
||||
topicId: nameToId.get(name),
|
||||
color: this.timelineColors[i % this.timelineColors.length],
|
||||
color: topicHierarchyColor(nameToColorInput.get(name)),
|
||||
fontSize: Math.round(12 + t * (32 - 12)),
|
||||
fontWeight: t > 0.66 ? 800 : t > 0.33 ? 600 : 400,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user