-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualization.component.ts
115 lines (94 loc) · 3.06 KB
/
visualization.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {
Component,
Input,
OnChanges,
OnDestroy,
SimpleChanges,
} from '@angular/core';
import * as _ from 'lodash';
import { Corpus, CorpusField, QueryModel } from '@models/index';
import { actionIcons, visualizationIcons } from '@shared/icons';
import { RouterStoreService } from '../store/router-store.service';
import {
VisualizationOption,
VisualizationSelector,
} from '@models/visualization-selector';
import { Observable, Subject, merge } from 'rxjs';
import { map } from 'rxjs/operators';
@Component({
selector: 'ia-visualization',
templateUrl: './visualization.component.html',
styleUrls: ['./visualization.component.scss'],
})
export class VisualizationComponent implements OnChanges, OnDestroy {
@Input() public corpus: Corpus;
@Input() public queryModel: QueryModel;
selector: VisualizationSelector;
public freqtable = false;
public manualPages = {
ngram: 'ngrams',
wordcloud: 'wordcloud',
resultscount: 'numberofresults',
termfrequency: 'termfrequency',
};
actionIcons = actionIcons;
visualizationIcons = visualizationIcons;
public palette: string[];
error$: Observable<string|undefined>;
private errorInChild$ = new Subject<string>();
constructor(
private routerStoreService: RouterStoreService,
) {
}
get manualPage(): string {
if (this.visualizationType) {
return this.manualPages[this.visualizationType];
}
}
get visualizationType(): string {
return this.selector.state$.value.name;
}
get visualizedField(): CorpusField {
return this.selector.state$.value.field;
}
get chartElementId(): string {
if (
this.visualizationType === 'resultscount' ||
this.visualizationType === 'termfrequency'
) {
return 'barchart';
}
if (this.visualizationType === 'ngram') {
return 'chart';
}
if (this.visualizationType === 'wordcloud') {
return 'wordcloud_div';
}
}
get imageFileName(): string {
if (this.visualizationType && this.corpus && this.visualizedField) {
return `${this.visualizationType}_${this.corpus.name}_${this.visualizedField.name}.png`;
}
}
ngOnChanges(changes: SimpleChanges) {
if (changes.queryModel || changes.corpus) {
this.selector = new VisualizationSelector(this.routerStoreService, this.queryModel);
const errorReset$ = this.selector.state$.pipe(
map(_.constant(undefined))
);
this.error$ = merge(errorReset$, this.errorInChild$);
}
}
ngOnDestroy(): void {
this.selector?.complete();
}
setVisualizationType(selection: VisualizationOption) {
this.selector.setVisualizationType(selection.name);
}
setVisualizedField(selectedField: CorpusField) {
this.selector.setVisualizedField(selectedField);
}
setErrorMessage(message: string) {
this.errorInChild$.next(message);
}
}