dagrejs / dagre

Directed graph layout for JavaScript
MIT License
4.72k stars 606 forks source link

When I have a lot of data to dagre.layout, it takes a long time.Is there an optimization scheme? #275

Open walk-liuyan opened 5 years ago

walk-liuyan commented 5 years ago

traceData.nodeList.length = 351 traceData.lineList.length = 2742

    console.log('start ->',new Date())
    let g = new dagre.graphlib.Graph();
    g.setGraph({ rankdir: 'LR' });
    g.setDefaultEdgeLabel(() => { return {}; });

    console.log('start, set data ->', new Date())

    traceData.nodeList.forEach(node => {
      g.setNode(node.nodeCode,  { label: node.nodeCode, width: 150, height: 30 });
    })
    console.log('setNode ->',new Date())

    traceData.lineList.forEach(edge => {
      g.setEdge(edge.fromNode, edge.toNode)
    })
    console.log('setEdge ->',new Date())

    dagre.layout(g)
    console.log('end, set data ->', new Date())

log result:

start -> Mon Jul 22 2019 23:40:38 GMT+0800 
start, set data -> Mon Jul 22 2019 23:40:38 GMT+0800
setNode -> Mon Jul 22 2019 23:40:38 GMT+0800 
setEdge -> Mon Jul 22 2019 23:40:38 GMT+0800
end, set data -> Mon Jul 22 2019 23:43:21 GMT+0800

Finish running:dagre.layout(g), It took three minutes. Is there an optimization scheme. THX!

laochake commented 3 years ago

traceData.nodeList.length = 351 traceData.lineList.length = 2742

    console.log('start ->',new Date())
    let g = new dagre.graphlib.Graph();
    g.setGraph({ rankdir: 'LR' });
    g.setDefaultEdgeLabel(() => { return {}; });

    console.log('start, set data ->', new Date())

    traceData.nodeList.forEach(node => {
      g.setNode(node.nodeCode,  { label: node.nodeCode, width: 150, height: 30 });
    })
    console.log('setNode ->',new Date())

    traceData.lineList.forEach(edge => {
      g.setEdge(edge.fromNode, edge.toNode)
    })
    console.log('setEdge ->',new Date())

    dagre.layout(g)
    console.log('end, set data ->', new Date())

log result:

start -> Mon Jul 22 2019 23:40:38 GMT+0800 
start, set data -> Mon Jul 22 2019 23:40:38 GMT+0800
setNode -> Mon Jul 22 2019 23:40:38 GMT+0800 
setEdge -> Mon Jul 22 2019 23:40:38 GMT+0800
end, set data -> Mon Jul 22 2019 23:43:21 GMT+0800

Finish running:dagre.layout(g), It took three minutes. Is there an optimization scheme. THX!

hugh, did you finally find that optimization scheme?