HTMLGraph

Straight Edge Shape

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

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

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

  
Straight Edge

In addition to type: "straight", 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
arrowOffsetnumberOffset from the arrow to the edge bendno15
hasSourceArrowbooleanDraw an arrow near the source portnofalse
hasTargetArrowbooleanDraw an arrow near the target portnofalse
cycleSquareSidenumberPort cycle square side sizeno30
roundnessnumberRoundness of the line anglesno10
detourDistancenumberNode cycle detour distanceno100
detourDirectionnumberNode cycle detour directionno-Math.PI/2

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

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

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

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

  

All parameters are the same as specified in the table.

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

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

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

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