Skip to content

Commit 65b0db9

Browse files
committed
Partial parsing fixed for circular heatmap
1 parent c5a99eb commit 65b0db9

2 files changed

Lines changed: 57 additions & 36 deletions

File tree

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

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,55 @@ export class CircularHeatmapComponent implements OnInit {
5050
this.yaml.setURI('./assets/YAML/generated/sample.yaml');
5151
// Function sets data
5252
this.yaml.getJson().subscribe((data) => {
53-
console.log(this.radial_labels)
53+
//console.log(this.radial_labels)
5454
this.YamlObject = data;
55-
56-
for(var x in this.YamlObject['dimension']){
57-
this.segment_labels.push(this.YamlObject['dimension'][x]['subdimension']['name'])
55+
var allDimensionNames=Object.keys(this.YamlObject)
56+
//console.log(allDimensionNames)
57+
for(var i=0;i<allDimensionNames.length;i++){
58+
var allSubDimensionInThisDimension=Object.keys(this.YamlObject[allDimensionNames[i]])
59+
for(var j=0;j<allSubDimensionInThisDimension.length;j++){
60+
this.segment_labels.push(allSubDimensionInThisDimension[j])
61+
}
5862
}
63+
//console.log(this.segment_labels)
5964
for(var l=0 ; l<this.maxLevelOfTasks; l++){
60-
for(var x in this.YamlObject['dimension']){
61-
var tempData:cardSchema={
62-
"Name": "",
63-
"Level": "",
64-
"Done%":-1,
65-
"Task":[]
66-
}
67-
var totalImplemented:number=0
68-
try{
69-
tempData["Name"]=this.YamlObject['dimension'][x]['subdimension']['name']
65+
var allDimensionNames=Object.keys(this.YamlObject)
66+
for(var i=0;i<allDimensionNames.length;i++){
67+
var allSubDimensionInThisDimension=Object.keys(this.YamlObject[allDimensionNames[i]])
68+
for(var j=0;j<allSubDimensionInThisDimension.length;j++){
69+
var allTaskInThisSubDimension=Object.keys(this.YamlObject[allDimensionNames[i]][allSubDimensionInThisDimension[j]])
70+
var tempData:cardSchema={
71+
"Name": "",
72+
"Level": "",
73+
"Done%":-1,
74+
"Task":[]
75+
}
76+
var totalImplemented:number=0
77+
var totalTasks:number=0
78+
tempData["Name"]=allSubDimensionInThisDimension[j]
7079
tempData["Level"]="Level "+(l+1)
71-
for(var i=0;i<this.YamlObject['dimension'][x]['subdimension']['level-'+(l+1)].length;i++){
72-
var nameOfTask:string=this.YamlObject['dimension'][x]['subdimension']['level-'+(l+1)][i]['name']
73-
var Status:boolean=this.YamlObject['dimension'][x]['subdimension']['level-'+(l+1)][i]['isImplemented']
74-
if(Status){
75-
totalImplemented+=1
80+
for(var k=0;k<allTaskInThisSubDimension.length;k++){
81+
try{
82+
var lvlOfCurrentTask=this.YamlObject[allDimensionNames[i]][allSubDimensionInThisDimension[j]][allTaskInThisSubDimension[k]]["level"]
83+
if (lvlOfCurrentTask==l+1){
84+
totalTasks+=1
85+
var nameOfTask:string=allTaskInThisSubDimension[k]
86+
var Status:boolean=true //this.YamlObject['dimension'][x]['subdimension']['level-'+(l+1)][i]['isImplemented']
87+
if(Status){
88+
totalImplemented+=1
89+
}
90+
tempData["Task"].push({"taskName":nameOfTask,"ifTaskDone":Status})
91+
}
92+
if(totalTasks>0){
93+
tempData["Done%"]=totalImplemented/totalTasks
94+
}
95+
}
96+
catch{
97+
console.log("level for task does not exist")
7698
}
77-
tempData["Task"].push({"taskName":nameOfTask,"ifTaskDone":Status})
7899
}
79-
tempData["Done%"]=totalImplemented/this.YamlObject['dimension'][x]['subdimension']['level-'+(l+1)].length
80-
}
81-
catch{
82-
tempData["Done%"]=-1
100+
this.ALL_CARD_DATA.push(tempData)
83101
}
84-
this.ALL_CARD_DATA.push(tempData)
85102
}
86103
}
87104
console.log(this.ALL_CARD_DATA)
@@ -127,7 +144,7 @@ export class CircularHeatmapComponent implements OnInit {
127144
var color = d3.scaleLinear<string,string>().domain([0,1]).range(["white", "green"]);
128145

129146
this.loadCircularHeatMap(this.ALL_CARD_DATA, "#chart", this.radial_labels, this.segment_labels);
130-
d3.selectAll("#segment-" + this.ALL_CARD_DATA[index]["Name"]+'-'+this.ALL_CARD_DATA[index]["Level"].replace(' ','-')).attr("fill", function(p) {
147+
d3.selectAll("#segment-" + this.ALL_CARD_DATA[index]["Name"].replace(/ /g, "-") +'-'+this.ALL_CARD_DATA[index]["Level"].replace(' ','-')).attr("fill", function(p) {
131148
return color(_self.ALL_CARD_DATA[index]["Done%"])
132149
});
133150

@@ -145,6 +162,7 @@ export class CircularHeatmapComponent implements OnInit {
145162
}
146163

147164
loadCircularHeatMap(dataset:any, dom_element_to_append_to:string, radial_labels:string[], segment_labels:string[]) {
165+
//console.log(segment_labels)
148166
//d3.select(dom_element_to_append_to).selectAll('svg').exit()
149167
//console.log(dataset)
150168
let _self=this
@@ -154,7 +172,7 @@ export class CircularHeatmapComponent implements OnInit {
154172
bottom: 50,
155173
left: 50
156174
};
157-
var width = 950 - margin.left - margin.right;
175+
var width = 1250 - margin.left - margin.right;
158176
var curr:any;
159177
var height = width;
160178
var innerRadius = 100; // width/14;
@@ -211,7 +229,7 @@ export class CircularHeatmapComponent implements OnInit {
211229
// while decreasing the height of all others accordingly
212230
//console.log(d)
213231
if(curr["Done%"]!=-1){
214-
d3.selectAll("#segment-" + curr.Name+'-'+curr.Level.replaceAll(' ','-')).attr("fill","white")
232+
d3.selectAll("#segment-" + curr.Name.replace(/ /g, "-")+'-'+curr.Level.replaceAll(' ','-')).attr("fill","white")
215233
};
216234

217235
})
@@ -225,15 +243,15 @@ export class CircularHeatmapComponent implements OnInit {
225243
// var fillcolor = segment.select("desc").text(); //access original color from desc
226244
// segment.style("fill", fillcolor);
227245
if(curr["Done%"]!=-1){
228-
d3.selectAll("#segment-" + curr.Name+'-'+curr.Level.replaceAll(' ','-')).attr("fill", function(p) {
246+
d3.selectAll("#segment-" + curr.Name.replace(/ /g, "-")+'-'+curr.Level.replaceAll(' ','-')).attr("fill", function(p) {
229247
var color = d3.scaleLinear<string,string>().domain([0,1]).range(["white", "green"]);
230248
// how to access a function within reusable charts
231249
//console.log(color(d.Done));
232250
return color(curr["Done%"]);
233251
});
234252
}
235253
else{
236-
d3.selectAll("#segment-" + curr.Name+'-'+curr.Level.replaceAll(' ','-')).attr("fill", "#DCDCDC");
254+
d3.selectAll("#segment-" + curr.Name.replace(/ /g, "-")+'-'+curr.Level.replaceAll(' ','-')).attr("fill", "#DCDCDC");
237255
}
238256
})
239257
}
@@ -282,10 +300,10 @@ export class CircularHeatmapComponent implements OnInit {
282300
.enter().append("path")
283301
// .attr("class","segment")
284302
.attr("class", function(d:any) {
285-
return "segment-" + d.Name
303+
return "segment-" + d.Name.replace(/ /g, "-")
286304
})
287305
.attr("id", function(d:any) {
288-
return "segment-" + d.Name + "-" + d.Level.replaceAll(' ','-');
306+
return "segment-" + d.Name.replace(/ /g, "-") + "-" + d.Level.replaceAll(' ','-');
289307
})
290308
.attr("d", d3.arc<any>().innerRadius(ir).outerRadius(or).startAngle(sa).endAngle(ea))
291309
.attr("stroke", function(d) {
@@ -320,7 +338,7 @@ export class CircularHeatmapComponent implements OnInit {
320338
.attr("xlink:href", "#segment-label-path-" + id)
321339
.style("font-size", "12px")
322340
.attr("startOffset", function(d, i) {
323-
return i * 100 / numSegments + 1.5 + "%";
341+
return i * 100 / numSegments+0.1+ "%";
324342
})
325343
.text(function(d:any) {
326344
return d;
@@ -404,9 +422,12 @@ export class CircularHeatmapComponent implements OnInit {
404422
}
405423

406424
noTasktoGrey():void{
407-
for (var x in this.ALL_CARD_DATA){
425+
console.log(this.ALL_CARD_DATA)
426+
for (var x=0;x<this.ALL_CARD_DATA.length;x++){
408427
if (this.ALL_CARD_DATA[x]["Done%"]==-1){
409-
d3.selectAll("#segment-" + this.ALL_CARD_DATA[x]["Name"]+'-'+this.ALL_CARD_DATA[x]["Level"].replace(' ','-')).attr("fill","#DCDCDC");
428+
console.log(this.ALL_CARD_DATA[x]["Name"])
429+
console.log(this.ALL_CARD_DATA[x]["Level"])
430+
d3.selectAll("#segment-" + this.ALL_CARD_DATA[x]["Name"].replace(/ /g, "-")+'-'+this.ALL_CARD_DATA[x]["Level"].replace(' ','-')).attr("fill","#DCDCDC");
410431
}
411432
}
412433
}

src/assets/YAML/generated/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ Implementation:
15471547
iso27001-2017:
15481548
- hardening is not explicitly covered by ISO 27001 - too specific
15491549
- 13.1.3
1550-
Development & Source Control:
1550+
Development and Source Control:
15511551
Local development linting & style checks performed:
15521552
risk:
15531553
- Creating and developing code that contains code smells and quality issues.

0 commit comments

Comments
 (0)