Skip to content

Commit 42651ad

Browse files
committed
improved design
1 parent a490239 commit 42651ad

1 file changed

Lines changed: 43 additions & 45 deletions

File tree

nodejs-assets/nodejs-project/index.html

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
.content {
3030
max-width: 1000px;
31-
width: 100%;
3231
margin-left: 10px;
32+
flex: 1;
3333
margin-right: 10px;
3434
}
3535

@@ -73,31 +73,37 @@
7373

7474
#sections {
7575
display: flex;
76-
flex-direction: column;
7776
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;
7981
}
8082

8183
.section {
8284
display: flex;
83-
background-color: rgba(255, 255, 255, 0.1);
85+
flex-direction: column;
8486
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;
8892
flex-shrink: 0;
8993

90-
border-radius: 8px;
9194
.section-title-description {
92-
flex: 1;
95+
font-weight: bold;
96+
text-align: center;
9397
}
9498
.section-value {
9599
flex-shrink: 0;
96100
font-variant-numeric: tabular-nums;
101+
opacity: 0.7;
97102
}
98103
}
99104

100105
#cellsSection {
106+
margin-top: 10px;
101107
background-color: rgba(255, 255, 255, 0.1);
102108
border-radius: 8px;
103109

@@ -150,15 +156,15 @@
150156

151157
@keyframes fadeGreen {
152158
0% {
153-
color: green;
159+
color: rgb(109, 255, 109);
154160
}
155161
100% {
156162
color: white;
157163
}
158164
}
159165
@keyframes fadeRed {
160166
0% {
161-
color: red;
167+
color: rgb(255, 100, 100);
162168
}
163169
100% {
164170
color: white;
@@ -192,6 +198,7 @@
192198
</div>
193199

194200
<div id="sections"></div>
201+
<div id="cells"></div>
195202
<div id="charts">
196203
<div id="voltageChart"></div>
197204
</div>
@@ -411,8 +418,7 @@
411418
return indices;
412419
}
413420

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'];
416422

417423
/** @returns {PromiseLike<{
418424
name: string;
@@ -428,12 +434,15 @@
428434
balanceStatus: boolean[];
429435
cellVolts: number[]
430436
* } | {code: string}>} */
437+
let currentUrl = 0;
431438
async function fetchBatteryInfo() {
432439
try {
440+
const infoUrl = urls[currentUrl];
433441
const response = await fetch(infoUrl);
434442
const info = await response.json();
435443
return info;
436444
} catch {
445+
currentUrl = (currentUrl + 1) % urls.length;
437446
return null;
438447
}
439448
}
@@ -584,7 +593,7 @@
584593
return;
585594
}
586595

587-
const sections = document.getElementById('sections');
596+
const sections = document.getElementById('cells');
588597
sections.innerHTML += element;
589598
}
590599

@@ -597,11 +606,14 @@
597606
}, 1500);
598607

599608
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+
}
603616
}
604-
header.innerText = info.code;
605617

606618
return;
607619
}
@@ -657,14 +669,14 @@
657669

658670
createOrUpdateSection(
659671
'remaining-capacity',
660-
'Remaining Capacity',
672+
' Capacity',
661673
'',
662674
info.remainingCapacityAh + 'Ah',
663675
);
664676

665677
createOrUpdateSection(
666678
't-voltage',
667-
'Total Voltage',
679+
'Voltage',
668680
'',
669681
info.totalVolts + 'V',
670682
);
@@ -689,14 +701,18 @@
689701
const ctx = document.getElementById('voltageChart');
690702
// Specify the configuration items and data for the chart
691703
const option = () => ({
704+
grid: {containLabel: true, top: 80},
692705
tooltip: {
693706
trigger: 'axis',
694-
position: function (pt) {
695-
return [pt[0], '10%'];
696-
},
707+
708+
confine: 'true',
697709
},
698710
legend: {
711+
textStyle: {
712+
color: '#9dffa6',
713+
},
699714
selected: {
715+
color: 'red',
700716
Cap: false,
701717
Volts: false,
702718
Curr: false,
@@ -846,28 +862,10 @@
846862
series: opts.series,
847863
xAxis: opts.xAxis,
848864
});
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();
871865
};
866+
867+
window.addEventListener('resize', () => {
868+
myChart.resize();
869+
});
872870
</script>
873871
</html>

0 commit comments

Comments
 (0)