Skip to content

Commit 9342741

Browse files
committed
Changed trees to graphs
1 parent 458a5dd commit 9342741

9 files changed

Lines changed: 141 additions & 156 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="1280" height="720"></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: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
@Component({
6+
selector: 'app-dependency-graph',
7+
templateUrl: './dependency-graph.component.html',
8+
styleUrls: ['./dependency-graph.component.css']
9+
})
10+
export class DependencyGraphComponent implements OnInit {
11+
SIZE_OF_NODE:number=10
12+
COLOR_OF_LINK:string="black"
13+
COLOR_OF_NODE:string="#55bc55"
14+
BORDER_COLOR_OF_NODE:string="black"
15+
simulation:any
16+
YamlObject:any;
17+
graph={
18+
nodes: [{
19+
id: "Alice"
20+
},
21+
{
22+
id: "Bob"
23+
},
24+
{
25+
id: "George"
26+
}
27+
],
28+
links: [{
29+
source: "Alice",
30+
target: "George"
31+
},
32+
{
33+
source: "George",
34+
target: "Bob"
35+
}
36+
]
37+
};
38+
39+
@Input() dimension: string= "";
40+
@Input() subDimension: string= "";
41+
@Input() taskName: string= "";
42+
43+
constructor(private yaml:ymlService) { }
44+
45+
ngOnInit(): void {
46+
this.generateGraph()
47+
}
48+
49+
generateGraph():void{
50+
51+
let svg = d3.select("svg"),
52+
width = +svg.attr("width"),
53+
height = +svg.attr("height");
54+
55+
this.simulation = d3.forceSimulation()
56+
.force("link", d3.forceLink().id(function(d:any) { return d.id; }))
57+
.force("charge", d3.forceManyBody().strength(-11215))
58+
.force("center", d3.forceCenter(width / 2, height / 2));
59+
60+
svg.append('defs').append('marker')
61+
.attr('id','arrowhead')
62+
.attr('viewBox','-0 -5 10 10')
63+
.attr('refX',20)
64+
.attr('refY',0)
65+
.attr('orient','auto')
66+
.attr('markerWidth',13)
67+
.attr('markerHeight',13)
68+
.attr('xoverflow','visible')
69+
.append('svg:path')
70+
.attr('d', 'M 0,-5 L 10 ,0 L 0,5')
71+
.attr('fill', this.COLOR_OF_LINK)
72+
.style('stroke','none');
73+
74+
let link = svg.append("g")
75+
.attr("class", "links")
76+
.selectAll("line")
77+
.data(this.graph.links)
78+
.enter().append("line")
79+
.style("stroke", this.COLOR_OF_LINK)
80+
.attr('marker-end','url(#arrowhead)');
81+
82+
let node = svg.append("g")
83+
.attr("class", "nodes")
84+
.selectAll("g")
85+
.data(this.graph.nodes)
86+
.enter().append("g")
87+
88+
89+
node.append("circle")
90+
.attr("r", 15)
91+
.attr("fill",this.COLOR_OF_NODE)
92+
93+
94+
95+
node.append("text")
96+
.attr("dy", ".35em")
97+
.attr("text-anchor","middle")
98+
.text(function(d) { return d.id });
99+
100+
this.simulation
101+
.nodes(this.graph.nodes)
102+
.on("tick", ticked);
103+
104+
this.simulation.force("link")
105+
.links(this.graph.links);
106+
107+
function ticked() {
108+
link
109+
.attr("x1", function(d:any) { return d.source.x; })
110+
.attr("y1", function(d:any) { return d.source.y; })
111+
.attr("x2", function(d:any) { return d.target.x; })
112+
.attr("y2", function(d:any) { return d.target.y; });
113+
114+
node
115+
.attr("transform", function(d:any) {
116+
return "translate(" + d.x + "," + d.y + ")";
117+
})
118+
}
119+
}
120+
121+
}

0 commit comments

Comments
 (0)