For those who are interested here are the code changes to add a sum of process and spot color values to the ink coverage page.
inkCoverage.js
function createInkCoverageTable(inks, head, index, total = false) {
let html = '<table class="txt-small ink-coverage-table">';
if(head !== "") {
html += `<tr class="page-head">
<th class="txt-col-red" translation-key="${head}"> ${index}</th>
<td></td><td></td><td></td>
</tr>`;
}
inks.forEach(function(ink, index) {
html += `<tr>
<th>${ink["name"]}</th>
${ink.hasOwnProperty("inkcov") ?
`<td>${ink["inkcov"]["prct"].toFixed(2)} %</td>
<td>${ink["inkcov"]["cm2"].toFixed(2)} cm²</td>
<td>${ink["inkcov"]["inch2"].toFixed(2)} inch²</td>`
:
'<td>-</td><td>-</td><td>-</td>'
}
</tr>`;
});
function sumInkCoverage(inks) {
return inks.reduce((acc, ink) => {
acc.prct += ink.inkcov.prct;
acc.cm2 += ink.inkcov.cm2;
acc.inch2 += ink.inkcov.inch2;
return acc;
}, { prct: 0, cm2: 0, inch2: 0 });
}
if(total) {
const processColors = new Set(["Cyan", "Magenta", "Yellow", "Black"]);
const processInks = inks.filter(ink => processColors.has(ink.name) && ink.inkcov);
const spotInks = inks.filter(ink => !processColors.has(ink.name) && ink.inkcov);
const processTotals = sumInkCoverage(processInks);
const spotTotals = sumInkCoverage(spotInks);
if(processTotals.prct > 0) {
html += `<tr>
<th translation-key="inkcov-process-color-sum"></th>
<td>${processTotals.prct.toFixed(2)} %</td>
<td>${processTotals.cm2.toFixed(2)} cm²</td>
<td>${processTotals.inch2.toFixed(2)} inch²</td>
</tr>`;
}
if(spotTotals.prct > 0) {
html += `<tr>
<th translation-key="inkcov-spot-color-sum"></th>
<td>${spotTotals.prct.toFixed(2)} %</td>
<td>${spotTotals.cm2.toFixed(2)} cm²</td>
<td>${spotTotals.inch2.toFixed(2)} inch²</td>
</tr>`;
}
}
html += "</table>";
return html;
}
function addDocumentInkCoverage(element, data) {
let html = createInkCoverageTable(data["doc"]["inks"], "", 0, true);
element.insertAdjacentHTML("beforeend", html);
}
function addPagesInkCoverage(element, data) {
if(!cals_sec_info.inkcoverage.hasOwnProperty("listpages") || cals_sec_info.inkcoverage.listpages) {
let html = "";
data["doc"]["pages"].forEach(function(page, index) {
if(cals_sec_info["inkcoverage"]["on_pages"].includes(index + 1)) {
html += createInkCoverageTable(page["inks"], "Page", index + 1);
}
});
element.insertAdjacentHTML("beforeend", html);
}else {
element.style.display = "none";
}
}
function addInkCoverage(json) {
const inkCoverageElement = document.querySelector(".page-ink-coverage");
inkCoverageElement.style.display = "block";
addDocumentInkCoverage(inkCoverageElement.querySelector(".ink-coverage-document"), json);
addPagesInkCoverage(inkCoverageElement.querySelector(".ink-coverage-pages"), json);
}
translations.js
{
"en": {
"inkcov-process-color-sum": "Process colors",
"inkcov-spot-color-sum": "Spot colors"
},
"de": {
"inkcov-process-color-sum": "Prozessfarben",
"inkcov-spot-color-sum": "Sonderfarben"
},
"es": {
"inkcov-process-color-sum": "Colores de proceso",
"inkcov-spot-color-sum": "Tintas planas"
},
"fr": {
"inkcov-process-color-sum": "Couleurs de processus",
"inkcov-spot-color-sum": "Tons directs"
},
"it": {
"inkcov-process-color-sum": "Colori di processo",
"inkcov-spot-color-sum": "Tinta piatta"
},
"ja": {
"inkcov-process-color-sum": "プロセスカラー",
"inkcov-spot-color-sum": "特殊色"
},
"zh_cn": {
"inkcov-process-color-sum": "工艺颜色",
"inkcov-spot-color-sum": "特殊颜色"
}
}
Example image
If you want to add the sum for each page and not just for total you can simply add a true to the createInkCoverageTable function call inside addPagesInkCoverage.
