|
501 | 501 | } |
502 | 502 | } |
503 | 503 |
|
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 | + |
505 | 515 | const exists = document.getElementById(`section-${id}`); |
506 | 516 | if (exists) { |
507 | 517 | document.getElementById(`section-title-${id}`).innerText = title; |
508 | 518 | document.getElementById(`section-description-${id}`).innerText = |
509 | 519 | description; |
510 | 520 |
|
| 521 | + document.getElementById(`section-init-value-${id}`).innerText = `${ |
| 522 | + diff > 0 ? '+' : '' |
| 523 | + }${diff.toFixed(2)}`; |
| 524 | + |
511 | 525 | const oldNums = parseFloat( |
512 | 526 | document |
513 | 527 | .getElementById(`section-value-${id}`) |
|
528 | 542 | } |
529 | 543 |
|
530 | 544 | const element = ` |
531 | | - <div class="section" id="section-${id}"> |
| 545 | + <div class="section" id="section-${id}" > |
532 | 546 | <div class="section-title-description"> |
533 | 547 | <div id="section-title-${id}">${title}</div> |
534 | 548 | <div id="section-description-${id}">${description}</div> |
535 | 549 | </div> |
536 | 550 | <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> |
537 | 554 | </div> |
538 | 555 | `; |
539 | 556 |
|
|
796 | 813 | ' Capacity', |
797 | 814 | '', |
798 | 815 | info.remainingCapacityAh.toFixed(2) + 'Ah', |
| 816 | + info.remainingCapacityAh, |
799 | 817 | ); |
800 | 818 |
|
801 | 819 | createOrUpdateSection( |
802 | 820 | 't-voltage', |
803 | 821 | 'Voltage', |
804 | 822 | '', |
805 | 823 | info.totalVolts + 'V', |
| 824 | + info.totalVolts, |
| 825 | + ); |
| 826 | + createOrUpdateSection( |
| 827 | + 'current', |
| 828 | + 'Current', |
| 829 | + '', |
| 830 | + info.current + 'A', |
| 831 | + info.current, |
806 | 832 | ); |
807 | | - createOrUpdateSection('current', 'Current', '', info.current + 'A'); |
808 | 833 | const watts = info.current * info.totalVolts; |
809 | 834 | createOrUpdateSection( |
810 | 835 | 'power', |
811 | 836 | 'Power', |
812 | 837 | '', |
813 | 838 | `${watts === 0 ? 0 : watts.toFixed(2)}W`, |
| 839 | + watts, |
814 | 840 | ); |
815 | 841 |
|
816 | 842 | createCellsSection(info.balanceStatus, info.cellVolts); |
|
0 commit comments