From bc822c6ca3e1ce3e16a38ba877449fc697be9511 Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期二, 06 十月 2026 14:09:41 +0800
Subject: [PATCH] fix(holiday): 折线图按标签精度绘制
---
traffic-audit-server/src/test/java/com/trafficaudit/holiday/service/HolidayTrendChartServiceTest.java | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 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..03cf0a1 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,40 @@
}
@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 rendersHigherPrecisionLineLabelsWhenRequested() {
HolidayTrendChartService service = new HolidayTrendChartService();
HolidayTrendChartService.ChartSeries congestion = new HolidayTrendChartService.ChartSeries();
--
Gitblit v1.9.1