File

projects/atft/src/lib/actor/data-center/layout/dagre-node.component.ts

Extends

AbstractEmptyDirective

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(rendererService: RendererService, parent: AbstractObject3D<any>, injector: Injector)
Parameters :
Name Type Optional
rendererService RendererService No
parent AbstractObject3D<any> No
injector Injector No

Inputs

composition
Type : string
translateZ
Type : number
Default value : 0
Inherited from AbstractObject3D
layer
Type : number
Default value : 0
Inherited from AbstractObject3D
name
Type : string
Default value : uuidv4()
Inherited from AbstractObject3D
rotateX
Type : number
Inherited from AbstractObject3D

Rotation in Euler angles (radians) with order X, Y, Z.

rotateY
Type : number
Inherited from AbstractObject3D
rotateZ
Type : number
Inherited from AbstractObject3D
scaleX
Type : number
Default value : 1
Inherited from AbstractObject3D
scaleY
Type : number
Default value : 1
Inherited from AbstractObject3D
scaleZ
Type : number
Default value : 1
Inherited from AbstractObject3D
translateX
Type : number
Inherited from AbstractObject3D

Translate the geometry. This is typically done as a one time operation, and not during a loop.

translateY
Type : number
Inherited from AbstractObject3D

Outputs

changed
Type : EventEmitter
Inherited from AbstractObject3D

Methods

Protected addNode
addNode()
Returns : void
ngOnDestroy
ngOnDestroy()
Inherited from AbstractObject3D
Returns : void
ngOnInit
ngOnInit()
Inherited from AbstractObject3D
Returns : void
Protected removeNode
removeNode()
Returns : void
Protected syncGraph
syncGraph()
Returns : void
Protected syncGraphNodes
syncGraphNodes(g: dagre.graphlib.Graph)
Parameters :
Name Type Optional
g dagre.graphlib.Graph No
Returns : void
Protected newObject3DInstance
newObject3DInstance()
Inherited from AbstractObject3D
Defined in AbstractObject3D:8
Returns : THREE.Object3D
Public addChild
addChild(object: AbstractObject3D<any>)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
object AbstractObject3D<any> No
Returns : void
Protected afterInit
afterInit()
Inherited from AbstractObject3D
Returns : void
Public applyRotation
applyRotation()
Inherited from AbstractObject3D
Returns : void
Public applyScale
applyScale()
Inherited from AbstractObject3D
Returns : void
Public applyTranslation
applyTranslation()
Inherited from AbstractObject3D
Returns : void
Public findByName
findByName(name: string)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
name string No
Returns : any
Public getChildren
getChildren()
Inherited from AbstractObject3D
Public getObject
getObject()
Inherited from AbstractObject3D
Returns : T
Public ngAfterViewInit
ngAfterViewInit()
Inherited from AbstractObject3D
Returns : void
Public ngOnChanges
ngOnChanges(changes: SimpleChanges)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
Protected recursionByName
recursionByName(currentNode: AbstractObject3D<any>, name: string)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
currentNode AbstractObject3D<any> No
name string No
Returns : any
Public removeChild
removeChild(object: AbstractObject3D<any>)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
object AbstractObject3D<any> No
Returns : void
Public removeChildByName
removeChildByName(name: string)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
name string No
Returns : void
Public updateParent
updateParent()
Inherited from AbstractObject3D
Returns : void

Properties

container
Type : any
Decorators :
@ViewChild('container', {read: ViewContainerRef, static: true})
Protected dagreLayout
Type : DagreLayoutComponent
Protected graphUpdated
Type : Subscription
Protected childlren
Type : Array<AbstractObject3D<any>>
Default value : []
Inherited from AbstractObject3D
Protected object
Type : T
Inherited from AbstractObject3D
import {Component, Injector, Input, OnDestroy, OnInit, Optional, SkipSelf, ViewChild, ViewContainerRef} from '@angular/core';
import * as dagre from 'dagre';
import {AbstractEmptyDirective, AbstractObject3D} from '../../../object';
import {RendererService} from '../../../renderer';
import {provideParent} from '../../../util';
import {DagreLayoutComponent} from './dagre-layout.component';
import {Subscription} from 'rxjs';

@Component({
  selector: 'atft-dagre-node',
  providers: [provideParent(DagreNodeComponent)],
  template: '<template #container></template><ng-content></ng-content>'
})
export class DagreNodeComponent extends AbstractEmptyDirective implements OnInit, OnDestroy {

  @Input() composition!: string;

  @Input() override translateZ = 0;

  @ViewChild('container', {read: ViewContainerRef, static: true}) container: any;

  protected dagreLayout: DagreLayoutComponent;
  protected graphUpdated: Subscription;

  constructor(
    protected override rendererService: RendererService,
    @SkipSelf() @Optional() protected override parent: AbstractObject3D<any>,
    protected injector: Injector
  ) {
    super(rendererService, parent);
    // console.log('DagreNodeComponent.constructor');

    this.dagreLayout = this.injector.get<DagreLayoutComponent>(DagreLayoutComponent);
    if (!this.dagreLayout) {
      console.warn('DagreNodeComponent.constructor: atft-dagre-layout not found!');
    }

    this.syncGraph = this.syncGraph.bind(this);
    this.graphUpdated = this.dagreLayout.updated.subscribe(this.syncGraph);
  }

  override ngOnInit() {
    super.ngOnInit();
    this.addNode();
  }

  protected addNode() {
    // console.log('DagreNodeComponent.addNode', this.name);
    if (this.dagreLayout && this.dagreLayout.getGraphModel()) {

      // Register as layout children
      this.dagreLayout.getChildren().push(this);

      // Create Graph Node
      this.dagreLayout.getGraphModel().nodes?.push({
        name: this.name,
        label: this.name,
        composition: this.composition
      });

       // Update Graph Layout
      this.dagreLayout.refreshLayout();
    }
  }

  override ngOnDestroy() {
    super.ngOnDestroy();
    this.removeNode();
  }

  protected removeNode() {
    if (this.dagreLayout && this.dagreLayout.getGraphModel()) {
      // console.log('DagreNodeComponent.removeNode', this.name);

      // Unsubscribe from graph update events
      this.graphUpdated?.unsubscribe();

      // Remove from layout
      this.dagreLayout.removeChildByName(this.name);

      // Remove from model
      this.dagreLayout.getGraphModel().nodes = this.dagreLayout.getGraphModel().nodes?.filter(i => i.name !== this.name);

      // Update Graph Layout
      this.dagreLayout.refreshLayout();
    }
  }

  protected syncGraphNodes(g: dagre.graphlib.Graph) {
    // console.log('DagreNodeComponent.syncGraphNodes', g.nodes());
    g.nodes().forEach((name) => {
      // console.log('DagreNodeComponent.syncGraphNodes NODE: ' + name + ': ' + JSON.stringify(g.node(name)));
      if (name === this.name) {
        const node = g.node(name);
        // console.log('DagreNodeComponent.syncGraphNodes: Update position', node);
        this.translateX = node.x;
        this.translateY = node.y;
        this.applyTranslation();
      }
    });
  }

  protected syncGraph() {
    // console.log('DagreNodeComponent.syncGraph');
    if (this.object) {
      this.syncGraphNodes(this.dagreLayout.getGraph());
    }
  }


}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""