Edge Customization

Comprehensive styling and configuration options for connections between nodes

TreeCharts provides extensive customization options for edges (connections between nodes). You can control every aspect of how connections appear, from basic styling to advanced features like arrows, text labels, and visual effects.

Edge Configuration Overview

All edge styling is controlled through the edgeConfig property in your TreeChart options. This configuration applies to all connections in your tree and works with all renderer types (direct, right-angle, curved, and all-directional).

Key Features

  • Visual Styling: Colors, thickness, opacity, and dash patterns
  • Arrow Indicators: Directional arrows with customizable size and color
  • Edge Text Labels: Text labels on connections with styling options
  • Advanced Options: Curve radius, transparency, and renderer-specific features

Edge Customization Example

This example demonstrates comprehensive edge styling including colors, patterns, arrows, and text labels.

jsx
import { TreeChart } from 'treecharts-react';

// Tree data with edge text labels
const treeData = {
  value: "A",
  child: [
    {
      value: "B",
      edgeText: "to Department B",
      child: [
        {
          value: "B1",
          edgeText: "sub-unit",
          child: [],
        },
        {
          value: "B2",
          edgeText: "branch",
          child: [],
        },
      ],
    },
    {
      value: "C",
      edgeText: "to Department C",
      child: [
        {
          value: "C1",
          edgeText: "division",
          child: [],
        },
      ],
    },
  ],
};

function EdgeCustomizationTree() {
  return (
    <TreeChart
      data={treeData}
      type="right-angle"
      horizontalGap={120}
      verticalGap={100}
      nodeConfig={{
        width: 60,
        height: 40,
        color: "#e8f4fd",
        borderColor: "#4a90e2",
        borderWidth: 2,
        fontSize: 14,
        fontColor: "#2c3e50",
      }}
      edgeConfig={{
        // Basic line styling
        color: "#e74c3c",        // Red edges
        width: 2,                // Thicker lines
        dasharray: "5,5",        // Dashed pattern
        opacity: 0.8,            // Slightly transparent

        // Arrow configuration
        showArrows: true,
        arrowDirection: "source-to-target",
        arrowSize: 5,
        arrowColor: "#c0392b",   // Darker red arrows

        // Edge text styling
        textSize: 11,
        textColor: "#8e44ad",    // Purple text
        textBackgroundColor: "#f8f9fa", // Light background
      }}
      titleConfig={{
        title: "Edge Customization Example",
        description: "Dashed red edges with purple text labels and arrow indicators",
      }}
      width={800}
      height={500}
    />
  );
}

export default EdgeCustomizationTree;

Expected Output

Output for Edge Customization Example

Basic Styling Properties

Line Appearance

PropertyTypeDefaultDescriptionExamples
colorstring"black"Edge line color (supports hex, RGB, RGBA, named, HSL)"#e74c3c", "red", "rgb(231, 76, 60)"
widthnumber1Line thickness in pixels2, 3, 0.5
opacitynumber1Line transparency (0.0 to 1.0)0.8, 0.5, 1
dasharraystring""SVG dash pattern for dashed lines"5,5", "10,3", "5,3,1,3"

Dash Pattern Examples

PatternResultUse Case
""Solid lineDefault, clean connections
"5,5"Equal dashes and gapsSubtle visual distinction
"10,3"Long dashes, short gapsEmphasis while maintaining readability
"5,3,1,3"Dash-dot patternComplex hierarchical relationships

Arrow Configuration

Arrow Properties

PropertyTypeDefaultDescriptionOptions
showArrowsbooleanfalseEnable/disable arrow indicatorstrue, false
arrowDirectionstring"source-to-target"Arrow direction: source-to-target (Parent → Child), target-to-source (Parent ← Child), both (Parent ↔ Child)"source-to-target", "target-to-source", "both"
arrowSizenumber6Arrow size in pixels4, 8, 10
arrowColorstring"black"Arrow color (inherits edge color if not set)Any CSS color format

Arrow Styling Notes

  • Arrows automatically inherit the edge color unless arrowColor is explicitly set
  • Arrow size controls both width and height of the arrowhead
  • Arrows work with all renderer types (direct, right-angle, curved, all-directional)

Edge Text Labels

Text Properties

PropertyTypeDefaultDescriptionExamples
textSizenumber12Font size in pixels10, 14, 16
textColorstring"#666666"Text color"#8e44ad", "blue", "rgb(142, 68, 173)"
textBackgroundColorstring""Background color behind text (optional)"#f8f9fa", "white", "rgba(255,255,255,0.9)"

Adding Edge Text to Data

Add text labels directly in your tree data structure:

const treeData = {
  value: "Parent",
  child: [
    {
      value: "Child 1",
      edgeText: "Primary Branch",  // Text for this connection
      child: []
    },
    {
      value: "Child 2", 
      edgeText: "Secondary Branch",
      child: []
    }
  ]
};

Text Background Behavior

Background SettingResultBest Use Case
Empty ("")Transparent backgroundClean, minimal appearance
Color valueRounded rectangle backgroundComplex backgrounds, better readability
Semi-transparentSubtle background highlightBalanced visibility without overwhelming

Advanced Configuration

Curve Radius (Curved Renderer Only)

PropertyTypeDefaultDescriptionExamples
curveRadiusnumber20Curve intensity for curved renderer10, 30, 50

Usage Example:

{
  type: "curved",
  edgeConfig: {
    curveRadius: 30  // Higher values = more pronounced curves
  }
}

Performance Impact

FeaturePerformance ImpactNotes
Basic StylingMinimalEfficiently rendered using SVG
ArrowsMinimalUses SVG markers, very efficient
Edge TextLowSlight impact with 100+ labels
Dash PatternsMinimalNative SVG support
TransparencyMinimalHardware accelerated on modern browsers

Complete EdgeConfig Reference

interface EdgeConfig {
  // Basic styling
  color?: string;              // Edge color
  width?: number;              // Line thickness  
  opacity?: number;            // Transparency (0.0-1.0)
  dasharray?: string;          // Dash pattern

  // Arrow options
  showArrows?: boolean;        // Enable/disable arrows
  arrowDirection?: "source-to-target" | "target-to-source" | "both";
  arrowSize?: number;          // Arrow size in pixels
  arrowColor?: string;         // Arrow color (defaults to edge color)

  // Curve options (curved renderer only)
  curveRadius?: number;        // Curve intensity

  // Edge text styling
  textSize?: number;           // Text font size
  textColor?: string;          // Text color  
  textBackgroundColor?: string; // Text background (optional)
}