HTMLGraph logo HTMLGraph

Bezier Edge Shape

The Bezier shape is used by default, but it can also be explicitly set using the setDefaults method on CanvasBuilder.

    
const element = document.getElementById('canvas');

const canvas = new CanvasBuilder(element)
  .setDefaults({
    edges: {
      shape: {
        type: "bezier",
      },
    },
  })
  .build();

  
Bezier Edge

In addition to type: "bezier", the following options are available:

NameTypeDescriptionRequiredDefault
colorstringColor of the line and arrowsno"#777777"
widthnumberLine widthno1
arrowLengthnumberFull length of the arrowno15
arrowWidthnumberWidth of the arrow from center to sideno4
curvaturenumberBezier curvatureno90
hasSourceArrowbooleanDraw an arrow near the source portnofalse
hasTargetArrowbooleanDraw an arrow near the target portnofalse
cycleRadiusnumberPort cycle line radiusno30
smallCycleRadiusnumberPort-cycle radius near the portno15
detourDistancenumberNode cycle detour distanceno100
detourDirectionnumberNode cycle detour directionno-Math.PI/2

Alternatively, you can create a Bezier shape by passing a factory function into the configuration.

    
import { BezierEdgeShape } from "@html-graph/html-graph";

const element = document.getElementById('canvas');

const canvas = new CanvasBuilder(element)
  .setDefaults({
    edges: {
      shape: () => new BezierEdgeShape({ hasTargetArrow: true })
    },
  })
  .build();

  

All parameters are the same as specified in the table.

You can also apply the Bezier shape to a specific edge using the addEdge and updateEdge methods.

    
import { BezierEdgeShape } from "@html-graph/html-graph";

canvas.addEdge({
  from: "port-1",
  to: "port-2",
  shape: new BezierEdgeShape(),
});

  
    
canvas.updateEdge("edge-1", {
  from: "port-3",
  to: "port-4",
  shape: new BezierEdgeShape(),
});