mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-16 03:41:43 +00:00
Dashboard Card ecit
This commit is contained in:
@@ -1150,23 +1150,46 @@ const Dashboard = () => {
|
|||||||
callbacks: {
|
callbacks: {
|
||||||
title: (context) => {
|
title: (context) => {
|
||||||
const label = context[0].label;
|
const label = context[0].label;
|
||||||
|
|
||||||
|
// Handle empty or invalid labels
|
||||||
|
if (!label || typeof label !== "string") {
|
||||||
|
return "Unknown Date";
|
||||||
|
}
|
||||||
|
|
||||||
// Format hourly labels (e.g., "2025-10-07T14" -> "Oct 7, 2:00 PM")
|
// Format hourly labels (e.g., "2025-10-07T14" -> "Oct 7, 2:00 PM")
|
||||||
if (label.includes("T")) {
|
if (label.includes("T")) {
|
||||||
const date = new Date(`${label}:00:00`);
|
try {
|
||||||
|
const date = new Date(`${label}:00:00`);
|
||||||
|
// Check if date is valid
|
||||||
|
if (isNaN(date.getTime())) {
|
||||||
|
return label; // Return original label if date is invalid
|
||||||
|
}
|
||||||
|
return date.toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return label; // Return original label if parsing fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format daily labels (e.g., "2025-10-07" -> "Oct 7")
|
||||||
|
try {
|
||||||
|
const date = new Date(label);
|
||||||
|
// Check if date is valid
|
||||||
|
if (isNaN(date.getTime())) {
|
||||||
|
return label; // Return original label if date is invalid
|
||||||
|
}
|
||||||
return date.toLocaleDateString("en-US", {
|
return date.toLocaleDateString("en-US", {
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
hour: "numeric",
|
|
||||||
minute: "2-digit",
|
|
||||||
hour12: true,
|
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return label; // Return original label if parsing fails
|
||||||
}
|
}
|
||||||
// Format daily labels (e.g., "2025-10-07" -> "Oct 7")
|
|
||||||
const date = new Date(label);
|
|
||||||
return date.toLocaleDateString("en-US", {
|
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1186,24 +1209,49 @@ const Dashboard = () => {
|
|||||||
},
|
},
|
||||||
callback: function (value, _index, _ticks) {
|
callback: function (value, _index, _ticks) {
|
||||||
const label = this.getLabelForValue(value);
|
const label = this.getLabelForValue(value);
|
||||||
|
|
||||||
|
// Handle empty or invalid labels
|
||||||
|
if (!label || typeof label !== "string") {
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
// Format hourly labels (e.g., "2025-10-07T14" -> "2 PM")
|
// Format hourly labels (e.g., "2025-10-07T14" -> "2 PM")
|
||||||
if (label.includes("T")) {
|
if (label.includes("T")) {
|
||||||
const hour = label.split("T")[1];
|
try {
|
||||||
const hourNum = parseInt(hour, 10);
|
const hour = label.split("T")[1];
|
||||||
return hourNum === 0
|
const hourNum = parseInt(hour, 10);
|
||||||
? "12 AM"
|
|
||||||
: hourNum < 12
|
// Validate hour number
|
||||||
? `${hourNum} AM`
|
if (isNaN(hourNum) || hourNum < 0 || hourNum > 23) {
|
||||||
: hourNum === 12
|
return hour; // Return original hour if invalid
|
||||||
? "12 PM"
|
}
|
||||||
: `${hourNum - 12} PM`;
|
|
||||||
|
return hourNum === 0
|
||||||
|
? "12 AM"
|
||||||
|
: hourNum < 12
|
||||||
|
? `${hourNum} AM`
|
||||||
|
: hourNum === 12
|
||||||
|
? "12 PM"
|
||||||
|
: `${hourNum - 12} PM`;
|
||||||
|
} catch (error) {
|
||||||
|
return label; // Return original label if parsing fails
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format daily labels (e.g., "2025-10-07" -> "Oct 7")
|
// Format daily labels (e.g., "2025-10-07" -> "Oct 7")
|
||||||
const date = new Date(label);
|
try {
|
||||||
return date.toLocaleDateString("en-US", {
|
const date = new Date(label);
|
||||||
month: "short",
|
// Check if date is valid
|
||||||
day: "numeric",
|
if (isNaN(date.getTime())) {
|
||||||
});
|
return label; // Return original label if date is invalid
|
||||||
|
}
|
||||||
|
return date.toLocaleDateString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return label; // Return original label if parsing fails
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
|
|||||||
Reference in New Issue
Block a user