Circle

6 min read

A built-in node Circle has the default style as below, the label is drawed on the center of it.
img

Usage

As stated in Built-in Nodes , there are three methods to configure nodes: Configure nodes globally when instantiating a Graph; Configure nodes in their data; Configure nodes by graph.node(nodeFn). Their priorities are:

graph.node(nodeFn) > Configure in data > Configure globally

⚠️ Attention: Expect for id, and label which should be assigned to every single node data, the other configurations in The Common Property and in each node type (refer to doc of each node type) support to be assigned by the three ways.

1 Global Configure When Instantiating a Graph

Assign type to 'circle' in the defaultNode object when instantiating a Graph:

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
  defaultNode: {
    type: 'circle', // The type of the node
    // ... Other configuraltions
  },
});

2 Configure in the Data

To configure different nodes with different properties, you can write the properties into the node data.

const data = {
  nodes: [
    {
      id: 'node0',
      type: 'circle', // The tyep of the node
      //... // Other configurations
    },
    //... // Other nodes
  ],
  edges: [
    //... // edges
  ],
};

Property

The Node Common Properties are available for Circle node, some special properties are shown below. The property with Object type will be described after the table:

NameDescriptionTypeRemark
sizeThe diameter of the nodeNumber / ArrayWhen it is an array, the first element will take effect
styleThe default style of circle nodeObjectCorrespond to the styles in Canvas
labelThe text of the labelString
labelCfgThe configurations of the labelObject
stateStylesThe styles in different statesObjectRefer to Configure Styles for State
linkPointsThe link points in visualObjectThey are invisible by default. It is usually used with the anchorPoints. The differences are described in linkPoints
iconThe configurations of the icon on the circle nodeObjectIt is invisible by default

style

The Node Common Styles are available for Circle node. style is an object to configure the filling color, stroke, and other styles. The following code shows how to configure the style globally when instantiating a Graph.
img

const data = {
  nodes: [
    {
      x: 100,
      y: 100,
      type: 'circle',
      label: 'circle',
    },
  ],
};
const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
  defaultNode: {
    // type: 'circle',  // The type has been assigned in the data, we do not have to define it any more
    style: {
      fill: '#bae637',
      stroke: '#eaff8f',
      lineWidth: 5,
    },
  },
});
graph.data(data);
graph.render();

labelCfg

labelCfg is an object to configure the label of the node. The Node Common Label Configurations are available. Base on the code in style section, we add labelCfg to defaultNode.
img

const data = {
  // ... data
};
const graph = new G6.Graph({
  // ... Other configurations for graph
  defaultNode: {
    // ... Other properties for nodes
    labelCfg: {
      position: 'bottom',
      offset: 10,
      style: {
        // ... The style of the label
      },
    },
  },
});
// ...

linkPoints

linkPoints is an object to configure the small circles on the 「top, bottom, left, and right」.

⚠️Attention: It is different from anchorPoints: anchorPoints is an 「array」 that indicates the actual relative positions used to specify the join position of the relevant edge of the node (refer to anchorPoints); linkPoints is an object that indicates whether 「render」the four small circles, which do not connect the relevant edges. These two properties are often used together.
NameDescriptionTypeRemark
topWhether to show the top small circleBooleanfalse by default
bottomWhether to show the bototm small circleBooleanfalse by default
leftWhether to show the left small circleBooleanfalse by default
rightWhether to show the right small circleBooleanfalse by default
sizeThe size of the small circlesNumber3 by default
fillThe filling color of the small circlesString'#72CC4A' by default
strokeThe stroke color of the small circlesString'#72CC4A' by default
lineWidthThe line width of the small circlesNumber1 by default

Base on the code in style section, we add linkPoints to defaultNode.
img

const data = {
  // ... data
};
const graph = new G6.Graph({
  // ... Other configurations for graph
  defaultNode: {
    // ... Other configurations for nodes
    linkPoints: {
      top: true,
      bottom: true,
      left: true,
      right: true,
      fill: '#fff',
      size: 5,
    },
  },
});
// ...

icon

icon is an object to configure the icon on the node.

NameDescriptionTypeRemark
showWhether to show the iconBooleanfalse by default
widthThe width of the iconNumber16 by default
heightThe height of the iconNumber16 by default
imgThe image url or base64 of the iconStringConfiguring it means the icon is an image
texticonfont for the iconStringConfiguring it means the icon is an iconfont

Base on the code in style section, we add icon to defaultNode.
img

const data = {
  // ... data
};
const graph = new G6.Graph({
  // ... Other configurations for the graph
  defaultNode: {
    // ... Other configurations for nodes
    icon: {
      show: true,
      width: 25,
      height: 25,
      // img: '...', The image url of the icon
      // text: '...', Use an iconfont for the icon
    },
  },
});
// ...