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} />

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

在此处输入图像描述

我希望它看起来像这样:

在此处输入图像描述

我怎样才能在 React 上实现这一点?

提前致谢

4

1 回答 1

0

您需要在 stable 事件中调用 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);
        }}
    />
于 2021-10-04T11:54:15.917 回答