Skip to content

Commit 1277ef3

Browse files
committed
changed the dependency graph node from yellow to #666666 when in dark mode. Also subscribed the dependency graph text to theme.service to dynamically change text color w/o refresh. Basic Linting.
1 parent a961553 commit 1277ef3

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

src/app/component/dependency-graph/dependency-graph.component.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Component, OnInit, Input } from '@angular/core';
1+
import { Component, OnInit, Input, ElementRef } from '@angular/core';
22
import * as d3 from 'd3';
33
import { ymlService } from 'src/app/service/yaml-parser/yaml-parser.service';
4+
import { Subscription } from 'rxjs';
5+
import { ThemeService } from '../../service/theme.service';
46

57
export interface graphNodes {
68
id: string;
@@ -35,10 +37,24 @@ export class DependencyGraphComponent implements OnInit {
3537
@Input() subDimension: string = '';
3638
@Input() activityName: string = '';
3739

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+
) {}
3948

4049
ngOnInit(): void {
4150
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+
4258
// Function sets data
4359
this.yaml.getJson().subscribe(data => {
4460
this.graphData = { nodes: [], links: [] };
@@ -108,7 +124,26 @@ export class DependencyGraphComponent implements OnInit {
108124
}
109125
}
110126

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+
111143
generateGraph(activity: string): void {
144+
const selectedNodeColor =
145+
this.currentTheme === 'dark' ? '#666666' : 'yellow';
146+
112147
let svg = d3.select('svg'),
113148
width = +svg.attr('width'),
114149
height = +svg.attr('height');
@@ -162,10 +197,9 @@ export class DependencyGraphComponent implements OnInit {
162197
node
163198
.append('circle')
164199
.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+
);
169203

170204
node
171205
.append('text')
@@ -175,6 +209,8 @@ export class DependencyGraphComponent implements OnInit {
175209
return d.id;
176210
});
177211

212+
this.applyTextColor(this.currentTheme);
213+
178214
this.simulation.nodes(this.graphData['nodes']).on('tick', ticked);
179215

180216
this.simulation.force('link').links(this.graphData['links']);

0 commit comments

Comments
 (0)