3

I am trying to display the people data as a tree with a filter following "select fields: area", does angular give a possibility to display the data in this form ? and how can I do it? I have data in this structure

public rowData = [
{
  area : area A',
  Persons: [
    { person:  'person 1', position :'lvl 1' , sup: '' } ,
    { person:  'person 2', position :'lvl 2' , sup :'person 1' }, 
    { person:  'person 3', position :'lvl 2' , sup :'person 1'  } ,
    { person:  'person 4', position :'lvl 3' , sup :'person 3'} ,
    { person:  'person 5', position :'lvl 3' , sup :'person 4'} ,
    { person:  'person 6', position :'lvl 3' , sup :'person 5'} ,
    { person:  'person 7', position :'lvl 4' , sup :'person 6'} 
  
},
{
  area : area B',
  Persons: [
    { person:  'person 21', position :'lvl 1' , sup :''} ,
    { person:  'person 22', position :'lvl 2' , sup :'person 1'}, 
    { person:  'person 23', position :'lvl 2' , sup :'person 1'} ,
    { person:  'person 24', position :'lvl 3' , sup :'person 2'} ,
    { person:  'person 25', position :'lvl 3' , sup :'person 2'} ,
   
  
},
  ]

enter image description here

5
  • did u tried something ? Commented Mar 30, 2021 at 11:29
  • @HadesZazif yes just html and css Commented Mar 30, 2021 at 11:30
  • 1
    try zingchart.com/docs/integrations/angular Commented Mar 30, 2021 at 12:39
  • @Eliseo there is nothing like what I said in Zingchart Commented Mar 30, 2021 at 14:06
  • Sorry, I see that has an angular and don't read any more :( Commented Mar 30, 2021 at 15:20

2 Answers 2

5

I'm working on create a TreeView Graphic in pure Angular. To not "re-invent the wheel" I copied the code from this old CodeProject article

I put the code in this stackblitz

It's hard (and too large) explain all the code, futhermore I need to do some cleanup because there are functions that are not implemented

Usage

Basically you need to copy the tree-view.component.ts and the econode.ts. Works simply using


    <tree-view #treeView [data]="data" [template]="treeTemplate"> 
    </tree-view>
    <ng-template #treeTemplate let-node>
      {{node.data.id}}
    </ng-template>

Where data is a typical object with children. The nodes are of type IECONode in the way

    export interface IECONode
    {
      data:any;
      linkColor?:string;
      background?:string;
      color?:string;
      width?:number;
      height?:number;
      children?:IECONode[];
    }

And the properties are inherited from the parent elements

  • NOTE: As I update the code, I'll update this post *

Update 1

I improved the component adding three functions:

  1. getChildren
  2. getParent
  3. getSlibingNodes

Futhermore, I got out the div element. the template is more complex but allows usage of (click) or (mouseover) to select one node or its parent/children.

Only the "nodes" are "colored" if they are selected, and only the "lines" are "colored" if go to a node selected.

This allow, e.g. select the nodes in a mouse over (or in a click)

    <ng-template #treeTemplate let-node>
      <div class="item" (mouseover)="selectSlibingNodes(treeView,node)" 
            [ngStyle]="node.isSelected?{'background-color':node.bc,color:node.c}:null">
      {{node.data.id}}
      </div>
    </ng-template>

The function selectSlibingNodes like:

      selectSlibingNodes(treeView: TreeViewComponent, node: ECONode) {
        if (node==this.nodeSelected) {
          this.nodeSelected=null;
          treeView.nodes.forEach(x => {
            x.isSelected = false;
          });
        } else {
          this.nodeSelected=node;
          const nodes = treeView.getSlibingNodes(node).map(x => x.id);
          treeView.nodes.forEach(x => {
            x.isSelected = x.id == node.id || nodes.indexOf(x.id) >= 0;
          });
        }
      }

I made a new stackblitz with the changes

Sign up to request clarification or add additional context in comments.

2 Comments

I used another Method using GOJS library , I get the same graph that I draw in the post but the library is not for free . I will try ur solution and go back for you . Thank you for your reply . I ll accept it as answer
Thanks to @JoSSte to check and edit my "terrorific english"
0

you can use angular2-tree-diagram package

angular2-tree-diagram

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.