diff --git a/README.md b/README.md index 4edb30ec0..89da2efd6 100644 --- a/README.md +++ b/README.md @@ -20,21 +20,13 @@ double[] yData = new double[]{2.0, 1.0, 0.0}; XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", xData, yData); // Show it -new - -SwingWrapper(chart). - -displayChart(); +new SwingWrapper(chart).displayChart(); // Save it -BitmapEncoder. - -saveBitmap(chart, "./Sample_Chart",BitmapFormat.PNG); +BitmapEncoder.saveBitmap(chart, "./Sample_Chart",BitmapFormat.PNG); // or save it in high-res -BitmapEncoder. - -saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI",BitmapFormat.PNG, 300); +BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI",BitmapFormat.PNG, 300); ``` ![](https://raw.githubusercontent.com/knowm/XChart/develop/etc/XChart_Simplest.png) @@ -49,41 +41,17 @@ Create a `XYChart` via a `XYChartBuilder`, style chart, add a series to it, styl XYChart chart = new XYChartBuilder().width(600).height(500).title("Gaussian Blobs").xAxisTitle("X").yAxisTitle("Y").build(); // Customize Chart -chart. - -getStyler(). - -setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter); -chart. - -getStyler(). - -setChartTitleVisible(false); -chart. - -getStyler(). - -setLegendPosition(LegendPosition.InsideSW); -chart. - -getStyler(). - -setMarkerSize(16); +chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter); +chart.getStyler().setChartTitleVisible(false); +chart.getStyler().setLegendPosition(LegendPosition.InsideSW); +chart.getStyler().setMarkerSize(16); // Series -chart. - -addSeries("Gaussian Blob 1",getGaussian(1000, 1,10),getGaussian(1000,1,10)); +chart.addSeries("Gaussian Blob 1",getGaussian(1000, 1,10),getGaussian(1000,1,10)); XYSeries series = chart.addSeries("Gaussian Blob 2", getGaussian(1000, 1, 10), getGaussian(1000, 0, 5)); -series. +series.setMarker(SeriesMarkers.DIAMOND); -setMarker(SeriesMarkers.DIAMOND); - -new - -SwingWrapper(chart). - -displayChart(); +new SwingWrapper(chart).displayChart(); ``` ![](https://raw.githubusercontent.com/knowm/XChart/develop/etc/XChart_Intermediate.png) @@ -98,33 +66,13 @@ Create a `XYChart` via a `XYChartBuilder`, style chart, add a series to it, add final XYChart chart = new XYChartBuilder().width(600).height(400).title("Area Chart").xAxisTitle("X").yAxisTitle("Y").build(); // Customize Chart -chart. - -getStyler(). - -setLegendPosition(LegendPosition.InsideNE); -chart. - -getStyler(). - -setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area); +chart.getStyler().setLegendPosition(LegendPosition.InsideNE); +chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area); // Series -chart. - -addSeries("a",new double[] { - 0, 3, 5, 7, 9 -},new double[]{-3,5,9,6,5}); - chart. - -addSeries("b",new double[] { - 0, 2, 4, 6, 9 -},new double[]{-1,6,4,0,4}); - chart. - -addSeries("c",new double[] { - 0, 1, 3, 8, 9 -},new double[]{-2,-1,1,0,1}); +chart.addSeries("a",new double[] { 0, 3, 5, 7, 9},new double[]{-3,5,9,6,5}); +chart.addSeries("b",new double[] { 0, 2, 4, 6, 9},new double[]{-1,6,4,0,4}); +chart.addSeries("c",new double[] { 0, 1, 3, 8, 9},new double[]{-2,-1,1,0,1}); // Schedule a job for the event-dispatching thread: // creating and showing this application's GUI. @@ -287,24 +235,12 @@ BoxChart chart = new BoxChartBuilder().title("box plot demo").build(); // Choose a calculation method -chart. - -getStyler(). - -setBoxplotCalCulationMethod(BoxplotCalCulationMethod.N_LESS_1_PLUS_1); -chart. - -getStyler(). - -setToolTipsEnabled(true); +chart.getStyler().setBoxplotCalCulationMethod(BoxplotCalCulationMethod.N_LESS_1_PLUS_1); +chart.getStyler().setToolTipsEnabled(true); // Series -chart. - -addSeries("boxOne",Arrays.asList(1,2,3,4)); - new SwingWrapper(chart). - -displayChart(); +chart.addSeries("boxOne",Arrays.asList(1,2,3,4)); +new SwingWrapper(chart).displayChart(); ``` Four calculation methods for boxplots: @@ -429,19 +365,9 @@ Default axis tick placement can be altered with `chart.getStyler().setXAxisTickM Default axis label labels can be altered with one of: ```java -chart.getStyler(). - -setDatePattern(datePattern) -chart. - -getStyler(). - -setXAxisDecimalPattern(pattern); -chart. - -getStyler(). - -setYAxisDecimalPattern(pattern); +chart.getStyler().setDatePattern(datePattern) +chart.getStyler().setXAxisDecimalPattern(pattern); +chart.getStyler().setYAxisDecimalPattern(pattern); ``` You can also create custom axis tick labels with a callback function. In the following example taken @@ -452,15 +378,7 @@ via a custom lambda function which takes the numerical (double) tick label value // set custom X-Axis tick labels LocalDateTime startTime = LocalDateTime.of(2001, Month.JANUARY, 1, 0, 0, 0); DateTimeFormatter xTickFormatter = DateTimeFormatter.ofPattern("LLL"); -chart. - -getStyler(). - -setxAxisTickLabelsFormattingFunction(x ->startTime. - -plusDays(x.longValue()). - -format(xTickFormatter)); +chart.getStyler().setxAxisTickLabelsFormattingFunction(x ->startTime.plusDays(x.longValue()).format(xTickFormatter)); ``` In the following example taken from [DateChart06](https://github.com/knowm/XChart/blob/develop/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart06.java), the @@ -468,11 +386,7 @@ Y-Axis tick labels are converted to the englich word reprentation of the numbers. ```java -chart.getStyler(). - -setyAxisTickLabelsFormattingFunction(x ->NumberWordConverter. - -convert(x.intValue())); +chart.getStyler().setyAxisTickLabelsFormattingFunction(x ->NumberWordConverter.convert(x.intValue())); ``` ### Multiple Axes @@ -488,28 +402,20 @@ series.setYAxisGroup(axisGroup); To manually change max/min of axis group: ```java -((AxesChartStyler)chart. - -getStyler()). - -setYAxisMax(axisGroup, 200.0); +((AxesChartStyler)chart.getStyler()).setYAxisMax(axisGroup, 200.0); ``` Axis can be drawn on the left (default) or on the right of the chart: ```java -chart.getStyler(). - -setYAxisGroupPosition(axisGroup, Styler.YAxisPosition.Right); +chart.getStyler().setYAxisGroupPosition(axisGroup, Styler.YAxisPosition.Right); ``` To set the Y axes titles: ```java chart.setYAxisGroupTitle(0,"A"); -chart. - -setYAxisGroupTitle(1,"B"); +chart.setYAxisGroupTitle(1,"B"); ``` ### Zooming In @@ -522,29 +428,11 @@ double-clicking on the chart or by clicking on the "reset" button, which can be The following example zoom style options show which are available: ```java -chart.getStyler(). - -setZoomEnabled(true); -chart. - -getStyler(). - -setZoomResetButtomPosition(Styler.CardinalPosition.InsideS); -chart. - -getStyler(). - -setZoomResetByDoubleClick(false); -chart. - -getStyler(). - -setZoomResetByButton(true); -chart. - -getStyler(). - -setZoomSelectionColor(new Color(0,0,192,128)); +chart.getStyler().setZoomEnabled(true); +chart.getStyler().setZoomResetButtomPosition(Styler.CardinalPosition.InsideS); +chart.getStyler().setZoomResetByDoubleClick(false); +chart.getStyler().setZoomResetByButton(true); +chart.getStyler().setZoomSelectionColor(new Color(0,0,192,128)); ``` A working example can be found at [DateChart01](https://github.com/knowm/XChart/blob/develop/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/date/DateChart01.java). @@ -567,24 +455,10 @@ Positioning is relative to the bottom-left corner of the chart and to the center The following example `AnnotationLine` and `AnnotationText` styling parameters show which are available: ```java -chart.getStyler(). - -setAnnotationLineColor(Color.GREEN); -chart. - -getStyler(). - -setAnnotationLineStroke(new BasicStroke(3.0f)); - chart. - -getStyler(). - -setAnnotationTextFont(new Font(Font.MONOSPACED, Font.ITALIC, 8)); - chart. - -getStyler(). - -setAnnotationTextFontColor(Color.BLUE); +chart.getStyler().setAnnotationLineColor(Color.GREEN); +chart.getStyler().setAnnotationLineStroke(new BasicStroke(3.0f)); +chart.getStyler().setAnnotationTextFont(new Font(Font.MONOSPACED, Font.ITALIC, 8)); +chart.getStyler().setAnnotationTextFontColor(Color.BLUE); ``` A working example can be found at [LineChart10](https://github.com/knowm/XChart/blob/develop/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart10.java). @@ -598,29 +472,11 @@ Positioning is relative to the bottom-left corner of the chart and to the bottom The following example `AnnotationTextPanel` styling parameters show which are available: ```java -chart.getStyler(). - -setAnnotationTextPanelPadding(20); -chart. - -getStyler(). - -setAnnotationTextPanelFont(new Font("Verdana", Font.BOLD, 12)); - chart. - -getStyler(). - -setAnnotationTextPanelBackgroundColor(Color.RED); -chart. - -getStyler(). - -setAnnotationTextPanelBorderColor(Color.BLUE); -chart. - -getStyler(). - -setAnnotationTextPanelFontColor(Color.GREEN); +chart.getStyler().setAnnotationTextPanelPadding(20); +chart.getStyler().setAnnotationTextPanelFont(new Font("Verdana", Font.BOLD, 12)); +chart.getStyler().setAnnotationTextPanelBackgroundColor(Color.RED); +chart.getStyler().setAnnotationTextPanelBorderColor(Color.BLUE); +chart.getStyler().setAnnotationTextPanelFontColor(Color.GREEN); ``` A working example can be found at [ScatterChart04](https://github.com/knowm/XChart/blob/develop/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/scatter/ScatterChart04.java). @@ -630,9 +486,7 @@ A working example can be found at [ScatterChart04](https://github.com/knowm/XCha For all chart types, tool tips can be activated on an `XChartPanel` via ```java -chart.getStyler(). - -setToolTipsEnabled(true); +chart.getStyler().setToolTipsEnabled(true); ``` ![](https://raw.githubusercontent.com/knowm/XChart/develop/etc/XChart_Tooltips.png) @@ -640,39 +494,13 @@ setToolTipsEnabled(true); The following example tooltip options show which are available: ```java -chart.getStyler(). - -setToolTipsEnabled(true); -chart. - -getStyler(). - -setToolTipsAlwaysVisible(true); -chart. - -getStyler(). - -setToolTipFont( new Font("Verdana", Font.BOLD, 12)); - chart. - -getStyler(). - -setToolTipHighlightColor(Color.CYAN); -chart. - -getStyler(). - -setToolTipBorderColor(Color.BLACK); -chart. - -getStyler(). - -setToolTipBackgroundColor(Color.LIGHT_GRAY); -chart. - -getStyler(). - -setToolTipType(Styler.ToolTipType.xAndYLabels); +chart.getStyler().setToolTipsEnabled(true); +chart.getStyler().setToolTipsAlwaysVisible(true); +chart.getStyler().setToolTipFont( new Font("Verdana", Font.BOLD, 12)); +chart.getStyler().setToolTipHighlightColor(Color.CYAN); +chart.getStyler().setToolTipBorderColor(Color.BLACK); +chart.getStyler().setToolTipBackgroundColor(Color.LIGHT_GRAY); +chart.getStyler().setToolTipType(Styler.ToolTipType.xAndYLabels); ``` A working example can be found at [LineChart05](https://github.com/knowm/XChart/blob/develop/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart05.java). @@ -682,9 +510,7 @@ A working example can be found at [LineChart05](https://github.com/knowm/XChart/ For the `XYChart` chart type, it is possible to add an interactive cursor on an `XChartPanel` via ```java -chart.getStyler(). - -setCursorEnabled(true); +chart.getStyler().setCursorEnabled(true); ``` ![](https://raw.githubusercontent.com/knowm/XChart/develop/etc/XChart_Cursor.png) @@ -692,44 +518,14 @@ setCursorEnabled(true); The following example cursor options show which are available: ```java -chart.getStyler(). - -setCursorEnabled(true); -chart. - -getStyler(). - -setCursorColor(Color.GREEN); -chart. - -getStyler(). - -setCursorLineWidth(30f); -chart. - -getStyler(). - -setCursorFont(new Font("Verdana", Font.BOLD, 12)); - chart. - -getStyler(). - -setCursorFontColor(Color.ORANGE); -chart. - -getStyler(). - -setCursorBackgroundColor(Color.BLUE); -chart. - -getStyler(). - -setCustomCursorXDataFormattingFunction(x ->"hello xvalue: "+x); - chart. - -getStyler(). - -setCustomCursorYDataFormattingFunction(y ->"hello yvalue divided by 2: "+y /2); +chart.getStyler().setCursorEnabled(true); +chart.getStyler().setCursorColor(Color.GREEN); +chart.getStyler().setCursorLineWidth(30f); +chart.getStyler().setCursorFont(new Font("Verdana", Font.BOLD, 12)); +chart.getStyler().setCursorFontColor(Color.ORANGE); +chart.getStyler().setCursorBackgroundColor(Color.BLUE); +chart.getStyler().setCustomCursorXDataFormattingFunction(x ->"hello xvalue: "+x); +chart.getStyler().setCustomCursorYDataFormattingFunction(y ->"hello yvalue divided by 2: "+y /2); ``` A working example can be found at [LineChart09](https://github.com/knowm/XChart/blob/develop/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart09.java). @@ -774,9 +570,15 @@ For snapshots, add the following to your pom.xml file: ```xml - sonatype-oss-snapshot - - https://oss.sonatype.org/content/repositories/snapshots + Central Portal Snapshots + central-portal-snapshots + https://central.sonatype.com/repository/maven-snapshots/ + + false + + + true + @@ -786,9 +588,6 @@ For snapshots, add the following to your pom.xml file: ``` -Snapshots can be manually downloaded from -Sonatype: [https://oss.sonatype.org/content/groups/public/org/knowm/xchart/xchart/](https://oss.sonatype.org/content/groups/public/org/knowm/xchart/xchart/) - ### SBT To use XChart with the Scala Build Tool (SBT) add the following to your build.sbt diff --git a/etc/settings.xml b/etc/settings.xml index 6e86c155f..ca2f823d6 100644 --- a/etc/settings.xml +++ b/etc/settings.xml @@ -9,7 +9,7 @@ - sonatype-nexus-snapshots + central ${env.CI_DEPLOY_USERNAME} ${env.CI_DEPLOY_PASSWORD} diff --git a/pom.xml b/pom.xml index 2177cfbec..47e371067 100644 --- a/pom.xml +++ b/pom.xml @@ -55,20 +55,6 @@ xchart-demo - - - sonatype-nexus-snapshots - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - sonatype-nexus-staging - Nexus Release Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - https://oss.sonatype.org/content/groups/public/org/knowm/xchart - - @@ -80,7 +66,7 @@ de.rototor.pdfbox graphics2d - 3.0.1 + 3.0.2 true @@ -108,7 +94,7 @@ org.assertj assertj-core - 3.25.3 + 3.26.0 test @@ -127,7 +113,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.2.4 + 3.2.8 sign-artifacts @@ -170,7 +156,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.5 + 3.5.0 @@ -203,7 +189,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.3 + 3.10.0 none org.knowm.xchart.internal.* @@ -233,7 +219,7 @@ com.spotify.fmt fmt-maven-plugin - 2.23 + 2.24 .*\.java false @@ -247,14 +233,13 @@ - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.13 + org.sonatype.central + central-publishing-maven-plugin + 0.9.0 true - ossrh - https://oss.sonatype.org/ - true + central + true diff --git a/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java b/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java index f100ac279..0e958b45d 100644 --- a/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java +++ b/xchart/src/main/java/org/knowm/xchart/BitmapEncoder.java @@ -39,13 +39,16 @@ private BitmapEncoder() {} */ public static String addFileExtension(String fileName, BitmapFormat bitmapFormat) { - String fileNameWithFileExtension = fileName; final String newFileExtension = "." + bitmapFormat.toString().toLowerCase(); - if (fileName.length() <= newFileExtension.length() + final String fileNameWithFileExtension; + if (fileName.length() < newFileExtension.length() || !fileName - .substring(fileName.length() - newFileExtension.length(), fileName.length()) + .substring(fileName.length() - newFileExtension.length()) .equalsIgnoreCase(newFileExtension)) { fileNameWithFileExtension = fileName + newFileExtension; + } else { + // This is to ensure the lower-case for the extension + fileNameWithFileExtension = fileName.substring(0, fileName.length() - newFileExtension.length()) + newFileExtension; } return fileNameWithFileExtension; } diff --git a/xchart/src/test/java/org/knowm/xchart/BitmapEncoderTest.java b/xchart/src/test/java/org/knowm/xchart/BitmapEncoderTest.java new file mode 100644 index 000000000..68d74f216 --- /dev/null +++ b/xchart/src/test/java/org/knowm/xchart/BitmapEncoderTest.java @@ -0,0 +1,26 @@ +package org.knowm.xchart; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +public class BitmapEncoderTest { + + @Test + public void testAddFileExtension() { + String fileName1 = "image"; + String fileName2 = "image.png"; + String fileName3 = "image.PNG"; + + for (String s : Arrays.asList(fileName1, fileName2, fileName3)) { + assertEquals("image.png", BitmapEncoder.addFileExtension(s, BitmapEncoder.BitmapFormat.PNG)); + } + assertEquals("z.bmp", BitmapEncoder.addFileExtension("z", BitmapEncoder.BitmapFormat.BMP)); + assertEquals("asdf.bmp", BitmapEncoder.addFileExtension("asdf", BitmapEncoder.BitmapFormat.BMP)); + assertEquals(".bmp", BitmapEncoder.addFileExtension(".bmp", BitmapEncoder.BitmapFormat.BMP)); + assertEquals(".bmp", BitmapEncoder.addFileExtension(".BmP", BitmapEncoder.BitmapFormat.BMP)); + } +}