如何调整或缩小React Vis.JS网络图?

问题描述 投票:0回答:2

晚上好, 我的网络图有以下设置:

const exceptionsGraph = {
        nodes: graph,
        edges: edges
    }

// Graph Options
const options = {
    height: "80%",
    width: "100%",
    nodes: {
        shape: "dot",
        size: 16
    },
    layout: {
        hierarchical: false
    },
    physics: {
        forceAtlas2Based: {
            gravitationalConstant: -26,
            centralGravity: 0.005,
            springLength: 230,
            springConstant: 0.18,
        },
        maxVelocity: 146,
        solver: "forceAtlas2Based",
        timestep: 0.35,
        stabilization: {
            enabled: true,
            iterations: 2000,
            updateInterval: 25,
        },
    },
    edges: {
        color: "#abb4be"
    }
}    

然后我这样称呼它:

<Graph graph={exceptionsGraph} options={options} />

但是当它渲染时,它全部放大了,所以看起来很糟糕。像这样:

enter image description here

我希望它看起来像这样:

enter image description here

如何在 React 上实现这一目标?

提前致谢

reactjs vis.js react-graph-vis
2个回答
1
投票

您需要在稳定事件内部调用 fit 函数。

声明事件对象并定义稳定:

const events = {
    stabilized: () => {
            if (network) { // Network will be set using getNetwork event from the Graph component
                network.setOptions({ physics: false }); // Disable physics after stabilization
                network.fit();
            }
        }
    };

这就是定义 Graph 组件的方式:

<Graph
        graph={graph}
        options={options}
        events={events}
        getNetwork={network => {
         setNetwork(network);
        }}
    />

0
投票

您可以使用“interaction”属性的“navigationButtons”属性来放置放大/缩小按钮

© www.soinside.com 2019 - 2024. All rights reserved.