|
28 | 28 |
|
29 | 29 | .content { |
30 | 30 | max-width: 1000px; |
31 | | - width: 100%; |
32 | 31 | margin-left: 10px; |
| 32 | + flex: 1; |
33 | 33 | margin-right: 10px; |
34 | 34 | } |
35 | 35 |
|
|
73 | 73 |
|
74 | 74 | #sections { |
75 | 75 | display: flex; |
76 | | - flex-direction: column; |
77 | 76 | gap: 8px; |
78 | | - margin-top: 30px; |
| 77 | + margin-top: 20px; |
| 78 | + flex-wrap: wrap; |
| 79 | + background-color: rgba(255, 255, 255, 0.1); |
| 80 | + border-radius: 8px; |
79 | 81 | } |
80 | 82 |
|
81 | 83 | .section { |
82 | 84 | display: flex; |
83 | | - background-color: rgba(255, 255, 255, 0.1); |
| 85 | + flex-direction: column; |
84 | 86 | align-items: center; |
85 | | - padding-left: 20px; |
86 | | - padding-right: 10px; |
87 | | - height: 50px; |
| 87 | + padding: 10px; |
| 88 | + flex: 1; |
| 89 | + flex-shrink: 0; |
| 90 | + justify-content: center; |
| 91 | + gap: 6px; |
88 | 92 | flex-shrink: 0; |
89 | 93 |
|
90 | | - border-radius: 8px; |
91 | 94 | .section-title-description { |
92 | | - flex: 1; |
| 95 | + font-weight: bold; |
| 96 | + text-align: center; |
93 | 97 | } |
94 | 98 | .section-value { |
95 | 99 | flex-shrink: 0; |
96 | 100 | font-variant-numeric: tabular-nums; |
| 101 | + opacity: 0.7; |
97 | 102 | } |
98 | 103 | } |
99 | 104 |
|
100 | 105 | #cellsSection { |
| 106 | + margin-top: 10px; |
101 | 107 | background-color: rgba(255, 255, 255, 0.1); |
102 | 108 | border-radius: 8px; |
103 | 109 |
|
|
150 | 156 |
|
151 | 157 | @keyframes fadeGreen { |
152 | 158 | 0% { |
153 | | - color: green; |
| 159 | + color: rgb(109, 255, 109); |
154 | 160 | } |
155 | 161 | 100% { |
156 | 162 | color: white; |
157 | 163 | } |
158 | 164 | } |
159 | 165 | @keyframes fadeRed { |
160 | 166 | 0% { |
161 | | - color: red; |
| 167 | + color: rgb(255, 100, 100); |
162 | 168 | } |
163 | 169 | 100% { |
164 | 170 | color: white; |
|
192 | 198 | </div> |
193 | 199 |
|
194 | 200 | <div id="sections"></div> |
| 201 | + <div id="cells"></div> |
195 | 202 | <div id="charts"> |
196 | 203 | <div id="voltageChart"></div> |
197 | 204 | </div> |
|
411 | 418 | return indices; |
412 | 419 | } |
413 | 420 |
|
414 | | - // const infoUrl = `http://192.168.1.190:12345/info`; |
415 | | - const infoUrl = `/info`; |
| 421 | + const urls = ['/info', 'http://192.168.1.190:12345/info']; |
416 | 422 |
|
417 | 423 | /** @returns {PromiseLike<{ |
418 | 424 | name: string; |
|
428 | 434 | balanceStatus: boolean[]; |
429 | 435 | cellVolts: number[] |
430 | 436 | * } | {code: string}>} */ |
| 437 | + let currentUrl = 0; |
431 | 438 | async function fetchBatteryInfo() { |
432 | 439 | try { |
| 440 | + const infoUrl = urls[currentUrl]; |
433 | 441 | const response = await fetch(infoUrl); |
434 | 442 | const info = await response.json(); |
435 | 443 | return info; |
436 | 444 | } catch { |
| 445 | + currentUrl = (currentUrl + 1) % urls.length; |
437 | 446 | return null; |
438 | 447 | } |
439 | 448 | } |
|
584 | 593 | return; |
585 | 594 | } |
586 | 595 |
|
587 | | - const sections = document.getElementById('sections'); |
| 596 | + const sections = document.getElementById('cells'); |
588 | 597 | sections.innerHTML += element; |
589 | 598 | } |
590 | 599 |
|
|
597 | 606 | }, 1500); |
598 | 607 |
|
599 | 608 | const header = document.getElementById('header'); |
600 | | - if (!info || !info.name) { |
601 | | - header.innerText = 'Fetching Battery...'; |
602 | | - return; |
| 609 | + if (info?.code) { |
| 610 | + header.innerText = info.code; |
| 611 | + } else { |
| 612 | + if (!info || !info.name) { |
| 613 | + header.innerText = 'Fetching Battery...'; |
| 614 | + return; |
| 615 | + } |
603 | 616 | } |
604 | | - header.innerText = info.code; |
605 | 617 |
|
606 | 618 | return; |
607 | 619 | } |
|
657 | 669 |
|
658 | 670 | createOrUpdateSection( |
659 | 671 | 'remaining-capacity', |
660 | | - 'Remaining Capacity', |
| 672 | + ' Capacity', |
661 | 673 | '', |
662 | 674 | info.remainingCapacityAh + 'Ah', |
663 | 675 | ); |
664 | 676 |
|
665 | 677 | createOrUpdateSection( |
666 | 678 | 't-voltage', |
667 | | - 'Total Voltage', |
| 679 | + 'Voltage', |
668 | 680 | '', |
669 | 681 | info.totalVolts + 'V', |
670 | 682 | ); |
|
689 | 701 | const ctx = document.getElementById('voltageChart'); |
690 | 702 | // Specify the configuration items and data for the chart |
691 | 703 | const option = () => ({ |
| 704 | + grid: {containLabel: true, top: 80}, |
692 | 705 | tooltip: { |
693 | 706 | trigger: 'axis', |
694 | | - position: function (pt) { |
695 | | - return [pt[0], '10%']; |
696 | | - }, |
| 707 | + |
| 708 | + confine: 'true', |
697 | 709 | }, |
698 | 710 | legend: { |
| 711 | + textStyle: { |
| 712 | + color: '#9dffa6', |
| 713 | + }, |
699 | 714 | selected: { |
| 715 | + color: 'red', |
700 | 716 | Cap: false, |
701 | 717 | Volts: false, |
702 | 718 | Curr: false, |
|
846 | 862 | series: opts.series, |
847 | 863 | xAxis: opts.xAxis, |
848 | 864 | }); |
849 | | - |
850 | | - // chart.data.labels = plotter.labels; |
851 | | - // chart.data.datasets[0].data = plotter.data.capacity; |
852 | | - // chart.data.datasets[1].data = plotter.data.voltage; |
853 | | - // chart.data.datasets[2].data = plotter.data.current; |
854 | | - // chart.data.datasets[3].data = plotter.data.cellDiff; |
855 | | - // plotter.data.cells.forEach((v, i) => { |
856 | | - // if (!chart.data.datasets[i + 4]) { |
857 | | - // chart.data.datasets[i + 4] = { |
858 | | - // hidden: true, |
859 | | - // label: `Cell ${i + 1}`, |
860 | | - // data: [], |
861 | | - // fill: false, |
862 | | - // pointBorderColor: 'rgba(0, 0, 0, 0)', |
863 | | - // pointBackgroundColor: 'rgba(0, 0, 0, 0)', |
864 | | - // pointHoverBorderColor: 'rgb(75, 192, 192)', |
865 | | - // tension: 0.1, |
866 | | - // }; |
867 | | - // } |
868 | | - // chart.data.datasets[i + 4].data = v; |
869 | | - // }); |
870 | | - // chart.update(); |
871 | 865 | }; |
| 866 | + |
| 867 | + window.addEventListener('resize', () => { |
| 868 | + myChart.resize(); |
| 869 | + }); |
872 | 870 | </script> |
873 | 871 | </html> |
0 commit comments