From 63e67d580739079dd1bf87ed674032d97597bcd3 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期五, 09 十月 2026 11:27:38 +0800
Subject: [PATCH] docs(交接): 记录 2026 十一假期人员流动量情况 Excel 制作与口径
---
traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java | 135 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 135 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 29a8ff1..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
@@ -5,7 +5,10 @@
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
+import java.math.BigDecimal;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -42,6 +45,56 @@
}
@Test
+ void roundsLineDataToTheSamePrecisionAsLabels() {
+ assertEquals(new BigDecimal("0.49"),
+ HolidayTrendChartService.displayValue(new BigDecimal("0.4904"), false, 2));
+ assertEquals(new BigDecimal("0.49"),
+ HolidayTrendChartService.displayValue(new BigDecimal("0.4911"), false, 2));
+ assertEquals(new BigDecimal("0.491"),
+ HolidayTrendChartService.displayValue(new BigDecimal("0.4911"), false, 3));
+ assertEquals(new BigDecimal("0.123"),
+ HolidayTrendChartService.displayValue(new BigDecimal("0.1234"), true, 2));
+ }
+
+ @Test
+ void rendersSameGeometryWhenValuesRoundToSameLabel() {
+ HolidayTrendChartService service = new HolidayTrendChartService();
+ HolidayTrendChartService.ChartSeries first = new HolidayTrendChartService.ChartSeries();
+ first.setName("骞冲潎鎷ユ尋搴�");
+ first.setValues(java.util.Arrays.asList(
+ new BigDecimal("0.4904"), new BigDecimal("0.4923"), new BigDecimal("0.5100")));
+ HolidayTrendChartService.ChartSeries second = new HolidayTrendChartService.ChartSeries();
+ second.setName("骞冲潎鎷ユ尋搴�");
+ second.setValues(java.util.Arrays.asList(
+ new BigDecimal("0.4911"), new BigDecimal("0.4934"), new BigDecimal("0.5100")));
+
+ byte[] firstChart = service.lineChart("鎷ユ尋搴�",
+ java.util.Collections.singletonList(first), false, 2, 1100, 590);
+ byte[] secondChart = service.lineChart("鎷ユ尋搴�",
+ java.util.Collections.singletonList(second), false, 2, 1100, 590);
+
+ assertPng(firstChart);
+ assertPng(secondChart);
+ assertArrayEquals(firstChart, secondChart);
+ }
+
+ @Test
+ void scalesLineChartHeightForBetterVerticalSeparation() throws Exception {
+ HolidayTrendChartService service = new HolidayTrendChartService();
+ HolidayTrendChartService.ChartSeries series = new HolidayTrendChartService.ChartSeries();
+ series.setName("娴嬭瘯");
+ series.setValues(java.util.Arrays.asList(
+ new BigDecimal("1.00"), new BigDecimal("2.00"), new BigDecimal("3.00")));
+
+ byte[] png = service.lineChart("涓囦汉娆�",
+ java.util.Collections.singletonList(series), false, 1100, 590);
+ BufferedImage image = ImageIO.read(new ByteArrayInputStream(png));
+
+ assertNotNull(image);
+ assertEquals(HolidayTrendChartService.scaleLineChartHeight(590), image.getHeight());
+ }
+
+ @Test
void rendersHigherPrecisionLineLabelsWhenRequested() {
HolidayTrendChartService service = new HolidayTrendChartService();
HolidayTrendChartService.ChartSeries congestion = new HolidayTrendChartService.ChartSeries();
@@ -61,6 +114,88 @@
assertFalse(java.util.Arrays.equals(twoDecimals, threeDecimals));
}
+ @Test
+ void rendersLineChartWithConfiguredDayLabels() {
+ HolidayTrendChartService service = new HolidayTrendChartService();
+ HolidayTrendChartService.ChartSeries congestion = new HolidayTrendChartService.ChartSeries();
+ congestion.setName("\u5e73\u5747\u62e5\u6324\u5ea6");
+ congestion.setValues(java.util.Arrays.asList(
+ new BigDecimal("0.50"), new BigDecimal("0.48"), new BigDecimal("0.47"),
+ new BigDecimal("0.49"), new BigDecimal("0.49"), new BigDecimal("0.49"),
+ new BigDecimal("0.47")));
+ java.util.List<String> sevenDays = java.util.Arrays.asList(
+ "10\u67081\u65e5", "10\u67082\u65e5", "10\u67083\u65e5", "10\u67084\u65e5",
+ "10\u67085\u65e5", "10\u67086\u65e5", "10\u67087\u65e5");
+
+ byte[] custom = service.lineChart("\u62e5\u6324\u5ea6",
+ java.util.Collections.singletonList(congestion), false, 2, sevenDays, 1100, 590);
+ byte[] defaults = service.lineChart("\u62e5\u6324\u5ea6",
+ java.util.Collections.singletonList(congestion), false, 2, 1100, 590);
+
+ assertPng(custom);
+ assertPng(defaults);
+ assertFalse(java.util.Arrays.equals(custom, defaults),
+ "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