From ce52eafb03c238cc960abf0133baf53206b38cc2 Mon Sep 17 00:00:00 2001 From: wisonic Date: Thu, 1 Aug 2024 00:17:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9B=BE=E8=A1=A8):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=86=E7=BB=84=E5=92=8C=E5=A0=86=E5=8F=A0=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E4=B8=8B=E9=92=BB=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../charts/impl/bar/StackBarHandler.java | 5 +-- .../charts/impl/bar/StackGroupBarHandler.java | 7 ++-- .../charts/impl/line/StackAreaHandler.java | 5 +-- .../dataease/chart/utils/ChartDataBuild.java | 34 ++++++------------- 4 files changed, 19 insertions(+), 32 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackBarHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackBarHandler.java index 992d1ca991..fb8b8cb805 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackBarHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackBarHandler.java @@ -65,7 +65,8 @@ public class StackBarHandler extends BarHandler { var xAxis = formatResult.getAxisMap().get(ChartAxis.xAxis); var extStack = formatResult.getAxisMap().get(ChartAxis.extStack); var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis); - var xAxisBase = xAxis.subList(0, xAxis.size() - extStack.size()); - return ChartDataBuild.transStackChartDataAntV(xAxisBase, yAxis, view, data, extStack, isDrill); + var drillAxis = xAxis.stream().filter(axis -> FieldSource.DRILL == axis.getSource()).toList(); + var xAxisBase = xAxis.subList(0, xAxis.size() - extStack.size() - drillAxis.size()); + return ChartDataBuild.transStackChartDataAntV(xAxisBase, xAxis, yAxis, view, data, extStack, isDrill); } } diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackGroupBarHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackGroupBarHandler.java index e1e7179b76..78e3fc04d7 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackGroupBarHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/bar/StackGroupBarHandler.java @@ -31,7 +31,6 @@ public class StackGroupBarHandler extends BarHandler { var xAxis = result.getAxisMap().get(ChartAxis.xAxis); xAxis.addAll(view.getXAxisExt()); xAxis.addAll(view.getExtStack()); - result.getAxisMap().put(ChartAxis.xAxisExt, view.getExtStack()); result.getAxisMap().put(ChartAxis.extStack, view.getExtStack()); result.getAxisMap().put(ChartAxis.xAxisExt, view.getXAxisExt()); return result; @@ -82,8 +81,8 @@ public class StackGroupBarHandler extends BarHandler { var xAxisExt = formatResult.getAxisMap().get(ChartAxis.xAxisExt); var extStack = formatResult.getAxisMap().get(ChartAxis.extStack); var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis); - var xAxisBase = xAxis.subList(0, xAxis.size() - xAxisExt.size() - extStack.size()); - var xAxisMain = xAxis.subList(0, xAxis.size() - extStack.size()); - return ChartDataBuild.transGroupStackDataAntV(xAxisBase, xAxisMain, xAxisExt, yAxis, extStack, data, view, isDrill); + var drillAxis = xAxis.stream().filter(axis -> FieldSource.DRILL == axis.getSource()).toList(); + var xAxisBase = xAxis.subList(0, xAxis.size() - xAxisExt.size() - extStack.size() - drillAxis.size()); + return ChartDataBuild.transGroupStackDataAntV(xAxisBase, xAxis, xAxisExt, yAxis, extStack, data, view, isDrill); } } diff --git a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/line/StackAreaHandler.java b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/line/StackAreaHandler.java index d7f4c8ed69..598c5f570c 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/charts/impl/line/StackAreaHandler.java +++ b/core/core-backend/src/main/java/io/dataease/chart/charts/impl/line/StackAreaHandler.java @@ -46,9 +46,10 @@ public class StackAreaHandler extends YoyChartHandler { .anyMatch(ele -> ele.getFilterType() == 1); var xAxis = formatResult.getAxisMap().get(ChartAxis.xAxis); var extStack = formatResult.getAxisMap().get(ChartAxis.extStack); - var axisBase = xAxis.subList(0, xAxis.size() - extStack.size()); var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis); - return ChartDataBuild.transStackChartDataAntV(axisBase, yAxis, view, data, extStack, isDrill); + var drillAxis = xAxis.stream().filter(axis -> FieldSource.DRILL == axis.getSource()).toList(); + var xAxisBase = xAxis.subList(0, xAxis.size() - extStack.size() - drillAxis.size()); + return ChartDataBuild.transStackChartDataAntV(xAxisBase, xAxis, yAxis, view, data, extStack, isDrill); } @Override diff --git a/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java b/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java index 28698d4652..6e7eeb0b51 100644 --- a/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java +++ b/core/core-backend/src/main/java/io/dataease/chart/utils/ChartDataBuild.java @@ -265,7 +265,7 @@ public class ChartDataBuild { } // AntV柱状堆叠图 - public static Map transStackChartDataAntV(List xAxis, List yAxis, ChartViewDTO view, List data, List extStack, boolean isDrill) { + public static Map transStackChartDataAntV(List xAxisBase, List xAxis, List yAxis, ChartViewDTO view, List data, List extStack, boolean isDrill) { Map map = new HashMap<>(); List dataList = new ArrayList<>(); @@ -279,8 +279,8 @@ public class ChartDataBuild { if (isDrill) { a.append(row[xAxis.size() - 1]); } else { - for (int i = 0; i < xAxis.size(); i++) { - if (i == xAxis.size() - 1) { + for (int i = 0; i < xAxisBase.size(); i++) { + if (i == xAxisBase.size() - 1) { a.append(row[i]); } else { a.append(row[i]).append("\n"); @@ -289,7 +289,7 @@ public class ChartDataBuild { } axisChartDataDTO.setField(a.toString()); axisChartDataDTO.setName(a.toString()); - axisChartDataDTO.setCategory(row[xAxis.size()]); + axisChartDataDTO.setCategory(row[xAxisBase.size()]); List dimensionList = new ArrayList<>(); List quotaList = new ArrayList<>(); @@ -300,18 +300,10 @@ public class ChartDataBuild { chartDimensionDTO.setValue(row[k]); dimensionList.add(chartDimensionDTO); } - ChartDimensionDTO chartDimensionDTO = new ChartDimensionDTO(); - chartDimensionDTO.setId(extStack.get(0).getId()); - chartDimensionDTO.setValue(row[xAxis.size()]); - dimensionList.add(chartDimensionDTO); axisChartDataDTO.setDimensionList(dimensionList); - // yAxis最后的数据对应extLabel和extTooltip,将他们从yAxis中去掉,同时转换成动态值 - int size = xAxis.size() + extStack.size() + yAxis.size(); - int extSize = view.getExtLabel().size() + view.getExtTooltip().size(); - if (ObjectUtils.isNotEmpty(yAxis)) { - int valueIndex = xAxis.size() + extStack.size(); + int valueIndex = xAxis.size(); ChartQuotaDTO chartQuotaDTO = new ChartQuotaDTO(); chartQuotaDTO.setId(yAxis.get(0).getId()); quotaList.add(chartQuotaDTO); @@ -321,7 +313,6 @@ public class ChartDataBuild { } catch (Exception e) { axisChartDataDTO.setValue(new BigDecimal(0)); } - buildDynamicValue(view, axisChartDataDTO, row, size, extSize); } else { axisChartDataDTO.setQuotaList(quotaList); axisChartDataDTO.setValue(new BigDecimal(0)); @@ -345,11 +336,7 @@ public class ChartDataBuild { } } - // yAxis最后的数据对应extLabel和extTooltip,将他们从yAxis中去掉,同时转换成动态值 - int size = xAxis.size() + yAxis.size(); - int extSize = view.getExtLabel().size() + view.getExtTooltip().size(); - - for (int i = xAxis.size(); i < size - extSize; i++) { + for (int i = xAxis.size(); i < xAxis.size() + yAxis.size(); i++) { AxisChartDataAntVDTO axisChartDataDTO = new AxisChartDataAntVDTO(); axisChartDataDTO.setField(a.toString()); axisChartDataDTO.setName(a.toString()); @@ -376,7 +363,6 @@ public class ChartDataBuild { axisChartDataDTO.setValue(new BigDecimal(0)); } axisChartDataDTO.setCategory(StringUtils.defaultIfBlank(yAxis.get(j).getChartShowName(), yAxis.get(j).getName())); - buildDynamicValue(view, axisChartDataDTO, row, size, extSize); dataList.add(axisChartDataDTO); } } @@ -1335,7 +1321,7 @@ public class ChartDataBuild { public static Map transGroupStackDataAntV(List xAxisBase, List xAxis, List xAxisExt, List yAxis, List extStack, List data, ChartViewDTO view, boolean isDrill) { // 堆叠柱状图 if (ObjectUtils.isEmpty(xAxisExt)) { - return transStackChartDataAntV(xAxis, yAxis, view, data, extStack, isDrill); + return transStackChartDataAntV(xAxisBase, xAxis, yAxis, view, data, extStack, isDrill); // 分组柱状图 } else if (ObjectUtils.isNotEmpty(xAxisExt) && ObjectUtils.isEmpty(extStack)) { return transBaseGroupDataAntV(xAxisBase, xAxis, xAxisExt, yAxis, view, data, isDrill); @@ -1370,8 +1356,8 @@ public class ChartDataBuild { } StringBuilder stackField = new StringBuilder(); - for (int i = xAxis.size(); i < xAxis.size() + extStack.size(); i++) { - if (i == xAxis.size() + extStack.size() - 1) { + for (int i = xAxisBase.size() + xAxisExt.size(); i < xAxisBase.size() + xAxisExt.size() + extStack.size(); i++) { + if (i == xAxisBase.size() + xAxisExt.size() + extStack.size() - 1) { stackField.append(row[i]); } else { stackField.append(row[i]).append("\n"); @@ -1398,7 +1384,7 @@ public class ChartDataBuild { axisChartDataDTO.setDimensionList(dimensionList); if (ObjectUtils.isNotEmpty(yAxis)) { - int valueIndex = xAxis.size() + extStack.size(); + int valueIndex = xAxis.size(); ChartQuotaDTO chartQuotaDTO = new ChartQuotaDTO(); chartQuotaDTO.setId(yAxis.get(0).getId()); quotaList.add(chartQuotaDTO);