Skip to content

Commit d01e459

Browse files
authored
Merge pull request #143 from 0x41head/angular-ui
Added Dependency Graphs
2 parents 458a5dd + 2f58bc6 commit d01e459

10 files changed

Lines changed: 193 additions & 158 deletions

src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +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';
23+
import { DependencyGraphComponent } from './dependency-graph/dependency-graph.component';
2424

2525

2626
@NgModule({
@@ -37,7 +37,7 @@ import { TreeMapComponent } from './component/tree-map/tree-map.component';
3737
ReadmeToHtmlComponent,
3838
UsageComponent,
3939
AboutUsComponent,
40-
TreeMapComponent,
40+
DependencyGraphComponent,
4141

4242
],
4343
imports: [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ <h1>{{currentTask.dimension}} -> {{currentTask.subDimension}}: {{currentTask.tas
132132
<b>Depends on</b>
133133
</mat-panel-title>
134134
</mat-expansion-panel-header>
135-
<app-tree-map dimension={{currentTask.dimension}} subDimension={{currentTask.subDimension}} taskName={{currentTask.taskName}}></app-tree-map>
135+
<app-dependency-graph dimension={{currentTask.dimension}} subDimension={{currentTask.subDimension}} taskName={{currentTask.taskName}}></app-dependency-graph>
136136
</mat-expansion-panel>
137137
</mat-accordion>
138138
</div>

src/app/component/tree-map/tree-map.component.css

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/app/component/tree-map/tree-map.component.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/app/component/tree-map/tree-map.component.ts

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
circle {
2+
cursor: pointer;
3+
stroke: #000;
4+
stroke-width: .5px;
5+
}
6+
line.link {
7+
fill: none;
8+
stroke: #000;
9+
stroke-width: 1.5px;
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<svg width="1920" height="1280"></svg>

src/app/component/tree-map/tree-map.component.spec.ts renamed to src/app/dependency-graph/dependency-graph.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

3-
import { TreeMapComponent } from './tree-map.component';
3+
import { DependencyGraphComponent } from './dependency-graph.component';
44

5-
describe('TreeMapComponent', () => {
6-
let component: TreeMapComponent;
7-
let fixture: ComponentFixture<TreeMapComponent>;
5+
describe('DependencyGraphComponent', () => {
6+
let component: DependencyGraphComponent;
7+
let fixture: ComponentFixture<DependencyGraphComponent>;
88

99
beforeEach(async () => {
1010
await TestBed.configureTestingModule({
11-
declarations: [ TreeMapComponent ]
11+
declarations: [ DependencyGraphComponent ]
1212
})
1313
.compileComponents();
1414
});
1515

1616
beforeEach(() => {
17-
fixture = TestBed.createComponent(TreeMapComponent);
17+
fixture = TestBed.createComponent(DependencyGraphComponent);
1818
component = fixture.componentInstance;
1919
fixture.detectChanges();
2020
});
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import { Component, OnInit, Input } from '@angular/core';
2+
import * as d3 from 'd3'
3+
import { ymlService } from '../service/yaml-parser/yaml-parser.service';
4+
5+
export interface graphNodes{
6+
id:string
7+
}
8+
9+
export interface graphLinks{
10+
source: string
11+
target: string
12+
}
13+
14+
export interface graph{
15+
nodes:graphNodes[]
16+
links:graphLinks[]
17+
}
18+
19+
@Component({
20+
selector: 'app-dependency-graph',
21+
templateUrl: './dependency-graph.component.html',
22+
styleUrls: ['./dependency-graph.component.css']
23+
})
24+
export class DependencyGraphComponent implements OnInit {
25+
SIZE_OF_NODE:number=10
26+
COLOR_OF_LINK:string="black"
27+
COLOR_OF_NODE:string="#55bc55"
28+
BORDER_COLOR_OF_NODE:string="black"
29+
simulation:any
30+
YamlObject:any;
31+
graphData:graph={nodes:[],links:[]};
32+
visited:string[]=[]
33+
34+
@Input() dimension: string= "";
35+
@Input() subDimension: string= "";
36+
@Input() taskName: string= "";
37+
38+
constructor(private yaml:ymlService) { }
39+
40+
ngOnInit(): void {
41+
this.yaml.setURI('./assets/YAML/generated/generated.yaml');
42+
// Function sets data
43+
this.yaml.getJson().subscribe((data) => {
44+
this.graphData={nodes:[],links:[]};
45+
this.YamlObject = data[this.dimension][this.subDimension];
46+
this.populateGraphWithActivitiesCurrentTaskDependsOn(this.taskName)
47+
this.populateGraphWithActivitiesThatDependsOnCurrentTask(this.taskName)
48+
//console.log({...this.graphData['nodes']})
49+
50+
51+
console.log({...this.graphData})
52+
this.generateGraph(this.taskName)
53+
})
54+
55+
}
56+
57+
populateGraphWithActivitiesCurrentTaskDependsOn(task:string):void{
58+
this.checkIfNodeHasBeenGenerated(task)
59+
try{
60+
var tasksThatCurrenTaskIsDependentOn= this.YamlObject[task]['dependsOn']
61+
for(var j=0; j<tasksThatCurrenTaskIsDependentOn.length;j++){
62+
this.checkIfNodeHasBeenGenerated(tasksThatCurrenTaskIsDependentOn[j])
63+
this.graphData['links'].push({'source':tasksThatCurrenTaskIsDependentOn[j],'target':task})
64+
this.populateGraphWithActivitiesCurrentTaskDependsOn(tasksThatCurrenTaskIsDependentOn[j])
65+
}
66+
}
67+
catch(e){
68+
console.log(e)
69+
}
70+
//console.log({...this.graphData['nodes']})
71+
72+
}
73+
populateGraphWithActivitiesThatDependsOnCurrentTask(task:string){
74+
var allTasks= Object.keys(this.YamlObject)
75+
for(var i =0;i<allTasks.length;i++){
76+
try{
77+
if(this.YamlObject[allTasks[i]]['dependsOn'].includes(task)){
78+
this.checkIfNodeHasBeenGenerated(allTasks[i])
79+
this.graphData['links'].push({'source':task,'target':allTasks[i]})
80+
}
81+
}
82+
catch{
83+
continue
84+
}
85+
}
86+
87+
}
88+
89+
checkIfNodeHasBeenGenerated(task:string){
90+
if(!this.visited.includes(task)){
91+
this.graphData['nodes'].push({'id':task})
92+
this.visited.push(task)
93+
}
94+
}
95+
96+
97+
generateGraph(task:string):void{
98+
99+
let svg = d3.select("svg"),
100+
width = +svg.attr("width"),
101+
height = +svg.attr("height");
102+
103+
this.simulation = d3.forceSimulation()
104+
.force("link", d3.forceLink().id(function(d:any) { return d.id; }))
105+
.force("charge", d3.forceManyBody().strength(-2000))
106+
.force("center", d3.forceCenter(width / 2, height / 2));
107+
108+
svg.append('defs').append('marker')
109+
.attr('id','arrowhead')
110+
.attr('viewBox','-0 -5 10 10')
111+
.attr('refX',18)
112+
.attr('refY',0)
113+
.attr('orient','auto')
114+
.attr('markerWidth',13)
115+
.attr('markerHeight',13)
116+
.attr('xoverflow','visible')
117+
.append('svg:path')
118+
.attr('d', 'M 0,-5 L 10 ,0 L 0,5')
119+
.attr('fill', this.COLOR_OF_LINK)
120+
.style('stroke','none');
121+
122+
let link = svg.append("g")
123+
.attr("class", "links")
124+
.selectAll("line")
125+
.data(this.graphData['links'])
126+
.enter().append("line")
127+
.style("stroke", this.COLOR_OF_LINK)
128+
.attr('marker-end','url(#arrowhead)');
129+
130+
let node = svg.append("g")
131+
.attr("class", "nodes")
132+
.selectAll("g")
133+
.data(this.graphData['nodes'])
134+
.enter().append("g")
135+
136+
var defaultNodeColor=this.COLOR_OF_NODE
137+
node.append("circle")
138+
.attr("r", 10)
139+
.attr("fill",function(d) {
140+
if(d.id==task)
141+
return "yellow"
142+
else
143+
return defaultNodeColor})
144+
145+
146+
147+
node.append("text")
148+
.attr("dy", ".35em")
149+
.attr("text-anchor","middle")
150+
.text(function(d) { return d.id });
151+
152+
this.simulation
153+
.nodes(this.graphData['nodes'])
154+
.on("tick", ticked);
155+
156+
this.simulation.force("link")
157+
.links(this.graphData['links']);
158+
159+
function ticked() {
160+
link
161+
.attr("x1", function(d:any) { return d.source.x; })
162+
.attr("y1", function(d:any) { return d.source.y; })
163+
.attr("x2", function(d:any) { return d.target.x; })
164+
.attr("y2", function(d:any) { return d.target.y; });
165+
166+
node
167+
.attr("transform", function(d:any) {
168+
return "translate(" + d.x + "," + d.y + ")";
169+
})
170+
}
171+
}
172+
173+
}

0 commit comments

Comments
 (0)