diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/App.java b/src/main/java/de/tudresden/inf/mci/brailleplot/App.java index 5f071a80db9d5b6423411855063f2312149663e7..9074a22d9cf8b30bb99ea335862ca556cd1b938b 100644 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/App.java +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/App.java @@ -189,6 +189,9 @@ public final class App { CategoricalPointListContainer<PointList> container = csvParser.parse(CsvType.X_ALIGNED_CATEGORIES, CsvOrientation.VERTICAL); mLogger.debug("Internal data representation:\n {}", container.toString()); CategoricalBarChart barChart = new CategoricalBarChart(container); + barChart.setTitle("Beispieldiagramm"); + barChart.setXAxisName("Gewicht in kg"); + barChart.setYAxisName("Länge in m"); // Render diagram MasterRenderer renderer = new MasterRenderer(indexV4Printer, a4Format); diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/Configurable.java b/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/Configurable.java index 0ccdce80a6590f1f714493b43343def94c475c1b..f453b4a19b766cc303e37c5bc97f94a23fa4e93a 100644 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/Configurable.java +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/Configurable.java @@ -62,7 +62,7 @@ abstract class Configurable { * Set the default/fallback {@link Configurable} that will be used if a property cannot be found. * @param fallback A {@link Configurable} object. */ - protected final void setFallback(final Configurable fallback) { + public final void setFallback(final Configurable fallback) { mFallback = fallback; } diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/JavaPropertiesConfigurationValidator.java b/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/JavaPropertiesConfigurationValidator.java index 608b86569f064a18f136f8e7562de71de6ba8c03..d8f5ecf10e7545674f1403b41e6fb4d1c1f3979d 100644 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/JavaPropertiesConfigurationValidator.java +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/configparser/JavaPropertiesConfigurationValidator.java @@ -16,7 +16,7 @@ import java.util.regex.Pattern; /** * Concrete validator for properties parsed from configuration files in Java Property File format. * @author Leonard Kupper, Andrey Ruzhanskiy - * @version 2019.07.30 + * @version 2019-09-13 */ public final class JavaPropertiesConfigurationValidator implements ConfigurationValidator { @@ -45,6 +45,7 @@ public final class JavaPropertiesConfigurationValidator implements Configuration Map<String, Predicate<String>> p = new HashMap<>(); definePrinterProperty("name", requireNotEmpty); definePrinterProperty("mode", requireNotEmpty); + definePrinterProperty("brailletable", requireNotEmpty, false); // checked in interpretation definePrinterProperty("semantictable", requireNotEmpty, false); // before predicate validation definePrinterProperty("floatingDot.support", requireBoolean); definePrinterProperty("floatingDot.resolution", requireDouble.and(requirePositive), false); @@ -84,11 +85,13 @@ public final class JavaPropertiesConfigurationValidator implements Configuration private String interpretProperty(final String propertyName, final String value) throws ConfigurationValidationException { try { switch (propertyName) { - case "semantictable": return new GeneralResource(value, mSearchPath).getResourcePath(); + case "brailletable": + case "semantictable": + return new GeneralResource(value, mSearchPath).getResourcePath(); default: return value; } } catch (Exception e) { - throw new ConfigurationValidationException("Problem while interpreting property.", e); + throw new ConfigurationValidationException("Problem while interpreting property: " + propertyName + "=" + value, e); } } diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/BarChart.java b/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/BarChart.java index ee769a1b808fca4bdc28854241eb865fbc7d40dc..3d138a9a71252a8789b2fee922d9760e4dde337e 100644 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/BarChart.java +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/BarChart.java @@ -4,7 +4,6 @@ import de.tudresden.inf.mci.brailleplot.datacontainers.Named; import de.tudresden.inf.mci.brailleplot.datacontainers.PointContainer; import de.tudresden.inf.mci.brailleplot.datacontainers.PointList; import de.tudresden.inf.mci.brailleplot.datacontainers.PointListContainer; -import de.tudresden.inf.mci.brailleplot.rendering.Renderable; import java.util.List; import java.util.Objects; @@ -15,7 +14,7 @@ import java.util.stream.Collectors; * @author Richard Schmidt, Georg Graßnick * @version 2019.09.02 */ -public class BarChart implements Renderable { +public class BarChart extends Diagram { private PointListContainer<PointList> mData; public BarChart(final PointListContainer<PointList> data) { diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/Diagram.java b/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/Diagram.java new file mode 100644 index 0000000000000000000000000000000000000000..6d62f713699a2a9067fb9517ac3169d889cace84 --- /dev/null +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/Diagram.java @@ -0,0 +1,95 @@ +package de.tudresden.inf.mci.brailleplot.diagrams; + +import de.tudresden.inf.mci.brailleplot.rendering.Renderable; + +import java.util.Objects; + +/** + * General representation of both scatter and line plots with basic data functions. Classes LinePlot and ScatterPlot extend this class. + * Implements Renderable. + * + * @author Richard Schmidt, Leonard Kupper + * @version 2019-09-12 + */ +public class Diagram implements Renderable { + + private String mTitle; + private String mXAxisName; + private String mYAxisName; + + public final String getTitle() { + return mTitle; + } + + public final void setTitle(final String title) { + this.mTitle = Objects.requireNonNull(title); + } + + public final String getXAxisName() { + return mXAxisName; + } + + public final void setXAxisName(final String xAxisName) { + this.mXAxisName = Objects.requireNonNull(xAxisName); + } + + public final String getYAxisName() { + return mYAxisName; + } + + public final void setYAxisName(final String yAxisName) { + this.mYAxisName = Objects.requireNonNull(yAxisName); + } + +// public PointListList mP; +// +// /** +// * Getter for the minimum x-value. +// * @return double minimum x-value +// */ +// public double getMinX() { +// return mP.getMinX(); +// } +// +// /** +// * Getter for the maximum x-value. +// * @return double maximum x-value +// */ +// public double getMaxX() { +// return mP.getMaxX(); +// } +// +// /** +// * Getter for the minimum y-value. +// * @return double minimum y-value +// */ +// public double getMinY() { +// return mP.getMinY(); +// } +// +// /** +// * Getter for the maximum y-value. +// * @return double maximum y-value +// */ +// public double getMaxY() { +// return mP.getMaxY(); +// } +// +// /** +// * Getter for a data set by index. +// * @param index int +// * @return PointList with the corresponding data set +// */ +// public PointListList.PointList getDataSet(final int index) { +// return (PointListList.PointList) mP.get(index); +// } +// +// /** +// * Getter for the name of a data set by index. +// * @param index int +// * @return name of the data set as a string +// */ +// public String getDataSetName(final int index) { +// return mP.get(index).getName(); +// } +} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/Diagram.java.txt b/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/Diagram.java.txt deleted file mode 100644 index 458955c5b0d3a937970cb2c9bf3a020eca921b71..0000000000000000000000000000000000000000 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/diagrams/Diagram.java.txt +++ /dev/null @@ -1,64 +0,0 @@ -package de.tudresden.inf.mci.brailleplot.diagrams; - -import de.tudresden.inf.mci.brailleplot.datacontainers.PointListList; -import de.tudresden.inf.mci.brailleplot.rendering.Renderable; - -/** - * General representation of both scatter and line plots with basic data functions. Classes LinePlot and ScatterPlot extend this class. - * Implements Renderable. - * - * @author Richard Schmidt - */ -public class Diagram implements Renderable { - public PointListList mP; - - /** - * Getter for the minimum x-value. - * @return double minimum x-value - */ - public double getMinX() { - return mP.getMinX(); - } - - /** - * Getter for the maximum x-value. - * @return double maximum x-value - */ - public double getMaxX() { - return mP.getMaxX(); - } - - /** - * Getter for the minimum y-value. - * @return double minimum y-value - */ - public double getMinY() { - return mP.getMinY(); - } - - /** - * Getter for the maximum y-value. - * @return double maximum y-value - */ - public double getMaxY() { - return mP.getMaxY(); - } - - /** - * Getter for a data set by index. - * @param index int - * @return PointList with the corresponding data set - */ - public PointListList.PointList getDataSet(final int index) { - return (PointListList.PointList) mP.get(index); - } - - /** - * Getter for the name of a data set by index. - * @param index int - * @return name of the data set as a string - */ - public String getDataSetName(final int index) { - return mP.get(index).getName(); - } -} diff --git a/src/main/java/de/tudresden/inf/mci/brailleplot/rendering/BarChartRasterizer.java b/src/main/java/de/tudresden/inf/mci/brailleplot/rendering/BarChartRasterizer.java index 1e62e0db980fb000013b589338d4d8dfd99e00ed..14477e74a6da68027a1f90e91957163bb39f60f0 100644 --- a/src/main/java/de/tudresden/inf/mci/brailleplot/rendering/BarChartRasterizer.java +++ b/src/main/java/de/tudresden/inf/mci/brailleplot/rendering/BarChartRasterizer.java @@ -133,13 +133,13 @@ public class BarChartRasterizer implements Rasterizer<CategoricalBarChart> { // PHASE 1 - LAYOUT: The following calculations will divide the canvas area to create the basic chart layout. // Diagram Title - String title = "Arbeitslosenzahl in Deutschland"; // TODO: get title from diagram + String title = diagram.getTitle(); int titleLength = mTextRasterizer.getBrailleStringLength(title); int titleHeight = (int) Math.ceil(titleLength / referenceCellArea.getWidth()); if (titleHeight > mMaximumTitleHeightCells) { throw new InsufficientRenderingAreaException("Title is too long. (Exceeds maximum height)"); } - Rectangle titleDotArea = canvas.toDotRectangle(referenceCellArea.removeFromTop(titleHeight)); // TODO: BrailleTextRasterizer will take cell rectangle later + Rectangle titleDotArea = canvas.toDotRectangle(referenceCellArea.removeFromTop(titleHeight)); // Y-Axis Name referenceCellArea.removeFromTop(mTitlePaddingCells); Rectangle yAxisNameDotArea = canvas.toDotRectangle(referenceCellArea.removeFromTop(1)); @@ -178,35 +178,37 @@ public class BarChartRasterizer implements Rasterizer<CategoricalBarChart> { // Bar Groups (Categories) int amountOfGroups = diagram.getDataSet().getSize(); // Count the total amount of groups int amountOfBars = countTotalBarAmount(diagram); // and bars - if (amountOfGroups == amountOfBars) { // If each group only contains a single bar - mGroupPaddingCells = mBarPaddingCells; // this is done because there are no 'real' groups. - } - int availableSizeCells = mFullChartCellArea.intWrapper().getHeight(); - int baseSizeCells = baseSize(amountOfGroups, mGroupPaddingCells, amountOfBars, mBarPaddingCells); - mBarThickness = Math.min((int) floor((availableSizeCells - baseSizeCells) / amountOfBars), mMaxBarThicknessCells); - if (mBarThickness < mMinBarThicknessCells) { - throw new InsufficientRenderingAreaException("Not enough space to rasterize all bar groups."); + if (amountOfBars >= 1) { + if (amountOfGroups == amountOfBars) { // If each group only contains a single bar + mGroupPaddingCells = mBarPaddingCells; // this is done because there are no 'real' groups. + } + int availableSizeCells = mFullChartCellArea.intWrapper().getHeight(); + int baseSizeCells = baseSize(amountOfGroups, mGroupPaddingCells, amountOfBars, mBarPaddingCells); + mBarThickness = Math.min((int) floor((availableSizeCells - baseSizeCells) / amountOfBars), mMaxBarThicknessCells); + if (mBarThickness < mMinBarThicknessCells) { + throw new InsufficientRenderingAreaException("Not enough space to rasterize all bar groups."); + } + // Remove space from top which is not needed + int requiredSizeCells = baseSizeCells + amountOfBars * mBarThickness; + mFullChartCellArea.removeFromTop(mFullChartCellArea.intWrapper().getHeight() - requiredSizeCells); } - // Remove space from top which is not needed - int requiredSizeCells = baseSizeCells + amountOfBars * mBarThickness; - mFullChartCellArea.removeFromTop(mFullChartCellArea.intWrapper().getHeight() - requiredSizeCells); // PHASE 2 - RASTERIZING: Now, every element of the chart will be drawn onto the according area. // Diagram Title - mTextRasterizer.rasterize(new BrailleText(title, titleDotArea), canvas); // TODO: use title variable + mTextRasterizer.rasterize(new BrailleText(title, titleDotArea), canvas); // Y-Axis: no units, no tickmarks Axis yAxis = new Axis(Axis.Type.Y_AXIS, originXDotCoordinate, originYDotCoordinate, 1, 0); yAxis.setBoundary(yAxisDotArea); mAxisRasterizer.rasterize(yAxis, canvas); // Y-Axis name - mTextRasterizer.rasterize(new BrailleText("Y-Achse Beschriftung", yAxisNameDotArea), canvas); // TODO: use axis name variable + mTextRasterizer.rasterize(new BrailleText(diagram.getYAxisName(), yAxisNameDotArea), canvas); // X-Axis: units and labels Axis xAxis = new Axis(Axis.Type.X_AXIS, originXDotCoordinate, originYDotCoordinate, X_AXIS_UNIT_SIZE_DOTS, X_AXIS_TICK_SIZE_DOTS); xAxis.setBoundary(xAxisDotArea); xAxis.setLabels(generateNumericAxisLabels(xAxisScaling, xAxisScalingMagnitude, negativeAvailableUnits, positiveAvailableUnits)); mAxisRasterizer.rasterize(xAxis, canvas); // X-Axis name - mTextRasterizer.rasterize(new BrailleText("Ich bin die X-Achse", xAxisNameDotArea), canvas); // TODO: use axis name variable + mTextRasterizer.rasterize(new BrailleText(diagram.getXAxisName(), xAxisNameDotArea), canvas); // The actual groups and bars: // This is done by iterating through the diagram data set and drawing borders with the respective padding based on whether switched // from one bar to another or a group to another. In between, the bars are rasterized as textured areas, with a line on the bars top. @@ -258,7 +260,7 @@ public class BarChartRasterizer implements Rasterizer<CategoricalBarChart> { // PHASE 3 - DIAGRAM LEGEND: Symbols and textures are explained in the legend which will be created by the LegendRasterizer Legend diagramLegend = new Legend(title); // Create a legend container - diagramLegend.addSymbolExplanation("Achsenskalierung:", "X-Achse", "Größenordung " + xAxisScalingMagnitude); // Explain axis scaling + diagramLegend.addSymbolExplanation("Achsenskalierung:", "X-Achse", "Faktor " + xAxisScalingMagnitude); // Explain axis scaling diagramLegend.addSymbolExplanationGroup("Kategorien:", groupNameExplanations); // Explain bar group single character captions if (textureExplanations.size() > 1) { // Explain textures (if multiple of them were used) diagramLegend.addTextureExplanationGroup("Reihen:", textureExplanations); @@ -355,9 +357,6 @@ public class BarChartRasterizer implements Rasterizer<CategoricalBarChart> { } amountOfBars += barsInGroup; } - if (amountOfBars < 1) { - throw new IllegalArgumentException("The given diagram does not contain any data."); - } return amountOfBars; } diff --git a/src/main/resources/config/default.properties b/src/main/resources/config/default.properties index f9ca64698f0d5b99df1770985c1f80b5e2ae7ca7..32f0a0860e06d648f2fe8c21ced38d61494b27c3 100644 --- a/src/main/resources/config/default.properties +++ b/src/main/resources/config/default.properties @@ -1,7 +1,7 @@ # JProperties Printer & Format Configuration # # Embosser: Default -# Version 1 Rev. 3 (19-09-11) +# Version 1 Rev. 5 (19-09-13) # # Description: # This is the default configuration file for the braille plot application. @@ -14,9 +14,11 @@ # are not overriding the defaults. printer.mode=normalprinter -#printer.brailletable=../mapping/eurobraille.properties printer.floatingDot.support=false +# Semantic Table: LibLouis String -> 6-Dot printer.semantictable=../mapping/kurzschrift_DE.properties +# Braille (Output Encoding) Table: 6-Dot -> Octet-Stream +printer.brailletable=../mapping/eurobraille.properties # The following values represent the fixed indentation and maximum technical printing area of the embosser. # If the outputs don't fit on the page you might want to tweak this values. (Check the format too.) @@ -47,9 +49,9 @@ printer.raster.dotDiameter=1.5 # Default Format Definition (assume A4 portrait) format.default.page.width=210 format.default.page.height=297 -format.default.margin.top=10 -format.default.margin.left=10 -format.default.margin.bottom=10 -format.default.margin.right=10 +format.default.margin.top=0 +format.default.margin.left=0 +format.default.margin.bottom=0 +format.default.margin.right=0 # This is a template. Do not define concrete formats in this file. Use the specific user config file for this purpose. \ No newline at end of file