Socket
Socket
Sign inDemoInstall

apextree

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    apextree

The Apextree is a javascript library built on SVG that helps to create organizational/hierarchy charts.


Version published
Maintainers
1
Install size
514 kB
Created

Readme

Source

ApexTree - Installation and Getting started

The Apextree is a javascript library built on SVG that helps to create organizational or hierarchical charts.

Screenshot 2023-12-17 at 10 28 04 PM

Installation

To add the Apextree to your project and its dependencies, install the package from npm.

npm install apextree

Usage

import ApexTree from 'apextree';

To create a basic tree with minimal configuration, write as follows:

<div id="svg-tree"></div>
 const data = {
   ...(nested data with format provided below)
 }
 const options = {
   width: 700,
   height: 700,
   nodeWidth: 120,
   nodeHeight: 80,
   childrenSpacing: 100,
   siblingSpacing: 30,
   direction: 'top',
   canvasStyle: 'border: 1px solid black;background: #f6f6f6;',
 };
 const tree = new ApexTree(document.getElementById('svg-tree'), options);
 const graph = tree.render(data);

Tree Options

The layout can be configured by either setting the properties in the table below by passing a second arg to Apextree with these properties set. The latter takes precedence.

OptionsDefaultDescription
width400The width of graph container
height400The height of graph container
directiontopThe direction of the tree to start rendering. Possible values: top, bottom, left and right
contentKeynameThe key of content in passed data object
siblingSpacing50The spacing between sibling nodes
childrenSpacing50The spacing between children and parent
highlightOnHovertrueEnable/disable highlight on hover
containerClassNamerootThe class name for the root container
canvasStyleNoneThe css styles for canvas root container
enableToolbarfalseEnable/disable graph toolbar
nodeWidth50The width of graph nodes
nodeHeight30The height of graph nodes
nodeTemplatedefaultNodeTemplateThe HTML template for nodes
nodeBGColor#FFFFFFThe background color of nodes
nodeBGColorHover#FFFFFFThe background color on hover of nodes
borderWidth1The border width of the nodes in pixels
borderStylesolidThe border style of the nodes
borderRadius5pxThe border radius of the nodes in pixels
borderColor#BCBCBCThe border color of the nodes
borderColorHover#5C6BC0The border color on hover of the nodes
edgeWidth1The width for the edges
edgeColor#BCBCBCThe color for the edges
edgeColorHover#BCBCBCThe color for the edges when highlighted
enableTooltipfalseEnable tooltip on hover of nodes
tooltipIdapextree-tooltip-containerThe tooltip HTML element id
tooltipTemplatedefaultNodeTemplateThe HTML template for tooltip
tooltipMaxWidth100The max width of the tooltip
tooltipBorderColor#BCBCBCThe border color of tooltip
tooltipBGColor#FFFFFFThe background color of tooltip
fontSize14pxThe size of font of nodes
fontFamilyNoneThe font family of nodes
fontWeight400The font weight of nodes
fontColor#000000The font color of nodes

Default node template

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

Expected data format

{
  "id": "1",
  "name": "A",
  "children": []
}

Passed data object should contain id, name and children.

For id key, value of id can be unique otherwise edge highlight won't work as expected.

For name key, if using other than name then specify key name in contentKey option

For children key, it contains list of child objects

Example

const data = {
  id: '1',
  name: 'A',
  children: [
    {
      id: '2',
      name: 'B',
      children: [
        {
          id: '3',
          name: 'C',
        },
        {
          id: '4',
          name: 'D',
        },
      ],
    },
  ],
};

Keywords

FAQs

Last updated on 25 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc