ng-flowchart icon indicating copy to clipboard operation
ng-flowchart copied to clipboard

Root job is not centering

Open JadeWilson94 opened this issue 3 years ago • 8 comments

Currently when I initally render my step component, it's not rendering the component in the top-center of the page: image However when I resize the page it re-centres it fine: image

 import { Component, ViewChild, Input, ChangeDetectorRef} from '@angular/core';
 import { NgFlowchart, NgFlowchartCanvasDirective, NgFlowchartStepRegistry } from '@joelwenzel/ng-flowchart';
 import { Job, JobStepComponent } from './Steps/jobstep.component';
 import { Schedule, ScheduleStepComponent } from './Steps/schedulestep.component';
 import { Task, TaskStepComponent } from './Steps/taskstep.component';

@Component({
  selector: 'cui-system-job-workflow-page',
  templateUrl: './workflow.component.html',
  styleUrls: ['../style.component.scss'],
})
export class WorkflowComponent {
  @Input() job: any;

  callbacks: NgFlowchart.Callbacks = {};
  options: NgFlowchart.Options = {
    stepGap: 40,
    rootPosition: 'TOP_CENTER'
  };

  @ViewChild(NgFlowchartCanvasDirective)
  canvas: NgFlowchartCanvasDirective;
  
  constructor(private stepRegistry: NgFlowchartStepRegistry, private cdref: ChangeDetectorRef) {
    this.callbacks.onDropError = this.onDropError;
    this.callbacks.onMoveError = this.onMoveError;
  }

  ngAfterViewInit() {
    this.stepRegistry.registerStep('job-step', JobStepComponent);
    this.stepRegistry.registerStep('schedule-step', ScheduleStepComponent);
    this.stepRegistry.registerStep('task-step', TaskStepComponent);

    var startingFlow =
    '{"root":{"id":"s1624491702043","type":"job-step","data":' + JSON.stringify(this.job) + ',"children":[]}}';
    
    let flow: NgFlowchart.Flow  = this.canvas.getFlow()
    flow.upload(startingFlow);
    this.cdref.detectChanges();
  }

  onDropError(error: NgFlowchart.DropError) {
    console.log(error);
  }

  onMoveError(error: NgFlowchart.MoveError) {
    console.log(error);
  }
}

I'm not sure what I'm doing wrong, I've tried re-rendering it as well, is there anything I am missing?

JadeWilson94 avatar Sep 27 '21 12:09 JadeWilson94

What version of the package are you using? Can you recreate the issue in a stackblitz?

michaelmarcuccio avatar Sep 27 '21 22:09 michaelmarcuccio

@michaelmarcuccio it's version 1.0.1-beta. unfortunately I cannot recreate the issue on stackblitz, but the only difference being that it's in a modal in my application? https://stackblitz.com/edit/ng-flowchart-workflow-dbhqh?file=src/app/app.component.ts

My workaround for the time being is that I'm calling the render method in ngAfterViewChecked(), which updates the view and centres the workflow.

JadeWilson94 avatar Sep 29 '21 10:09 JadeWilson94

Try version 1.0.0-beta.9 which is the most recent version.

michaelmarcuccio avatar Sep 29 '21 10:09 michaelmarcuccio

I believe this solves the problem if you are still having the issue: setTimeout(() => flow.upload(startingFlow));

Reason being you need to wait until next cycle after afterViewInit to upload a flow.

michaelmarcuccio avatar Oct 04 '21 15:10 michaelmarcuccio

I've upgraded to 1.0.0-beta.9 and used setTimeout(() => flow.upload(startingFlow)) but still having same issue. It needing to wait until next cycle makes sense why uploading the flow in ngAfterViewChecked() works though.

JadeWilson94 avatar Oct 04 '21 18:10 JadeWilson94

@JadeWilson94 So just to confirm it is working as expected in after init and on next tick correct?

joel-wenzel avatar Oct 04 '21 23:10 joel-wenzel

@joel-wenzel no that's not what's occurring. I still am getting the same issue when I try:  setTimeout(() => flow.upload(startingFlow)) in the ngAfterViewInit()... however as a workaround I re-render the flow in ngAfterViewChecked()

JadeWilson94 avatar Oct 05 '21 05:10 JadeWilson94

@JadeWilson94 Are you using changeDetection onPush by chance in your component containing the flow?

joel-wenzel avatar Oct 06 '21 00:10 joel-wenzel