我正在使用下面的包
https://goodguydaniel.com/react-d3-graph/docs/index.html
https://www.npmjs.com/package/react-d3-graph
我的问题是my label is not showing between two nodes
为什么?
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
。 您可以像这样为labelProperty
提供target
/source
/label
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"
}
};
我们可以增加初始缩放级别吗?
不,还没有。查看问题
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>
);
}