@@ -32,25 +32,22 @@ const GRADIENT_COLORS = [
3232
3333const chartOptions = {
3434 responsive : true ,
35+ maintainAspectRatio : false ,
3536 plugins : {
3637 legend : {
37- position : "top" as const ,
38- } ,
39- title : {
40- display : false ,
38+ position : "top" as const , // ✅ 字面量 "top"
4139 } ,
40+ title : { display : false } ,
4241 } ,
43- maintainAspectRatio : false ,
4442 elements : {
45- line : {
46- tension : 0.4 , // Add curve to the lines
47- } ,
48- point : {
49- radius : 4 ,
50- hoverRadius : 6 ,
51- } ,
43+ line : { tension : 0 } , // 直线
44+ point : { radius : 0 } , // 不画点
45+ } ,
46+ scales : {
47+ x : { grid : { display : false } } ,
48+ y : { grid : { color : "rgba(128,128,128,0.1" } } ,
5249 } ,
53- } ;
50+ } as const ; // ✅ 整个对象也锁定,避免其他推导错误
5451
5552interface ServerStatusCardProps {
5653 node : string ;
@@ -73,10 +70,10 @@ export function ServerStatusCard({ node }: ServerStatusCardProps) {
7370 console . log ( "Fetched node data:" , data ) ; // Debug log for fetched data
7471 setNodeData ( data ) ;
7572
76- // Only keep the last 50 entries
77- const statusList = data . data ?. status_list ?. slice ( - 50 ) || [ ] ;
73+ const raw = data . data ?. status_list || [ ] ;
74+ const step = Math . max ( 1 , Math . floor ( raw . length / 50 ) ) ;
75+ const statusList = raw . filter ( ( _ : any , i : number ) => i % step === 0 ) . slice ( - 50 ) ;
7876
79- // Format timestamps
8077 const timestamps = statusList . map ( ( item : any ) =>
8178 new Date ( item . timestamp ) . toLocaleTimeString ( "zh-CN" , {
8279 hour : "2-digit" ,
@@ -85,22 +82,26 @@ export function ServerStatusCard({ node }: ServerStatusCardProps) {
8582 } )
8683 ) ;
8784
88- // Update CPU usage chart data
8985 const cpuUsages = statusList . map ( ( item : any ) => item . cpu_usage ) ;
9086 setCpuChartData ( {
9187 labels : timestamps ,
9288 datasets : [
9389 {
9490 label : "CPU Usage (%)" ,
9591 data : cpuUsages ,
96- backgroundColor : "rgba(75, 192, 192, 0.2)" ,
92+ backgroundColor : ( ctx : any ) => {
93+ const g = ctx . chart . ctx . createLinearGradient ( 0 , 0 , 0 , 300 ) ;
94+ g . addColorStop ( 0 , `rgba(75, 192, 192, 0.2)` ) ;
95+ g . addColorStop ( 1 , `rgba(75, 192, 192, 0)` ) ;
96+ return g ;
97+ } ,
9798 borderColor : "rgba(75, 192, 192, 1)" ,
9899 borderWidth : 2 ,
100+ fill : true ,
99101 } ,
100102 ] ,
101103 } ) ;
102104
103- // Update traffic chart data
104105 const uploadBandwidth = statusList . map ( ( item : any ) => item . upload_bandwidth ) ;
105106 const downloadBandwidth = statusList . map ( ( item : any ) => item . recv_packets ) ;
106107 setTrafficChartData ( {
@@ -109,16 +110,28 @@ export function ServerStatusCard({ node }: ServerStatusCardProps) {
109110 {
110111 label : "Upload Bandwidth (MB/s)" ,
111112 data : uploadBandwidth ,
112- backgroundColor : "rgba(255, 99, 132, 0.2)" ,
113+ backgroundColor : ( ctx : any ) => {
114+ const g = ctx . chart . ctx . createLinearGradient ( 0 , 0 , 0 , 300 ) ;
115+ g . addColorStop ( 0 , `rgba(255, 99, 132, 0.2)` ) ;
116+ g . addColorStop ( 1 , `rgba(255, 99, 132, 0)` ) ;
117+ return g ;
118+ } ,
113119 borderColor : "rgba(255, 99, 132, 1)" ,
114120 borderWidth : 2 ,
121+ fill : true ,
115122 } ,
116123 {
117124 label : "Download Bandwidth (MB/s)" ,
118125 data : downloadBandwidth ,
119- backgroundColor : "rgba(54, 162, 235, 0.2)" ,
126+ backgroundColor : ( ctx : any ) => {
127+ const g = ctx . chart . ctx . createLinearGradient ( 0 , 0 , 0 , 300 ) ;
128+ g . addColorStop ( 0 , `rgba(54, 162, 235, 0.2)` ) ;
129+ g . addColorStop ( 1 , `rgba(54, 162, 235, 0)` ) ;
130+ return g ;
131+ } ,
120132 borderColor : "rgba(54, 162, 235, 1)" ,
121133 borderWidth : 2 ,
134+ fill : true ,
122135 } ,
123136 ] ,
124137 } ) ;
@@ -181,4 +194,4 @@ export function ServerStatusCard({ node }: ServerStatusCardProps) {
181194 </ Card >
182195 </ div >
183196 ) ;
184- }
197+ }
0 commit comments