@@ -10,9 +10,10 @@ import {
10
10
ElementRef ,
11
11
NgZone ,
12
12
ChangeDetectionStrategy ,
13
+ Input ,
14
+ OnInit ,
13
15
} from '@angular/core' ;
14
16
import { startWith } from 'rxjs' ;
15
- import { Arrangements2 as Arrangements } from './arrangements' ;
16
17
import { Connections } from './connections' ;
17
18
import { FlowChildComponent } from './flow-child.component' ;
18
19
import { FlowService } from './flow.service' ;
@@ -22,9 +23,10 @@ import {
22
23
FlowDirection ,
23
24
DotOptions ,
24
25
ArrowPathFn ,
26
+ FlowConfig ,
27
+ FlowPlugin ,
25
28
} from './flow-interface' ;
26
29
import { blendCorners , flowPath , bezierPath , blendCorners1 } from './svg' ;
27
- import { FitToWindow } from './fit-to-window' ;
28
30
29
31
const BASE_SCALE_AMOUNT = 0.05 ;
30
32
@@ -125,10 +127,11 @@ const BASE_SCALE_AMOUNT = 0.05;
125
127
] ,
126
128
} )
127
129
export class FlowComponent
128
- implements AfterContentInit , AfterViewInit , OnDestroy
130
+ implements OnInit , AfterContentInit , AfterViewInit , OnDestroy
129
131
{
130
- @ContentChildren ( FlowChildComponent ) children : QueryList < FlowChildComponent > =
131
- new QueryList ( ) ;
132
+ @Input ( ) config : FlowConfig = new FlowConfig ( ) ;
133
+ @ContentChildren ( FlowChildComponent ) children =
134
+ new QueryList < FlowChildComponent > ( ) ;
132
135
133
136
// @ViewChildren ('arrowPaths') arrowPaths: QueryList<ElementRef<SVGPathElement>>;
134
137
@ViewChild ( 'zoomContainer' ) zoomContainer : ElementRef < HTMLDivElement > ;
@@ -143,7 +146,9 @@ export class FlowComponent
143
146
public el : ElementRef < HTMLElement > ,
144
147
public flow : FlowService ,
145
148
private ngZone : NgZone
146
- ) {
149
+ ) { }
150
+
151
+ ngOnInit ( ) : void {
147
152
this . flow . zoomContainer = this . el . nativeElement ;
148
153
this . flow . arrowsChange . subscribe ( ( e ) => this . updateArrows ( e ) ) ;
149
154
this . ngZone . runOutsideAngular ( ( ) => {
@@ -166,14 +171,24 @@ export class FlowComponent
166
171
167
172
ngAfterViewInit ( ) : void {
168
173
this . createArrows ( ) ;
174
+ this . runPlugin ( ( e ) => e . afterInit ?.( this ) ) ;
175
+ }
176
+
177
+ private runPlugin ( callback : ( e : FlowPlugin ) => void ) {
178
+ for ( const key in this . config . Plugins ) {
179
+ if ( Object . prototype . hasOwnProperty . call ( this . config . Plugins , key ) ) {
180
+ const element = this . config . Plugins [ key ] ;
181
+ callback ( element ) ;
182
+ }
183
+ }
169
184
}
170
185
171
186
ngAfterContentInit ( ) {
172
187
this . children . changes
173
188
. pipe ( startWith ( this . children ) )
174
189
. subscribe ( ( children ) => {
175
190
this . flow . update ( this . children . map ( ( x ) => x . position ) ) ;
176
- this . arrangeChildren ( ) ;
191
+ this . runPlugin ( ( e ) => e . beforeArrowUpdate ?. ( this ) ) ;
177
192
this . createArrows ( ) ;
178
193
} ) ;
179
194
requestAnimationFrame ( ( ) => this . updateArrows ( ) ) ; // this required for angular to render the dot
@@ -189,7 +204,7 @@ export class FlowComponent
189
204
190
205
updateDirection ( direction : FlowDirection ) {
191
206
this . flow . direction = direction ;
192
- this . arrangeChildren ( ) ;
207
+ this . runPlugin ( ( e ) => e . beforeArrowUpdate ?. ( this ) ) ;
193
208
this . createArrows ( ) ;
194
209
}
195
210
@@ -281,38 +296,10 @@ export class FlowComponent
281
296
return { scale : newScale , panX : newPanX , panY : newPanY } ;
282
297
}
283
298
284
- fitToWindow ( ) {
285
- const ftw = new FitToWindow (
286
- this . list ,
287
- this . zoomContainer . nativeElement . getBoundingClientRect ( ) ,
288
- this . flow . scale ,
289
- this . flow . panX ,
290
- this . flow . panY
291
- ) ;
292
- const { scale, panX, panY } = ftw . fitToWindow ( ) ;
293
- this . flow . scale = scale ;
294
- this . flow . panX = panX ;
295
- this . flow . panY = panY ;
296
- this . updateZoomContainer ( ) ;
297
- }
298
-
299
- private updateZoomContainer ( ) {
299
+ updateZoomContainer ( ) {
300
300
this . zoomContainer . nativeElement . style . transform = `translate3d(${ this . flow . panX } px, ${ this . flow . panY } px, 0) scale(${ this . flow . scale } )` ;
301
301
}
302
302
303
- arrangeChildren ( ) {
304
- const arrangements = new Arrangements (
305
- this . list ,
306
- this . flow . direction ,
307
- this . flow . horizontalPadding ,
308
- this . flow . verticalPadding ,
309
- this . flow . groupPadding
310
- ) ;
311
- const newList = arrangements . autoArrange ( ) ;
312
- this . flow . update ( [ ...newList . values ( ) ] ) ;
313
- this . flow . layoutUpdated . next ( ) ;
314
- }
315
-
316
303
get list ( ) {
317
304
return this . children . toArray ( ) . map ( ( x ) => {
318
305
// calculate the width and height with scale
0 commit comments