2017-03-14 6 views
0

Ich verwende Cytoscape, um ein Diagramm anzuzeigen, deren Knoten sich überlappen können. Ich möchte das vermeiden, aber ohne die Position y jedes Knotens zu ändern. Ich verwende die Position y eines Knotens, um Ebenen zu verwalten, aber die Position x kann problemlos variieren.Erstellen Sie ein Diagramm mit Cytoscape ohne Überlappungen



     $.getJSON("/stratifiant/cytoscape", function(data) { 
      var cy = cytoscape({ 
       container: document.getElementById('container'), 
       elements: data, 
       style: [{ 
        selector: 'node', 
        style: { 
         shape: 'rectangle', 
         'background-color': 'red', 
         label: 'data(label)' 
        } 
       }] 
      }); 
     }); 

JSON:



    { 
     "nodes" : [ { 
     "data" : { 
      "x" : 0, 
      "y" : 0, 
      "id" : "120510", 
      "label" : "SOG.1006" 
     } 
     }, { 
     "data" : { 
      "x" : 100, 
      "y" : 0, 
      "id" : "120487", 
      "label" : "SOG.1005" 
     } 
     }, { 
     "data" : { 
      "x" : 200, 
      "y" : 0, 
      "id" : "120188", 
      "label" : "SOG.1002" 
     } 
     }, { 
     "data" : { 
      "x" : 300, 
      "y" : 0, 
      "id" : "120189", 
      "label" : "SOG.1003" 
     } 
     }, { 
     "data" : { 
      "x" : 400, 
      "y" : 0, 
      "id" : "120537", 
      "label" : "SOG.1008" 
     } 
     }, { 
     "data" : { 
      "x" : 0, 
      "y" : 100, 
      "id" : "120179", 
      "label" : "SOG.1000" 
     } 
     }, { 
     "data" : { 
      "x" : 100, 
      "y" : 100, 
      "id" : "120187", 
      "label" : "SOG.1001" 
     } 
     }, { 
     "data" : { 
      "x" : 0, 
      "y" : 200, 
      "id" : "120536", 
      "label" : "SOG.1007" 
     } 
     }, { 
     "data" : { 
      "x" : 100, 
      "y" : 200, 
      "id" : "120190", 
      "label" : "SOG.1004" 
     } 
     } ], 
     "edges" : [ { 
     "data" : { 
      "id" : "s120510-120487", 
      "source" : "120510", 
      "target" : "120487" 
     } 
     }, { 
     "data" : { 
      "id" : "a120179-120188", 
      "source" : "120179", 
      "target" : "120188" 
     } 
     }, { 
     "data" : { 
      "id" : "s120179-120187", 
      "source" : "120179", 
      "target" : "120187" 
     } 
     }, { 
     "data" : { 
      "id" : "a120536-120187", 
      "source" : "120190", 
      "target" : "120187" 
     } 
     }, { 
     "data" : { 
      "id" : "s120536-120190", 
      "source" : "120536", 
      "target" : "120190" 
     } 
     } ] 
    } 

Welche Layout sollte ich mit Cytoscape verwenden mit welchen Optionen?

Antwort

1

könnten Sie ein Layout verwenden, so müssen Sie nicht für jeden Knoten die specyfic Stelle gesetzt. Meine Empfehlung für Sie ist das dagre oder breadthfirst Layout.

$.getJSON("/stratifiant/cytoscape", function(data) { 
     var cy = cytoscape({ 
      container: document.getElementById('container'), 
      elements: data, 
      layout:{ 
       name:'dagre', 
      }, 
      style: [{ 
       selector: 'node', 
       style: { 
        shape: 'rectangle', 
        'background-color': 'red', 
        label: 'data(label)' 
       } 
      }] 
     }); 
    }); 
Verwandte Themen