优化server-status主题首页网络图表 (#378)

This commit is contained in:
nap0o 2024-06-25 10:16:32 -04:00 committed by GitHub
parent 8805dffe85
commit 61127b3435
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -533,6 +533,21 @@
connectNulls: true connectNulls: true
}; };
}); });
const legendData = chartData.map(item => item.monitor_name);
const maxLegendsPerRowMobile = localStorage.getItem("maxLegendsPerRowMobile") ? localStorage.getItem("maxLegendsPerRowMobile") : 3;
const maxLegendsPerRowPc = localStorage.getItem("maxLegendsPerRowPc") ? localStorage.getItem("maxLegendsPerRowPc") : 6;
const autoIncrement = Math.floor((legendData.length - 1) / (isMobile ? maxLegendsPerRowMobile : maxLegendsPerRowPc)) * (isMobile ? 20 : 28)
const height = 300 + autoIncrement;
const gridTop = 40 + autoIncrement;
const legendIcon = isMobile ? 'rect' : "";
const itemWidth = isMobile ? 10 : 25;
const itemHeight = isMobile ? 10 : 14;
chart.resize({
width: 'auto',
height: height
});
const option = { const option = {
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
title: { title: {
@ -548,8 +563,9 @@
} }
}, },
legend: { legend: {
data: chartData.map(item => item.monitor_name), data: legendData,
show: true, show: true,
icon: legendIcon,
textStyle: { textStyle: {
fontSize: fontSize, fontSize: fontSize,
color: fontColor color: fontColor
@ -557,7 +573,9 @@
top: legendTop, top: legendTop,
bottom: 0, bottom: 0,
left: legendLeft, left: legendLeft,
padding: legendPadding padding: legendPadding,
itemWidth: itemWidth,
itemHeight: itemHeight,
}, },
xAxis: { xAxis: {
type: 'time', type: 'time',
@ -589,7 +607,7 @@
color: fontColor color: fontColor
}, },
grid: { grid: {
top: '40', top: gridTop,
left: gridLeft, left: gridLeft,
right: gridRight right: gridRight
} }