Options

Configuration Structure

Options: {
a11y: A11yOptions,
enabled: boolean,
label: string,
canvasStyle: string,
childrenSpacing: number,
containerClassName: string,
contentKey: string,
direction: TreeDirection,
enableAnimation: boolean,
enableToolbar: boolean,
groupLeafNodes: boolean,
height: number | string,
highlightOnHover: boolean,
siblingSpacing: number,
viewPortHeight: number,
viewPortWidth: number,
width: number | string,
edgeColor: string,
edgeColorHover: string,
edgeWidth: number,
fontColor: string,
fontFamily: string,
fontSize: string,
fontWeight: string,
borderColor: string,
borderColorHover: string,
borderRadius: string,
borderStyle: string,
borderWidth: number,
collapseBadgeEnabled: boolean,
enableExpandCollapse: boolean,
nodeBGColor: string,
nodeBGColorHover: string,
nodeClassName: string,
nodeHeight: number,
nodeStyle: string,
nodeTemplate: Function,
nodeWidth: number,
onNodeClick: Function,
enableTooltip: boolean,
tooltipBGColor: string,
tooltipBorderColor: string,
tooltipFontColor: string,
tooltipFontSize: string,
tooltipId: string,
tooltipMaxWidth: number | undefined,
tooltipMinWidth: number,
tooltipPadding: number,
tooltipTemplate: Function,
tooltipOffset: number,
}

width

Default: '100%'

Width of the canvas. Accepts a pixel number or CSS percentage string.

height

Default: 'auto'

Height of the canvas. Use 'auto' to size to content.

direction

Default: 'top'

Controls the direction the tree grows from the root node.

Available Options:

  • top — root at the top, children flow downward (default)
  • bottom — root at the bottom, children flow upward
  • left — root on the left, children flow rightward
  • right — root on the right, children flow leftward

contentKey

Default: 'name'

Key in the data object used as the node display label.

siblingSpacing

Default: 50

Horizontal distance between sibling nodes in pixels.

childrenSpacing

Default: 50

Vertical distance between a parent node and its children in pixels.

highlightOnHover

Default: true

Highlight the hovered node and its connecting edges.

containerClassName

Default: 'root'

CSS class name for the root SVG container element.

canvasStyle

Default: ''

Arbitrary CSS injected onto the SVG root container element.

enableToolbar

Default: false

Show the zoom/pan toolbar.

enableAnimation

Default: true

Animate node expansion/collapse transitions.

groupLeafNodes

Default: false

Stack leaf nodes vertically instead of spreading them horizontally.

viewPortWidth

Default: 800

Internal SVG viewport width in pixels.

viewPortHeight

Default: 600

Internal SVG viewport height in pixels.

nodeWidth

Default: 50

Width of each node in pixels.

nodeHeight

Default: 30

Height of each node in pixels.

nodeTemplate

Custom function returning an HTML string rendered inside each node.

nodeTemplate: (content) => {
  return `
    <div style='display:flex;justify-content:center;
      align-items:center;text-align:center;height:100%;'>
      ${content}
    </div>
  `;
}

nodeBGColor

Default: '#FFFFFF'

Default background color of nodes.

nodeBGColorHover

Default: '#FFFFFF'

Background color of nodes on hover.

nodeClassName

Default: 'apextree-node'

CSS class name added to every node element.

nodeStyle

Default: ''

Inline CSS string applied to each node element.

onNodeClick

Callback fired when the user clicks a node. Receives the raw node data object.

onNodeClick: (node) => {
  console.log('Clicked:', node);
}

borderWidth

Default: 1

Border width of nodes in pixels.

borderStyle

Default: 'solid'

CSS border-style for nodes.

borderRadius

Default: '5px'

CSS border-radius for nodes.

borderColor

Default: '#BCBCBC'

Border color of nodes in their default state.

borderColorHover

Default: '#5C6BC0'

Border color of nodes on hover.

enableExpandCollapse

Default: true

Show expand/collapse buttons on nodes that have children.

expandCollapseButtonBGColor

Default: '#FFFFFF'

Background color of the expand/collapse button.

expandCollapseButtonBorderColor

Default: '#BCBCBC'

Border color of the expand/collapse button.

collapseBadgeEnabled

Default: true

Show the collapse-count badge on collapsed nodes.

collapseBadgeBGColor

Default: '#5C6BC0'

Background color of the collapse-count badge.

collapseBadgeFontColor

Default: '#FFFFFF'

Font color of the collapse-count badge.

collapseBadgeFontSize

Default: '12px'

Font size of the collapse-count badge.

collapseBadgeThreshold

Default: 1

Minimum number of hidden children required before the badge appears.

groupLeafNodesSpacing

Default: 10

Spacing between stacked leaf nodes when groupLeafNodes is true, in pixels.

edgeColor

Default: '#A1A1A1'

Color of the connecting lines between nodes.

edgeColorHover

Default: '#5C6BC0'

Color of connecting lines when highlighted on hover.

edgeWidth

Default: 1

Stroke width of connecting lines in pixels.

enableTooltip

Default: false

Show a tooltip on node hover.

tooltipId

Default: 'apextree-tooltip-container'

HTML id for the tooltip container element.

tooltipTemplate

Custom function returning an HTML string for the tooltip content.

tooltipTemplate: (content) => {
  return `
    <div style='display:flex;justify-content:center;
      align-items:center;text-align:center;height:100%;'>
      ${content}
    </div>
  `;
}

tooltipMaxWidth

Maximum width of the tooltip in pixels. undefined means unconstrained.

tooltipMinWidth

Default: 100

Minimum width of the tooltip in pixels.

tooltipPadding

Default: 8

Inner padding of the tooltip in pixels. Set to 0 when using a custom tooltipTemplate.

tooltipOffset

Default: 10

Distance between the tooltip and the cursor in pixels.

tooltipBGColor

Default: '#FFFFFF'

Background color of the tooltip.

tooltipBorderColor

Default: '#BCBCBC'

Border color of the tooltip.

tooltipFontColor

Default: '#000000'

Font color of tooltip text.

tooltipFontSize

Default: '12px'

Font size of tooltip text.

fontColor

Default: '#000000'

CSS color for node text.

fontFamily

Default: ''

CSS font-family for node text. Falls back to the page default when empty.

fontSize

Default: '14px'

CSS font-size for node text.

fontWeight

Default: '400'

CSS font-weight for node text.

a11y

WCAG 2.1 AA accessibility options for the tree chart.

enabled

Options.a11y.enabled

Enable ARIA semantics and keyboard navigation.

label

Options.a11y.label

Override the default aria-label ("Organizational chart") on the root SVG.