user12130378
user12130378

Reputation:

how to show label between two nodes in react?

I am using below package

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

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

my issue is my label is not showing between two nodes why ?

https://codesandbox.io/s/zealous-volhard-lqyvi here is my code

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

can we increase the initial zoom level ?

Upvotes: 0

Views: 329

Answers (1)

blueseal
blueseal

Reputation: 2908

You need to add labelProperty to the config to show label. you can provide target/source/label to labelProperty like so

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

can we increase the initial zoom level ?

No, not yet. check out the 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>
  );
}

Upvotes: 2

Related Questions