Cubic

4 min read

A built-in edge Cubic has the default style as below.
img

Usage

As stated in Built-in Edges , there are three methods to configure edges: Configure edges globally when instantiating a Graph; Configure edges in their data; Configure edges by graph.edge(edgeFn). Their priorities are:

graph.edge(edgeFn) > Configure in data > Configure globally

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

1 Global Configure When Instantiating a Graph

Assign type to 'cubic' in the defaultEdge object when instantiating a Graph:

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

2 Configure in the Data

To configure different edges with different properties, you can write the properties into the edge data.

const data = {
  nodes: [
    // ... // nodes
  ],
  edges: [{
    source: 'node0',
    target: 'node1'
    type: 'cubic',
    //... // Other configurations for edges
    style: {
      //...  // Style properties for edges
    }
  },
    //... // Other edges
  ]
}

Property

Cubic edge has the Common Edge Properties, and some commonly used properties are shown below. The properties with object type will be described in detail after the table.

NameDescriptionTypeRemark
colorThe color of the edgeStringThe priority id lower than stroke in style
styleThe default style of edgeObjectCorrespond to the styles in Canvas
labelThe text of the labelString
labelCfgThe configurations of the labelObject
controlPointsThe array of the control points for the cubic curveArrayIf it is not assgined, the default control points on the 1/3 and 2/3 of the curve will take effect. e.g. [{ x: 10, y: 20 }, { x: 15, y: 30 }]
curveOffsetThe distances between the controlPoints to the line connecting the two endpoints. They control the degree of bending of the curve. When the type is Number, the two controlPoints are on different sides of the line and the distances are the same. The sign of it controls the bending direction.Number / Number[]It is a special configuration for 'cubic', 'quadratic', 'cubic-vertical', 'cubic-horizontal' type edge
minCurveOffsetThe MINIMUM distances betweent the controlPoints to the line connecting to two endpoints. They control the degree of bending of the curve to prevent the too 'flat' curve. And it takes effect when the curveOffset is not assignedNumber / Number[]It is a special configuration for 'cubic-vertical' type and 'cubic-horizontal' type edge
curvePositionThe relative positions of the two controlPoints on the line connecting the two endpoints. Ranges from 0 to 1Number / Number[]It is a special configuration for 'cubic', 'quadratic', 'cubic-vertical', 'cubic-horizontal' type edge
stateStylesThe styles in different statesObjectRefer to Configure Styles for State

style

style is an object which is the same as the Common Edge Style Properties. The following code shows how to configure the style globally when instantiating a Graph.
img

const data = {
  nodes: [
    {
      id: 'node0',
      x: 100,
      y: 100,
      size: 20,
    },
    {
      id: 'node1',
      x: 200,
      y: 200,
      size: 20,
    },
  ],
  edges: [
    {
      source: 'node0',
      target: 'node1',
      type: 'cubic',
      label: 'cubic',
    },
  ],
};
const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
  defaultEdge: {
    // type: 'cubic',  // The type has been assigned in the data, we do not have to define it any more
    style: {
      endArrow: true,
      stroke: '#088',
      lineWidth: 3,
    },
  },
});
graph.data(data);
graph.render();

labelCfg

labelCfg is an object which is the same as the Common Edge Label Properties. Base on the code in style section, we add labelCfg to defaultEdge.
img

const data = {
  // ... data
};
const graph = new G6.Graph({
  // ... Other configurations for graph
  defaultEdge: {
    // ... Other properties for edges
    labelCfg: {
      autoRotate: true,
      refY: 10,
      refX: 40,
    },
  },
});
// ...