How to manually set the zoom on a Jung visualisation?

后端 未结 2 1684
囚心锁ツ
囚心锁ツ 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: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.

提交回复
热议问题