From d79e19c005df3ca0a191722f42a2d2038f517218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Mon, 15 Nov 2021 19:28:03 +0100 Subject: [PATCH] do not delete temp directory --- gradle.properties | 4 +- gradle/test/junit5.gradle | 2 + .../AxesChartSeriesNumericalNoErrorBars.java | 14 +++-- .../org/xbib/graphics/chart/xy/XYSeries.java | 6 +-- .../org/xbib/graphics/chart/MatlabTest.java | 51 ++++++++++++++++++- .../graphics/ghostscript/Ghostscript.java | 38 +------------- 6 files changed, 67 insertions(+), 48 deletions(-) diff --git a/gradle.properties b/gradle.properties index b5f13be..f8db79d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib.graphics name = graphics -version = 4.0.3 +version = 4.0.4 gradle.wrapper.version = 6.6.1 pdfbox.version = 2.0.23 @@ -9,7 +9,7 @@ zxing.version = 3.3.1 reflections.version = 0.9.11 jfreechart.version = 1.5.1 batik.version = 1.13 -junit.version = 5.7.1 +junit.version = 5.7.2 junit4.version = 4.13.2 groovy.version = 2.5.12 spock.version = 1.3-groovy-2.5 diff --git a/gradle/test/junit5.gradle b/gradle/test/junit5.gradle index dddd158..b5d9c5f 100644 --- a/gradle/test/junit5.gradle +++ b/gradle/test/junit5.gradle @@ -13,8 +13,10 @@ test { useJUnitPlatform() failFast = false environment 'TMPDIR', '/var/tmp/gs' + file('/var/tmp/gs').mkdirs() systemProperty 'java.awt.headless', 'true' systemProperty 'java.io.tmpdir', '/var/tmp/' + systemProperty 'jna.tmpdir', '/var/tmp/' systemProperty 'jna.debug', 'false' systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties' testLogging { diff --git a/graphics-chart/src/main/java/org/xbib/graphics/chart/series/AxesChartSeriesNumericalNoErrorBars.java b/graphics-chart/src/main/java/org/xbib/graphics/chart/series/AxesChartSeriesNumericalNoErrorBars.java index af1365c..931a482 100644 --- a/graphics-chart/src/main/java/org/xbib/graphics/chart/series/AxesChartSeriesNumericalNoErrorBars.java +++ b/graphics-chart/src/main/java/org/xbib/graphics/chart/series/AxesChartSeriesNumericalNoErrorBars.java @@ -12,8 +12,10 @@ import java.util.List; */ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries { - protected List xData; // can be Number or Instant + protected List xData; + protected List yData; + protected List extraValues; public AxesChartSeriesNumericalNoErrorBars(String name, @@ -30,11 +32,9 @@ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries { @Override protected void calculateMinMax() { - // xData List xMinMax = findMinMax(xData); setXMin(xMinMax.get(0)); setXMax(xMinMax.get(1)); - // yData List yMinMax; if (extraValues == null) { yMinMax = findMinMax(yData); @@ -46,6 +46,9 @@ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries { } List findMinMax(List data) { + if (data == null) { + return Arrays.asList(null, null); + } Double min = null; Double max = null; for (Object dataPoint : data) { @@ -113,7 +116,10 @@ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries { } private List findMinMaxWithErrorBars(List data, - List errorBars) { + List errorBars) { + if (data == null) { + return Arrays.asList(Double.MAX_VALUE, Double.MAX_VALUE); + } double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; for (int i = 0; i < data.size(); i++) { diff --git a/graphics-chart/src/main/java/org/xbib/graphics/chart/xy/XYSeries.java b/graphics-chart/src/main/java/org/xbib/graphics/chart/xy/XYSeries.java index 676f317..1d1fd66 100644 --- a/graphics-chart/src/main/java/org/xbib/graphics/chart/xy/XYSeries.java +++ b/graphics-chart/src/main/java/org/xbib/graphics/chart/xy/XYSeries.java @@ -7,7 +7,7 @@ import org.xbib.graphics.chart.legend.LegendRenderType; import java.util.List; /** - * A Series containing X and Y data to be plotted on a Chart + * A Series containing X and Y data to be plotted on a Chart. */ public class XYSeries extends AxesChartSeriesNumericalNoErrorBars { @@ -33,6 +33,4 @@ public class XYSeries extends AxesChartSeriesNumericalNoErrorBars { public LegendRenderType getLegendRenderType() { return xySeriesRenderStyle.getLegendRenderType(); } - - -} \ No newline at end of file +} diff --git a/graphics-chart/src/test/java/org/xbib/graphics/chart/MatlabTest.java b/graphics-chart/src/test/java/org/xbib/graphics/chart/MatlabTest.java index be4c979..b204f09 100644 --- a/graphics-chart/src/test/java/org/xbib/graphics/chart/MatlabTest.java +++ b/graphics-chart/src/test/java/org/xbib/graphics/chart/MatlabTest.java @@ -2,6 +2,7 @@ package org.xbib.graphics.chart; import org.junit.jupiter.api.Test; import org.xbib.graphics.chart.io.VectorGraphicsFormat; +import org.xbib.graphics.chart.legend.LegendPosition; import org.xbib.graphics.chart.theme.MatlabTheme; import org.xbib.graphics.chart.xy.XYChart; import org.xbib.graphics.chart.xy.XYChartBuilder; @@ -16,7 +17,7 @@ import java.util.List; public class MatlabTest { @Test - public void testMatlabInstants() throws IOException { + public void testMatlabInstantsWithDoubles() throws IOException { XYChart chart = new XYChartBuilder().width(800).height(600) .theme(new MatlabTheme()) .title("Matlab Theme") @@ -61,7 +62,53 @@ public class MatlabTest { chart.addSeries("downloads", xData, y1Data); chart.addSeries("price", xData, y2Data); - chart.write(Files.newOutputStream(Paths.get("build/matlab.svg")), + chart.write(Files.newOutputStream(Paths.get("build/matlab1.svg")), VectorGraphicsFormat.SVG); } + + @Test + public void testMatlabInstantsWitInts() throws IOException { + XYChart chart = new XYChartBuilder() + .width(800) + .height(600) + .theme(new MatlabTheme()) + .title("Matlab Style Demo") + .xAxisTitle("X") + .yAxisTitle("Y") + .build(); + chart.getStyler().setLegendPosition(LegendPosition.OutsideE); + chart.getStyler().setDatePattern("LLL yyyy"); + chart.getStyler().setPlotGridLinesVisible(true); + chart.getStyler().setYAxisMin(0.0d); + + List xData = new ArrayList<>(); + List y1Data = new ArrayList<>(); + + xData.add(Instant.parse("2012-01-01T00:00:00Z")); + y1Data.add(120); + + xData.add(Instant.parse("2012-02-01T00:00:00Z")); + y1Data.add(165); + + xData.add(Instant.parse("2012-03-01T00:00:00Z")); + y1Data.add(210); + + xData.add(Instant.parse("2012-04-01T00:00:00Z")); + y1Data.add(400); + + xData.add(Instant.parse("2012-05-01T00:00:00Z")); + y1Data.add(80); + + xData.add(Instant.parse("2012-06-01T00:00:00Z")); + y1Data.add(200); + + xData.add(Instant.parse("2012-07-01T00:00:00Z")); + y1Data.add(300); + + chart.addSeries("Anzahl", xData, y1Data); + + chart.write(Files.newOutputStream(Paths.get("build/matlab2.svg")), + VectorGraphicsFormat.SVG); + } + } diff --git a/graphics-ghostscript/src/main/java/org/xbib/graphics/ghostscript/Ghostscript.java b/graphics-ghostscript/src/main/java/org/xbib/graphics/ghostscript/Ghostscript.java index 2792f50..8225ae1 100644 --- a/graphics-ghostscript/src/main/java/org/xbib/graphics/ghostscript/Ghostscript.java +++ b/graphics-ghostscript/src/main/java/org/xbib/graphics/ghostscript/Ghostscript.java @@ -11,13 +11,9 @@ import org.xbib.graphics.ghostscript.internal.NullOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.file.FileVisitResult; import java.nio.file.Files; -import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Arrays; @@ -99,7 +95,6 @@ public class Ghostscript { nativeInstanceByRef = null; } instance = null; - deleteTmp(); } } @@ -326,38 +321,9 @@ public class Ghostscript { throw new IllegalStateException("no TEMP/TMPDIR environment set for ghostscript"); } tmpDir = Paths.get(tmp); - deleteTmp(); - Files.createDirectories(tmpDir); - } - - private static void deleteTmp() throws IOException { - if (tmpDir == null) { - return; - } if (!Files.exists(tmpDir)) { - return; - } - try { - Files.walkFileTree(tmpDir, new SimpleFileVisitor<>() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - logger.info("deleting " + file); - Files.deleteIfExists(file); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - logger.info("deleting " + dir); - Files.deleteIfExists(dir); - return FileVisitResult.CONTINUE; - } - }); - } catch (NoSuchFileException e) { - logger.log(Level.WARNING, e.getMessage(), e); - } finally { - logger.info("deleting " + tmpDir); - Files.deleteIfExists(tmpDir); + Files.createDirectories(tmpDir); } + // never delete TMPDIR or TEMP automatically, it might be a shared directory } }