How to manually set the zoom on a Jung visualisation?

后端 未结 2 1661
囚心锁ツ
囚心锁ツ 2021-01-20 10:47

I have a jung tree displayed in a JPanel. The constructor of my tree looks like this:

  Forest graph = new DelegateForest

        
相关标签:
2条回答
  • 2021-01-20 11:18

    ScalingControl is not good method if you use Mouse Transformer.

    Try to:

    // 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());
    
    0 讨论(0)
  • 2021-01-20 11:32
    ScalingControl scaler = new CrossoverScalingControl();
    
    public void zoomIn() {
        setZoom(1);
    }
    
    public void zoomOut() {
        setZoom(-1);
    }
    
    private void setZoom(int amount) {
        scaler.scale(vv, amount > 0 ? 1.1f : 1 / 1.1f, vv.getCenter());
    }
    

    To fits the graph on the window, you can calculate the diference between the graph size and the panel size, and call the setZoom() method passing the factor of diference.

    0 讨论(0)
提交回复
热议问题