fix(timeline): align range mask with slider

This commit is contained in:
2026-07-16 11:38:22 +08:00
parent 041b4ef89d
commit d90ca7c951
3 changed files with 47 additions and 15 deletions
+23 -15
View File
@@ -33,6 +33,7 @@ import { useMap } from "../MapComponent";
import { import {
formatTimelineTime, formatTimelineTime,
getRoundedCurrentTimelineMinutes, getRoundedCurrentTimelineMinutes,
getTimelineDisabledRangePercentages,
normalizeTimelineMinutes, normalizeTimelineMinutes,
} from "./timelineTime"; } from "./timelineTime";
@@ -109,6 +110,10 @@ const Timeline: React.FC<TimelineProps> = ({
minTime, minTime,
maxTime, maxTime,
); );
const disabledRangePercentages = getTimelineDisabledRangePercentages(
minTime,
maxTime,
);
useEffect(() => { useEffect(() => {
if (schemeDate) { if (schemeDate) {
setSelectedDate(schemeDate); setSelectedDate(schemeDate);
@@ -945,22 +950,28 @@ const Timeline: React.FC<TimelineProps> = ({
/> />
{/* 禁用区域遮罩 */} {/* 禁用区域遮罩 */}
{timeRange && ( {timeRange && (
<> <Box
sx={{
position: "absolute",
left: 16,
right: 16,
top: "30%",
transform: "translateY(-50%)",
height: "20px",
pointerEvents: "none",
}}
>
{/* 左侧禁用区域 */} {/* 左侧禁用区域 */}
{minTime > 0 && ( {minTime > 0 && (
<Box <Box
sx={{ sx={{
position: "absolute", position: "absolute",
left: "14px", left: 0,
top: "30%", width: `${disabledRangePercentages.leftWidth}%`,
transform: "translateY(-50%)", height: "100%",
width: `${(minTime / 1440) * 856 + 2}px`,
height: "20px",
backgroundColor: "rgba(189, 189, 189, 0.4)", backgroundColor: "rgba(189, 189, 189, 0.4)",
pointerEvents: "none",
backdropFilter: "blur(1px)", backdropFilter: "blur(1px)",
borderRadius: "2.5px", borderRadius: "2.5px",
rounded: "true",
}} }}
/> />
)} )}
@@ -969,19 +980,16 @@ const Timeline: React.FC<TimelineProps> = ({
<Box <Box
sx={{ sx={{
position: "absolute", position: "absolute",
left: `${16 + (maxTime / 1440) * 856}px`, left: `${disabledRangePercentages.rightLeft}%`,
top: "30%", width: `${disabledRangePercentages.rightWidth}%`,
transform: "translateY(-50%)", height: "100%",
width: `${((1440 - maxTime) / 1440) * 856}px`,
height: "20px",
backgroundColor: "rgba(189, 189, 189, 0.4)", backgroundColor: "rgba(189, 189, 189, 0.4)",
pointerEvents: "none",
backdropFilter: "blur(1px)", backdropFilter: "blur(1px)",
borderRadius: "2.5px", borderRadius: "2.5px",
}} }}
/> />
)} )}
</> </Box>
)} )}
</Box> </Box>
</Box> </Box>
@@ -1,6 +1,7 @@
import { import {
formatTimelineTime, formatTimelineTime,
getRoundedCurrentTimelineMinutes, getRoundedCurrentTimelineMinutes,
getTimelineDisabledRangePercentages,
normalizeTimelineMinutes, normalizeTimelineMinutes,
} from "./timelineTime"; } from "./timelineTime";
@@ -18,4 +19,12 @@ describe("timelineTime", () => {
it("rounds the current time down to the timeline step", () => { it("rounds the current time down to the timeline step", () => {
expect(getRoundedCurrentTimelineMinutes(new Date("2026-07-16T10:29:00"))).toBe(615); expect(getRoundedCurrentTimelineMinutes(new Date("2026-07-16T10:29:00"))).toBe(615);
}); });
it("calculates disabled range as full-day percentages", () => {
expect(getTimelineDisabledRangePercentages(360, 1080)).toEqual({
leftWidth: 25,
rightLeft: 75,
rightWidth: 25,
});
});
}); });
@@ -30,3 +30,18 @@ export const formatTimelineTime = (
.toString() .toString()
.padStart(2, "0")}`; .padStart(2, "0")}`;
}; };
export const getTimelineDisabledRangePercentages = (
minTime: number,
maxTime: number,
) => {
const rangeStart = normalizeTimelineMinutes(minTime);
const rangeEnd = normalizeTimelineMinutes(maxTime);
return {
leftWidth: (rangeStart / TIMELINE_MINUTES_PER_DAY) * 100,
rightLeft: (rangeEnd / TIMELINE_MINUTES_PER_DAY) * 100,
rightWidth:
((TIMELINE_MINUTES_PER_DAY - rangeEnd) / TIMELINE_MINUTES_PER_DAY) * 100,
};
};