Я сделал высокую диаграмму солнечных лучей в Angular.для первого уровня я напрямую вычисляю общее количество всех остальных, а для третьего уровня я использовал point.value
, который был также passAssetCnt/totalAssetCnt * 100
, но для второго уровня, он не будет работать таким образом.
этомоя функция форматирования.моя цель - вычислить процент, равный passAssetCnt/totalAssetCnt * 100
, если они имеют одинаковые reqnum
.
Все хорошо, пока я не сделаю инструкцию возврата, которая будет рисовать процент, и он тянет ноль для всего.
Я пытался вызвать отдельную функцию внутри функции форматирования, которая будет делать все это, но это тоже не вызывается.
JS FIDDLE LINK
var data = [{"id":"CSA-CCM","parent":"","name":"CSA-CCM"},{"id":"Application & Interface Security","parent":"CSA-CCM","name":"Application & Interface Security","complianceId":4,"inclusionId":1,"passAssetCnt":821,"totalAssetCnt":1198,"layer":"second","reqnum":1},{"id":"Audit Assurance & Compliance\r\n","parent":"CSA-CCM","name":"Audit Assurance & Compliance\r\n","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":2},{"id":"Business Continuity & Operational Resilience","parent":"CSA-CCM","name":"Business Continuity & Operational Resilience","complianceId":4,"inclusionId":1,"passAssetCnt":2,"totalAssetCnt":279,"layer":"second","reqnum":3},{"id":"Change Control & Configuration Management\r\n","parent":"CSA-CCM","name":"Change Control & Configuration Management\r\n","complianceId":4,"inclusionId":1,"passAssetCnt":7,"totalAssetCnt":10,"layer":"second","reqnum":4},{"id":"Data Security & Information Lifecycle ","parent":"CSA-CCM","name":"Data Security & Information Lifecycle ","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":5},{"id":"Datacenter Security","parent":"CSA-CCM","name":"Datacenter Security","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":6},{"id":"Encryption & Key Management","parent":"CSA-CCM","name":"Encryption & Key Management","complianceId":4,"inclusionId":1,"passAssetCnt":9,"totalAssetCnt":36,"layer":"second","reqnum":7},{"id":"Governance and Risk Management\r\n","parent":"CSA-CCM","name":"Governance and Risk Management\r\n","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":8},{"id":"Human Resources","parent":"CSA-CCM","name":"Human Resources","complianceId":4,"inclusionId":1,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":9},{"id":"Identity & Access Management\r\n","parent":"CSA-CCM","name":"Identity & Access Management\r\n","complianceId":4,"inclusionId":1,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":10},{"id":"Infrastructure & Virtualization Security","parent":"CSA-CCM","name":"Infrastructure & Virtualization Security","complianceId":4,"inclusionId":13,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":11},{"id":"Supply Chain Management, Transparency, and Accountability\r\n","parent":"CSA-CCM","name":"Supply Chain Management, Transparency, and Accountability\r\n","complianceId":4,"inclusionId":1,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":14},{"id":"Threat and Vulnerability Management","parent":"CSA-CCM","name":"Threat and Vulnerability Management","complianceId":4,"inclusionId":3,"passAssetCnt":0,"totalAssetCnt":1,"layer":"second","reqnum":15},{"id":"AIS-01","parent":"Application & Interface Security","name":"AIS-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":1},{"id":"AIS-02","parent":"Application & Interface Security","name":"AIS-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":1},{"id":"AIS-03","parent":"Application & Interface Security","name":"AIS-03","value":28,"passAssetCnt":37,"totalAssetCnt":130,"layer":"third","reqnum":1},{"id":"AIS-04","parent":"Application & Interface Security","name":"AIS-04","value":69,"passAssetCnt":821,"totalAssetCnt":1198,"layer":"third","reqnum":1},{"id":"AAC-01","parent":"Audit Assurance & Compliance\r\n","name":"AAC-01","value":100,"passAssetCnt":1,"totalAssetCnt":1,"layer":"third","reqnum":2},{"id":"AAC-02","parent":"Audit Assurance & Compliance\r\n","name":"AAC-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":2},{"id":"AAC-03","parent":"Audit Assurance & Compliance\r\n","name":"AAC-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":2},{"id":"BCR-07","parent":"Business Continuity & Operational Resilience","name":"BCR-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":3},{"id":"BCR-09","parent":"Business Continuity & Operational Resilience","name":"BCR-09","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":3},{"id":"BCR-11","parent":"Business Continuity & Operational Resilience","name":"BCR-11","value":1,"passAssetCnt":2,"totalAssetCnt":279,"layer":"third","reqnum":3},{"id":"CCC-04","parent":"Change Control & Configuration Management\r\n","name":"CCC-04","value":70,"passAssetCnt":7,"totalAssetCnt":10,"layer":"third","reqnum":4},{"id":"DSI-01","parent":"Data Security & Information Lifecycle ","name":"DSI-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DSI-03","parent":"Data Security & Information Lifecycle ","name":"DSI-03","value":0,"passAssetCnt":0,"totalAssetCnt":4,"layer":"third","reqnum":5},{"id":"DSI-05","parent":"Data Security & Information Lifecycle ","name":"DSI-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DSI-06","parent":"Data Security & Information Lifecycle ","name":"DSI-06","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DSI-07","parent":"Data Security & Information Lifecycle ","name":"DSI-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":5},{"id":"DCS-01","parent":"Datacenter Security","name":"DCS-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-02","parent":"Datacenter Security","name":"DCS-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-03","parent":"Datacenter Security","name":"DCS-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-04","parent":"Datacenter Security","name":"DCS-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-05","parent":"Datacenter Security","name":"DCS-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-06","parent":"Datacenter Security","name":"DCS-06","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-07","parent":"Datacenter Security","name":"DCS-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-08","parent":"Datacenter Security","name":"DCS-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"DCS-09","parent":"Datacenter Security","name":"DCS-09","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":6},{"id":"EKM-01","parent":"Encryption & Key Management","name":"EKM-01","value":51,"passAssetCnt":34,"totalAssetCnt":67,"layer":"third","reqnum":7},{"id":"EKM-02","parent":"Encryption & Key Management","name":"EKM-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":7},{"id":"EKM-03","parent":"Encryption & Key Management","name":"EKM-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":7},{"id":"EKM-04","parent":"Encryption & Key Management","name":"EKM-04","value":25,"passAssetCnt":9,"totalAssetCnt":36,"layer":"third","reqnum":7},{"id":"GRM-03","parent":"Governance and Risk Management\r\n","name":"GRM-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-04","parent":"Governance and Risk Management\r\n","name":"GRM-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-05","parent":"Governance and Risk Management\r\n","name":"GRM-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-07","parent":"Governance and Risk Management\r\n","name":"GRM-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-08","parent":"Governance and Risk Management\r\n","name":"GRM-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-09","parent":"Governance and Risk Management\r\n","name":"GRM-09","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"GRM-10","parent":"Governance and Risk Management\r\n","name":"GRM-10","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":8},{"id":"HRS-01","parent":"Human Resources","name":"HRS-01","value":55,"passAssetCnt":40,"totalAssetCnt":73,"layer":"third","reqnum":9},{"id":"HRS-07","parent":"Human Resources","name":"HRS-07","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":9},{"id":"HRS-08","parent":"Human Resources","name":"HRS-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":9},{"id":"HRS-11","parent":"Human Resources","name":"HRS-11","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":9},{"id":"IAM-01","parent":"Identity & Access Management\r\n","name":"IAM-01","value":41,"passAssetCnt":14,"totalAssetCnt":34,"layer":"third","reqnum":10},{"id":"IAM-02","parent":"Identity & Access Management\r\n","name":"IAM-02","value":63,"passAssetCnt":24,"totalAssetCnt":38,"layer":"third","reqnum":10},{"id":"IAM-03","parent":"Identity & Access Management\r\n","name":"IAM-03","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-04","parent":"Identity & Access Management\r\n","name":"IAM-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-05","parent":"Identity & Access Management\r\n","name":"IAM-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-08","parent":"Identity & Access Management\r\n","name":"IAM-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"IAM-11","parent":"Identity & Access Management\r\n","name":"IAM-11","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":10},{"id":"ISV-01","parent":"Infrastructure & Virtualization Security","name":"ISV-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-02","parent":"Infrastructure & Virtualization Security","name":"ISV-02","value":44,"passAssetCnt":121,"totalAssetCnt":274,"layer":"third","reqnum":11},{"id":"ISV-04","parent":"Infrastructure & Virtualization Security","name":"ISV-04","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-05","parent":"Infrastructure & Virtualization Security","name":"ISV-05","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-06","parent":"Infrastructure & Virtualization Security","name":"ISV-06","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-07","parent":"Infrastructure & Virtualization Security","name":"ISV-07","value":100,"passAssetCnt":1,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-08","parent":"Infrastructure & Virtualization Security","name":"ISV-08","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"ISV-12","parent":"Infrastructure & Virtualization Security","name":"ISV-12","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":11},{"id":"STA-01","parent":"Supply Chain Management, Transparency, and Accountability\r\n","name":"STA-01","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":14},{"id":"TEV-01","parent":"Threat and Vulnerability Management","name":"TEV-01","value":100,"passAssetCnt":1,"totalAssetCnt":1,"layer":"third","reqnum":15},{"id":"TEV-02","parent":"Threat and Vulnerability Management","name":"TEV-02","value":0,"passAssetCnt":0,"totalAssetCnt":1,"layer":"third","reqnum":15}];
formatter: function(data) {
let modifiedData = this.data.filter(
val => {
return val.layer == 'third';
}
);
// let modified = [];
for (let i = 0; i < modifiedData.length; i++) {
const modified = modifiedData.filter(val => {
return val.reqnum == modifiedData[i].reqnum;
});
const passAssetCnt = modified.reduce(
(prev, cur) => prev + cur.passAssetCnt,
0
);
console.log(passAssetCnt);
const totalAssetCnt = modified.reduce(
(prev, cur) => prev + cur.totalAssetCnt,
0
);
console.log(totalAssetCnt);
// console.log((passAssetCnt / totalAssetCnt) * 100);
const percent = (passAssetCnt / totalAssetCnt) * 100;
console.log(percent);
// return this.point.name + '<br>' + Math.round(percent) + '%';
}
}