projects/atft/src/lib/actor/data-center/layout/dagre-yaml-parser.component.ts
OnChanges
AfterViewInit
providers |
provideParent(DagreYamlParserComponent)
|
selector | atft-dagre-yaml-parser |
template |
|
Properties |
Methods |
|
Inputs |
Outputs |
constructor(rendererService: RendererService, parent: AbstractObject3D<any>, resolver: ComponentFactoryResolver, actorRepository: ActorRepositoryService)
|
|||||||||||||||
Parameters :
|
yaml | |
Type : string
|
|
layer | |
Type : number
|
|
Default value : 0
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:42
|
name | |
Type : string
|
|
Default value : uuidv4()
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:40
|
rotateX | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:24
|
|
Rotation in Euler angles (radians) with order X, Y, Z. |
rotateY | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:25
|
rotateZ | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:26
|
scaleX | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:36
|
scaleY | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:37
|
scaleZ | |
Type : number
|
|
Default value : 1
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:38
|
translateX | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:31
|
|
Translate the geometry. This is typically done as a one time operation, and not during a loop. |
translateY | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:32
|
translateZ | |
Type : number
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:33
|
status | |
Type : EventEmitter
|
|
changed | |
Type : EventEmitter
|
|
Inherited from
AbstractObject3D
|
|
Defined in
AbstractObject3D:44
|
Private createComposition | ||||||
createComposition(composition: Composition)
|
||||||
Parameters :
Returns :
void
|
Protected createEdge | ||||||
createEdge(edge: Edge)
|
||||||
Parameters :
Returns :
void
|
Protected createNode | ||||||
createNode(node: Node)
|
||||||
Parameters :
Returns :
void
|
Protected destroyAll |
destroyAll()
|
Returns :
void
|
Protected getNodeComponent | ||||||
getNodeComponent(id: string | undefined)
|
||||||
Parameters :
Returns :
any
|
ngAfterViewInit |
ngAfterViewInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:57
|
Returns :
void
|
Public ngOnChanges | ||||||
ngOnChanges(changes: SimpleChanges)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:62
|
||||||
Parameters :
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
|
||||||
Defined in
AbstractObject3D:143
|
||||||
Parameters :
Returns :
void
|
Protected afterInit |
afterInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:156
|
Returns :
void
|
Public applyRotation |
applyRotation()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:118
|
Returns :
void
|
Public applyScale |
applyScale()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:135
|
Returns :
void
|
Public applyTranslation |
applyTranslation()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:127
|
Returns :
void
|
Public findByName | ||||||
findByName(name: string)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:185
|
||||||
Parameters :
Returns :
any
|
Public getChildren |
getChildren()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:202
|
Returns :
Array<AbstractObject3D<any>>
|
Public getObject |
getObject()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:175
|
Returns :
T
|
Public ngOnDestroy |
ngOnDestroy()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:86
|
Returns :
void
|
Public ngOnInit |
ngOnInit()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:97
|
Returns :
void
|
Protected recursionByName | |||||||||
recursionByName(currentNode: AbstractObject3D<any>, name: string)
|
|||||||||
Inherited from
AbstractObject3D
|
|||||||||
Defined in
AbstractObject3D:192
|
|||||||||
Parameters :
Returns :
any
|
Public removeChild | ||||||
removeChild(object: AbstractObject3D<any>)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:160
|
||||||
Parameters :
Returns :
void
|
Public removeChildByName | ||||||
removeChildByName(name: string)
|
||||||
Inherited from
AbstractObject3D
|
||||||
Defined in
AbstractObject3D:206
|
||||||
Parameters :
Returns :
void
|
Public updateParent |
updateParent()
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:111
|
Returns :
void
|
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
|
Defined in
AbstractObject3D:46
|
Protected object |
Type : T
|
Inherited from
AbstractObject3D
|
Defined in
AbstractObject3D:48
|
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);
}
}