@@ -3,6 +3,7 @@ import * as d3 from 'd3';
33import { LoaderService } from '../../service/loader/data-loader.service' ;
44import { Activity } from 'src/app/model/activity-store' ;
55import { DataStore } from 'src/app/model/data-store' ;
6+ import { ThemeService } from 'src/app/service/theme.service' ;
67
78export interface graphNodes {
89 id : string ;
@@ -21,25 +22,35 @@ export interface graph {
2122 links : graphLinks [ ] ;
2223}
2324
25+ interface ThemeColors {
26+ linkColor : string ;
27+ borderColor : string ;
28+ mainNodeColor : string ;
29+ mainNodeFill : string ;
30+ predecessorFill : string ;
31+ successorFill : string ;
32+ }
33+
2434@Component ( {
2535 selector : 'app-dependency-graph' ,
2636 templateUrl : './dependency-graph.component.html' ,
2737 styleUrls : [ './dependency-graph.component.css' ] ,
2838} )
2939export class DependencyGraphComponent implements OnInit , OnChanges {
30- COLOR_OF_LINK : string = 'black' ;
31- COLOR_OF_NODE : string = '#66bb6a' ;
32- COLOR_OF_PREDECESSOR : string = '#deeedeff' ;
33- COLOR_OF_SUCCESSOR : string = '#fdfdfdff' ;
34- BORDER_COLOR_OF_NODE : string = 'black' ;
40+ css : CSSStyleDeclaration = getComputedStyle ( document . body ) ;
41+ themeColors : Partial < ThemeColors > = { } ;
42+ theme : string ;
3543 simulation : any ;
3644 dataStore : Partial < DataStore > = { } ;
3745 graphData : graph = { nodes : [ ] , links : [ ] } ;
3846 visited : Set < string > = new Set ( ) ;
3947
4048 @Input ( ) activityName : string = '' ;
4149
42- constructor ( private loader : LoaderService ) { }
50+ constructor ( private loader : LoaderService , private themeService : ThemeService ) {
51+ this . theme = this . themeService . getTheme ( ) ;
52+ this . setThemeColors ( this . theme ) ;
53+ }
4354
4455 ngOnInit ( ) : void {
4556 this . loader . load ( ) . then ( ( dataStore : DataStore ) => {
@@ -50,6 +61,11 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
5061 }
5162 this . populateGraph ( this . activityName ) ;
5263 } ) ;
64+
65+ // Reactively handle theme changes (if user toggles later)
66+ this . themeService . theme$ . subscribe ( ( theme : string ) => {
67+ this . setThemeColors ( theme ) ;
68+ } ) ;
5369 }
5470
5571 ngOnChanges ( changes : SimpleChanges ) : void {
@@ -61,6 +77,19 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
6177 }
6278 }
6379
80+ setThemeColors ( theme : string ) {
81+ /* eslint-disable */
82+ this . themeColors . mainNodeFill = this . css . getPropertyValue ( '--heatmap-filled' ) . trim ( ) ;
83+ this . themeColors . mainNodeColor = this . css . getPropertyValue ( '--text-primary' ) . trim ( ) ;
84+ this . themeColors . linkColor = this . css . getPropertyValue ( '--dependency-link' ) . trim ( ) ;
85+ this . themeColors . borderColor = this . css . getPropertyValue ( '--dependency-border' ) . trim ( ) ;
86+ this . themeColors . predecessorFill = this . css . getPropertyValue ( '--dependency-predecessor-fill' ) . trim ( ) ;
87+ this . themeColors . successorFill = this . css . getPropertyValue ( '--dependency-successor-fill' ) . trim ( ) ;
88+ /*eslint-enable */
89+
90+ this . generateGraph ( ) ;
91+ }
92+
6493 populateGraph ( activityName : string ) : void {
6594 if ( this . simulation ) {
6695 this . simulation . stop ( ) ;
@@ -74,7 +103,7 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
74103 this . populateGraphWithActivitiesCurrentActivityDependsOn ( activity ) ;
75104 this . populateGraphWithActivitiesThatDependsOnCurrentActivity ( activity ) ;
76105
77- this . generateGraph ( this . activityName ) ;
106+ this . generateGraph ( ) ;
78107 }
79108 }
80109
@@ -138,7 +167,7 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
138167 return d . relativeLevel * 30 ;
139168 }
140169
141- generateGraph ( activityName : string ) : void {
170+ generateGraph ( ) : void {
142171 let svg = d3 . select ( 'svg' ) ;
143172 svg . selectAll ( '*' ) . remove ( ) ;
144173
@@ -174,7 +203,7 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
174203 . attr ( 'overflow' , 'visible' )
175204 . append ( 'svg:path' )
176205 . attr ( 'd' , 'M 0,-5 L 10 ,0 L 0,5' )
177- . attr ( 'fill' , this . COLOR_OF_LINK )
206+ . attr ( 'fill' , this . themeColors . linkColor || 'black' )
178207 . style ( 'stroke' , 'none' ) ;
179208
180209 let links = svg
@@ -184,7 +213,7 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
184213 . data ( this . graphData [ 'links' ] )
185214 . enter ( )
186215 . append ( 'line' )
187- . style ( 'stroke' , this . COLOR_OF_LINK )
216+ . style ( 'stroke' , this . themeColors . linkColor || 'black' )
188217 . attr ( 'marker-end' , 'url(#arrowhead)' ) ;
189218
190219 let nodes = svg
@@ -229,10 +258,12 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
229258 . attr ( 'rx' , rectRx )
230259 . attr ( 'ry' , rectRy )
231260 . attr ( 'fill' , ( d : any ) => {
232- if ( d . relativeLevel == 0 ) return self . COLOR_OF_NODE ;
233- return d . relativeLevel < 0 ? self . COLOR_OF_PREDECESSOR : self . COLOR_OF_SUCCESSOR ;
261+ if ( d . relativeLevel == 0 ) return self . themeColors . mainNodeFill || 'green' ;
262+ let col : string | undefined =
263+ d . relativeLevel < 0 ? self . themeColors . predecessorFill : self . themeColors . successorFill ;
264+ return col || 'white' ;
234265 } )
235- . attr ( 'stroke' , self . BORDER_COLOR_OF_NODE )
266+ . attr ( 'stroke' , self . themeColors . borderColor || 'black' )
236267 . attr ( 'stroke-width' , 1.5 ) ;
237268 } ) ;
238269
@@ -244,51 +275,49 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
244275 this . simulation . force ( 'link' ) . links ( this . graphData [ 'links' ] ) ;
245276
246277 function ticked ( ) {
247- if ( self . simulation . alpha ( ) < 1.9 ) {
248- // Improved rectangle edge intersection for arrowhead placement
249- links
250- . attr ( 'x1' , function ( d : any ) {
251- return d . source . x ;
252- } )
253- . attr ( 'y1' , function ( d : any ) {
254- return d . source . y ;
255- } )
256- . attr ( 'x2' , function ( d : any ) {
257- // If target has rectWidth, adjust arrow to edge minus offset
258- if ( d . target . rectWidth ) {
259- const pt = self . rectEdgeIntersection (
260- d . source . x ,
261- d . source . y ,
262- d . target . x ,
263- d . target . y ,
264- d . target . rectWidth ,
265- 30 ,
266- 10 // rectHeight, offset
267- ) ;
268- return pt . x ;
269- }
270- return d . target . x ;
271- } )
272- . attr ( 'y2' , function ( d : any ) {
273- if ( d . target . rectWidth ) {
274- const pt = self . rectEdgeIntersection (
275- d . source . x ,
276- d . source . y ,
277- d . target . x ,
278- d . target . y ,
279- d . target . rectWidth ,
280- 30 ,
281- 10
282- ) ;
283- return pt . y ;
284- }
285- return d . target . y ;
286- } ) ;
287-
288- nodes . attr ( 'transform' , function ( d : any ) {
289- return 'translate(' + d . x + ',' + d . y + ')' ;
278+ // Improved rectangle edge intersection for arrowhead placement
279+ links
280+ . attr ( 'x1' , function ( d : any ) {
281+ return d . source . x ;
282+ } )
283+ . attr ( 'y1' , function ( d : any ) {
284+ return d . source . y ;
285+ } )
286+ . attr ( 'x2' , function ( d : any ) {
287+ // If target has rectWidth, adjust arrow to edge minus offset
288+ if ( d . target . rectWidth ) {
289+ const pt = self . rectEdgeIntersection (
290+ d . source . x ,
291+ d . source . y ,
292+ d . target . x ,
293+ d . target . y ,
294+ d . target . rectWidth ,
295+ 30 ,
296+ 10 // rectHeight, offset
297+ ) ;
298+ return pt . x ;
299+ }
300+ return d . target . x ;
301+ } )
302+ . attr ( 'y2' , function ( d : any ) {
303+ if ( d . target . rectWidth ) {
304+ const pt = self . rectEdgeIntersection (
305+ d . source . x ,
306+ d . source . y ,
307+ d . target . x ,
308+ d . target . y ,
309+ d . target . rectWidth ,
310+ 30 ,
311+ 10
312+ ) ;
313+ return pt . y ;
314+ }
315+ return d . target . y ;
290316 } ) ;
291- }
317+
318+ nodes . attr ( 'transform' , function ( d : any ) {
319+ return 'translate(' + d . x + ',' + d . y + ')' ;
320+ } ) ;
292321 }
293322 }
294323
@@ -364,8 +393,8 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
364393 for ( i = 0 ; i < n ; ++ i ) {
365394 node = nodes [ i ] ;
366395 // Calculate bounding box for node
367- nx1 = node . x - node . rectWidth / 2 - 10 ;
368- nx2 = node . x + node . rectWidth / 2 + 10 ;
396+ nx1 = node . x - node . rectWidth / 2 - 25 ;
397+ nx2 = node . x + node . rectWidth / 2 + 25 ;
369398 ny1 = node . y - 25 ;
370399 ny2 = node . y + 25 ;
371400 for ( let j = i + 1 ; j < n ; ++ j ) {
0 commit comments