HTMLGraph logo HTMLGraph

Defaults

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

These defaults apply to all graph entities (nodes, ports, and edges) 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 Fields

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 Fields

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 Fields

NameTypeDescriptionRequiredDefault
shapeEdgeShapeConfigDefault edge shape configurationno{}
priorityPriorityDefault edge priorityno0

EdgeShapeConfig Options

NameConfigurationExample
BezierBezierShape{ type: "bezier" }
DirectDirectShape{ type: "direct" }
StraightStraightShape{ type: "straight" }
HorizontalHorizontalShape{ type: "horizontal" }
VerticalVerticalShape{ type: "vertical" }
CustomCustomShape(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++;