How to manually adjust the scale on Young's visualization?

I have a jung tree displayed in a JPanel. My tree constructor looks like this:

  Forest<String, Integer> graph = new DelegateForest<String, Integer>();
  static GraphZoomScrollPane panel = null;
  static DefaultModalGraphMouse graphMouse = null;
  static JComboBox modeBox = null;
  static ScalingControl scaler;

  public PanelTree(List<Cluster> clist) {
    setBounds(215, 10, 550, 550);
    updateData(clist); // adds vertex and edges to graph

    treeLayout = new TreeLayout<String, Integer>(graph);
    vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(500, 500));
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller());
            .setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));

    panel = new GraphZoomScrollPane(vv);

    graphMouse = new DefaultModalGraphMouse();


    modeBox = graphMouse.getModeComboBox();

    scaler = new CrossoverScalingControl();


But the tree is pretty big. So I want to know if there is a way to automatically zoom out so that the tree fits into the windows, and otherwise just set the default scale to less than the default. How can i do this?


source to share

2 answers

ScalingControl scaler = new CrossoverScalingControl();

public void zoomIn() {

public void zoomOut() {

private void setZoom(int amount) {
    scaler.scale(vv, amount > 0 ? 1.1f : 1 / 1.1f, vv.getCenter());


To fit the graph in the window, you can calculate the difference between the graph size and the pane size and call the setZoom () method passing the difference coefficient.



ScalingControl is not a good method if you are using Mouse Transformer.


// for zoom:
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setScale(scale_x1, scale_y1, vv.getCenter());
// for out:
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setScale(scale_x2, scale_y2, vv.getCenter());




All Articles