question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dagre Rendering Fails Based On Compound Node Element Order

See original GitHub issue

Description

The “dagre” layout produces badly formatted layouts when the parent node follows children nodes in the list of elements. This isn’t noted in the documentation, to my knowledge.

Steps/Code to Reproduce

import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html

import dash_cytoscape as cyto

cyto.load_extra_layouts()

app = dash.Dash(__name__)

elements = [
    {
        "data": { 
            "id": "1",
            "label": "1",
        }
    },

    {
        "data": { 
            "id": "2_parent",
            "label": "2_parent",
        }
    },

    {
        "data": { 
            "id": "2",
            "label": "2",
            "parent": "2_parent",
        }
    },

    {
        "data": {
            "source": "1",
            "target": "2",
        }
    }
]

app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape-compound',
        layout={
            "name": "dagre",
            "nodeDimensionsIncludeLabels": "true",
            "animate": "true",
        },
        style={'width': '50%', 'height': '400px', "background-color": "azure",},
        stylesheet=[
            {
                'selector': 'node',
                'style': {'content': 'data(label)'}
            },
            {
                "selector": "edge",
                "style": {
                    "curve-style": "straight",
                    "target-arrow-shape": "triangle",
                    "arrow-scale": 2,
                },
            },
        ],
        elements=elements,
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

Above is the working code. To reproduce, swap the 2nd and 3rd elements in the elements list.

elements = [
    {
        "data": { 
            "id": "1",
            "label": "1",
        }
    },

    {
        "data": { 
            "id": "2",
            "label": "2",
            "parent": "2_parent",
        }
    },

    {
        "data": { 
            "id": "2_parent",
            "label": "2_parent",
        }
    },

    {
        "data": {
            "source": "1",
            "target": "2",
        }
    }
]

Alternatively, insert elements = elements[::-1].

Expected Results

From working example: image

Actual Results

From broken example: image

Notice that not all elements are in the viewport. This is the output after zooming out: image

The output is also not deterministic. Sometimes the layout renders like this: image

Zoomed out: image

However, the rendering is fine in any order when the “animate” option isn’t specified in the layout dictionary ("animate": "false" still fails). Omitting the “animate” option yields: image

Versions

Dash 1.16.0 Dash Core Components 1.1.1 Dash HTML Components 1.12.0 Dash Renderer 1.8.0 Dash Cytoscape 0.2.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
riverchen99commented, Nov 5, 2020

Thanks for your help @xhlulu ! Your gist with reproduces the error when I try to run it. Will open a PR in the dagre repo. Appreciate your help!

1reaction
xhlucacommented, Nov 4, 2020

This is definitely a strange issue. I tried to run it locally and it seems to work in v0.1.1 but not in v0.2.0, so I’m suspecting it is linked to #106 .

Were you able to run the steps described in this comment with your graph? If it has the same behavior (i.e. the problem appears after 4cba5bcc8aa8110b5365c0995e177b318e09c18d), then I believe this problem can be solved at the same time as #106

Given sufficient bandwidth, I’ll spend some time looking into this issue (along with the previous issue). In the meantime, I recommend using Dash Cytoscape v0.1.1 if you do not need image export and responsive relayout.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deal with multiple trees situation when using dagre ...
I'm new to Cytoscape.js and trying to draw a graph with the help of Dagre layout depending on users' search input. Number of...
Read more >
dagre - npm
Rendering agnostic. Dagre requires only very basic information to lay out graphs, such as the dimensions of nodes. You're free to render the ......
Read more >
Using layouts - Cytoscape.js
The problem, then, is to filter the elements to show only a relevant subset of ... By using filtering and layout based on...
Read more >
Make interactive node-based graphs with React Flow.
To make a new graph we need to add elements, some styling and render them. First, make the elements object containing the necessary...
Read more >
Cytoscape Reference - Python - Dash Plotly
id (string): Reference to the element, useful for selectors and edges. ... layouts: - fit (boolean): Whether to render the nodes in order...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found