From 9ee7acd9d16e59224ee5184c89374f06d6592ad3 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期日, 04 十月 2026 17:47:34 +0800
Subject: [PATCH] feat(holiday): 新增节假日综合运输客流量走势图

---
 traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java |   62 +++++++++++++++++++++++++++++++
 1 files changed, 62 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
new file mode 100644
index 0000000..e705637
--- /dev/null
+++ b/traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java
@@ -0,0 +1,62 @@
+package com.trafficaudit.holiday.service;
+
+import org.junit.jupiter.api.Test;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class HolidayTrendChartServiceTest {
+
+    @Test
+    void rendersLinePieAndStackedChartsAsPng() throws Exception {
+        HolidayTrendChartService service = new HolidayTrendChartService();
+        HolidayTrendChartService.ChartSeries first = new HolidayTrendChartService.ChartSeries();
+        first.setName("2026骞�");
+        first.setValues(java.util.Arrays.asList(
+                java.math.BigDecimal.ONE, java.math.BigDecimal.TEN, null));
+        HolidayTrendChartService.ChartSeries second = new HolidayTrendChartService.ChartSeries();
+        second.setName("2025骞�");
+        second.setValues(java.util.Arrays.asList(
+                java.math.BigDecimal.valueOf(2), java.math.BigDecimal.valueOf(8),
+                java.math.BigDecimal.valueOf(4)));
+
+        byte[] line = service.lineChart("涓囦汉娆�", java.util.Arrays.asList(first, second), false);
+        assertPng(line);
+        assertNoLargeLightGrayBackground(line);
+
+        HolidayTrendChartService.ChartCategory category = new HolidayTrendChartService.ChartCategory();
+        category.setName("閾佽矾");
+        category.setValue(java.math.BigDecimal.TEN);
+        byte[] pie = service.pieChart("浜烘", java.util.Collections.singletonList(category), 400, 300);
+        assertPng(pie);
+
+        byte[] stacked = service.stackedBarChart("鍗犳瘮", java.util.Arrays.asList("10鏈�1鏃�", "10鏈�2鏃�"),
+                java.util.Arrays.asList(first, second), true, 500, 320);
+        assertPng(stacked);
+        assertNoLargeLightGrayBackground(stacked);
+    }
+
+    private void assertNoLargeLightGrayBackground(byte[] data) throws Exception {
+        BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
+        int matches = 0;
+        for (int y = 0; y < image.getHeight(); y++) {
+            for (int x = 0; x < image.getWidth(); x++) {
+                int rgb = image.getRGB(x, y) & 0xFFFFFF;
+                if (rgb == 0xF3F4F3) matches++;
+            }
+        }
+        assertTrue(matches < image.getWidth() * image.getHeight() / 20,
+                "chart still contains a large light-gray background area");
+    }
+
+    private void assertPng(byte[] data) {
+        assertNotNull(data);
+        assertTrue(data.length > 100);
+        assertTrue(data[0] == (byte) 0x89 && data[1] == 0x50
+                && data[2] == 0x4e && data[3] == 0x47);
+    }
+}

--
Gitblit v1.9.1