HTMLGraph

Defaults

Use the setDefaults method of CanvasBuilder to establish base visualization settings.

These defaults apply when no explicit values are provided.


Nodes #

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

const canvas = new CanvasBuilder(element)
  .setDefaults({
    nodes: {
      centerFn: (w, h) => ({ x: w / 2, y: h / 2 }),
      priority: "incremental",
    },
  })
  .build();

  

NodesConfig

NameTypeDescriptionRequiredDefault
centerFnfunctionDefault function to determine the node’s centerno(w, h) => ({ x: w/2, y: h/2 })
priorityPriorityDefault node priorityno0

Priority Options

TypeDescriptionExample
numberEach node is assigned a constant Z-index5
"incremental"Each subsequent node receives an incremented Z-index"incremental"
() => numberZ-index is determined by a specified function() => 10 + i++;

Ports #

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

const canvas = new CanvasBuilder(element)
  .setDefaults({
    ports: {
      direction: -Math.PI,
    },
  })
  .build();

  

PortsConfig

NameTypeDescriptionRequiredDefault
directionnumberDefault port directionno0

Edges #

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

const canvas = new CanvasBuilder(element)
  .setDefaults({
    edges: {
      shape: {
        type: "bezier",
        color: "#000",
        hasTargetArrow: true,
      },
      priority: "incremental",
    },
  })
  .build();

  

EdgesConfig

NameTypeDescriptionRequiredDefault
shapeEdgeShapeConfigDefault edge shape configurationno{ type: "bezier" }
priorityPriorityDefault edge priorityno0

EdgeShapeConfig Options

NameConfigurationExample
BezierBezierEdgeShape{ type: "bezier" }
DirectDirectEdgeShape{ type: "direct" }
StraightStraightEdgeShape{ type: "straight" }
HorizontalHorizontalEdgeShape{ type: "horizontal" }
VerticalVerticalEdgeShape{ type: "vertical" }
CustomCustomEdgeShape(edgeId) => new CustomEdgeShape(edgeId)

Priority Options

TypeDescriptionExample
numberEach edge is assigned a constant Z-index5
"incremental"Each subsequent edge receives an incremented Z-index"incremental"
functionZ-index is determined by a specified function() => 10 + i++;

Focus #

Configures canvas.focus() default parameters

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

const canvas = new CanvasBuilder(element)
  .setDefaults({
    focus: {
      minContentScale: 0.5,
      contentPadding: 200,
      animationDuration: 150,
    },
  })
  .build();

  

FocusConfig

NameTypeDescriptionRequiredDefault
minContentScalenumberWhen all nodes don’t fit, the content scale gets smaller to fit all nodes. But minimum scaling value can be specified using this argumentno0
contentPaddingnumberExtra space between viewport border and graph nodesno100
animationDurationnumberDuration of transition animation (milliseconds)no0