| 299 | "rgb(255, 215, 0)", |
| 300 | "rgb(255, 105, 180)", |
| 301 | "rgb(255, 165, 0)", |
| 302 | ]; |
| 303 | |
| 304 | if (!monitorData.length || !monitorData[0]?.created_at?.length) { |
| 305 | return { type: "line", data: { labels: [], datasets: [] } }; |
| 306 | } |
| 307 | |
| 308 | const baseCreatedAt = monitorData[0].created_at; |
| 309 | const dataLength = baseCreatedAt.length; |
| 310 | |
| 311 | const maxPoints = 200; |
| 312 | const sampleIndices: number[] = []; |
| 313 | if (dataLength <= maxPoints) { |
| 314 | for (let i = 0; i < dataLength; i++) sampleIndices.push(i); |
| 315 | } else { |
| 316 | const step = (dataLength - 1) / (maxPoints - 1); |
| 317 | for (let j = 0; j < maxPoints; j++) { |
| 318 | sampleIndices.push(Math.round(j * step)); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | const labels = sampleIndices.map((i) => { |
| 323 | const ts = baseCreatedAt[i]; |
| 324 | const date = new Date(ts); |
| 325 | return `${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`; |
| 326 | }); |
| 327 | |
| 328 | const datasets = monitorData.map((item, index) => ({ |
| 329 | label: item.monitor_name, |
| 330 | data: sampleIndices.map((i) => item.avg_delay[i] ?? null), |
| 331 | borderColor: colors[index % colors.length], |
| 332 | fill: false, |
| 333 | pointRadius: 0, |
| 334 | borderWidth: 1.5, |
| 335 | })); |
| 336 | |
| 337 | return { |
| 338 | type: "line", |
| 339 | data: { labels, datasets }, |
| 340 | options: { |
| 341 | title: { |
| 342 | display: true, |
| 343 | text: `${serverName} - Service Monitor`, |
| 344 | fontColor: "#ffffff", |
| 345 | }, |
| 346 | legend: { |
| 347 | position: "bottom", |
| 348 | labels: { |
| 349 | fontColor: "#ffffff", |
| 350 | }, |
| 351 | }, |
| 352 | scales: { |
| 353 | yAxes: [{ |
| 354 | scaleLabel: { |
| 355 | display: true, |
| 356 | labelString: "Delay (ms)", |
| 357 | fontColor: "#ffffff", |
| 358 | }, |