1
- import { Component , OnInit , Input } from '@angular/core' ;
1
+ import { Component , OnInit , Input , ElementRef } from '@angular/core' ;
2
2
import * as d3 from 'd3' ;
3
3
import { ymlService } from 'src/app/service/yaml-parser/yaml-parser.service' ;
4
+ import { Subscription } from 'rxjs' ;
5
+ import { ThemeService } from '../../service/theme.service' ;
4
6
5
7
export interface graphNodes {
6
8
id : string ;
@@ -35,10 +37,24 @@ export class DependencyGraphComponent implements OnInit {
35
37
@Input ( ) subDimension : string = '' ;
36
38
@Input ( ) activityName : string = '' ;
37
39
38
- constructor ( private yaml : ymlService ) { }
40
+ private themeSub : Subscription | undefined ;
41
+ currentTheme : string = 'light' ; // default
42
+
43
+ constructor (
44
+ private yaml : ymlService ,
45
+ private elementRef : ElementRef ,
46
+ private themeService : ThemeService
47
+ ) { }
39
48
40
49
ngOnInit ( ) : void {
41
50
this . yaml . setURI ( './assets/YAML/generated/generated.yaml' ) ;
51
+
52
+ this . currentTheme = this . themeService . getTheme ( ) ;
53
+ this . themeSub = this . themeService . theme$ . subscribe ( theme => {
54
+ this . currentTheme = theme ;
55
+ this . applyTextColor ( theme ) ;
56
+ } ) ;
57
+
42
58
// Function sets data
43
59
this . yaml . getJson ( ) . subscribe ( data => {
44
60
this . graphData = { nodes : [ ] , links : [ ] } ;
@@ -108,7 +124,26 @@ export class DependencyGraphComponent implements OnInit {
108
124
}
109
125
}
110
126
127
+ applyTextColor ( theme : string ) : void {
128
+ const fill = theme === 'dark' ? '#ffffff' : '#000000' ;
129
+ const selectedNodeColor = theme === 'dark' ? '#666666' : 'yellow' ;
130
+ const defaultNodeColor = this . COLOR_OF_NODE ;
131
+
132
+ d3 . select ( this . elementRef . nativeElement )
133
+ . selectAll ( 'text' )
134
+ . attr ( 'fill' , fill ) ;
135
+
136
+ d3 . select ( this . elementRef . nativeElement )
137
+ . selectAll ( 'circle' )
138
+ . attr ( 'fill' , ( d : any ) =>
139
+ d . id === this . activityName ? selectedNodeColor : defaultNodeColor
140
+ ) ;
141
+ }
142
+
111
143
generateGraph ( activity : string ) : void {
144
+ const selectedNodeColor =
145
+ this . currentTheme === 'dark' ? '#666666' : 'yellow' ;
146
+
112
147
let svg = d3 . select ( 'svg' ) ,
113
148
width = + svg . attr ( 'width' ) ,
114
149
height = + svg . attr ( 'height' ) ;
@@ -162,10 +197,9 @@ export class DependencyGraphComponent implements OnInit {
162
197
node
163
198
. append ( 'circle' )
164
199
. attr ( 'r' , 10 )
165
- . attr ( 'fill' , function ( d ) {
166
- if ( d . id == activity ) return 'yellow' ;
167
- else return defaultNodeColor ;
168
- } ) ;
200
+ . attr ( 'fill' , ( d : any ) =>
201
+ d . id === this . activityName ? selectedNodeColor : defaultNodeColor
202
+ ) ;
169
203
170
204
node
171
205
. append ( 'text' )
@@ -175,6 +209,8 @@ export class DependencyGraphComponent implements OnInit {
175
209
return d . id ;
176
210
} ) ;
177
211
212
+ this . applyTextColor ( this . currentTheme ) ;
213
+
178
214
this . simulation . nodes ( this . graphData [ 'nodes' ] ) . on ( 'tick' , ticked ) ;
179
215
180
216
this . simulation . force ( 'link' ) . links ( this . graphData [ 'links' ] ) ;
0 commit comments