gpt4 book ai didi

javascript - 如何在 react 中显示两个节点之间的标签?

转载 作者:行者123 更新时间:2023-12-02 22:27:49 26 4
gpt4 key购买 nike

我正在使用下面的包

https://goodguydaniel.com/react-d3-graph/docs/index.html

https://www.npmjs.com/package/react-d3-graph

我的问题是我的标签没有在两个节点之间显示为什么?

https://codesandbox.io/s/zealous-volhard-lqyvi这是我的代码

const data = {
nodes: [{ id: "Harry" }, { id: "Sally" }, { id: "Alice" }],
links: [
{ source: "Harry", target: "Sally", label: "dddddds" },
{ source: "Harry", target: "Alice", label: "dddddds" }
]
};

我们可以增加初始缩放级别吗?

最佳答案

您需要将labelProperty添加到config中以显示label。您可以像这样将 target/source/label 提供给 labelProperty

const myConfig = {
nodeHighlightBehavior: true,
maxZoom: 3,
minZoom: 1,
node: {
color: "lightgreen",
size: 300,
highlightStrokeColor: "blue",
labelProperty: "id",
symbolType: "circle"
},
link: {
highlightColor: "lightblue",
renderLabel: true,
labelProperty: "target"
}
};

我们可以增加初始缩放级别吗?

不,还没有。查看issue

jsx

// graph payload (with minimalist structure)
const data = {
nodes: [
{
id: "Harry",
symbolType: "diamond",
color: "red",
size: 300
},
{ id: "Sally" },
{ id: "Alice" }
],
links: [
{ source: "Harry", target: "Sally", label: "dddddds" },
{ source: "Harry", target: "Alice", label: "dddddds" }
]
};

// the graph configuration, you only need to pass down properties
// that you want to override, otherwise default ones will be used
const myConfig = {
nodeHighlightBehavior: true,
maxZoom: 3,
minZoom: 1,
node: {
color: "lightgreen",
size: 300,
highlightStrokeColor: "blue",
labelProperty: "id",
symbolType: "circle"
},
link: {
highlightColor: "lightblue",
renderLabel: true,
labelProperty: "source"
}
};

function App() {
return (
<div className="App">
<Graph
id="graph-id" // id is mandatory, if no id is defined rd3g will throw an error
data={data}
config={myConfig}
/>
;
</div>
);
}

关于javascript - 如何在 react 中显示两个节点之间的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59005923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com