在vis js网络中设置默认比例

Set default scale in vis js network

我正在使用 vis.js 库来创建网络拓扑。在我创建网络后使用:

network = new vis.Network(container, data, options);

其中容器是我正在绘制的 canvas

数据:

{
    nodes: Nodes,
    edges: Edges
};

选项:

{ 
    autoResize: true,
    nodes: {
        shape: 'image',
        size:  25,
        font: {
            size: 16,
            color: 'darkbrown'
        },
        borderWidth: 0,
        shadow: true
    },
    edges: {
        smooth: {
            forceDirection: "none"
        }
    },
    physics: {
        forceAtlas2Based: {
            springLength: 80,
            springConstant: 0.27
        },
        minVelocity: 0.75,
        solver: "forceAtlas2Based",
        timestep: 0.34
    },
    layout: {
        randomSeed: undefined
    },
    interaction: {
        hover: true
    }
}

绘制后,默认比例 (1) 相对于我的 canvas 非常大。我想调整比例。我试过这种方式:

network = new vis.Network(container, data, options); //network is drawn

var scaleOption = { scale : 0.5 }; -(1) 

network.moveTo(scaleOption); -(2)

这样不行。但是,如果 (1) 和 (2) 在特定事件中触发,请说:

network.on("click",function(params) {

    var scaleOption = { scale : 0.5 };
    network.moveTo(scaleOption);
}); 

有效。我需要在一开始就设置比例,即在绘制拓扑之后(在任何此类事件发生之前)。 AfterDrawing 绘制拓扑后事件不断触发,因此也失败了。有什么办法可以解决这个问题?

首次绘制网络时,使用 stabilized 事件和 once 方法缩小网络。

network.once('stabilized', function() {
    var scaleOption = { scale : 0.5 };
    network.moveTo(scaleOption);
})