@@ -5,6 +5,8 @@ import { Activity } from 'src/app/model/activity-store';
55import { DataStore } from 'src/app/model/data-store' ;
66import { ThemeService } from 'src/app/service/theme.service' ;
77
8+ import { Output , EventEmitter } from '@angular/core' ;
9+
810export interface graphNodes {
911 id : string ;
1012 relativeLevel : number ;
@@ -47,6 +49,8 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
4749
4850 @Input ( ) activityName : string = '' ;
4951
52+ @Output ( ) activityClicked = new EventEmitter < string > ( ) ;
53+
5054 constructor ( private loader : LoaderService , private themeService : ThemeService ) {
5155 this . theme = this . themeService . getTheme ( ) ;
5256 this . setThemeColors ( this . theme ) ;
@@ -55,7 +59,6 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
5559 ngOnInit ( ) : void {
5660 this . loader . load ( ) . then ( ( dataStore : DataStore ) => {
5761 this . dataStore = dataStore ;
58- console . log ( 'Dep-graph: Setting datastore' ) ;
5962 if ( ! dataStore . activityStore ) {
6063 throw Error ( 'No activity store loaded' ) ;
6164 }
@@ -69,7 +72,6 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
6972 }
7073
7174 ngOnChanges ( changes : SimpleChanges ) : void {
72- console . log ( changes ) ;
7375 if ( this . dataStore ?. activityStore ) {
7476 if ( changes ?. hasOwnProperty ( 'activityName' ) ) {
7577 this . populateGraph ( changes [ 'activityName' ] . currentValue ) ;
@@ -157,11 +159,12 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
157159 }
158160
159161 initX ( d : any ) : number {
160- let col : number = 8 ;
161- if ( d . activityCount > col && d . activityCount < col * 2 ) {
162- col = Math . ceil ( d . activityCount / 2 ) ;
162+ let colSize : number = 8 ;
163+ if ( d . activityCount > colSize && d . activityCount <= colSize * 2.5 ) {
164+ let colCount : number = Math . ceil ( d . activityCount / colSize ) ;
165+ colSize = Math . ceil ( d . activityCount / colCount ) ;
163166 }
164- return d . relativeLevel * Math . ceil ( d . activityIndex / col ) * 300 ;
167+ return d . relativeLevel * Math . ceil ( d . activityIndex / colSize ) * 300 ;
165168 }
166169 initY ( d : any ) : number {
167170 return d . relativeLevel * 30 ;
@@ -176,15 +179,8 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
176179 this . simulation = d3
177180 . forceSimulation ( )
178181 // .alphaMin(0.11)
179- . force (
180- 'link' ,
181- d3 . forceLink ( ) . id ( function ( d : any ) {
182- return d . id ;
183- } ) . strength ( 0.1 )
184- )
185- . force ( 'x' , d3 . forceX ( ( d : any ) => { return self . initX ( d ) } ) . strength ( 5 )
186- )
187- // .force('y', d3.forceY( this.initY ).strength(5))
182+ . force ( 'link' , d3 . forceLink ( ) . id ( ( d : any ) => { return d . id ; } ) . strength ( 0.1 ) )
183+ . force ( 'x' , d3 . forceX ( ( d : any ) => { return self . initX ( d ) } ) . strength ( 5 ) )
188184 . force ( 'charge' , d3 . forceManyBody ( ) . strength ( - 30 ) )
189185 . force ( 'collide' , d3 . forceCollide ( ( d : any ) => 30 ) )
190186 . force ( 'center' , d3 . forceCenter ( 0 , 0 ) ) ;
@@ -222,7 +218,24 @@ export class DependencyGraphComponent implements OnInit, OnChanges {
222218 . selectAll ( 'g' )
223219 . data ( this . graphData [ 'nodes' ] )
224220 . enter ( )
225- . append ( 'g' ) ;
221+ . append ( 'g' )
222+ . on ( 'click' , ( event : MouseEvent , d : any ) => {
223+ if ( d . relativeLevel != 0 ) {
224+ this . activityClicked . emit ( d . id ) ;
225+ }
226+ } )
227+ . on ( 'mouseover' , ( event : MouseEvent , d : any ) => {
228+ if ( this . activityClicked . observed ) {
229+ if ( d . relativeLevel != 0 ) {
230+ d3 . select ( event . currentTarget as Element ) . style ( 'cursor' , 'pointer' ) ;
231+ } else {
232+ d3 . select ( event . currentTarget as Element ) . style ( 'cursor' , 'default' ) ;
233+ }
234+ }
235+ } )
236+ . on ( 'mouseout' , ( event : MouseEvent , d : any ) => {
237+ d3 . select ( event . currentTarget as Element ) . style ( 'cursor' , 'default' ) ;
238+ } ) ;
226239
227240 const rectHeight = 30 ;
228241 const rectRx = 10 ;
0 commit comments