HTMLGraph logo HTMLGraph

Direct Edge Shape

The Direct edge shape can be configured by calling the setDefaults method on CanvasBuilder.

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

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

  
Direct Edge

In addition to type: "direct", 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
sourceOffsetnumberEmpty space distance from source port to an edgeno0
targetOffsetnumberEmpty space distance from target port to an edgeno0
hasSourceArrowbooleanDraw an arrow near the source portnofalse
hasTargetArrowbooleanDraw an arrow near the target portnofalse

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

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

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

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

  

All parameters are the same as specified in the table.

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

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

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

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