How to manually set the zoom on a Jung visualisation?

落爺英雄遲暮 提交于 2019-12-01 20:39:36
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.

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());
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!