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/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java b/traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java
index 24bffda..90db24d 100644
--- a/traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java
+++ b/traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java
@@ -138,6 +138,64 @@
                 "custom day labels should change the rendered axis");
     }
 
+    @Test
+    void pinsRequestedLineLabelToFixedAnchor() throws Exception {
+        HolidayTrendChartService service = new HolidayTrendChartService();
+        HolidayTrendChartService.ChartSeries series = new HolidayTrendChartService.ChartSeries();
+        series.setName("2026\u5e74");
+        series.setValues(java.util.Collections.singletonList(new BigDecimal("72.4")));
+        java.util.List<HolidayTrendChartService.ChartSeries> single =
+                java.util.Collections.singletonList(series);
+
+        byte[] plain = service.lineChart("\u4e07\u4eba\u6b21", single, false, 2, 1100, 590);
+        byte[] emptyOverrides = service.lineChart("\u4e07\u4eba\u6b21", single, false, 2,
+                HolidayTrendChartService.DAY_LABELS, 1100, 590,
+                java.util.Collections.emptyList());
+        assertArrayEquals(plain, emptyOverrides,
+                "an empty override list must keep the automatic placement");
+
+        byte[] unmatched = service.lineChart("\u4e07\u4eba\u6b21", single, false, 2,
+                HolidayTrendChartService.DAY_LABELS, 1100, 590,
+                java.util.Collections.singletonList(new HolidayTrendChartService.LineLabelOverride(
+                        0, 7, HolidayTrendChartService.LineLabelAnchor.ABOVE)));
+        assertArrayEquals(plain, unmatched,
+                "an override for a label that does not exist must not change rendering");
+
+        byte[] above = service.lineChart("\u4e07\u4eba\u6b21", single, false, 2,
+                HolidayTrendChartService.DAY_LABELS, 1100, 590,
+                java.util.Collections.singletonList(new HolidayTrendChartService.LineLabelOverride(
+                        0, 0, HolidayTrendChartService.LineLabelAnchor.ABOVE)));
+        byte[] below = service.lineChart("\u4e07\u4eba\u6b21", single, false, 2,
+                HolidayTrendChartService.DAY_LABELS, 1100, 590,
+                java.util.Collections.singletonList(new HolidayTrendChartService.LineLabelOverride(
+                        0, 0, HolidayTrendChartService.LineLabelAnchor.BELOW)));
+
+        assertPng(above);
+        assertPng(below);
+        assertFalse(java.util.Arrays.equals(above, below),
+                "ABOVE and BELOW anchors must render differently");
+        assertTrue(meanSeriesColorY(above) < meanSeriesColorY(below),
+                "the ABOVE anchor must place the label higher than the BELOW anchor");
+    }
+
+    private double meanSeriesColorY(byte[] data) throws Exception {
+        BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
+        assertNotNull(image);
+        int target = 0xC0504D;
+        long count = 0;
+        long sum = 0;
+        for (int y = 0; y < image.getHeight() - 60; y++) {
+            for (int x = 0; x < image.getWidth(); x++) {
+                if ((image.getRGB(x, y) & 0xFFFFFF) == target) {
+                    count++;
+                    sum += y;
+                }
+            }
+        }
+        assertTrue(count > 0, "expected series-coloured pixels for the item label");
+        return (double) sum / count;
+    }
+
     private void assertNoLargeLightGrayBackground(byte[] data) throws Exception {
         BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
         int matches = 0;

--
Gitblit v1.9.1