g6/packages/site/docs/manual/middle/elements/advanced-style/set-label-bg.en.md
2023-02-02 10:31:36 +08:00

1.0 KiB
Raw Blame History

title order
Set the background of the label on node or edge 0

Problem

In versions below G6 3.4.4, when we want to add the background to label of a node or edge, wo need use group.addShape('rect', {}) to implement it, the implementation method is not friendly enough.

Solution

In G6 3.4.5 version, uses can set the background for nodes or edges through background configuration.

Important Hint The PR comes from GitHub use @zhanba.

const graph = new G6.Graph({
  // ...
  defaultNode: {
    labelCfg: {
      position: 'left',
      style: {
        background: {
          fill: '#ffffff',
          stroke: 'green',
          padding: [3, 2, 3, 2],
          radius: 2,
          lineWidth: 3,
        },
      },
    }
  },
  defaultEdge: {
    labelCfg: {
      autoRotate: true,
      style: {
        background: {
          fill: '#ffffff',
          stroke: '#000000',
          padding: [2, 2, 2, 2],
          radius: 2,
        },
      },
    }
  }
})