From 23cc3c6a3af32668a9c4cb19e67301d76d555e3a Mon Sep 17 00:00:00 2001 From: Patrykb0802 Date: Wed, 7 Feb 2024 11:38:32 +0100 Subject: [PATCH 1/8] #2726 Legend occupies too much space in reports screen Added: - In ReportChartCreator.java, variables that control height (of legend and consolidated chart) for every point added to report - calculateHeightConsolidatedChart method to calculate height needed for consolidated graph in ImageChartUtils.java - CalculateConsolidatedChartHeightTest.java and CalculateConsolidatedChartHeightExceptionTest.java for testing calculateHeightConsolidatedChart method - ReplaceMacroStringUtilsWithProdParametersTest.java for testing RepalceMacro method - getters inside PointInfo in ReportInstancePointDAO.java Changed: - In ReportInstancePointDAO.java how names of data source and data point are passed, now they are truncated before passing them to ReportChartCreator - insert method in ReportInstancePointDAO.java so now it takes less parameters (uses only pointInfo now for all necessary data point information) - truncate method to abbreviateMiddle for truncating data source and data point names so they fit report chart - Deprecated truncate method in StringUtils.java and truncate method tests in StringUtilsTest.java --- build.gradle | 2 + .../mango/vo/report/ImageChartUtils.java | 27 ++ .../mango/vo/report/ReportChartCreator.java | 31 +- .../dao/report/ReportInstancePointDAO.java | 32 ++- .../mango/service/ReportService.java | 15 +- .../scada_lts/serorepl/utils/StringUtils.java | 16 +- ...eConsolidatedChartHeightExceptionTest.java | 58 ++++ .../CalculateConsolidatedChartHeightTest.java | 269 ++++++++++++++++++ ...acroStringUtilsWithProdParametersTest.java | 69 +++++ .../serorepl/utils/StringUtilsTest.java | 2 +- 10 files changed, 500 insertions(+), 21 deletions(-) create mode 100644 test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java create mode 100644 test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java create mode 100644 test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java diff --git a/build.gradle b/build.gradle index 101f809700..02acf7a856 100644 --- a/build.gradle +++ b/build.gradle @@ -204,5 +204,7 @@ test { includeTestsMatching "com.serotonin.mango.rt.maint.work.CreateWorkItemToStringTest" includeTestsMatching "com.serotonin.util.SerializationHelperTest" includeTestsMatching "org.scada_lts.web.mvc.api.json.WorkItemInfoListTest" + includeTestsMatching "com.serotonin.mango.vo.report.CalculateConsolidatedChartHeightTest" + includeTestsMatching "com.serotonin.mango.vo.report.CalculateConsolidatedChartHeightTestException" } } \ No newline at end of file diff --git a/src/com/serotonin/mango/vo/report/ImageChartUtils.java b/src/com/serotonin/mango/vo/report/ImageChartUtils.java index 3e34f72408..4d3e2c1b34 100644 --- a/src/com/serotonin/mango/vo/report/ImageChartUtils.java +++ b/src/com/serotonin/mango/vo/report/ImageChartUtils.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Date; +import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -210,4 +211,30 @@ public static void addSecond(TimeSeries timeSeries, long time, Number value) { catch (SeriesException e) { /* duplicate Second. Ignore. */ } } + + public static int calculateHeightConsolidatedChart(List pointStatistics, int imageHeight, int imageHeightForDataPointNameInLegend, int charNumberPerLine) { + StringBuilder subLegend = new StringBuilder(); + int linesAmount = 0; + String charsForColorIndicator = "111"; + for (ReportChartCreator.PointStatistics point : pointStatistics){ + subLegend.append(charsForColorIndicator); + if (point.getName().length() > charNumberPerLine){ + throw new IllegalArgumentException("Point name is too long: " + point.getName()); + } + + else if ((subLegend.length() + point.getName().length()) > charNumberPerLine){ + subLegend.delete(0, subLegend.length()); + linesAmount++; + subLegend.append(charsForColorIndicator); + subLegend.append(point.getName()); + } + else { + subLegend.append(point.getName()); + } + } + if (pointStatistics.isEmpty() || pointStatistics.get(pointStatistics.size() - 1).getName().length() != charNumberPerLine) { + linesAmount++; + } + return (imageHeight - imageHeightForDataPointNameInLegend + (linesAmount*imageHeightForDataPointNameInLegend)); + } } diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index d77ddb2c12..47a92e64ed 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -58,6 +58,10 @@ public class ReportChartCreator { */ private static final int IMAGE_WIDTH = 930; private static final int IMAGE_HEIGHT = 400; + private static final int IMAGE_POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; + private static final int CHARACTERS_PER_LINE_IN_CHART_LEGEND_NUMBER = 149; + private static final int DATA_SOURCE_NAME_LENGTH_FOR_CHART = 35; + private static final int DATA_POINT_NAME_LENGTH_FOR_CHART = 100; public static final String IMAGE_CONTENT_ID = "reportChart.png"; public static final int POINT_IMAGE_WIDTH = 440; @@ -79,7 +83,15 @@ public ReportChartCreator(ResourceBundle bundle) { this.bundle = bundle; } - /** + public static int getDataSourceNameLengthForReport() { + return DATA_SOURCE_NAME_LENGTH_FOR_CHART; + } + + public static int getDataPointNameLengthForReport() { + return DATA_POINT_NAME_LENGTH_FOR_CHART; + } + + /** * Uses the given parameters to create the data for the fields of this class. Once the content has been created the * getters for the fields can be used to retrieve. * @@ -144,8 +156,12 @@ else if (pointStat.getDiscreteTimeSeries() != null) // The path comes from the servlet path definition in web.xml. model.put("chartName", IMAGE_SERVLET + chartName); } - - imageData = ImageChartUtils.getChartData(ptsc, true, IMAGE_WIDTH, IMAGE_HEIGHT); + try{ + int consolidatedChartHeight = ImageChartUtils.calculateHeightConsolidatedChart(pointStatistics, IMAGE_HEIGHT, IMAGE_POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS, CHARACTERS_PER_LINE_IN_CHART_LEGEND_NUMBER); + imageData = ImageChartUtils.getChartData(ptsc, true, IMAGE_WIDTH, consolidatedChartHeight); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } } List events = null; @@ -255,7 +271,7 @@ public List getPointStatistics() { return pointStatistics; } - public class PointStatistics { + public static class PointStatistics { private final int reportPointId; private String name; private int dataType; @@ -268,8 +284,11 @@ public class PointStatistics { private DiscreteTimeSeries discreteTimeSeries; private byte[] imageData; - public PointStatistics(int reportPointId) { + private String inlinePrefix; + + public PointStatistics(int reportPointId, String inlinePrefix) { this.reportPointId = reportPointId; + this.inlinePrefix = inlinePrefix; } public String getName() { @@ -475,7 +494,7 @@ public PointTimeSeriesCollection getPointTimeSeriesCollection() { public void startPoint(ReportPointInfo pointInfo) { donePoint(); - point = new PointStatistics(pointInfo.getReportPointId()); + point = new PointStatistics(pointInfo.getReportPointId(), inlinePrefix); point.setName(pointInfo.getExtendedName()); point.setDataType(pointInfo.getDataType()); point.setDataTypeDescription(DataTypes.getDataTypeMessage(pointInfo.getDataType()).getLocalizedMessage( diff --git a/src/org/scada_lts/dao/report/ReportInstancePointDAO.java b/src/org/scada_lts/dao/report/ReportInstancePointDAO.java index adb0642564..31dd6e9adc 100644 --- a/src/org/scada_lts/dao/report/ReportInstancePointDAO.java +++ b/src/org/scada_lts/dao/report/ReportInstancePointDAO.java @@ -22,12 +22,14 @@ import com.serotonin.mango.rt.dataImage.types.MangoValue; import com.serotonin.mango.view.text.TextRenderer; import com.serotonin.mango.vo.DataPointVO; +import com.serotonin.mango.vo.report.ReportChartCreator; import com.serotonin.mango.vo.report.ReportInstance; import com.serotonin.mango.vo.report.ReportPointInfo; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.scada_lts.dao.DAO; import org.scada_lts.dao.SerializationData; +import org.scada_lts.serorepl.utils.StringUtils; import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.jdbc.core.PreparedStatementCreator; import org.springframework.jdbc.core.RowMapper; @@ -111,6 +113,10 @@ public PointInfo(DataPointVO point, String colour, boolean consolidatedChart) { this.consolidatedChart = consolidatedChart; } + public int getId() { + return point.getId(); + } + public DataPointVO getPoint() { return point; } @@ -119,6 +125,20 @@ public String getColour() { return colour; } + public String getName() { + return StringUtils.abbreviateMiddle(point.getName(), ReportChartCreator.getDataPointNameLengthForReport()); + } + + public String getDeviceName() { + return StringUtils.abbreviateMiddle(point.getDeviceName(), ReportChartCreator.getDataSourceNameLengthForReport()); + } + + public TextRenderer getTextRenderer() { + return point.getTextRenderer(); + } + + + public boolean isConsolidatedChart() { return consolidatedChart; } @@ -133,8 +153,14 @@ public List getPointInfos(int instanceId) { return DAO.getInstance().getJdbcTemp().query(REPORT_INSTANCE_POINT_SELECT_WHERE, new Object[]{instanceId}, new ReportPointInfoRowMapper()); } + @Deprecated(since = "2.7.7") @Transactional(readOnly = false,propagation= Propagation.REQUIRES_NEW,isolation= Isolation.READ_COMMITTED,rollbackFor=SQLException.class) public int insert(final ReportInstance reportInstance, final DataPointVO point, final String name, final int dataType, final MangoValue startValue, final PointInfo pointInfo) { + return insert(reportInstance, dataType, startValue, pointInfo); + } + + @Transactional(readOnly = false,propagation= Propagation.REQUIRES_NEW,isolation= Isolation.READ_COMMITTED,rollbackFor=SQLException.class) + public int insert(final ReportInstance reportInstance, final int dataType, final MangoValue startValue, final PointInfo pointInfo) { if (LOG.isTraceEnabled()) { LOG.trace("insert()"); @@ -147,11 +173,11 @@ public PreparedStatement createPreparedStatement(Connection connection) throws S PreparedStatement preparedStatement = connection.prepareStatement(REPORT_INSTANCE_POINT_INSERT, Statement.RETURN_GENERATED_KEYS); new ArgumentPreparedStatementSetter(new Object[] { reportInstance.getId(), - point.getDeviceName(), - name, + pointInfo.getDeviceName(), + pointInfo.getName(), dataType, DataTypes.valueToString(startValue), - new SerializationData().writeObject(point.getTextRenderer()), + new SerializationData().writeObject(pointInfo.getTextRenderer()), pointInfo.getColour(), DAO.boolToChar(pointInfo.isConsolidatedChart()) }).setValues(preparedStatement); diff --git a/src/org/scada_lts/mango/service/ReportService.java b/src/org/scada_lts/mango/service/ReportService.java index d6f2a4f521..076ab695a1 100644 --- a/src/org/scada_lts/mango/service/ReportService.java +++ b/src/org/scada_lts/mango/service/ReportService.java @@ -27,14 +27,13 @@ import com.serotonin.mango.vo.User; import com.serotonin.mango.vo.UserComment; import com.serotonin.mango.vo.report.*; -import com.serotonin.util.StringUtils; import com.serotonin.web.i18n.I18NUtils; -import com.serotonin.web.taglib.Functions; import org.scada_lts.dao.DAO; import org.scada_lts.dao.report.*; import org.scada_lts.mango.adapter.MangoReport; import org.scada_lts.permissions.service.GetReportInstancesWithAccess; import org.scada_lts.permissions.service.GetReportsWithAccess; +import org.scada_lts.serorepl.utils.StringUtils; import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.stereotype.Service; @@ -222,7 +221,7 @@ else if (instance.isToNow()) { MangoValue startValue = null; if (!instance.isFromInception()) { // Get the value just before the start of the report - PointValueTime pvt = pointValueService.getPointValueBefore(point.getId(), instance.getReportStartTime()); + PointValueTime pvt = pointValueService.getPointValueBefore(pointInfo.getId(), instance.getReportStartTime()); if (pvt != null) startValue = pvt.getValue(); @@ -233,10 +232,8 @@ else if (instance.isToNow()) { // Insert the reportInstancePoints record //TODO SeroUtils - String name = Functions.truncate(point.getName(), 100); - - int reportPointId = reportInstancePointDAO.insert(instance, point, name, dataType, startValue, pointInfo); - count += reportInstanceDataDAO.insert(appendParameters(timestampParams, point.getId(), dataType), reportPointId, StringUtils.replaceMacro(timestampSql, "field", "ts")); + int reportPointId = reportInstancePointDAO.insert(instance, dataType, startValue, pointInfo); + count += reportInstanceDataDAO.insert(appendParameters(timestampParams, pointInfo.getId(), dataType), reportPointId, StringUtils.replaceMacro(timestampSql, "field", "ts")); String annotationCase = " case pva.sourceType" // + " when 1 then concat('" + userLabel + ": ',ifnull(u.username,'" + deletedLabel + "')) " // @@ -269,7 +266,7 @@ else if (instance.isToNow()) { } eventSQL += StringUtils.replaceMacro(timestampSql, "field", "e.activeTs"); - DAO.getInstance().getJdbcTemp().update(eventSQL, appendParameters(timestampParams, instance.getUserId(), point.getId())); + DAO.getInstance().getJdbcTemp().update(eventSQL, appendParameters(timestampParams, instance.getUserId(), pointInfo.getId())); } // Insert the reportInstanceUserComments records for the point. @@ -285,7 +282,7 @@ else if (instance.isToNow()) { // Only include comments made in the duration of the report. commentSQL += StringUtils.replaceMacro(timestampSql, "field", "uc.ts"); - DAO.getInstance().getJdbcTemp().update(commentSQL, appendParameters(timestampParams, point.getId())); + DAO.getInstance().getJdbcTemp().update(commentSQL, appendParameters(timestampParams, pointInfo.getId())); } } diff --git a/src/org/scada_lts/serorepl/utils/StringUtils.java b/src/org/scada_lts/serorepl/utils/StringUtils.java index b8c9220cf1..5212ddea3f 100644 --- a/src/org/scada_lts/serorepl/utils/StringUtils.java +++ b/src/org/scada_lts/serorepl/utils/StringUtils.java @@ -1,5 +1,6 @@ package org.scada_lts.serorepl.utils; +import br.org.scadabr.api.da.WriteDataOptions; import org.apache.commons.lang3.ObjectUtils; import java.util.Properties; @@ -132,11 +133,11 @@ public static String replaceMacros(String s, Properties properties){ public static String trimWhitespace(String s){ return s.trim(); } - + @Deprecated public static String truncate(String s, int length){ return truncate(s, length, (String)null); } - + @Deprecated public static String truncate(String s, int length, String truncateSuffix){ if (s == null) { return null; @@ -149,4 +150,15 @@ public static String truncate(String s, int length, String truncateSuffix){ } return s.substring(0,length); } + public static String abbreviateMiddle(String s, int length) { + return abbreviateMiddle(s, length, (String)null); + } + + public static String abbreviateMiddle(String s, int length, String truncateSuffix) { + if(truncateSuffix == null) { + truncateSuffix = "..."; + } + return org.apache.commons.lang3.StringUtils.abbreviateMiddle(s, truncateSuffix, length); + } + } diff --git a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java new file mode 100644 index 0000000000..67be36c473 --- /dev/null +++ b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java @@ -0,0 +1,58 @@ +package com.serotonin.mango.vo.report; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +@RunWith(Parameterized.class) +public class CalculateConsolidatedChartHeightExceptionTest { + + + private final List pointStatistics; + private final int imageHeightForDataPointNameInLegend; + private final int imageHeight; + private final int charAmountPerLine; + public CalculateConsolidatedChartHeightExceptionTest(List pointStatistics, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { + this.pointStatistics = pointStatistics; + this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; + this.imageHeight = imageHeight; + this.charAmountPerLine = charAmountPerLine; + } + + @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeightException(points: {0}, expected height: {1},pixels per line: {2} base height of chart: {3}, characters per line: {4})") + public static Collection data() { + String _4CharacterPointName = "4cha"; + String _8CharacterPointName = "8charact"; + String _25CharactersPointName = "25characters - 25characte"; + String _50CharactersPointName = "50characters - 50characters50characters50character"; + String _140CharactersPointName = "140characters - 140characters140characters140characters140characters140characters140characters140characters140characters140characters140char"; + return Arrays.asList(new Object[][]{ + {createPointStatisticsList(List.of(_4CharacterPointName)), 20, 400, 3}, + {createPointStatisticsList(List.of(_8CharacterPointName)), 20, 400, 7}, + {createPointStatisticsList(List.of(_25CharactersPointName)), 20, 400, 20}, + {createPointStatisticsList(List.of(_50CharactersPointName)), 20, 400, 40}, + {createPointStatisticsList(List.of(_140CharactersPointName)), 20, 400, 138}, + }); + } + + private static List createPointStatisticsList(List pointName) { + List pointStatisticsList = new ArrayList<>(); + for (String pName : pointName) { + ReportChartCreator.PointStatistics pointStatistics = new ReportChartCreator.PointStatistics(1, ""); + pointStatistics.setName(pName); + pointStatisticsList.add(pointStatistics); + } + return pointStatisticsList; + } + + @Test(expected = IllegalArgumentException.class) + public void when_calculateConsolidatedChartHeightExpectException() { + ImageChartUtils.calculateHeightConsolidatedChart(pointStatistics, imageHeight, imageHeightForDataPointNameInLegend, charAmountPerLine); + } + +} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java new file mode 100644 index 0000000000..a4779620ae --- /dev/null +++ b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java @@ -0,0 +1,269 @@ +package com.serotonin.mango.vo.report; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class CalculateConsolidatedChartHeightTest { + + private final List pointStatistics; + private final int expectedHeight; + private final int imageHeightForDataPointNameInLegend; + private final int imageHeight; + private final int charAmountPerLine; + public CalculateConsolidatedChartHeightTest(List pointStatistics, int expectedHeight, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { + this.pointStatistics = pointStatistics; + this.expectedHeight = expectedHeight; + this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; + this.imageHeight = imageHeight; + this.charAmountPerLine = charAmountPerLine; + } + + @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, expected height: {1},pixels per line: {2} base height of chart: {3}, characters per line: {4})") + public static Collection data() { + String chars0PointName = ""; + String chars1PointName = "1"; + String chars2PointName = "2c"; + String chars3PointName = "3ch"; + String chars4PointName = "4cha"; + String chars5PointName = "5char"; + String chars6PointName = "6chara"; + String chars7PointName = "7charac"; + String chars8PointName = "8charact"; + String chars9PointName = "9characte"; + String chars10PointName = "ds_1 - 10c"; + String chars15PointName = "ds_1 - 15charac"; + String chars20PointName = "ds_1 - 20characters2"; + String chars25PointName = "ds_1 - 25characters25char"; + String chars30PointName = "ds_1 - 30characters30character"; + String chars50PointName = "ds_1 - 50characters50characters50characters50chara"; + String chars60PointName = "ds_1 - 60characters60characters60characters60characters60cha"; + String chars70PointName = "ds_1 - 70characters70characters70characters70characters70characters70c"; + String chars80PointName = "ds_1 - 80characters80characters80characters80characters80characters80characters8"; + String chars90PointName = "ds_1 - 90characters90characters90characters90characters90characters90characters90character"; + String chars100PointName = "ds_1 - 100characters100characters100characters100characters100characters100characters100characters10"; + String chars135PointName = "135characters - 135characters135characters135characters135characters135characters135characters135characters135characters135characters13"; + String chars138PointName = "138characters - 138characters138characters138characters138characters138characters138characters138characters138characters138characters138ch"; + + return Arrays.asList(new Object[][]{ + {List.of(), 400, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList( + chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName + )), 420, 20, 400, 15}, + {createPointStatisticsList(List.of(chars135PointName)), 400, 20, 400, 138}, + {createPointStatisticsList(List.of(chars138PointName)), 400, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList(chars138PointName, chars138PointName, chars138PointName)), 440, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList(chars135PointName, chars135PointName, chars135PointName)), 440, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList( + chars4PointName, chars2PointName, chars1PointName, chars3PointName, chars4PointName + )), 420, 20, 400, 16}, + {createPointStatisticsList(Arrays.asList( + chars4PointName, chars2PointName, chars3PointName, chars1PointName, chars4PointName + )), 440, 20, 400, 16}, + {createPointStatisticsList(Arrays.asList( + chars5PointName, chars6PointName, chars7PointName, chars8PointName, chars9PointName + )), 460, 20, 400, 18}, + {createPointStatisticsList(Arrays.asList( + chars5PointName, chars8PointName, chars6PointName, chars9PointName, chars7PointName + )), 480, 20, 400, 18}, + {createPointStatisticsList(Arrays.asList( + chars10PointName, chars15PointName, chars20PointName, chars30PointName, chars25PointName + )), 460, 20, 400, 35}, + {createPointStatisticsList(Arrays.asList( + chars10PointName, chars20PointName, chars15PointName, chars25PointName, chars30PointName + )), 480, 20, 400, 35}, + + + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars50PointName, + chars100PointName + )), 440, 20, 400, 149}, + {createPointStatisticsList(Arrays.asList( + chars50PointName, + chars100PointName, + chars80PointName, + chars90PointName, + chars60PointName, + chars50PointName + )), 480, 20, 400, 149}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars10PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars90PointName + )), 460, 20, 400, 149}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars10PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars90PointName, + chars70PointName, + chars30PointName, + chars20PointName, + chars90PointName, + chars100PointName + )),520,20,400,138}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars10PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars90PointName, + chars70PointName, + chars30PointName, + chars20PointName, + chars90PointName, + chars100PointName, + chars30PointName, + chars20PointName, + chars100PointName, + chars50PointName, + chars10PointName, + chars90PointName + )),580,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars90PointName, + chars70PointName, + chars30PointName, + chars90PointName, + chars100PointName, + chars100PointName, + chars50PointName, + chars90PointName, + chars20PointName, + chars80PointName, + chars80PointName, + chars10PointName + )),580,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars20PointName, + chars30PointName, + chars60PointName, + chars70PointName, + chars20PointName, + chars10PointName, + chars50PointName, + chars30PointName, + chars80PointName, + chars30PointName + )),480,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars50PointName, + chars30PointName, + chars60PointName, + chars70PointName, + chars10PointName, + chars30PointName, + chars30PointName, + chars100PointName, + chars20PointName, + chars70PointName, + chars90PointName, + chars100PointName, + chars20PointName, + chars50PointName, + chars20PointName, + chars10PointName + )),540,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars20PointName, + chars70PointName, + chars20PointName, + chars10PointName, + chars100PointName, + chars90PointName, + chars30PointName, + chars90PointName, + chars20PointName, + chars10PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars30PointName, + chars60PointName + )),520,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars20PointName, + chars70PointName, + chars20PointName, + chars10PointName, + chars100PointName, + chars90PointName, + chars30PointName, + chars90PointName, + chars20PointName, + chars10PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars30PointName, + chars60PointName, + chars100PointName, + chars80PointName, + chars90PointName, + chars100PointName, + chars80PointName, + chars30PointName, + chars80PointName, + chars50PointName, + chars70PointName, + chars50PointName, + chars60PointName, + chars60PointName + )),680,20,400,149}, + }); + } + + private static List createPointStatisticsList(List pointName) { + List pointStatisticsList = new ArrayList<>(); + for (String pName : pointName) { + ReportChartCreator.PointStatistics pointStatistics = new ReportChartCreator.PointStatistics(1, ""); + pointStatistics.setName(pName); + pointStatisticsList.add(pointStatistics); + } + return pointStatisticsList; + } + + @Test + public void when_calculateConsolidatedChartHeight() { + //when: + int actualHeight = ImageChartUtils.calculateHeightConsolidatedChart(pointStatistics, imageHeight, imageHeightForDataPointNameInLegend, charAmountPerLine); + //than: + assertEquals(expectedHeight, actualHeight); + } + +} \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java b/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java new file mode 100644 index 0000000000..8d64286970 --- /dev/null +++ b/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java @@ -0,0 +1,69 @@ +package org.scada_lts.serorepl.utils; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class ReplaceMacroStringUtilsWithProdParametersTest { + + private final static String timestampSql = "and ${field}>=? and ${field} Date: Wed, 7 Feb 2024 16:43:18 +0100 Subject: [PATCH 2/8] #2726 Legend occupies too much space in reports screen Changed length of displayed names to shorter in reports so graphs in statistics won't get stretched --- src/com/serotonin/mango/vo/report/ReportChartCreator.java | 8 ++++---- src/org/scada_lts/dao/report/ReportInstancePointDAO.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index 47a92e64ed..d1d5e641ae 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -60,8 +60,8 @@ public class ReportChartCreator { private static final int IMAGE_HEIGHT = 400; private static final int IMAGE_POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; private static final int CHARACTERS_PER_LINE_IN_CHART_LEGEND_NUMBER = 149; - private static final int DATA_SOURCE_NAME_LENGTH_FOR_CHART = 35; - private static final int DATA_POINT_NAME_LENGTH_FOR_CHART = 100; + private static final int DATA_SOURCE_NAME_LENGTH_FOR_CHART = 30; + private static final int DATA_SOURCE_AND_DATA_POINT_NAME_LENGTH_FOR_CHART = 65; public static final String IMAGE_CONTENT_ID = "reportChart.png"; public static final int POINT_IMAGE_WIDTH = 440; @@ -87,8 +87,8 @@ public static int getDataSourceNameLengthForReport() { return DATA_SOURCE_NAME_LENGTH_FOR_CHART; } - public static int getDataPointNameLengthForReport() { - return DATA_POINT_NAME_LENGTH_FOR_CHART; + public static int getDataSourceAndDataPointNameLengthForReport() { + return DATA_SOURCE_AND_DATA_POINT_NAME_LENGTH_FOR_CHART; } /** diff --git a/src/org/scada_lts/dao/report/ReportInstancePointDAO.java b/src/org/scada_lts/dao/report/ReportInstancePointDAO.java index 31dd6e9adc..01b4a98ace 100644 --- a/src/org/scada_lts/dao/report/ReportInstancePointDAO.java +++ b/src/org/scada_lts/dao/report/ReportInstancePointDAO.java @@ -126,7 +126,7 @@ public String getColour() { } public String getName() { - return StringUtils.abbreviateMiddle(point.getName(), ReportChartCreator.getDataPointNameLengthForReport()); + return StringUtils.abbreviateMiddle(point.getName(), ReportChartCreator.getDataSourceAndDataPointNameLengthForReport()-getDeviceName().length()); } public String getDeviceName() { From 12ab7eefeb4848fc2e48888c0d2640dd284856ae Mon Sep 17 00:00:00 2001 From: patrykb0802 Date: Mon, 12 Feb 2024 11:38:32 +0100 Subject: [PATCH 3/8] #2726 Legend occupies too much space in reports screen Added: - calculatePointNameForReport method for for each point graph names to make them parse correctly - Truncate parameterized Junit tests - Suites to group up tests for StringUtils and ImageChartUtils Changed: - Length of point and data source name so they are truncated to length that database accept - Way of truncating names, now "..." are added at the end of extended name --- build.gradle | 4 +- .../mango/vo/report/ReportChartCreator.java | 25 +- .../dao/report/ReportInstancePointDAO.java | 5 +- .../mango/service/ReportService.java | 3 + .../scada_lts/serorepl/utils/StringUtils.java | 25 +- ...eConsolidatedChartHeightExceptionTest.java | 23 +- .../CalculateConsolidatedChartHeightTest.java | 396 +++++++++--------- .../vo/report/ImageChartUtilsTestsSuite.java | 13 + .../serorepl/utils/StringUtilsTestsSuite.java | 14 + .../TruncateStringUtilsExceptionTest.java | 44 ++ .../utils/TruncateStringUtilsTest.java | 50 +++ 11 files changed, 367 insertions(+), 235 deletions(-) create mode 100644 test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java create mode 100644 test/org/scada_lts/serorepl/utils/StringUtilsTestsSuite.java create mode 100644 test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java create mode 100644 test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java diff --git a/build.gradle b/build.gradle index 02acf7a856..904486df8a 100644 --- a/build.gradle +++ b/build.gradle @@ -204,7 +204,7 @@ test { includeTestsMatching "com.serotonin.mango.rt.maint.work.CreateWorkItemToStringTest" includeTestsMatching "com.serotonin.util.SerializationHelperTest" includeTestsMatching "org.scada_lts.web.mvc.api.json.WorkItemInfoListTest" - includeTestsMatching "com.serotonin.mango.vo.report.CalculateConsolidatedChartHeightTest" - includeTestsMatching "com.serotonin.mango.vo.report.CalculateConsolidatedChartHeightTestException" + includeTestsMatching "com.serotonin.mango.vo.report.ImageChartUtilsTestSuite" + includeTestsMatching "org.scada_lts.serorepl.utils.StringUtilsTestsSuite" } } \ No newline at end of file diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index d1d5e641ae..5234fd88f7 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -37,6 +37,7 @@ import org.apache.commons.logging.LogFactory; import org.jfree.data.time.Second; import org.jfree.data.time.TimeSeries; +import org.scada_lts.serorepl.utils.StringUtils; import org.scada_lts.utils.ColorUtils; import com.serotonin.mango.util.DateUtils; @@ -60,8 +61,7 @@ public class ReportChartCreator { private static final int IMAGE_HEIGHT = 400; private static final int IMAGE_POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; private static final int CHARACTERS_PER_LINE_IN_CHART_LEGEND_NUMBER = 149; - private static final int DATA_SOURCE_NAME_LENGTH_FOR_CHART = 30; - private static final int DATA_SOURCE_AND_DATA_POINT_NAME_LENGTH_FOR_CHART = 65; + private static final int DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART = 65; public static final String IMAGE_CONTENT_ID = "reportChart.png"; public static final int POINT_IMAGE_WIDTH = 440; @@ -83,14 +83,6 @@ public ReportChartCreator(ResourceBundle bundle) { this.bundle = bundle; } - public static int getDataSourceNameLengthForReport() { - return DATA_SOURCE_NAME_LENGTH_FOR_CHART; - } - - public static int getDataSourceAndDataPointNameLengthForReport() { - return DATA_SOURCE_AND_DATA_POINT_NAME_LENGTH_FOR_CHART; - } - /** * Uses the given parameters to create the data for the fields of this class. Once the content has been created the * getters for the fields can be used to retrieve. @@ -271,6 +263,10 @@ public List getPointStatistics() { return pointStatistics; } + public static int getDataPointExtendedNameLengthForChart(){ + return DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART; + } + public static class PointStatistics { private final int reportPointId; private String name; @@ -495,7 +491,7 @@ public void startPoint(ReportPointInfo pointInfo) { donePoint(); point = new PointStatistics(pointInfo.getReportPointId(), inlinePrefix); - point.setName(pointInfo.getExtendedName()); + point.setName(calculatePointNameForReport(pointInfo.getExtendedName())); point.setDataType(pointInfo.getDataType()); point.setDataTypeDescription(DataTypes.getDataTypeMessage(pointInfo.getDataType()).getLocalizedMessage( bundle)); @@ -568,6 +564,13 @@ else if (pointInfo.getDataType() == DataTypes.IMAGE) { reportCsvStreamer.startPoint(pointInfo); } + private String calculatePointNameForReport(String extendedName) { + if(extendedName.length() > DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART) { + return StringUtils.truncate(extendedName, "...", DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART); + } + return extendedName; + } + public void pointData(ReportDataValue rdv) { if (quantizer != null) quantizer.data(rdv.getValue(), rdv.getTime()); diff --git a/src/org/scada_lts/dao/report/ReportInstancePointDAO.java b/src/org/scada_lts/dao/report/ReportInstancePointDAO.java index 01b4a98ace..412aed8517 100644 --- a/src/org/scada_lts/dao/report/ReportInstancePointDAO.java +++ b/src/org/scada_lts/dao/report/ReportInstancePointDAO.java @@ -22,7 +22,6 @@ import com.serotonin.mango.rt.dataImage.types.MangoValue; import com.serotonin.mango.view.text.TextRenderer; import com.serotonin.mango.vo.DataPointVO; -import com.serotonin.mango.vo.report.ReportChartCreator; import com.serotonin.mango.vo.report.ReportInstance; import com.serotonin.mango.vo.report.ReportPointInfo; import org.apache.commons.logging.Log; @@ -126,11 +125,11 @@ public String getColour() { } public String getName() { - return StringUtils.abbreviateMiddle(point.getName(), ReportChartCreator.getDataSourceAndDataPointNameLengthForReport()-getDeviceName().length()); + return StringUtils.truncate(point.getName(), "", 100); } public String getDeviceName() { - return StringUtils.abbreviateMiddle(point.getDeviceName(), ReportChartCreator.getDataSourceNameLengthForReport()); + return StringUtils.truncate(point.getDeviceName(), "", 40); } public TextRenderer getTextRenderer() { diff --git a/src/org/scada_lts/mango/service/ReportService.java b/src/org/scada_lts/mango/service/ReportService.java index 076ab695a1..cb68ab3b6b 100644 --- a/src/org/scada_lts/mango/service/ReportService.java +++ b/src/org/scada_lts/mango/service/ReportService.java @@ -73,6 +73,9 @@ public ReportService() { private void setReportDataValue(List pointInfos, final ReportDataStreamHandler handler) { final ReportDataValue rdv = new ReportDataValue(); for (final ReportPointInfo point: pointInfos) { + if (point.getExtendedName().length() > ReportChartCreator.getDataPointExtendedNameLengthForChart()) { + point.setPointName(StringUtils.truncate(point.getPointName(), "...", ReportChartCreator.getDataPointExtendedNameLengthForChart() - point.getDeviceName().length() - 3)); + } handler.startPoint(point); rdv.setReportPointId(point.getReportPointId()); reportInstanceDataDAO.setReportValue(point, rdv, handler); diff --git a/src/org/scada_lts/serorepl/utils/StringUtils.java b/src/org/scada_lts/serorepl/utils/StringUtils.java index 5212ddea3f..dab987bc2c 100644 --- a/src/org/scada_lts/serorepl/utils/StringUtils.java +++ b/src/org/scada_lts/serorepl/utils/StringUtils.java @@ -133,11 +133,11 @@ public static String replaceMacros(String s, Properties properties){ public static String trimWhitespace(String s){ return s.trim(); } - @Deprecated + @Deprecated(since = "2.7.7") public static String truncate(String s, int length){ return truncate(s, length, (String)null); } - @Deprecated + @Deprecated(since = "2.7.7") public static String truncate(String s, int length, String truncateSuffix){ if (s == null) { return null; @@ -150,15 +150,22 @@ public static String truncate(String s, int length, String truncateSuffix){ } return s.substring(0,length); } - public static String abbreviateMiddle(String s, int length) { - return abbreviateMiddle(s, length, (String)null); - } - public static String abbreviateMiddle(String s, int length, String truncateSuffix) { + public static String truncate(String s, String truncateSuffix, int length) { + if(truncateSuffix != null && truncateSuffix.length() >= length) + throw new IllegalArgumentException(""); + if (length < 4) + throw new IllegalArgumentException("Minimum abbreviation width is 4"); + String name; if(truncateSuffix == null) { - truncateSuffix = "..."; + name = org.apache.commons.lang3.StringUtils.abbreviate(s, length); + return name; + } else { + int fixedLength = length - truncateSuffix.length(); + name = org.apache.commons.lang3.StringUtils.abbreviate(s, fixedLength + 3); + if(name.length() > fixedLength) + name = name.substring(0, fixedLength); + return name + truncateSuffix; } - return org.apache.commons.lang3.StringUtils.abbreviateMiddle(s, truncateSuffix, length); } - } diff --git a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java index 67be36c473..ee79ee4cc4 100644 --- a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java @@ -12,18 +12,6 @@ @RunWith(Parameterized.class) public class CalculateConsolidatedChartHeightExceptionTest { - - private final List pointStatistics; - private final int imageHeightForDataPointNameInLegend; - private final int imageHeight; - private final int charAmountPerLine; - public CalculateConsolidatedChartHeightExceptionTest(List pointStatistics, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { - this.pointStatistics = pointStatistics; - this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; - this.imageHeight = imageHeight; - this.charAmountPerLine = charAmountPerLine; - } - @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeightException(points: {0}, expected height: {1},pixels per line: {2} base height of chart: {3}, characters per line: {4})") public static Collection data() { String _4CharacterPointName = "4cha"; @@ -40,6 +28,17 @@ public static Collection data() { }); } + private final List pointStatistics; + private final int imageHeightForDataPointNameInLegend; + private final int imageHeight; + private final int charAmountPerLine; + public CalculateConsolidatedChartHeightExceptionTest(List pointStatistics, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { + this.pointStatistics = pointStatistics; + this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; + this.imageHeight = imageHeight; + this.charAmountPerLine = charAmountPerLine; + } + private static List createPointStatisticsList(List pointName) { List pointStatisticsList = new ArrayList<>(); for (String pName : pointName) { diff --git a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java index a4779620ae..093aab3f48 100644 --- a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java @@ -15,19 +15,6 @@ @RunWith(Parameterized.class) public class CalculateConsolidatedChartHeightTest { - private final List pointStatistics; - private final int expectedHeight; - private final int imageHeightForDataPointNameInLegend; - private final int imageHeight; - private final int charAmountPerLine; - public CalculateConsolidatedChartHeightTest(List pointStatistics, int expectedHeight, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { - this.pointStatistics = pointStatistics; - this.expectedHeight = expectedHeight; - this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; - this.imageHeight = imageHeight; - this.charAmountPerLine = charAmountPerLine; - } - @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, expected height: {1},pixels per line: {2} base height of chart: {3}, characters per line: {4})") public static Collection data() { String chars0PointName = ""; @@ -55,199 +42,212 @@ public static Collection data() { String chars138PointName = "138characters - 138characters138characters138characters138characters138characters138characters138characters138characters138characters138ch"; return Arrays.asList(new Object[][]{ - {List.of(), 400, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList( - chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName - )), 420, 20, 400, 15}, - {createPointStatisticsList(List.of(chars135PointName)), 400, 20, 400, 138}, - {createPointStatisticsList(List.of(chars138PointName)), 400, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList(chars138PointName, chars138PointName, chars138PointName)), 440, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList(chars135PointName, chars135PointName, chars135PointName)), 440, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList( - chars4PointName, chars2PointName, chars1PointName, chars3PointName, chars4PointName - )), 420, 20, 400, 16}, - {createPointStatisticsList(Arrays.asList( - chars4PointName, chars2PointName, chars3PointName, chars1PointName, chars4PointName - )), 440, 20, 400, 16}, - {createPointStatisticsList(Arrays.asList( - chars5PointName, chars6PointName, chars7PointName, chars8PointName, chars9PointName - )), 460, 20, 400, 18}, - {createPointStatisticsList(Arrays.asList( - chars5PointName, chars8PointName, chars6PointName, chars9PointName, chars7PointName - )), 480, 20, 400, 18}, - {createPointStatisticsList(Arrays.asList( - chars10PointName, chars15PointName, chars20PointName, chars30PointName, chars25PointName - )), 460, 20, 400, 35}, - {createPointStatisticsList(Arrays.asList( - chars10PointName, chars20PointName, chars15PointName, chars25PointName, chars30PointName - )), 480, 20, 400, 35}, + {List.of(), 400, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList( + chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName + )), 420, 20, 400, 15}, + {createPointStatisticsList(List.of(chars135PointName)), 400, 20, 400, 138}, + {createPointStatisticsList(List.of(chars138PointName)), 400, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList(chars138PointName, chars138PointName, chars138PointName)), 440, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList(chars135PointName, chars135PointName, chars135PointName)), 440, 20, 400, 138}, + {createPointStatisticsList(Arrays.asList( + chars4PointName, chars2PointName, chars1PointName, chars3PointName, chars4PointName + )), 420, 20, 400, 16}, + {createPointStatisticsList(Arrays.asList( + chars4PointName, chars2PointName, chars3PointName, chars1PointName, chars4PointName + )), 440, 20, 400, 16}, + {createPointStatisticsList(Arrays.asList( + chars5PointName, chars6PointName, chars7PointName, chars8PointName, chars9PointName + )), 460, 20, 400, 18}, + {createPointStatisticsList(Arrays.asList( + chars5PointName, chars8PointName, chars6PointName, chars9PointName, chars7PointName + )), 480, 20, 400, 18}, + {createPointStatisticsList(Arrays.asList( + chars10PointName, chars15PointName, chars20PointName, chars30PointName, chars25PointName + )), 460, 20, 400, 35}, + {createPointStatisticsList(Arrays.asList( + chars10PointName, chars20PointName, chars15PointName, chars25PointName, chars30PointName + )), 480, 20, 400, 35}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars50PointName, - chars100PointName + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars50PointName, + chars100PointName )), 440, 20, 400, 149}, - {createPointStatisticsList(Arrays.asList( - chars50PointName, - chars100PointName, - chars80PointName, - chars90PointName, - chars60PointName, - chars50PointName + {createPointStatisticsList(Arrays.asList( + chars50PointName, + chars100PointName, + chars80PointName, + chars90PointName, + chars60PointName, + chars50PointName )), 480, 20, 400, 149}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars10PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars90PointName + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars10PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars90PointName )), 460, 20, 400, 149}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars10PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars90PointName, - chars70PointName, - chars30PointName, - chars20PointName, - chars90PointName, - chars100PointName - )),520,20,400,138}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars10PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars90PointName, - chars70PointName, - chars30PointName, - chars20PointName, - chars90PointName, - chars100PointName, - chars30PointName, - chars20PointName, - chars100PointName, - chars50PointName, - chars10PointName, - chars90PointName - )),580,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars90PointName, - chars70PointName, - chars30PointName, - chars90PointName, - chars100PointName, - chars100PointName, - chars50PointName, - chars90PointName, - chars20PointName, - chars80PointName, - chars80PointName, - chars10PointName - )),580,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars20PointName, - chars30PointName, - chars60PointName, - chars70PointName, - chars20PointName, - chars10PointName, - chars50PointName, - chars30PointName, - chars80PointName, - chars30PointName - )),480,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars50PointName, - chars30PointName, - chars60PointName, - chars70PointName, - chars10PointName, - chars30PointName, - chars30PointName, - chars100PointName, - chars20PointName, - chars70PointName, - chars90PointName, - chars100PointName, - chars20PointName, - chars50PointName, - chars20PointName, - chars10PointName - )),540,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars20PointName, - chars70PointName, - chars20PointName, - chars10PointName, - chars100PointName, - chars90PointName, - chars30PointName, - chars90PointName, - chars20PointName, - chars10PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars30PointName, - chars60PointName - )),520,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars20PointName, - chars70PointName, - chars20PointName, - chars10PointName, - chars100PointName, - chars90PointName, - chars30PointName, - chars90PointName, - chars20PointName, - chars10PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars30PointName, - chars60PointName, - chars100PointName, - chars80PointName, - chars90PointName, - chars100PointName, - chars80PointName, - chars30PointName, - chars80PointName, - chars50PointName, - chars70PointName, - chars50PointName, - chars60PointName, - chars60PointName - )),680,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars10PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars90PointName, + chars70PointName, + chars30PointName, + chars20PointName, + chars90PointName, + chars100PointName + )),520,20,400,138}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars10PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars90PointName, + chars70PointName, + chars30PointName, + chars20PointName, + chars90PointName, + chars100PointName, + chars30PointName, + chars20PointName, + chars100PointName, + chars50PointName, + chars10PointName, + chars90PointName + )),580,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars100PointName, + chars80PointName, + chars90PointName, + chars70PointName, + chars30PointName, + chars90PointName, + chars100PointName, + chars100PointName, + chars50PointName, + chars90PointName, + chars20PointName, + chars80PointName, + chars80PointName, + chars10PointName + )),580,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars20PointName, + chars30PointName, + chars60PointName, + chars70PointName, + chars20PointName, + chars10PointName, + chars50PointName, + chars30PointName, + chars80PointName, + chars30PointName + )),480,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars50PointName, + chars30PointName, + chars60PointName, + chars70PointName, + chars10PointName, + chars30PointName, + chars30PointName, + chars100PointName, + chars20PointName, + chars70PointName, + chars90PointName, + chars100PointName, + chars20PointName, + chars50PointName, + chars20PointName, + chars10PointName + )),540,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars20PointName, + chars70PointName, + chars20PointName, + chars10PointName, + chars100PointName, + chars90PointName, + chars30PointName, + chars90PointName, + chars20PointName, + chars10PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars30PointName, + chars60PointName + )),520,20,400,149}, + {createPointStatisticsList(Arrays.asList( + chars70PointName, + chars30PointName, + chars20PointName, + chars70PointName, + chars20PointName, + chars10PointName, + chars100PointName, + chars90PointName, + chars30PointName, + chars90PointName, + chars20PointName, + chars10PointName, + chars50PointName, + chars20PointName, + chars10PointName, + chars30PointName, + chars60PointName, + chars100PointName, + chars80PointName, + chars90PointName, + chars100PointName, + chars80PointName, + chars30PointName, + chars80PointName, + chars50PointName, + chars70PointName, + chars50PointName, + chars60PointName, + chars60PointName + )),680,20,400,149}, }); } + private final List pointStatistics; + private final int expectedHeight; + private final int imageHeightForDataPointNameInLegend; + private final int imageHeight; + private final int charAmountPerLine; + public CalculateConsolidatedChartHeightTest(List pointStatistics, int expectedHeight, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { + this.pointStatistics = pointStatistics; + this.expectedHeight = expectedHeight; + this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; + this.imageHeight = imageHeight; + this.charAmountPerLine = charAmountPerLine; + } + private static List createPointStatisticsList(List pointName) { List pointStatisticsList = new ArrayList<>(); for (String pName : pointName) { diff --git a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java new file mode 100644 index 0000000000..24c64720b9 --- /dev/null +++ b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java @@ -0,0 +1,13 @@ +package com.serotonin.mango.vo.report; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CalculateConsolidatedChartHeightExceptionTest.class, + CalculateConsolidatedChartHeightTest.class, +}) + +public class ImageChartUtilsTestsSuite { } \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/StringUtilsTestsSuite.java b/test/org/scada_lts/serorepl/utils/StringUtilsTestsSuite.java new file mode 100644 index 0000000000..f11984f0ce --- /dev/null +++ b/test/org/scada_lts/serorepl/utils/StringUtilsTestsSuite.java @@ -0,0 +1,14 @@ +package org.scada_lts.serorepl.utils; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + + + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + TruncateStringUtilsTest.class, + TruncateStringUtilsExceptionTest.class, +}) + +public class StringUtilsTestsSuite { } \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java new file mode 100644 index 0000000000..aa1c1706d2 --- /dev/null +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java @@ -0,0 +1,44 @@ +package org.scada_lts.serorepl.utils; + +import com.serotonin.mango.vo.report.ReportChartCreator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +public class TruncateStringUtilsExceptionTest { + + @Parameterized.Parameters(name = "{index}: truncate(word: {0}, truncateSuffix: {1}, length: {2})") + public static Collection data() { + return Arrays.asList(new Object[][]{ + {"ds - datap", "longsuffix", 6}, + {"ds - dp", "suffix", 6}, + {"2c", ".", 1}, + {"ds - datapointnameplaceholder1", "longsuffix", 9}, + {"ds-dp", ".", 3}, + {"ds-dp", null, 3} + }); + } + + private final String word; + private final String truncateSuffix; + private final int length; + + public TruncateStringUtilsExceptionTest(String word, String truncateSuffix, int length) { + this.word = word; + this.truncateSuffix = truncateSuffix; + this.length = length; + } + + + @Test(expected = IllegalArgumentException.class) + public void when_truncateExpectException() { + StringUtils.truncate(word, truncateSuffix, length); + } +} \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java new file mode 100644 index 0000000000..efa08d10e3 --- /dev/null +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java @@ -0,0 +1,50 @@ +package org.scada_lts.serorepl.utils; + +import com.serotonin.mango.vo.report.ReportChartCreator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +public class TruncateStringUtilsTest { + + @Parameterized.Parameters(name = "{index}: truncate(word: {0}, truncateSuffix: {1}, length: {2}, expectedWord: {3})") + public static Collection data() { + return Arrays.asList(new Object[][]{ + {"ds - datapointnameDP", "...", 10, "ds - da..."}, + {"ds - datapointnameDP", "", 10, "ds - datap"}, + {"ds - datapointnameDP", null, 10, "ds - da..."}, + {"ds - datap", "12345", 7, "ds12345"}, + {"ds - data", " - datapoint", 14, "ds - datapoint"}, + {"ds - wrongname ", " - datapoint", 14, "ds - datapoint"} + }); + } + + private final String word; + private final String truncateSuffix; + private final int length; + private final String expectedWord; + + public TruncateStringUtilsTest(String word, String truncateSuffix, int length, String expectedWord) { + this.word = word; + this.truncateSuffix = truncateSuffix; + this.length = length; + this.expectedWord = expectedWord; + } + + + @Test + public void truncate() { + //when: + String actualWord = StringUtils.truncate(word, truncateSuffix, length); + + //than: + assertEquals(expectedWord, actualWord); + } +} \ No newline at end of file From feec7bebb6c97f5e4d21643fd03dacad630e3708 Mon Sep 17 00:00:00 2001 From: Patrykb0802 Date: Tue, 13 Feb 2024 15:53:41 +0100 Subject: [PATCH 4/8] #2726 Legend occupies too much space in reports screen - Moved calculatePointNameForReport method to ImageChartUtils.java - Added getExtendedNameForReport() in ReportPointInfo.java - Changed getExtendedName() method to getExtendedNameForReport() so graphs will have correct name length --- .../mango/vo/report/ImageChartUtils.java | 8 ++++++++ .../mango/vo/report/ReportChartCreator.java | 15 ++++----------- .../mango/vo/report/ReportPointInfo.java | 4 +++- .../scada_lts/mango/service/ReportService.java | 3 --- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/com/serotonin/mango/vo/report/ImageChartUtils.java b/src/com/serotonin/mango/vo/report/ImageChartUtils.java index 4d3e2c1b34..ef059312d9 100644 --- a/src/com/serotonin/mango/vo/report/ImageChartUtils.java +++ b/src/com/serotonin/mango/vo/report/ImageChartUtils.java @@ -237,4 +237,12 @@ else if ((subLegend.length() + point.getName().length()) > charNumberPerLine){ } return (imageHeight - imageHeightForDataPointNameInLegend + (linesAmount*imageHeightForDataPointNameInLegend)); } + + public static String calculatePointNameForReport(String extendedName) { + if(extendedName.length() > ReportChartCreator.getDataPointExtendedNameLengthForChart()) { + return org.scada_lts.serorepl.utils.StringUtils.truncate(extendedName, "...", ReportChartCreator.getDataPointExtendedNameLengthForChart()); + } + return extendedName; + } + } diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index 5234fd88f7..8b41184edb 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -491,7 +491,7 @@ public void startPoint(ReportPointInfo pointInfo) { donePoint(); point = new PointStatistics(pointInfo.getReportPointId(), inlinePrefix); - point.setName(calculatePointNameForReport(pointInfo.getExtendedName())); + point.setName(pointInfo.getExtendedNameForReport()); point.setDataType(pointInfo.getDataType()); point.setDataTypeDescription(DataTypes.getDataTypeMessage(pointInfo.getDataType()).getLocalizedMessage( bundle)); @@ -516,7 +516,7 @@ public void startPoint(ReportPointInfo pointInfo) { quantizer = new NumericDataQuantizer(start, end, imageWidth, this); discreteTimeSeries = null; - numericTimeSeries = new TimeSeries(pointInfo.getExtendedName(), null, null, Second.class); + numericTimeSeries = new TimeSeries(pointInfo.getExtendedNameForReport(), null, null, Second.class); numericTimeSeries.setRangeDescription(point.getTextRenderer().getMetaText()); point.setNumericTimeSeries(numericTimeSeries); point.setNumericTimeSeriesColor(colour); @@ -527,7 +527,7 @@ else if (pointInfo.getDataType() == DataTypes.MULTISTATE) { point.setStats(new StartsAndRuntimeList(pointInfo.getStartValue(), start, end)); quantizer = new MultistateDataQuantizer(start, end, imageWidth, this); - discreteTimeSeries = new DiscreteTimeSeries(pointInfo.getExtendedName(), pointInfo.getTextRenderer(), + discreteTimeSeries = new DiscreteTimeSeries(pointInfo.getExtendedNameForReport(), pointInfo.getTextRenderer(), colour); point.setDiscreteTimeSeries(discreteTimeSeries); if (pointInfo.isConsolidatedChart()) @@ -538,7 +538,7 @@ else if (pointInfo.getDataType() == DataTypes.BINARY) { point.setStats(new StartsAndRuntimeList(pointInfo.getStartValue(), start, end)); quantizer = new BinaryDataQuantizer(start, end, imageWidth, this); - discreteTimeSeries = new DiscreteTimeSeries(pointInfo.getExtendedName(), pointInfo.getTextRenderer(), + discreteTimeSeries = new DiscreteTimeSeries(pointInfo.getExtendedNameForReport(), pointInfo.getTextRenderer(), colour); point.setDiscreteTimeSeries(discreteTimeSeries); if (pointInfo.isConsolidatedChart()) @@ -564,13 +564,6 @@ else if (pointInfo.getDataType() == DataTypes.IMAGE) { reportCsvStreamer.startPoint(pointInfo); } - private String calculatePointNameForReport(String extendedName) { - if(extendedName.length() > DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART) { - return StringUtils.truncate(extendedName, "...", DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART); - } - return extendedName; - } - public void pointData(ReportDataValue rdv) { if (quantizer != null) quantizer.data(rdv.getValue(), rdv.getTime()); diff --git a/src/com/serotonin/mango/vo/report/ReportPointInfo.java b/src/com/serotonin/mango/vo/report/ReportPointInfo.java index 8030b97c63..d6b93fe838 100644 --- a/src/com/serotonin/mango/vo/report/ReportPointInfo.java +++ b/src/com/serotonin/mango/vo/report/ReportPointInfo.java @@ -37,7 +37,9 @@ public class ReportPointInfo { public String getExtendedName() { return deviceName + " - " + pointName; } - + public String getExtendedNameForReport() { + return ImageChartUtils.calculatePointNameForReport(getExtendedName()); + } public int getReportPointId() { return reportPointId; } diff --git a/src/org/scada_lts/mango/service/ReportService.java b/src/org/scada_lts/mango/service/ReportService.java index cb68ab3b6b..076ab695a1 100644 --- a/src/org/scada_lts/mango/service/ReportService.java +++ b/src/org/scada_lts/mango/service/ReportService.java @@ -73,9 +73,6 @@ public ReportService() { private void setReportDataValue(List pointInfos, final ReportDataStreamHandler handler) { final ReportDataValue rdv = new ReportDataValue(); for (final ReportPointInfo point: pointInfos) { - if (point.getExtendedName().length() > ReportChartCreator.getDataPointExtendedNameLengthForChart()) { - point.setPointName(StringUtils.truncate(point.getPointName(), "...", ReportChartCreator.getDataPointExtendedNameLengthForChart() - point.getDeviceName().length() - 3)); - } handler.startPoint(point); rdv.setReportPointId(point.getReportPointId()); reportInstanceDataDAO.setReportValue(point, rdv, handler); From 1af8215420195eac098285cd2bb48b3fe07636f0 Mon Sep 17 00:00:00 2001 From: Kamil Jarmusik Date: Fri, 16 Feb 2024 19:45:24 +0100 Subject: [PATCH 5/8] #2726 Legend occupies too much space in reports screen: - corrected includeTestsMatching from ImageChartUtilsTestSuite to ImageChartUtilsTestsSuite (build.gradle) - corrected tests, added cases, and renamed: CalculateLinesImageChartUtilsTest, CalculateLinesImageChartUtilsExceptionTest, and corrected tests, added cases for: TruncateStringUtilsExceptionTest, TruncateStringUtilsTest and renamed test: ReplaceMacroStringUtilsTest; - refactoring, corrected method ImageChartUtils.calculateHeightConsolidatedChart, renamed on calculateHeightChart, removed throws IllegalArgumentException, extracted method calculateLinesNumber for calculate only lines number, corrected algorithm; - corrected state: LINE_LENGTH_IN_LEGEND_LIMIT=156, and DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT=54; - renamed state: IMAGE_WIDTH_PIXELS, IMAGE_HEIGHT_PIXELS, POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS, LINE_LENGTH_IN_LEGEND_LIMIT, DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT, POINT_IMAGE_WIDTH_PIXELS, POINT_IMAGE_HEIGHT_PIXELS; - corrected method ReportChartCreator.createContent; - not use deprecated method reportInstancePointDAO.insert; - corrected method StringUtils.truncate; --- build.gradle | 2 +- .../mango/vo/report/ImageChartUtils.java | 65 +++-- .../mango/vo/report/ReportChartCreator.java | 32 +-- .../scada_lts/serorepl/utils/StringUtils.java | 31 +- test/br/org/scadabr/db/utils/TestUtils.java | 42 ++- ...eConsolidatedChartHeightExceptionTest.java | 57 ---- .../CalculateConsolidatedChartHeightTest.java | 269 ------------------ ...lateLinesImageChartUtilsExceptionTest.java | 46 +++ .../CalculateLinesImageChartUtilsTest.java | 156 ++++++++++ .../vo/report/ImageChartUtilsTestsSuite.java | 4 +- .../scada_lts/dao/ReportInstanceDaoTest.java | 6 +- ....java => ReplaceMacroStringUtilsTest.java} | 2 +- .../TruncateStringUtilsExceptionTest.java | 70 +++-- .../utils/TruncateStringUtilsTest.java | 111 +++++++- 14 files changed, 471 insertions(+), 422 deletions(-) delete mode 100644 test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java delete mode 100644 test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java create mode 100644 test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java create mode 100644 test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java rename test/org/scada_lts/serorepl/utils/{ReplaceMacroStringUtilsWithProdParametersTest.java => ReplaceMacroStringUtilsTest.java} (97%) diff --git a/build.gradle b/build.gradle index 904486df8a..213ed68cde 100644 --- a/build.gradle +++ b/build.gradle @@ -204,7 +204,7 @@ test { includeTestsMatching "com.serotonin.mango.rt.maint.work.CreateWorkItemToStringTest" includeTestsMatching "com.serotonin.util.SerializationHelperTest" includeTestsMatching "org.scada_lts.web.mvc.api.json.WorkItemInfoListTest" - includeTestsMatching "com.serotonin.mango.vo.report.ImageChartUtilsTestSuite" + includeTestsMatching "com.serotonin.mango.vo.report.ImageChartUtilsTestsSuite" includeTestsMatching "org.scada_lts.serorepl.utils.StringUtilsTestsSuite" } } \ No newline at end of file diff --git a/src/com/serotonin/mango/vo/report/ImageChartUtils.java b/src/com/serotonin/mango/vo/report/ImageChartUtils.java index ef059312d9..6f5887c9ba 100644 --- a/src/com/serotonin/mango/vo/report/ImageChartUtils.java +++ b/src/com/serotonin/mango/vo/report/ImageChartUtils.java @@ -26,9 +26,12 @@ import java.io.OutputStream; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; @@ -49,10 +52,15 @@ import com.serotonin.mango.util.mindprod.StripEntities; import com.serotonin.util.StringUtils; +import static org.scada_lts.serorepl.utils.StringUtils.truncate; + /** * @author Matthew Lohbihler */ public class ImageChartUtils { + + private static final Log LOG = LogFactory.getLog(ImageChartUtils.class); + private static final int NUMERIC_DATA_INDEX = 0; private static final int DISCRETE_DATA_INDEX = 1; @@ -212,37 +220,46 @@ public static void addSecond(TimeSeries timeSeries, long time, Number value) { } } - public static int calculateHeightConsolidatedChart(List pointStatistics, int imageHeight, int imageHeightForDataPointNameInLegend, int charNumberPerLine) { - StringBuilder subLegend = new StringBuilder(); - int linesAmount = 0; - String charsForColorIndicator = "111"; - for (ReportChartCreator.PointStatistics point : pointStatistics){ - subLegend.append(charsForColorIndicator); - if (point.getName().length() > charNumberPerLine){ - throw new IllegalArgumentException("Point name is too long: " + point.getName()); - } + public static int calculateHeightChart(List pointStatistics, int imageHeightPixels, + int pointLabelHeightInLegendPixels, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { + int linesNumber = calculateLinesNumber(toListNames(pointStatistics), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); + return imageHeightPixels - pointLabelHeightInLegendPixels + (linesNumber * pointLabelHeightInLegendPixels) + 1; + } - else if ((subLegend.length() + point.getName().length()) > charNumberPerLine){ - subLegend.delete(0, subLegend.length()); - linesAmount++; - subLegend.append(charsForColorIndicator); - subLegend.append(point.getName()); - } - else { - subLegend.append(point.getName()); - } - } - if (pointStatistics.isEmpty() || pointStatistics.get(pointStatistics.size() - 1).getName().length() != charNumberPerLine) { - linesAmount++; + public static int calculateLinesNumber(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { + if(pointStatisticsNames.isEmpty() || (pointStatisticsNames.size() == 1 && pointStatisticsNames.get(0) == null)) { + return 1; } - return (imageHeight - imageHeightForDataPointNameInLegend + (linesAmount*imageHeightForDataPointNameInLegend)); + StringBuilder subLegend = new StringBuilder(); + int linesNumber = 1; + String split = " ** "; + for (int i = 0; i < pointStatisticsNames.size(); i++) { + String name = pointStatisticsNames.get(i); + if (name == null || name.isEmpty()) + continue; + name = truncate(split + truncate(name, "", dataPointExtendedNameLengthLimit), "", lineLengthInLegendLimit); + if ((subLegend.length() + name.length()) > lineLengthInLegendLimit) { + LOG.error(subLegend); + subLegend.delete(0, subLegend.length()); + linesNumber++; + } + subLegend.append(name); + if(i == pointStatisticsNames.size() - 1) { + LOG.error(subLegend); + subLegend.delete(0, subLegend.length()); + } + } + return linesNumber; } public static String calculatePointNameForReport(String extendedName) { - if(extendedName.length() > ReportChartCreator.getDataPointExtendedNameLengthForChart()) { - return org.scada_lts.serorepl.utils.StringUtils.truncate(extendedName, "...", ReportChartCreator.getDataPointExtendedNameLengthForChart()); + if(extendedName.length() > ReportChartCreator.getDataPointExtendedNameLengthLimit()) { + return truncate(extendedName, "...", ReportChartCreator.getDataPointExtendedNameLengthLimit()); } return extendedName; } + private static List toListNames(List pointStatistics) { + return pointStatistics.stream().map(ReportChartCreator.PointStatistics::getName).collect(Collectors.toList()); + } } diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index 8b41184edb..22ea5c0d07 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -37,7 +37,6 @@ import org.apache.commons.logging.LogFactory; import org.jfree.data.time.Second; import org.jfree.data.time.TimeSeries; -import org.scada_lts.serorepl.utils.StringUtils; import org.scada_lts.utils.ColorUtils; import com.serotonin.mango.util.DateUtils; @@ -57,15 +56,15 @@ public class ReportChartCreator { /** * This image width is specifically chosen such that the report will print on a single page width in landscape. */ - private static final int IMAGE_WIDTH = 930; - private static final int IMAGE_HEIGHT = 400; - private static final int IMAGE_POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; - private static final int CHARACTERS_PER_LINE_IN_CHART_LEGEND_NUMBER = 149; - private static final int DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART = 65; + private static final int IMAGE_WIDTH_PIXELS = 930; + private static final int IMAGE_HEIGHT_PIXELS = 400; + private static final int POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; + private static final int LINE_LENGTH_IN_LEGEND_LIMIT = 156; + private static final int DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT = 54; public static final String IMAGE_CONTENT_ID = "reportChart.png"; - public static final int POINT_IMAGE_WIDTH = 440; - public static final int POINT_IMAGE_HEIGHT = 250; // 340 + public static final int POINT_IMAGE_WIDTH_PIXELS = 440; + public static final int POINT_IMAGE_HEIGHT_PIXELS = 250; // 340 String inlinePrefix; private String html; @@ -101,7 +100,7 @@ public void createContent(ReportInstance reportInstance, ReportDao reportDao, St // Use a stream handler to get the report data from the database. StreamHandler handler = new StreamHandler(reportInstance.getReportStartTime(), - reportInstance.getReportEndTime(), IMAGE_WIDTH, createExportFile, bundle); + reportInstance.getReportEndTime(), IMAGE_WIDTH_PIXELS, createExportFile, bundle); // Process the report content with the handler. reportDao.reportInstanceData(reportInstance.getId(), handler); @@ -135,7 +134,7 @@ else if (pointStat.getDiscreteTimeSeries() != null) if (ptsc.hasData()) { if (inlinePrefix != null) model.put("chartName", inlinePrefix + pointStat.getChartName()); - pointStat.setImageData(ImageChartUtils.getChartData(ptsc, POINT_IMAGE_WIDTH, POINT_IMAGE_HEIGHT)); + pointStat.setImageData(ImageChartUtils.getChartData(ptsc, POINT_IMAGE_WIDTH_PIXELS, POINT_IMAGE_HEIGHT_PIXELS)); } } @@ -148,12 +147,9 @@ else if (pointStat.getDiscreteTimeSeries() != null) // The path comes from the servlet path definition in web.xml. model.put("chartName", IMAGE_SERVLET + chartName); } - try{ - int consolidatedChartHeight = ImageChartUtils.calculateHeightConsolidatedChart(pointStatistics, IMAGE_HEIGHT, IMAGE_POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS, CHARACTERS_PER_LINE_IN_CHART_LEGEND_NUMBER); - imageData = ImageChartUtils.getChartData(ptsc, true, IMAGE_WIDTH, consolidatedChartHeight); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } + int consolidatedChartHeight = ImageChartUtils.calculateHeightChart(pointStatistics, IMAGE_HEIGHT_PIXELS, + POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS, LINE_LENGTH_IN_LEGEND_LIMIT, DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT); + imageData = ImageChartUtils.getChartData(ptsc, true, IMAGE_WIDTH_PIXELS, consolidatedChartHeight); } List events = null; @@ -263,8 +259,8 @@ public List getPointStatistics() { return pointStatistics; } - public static int getDataPointExtendedNameLengthForChart(){ - return DATA_POINT_EXTENDED_NAME_LENGTH_FOR_CHART; + public static int getDataPointExtendedNameLengthLimit(){ + return DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT; } public static class PointStatistics { diff --git a/src/org/scada_lts/serorepl/utils/StringUtils.java b/src/org/scada_lts/serorepl/utils/StringUtils.java index dab987bc2c..3c71af77fa 100644 --- a/src/org/scada_lts/serorepl/utils/StringUtils.java +++ b/src/org/scada_lts/serorepl/utils/StringUtils.java @@ -1,6 +1,5 @@ package org.scada_lts.serorepl.utils; -import br.org.scadabr.api.da.WriteDataOptions; import org.apache.commons.lang3.ObjectUtils; import java.util.Properties; @@ -10,7 +9,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -public class StringUtils { +public final class StringUtils { private static final Random RANDOM = new Random(); @@ -25,6 +24,8 @@ public class StringUtils { private static final String CLOSE_BRACKET = "}"; private static int FIRST_GROUP = 1; + private StringUtils() {} + public static String capitalize(String s){ if (s != null){ @@ -151,21 +152,27 @@ public static String truncate(String s, int length, String truncateSuffix){ return s.substring(0,length); } - public static String truncate(String s, String truncateSuffix, int length) { - if(truncateSuffix != null && truncateSuffix.length() >= length) - throw new IllegalArgumentException(""); - if (length < 4) - throw new IllegalArgumentException("Minimum abbreviation width is 4"); + public static String truncate(String word, String suffix, int length) { + if(word == null) + throw new IllegalArgumentException("The abbreviated word cannot be null."); + if(word.length() <= length) { + return word; + } String name; - if(truncateSuffix == null) { - name = org.apache.commons.lang3.StringUtils.abbreviate(s, length); + if(suffix == null) { + if (length < 4) + throw new IllegalArgumentException("Minimum abbreviation width is 4 but was: " + length); + name = org.apache.commons.lang3.StringUtils.abbreviate(word, length); return name; } else { - int fixedLength = length - truncateSuffix.length(); - name = org.apache.commons.lang3.StringUtils.abbreviate(s, fixedLength + 3); + int minLength = suffix.length() + 1; + if (length < minLength) + throw new IllegalArgumentException("Minimum abbreviation width is " + minLength + " but was: " + length); + int fixedLength = length - suffix.length(); + name = org.apache.commons.lang3.StringUtils.abbreviate(word, fixedLength + 3); if(name.length() > fixedLength) name = name.substring(0, fixedLength); - return name + truncateSuffix; + return name + suffix; } } } diff --git a/test/br/org/scadabr/db/utils/TestUtils.java b/test/br/org/scadabr/db/utils/TestUtils.java index 35aaf64ebd..19f295cfff 100644 --- a/test/br/org/scadabr/db/utils/TestUtils.java +++ b/test/br/org/scadabr/db/utils/TestUtils.java @@ -1,20 +1,52 @@ package br.org.scadabr.db.utils; import java.util.ArrayList; -import java.util.Random; import com.serotonin.mango.db.dao.UserDao; import com.serotonin.mango.vo.DataPointVO; import com.serotonin.mango.vo.User; import com.serotonin.mango.vo.dataSource.DataSourceVO; -import com.serotonin.mango.vo.dataSource.PointLocatorVO; -import com.serotonin.mango.vo.dataSource.viconics.ViconicsPointLocatorVO; import com.serotonin.mango.vo.dataSource.virtual.VirtualDataSourceVO; import com.serotonin.mango.vo.dataSource.virtual.VirtualPointLocatorVO; import com.serotonin.mango.vo.permission.DataPointAccess; -import org.scada_lts.dao.model.pointhierarchy.PointHierarchyNode; -public class TestUtils { +public final class TestUtils { + + private TestUtils() {} + + public static String STRING_LENGTH_0 = ""; + public static String STRING_LENGTH_1 = "d"; + public static String STRING_LENGTH_2 = "ds"; + public static String STRING_LENGTH_3 = "ds_"; + public static String STRING_LENGTH_4 = "ds_1"; + public static String STRING_LENGTH_5 = "ds_1 "; + public static String STRING_LENGTH_6 = "ds_1 -"; + public static String STRING_LENGTH_7 = "ds_1 - "; + public static String STRING_LENGTH_8 = "ds_1 - 8"; + public static String STRING_LENGTH_9 = "ds_1 - 9c"; + public static String STRING_LENGTH_10 = "ds_1 - 10c"; + public static String STRING_LENGTH_11 = "ds_1 - 11ch"; + public static String STRING_LENGTH_12 = "ds_1 - 12cha"; + public static String STRING_LENGTH_13 = "ds_1 - 13char"; + public static String STRING_LENGTH_14 = "ds_1 - 14chara"; + public static String STRING_LENGTH_15 = "ds_1 - 15charac"; + public static String STRING_LENGTH_16 = "ds_1 - 16charact"; + public static String STRING_LENGTH_17 = "ds_1 - 17characte"; + public static String STRING_LENGTH_18 = "ds_1 - 18character"; + public static String STRING_LENGTH_19 = "ds_1 - 19characters"; + public static String STRING_LENGTH_20 = "ds_1 - 20characters2"; + public static String STRING_LENGTH_25 = "ds_1 - 25characters25char"; + public static String STRING_LENGTH_30 = "ds_1 - 30characters30character"; + public static String STRING_LENGTH_40 = "ds_1 - 40characters40characters40charact"; + public static String STRING_LENGTH_50 = "ds_1 - 50characters50characters50characters50chara"; + public static String STRING_LENGTH_60 = "ds_1 - 60characters60characters60characters60characters60cha"; + public static String STRING_LENGTH_70 = "ds_1 - 70characters70characters70characters70characters70characters70c"; + public static String STRING_LENGTH_80 = "ds_1 - 80characters80characters80characters80characters80characters80characters8"; + public static String STRING_LENGTH_90 = "ds_1 - 90characters90characters90characters90characters90characters90characters90character"; + public static String STRING_LENGTH_100 = "ds_1 - 100characters100characters100characters100characters100characters100characters100characters10"; + public static String STRING_LENGTH_135 = "ds_1 - 135characters135characters135characters135characters135characters135characters135characters135characters135characters135characte"; + public static String STRING_LENGTH_138 = "ds_1 - 138characters138characters138characters138characters138characters138characters138characters138characters138characters138characters1"; + public static String STRING_LENGTH_140 = "ds_1 - 140characters140characters140characters140characters140characters140characters140characters140characters140characters140characters140"; public static User createUser() { User user = new User(); diff --git a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java deleted file mode 100644 index ee79ee4cc4..0000000000 --- a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightExceptionTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.serotonin.mango.vo.report; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -@RunWith(Parameterized.class) -public class CalculateConsolidatedChartHeightExceptionTest { - - @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeightException(points: {0}, expected height: {1},pixels per line: {2} base height of chart: {3}, characters per line: {4})") - public static Collection data() { - String _4CharacterPointName = "4cha"; - String _8CharacterPointName = "8charact"; - String _25CharactersPointName = "25characters - 25characte"; - String _50CharactersPointName = "50characters - 50characters50characters50character"; - String _140CharactersPointName = "140characters - 140characters140characters140characters140characters140characters140characters140characters140characters140characters140char"; - return Arrays.asList(new Object[][]{ - {createPointStatisticsList(List.of(_4CharacterPointName)), 20, 400, 3}, - {createPointStatisticsList(List.of(_8CharacterPointName)), 20, 400, 7}, - {createPointStatisticsList(List.of(_25CharactersPointName)), 20, 400, 20}, - {createPointStatisticsList(List.of(_50CharactersPointName)), 20, 400, 40}, - {createPointStatisticsList(List.of(_140CharactersPointName)), 20, 400, 138}, - }); - } - - private final List pointStatistics; - private final int imageHeightForDataPointNameInLegend; - private final int imageHeight; - private final int charAmountPerLine; - public CalculateConsolidatedChartHeightExceptionTest(List pointStatistics, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { - this.pointStatistics = pointStatistics; - this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; - this.imageHeight = imageHeight; - this.charAmountPerLine = charAmountPerLine; - } - - private static List createPointStatisticsList(List pointName) { - List pointStatisticsList = new ArrayList<>(); - for (String pName : pointName) { - ReportChartCreator.PointStatistics pointStatistics = new ReportChartCreator.PointStatistics(1, ""); - pointStatistics.setName(pName); - pointStatisticsList.add(pointStatistics); - } - return pointStatisticsList; - } - - @Test(expected = IllegalArgumentException.class) - public void when_calculateConsolidatedChartHeightExpectException() { - ImageChartUtils.calculateHeightConsolidatedChart(pointStatistics, imageHeight, imageHeightForDataPointNameInLegend, charAmountPerLine); - } - -} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java b/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java deleted file mode 100644 index 093aab3f48..0000000000 --- a/test/com/serotonin/mango/vo/report/CalculateConsolidatedChartHeightTest.java +++ /dev/null @@ -1,269 +0,0 @@ -package com.serotonin.mango.vo.report; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(Parameterized.class) -public class CalculateConsolidatedChartHeightTest { - - @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, expected height: {1},pixels per line: {2} base height of chart: {3}, characters per line: {4})") - public static Collection data() { - String chars0PointName = ""; - String chars1PointName = "1"; - String chars2PointName = "2c"; - String chars3PointName = "3ch"; - String chars4PointName = "4cha"; - String chars5PointName = "5char"; - String chars6PointName = "6chara"; - String chars7PointName = "7charac"; - String chars8PointName = "8charact"; - String chars9PointName = "9characte"; - String chars10PointName = "ds_1 - 10c"; - String chars15PointName = "ds_1 - 15charac"; - String chars20PointName = "ds_1 - 20characters2"; - String chars25PointName = "ds_1 - 25characters25char"; - String chars30PointName = "ds_1 - 30characters30character"; - String chars50PointName = "ds_1 - 50characters50characters50characters50chara"; - String chars60PointName = "ds_1 - 60characters60characters60characters60characters60cha"; - String chars70PointName = "ds_1 - 70characters70characters70characters70characters70characters70c"; - String chars80PointName = "ds_1 - 80characters80characters80characters80characters80characters80characters8"; - String chars90PointName = "ds_1 - 90characters90characters90characters90characters90characters90characters90character"; - String chars100PointName = "ds_1 - 100characters100characters100characters100characters100characters100characters100characters10"; - String chars135PointName = "135characters - 135characters135characters135characters135characters135characters135characters135characters135characters135characters13"; - String chars138PointName = "138characters - 138characters138characters138characters138characters138characters138characters138characters138characters138characters138ch"; - - return Arrays.asList(new Object[][]{ - {List.of(), 400, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList( - chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName, chars0PointName - )), 420, 20, 400, 15}, - {createPointStatisticsList(List.of(chars135PointName)), 400, 20, 400, 138}, - {createPointStatisticsList(List.of(chars138PointName)), 400, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList(chars138PointName, chars138PointName, chars138PointName)), 440, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList(chars135PointName, chars135PointName, chars135PointName)), 440, 20, 400, 138}, - {createPointStatisticsList(Arrays.asList( - chars4PointName, chars2PointName, chars1PointName, chars3PointName, chars4PointName - )), 420, 20, 400, 16}, - {createPointStatisticsList(Arrays.asList( - chars4PointName, chars2PointName, chars3PointName, chars1PointName, chars4PointName - )), 440, 20, 400, 16}, - {createPointStatisticsList(Arrays.asList( - chars5PointName, chars6PointName, chars7PointName, chars8PointName, chars9PointName - )), 460, 20, 400, 18}, - {createPointStatisticsList(Arrays.asList( - chars5PointName, chars8PointName, chars6PointName, chars9PointName, chars7PointName - )), 480, 20, 400, 18}, - {createPointStatisticsList(Arrays.asList( - chars10PointName, chars15PointName, chars20PointName, chars30PointName, chars25PointName - )), 460, 20, 400, 35}, - {createPointStatisticsList(Arrays.asList( - chars10PointName, chars20PointName, chars15PointName, chars25PointName, chars30PointName - )), 480, 20, 400, 35}, - - - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars50PointName, - chars100PointName - )), 440, 20, 400, 149}, - {createPointStatisticsList(Arrays.asList( - chars50PointName, - chars100PointName, - chars80PointName, - chars90PointName, - chars60PointName, - chars50PointName - )), 480, 20, 400, 149}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars10PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars90PointName - )), 460, 20, 400, 149}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars10PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars90PointName, - chars70PointName, - chars30PointName, - chars20PointName, - chars90PointName, - chars100PointName - )),520,20,400,138}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars10PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars90PointName, - chars70PointName, - chars30PointName, - chars20PointName, - chars90PointName, - chars100PointName, - chars30PointName, - chars20PointName, - chars100PointName, - chars50PointName, - chars10PointName, - chars90PointName - )),580,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars100PointName, - chars80PointName, - chars90PointName, - chars70PointName, - chars30PointName, - chars90PointName, - chars100PointName, - chars100PointName, - chars50PointName, - chars90PointName, - chars20PointName, - chars80PointName, - chars80PointName, - chars10PointName - )),580,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars20PointName, - chars30PointName, - chars60PointName, - chars70PointName, - chars20PointName, - chars10PointName, - chars50PointName, - chars30PointName, - chars80PointName, - chars30PointName - )),480,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars50PointName, - chars30PointName, - chars60PointName, - chars70PointName, - chars10PointName, - chars30PointName, - chars30PointName, - chars100PointName, - chars20PointName, - chars70PointName, - chars90PointName, - chars100PointName, - chars20PointName, - chars50PointName, - chars20PointName, - chars10PointName - )),540,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars20PointName, - chars70PointName, - chars20PointName, - chars10PointName, - chars100PointName, - chars90PointName, - chars30PointName, - chars90PointName, - chars20PointName, - chars10PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars30PointName, - chars60PointName - )),520,20,400,149}, - {createPointStatisticsList(Arrays.asList( - chars70PointName, - chars30PointName, - chars20PointName, - chars70PointName, - chars20PointName, - chars10PointName, - chars100PointName, - chars90PointName, - chars30PointName, - chars90PointName, - chars20PointName, - chars10PointName, - chars50PointName, - chars20PointName, - chars10PointName, - chars30PointName, - chars60PointName, - chars100PointName, - chars80PointName, - chars90PointName, - chars100PointName, - chars80PointName, - chars30PointName, - chars80PointName, - chars50PointName, - chars70PointName, - chars50PointName, - chars60PointName, - chars60PointName - )),680,20,400,149}, - }); - } - - private final List pointStatistics; - private final int expectedHeight; - private final int imageHeightForDataPointNameInLegend; - private final int imageHeight; - private final int charAmountPerLine; - public CalculateConsolidatedChartHeightTest(List pointStatistics, int expectedHeight, int imageHeightForDataPointNameInLegend, int imageHeight, int charAmountPerLine) { - this.pointStatistics = pointStatistics; - this.expectedHeight = expectedHeight; - this.imageHeightForDataPointNameInLegend = imageHeightForDataPointNameInLegend; - this.imageHeight = imageHeight; - this.charAmountPerLine = charAmountPerLine; - } - - private static List createPointStatisticsList(List pointName) { - List pointStatisticsList = new ArrayList<>(); - for (String pName : pointName) { - ReportChartCreator.PointStatistics pointStatistics = new ReportChartCreator.PointStatistics(1, ""); - pointStatistics.setName(pName); - pointStatisticsList.add(pointStatistics); - } - return pointStatisticsList; - } - - @Test - public void when_calculateConsolidatedChartHeight() { - //when: - int actualHeight = ImageChartUtils.calculateHeightConsolidatedChart(pointStatistics, imageHeight, imageHeightForDataPointNameInLegend, charAmountPerLine); - //than: - assertEquals(expectedHeight, actualHeight); - } - -} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java new file mode 100644 index 0000000000..fbf0525654 --- /dev/null +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsExceptionTest.java @@ -0,0 +1,46 @@ +package com.serotonin.mango.vo.report; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.List; + +import static br.org.scadabr.db.utils.TestUtils.*; + +@RunWith(Parameterized.class) +public class CalculateLinesImageChartUtilsExceptionTest { + + @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, lineLengthInLegendLimit: {1}, dataPointExtendedNameLengthLimit: {2})") + public static Object[][] data() { + + return new Object[][] { + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), -1, -1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 0, 0}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 0, -1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), -1, 0}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), -1, 1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 0, 1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 1, -1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 1, 0}, + }; + } + + private final List pointStatisticsNames; + private final int lineLengthInLegendLimit; + private final int dataPointExtendedNameLengthLimit; + + public CalculateLinesImageChartUtilsExceptionTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { + this.pointStatisticsNames = pointStatisticsNames; + this.lineLengthInLegendLimit = lineLengthInLegendLimit; + this.dataPointExtendedNameLengthLimit = dataPointExtendedNameLengthLimit; + } + + @Test(expected = IllegalArgumentException.class) + public void when_calculateConsolidatedChartHeight() { + + //when: + ImageChartUtils.calculateLinesNumber(pointStatisticsNames, lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); + } + +} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java new file mode 100644 index 0000000000..a27a30fbbc --- /dev/null +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java @@ -0,0 +1,156 @@ +package com.serotonin.mango.vo.report; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.List; + +import static br.org.scadabr.db.utils.TestUtils.*; +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class CalculateLinesImageChartUtilsTest { + + @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, lineLengthInLegendLimit: {1}, dataPointExtendedNameLengthLimit: {2}, expectedLinesNumber: {3})") + public static Object[][] data() { + + List withNulls = new ArrayList<>(); + withNulls.add(null); + withNulls.add(null); + return new Object[][] { + + {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16), 156, 54, 1}, + + {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16, STRING_LENGTH_8), 156, 54, 1}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_138, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_17), 156, 54, 2}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15 + ), 156, 54, 3}, + + {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10 + ), 156, 54, 2}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, + STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70 + ), 156, 54, 4}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, + STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, + STRING_LENGTH_8, STRING_LENGTH_80, STRING_LENGTH_90, STRING_LENGTH_9, STRING_LENGTH_11, + STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17 + ), 156, 54, 7}, + + {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10, + STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, STRING_LENGTH_40, + STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, STRING_LENGTH_80, + STRING_LENGTH_90, STRING_LENGTH_9, STRING_LENGTH_11 + ), 156, 54, 6}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, + STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, + STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, + STRING_LENGTH_80, STRING_LENGTH_90, STRING_LENGTH_9 + ), 156, 54, 7}, + + + {List.of(), 1, 1, 1}, + {List.of(STRING_LENGTH_0, STRING_LENGTH_0), 1, 1, 1}, + {withNulls, 1, 1, 1}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 1, 1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 2, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 3, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 4, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 5, 2}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 1, 1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 2, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 3, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 4, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 5, 2}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 1, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 2, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 3, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 4, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 5, 2}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 18, 1, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 18, 2, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 18, 3, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 18, 4, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 18, 5, 3}, + + + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 14, 1, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 14, 2, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 14, 3, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 14, 4, 4}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 14, 5, 4}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 14, 1, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 14, 2, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 14, 3, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 14, 4, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 14, 5, 3}, + + + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 12, 1, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 12, 2, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 12, 3, 4}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 12, 4, 4}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 12, 5, 4}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 12, 1, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 12, 2, 3}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 12, 3, 4}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 12, 4, 4}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 12, 5, 4}, + + + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 9, 1, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 9, 2, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 9, 3, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 9, 4, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 9, 5, 5}, + + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 9, 1, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 9, 2, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 9, 3, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 9, 4, 5}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 9, 5, 5}, + + }; + } + + private final List pointStatisticsNames; + private final int expectedLinesNumber; + private final int lineLengthInLegendLimit; + private final int dataPointExtendedNameLengthLimit; + + public CalculateLinesImageChartUtilsTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { + this.pointStatisticsNames = pointStatisticsNames; + this.expectedLinesNumber = expectedLinesNumber; + this.lineLengthInLegendLimit = lineLengthInLegendLimit; + this.dataPointExtendedNameLengthLimit = dataPointExtendedNameLengthLimit; + } + + @Test + public void when_calculateConsolidatedChartHeight() { + + //when: + int resultLinesNumber = ImageChartUtils.calculateLinesNumber(pointStatisticsNames, lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); + + //then: + assertEquals(expectedLinesNumber, resultLinesNumber); + } + +} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java index 24c64720b9..fa07827023 100644 --- a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java +++ b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java @@ -6,8 +6,8 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - CalculateConsolidatedChartHeightExceptionTest.class, - CalculateConsolidatedChartHeightTest.class, + CalculateLinesImageChartUtilsTest.class, + CalculateLinesImageChartUtilsExceptionTest.class, }) public class ImageChartUtilsTestsSuite { } \ No newline at end of file diff --git a/test/org/scada_lts/dao/ReportInstanceDaoTest.java b/test/org/scada_lts/dao/ReportInstanceDaoTest.java index ba47dd3a23..d559dfcf31 100644 --- a/test/org/scada_lts/dao/ReportInstanceDaoTest.java +++ b/test/org/scada_lts/dao/ReportInstanceDaoTest.java @@ -205,7 +205,7 @@ public void testReportInstanceDataDAO() { + ", " + REPORT_START_TIME + ", " + REPORT_END_TIME + "," + RUN_START_TIME + "," + RUN_END_TIME + "," + RECORD_COUNT + "," + PREVENT_PURGE + ")"); ReportInstancePointDAO reportInstancePointDAO = new ReportInstancePointDAO(); - reportInstancePointDAO.insert(reportInstance, dataPointVO, POINT_NAME, DATA_TYPE, startValue, pointInfo); + reportInstancePointDAO.insert(reportInstance, DATA_TYPE, startValue, pointInfo); ReportInstanceDataDAO reportInstanceDataDAO = new ReportInstanceDataDAO(); @@ -266,8 +266,8 @@ public void testReportInstancePointDAO() { ReportInstancePointDAO reportInstancePointDAO = new ReportInstancePointDAO(); //Insert objects - int firstId = reportInstancePointDAO.insert(reportInstance, dataPointVO, POINT_NAME, DATA_TYPE, startValue, pointInfo); - int secondId = reportInstancePointDAO.insert(reportInstance, dataPointVO, SECOND_POINT_NAME, SECOND_DATA_TYPE, startValue, pointInfo); + int firstId = reportInstancePointDAO.insert(reportInstance, DATA_TYPE, startValue, pointInfo); + int secondId = reportInstancePointDAO.insert(reportInstance, SECOND_DATA_TYPE, startValue, pointInfo); //Select all objects List reportPointInfoList = reportInstancePointDAO.getPointInfos(INSTANCE_ID); diff --git a/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java b/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsTest.java similarity index 97% rename from test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java rename to test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsTest.java index 8d64286970..eb79c4120c 100644 --- a/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsWithProdParametersTest.java +++ b/test/org/scada_lts/serorepl/utils/ReplaceMacroStringUtilsTest.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -public class ReplaceMacroStringUtilsWithProdParametersTest { +public class ReplaceMacroStringUtilsTest { private final static String timestampSql = "and ${field}>=? and ${field} data() { - return Arrays.asList(new Object[][]{ - {"ds - datap", "longsuffix", 6}, - {"ds - dp", "suffix", 6}, - {"2c", ".", 1}, - {"ds - datapointnameplaceholder1", "longsuffix", 9}, - {"ds-dp", ".", 3}, - {"ds-dp", null, 3} + return Arrays.asList(new Object[][] { + + {null, null, 6}, + {null, "", 6}, + {null, ".", 6}, + {null, "....", 6}, + + {STRING_LENGTH_7, null, 3}, + {STRING_LENGTH_8, null, 3}, + {STRING_LENGTH_9, null, 3}, + + {STRING_LENGTH_7, null, 2}, + {STRING_LENGTH_8, null, 2}, + {STRING_LENGTH_9, null, 2}, + + {STRING_LENGTH_7, null, 1}, + {STRING_LENGTH_8, null, 1}, + {STRING_LENGTH_9, null, 1}, + + {STRING_LENGTH_7, null, 0}, + {STRING_LENGTH_8, null, 0}, + {STRING_LENGTH_9, null, 0}, + + {STRING_LENGTH_7, "", 0}, + {STRING_LENGTH_8, "", 0}, + {STRING_LENGTH_9, "", 0}, + + {STRING_LENGTH_7, ".", 0}, + {STRING_LENGTH_8, ".", 0}, + {STRING_LENGTH_9, ".", 0}, + + {STRING_LENGTH_7, "..", 0}, + {STRING_LENGTH_8, "..", 0}, + {STRING_LENGTH_9, "..", 0}, + + {STRING_LENGTH_7, null, -1}, + {STRING_LENGTH_8, null, -1}, + {STRING_LENGTH_9, null, -1}, + + {STRING_LENGTH_9, "123456", 6}, + {STRING_LENGTH_9, "1234567", 7}, + {STRING_LENGTH_9, "12345678", 8}, + + {STRING_LENGTH_9, "123456", 5}, + {STRING_LENGTH_9, "1234567", 6}, + {STRING_LENGTH_9, "12345678", 7}, + + }); } private final String word; - private final String truncateSuffix; + private final String suffix; private final int length; - public TruncateStringUtilsExceptionTest(String word, String truncateSuffix, int length) { + public TruncateStringUtilsExceptionTest(String word, String suffix, int length) { this.word = word; - this.truncateSuffix = truncateSuffix; + this.suffix = suffix; this.length = length; } - @Test(expected = IllegalArgumentException.class) public void when_truncateExpectException() { - StringUtils.truncate(word, truncateSuffix, length); + StringUtils.truncate(word, suffix, length); } } \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java index efa08d10e3..e8925198a3 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java @@ -1,14 +1,13 @@ package org.scada_lts.serorepl.utils; -import com.serotonin.mango.vo.report.ReportChartCreator; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.util.Arrays; import java.util.Collection; -import java.util.List; +import static br.org.scadabr.db.utils.TestUtils.*; import static org.junit.Assert.*; @RunWith(Parameterized.class) @@ -16,35 +15,119 @@ public class TruncateStringUtilsTest { @Parameterized.Parameters(name = "{index}: truncate(word: {0}, truncateSuffix: {1}, length: {2}, expectedWord: {3})") public static Collection data() { - return Arrays.asList(new Object[][]{ - {"ds - datapointnameDP", "...", 10, "ds - da..."}, - {"ds - datapointnameDP", "", 10, "ds - datap"}, - {"ds - datapointnameDP", null, 10, "ds - da..."}, - {"ds - datap", "12345", 7, "ds12345"}, - {"ds - data", " - datapoint", 14, "ds - datapoint"}, - {"ds - wrongname ", " - datapoint", 14, "ds - datapoint"} + return Arrays.asList(new Object[][] { + + {STRING_LENGTH_13, null, 10, "ds_1 - ...", 10}, + {STRING_LENGTH_13, "", 10, "ds_1 - 13c", 10}, + {STRING_LENGTH_13, ".", 10, "ds_1 - 13.", 10}, + {STRING_LENGTH_13, "..", 10, "ds_1 - 2..", 10}, + + {STRING_LENGTH_12, null, 10, "ds_1 - ...", 10}, + {STRING_LENGTH_12, "", 10, "ds_1 - 12c", 10}, + {STRING_LENGTH_12, ".", 10, "ds_1 - 12.", 10}, + {STRING_LENGTH_12, "..", 10, "ds_1 - 1..", 10}, + + {STRING_LENGTH_11, null, 10, "ds_1 - ...", 10}, + {STRING_LENGTH_11, "", 10, "ds_1 - 11c", 10}, + {STRING_LENGTH_11, ".", 10, "ds_1 - 11.", 10}, + {STRING_LENGTH_11, "..", 10, "ds_1 - 1..", 10}, + + {STRING_LENGTH_10, null, 10, "ds_1 - 10c", 10}, + {STRING_LENGTH_10, "", 10, "ds_1 - 10c", 10}, + {STRING_LENGTH_10, ".", 10, "ds_1 - 10c", 10}, + {STRING_LENGTH_10, "..", 10, "ds_1 - 10c", 10}, + + {STRING_LENGTH_9, null, 10, "ds_1 - 9c", 9}, + {STRING_LENGTH_9, "", 10, "ds_1 - 9c", 9}, + {STRING_LENGTH_9, ".", 10, "ds_1 - 9c", 9}, + {STRING_LENGTH_9, "..", 10, "ds_1 - 9c", 9}, + + {STRING_LENGTH_8, null, 10, "ds_1 - 8", 8}, + {STRING_LENGTH_8, "", 10, "ds_1 - 8", 8}, + {STRING_LENGTH_8, ".", 10, "ds_1 - 8", 8}, + {STRING_LENGTH_8, "..", 10, "ds_1 - 8", 8}, + + + {STRING_LENGTH_14, null, 11, "ds_1 - 1...", 11}, + {STRING_LENGTH_14, "", 11, "ds_1 - 14ch", 11}, + {STRING_LENGTH_14, ".", 11, "ds_1 - 14c.", 11}, + {STRING_LENGTH_14, "..", 11, "ds_1 - 14..", 11}, + + {STRING_LENGTH_13, null, 11, "ds_1 - 1...", 11}, + {STRING_LENGTH_13, "", 11, "ds_1 - 13ch", 11}, + {STRING_LENGTH_13, ".", 11, "ds_1 - 13c.", 11}, + {STRING_LENGTH_13, "..", 11, "ds_1 - 13..", 11}, + + {STRING_LENGTH_12, null, 11, "ds_1 - 1...", 11}, + {STRING_LENGTH_12, "", 11, "ds_1 - 12ch", 11}, + {STRING_LENGTH_12, ".", 11, "ds_1 - 12c.", 11}, + {STRING_LENGTH_12, "..", 11, "ds_1 - 12..", 11}, + + + {STRING_LENGTH_10, null, 11, "ds_1 - 10c", 10}, + {STRING_LENGTH_10, "", 11, "ds_1 - 10c", 10}, + {STRING_LENGTH_10, ".", 11, "ds_1 - 10c", 10}, + {STRING_LENGTH_10, "..", 11, "ds_1 - 10c", 10}, + + {STRING_LENGTH_9, null, 11, "ds_1 - 9c", 9}, + {STRING_LENGTH_9, "", 11, "ds_1 - 9c", 9}, + {STRING_LENGTH_9, ".", 11, "ds_1 - 9c", 9}, + {STRING_LENGTH_9, "..", 11, "ds_1 - 9c", 9}, + + {STRING_LENGTH_8, null, 11, "ds_1 - 8", 8}, + {STRING_LENGTH_8, "", 11, "ds_1 - 8", 8}, + {STRING_LENGTH_8, ".", 11, "ds_1 - 8", 8}, + {STRING_LENGTH_8, "..", 11, "ds_1 - 8", 8}, + + + {STRING_LENGTH_10, null, 4, "d...", 4}, + {STRING_LENGTH_10, "", 1, "d", 1}, + {STRING_LENGTH_10, ".", 2, "d.", 2}, + {STRING_LENGTH_10, "..", 3, "d..", 3}, + + {STRING_LENGTH_9, null, 4, "d...", 4}, + {STRING_LENGTH_9, "", 1, "d", 1}, + {STRING_LENGTH_9, ".", 2, "d.", 2}, + {STRING_LENGTH_9, "..", 3, "d..", 3}, + + {STRING_LENGTH_8, null, 4, "d...", 4}, + {STRING_LENGTH_8, "", 1, "d", 1}, + {STRING_LENGTH_8, ".", 2, "d.", 2}, + {STRING_LENGTH_8, "..", 3, "d..", 3}, + }); } private final String word; - private final String truncateSuffix; + private final String suffix; private final int length; private final String expectedWord; + private final int expectedLength; - public TruncateStringUtilsTest(String word, String truncateSuffix, int length, String expectedWord) { + public TruncateStringUtilsTest(String word, String suffix, int length, String expectedWord, int expectedLength) { this.word = word; - this.truncateSuffix = truncateSuffix; + this.suffix = suffix; this.length = length; this.expectedWord = expectedWord; + this.expectedLength = expectedLength; } @Test - public void truncate() { + public void when_truncate_then_word() { //when: - String actualWord = StringUtils.truncate(word, truncateSuffix, length); + String actualWord = StringUtils.truncate(word, suffix, length); //than: assertEquals(expectedWord, actualWord); } + + @Test + public void when_truncate_then_length() { + //when: + String actualWord = StringUtils.truncate(word, suffix, length); + + //than: + assertEquals(expectedLength, actualWord.length()); + } } \ No newline at end of file From 57d611f8dad2c2037745db8f39292239dc328a59 Mon Sep 17 00:00:00 2001 From: Kamil Jarmusik Date: Fri, 16 Feb 2024 19:51:53 +0100 Subject: [PATCH 6/8] #2726 Legend occupies too much space in reports screen: - corrected test TruncateStringUtilsTest --- test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java index e8925198a3..695fe2deac 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java @@ -20,7 +20,7 @@ public static Collection data() { {STRING_LENGTH_13, null, 10, "ds_1 - ...", 10}, {STRING_LENGTH_13, "", 10, "ds_1 - 13c", 10}, {STRING_LENGTH_13, ".", 10, "ds_1 - 13.", 10}, - {STRING_LENGTH_13, "..", 10, "ds_1 - 2..", 10}, + {STRING_LENGTH_13, "..", 10, "ds_1 - 1..", 10}, {STRING_LENGTH_12, null, 10, "ds_1 - ...", 10}, {STRING_LENGTH_12, "", 10, "ds_1 - 12c", 10}, From 3689bde46bae2108b05e294129404e74fb400256 Mon Sep 17 00:00:00 2001 From: Kamil Jarmusik Date: Mon, 19 Feb 2024 20:39:31 +0100 Subject: [PATCH 7/8] #2798 Corrected History Annotation Change Point Value By User: - change error on debug logging level in ImageChartUtils.calculateLinesNumber; - separate logic and app cases: CalculateLinesImageChartUtilsAppCaseTest, CalculateLinesImageChartUtilsLogicCaseTest; - added cases to test TruncateStringUtilsExceptionTest --- .../mango/vo/report/ImageChartUtils.java | 8 +- .../mango/vo/report/ReportChartCreator.java | 8 +- ...culateLinesImageChartUtilsAppCaseTest.java | 107 ++++++++++++++++++ ...ateLinesImageChartUtilsLogicCaseTest.java} | 46 +------- .../vo/report/ImageChartUtilsTestsSuite.java | 5 +- .../TruncateStringUtilsExceptionTest.java | 36 +++++- .../utils/TruncateStringUtilsTest.java | 2 +- 7 files changed, 158 insertions(+), 54 deletions(-) create mode 100644 test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java rename test/com/serotonin/mango/vo/report/{CalculateLinesImageChartUtilsTest.java => CalculateLinesImageChartUtilsLogicCaseTest.java} (71%) diff --git a/src/com/serotonin/mango/vo/report/ImageChartUtils.java b/src/com/serotonin/mango/vo/report/ImageChartUtils.java index 6f5887c9ba..335715be5a 100644 --- a/src/com/serotonin/mango/vo/report/ImageChartUtils.java +++ b/src/com/serotonin/mango/vo/report/ImageChartUtils.java @@ -223,7 +223,7 @@ public static void addSecond(TimeSeries timeSeries, long time, Number value) { public static int calculateHeightChart(List pointStatistics, int imageHeightPixels, int pointLabelHeightInLegendPixels, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { int linesNumber = calculateLinesNumber(toListNames(pointStatistics), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); - return imageHeightPixels - pointLabelHeightInLegendPixels + (linesNumber * pointLabelHeightInLegendPixels) + 1; + return imageHeightPixels - pointLabelHeightInLegendPixels + ((linesNumber + 1) * pointLabelHeightInLegendPixels); } public static int calculateLinesNumber(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { @@ -238,14 +238,14 @@ public static int calculateLinesNumber(List pointStatisticsNames, int li if (name == null || name.isEmpty()) continue; name = truncate(split + truncate(name, "", dataPointExtendedNameLengthLimit), "", lineLengthInLegendLimit); - if ((subLegend.length() + name.length()) > lineLengthInLegendLimit) { - LOG.error(subLegend); + if (subLegend.length() + name.length() > lineLengthInLegendLimit) { + LOG.debug(subLegend); subLegend.delete(0, subLegend.length()); linesNumber++; } subLegend.append(name); if(i == pointStatisticsNames.size() - 1) { - LOG.error(subLegend); + LOG.debug(subLegend); subLegend.delete(0, subLegend.length()); } } diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index 22ea5c0d07..07382c5c20 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -59,8 +59,8 @@ public class ReportChartCreator { private static final int IMAGE_WIDTH_PIXELS = 930; private static final int IMAGE_HEIGHT_PIXELS = 400; private static final int POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; - private static final int LINE_LENGTH_IN_LEGEND_LIMIT = 156; - private static final int DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT = 54; + private static final int LINE_LENGTH_IN_LEGEND_LIMIT = 161; + private static final int DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT = 64; public static final String IMAGE_CONTENT_ID = "reportChart.png"; public static final int POINT_IMAGE_WIDTH_PIXELS = 440; @@ -263,6 +263,10 @@ public static int getDataPointExtendedNameLengthLimit(){ return DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT; } + public static int getLineLengthInLegendLimit() { + return LINE_LENGTH_IN_LEGEND_LIMIT; + } + public static class PointStatistics { private final int reportPointId; private String name; diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java new file mode 100644 index 0000000000..4f9a1ce748 --- /dev/null +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java @@ -0,0 +1,107 @@ +package com.serotonin.mango.vo.report; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static br.org.scadabr.db.utils.TestUtils.*; +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class CalculateLinesImageChartUtilsAppCaseTest { + + @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, lineLengthInLegendLimit: {1}, dataPointExtendedNameLengthLimit: {2}, expectedLinesNumber: {3})") + public static Object[][] data() { + + List withNulls = new ArrayList<>(); + withNulls.add(null); + withNulls.add(null); + + int lineLengthInLegendLimit = ReportChartCreator.getLineLengthInLegendLimit(); + int dataPointExtendedNameLengthLimit = ReportChartCreator.getDataPointExtendedNameLengthLimit(); + + return new Object[][] { + + {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16), + lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 1}, + + {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16, STRING_LENGTH_8), + lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 2}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_138, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_17), + lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 2}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 3}, + + {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 3}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, + STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 4}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, + STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, + STRING_LENGTH_8, STRING_LENGTH_80, STRING_LENGTH_9, STRING_LENGTH_11, + STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 6}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, + STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, + STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, + STRING_LENGTH_80, STRING_LENGTH_9 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 6}, + + {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10, + STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, STRING_LENGTH_40, + STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, STRING_LENGTH_80, + STRING_LENGTH_9, STRING_LENGTH_11 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 7}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, + STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, + STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, + STRING_LENGTH_80, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_90 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 7}, + + }; + } + + private final List pointStatisticsNames; + private final int expectedLinesNumber; + private final int lineLengthInLegendLimit; + private final int dataPointExtendedNameLengthLimit; + + public CalculateLinesImageChartUtilsAppCaseTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { + this.pointStatisticsNames = pointStatisticsNames.stream().map(a -> { + if(a == null) + return null; + return ImageChartUtils.calculatePointNameForReport(a); + }).collect(Collectors.toList()); + this.expectedLinesNumber = expectedLinesNumber; + this.lineLengthInLegendLimit = lineLengthInLegendLimit; + this.dataPointExtendedNameLengthLimit = dataPointExtendedNameLengthLimit; + } + + @Test + public void when_calculateConsolidatedChartHeight() { + + //when: + int resultLinesNumber = ImageChartUtils.calculateLinesNumber(pointStatisticsNames, lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); + + //then: + assertEquals(expectedLinesNumber, resultLinesNumber); + } + +} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java similarity index 71% rename from test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java rename to test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java index a27a30fbbc..d68052ff33 100644 --- a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java @@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals; @RunWith(Parameterized.class) -public class CalculateLinesImageChartUtilsTest { +public class CalculateLinesImageChartUtilsLogicCaseTest { @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, lineLengthInLegendLimit: {1}, dataPointExtendedNameLengthLimit: {2}, expectedLinesNumber: {3})") public static Object[][] data() { @@ -21,50 +21,11 @@ public static Object[][] data() { withNulls.add(null); return new Object[][] { - {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16), 156, 54, 1}, - - {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16, STRING_LENGTH_8), 156, 54, 1}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_138, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_17), 156, 54, 2}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, - STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15 - ), 156, 54, 3}, - - {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, - STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10 - ), 156, 54, 2}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, - STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70 - ), 156, 54, 4}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, - STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, - STRING_LENGTH_8, STRING_LENGTH_80, STRING_LENGTH_90, STRING_LENGTH_9, STRING_LENGTH_11, - STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, - STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17 - ), 156, 54, 7}, - - {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, - STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10, - STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, STRING_LENGTH_40, - STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, STRING_LENGTH_80, - STRING_LENGTH_90, STRING_LENGTH_9, STRING_LENGTH_11 - ), 156, 54, 6}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, - STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, - STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, - STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, - STRING_LENGTH_80, STRING_LENGTH_90, STRING_LENGTH_9 - ), 156, 54, 7}, - - {List.of(), 1, 1, 1}, {List.of(STRING_LENGTH_0, STRING_LENGTH_0), 1, 1, 1}, {withNulls, 1, 1, 1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 1, 1}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 2, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 3, 2}, @@ -77,6 +38,7 @@ public static Object[][] data() { {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 4, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 5, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 1, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 2, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 3, 2}, @@ -136,7 +98,7 @@ public static Object[][] data() { private final int lineLengthInLegendLimit; private final int dataPointExtendedNameLengthLimit; - public CalculateLinesImageChartUtilsTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { + public CalculateLinesImageChartUtilsLogicCaseTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { this.pointStatisticsNames = pointStatisticsNames; this.expectedLinesNumber = expectedLinesNumber; this.lineLengthInLegendLimit = lineLengthInLegendLimit; diff --git a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java index fa07827023..aa34a7c91c 100644 --- a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java +++ b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java @@ -6,8 +6,9 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - CalculateLinesImageChartUtilsTest.class, - CalculateLinesImageChartUtilsExceptionTest.class, + CalculateLinesImageChartUtilsAppCaseTest.class, + CalculateLinesImageChartUtilsLogicCaseTest.class, + CalculateLinesImageChartUtilsExceptionTest.class, }) public class ImageChartUtilsTestsSuite { } \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java index 6c1671f663..07792e276e 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java @@ -53,14 +53,44 @@ public static Collection data() { {STRING_LENGTH_8, null, -1}, {STRING_LENGTH_9, null, -1}, + + {STRING_LENGTH_9, "1", 1}, + {STRING_LENGTH_9, "12", 2}, + {STRING_LENGTH_9, "123", 3}, + + {STRING_LENGTH_9, "1234", 4}, + {STRING_LENGTH_9, "12345", 5}, + {STRING_LENGTH_9, "123456", 6}, + + {STRING_LENGTH_9, "12345", 5}, {STRING_LENGTH_9, "123456", 6}, {STRING_LENGTH_9, "1234567", 7}, - {STRING_LENGTH_9, "12345678", 8}, + + {STRING_LENGTH_9, "1", 0}, + {STRING_LENGTH_9, "12", 1}, + {STRING_LENGTH_9, "123", 2}, + + {STRING_LENGTH_9, "1234", 3}, + {STRING_LENGTH_9, "12345", 4}, {STRING_LENGTH_9, "123456", 5}, - {STRING_LENGTH_9, "1234567", 6}, - {STRING_LENGTH_9, "12345678", 7}, + {STRING_LENGTH_9, "123456", 6}, + {STRING_LENGTH_9, "1234567", 7}, + {STRING_LENGTH_9, "12345678", 8}, + + + {STRING_LENGTH_9, "1", 0}, + {STRING_LENGTH_9, "12", 0}, + {STRING_LENGTH_9, "123", 1}, + + {STRING_LENGTH_9, "1234", 2}, + {STRING_LENGTH_9, "12345", 3}, + {STRING_LENGTH_9, "123456", 4}, + + {STRING_LENGTH_9, "12345", 5}, + {STRING_LENGTH_9, "123456", 6}, + {STRING_LENGTH_9, "1234567", 7}, }); } diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java index 695fe2deac..46b0415e2c 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java @@ -13,7 +13,7 @@ @RunWith(Parameterized.class) public class TruncateStringUtilsTest { - @Parameterized.Parameters(name = "{index}: truncate(word: {0}, truncateSuffix: {1}, length: {2}, expectedWord: {3})") + @Parameterized.Parameters(name = "{index}: truncate(word: {0}, suffix: {1}, length: {2}, expectedWord: {3}, expectedLength: {4})") public static Collection data() { return Arrays.asList(new Object[][] { From fe4deef0ef39e30809f2d8329baa3403084d6259 Mon Sep 17 00:00:00 2001 From: Kamil Jarmusik Date: Mon, 19 Feb 2024 20:39:31 +0100 Subject: [PATCH 8/8] #2726 Legend occupies too much space in reports screen: - change error on debug logging level in ImageChartUtils.calculateLinesNumber; - separate logic and app cases: CalculateLinesImageChartUtilsAppCaseTest, CalculateLinesImageChartUtilsLogicCaseTest; - added cases to test TruncateStringUtilsExceptionTest --- .../mango/vo/report/ImageChartUtils.java | 8 +- .../mango/vo/report/ReportChartCreator.java | 8 +- ...culateLinesImageChartUtilsAppCaseTest.java | 107 ++++++++++++++++++ ...ateLinesImageChartUtilsLogicCaseTest.java} | 46 +------- .../vo/report/ImageChartUtilsTestsSuite.java | 5 +- .../TruncateStringUtilsExceptionTest.java | 36 +++++- .../utils/TruncateStringUtilsTest.java | 2 +- 7 files changed, 158 insertions(+), 54 deletions(-) create mode 100644 test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java rename test/com/serotonin/mango/vo/report/{CalculateLinesImageChartUtilsTest.java => CalculateLinesImageChartUtilsLogicCaseTest.java} (71%) diff --git a/src/com/serotonin/mango/vo/report/ImageChartUtils.java b/src/com/serotonin/mango/vo/report/ImageChartUtils.java index 6f5887c9ba..335715be5a 100644 --- a/src/com/serotonin/mango/vo/report/ImageChartUtils.java +++ b/src/com/serotonin/mango/vo/report/ImageChartUtils.java @@ -223,7 +223,7 @@ public static void addSecond(TimeSeries timeSeries, long time, Number value) { public static int calculateHeightChart(List pointStatistics, int imageHeightPixels, int pointLabelHeightInLegendPixels, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { int linesNumber = calculateLinesNumber(toListNames(pointStatistics), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); - return imageHeightPixels - pointLabelHeightInLegendPixels + (linesNumber * pointLabelHeightInLegendPixels) + 1; + return imageHeightPixels - pointLabelHeightInLegendPixels + ((linesNumber + 1) * pointLabelHeightInLegendPixels); } public static int calculateLinesNumber(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit) { @@ -238,14 +238,14 @@ public static int calculateLinesNumber(List pointStatisticsNames, int li if (name == null || name.isEmpty()) continue; name = truncate(split + truncate(name, "", dataPointExtendedNameLengthLimit), "", lineLengthInLegendLimit); - if ((subLegend.length() + name.length()) > lineLengthInLegendLimit) { - LOG.error(subLegend); + if (subLegend.length() + name.length() > lineLengthInLegendLimit) { + LOG.debug(subLegend); subLegend.delete(0, subLegend.length()); linesNumber++; } subLegend.append(name); if(i == pointStatisticsNames.size() - 1) { - LOG.error(subLegend); + LOG.debug(subLegend); subLegend.delete(0, subLegend.length()); } } diff --git a/src/com/serotonin/mango/vo/report/ReportChartCreator.java b/src/com/serotonin/mango/vo/report/ReportChartCreator.java index 22ea5c0d07..07382c5c20 100644 --- a/src/com/serotonin/mango/vo/report/ReportChartCreator.java +++ b/src/com/serotonin/mango/vo/report/ReportChartCreator.java @@ -59,8 +59,8 @@ public class ReportChartCreator { private static final int IMAGE_WIDTH_PIXELS = 930; private static final int IMAGE_HEIGHT_PIXELS = 400; private static final int POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20; - private static final int LINE_LENGTH_IN_LEGEND_LIMIT = 156; - private static final int DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT = 54; + private static final int LINE_LENGTH_IN_LEGEND_LIMIT = 161; + private static final int DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT = 64; public static final String IMAGE_CONTENT_ID = "reportChart.png"; public static final int POINT_IMAGE_WIDTH_PIXELS = 440; @@ -263,6 +263,10 @@ public static int getDataPointExtendedNameLengthLimit(){ return DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT; } + public static int getLineLengthInLegendLimit() { + return LINE_LENGTH_IN_LEGEND_LIMIT; + } + public static class PointStatistics { private final int reportPointId; private String name; diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java new file mode 100644 index 0000000000..4f9a1ce748 --- /dev/null +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsAppCaseTest.java @@ -0,0 +1,107 @@ +package com.serotonin.mango.vo.report; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import static br.org.scadabr.db.utils.TestUtils.*; +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class CalculateLinesImageChartUtilsAppCaseTest { + + @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, lineLengthInLegendLimit: {1}, dataPointExtendedNameLengthLimit: {2}, expectedLinesNumber: {3})") + public static Object[][] data() { + + List withNulls = new ArrayList<>(); + withNulls.add(null); + withNulls.add(null); + + int lineLengthInLegendLimit = ReportChartCreator.getLineLengthInLegendLimit(); + int dataPointExtendedNameLengthLimit = ReportChartCreator.getDataPointExtendedNameLengthLimit(); + + return new Object[][] { + + {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16), + lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 1}, + + {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16, STRING_LENGTH_8), + lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 2}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_138, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_17), + lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 2}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 3}, + + {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 3}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, + STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 4}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, + STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, + STRING_LENGTH_8, STRING_LENGTH_80, STRING_LENGTH_9, STRING_LENGTH_11, + STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 6}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, + STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, + STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, + STRING_LENGTH_80, STRING_LENGTH_9 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 6}, + + {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, + STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10, + STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, STRING_LENGTH_40, + STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, STRING_LENGTH_80, + STRING_LENGTH_9, STRING_LENGTH_11 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 7}, + + {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, + STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, + STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, + STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, + STRING_LENGTH_80, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_90 + ), lineLengthInLegendLimit, dataPointExtendedNameLengthLimit, 7}, + + }; + } + + private final List pointStatisticsNames; + private final int expectedLinesNumber; + private final int lineLengthInLegendLimit; + private final int dataPointExtendedNameLengthLimit; + + public CalculateLinesImageChartUtilsAppCaseTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { + this.pointStatisticsNames = pointStatisticsNames.stream().map(a -> { + if(a == null) + return null; + return ImageChartUtils.calculatePointNameForReport(a); + }).collect(Collectors.toList()); + this.expectedLinesNumber = expectedLinesNumber; + this.lineLengthInLegendLimit = lineLengthInLegendLimit; + this.dataPointExtendedNameLengthLimit = dataPointExtendedNameLengthLimit; + } + + @Test + public void when_calculateConsolidatedChartHeight() { + + //when: + int resultLinesNumber = ImageChartUtils.calculateLinesNumber(pointStatisticsNames, lineLengthInLegendLimit, dataPointExtendedNameLengthLimit); + + //then: + assertEquals(expectedLinesNumber, resultLinesNumber); + } + +} \ No newline at end of file diff --git a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java similarity index 71% rename from test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java rename to test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java index a27a30fbbc..d68052ff33 100644 --- a/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsTest.java +++ b/test/com/serotonin/mango/vo/report/CalculateLinesImageChartUtilsLogicCaseTest.java @@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals; @RunWith(Parameterized.class) -public class CalculateLinesImageChartUtilsTest { +public class CalculateLinesImageChartUtilsLogicCaseTest { @Parameterized.Parameters(name = "{index}: calculateConsolidatedChartHeight(points: {0}, lineLengthInLegendLimit: {1}, dataPointExtendedNameLengthLimit: {2}, expectedLinesNumber: {3})") public static Object[][] data() { @@ -21,50 +21,11 @@ public static Object[][] data() { withNulls.add(null); return new Object[][] { - {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16), 156, 54, 1}, - - {List.of(STRING_LENGTH_135, STRING_LENGTH_138, STRING_LENGTH_16, STRING_LENGTH_8), 156, 54, 1}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_138, STRING_LENGTH_8, STRING_LENGTH_9, STRING_LENGTH_17), 156, 54, 2}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, - STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15 - ), 156, 54, 3}, - - {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, - STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10 - ), 156, 54, 2}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, - STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70 - ), 156, 54, 4}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, - STRING_LENGTH_30, STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, - STRING_LENGTH_8, STRING_LENGTH_80, STRING_LENGTH_90, STRING_LENGTH_9, STRING_LENGTH_11, - STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, - STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17 - ), 156, 54, 7}, - - {List.of(STRING_LENGTH_12, STRING_LENGTH_135, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, - STRING_LENGTH_15, STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_100, STRING_LENGTH_10, - STRING_LENGTH_138, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, STRING_LENGTH_40, - STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, STRING_LENGTH_80, - STRING_LENGTH_90, STRING_LENGTH_9, STRING_LENGTH_11 - ), 156, 54, 6}, - - {List.of(STRING_LENGTH_100, STRING_LENGTH_10, STRING_LENGTH_11, STRING_LENGTH_12, STRING_LENGTH_135, - STRING_LENGTH_138, STRING_LENGTH_13, STRING_LENGTH_140, STRING_LENGTH_14, STRING_LENGTH_15, - STRING_LENGTH_16, STRING_LENGTH_17, STRING_LENGTH_20, STRING_LENGTH_25, STRING_LENGTH_30, - STRING_LENGTH_40, STRING_LENGTH_50, STRING_LENGTH_60, STRING_LENGTH_70, STRING_LENGTH_8, - STRING_LENGTH_80, STRING_LENGTH_90, STRING_LENGTH_9 - ), 156, 54, 7}, - - {List.of(), 1, 1, 1}, {List.of(STRING_LENGTH_0, STRING_LENGTH_0), 1, 1, 1}, {withNulls, 1, 1, 1}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 1, 1}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 2, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 27, 3, 2}, @@ -77,6 +38,7 @@ public static Object[][] data() { {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 4, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_2, STRING_LENGTH_1, STRING_LENGTH_3, STRING_LENGTH_4), 27, 5, 2}, + {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 1, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 2, 2}, {List.of(STRING_LENGTH_4, STRING_LENGTH_4, STRING_LENGTH_3, STRING_LENGTH_2, STRING_LENGTH_1), 18, 3, 2}, @@ -136,7 +98,7 @@ public static Object[][] data() { private final int lineLengthInLegendLimit; private final int dataPointExtendedNameLengthLimit; - public CalculateLinesImageChartUtilsTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { + public CalculateLinesImageChartUtilsLogicCaseTest(List pointStatisticsNames, int lineLengthInLegendLimit, int dataPointExtendedNameLengthLimit, int expectedLinesNumber) { this.pointStatisticsNames = pointStatisticsNames; this.expectedLinesNumber = expectedLinesNumber; this.lineLengthInLegendLimit = lineLengthInLegendLimit; diff --git a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java index fa07827023..aa34a7c91c 100644 --- a/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java +++ b/test/com/serotonin/mango/vo/report/ImageChartUtilsTestsSuite.java @@ -6,8 +6,9 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - CalculateLinesImageChartUtilsTest.class, - CalculateLinesImageChartUtilsExceptionTest.class, + CalculateLinesImageChartUtilsAppCaseTest.class, + CalculateLinesImageChartUtilsLogicCaseTest.class, + CalculateLinesImageChartUtilsExceptionTest.class, }) public class ImageChartUtilsTestsSuite { } \ No newline at end of file diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java index 6c1671f663..07792e276e 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsExceptionTest.java @@ -53,14 +53,44 @@ public static Collection data() { {STRING_LENGTH_8, null, -1}, {STRING_LENGTH_9, null, -1}, + + {STRING_LENGTH_9, "1", 1}, + {STRING_LENGTH_9, "12", 2}, + {STRING_LENGTH_9, "123", 3}, + + {STRING_LENGTH_9, "1234", 4}, + {STRING_LENGTH_9, "12345", 5}, + {STRING_LENGTH_9, "123456", 6}, + + {STRING_LENGTH_9, "12345", 5}, {STRING_LENGTH_9, "123456", 6}, {STRING_LENGTH_9, "1234567", 7}, - {STRING_LENGTH_9, "12345678", 8}, + + {STRING_LENGTH_9, "1", 0}, + {STRING_LENGTH_9, "12", 1}, + {STRING_LENGTH_9, "123", 2}, + + {STRING_LENGTH_9, "1234", 3}, + {STRING_LENGTH_9, "12345", 4}, {STRING_LENGTH_9, "123456", 5}, - {STRING_LENGTH_9, "1234567", 6}, - {STRING_LENGTH_9, "12345678", 7}, + {STRING_LENGTH_9, "123456", 6}, + {STRING_LENGTH_9, "1234567", 7}, + {STRING_LENGTH_9, "12345678", 8}, + + + {STRING_LENGTH_9, "1", 0}, + {STRING_LENGTH_9, "12", 0}, + {STRING_LENGTH_9, "123", 1}, + + {STRING_LENGTH_9, "1234", 2}, + {STRING_LENGTH_9, "12345", 3}, + {STRING_LENGTH_9, "123456", 4}, + + {STRING_LENGTH_9, "12345", 5}, + {STRING_LENGTH_9, "123456", 6}, + {STRING_LENGTH_9, "1234567", 7}, }); } diff --git a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java index 695fe2deac..46b0415e2c 100644 --- a/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java +++ b/test/org/scada_lts/serorepl/utils/TruncateStringUtilsTest.java @@ -13,7 +13,7 @@ @RunWith(Parameterized.class) public class TruncateStringUtilsTest { - @Parameterized.Parameters(name = "{index}: truncate(word: {0}, truncateSuffix: {1}, length: {2}, expectedWord: {3})") + @Parameterized.Parameters(name = "{index}: truncate(word: {0}, suffix: {1}, length: {2}, expectedWord: {3}, expectedLength: {4})") public static Collection data() { return Arrays.asList(new Object[][] {