Adding Arrows in OrgChart JS Links

Adding Arrows in OrgChart JS Links

Adding Arrows in OrgChart JS Links: Adding and Reversing Arrows in OrgChart JS Links: A Beginner's Guide

Adding and Reversing Arrows in OrgChart JS Links: A Beginner's Guide

Organization charts are a vital part of visualizing hierarchy and relationships within an organization. With OrgChart JS, you can customize links between nodes, including adding directional arrows. This guide will walk you through how to add and reverse arrows in an OrgChart JS instance using a simple code example.

Here is the example


Step 1: Defining Arrow Markers

To add arrows to links, we first define an SVG marker that represents the arrowhead. In the code below, we create an arrow marker and apply it to our chart template:

OrgChart.templates.ana.defs =
    `<marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse">
        <path fill="#aeaeae" d="M 0 0 L 10 5 L 0 10 z" />
    </marker>`;

The **marker** element defines an arrow that can be applied to paths. The orient="auto-start-reverse" attribute ensures the arrow adjusts based on the link direction.


Step 2: Adding Arrows to Links

Once the marker is defined, we integrate it into the link template:

OrgChart.templates.ana.link =
    `<path marker-end="url(#arrow)" stroke-linejoin="round" stroke="#aeaeae" stroke-width="1px" fill="none" d="M{xa},{ya} {xb},{yb} {xc},{yc} L{xd},{yd}" />`;

Here, marker-end="url(#arrow)" ensures the arrow appears at the end of the link, pointing towards the child node.


Step 3: Reversing Arrows on Links

To reverse the direction of the arrow, we create a modified template named "reverse" that places the arrow at the start of the link instead of the end:

OrgChart.templates.reverse = Object.assign({}, OrgChart.templates.ana);
OrgChart.templates.reverse.link =
    `<path marker-start="url(#arrow)" stroke-linejoin="round" stroke="#aeaeae" stroke-width="1px" fill="none" d="M{xa},{ya} {xb},{yb} {xc},{yc} L{xd},{yd}" />`;
OrgChart.templates.reverse.plus = "";
OrgChart.templates.reverse.minus = "";

Now, marker-start="url(#arrow)" ensures that the arrow appears at the beginning of the link, pointing towards the parent node.


Step 4: Initializing and Configuring the Chart

Now, we set up the OrgChart instance and apply the templates:

let chart = new OrgChart(document.getElementById("tree"), {
    enableSearch: false,
    mouseScrool: OrgChart.action.none,
    nodeMouseClick: OrgChart.action.none,
    tags: {
        "ig": {
            template: "invisibleGroup",
            subTreeConfig: {
                orientation: OrgChart.orientation.bottom
            },
        },
        "reverse": {
            template: "reverse"
        }
    }
});

This configuration disables search and mouse scrolling and defines the "reverse" tag for nodes that need reversed arrows.


Step 5: Loading the Data

Finally, we load data into the chart, assigning the "reverse" tag where needed:

chart.load([
    { id: "root", tags: ["ig"] },
    { id: 0, stpid: "root", tags: ["reverse"] },
    { id: 1, pid: 0, tags: ["reverse"] },
    { id: 2, pid: 0, tags: ["reverse"] },
    { id: 3, pid: "root" },
    { id: 4, pid: "root" }
]);

Here, nodes with the "reverse" tag will have arrows pointing toward the parent, instead of the default downward direction.


Link Arrows - OrgChart JS

Conclusion

By following these steps, you can easily customize link arrows in your OrgChart JS visualization. Whether you need arrows pointing to children or parents, adjusting link templates makes it simple. Try experimenting with different styles and colors to match your design needs!

Custom Aligning Nodes in a JavaScript Organizational Chart

Center and Zoom on Search Click in OrgChart JS

Create Multiline Group Titles in OrgChart JS

Show a Custom Edit Form for a node in OrgChart JS

Jeff Bezos Family Tree

How to Add Material Icons in OrgChart JS

Leonardo DiCaprio Family Tree

Visualizing Dual Reporting Structures with OrgChart JS

Exporting OrgChart JS to A4 PDF: A Step-by-Step Guide

Genghis Khan Family Tree: The Lineage of the Great Khan

OrgChart JS now support Export to Visio

New Export Option: childLevels in OrgChart JS

Elon Musk Family Tree

AI for OrgChart JS: Revolutionizing Organization Charts

Family Tree JS 2 (Preview)

d3 org chart

Our Family Tree App is Now on Android!

Why BALKAN OrgChart JS is the Best Organizational Chart Library

How to Create a JavaScript Flow Chart

How to Add an Organizational Chart to a Mobile Application

How to Create a JavaScript Organizational Chart

OrgChart JS Now Supports PDF Export Per Team

Introducing Family Tree App

Donald Trump Family Tree

Discover Your Roots: Build Your Family Tree with BALKAN App

JavaScript Organization Chart

Instantly create interactive, intuitive flowcharts in seconds

JavaScript Hierarchy Chart

Mermaid js alternative

Create Flowcharts in Seconds with Flow Chart JS: Your New Favorite JavaScript Library

Customizing Filter UI - Code of The Week

Zoom Slider - Code of The Week

Bookmarks - Code of The Week

Customizing Search Results - Code of The Week

Introducing Undo Redo - Code Of The Week

Price adjustment announcement

The price will increase for new customers

Buttons for adding family members to a family tree - Code of The Week

Levels - Code of The Week

Change node color from a button in the Edit Form - Code of The Week

Filter and Highlight Nodes - Code of The Week

Up Expanding - Code Of The Week

Programmatically move the chart - Code of The Week

Siblings in Family Tree JS - Code of The Week

Purple template - Code of The Week

Assistant With Children - Code of The Week

Conditional Layout - Code of The Week

Conditional Color - Code of the Week

Sriniz Family Tree Template - Code of The Week

Color Picker - Code of The Week

Add company logo as watermark in exported PDF documents - Code of The Week

Mind map - Code of The Week

Create relationship with circle menu - Code of The Week

Animated Photos - Code of the Week

Grouped Dotted Lines - Code Of The Week

Dotted Lines - Code Of The Week

Department Dynamic Title - Code Of The Week

Add expand button for partners - Code of the Week

Change the sub levels with Drag and Drop - Code of The Week

Custom Edit From using Popover - Code of the Week

Sub levels tag option - Code of the Week

Highlights search results directly on Org Chart nodes - Code of the Week

Code of the Week/Relationship maps and Business process diagrams

Search using field name abbreviations - Code of the Week

Dynamic Template - Code of the Week

Read and Write local CSV file using File API and Org Chart JS - Code of The Week

Organizational Chart Path Highlighting and Selection

Modern Template - Org Chart JS

Performance - Org Chart JS

Single parent is supported in Family Tree JS

How To Develop a Flowchart Maker with Org Chart JS

How to upload a photo to Family Tree JS in .NET core

How to change the color of selected node - Family Tree JS

Family Tree with live tiles

Error

BALKAN Blog

The Latest BALKAN App News and Releases. Latest information on Org Chart JS and Family Tree JS.