Skip to content

Commit 458a5dd

Browse files
authored
Merge pull request #142 from 0x41head/angular-ui
Angular UI
2 parents 984dfe6 + a0f734e commit 458a5dd

9 files changed

Lines changed: 182 additions & 9 deletions

File tree

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MappingComponent } from './component/mapping/mapping.component';
2020
import { ReadmeToHtmlComponent } from './component/readme-to-html/readme-to-html.component';
2121
import { UsageComponent } from './component/usage/usage.component';
2222
import { AboutUsComponent } from './component/about-us/about-us.component';
23+
import { TreeMapComponent } from './component/tree-map/tree-map.component';
2324

2425

2526
@NgModule({
@@ -36,6 +37,7 @@ import { AboutUsComponent } from './component/about-us/about-us.component';
3637
ReadmeToHtmlComponent,
3738
UsageComponent,
3839
AboutUsComponent,
40+
TreeMapComponent,
3941

4042
],
4143
imports: [

src/app/component/circular-heatmap/circular-heatmap.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class CircularHeatmapComponent implements OnInit {
234234
//console.log(_self.tasksData)
235235
})
236236
.on('mouseover', function(d) {
237-
console.log(d.toElement.__data__.Name)
237+
//console.log(d.toElement.__data__.Name)
238238
try{
239239
curr=d.explicitOriginalTarget.__data__
240240
}

src/app/component/matrix/matrix.component.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ button{
3131
background-color: white;
3232
border: none;
3333
text-align: left;
34+
cursor:pointer;
3435
}
3536

src/app/component/matrix/matrix.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<li *ngFor="let task of element[lvl]; index as j" >
5252
<button (click)="navigate(element.Dimension,element.SubDimension,i+1,task)">
5353
{{task}}
54-
</button>
54+
</button>
5555
</li>
5656
</ul>
5757
</td>

src/app/component/task-description/task-description.component.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h1>{{currentTask.dimension}} -> {{currentTask.subDimension}}: {{currentTask.tas
6363
</mat-expansion-panel-header>
6464
<p>
6565
<mat-accordion multi="true">
66-
<mat-expansion-panel>
66+
<mat-expansion-panel [expanded]="true">
6767
<mat-expansion-panel-header>
6868
<mat-panel-title>
6969
<b>Tags</b>
@@ -73,15 +73,15 @@ <h1>{{currentTask.dimension}} -> {{currentTask.subDimension}}: {{currentTask.tas
7373
<li [innerHTML]="tag"></li>
7474
</ul>
7575
</mat-expansion-panel>
76-
<mat-expansion-panel>
76+
<mat-expansion-panel [expanded]="true">
7777
<mat-expansion-panel-header>
7878
<mat-panel-title>
7979
<b>URL</b>
8080
</mat-panel-title>
8181
</mat-expansion-panel-header>
8282
<p [innerHTML]="implement['url']"></p>
8383
</mat-expansion-panel>
84-
<mat-expansion-panel>
84+
<mat-expansion-panel [expanded]="true">
8585
<mat-expansion-panel-header>
8686
<mat-panel-title>
8787
<b>Description</b>
@@ -126,15 +126,13 @@ <h1>{{currentTask.dimension}} -> {{currentTask.subDimension}}: {{currentTask.tas
126126
</mat-accordion>
127127
</p>
128128
</mat-expansion-panel>
129-
<mat-expansion-panel *ngIf="this.currentTask.dependsOn">
129+
<mat-expansion-panel>
130130
<mat-expansion-panel-header>
131131
<mat-panel-title>
132132
<b>Depends on</b>
133133
</mat-panel-title>
134134
</mat-expansion-panel-header>
135-
<ul *ngFor="let dependency of this.currentTask.dependsOn">
136-
<li>{{dependency}}</li>
137-
</ul>
135+
<app-tree-map dimension={{currentTask.dimension}} subDimension={{currentTask.subDimension}} taskName={{currentTask.taskName}}></app-tree-map>
138136
</mat-expansion-panel>
139137
</mat-accordion>
140138
</div>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
body {
2+
background-color: #eee;
3+
}
4+
5+
.node circle {
6+
fill: #fff;
7+
stroke: steelblue;
8+
stroke-width: 3px;
9+
}
10+
11+
.node text { font: 16px sans-serif; }
12+
13+
.link {
14+
15+
stroke: #ccc;
16+
stroke-width: 2px;
17+
fill: none;
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<div id="tree">
2+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { TreeMapComponent } from './tree-map.component';
4+
5+
describe('TreeMapComponent', () => {
6+
let component: TreeMapComponent;
7+
let fixture: ComponentFixture<TreeMapComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ TreeMapComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(TreeMapComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { Component, OnInit, Input } from '@angular/core';
2+
import { ymlService } from '../../service/yaml-parser/yaml-parser.service';
3+
import * as d3 from 'd3';
4+
5+
export interface TreeNode {
6+
name: string;
7+
dependsOn:TreeNode[]
8+
}
9+
10+
11+
@Component({
12+
selector: 'app-tree-map',
13+
templateUrl: './tree-map.component.html',
14+
styleUrls: ['./tree-map.component.css']
15+
})
16+
17+
export class TreeMapComponent implements OnInit {
18+
SIZE_OF_NODE:number=10
19+
COLOR_OF_LINK:string="black"
20+
COLOR_OF_NODE:string="#55bc55"
21+
BORDER_COLOR_OF_NODE:string="black"
22+
TREE_DATA:TreeNode={name:"",dependsOn:[]};
23+
YamlObject:any;
24+
@Input() dimension: string= "";
25+
@Input() subDimension: string= "";
26+
@Input() taskName: string= "";
27+
28+
constructor(private yaml:ymlService) { }
29+
30+
ngOnInit(): void {
31+
this.setTreeData()
32+
}
33+
34+
setTreeData():void{
35+
this.yaml.setURI('./assets/YAML/generated/generated.yaml');
36+
// Function sets data
37+
this.yaml.getJson().subscribe((data) => {
38+
39+
this.YamlObject = data[this.dimension][this.subDimension];
40+
//console.log(JSON.parse(JSON.stringify(this.TREE_DATA)));
41+
this.TREE_DATA=this.generateTreeNodes(this.taskName)
42+
//console.log(this.TREE_DATA)
43+
this.generateTree()
44+
})
45+
46+
}
47+
48+
generateTreeNodes(currentTask:string):TreeNode{
49+
var tempTreeNode:TreeNode={name:'',dependsOn:[]}
50+
tempTreeNode['name']=currentTask
51+
try{
52+
for(var i=0;i<this.YamlObject[currentTask]["dependsOn"].length;i++){
53+
tempTreeNode['dependsOn'].push(this.generateTreeNodes(this.YamlObject[currentTask]["dependsOn"][i]))
54+
}
55+
}
56+
catch{
57+
return tempTreeNode
58+
}
59+
//console.log(tempTreeNode)
60+
return tempTreeNode
61+
}
62+
63+
generateTree():void{
64+
// set the dimensions and margins of the diagram
65+
const margin = {top: 20, right: 1250, bottom: 30, left: 90},
66+
width = 2000 - margin.left - margin.right,
67+
height = 500 - margin.top - margin.bottom;
68+
69+
// declares a tree layout and assigns the size
70+
const treemap = d3.tree().size([height, width]);
71+
72+
// assigns the data to a hierarchy using parent-child relationships
73+
var nodes:any = d3.hierarchy(this.TREE_DATA, (d:any) => d.dependsOn);
74+
console.log(JSON.parse(JSON.stringify(this.TREE_DATA)));
75+
76+
// maps the node data to the tree layout
77+
nodes = treemap(nodes);
78+
79+
// append the svg object to the body of the page
80+
// appends a 'group' element to 'svg'
81+
// moves the 'group' element to the top left margin
82+
const svg = d3.select("#tree").append("svg")
83+
.attr("width", width + margin.left + margin.right)
84+
.attr("height", height + margin.top + margin.bottom),
85+
g = svg.append("g")
86+
.attr("transform",
87+
"translate(" + margin.left + "," + margin.top + ")");
88+
89+
// adds the links between the nodes
90+
const link = g.selectAll(".link")
91+
.data( nodes.descendants().slice(1))
92+
.enter().append("path")
93+
.attr("class", "link")
94+
.style("stroke", this.COLOR_OF_LINK)
95+
.style("fill","none")
96+
.attr("d", (d:any) => {
97+
return "M" + d.y + "," + d.x
98+
+ "C" + (d.y + d.parent.y) / 2 + "," + d.x
99+
+ " " + (d.y + d.parent.y) / 2 + "," + d.parent.x
100+
+ " " + d.parent.y + "," + d.parent.x;
101+
});
102+
103+
// adds each node as a group
104+
const node = g.selectAll(".node")
105+
.data(nodes.descendants())
106+
.enter().append("g")
107+
.attr("class", (d:any) => "node" + (d.dependsOn ? " node--internal" : " node--leaf"))
108+
.attr("transform", (d:any) => "translate(" + d.y + "," + d.x + ")");
109+
110+
// adds the circle to the node
111+
node.append("circle")
112+
.attr("r", this.SIZE_OF_NODE)
113+
.style("stroke", this.BORDER_COLOR_OF_NODE)
114+
.style("fill", this.COLOR_OF_NODE);
115+
116+
// adds the text to the node
117+
node.append("text")
118+
.attr("dy", ".25em")
119+
.attr("x", "-20")
120+
.attr("y", "-20")
121+
.style("text-anchor", (d:any) => d.dependsOn ? "end" : "start")
122+
.text((d:any) => d.data.name);
123+
console.log()
124+
}
125+
126+
127+
}

0 commit comments

Comments
 (0)