File

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

Extends

AbstractEmptyDirective

Implements

OnChanges AfterViewInit

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(rendererService: RendererService, parent: AbstractObject3D<any>, resolver: ComponentFactoryResolver, actorRepository: ActorRepositoryService)
Parameters :
Name Type Optional
rendererService RendererService No
parent AbstractObject3D<any> No
resolver ComponentFactoryResolver No
actorRepository ActorRepositoryService No

Inputs

yaml
Type : string
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
translateZ
Type : number
Inherited from AbstractObject3D

Outputs

status
Type : EventEmitter
changed
Type : EventEmitter
Inherited from AbstractObject3D

Methods

Private createComposition
createComposition(composition: Composition)
Parameters :
Name Type Optional
composition Composition No
Returns : void
Protected createEdge
createEdge(edge: Edge)
Parameters :
Name Type Optional
edge Edge No
Returns : void
Protected createNode
createNode(node: Node)
Parameters :
Name Type Optional
node Node No
Returns : void
Protected destroyAll
destroyAll()
Returns : void
Protected getNodeComponent
getNodeComponent(id: string | undefined)
Parameters :
Name Type Optional
id string | undefined No
Returns : any
ngAfterViewInit
ngAfterViewInit()
Inherited from AbstractObject3D
Returns : void
Public ngOnChanges
ngOnChanges(changes: SimpleChanges)
Inherited from AbstractObject3D
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
Public parseAndCreate
parseAndCreate()
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 ngOnDestroy
ngOnDestroy()
Inherited from AbstractObject3D
Returns : void
Public ngOnInit
ngOnInit()
Inherited from AbstractObject3D
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})
Private instances
Type : any[]
Default value : []
Protected childlren
Type : Array<AbstractObject3D<any>>
Default value : []
Inherited from AbstractObject3D
Protected object
Type : T
Inherited from AbstractObject3D
import {
  AfterViewInit,
  Component,
  ComponentFactoryResolver,
  EventEmitter,
  Input,
  OnChanges,
  Optional,
  Output,
  SimpleChanges,
  SkipSelf,
  ViewChild,
  ViewContainerRef
} from '@angular/core';
import * as yaml from 'yaml';
import {AbstractEmptyDirective, AbstractObject3D} from '../../../object';
import {RendererService} from '../../../renderer';
import {provideParent} from '../../../util';
import {DagreCompositionComponent} from './dagre-composition.component';
import {DagreEdgeComponent} from './dagre-edge.component';
import {Composition, Edge, GraphModel, Node} from './dagre-model';
import {DagreNodeComponent} from './dagre-node.component';
import {ActorRepositoryService} from '../service';


/*
function onlyUnique(value, index, self) {
  return self.indexOf(value) === index;
}
*/

@Component({
  selector: 'atft-dagre-yaml-parser',
  providers: [provideParent(DagreYamlParserComponent)],
  template: `
    <template #container></template>`
})
export class DagreYamlParserComponent extends AbstractEmptyDirective implements OnChanges, AfterViewInit {

  @Input() yaml! : string;

  @Output() status = new EventEmitter<boolean>();

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

  private instances: any[] = [];

  constructor(
    protected override rendererService: RendererService,
    @SkipSelf() @Optional() protected override parent: AbstractObject3D<any>,
    protected resolver: ComponentFactoryResolver,
    protected actorRepository: ActorRepositoryService
  ) {
    super(rendererService, parent);
  }

  override ngAfterViewInit() {
    super.ngAfterViewInit();
    this.parseAndCreate();
  }

  public override ngOnChanges(changes: SimpleChanges) {
    super.ngOnChanges(changes);
    // console.log('DagreYamlParserComponent.ngOnChanges', this.name);

    if (!this.object) {
      return;
    }

    if (['yaml'].some(propName => propName in changes)) {
      this.parseAndCreate();
    }
  }

  public parseAndCreate() {
    // console.log('DagreYamlParserComponent.parseAndCreate');
    if (this.yaml) {
      try {
        this.destroyAll();
        const model: GraphModel = yaml.parse(this.yaml);

        // console.log('DagreYamlParserComponent.parseAndCreate yaml', model);
        if (model && model.nodes && model.nodes.length > 0) {

          model.compositions?.forEach(i => this.createComposition(i));
          model.nodes?.forEach(i => this.createNode(i));
          model.edges?.forEach(i => this.createEdge(i));
        }
        this.status.emit(true);
      } catch (e) {
        console.warn('DagreYamlParserComponent.parseAndCreate failed', e);
        this.status.emit(false);
        throw e;
      }
    }
  }

  protected getNodeComponent(id: string | undefined) {
    return this.actorRepository.getComponentFactory(id);
  }

  protected createNode(node: Node) {
    // console.log('DagreYamlParserComponent.createNode', node);
    const nodeFactory = this.resolver.resolveComponentFactory(DagreNodeComponent);
    const nodeRef = this.container.createComponent(nodeFactory);
    nodeRef.instance.name = node.name;
    nodeRef.instance.composition = node.composition;
    this.instances.push(nodeRef);

    const id = (node.model ? 'model' : node.type);
    const serverFactory = this.getNodeComponent(id);
    const serverRef = nodeRef.instance.container.createComponent(serverFactory);
    serverRef.instance.name = node.name;
    serverRef.instance.label = (node.label ? node.label : node.name);
    serverRef.instance.icon = node.icon;
    serverRef.instance.model = node.model;

    this.instances.push(serverRef);
  }


  protected createEdge(edge: Edge) {
    // console.log('DagreYamlParserComponent.createEdge', edge);
    const factory = this.resolver.resolveComponentFactory(DagreEdgeComponent);
    const edgeRef = this.container.createComponent(factory);
    edgeRef.instance.from = edge.from;
    edgeRef.instance.to = edge.to;
    if (edge.type) {
      edgeRef.instance.type = edge.type;
    }
    if (edge.color) {
      edgeRef.instance.materialColor = edge.color;
    }

    this.instances.push(edgeRef);
  }


  protected destroyAll() {
    // console.log('DagreYamlParserComponent.destroyAll');
    this.instances.forEach(i => {
      // console.log('DagreYamlParserComponent destroy', i);
      i.destroy();
    });
    this.instances = [];
  }


  private createComposition(composition: Composition) {
    // console.log('DagreYamlParserComponent.createComposition', node);
    const factory = this.resolver.resolveComponentFactory(DagreCompositionComponent);
    const compositionRef = this.container.createComponent(factory);
    compositionRef.instance.name = composition.name;
    compositionRef.instance.label = (composition.label ? composition.label : composition.name);
    compositionRef.instance.composition = composition.composition;
    compositionRef.instance.border = composition.border;

    this.instances.push(compositionRef);
  }

}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""