2012-11-05 2 views
0

JUNG을 사용하여 일부 그래프를 만들고 시각화했습니다. 노드의 중심은 레이아웃 알고리즘에 의해 좌표가 주어진다. 따라서 노드가 창 가장자리에 있으면 해당 노드 중 일부가 잘릴 것입니다 (노드 레이블 일 수도 있습니다). 나는 JUNG 이슈인지 또는 JFrame/GUI 이슈인지 잘 모르겠다. (나는 자바 GUI 개발에 익숙하지 않다.) 그래프 이미지 (600x600)의 최대 크기를 창 (800x800) 크기보다 작게하려고했습니다. setLocation()을 사용하여 그래프를 중앙에 놓으려고했으나 작동하지 않는 것 같습니다. 그래프를 중앙에 놓아도 문제를 해결할 수 있는지 확실하지 않습니다.시각화에 JUNG 노드가 잘립니다.

여기 내 코드가 있습니다.

import java.awt.Dimension; 
import javax.swing.*; 

import edu.uci.ics.jung.graph.*; 
import edu.uci.ics.jung.visualization.VisualizationImageServer; 
import edu.uci.ics.jung.algorithms.layout.SpringLayout; 
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller; 
import edu.uci.ics.jung.algorithms.generators.random.EppsteinPowerLawGenerator; 
import edu.uci.ics.jung.visualization.decorators.EdgeShape; 
import org.apache.commons.collections15.Factory; 

public class Main { 

    public static void main(String[] args) { 

     // Factories required for the graph generator 
     Factory <Integer> vertexFactory = new Factory<Integer>() { 
      int vertexCount = 0; 
      public Integer create() { 
       return vertexCount++; 
      } 
     }; 

     Factory <Integer> edgeFactory = new Factory<Integer>() { 
      int edgeCount = 0; 
      public Integer create() { 
       return edgeCount++; 
      } 
     }; 

     Factory<Graph<Integer,Integer>> graphFactory = new Factory<Graph<Integer,Integer>>() { 
      public Graph<Integer,Integer> create() { 
       return new UndirectedSparseGraph<Integer, Integer>(); 
      } 
     }; 

     int numVertices = 150; 
     int numEdges = 150; 
     int numIter = 100;  
     // Create a graph using a power law generator 
     EppsteinPowerLawGenerator gen = new EppsteinPowerLawGenerator(graphFactory, vertexFactory, edgeFactory, numVertices, numEdges, numIter);  
     Graph<Integer, Integer> graph = gen.create(); 

     // Visualization of graph 
     SpringLayout layout = new SpringLayout(graph); 
     layout.setSize(new Dimension(600,600)); 
     VisualizationImageServer vs = new VisualizationImageServer(layout, new Dimension(800, 800)); 
     vs.setLocation(100,700); // seems to have no effect 
     vs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); 
     vs.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, Number>()); 

     JFrame frame = new JFrame(); 
     frame.add(vs); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.pack(); 
     frame.setVisible(true); 
    } 
} 

답변

1

이에게 탄 보내기 또한

float factor = 0.5; 
ScalingControl scalingControl = new CrossoverScalingControl(); 
scalingControl.scale(vs, factor, vs.getCenter()); 

을, 당신은 스윙 프레임에 직접 추가되어서는 안되며, 오히려 사용하여 컨텐츠 창에 추가해야합니다

frame.getContentPane().add(...)