Diagram nodes and connectors not displaying properly

hi,

I tried to display dynamic collection of nodes and connectorsUntitled.png .But its not displaying properly.

@using Syncfusion.Blazor.Diagram

@using System.Net.Http

@inject HttpClient Http

@using FamilyTree_Application.Data

@using Syncfusion.Blazor.Data


<h3>MemberTree</h3>


<SfDiagramComponent Height="600px" Nodes="@nodes" Connectors="@connectors" NodeCreating="@OnNodeCreating" ConnectorCreating="@OnConnectorCreating">

    <Layout Type="LayoutType.HierarchicalTree" @bind-HorizontalSpacing="@HorizontalSpacing" @bind-VerticalSpacing="@VerticalSpacing">

    </Layout>

</SfDiagramComponent>


@code

{

    protected List<Node_data> Node_Datas = new List<Node_data>();

    protected List<Connector_data> Connector_Datas = new List<Connector_data>();

    int left = 40;

    int top = 50;

    DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>();

    DiagramObjectCollection<Connector> connectors = new DiagramObjectCollection<Connector>();

    int HorizontalSpacing = 40;

    int VerticalSpacing = 40;


    private void OnNodeCreating(IDiagramObject obj)

    {

        Node node = obj as Node;

        node.Height = 40;

        node.Width = 100;

        //Initializing the default node's shape style.

        node.Style = new ShapeStyle() { Fill = "darkcyan", StrokeWidth = 3, StrokeColor = "Black" };

        node.Annotations = new DiagramObjectCollection<ShapeAnnotation>()

{

            new ShapeAnnotation

            {

                Content = node.Annotations[0].Content,

                Style = new TextStyle() { Color = "white", Bold = true },

            }

        };

    }


    private void OnConnectorCreating(IDiagramObject connector)

    {

        (connector as Connector).Type = ConnectorSegmentType.Orthogonal;

    }


    protected override async Task OnInitializedAsync()

    {


        Node_Datas = await Http.GetFromJsonAsync<List<Node_data>>("sample-data/node1.json");

        Connector_Datas = await Http.GetFromJsonAsync<List<Connector_data>>("sample-data/connect1.json");



        foreach (var a in Node_Datas)

        {

            Node node= new Node()

            {

                ID = a.ID,Annotations = new DiagramObjectCollection<ShapeAnnotation>() { new ShapeAnnotation { Content = a.Content} },

            };

            nodes.Add(node);

        }

        connectors = new DiagramObjectCollection<Connector>();

        foreach (var a in Connector_Datas)

        {

            Connector connector= new Connector() { ID = a.ID, SourceID = a.Source_Id, TargetID = a.Target_Id };

            connectors.Add(connector);

        }

    }

}



9 Replies

RA Ranjitha Amirthalingam Syncfusion Team April 26, 2022 09:01 AM UTC

Hi Jyothi,


We understood that you are making await call before data initialization in the OnInitializedAsync method from the given details. This method will execute only one time. If a component is refreshed say a parent component refreshes a child component, this method is completely skipped upon refresh. When you call await(delay) before executing logic(nodes and connectors initialization), a refresh is needed. So, you need to call the DoLayout() either in the external button click or in the OnAfterRenderAsync() method. We have provided the code example to call the DoLayout in the OnAfterRenderAsync method.


Code Example:

bool isUpdate = true;

    protected override Task OnAfterRenderAsync(bool firstRender)

    {

        if (isUpdate && Diagram!=null && Diagram.Nodes.Count>0 && Diagram.Connectors.Count>0)

        {

            _=Diagram.DoLayout();

            isUpdate = false;

        }

        return base.OnAfterRenderAsync(firstRender);

    }

 




Regards,

Ranjitha A.



JL jyothi lekshmi replied to Ranjitha Amirthalingam April 28, 2022 10:07 AM UTC

Hi Ranjitha,

Thank you for your reply. But its not helping. On page load dispayserror2.png one arrow, after clicking arrow it shows nodes and connectors.error1.png



RA Ranjitha Amirthalingam Syncfusion Team April 29, 2022 02:14 PM UTC

Hi Jyothi,


We have prepared a simple sample to replicate the issue in our end. And we have called the DoLayout in the OnAfterRenderAsync() method as per our previous update. The reported issue is not reproduced in our end. We have shared the sample for your reference.


If the reported scenario is different from the provided sample, please replicate the issue in the provided sample and revert us. These details helps us to look into the issue further.


Also, please share your Syncfusion product version.


Regards,

Ranjitha A.


Attachment: Sample174617_f88205d4.zip


JL jyothi lekshmi April 30, 2022 03:35 AM UTC

hi Ranjitha,

I am using web assembly progressive web app and syncfusion 20.1.0.47 version. Again same issue, no changes in the webpage. Two db tables Node_data and Connector_Data. Node collection and connector collection get from json files. 



RA Ranjitha Amirthalingam Syncfusion Team May 2, 2022 01:57 PM UTC

Hi Jyothi,


Have you faced any console exception while trying to render the layout?


If yes, please share the exception details with us. If possible, please share your application or else share video input to replicate the issue at our end.


Regards,

Ranjitha A.



JL jyothi lekshmi May 4, 2022 03:58 AM UTC

Hi Ranjitha,

please find the attached file.


Attachment: Diagram1_c4c744e0.zip


RA Ranjitha Amirthalingam Syncfusion Team May 4, 2022 04:14 PM UTC

Hi Jyothi,


We have tried to replicate the issue with the files which you have shared in the previous update. However, node1.json and connector1.json files were needed. So, we have tried the same scenario as you did by passing nodes and connectors as separate json files in GetFromJsonAsync method. But we are facing console exception. We have shared the exception details and json files for your reference.


Could you please share the json files or please update the values in the shared json files? This helps us to proceed with the issue further.



Regards,

Ranjitha A.


Attachment: JsonFilesException_a9b919a6.zip


JL jyothi lekshmi May 5, 2022 03:23 AM UTC

hi Ranjitha,

please find the attached json files.


Attachment: sample_b36857b.zip


RA Ranjitha Amirthalingam Syncfusion Team May 6, 2022 04:02 PM UTC

Hi Jyothi,


Thanks for sharing the files.


We could able to run the application with the shared files. As informed earlier, we are facing console exception and have shared the sample and console log details for your reference.


Could you please run the provided(shared by us in this update) application on your end and record the output as a video along with the console window details and share it with us? We can move forward with this issue based on these details.


Also, please share your system configuration details like OS, Visual Studio version, culture (machine language) details.


Regards,

Ranjitha A.


Attachment: SampleConsole_48bb1eb9.zip

Loader.
Up arrow icon