npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular13-organization-chart

v2.0.1

Published

Organization chart library for angular 15+

Downloads

2,426

Readme

Angular Org Chart

An Angular 15+ library for displaying Organization charts. It's a very lightweight library with the features currently not available in any other library. It's written in pure typescript and is developed focussing on Angular projects Now the name of the package is misguiding, but no point crying over spilled milk, the other names were taken.

Getting Started

For using the chart, you'll need to do the following steps:

Installation

npm install angular13-organization-chart --save

Add the dependency in module

Add OrgChartModule in imports

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { OrgChartModule } from 'angular13-organization-chart';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    OrgChartModule // << this module
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Formatting the data in component

The data requires few parameters for displaying the correct chart:

export interface TreeNode {
    // Node
    children: TreeNode[];
    hideChildren?: boolean;
    onClick?: () => void;
    // CSS (used for custom styling of individual nodes)
    cssClass?: string;
    css?: string;
}

For example I want my nodes to have a name, a description, and an image:

// make your own interface that extends TreeNode
interface MyTreeNode extends TreeNode {
    name: string;
    description?: string;
    image?: string;
    children: MyTreeNode[];
}

Example:

Chart example Chart example zoomed out

Code:

Typescript

tree: MyTreeNode = {
    name: 'Felines',
    description: 'Cute playful animals',
    image: 'assets/chart-images/1.png',
    onClick: () => alert('Death to dogs'),
    children: [
      {
        name: 'Big Cats',
        image: 'assets/chart-images/3.jpg',
        css: 'background-color: #F00000',
        children: [
          {
            name: 'Lion',
            image: 'assets/chart-images/6.png',
            children: []
          },
          {
            name: 'Tiger',
            cssClass: 'yellow-on-hover',
            image: 'assets/chart-images/4.jpg',
            children: []
          },
          {
            name: 'Cheetah',
            image: 'assets/chart-images/8.png',
            children: []
          }
        ]
      },
      {
        name: 'Small Cats',
        description: 'Cute, but can also be crude. Like when they defecate on your lap, that would be a good example of crudeness on their part',
        image: 'assets/chart-images/9.png',
        children: [
          {
            name: 'House Cat',
            image: 'assets/chart-images/7.png',
            children: []
          },
          {
            name: 'Street Cat',
            image: 'assets/chart-images/8.png',
            children: [
              {
                name: 'Dumb Cat',
                image: 'assets/chart-images/13.png',
                children: [
                  {
                    name: 'Sorry For Bad Example',
                    image: 'assets/chart-images/6.png',
                    children: []
                  }
                ],
              },
              {
                name: 'Good Cat',
                image: 'assets/chart-images/8.png',
                children: [
                  {
                    name: 'Binary Search Tree',
                    image: 'assets/chart-images/10.png',
                    children: [
                      {
                        name: '7',
                        image: 'assets/chart-images/11.png',
                        children: [
                          {
                            name: '3',
                            image: 'assets/chart-images/6.png',
                            children: [
                              {
                                name: '2',
                                image: 'assets/chart-images/7.png',
                                children: []
                              },
                              {
                                name: '5',
                                image: 'assets/chart-images/12.png',
                                children: []
                              }
                            ]
                          },
                          {
                            name: '13',
                            description: 'An odd yet funny number.',
                            image: 'assets/chart-images/14.png',
                            children: [
                              {
                                name: '11',
                                description: 'All nodes to the right are greater',
                                image: 'assets/chart-images/15.png',
                                children: []
                              },
                              {
                                name: '17',
                                image: 'assets/chart-images/13.png',
                                description: 'This number is less that 17.00000001',
                                children: []
                              }
                            ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        name: 'Fake Cats',
        image: 'assets/chart-images/5.png',
        children: [],
        onClick: () => console.log('Google chrome stole some RAM')
      }
    ]
  };

HTML

<angular-org-chart [nodeTemplate]="nodeTemplate" [data]="tree" #exampleChart="orgChart">

    <!-- OPTIONAL: zoom button with an ugly png -->
    <button zoom-button class="zoom-button" (click)="exampleChart.toggleZoom()">
        <img src="assets/zoom-in-out.png" width="100%" alt="ZoomInOut">
    </button>

</angular-org-chart>

<!-- Node Template -->
<ng-template #nodeTemplate let-node>
    <div class="chart-node">
        <img [src]="node?.image">
        <div class="name">{{node?.name}}</div>
        <div class="description">{{node?.description}} </div>
        <!-- An ugly button to fold/unfold -->
        <div *ngIf="node.children.length" (click)="node.hideChildren = !node.hideChildren" class="tree-fold-btn">{{node.hideChildren ? '+' : '-'}}</div>
    </div>
</ng-template>

CSS


:host {
    display: block;
    text-align: center;
    padding: 64px;
}

// ugly css for quick test, use your own!
.zoom-button {
    padding: 0;
    margin: 0;
    border-radius: 50%;
    text-align: center;
    width: 40px;
    height: 40px;
    overflow: hidden;
}

See Full Example On Github

Customizing CSS

encapsulation: ViewEncapsulation.None

Encapsulation is disabled, So... go crazy. Here is the style sheet, you can find all the classes here.

  • PS: To style a single node you can use the optional fields in OrgData.

Features

  • OnClick callback
  • Custom Angular-Templates for nodes
  • Custom styles for individual nodes
  • Maintained and lightweight code
  • Zoom to see the overview, and hove on nodes to expand them
  • Supports folding/unfolding

Authors

  • Shrey Kumar Jain - Original Author
  • MuaazH - Contributed to the problem