|
@@ -87,21 +87,30 @@ export function AMSHistoryModal({
|
|
|
if (!isOpen) return null;
|
|
if (!isOpen) return null;
|
|
|
|
|
|
|
|
// Format data for chart
|
|
// Format data for chart
|
|
|
- const chartData = data?.data.map(point => {
|
|
|
|
|
|
|
+ const rawPoints = data?.data.map(point => {
|
|
|
const date = parseUTCDate(point.recorded_at) || new Date();
|
|
const date = parseUTCDate(point.recorded_at) || new Date();
|
|
|
- const timeOptions: Intl.DateTimeFormatOptions = {
|
|
|
|
|
- hour: '2-digit',
|
|
|
|
|
- minute: '2-digit',
|
|
|
|
|
- ...(hours > 24 ? { day: 'numeric', month: 'short' } : {}),
|
|
|
|
|
- };
|
|
|
|
|
return {
|
|
return {
|
|
|
time: date.getTime(),
|
|
time: date.getTime(),
|
|
|
humidity: point.humidity,
|
|
humidity: point.humidity,
|
|
|
temperature: point.temperature,
|
|
temperature: point.temperature,
|
|
|
- timeLabel: date.toLocaleTimeString([], applyTimeFormat(timeOptions, timeFormat)),
|
|
|
|
|
};
|
|
};
|
|
|
}) || [];
|
|
}) || [];
|
|
|
|
|
|
|
|
|
|
+ // Pad edges so the line extends across the full time window
|
|
|
|
|
+ const domainStart = Date.now() - hours * 60 * 60 * 1000;
|
|
|
|
|
+ const domainEnd = Date.now();
|
|
|
|
|
+ const chartData = [...rawPoints];
|
|
|
|
|
+ if (chartData.length > 0) {
|
|
|
|
|
+ const first = chartData[0];
|
|
|
|
|
+ if (first.time > domainStart) {
|
|
|
|
|
+ chartData.unshift({ ...first, time: domainStart });
|
|
|
|
|
+ }
|
|
|
|
|
+ const last = chartData[chartData.length - 1];
|
|
|
|
|
+ if (last.time < domainEnd) {
|
|
|
|
|
+ chartData.push({ ...last, time: domainEnd });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Get thresholds
|
|
// Get thresholds
|
|
|
const humidityGood = thresholds?.humidityGood || 40;
|
|
const humidityGood = thresholds?.humidityGood || 40;
|
|
|
const humidityFair = thresholds?.humidityFair || 60;
|
|
const humidityFair = thresholds?.humidityFair || 60;
|
|
@@ -313,7 +322,7 @@ export function AMSHistoryModal({
|
|
|
<XAxis
|
|
<XAxis
|
|
|
dataKey="time"
|
|
dataKey="time"
|
|
|
type="number"
|
|
type="number"
|
|
|
- domain={['dataMin', 'dataMax']}
|
|
|
|
|
|
|
+ domain={[Date.now() - hours * 60 * 60 * 1000, Date.now()]}
|
|
|
tickFormatter={(ts) => {
|
|
tickFormatter={(ts) => {
|
|
|
const date = new Date(ts);
|
|
const date = new Date(ts);
|
|
|
if (hours > 24) {
|
|
if (hours > 24) {
|
|
@@ -372,6 +381,7 @@ export function AMSHistoryModal({
|
|
|
strokeWidth={2}
|
|
strokeWidth={2}
|
|
|
dot={false}
|
|
dot={false}
|
|
|
activeDot={{ r: 4 }}
|
|
activeDot={{ r: 4 }}
|
|
|
|
|
+ connectNulls={true}
|
|
|
/>
|
|
/>
|
|
|
</LineChart>
|
|
</LineChart>
|
|
|
</ResponsiveContainer>
|
|
</ResponsiveContainer>
|