From adee580f186d7f1cc5d5405792d6b0c13076f0a2 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期四, 08 十月 2026 14:29:41 +0800
Subject: [PATCH] fix(holiday): 铁路客运量走势图10月3日标签上移避免遮挡
---
traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayTrendService.java | 33 ++++++++++++++++++++++++---------
1 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayTrendService.java b/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayTrendService.java
index 9960464..08ef648 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayTrendService.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/holiday/service/HolidayTrendService.java
@@ -15,6 +15,7 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -84,7 +85,13 @@
blocks.add(new HolidayTrendWordService.ChartBlock(
"鈥�" + holidayLabel + "鈥濆亣鏈熼搧璺杩愰噺鎯呭喌",
chartService.lineChart("涓囦汉娆�",
- series(years, yearData, item -> item.rail), false, 1100, 445),
+ // Pin the 2026 rail label for day 3 above its point so the
+ // 2024 label (70.6) no longer covers it; other charts keep
+ // automatic placement.
+ series(years, yearData, item -> item.rail), false, 2,
+ HolidayTrendChartService.DAY_LABELS, 1100, 445,
+ Collections.singletonList(new HolidayTrendChartService.LineLabelOverride(
+ 0, 2, HolidayTrendChartService.LineLabelAnchor.ABOVE))),
lineImageSize(5264785L, 2129155L)));
blocks.add(new HolidayTrendWordService.ChartBlock(
"鈥�" + holidayLabel + "鈥濆亣鏈熸按璺杩愰噺鎯呭喌",
@@ -138,12 +145,14 @@
blocks.add(new HolidayTrendWordService.ChartBlock(
prefix + "鏅�氬浗鐪侀亾瑙傛祴绔欏钩鍧囨満鍔ㄨ溅閫熷害",
chartService.lineChart("鍏噷/灏忔椂",
- Collections.singletonList(series("骞冲潎閫熷害", observation.speed)), false, 1100, 590),
+ Collections.singletonList(series("骞冲潎閫熷害", observation.speed)), false, 2,
+ observation.labels, 1100, 590),
lineImageSize(5268595L, 2821305L)));
blocks.add(new HolidayTrendWordService.ChartBlock(
prefix + "鏅�氬浗鐪侀亾瑙傛祴绔欏钩鍧囨嫢鎸ゅ害",
chartService.lineChart("鎷ユ尋搴�",
- Collections.singletonList(series("骞冲潎鎷ユ尋搴�", observation.congestion)), false, 1100, 590),
+ Collections.singletonList(series("骞冲潎鎷ユ尋搴�", observation.congestion)), false, 2,
+ observation.labels, 1100, 590),
lineImageSize(5268595L, 2821305L)));
File template = resolveTemplateFile();
@@ -263,23 +272,27 @@
private ObservationData observationData(int year, String holidayType) {
List<HolidayCalendar> days = configService.findHolidayDays(year, holidayType);
if (days.isEmpty()) {
- return new ObservationData(nulls(), nulls());
+ return new ObservationData(nulls(), nulls(), HolidayTrendChartService.DAY_LABELS);
}
LocalDate start = days.get(0).getHolidayDate();
- LocalDate end = start.plusDays(HolidayTrendChartService.DAY_LABELS.size() - 1L);
+ LocalDate end = days.get(days.size() - 1).getHolidayDate();
List<ObservationDailyOperation> rows = observationStationFlowMapper.selectDailyOperations(start, end);
Map<LocalDate, ObservationDailyOperation> byDate = new LinkedHashMap<>();
for (ObservationDailyOperation row : rows) {
byDate.put(row.getObsDate(), row);
}
+ DateTimeFormatter labelFormat = DateTimeFormatter.ofPattern("M鏈坉鏃�");
List<BigDecimal> speed = new ArrayList<>();
List<BigDecimal> congestion = new ArrayList<>();
- for (int i = 0; i < HolidayTrendChartService.DAY_LABELS.size(); i++) {
- ObservationDailyOperation row = byDate.get(start.plusDays(i));
+ List<String> labels = new ArrayList<>();
+ for (HolidayCalendar day : days) {
+ LocalDate date = day.getHolidayDate();
+ ObservationDailyOperation row = byDate.get(date);
speed.add(row == null ? null : row.getAverageSpeed());
congestion.add(row == null ? null : row.getAverageCongestion());
+ labels.add(date.format(labelFormat));
}
- return new ObservationData(speed, congestion);
+ return new ObservationData(speed, congestion, labels);
}
private HolidayTrendChartService.ChartSeries series(String name, List<BigDecimal> values) {
@@ -441,10 +454,12 @@
private static class ObservationData {
private final List<BigDecimal> speed;
private final List<BigDecimal> congestion;
+ private final List<String> labels;
- private ObservationData(List<BigDecimal> speed, List<BigDecimal> congestion) {
+ private ObservationData(List<BigDecimal> speed, List<BigDecimal> congestion, List<String> labels) {
this.speed = speed;
this.congestion = congestion;
+ this.labels = labels;
}
}
}
--
Gitblit v1.9.1