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



我正在使用下面的包

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>
  );
}

相关内容

  • 没有找到相关文章

最新更新