Skip to content

Commit 8de0f96

Browse files
committed
add diff for capacity and more
1 parent 2f8979b commit 8de0f96

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

nodejs-assets/nodejs-project/index.html

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,27 @@
501501
}
502502
}
503503

504-
const createOrUpdateSection = (id, title, description, value) => {
504+
const initialValues = {};
505+
506+
const createOrUpdateSection = (id, title, description, value, rawValue) => {
507+
let initVal = initialValues[id];
508+
if (initVal === undefined) {
509+
initialValues[id] = rawValue;
510+
initVal = rawValue;
511+
}
512+
513+
const diff = rawValue - initVal;
514+
505515
const exists = document.getElementById(`section-${id}`);
506516
if (exists) {
507517
document.getElementById(`section-title-${id}`).innerText = title;
508518
document.getElementById(`section-description-${id}`).innerText =
509519
description;
510520

521+
document.getElementById(`section-init-value-${id}`).innerText = `${
522+
diff > 0 ? '+' : ''
523+
}${diff.toFixed(2)}`;
524+
511525
const oldNums = parseFloat(
512526
document
513527
.getElementById(`section-value-${id}`)
@@ -528,12 +542,15 @@
528542
}
529543

530544
const element = `
531-
<div class="section" id="section-${id}">
545+
<div class="section" id="section-${id}" >
532546
<div class="section-title-description">
533547
<div id="section-title-${id}">${title}</div>
534548
<div id="section-description-${id}">${description}</div>
535549
</div>
536550
<div class="section-value" id="section-value-${id}">${value}</div>
551+
<div class="section-value" style="opacity: 0.5;" id="section-init-value-${id}">${
552+
diff > 0 ? '+' : ''
553+
}${diff.toFixed(2)}</div>
537554
</div>
538555
`;
539556

@@ -796,21 +813,30 @@
796813
' Capacity',
797814
'',
798815
info.remainingCapacityAh.toFixed(2) + 'Ah',
816+
info.remainingCapacityAh,
799817
);
800818

801819
createOrUpdateSection(
802820
't-voltage',
803821
'Voltage',
804822
'',
805823
info.totalVolts + 'V',
824+
info.totalVolts,
825+
);
826+
createOrUpdateSection(
827+
'current',
828+
'Current',
829+
'',
830+
info.current + 'A',
831+
info.current,
806832
);
807-
createOrUpdateSection('current', 'Current', '', info.current + 'A');
808833
const watts = info.current * info.totalVolts;
809834
createOrUpdateSection(
810835
'power',
811836
'Power',
812837
'',
813838
`${watts === 0 ? 0 : watts.toFixed(2)}W`,
839+
watts,
814840
);
815841

816842
createCellsSection(info.balanceStatus, info.cellVolts);

0 commit comments

Comments
 (0)