How to plot multiple connectors (straight line) using dynamic data

This is my diagram



I want multiple lines like the selected 1 with dynamic data. I tried to plot using for loop, but it is plotting only last value, there are total 3 lines.

Below is my HTML code

<ejs-diagram #diagram id="diagram" (created)='created($event)' [rulerSettings]='rulerSettings' [getConnectorDefaults] ='getConnectorDefaults'(click)="click($event)">                   
          <e-connectors>
            <e-connector id='connector' type='Straight' [sourcePoint]='sourcePoint' [targetPoint]='targetPoint'>
            </e-connector>
        </e-connectors>
        </ejs-diagram>

Below is my component.ts code

import { ComponentOnInitViewEncapsulationViewChild } from '@angular/core';
import { DiagramComponentNodeModelDiagramToolsConnectorModelPointModelRulerSettingsModel } from '@syncfusion/ej2-angular-diagrams';

@Component({
  templateUrl: 'dashboard.component.html',
  encapsulation: ViewEncapsulation.None 
})

export class DashboardComponent implements OnInit {

//user input
  xaxis:any;
  yaxis:any;
  rwidth:any;
  rlength:any;
  typeid:any;

  //shape properties
  bgcolor:any;
  bordercolor:any;

//layout data
  layout : any[]=
  [

    {
  
      "xaxis": 400,
  
      "yaxis": 200,
  
      "rwidth": 200,
  
      "rlength": 400,
  
      "typeid": 1
  
    },
  
    {
  
      "xaxis": 90,
  
      "yaxis": 50,
  
      "rwidth": 50,
  
      "rlength": 90,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 120,
  
      "yaxis": 50,
  
      "rwidth": 50,
  
      "rlength": 30,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 270,
  
      "yaxis": 50,
  
      "rwidth": 50,
  
      "rlength": 150,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 310,
  
      "yaxis": 10,
  
      "rwidth": 10,
  
      "rlength": 40,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 310,
  
      "yaxis": 30,
  
      "rwidth": 20,
  
      "rlength": 40,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 310,
  
      "yaxis": 50,
  
      "rwidth": 20,
  
      "rlength": 40,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 400,
  
      "yaxis": 50,
  
      "rwidth": 50,
  
      "rlength": 90,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 110,
  
      "yaxis": 140,
  
      "rwidth": 90,
  
      "rlength": 110,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 50,
  
      "yaxis": 200,
  
      "rwidth": 60,
  
      "rlength": 50,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 110,
  
      "yaxis": 200,
  
      "rwidth": 60,
  
      "rlength": 60,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 260,
  
      "yaxis": 90,
  
      "rwidth": 40,
  
      "rlength": 150,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 260,
  
      "yaxis": 130,
  
      "rwidth": 40,
  
      "rlength": 150,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 260,
  
      "yaxis": 170,
  
      "rwidth": 40,
  
      "rlength": 150,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 140,
  
      "yaxis": 200,
  
      "rwidth": 30,
  
      "rlength": 30,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 170,
  
      "yaxis": 200,
  
      "rwidth": 30,
  
      "rlength": 30,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 200,
  
      "yaxis": 200,
  
      "rwidth": 30,
  
      "rlength": 30,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 230,
  
      "yaxis": 200,
  
      "rwidth": 30,
  
      "rlength": 30,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 260,
  
      "yaxis": 200,
  
      "rwidth": 30,
  
      "rlength": 30,
  
      "typeid": 2
  
    },
  
    {
  
      "xaxis": 400,
  
      "yaxis": 200,
  
      "rwidth": 150,
  
      "rlength": 140,
  
      "typeid": 2
  
    }
  
  ]

  //line data
  startx:any;
  starty:any;
  endx:any;
  endy:any;

  line : any[]=
  [
    {
      "startx":500,
      "starty":100,
      "endx":900,
      "endy":500
    },
    {
      "startx":500,
      "starty":200,
      "endx":900,
      "endy":500
    },
    {
      "startx":500,
      "starty":300,
      "endx":900,
      "endy":300
    }
  ];

@ViewChild("diagram")
 
   public diagramDiagramComponent;

   public sourcePointPointModel;
   public targetPointPointModel;
   
   public pivotPointModel;
   
   public rulerSettingsRulerSettingsModel = { showRulers: truedynamicGrid: true }

   public toolDiagramTools;
   
   public node:NodeModel = { };

 //user input
  public drawrectangle()
  {
    // this.layout.map(function(x)
    // {
    //   if (x.xaxis >=+_me.xaxis && x.xaxis <=+_me.yaxis) {
    //     alert("You can not overlap the shapes. Please check the co-ordinates.");
    //     return;
    //   }
    // }    
    // )
      this.node = {
        offsetX: +this.xaxis,
        offsetY: +this.yaxis,        
        width: +this.rlength,
        height: +this.rwidth,
        style: {
            fill: 'pink',
            strokeColor: 'cornflowerblue'
        },
        pivot : { x: 1y: 1 }
      };
      this.diagram.add(this.node);      
  }

//predefined
  public created(): void {  
    var _me = this;  
    this.layout.map(function(shapes)
    {      
      if (shapes.typeid==1) {
        _me.bgcolor='burlywood';
        _me.bordercolor='black';
      }
      else
      {
        _me.bgcolor='azure';
        _me.bordercolor='aqua';
      }
      _me.node = {
        offsetX: shapes.xaxis,
        offsetY: shapes.yaxis,        
        width: shapes.rlength,
        height: shapes.rwidth,
        style: {
            fill: _me.bgcolor,
            strokeColor: _me.bordercolor
        },
        pivot : { x: 1y: 1 }
      };
      _me.diagram.add(_me.node); 
    }
    )

    // Selects when you click a node and pans when you click the Diagram surface
    this.diagram.tool = DiagramTools.Default | DiagramTools.ZoomPan
   }


   public getConnectorDefaults(objConnectorModel) {
    obj.style = {
        strokeColor: '#6BA5D7',
        fill: '#6BA5D7',
        strokeWidth: 2
    }
    obj.targetDecorator = {
        style: {
            fill: 'transparent',
            strokeColor: 'transparent'
        }
    }
}

ngOnInit(): void {

    var _me = this;  
    this.line.map(function(cuts)
    {
      _me.sourcePoint = { x: cuts.startxy: cuts.starty };
      _me.targetPoint = { x: cuts.endxy: cuts.endy };
    }
    )

    // this.sourcePoint = { x: 500, y: 100 };
    // this.targetPoint = { x: 700, y: 100 };

    this.pivot = { x: 1y: 1 };
  }

public click (argsany) {
    alert("X:" + args.actualObject.offsetX + "Y:" + args.actualObject.offsetY + "Width" + args.actualObject.height + "Length" + args.actualObject.width);
    // console.log("offsetX:"+ args.actualObject.offsetX);
   }

}


I want to plot the lines on the diagram which is in aqua border color, but if I keep the same values as a rectangle (x,y) then the line is getting plotted behind rectangle which is not visible.

3 Replies 1 reply marked as answer

AR Aravind Ravi Syncfusion Team June 25, 2020 01:57 PM UTC

Hi Monika,  
  
To bring the connector over node use order commands. By using the order commands or changing the z index of the connector we can able to bring the connector over the node. Select the connector and call diagram public API method BringToFront or through context menu order commands call Bring to front. So that connector come front all over the node and it does not gets hide under the nodes. We have attached a video demonstration that how to use bring to front method.  
  
  
For more information about z order commands and context menu please refer to below UG link  
  
  
  
For your information, please find the Z-order index behavior in our diagram control.  
  
While loading or deserialzing  the diagram elements or during automatic layouting, we used to render all the nodes and then the connectors. In this case, all the connectors will be having the higher z-index value than all the nodes. All the connectors will be positioning above the nodes. 
When creating dynamically through interaction, drag and drop from stencil, or clipboard, we set the z-index value for every element. 
For example:  
1)      First element – consider it as node – its z-index value is set as 0  
2)      Second element  – consider it as connector  – its z-index value is set as 1  
3)      Third element – consider it as connector  – its z-index value is set as 2   
Likewise, zindex value will be increment for each diagram element (node or connector) in the order of addng into the diagram surface.  
  
  
Regards  
Aravind Ravi  


Marked as answer

MS Monika Suresh Gujar July 3, 2020 07:14 AM UTC

Thanks


AR Aravind Ravi Syncfusion Team July 6, 2020 11:17 AM UTC

Hi Monika,  

Thanks for the update.  

Regards 
Aravind Ravi 


Loader.
Up arrow icon