diff --git a/xchart/src/main/java/com/xeiam/xchart/CSVExporter.java b/xchart/src/main/java/com/xeiam/xchart/CSVExporter.java index d20b030a679ae534c69dc2ae6b10c2b1e304dfe7..3a77bf196eb797af051d0be99b842d086a0f1a82 100644 --- a/xchart/src/main/java/com/xeiam/xchart/CSVExporter.java +++ b/xchart/src/main/java/com/xeiam/xchart/CSVExporter.java @@ -46,7 +46,6 @@ public class CSVExporter { } } } - } public static void writeCSVColumns(Series series, String path2Dir) { diff --git a/xchart/src/main/java/com/xeiam/xchart/CSVImporter.java b/xchart/src/main/java/com/xeiam/xchart/CSVImporter.java index 774afe552838632e503654a84ee69322c4330637..9c02ad6ab481effdf51e109e4ebe094074cc06b0 100644 --- a/xchart/src/main/java/com/xeiam/xchart/CSVImporter.java +++ b/xchart/src/main/java/com/xeiam/xchart/CSVImporter.java @@ -29,6 +29,8 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import com.xeiam.xchart.StyleManager.ChartTheme; + /** * This class is used to create a Chart object from a folder containing one or more CSV files. The parent folder's name becomes the title of the chart. Each CSV file in the folder becomes a series on * the chart. the CSV file's name becomes the series' name. @@ -44,15 +46,21 @@ public class CSVImporter { /** * @param path2Directory + * @param dataOrientation * @param width * @param height + * @param chartTheme * @return */ - public static Chart getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height) { + public static Chart getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height, ChartTheme chartTheme) { // 1. get the directory, name chart the dir name - - Chart chart = new Chart(width, height); + Chart chart = null; + if (chartTheme != null) { + chart = new Chart(width, height, chartTheme); + } else { + chart = new Chart(width, height); + } // 2. get all the csv files in the dir File[] csvFiles = getAllFiles(path2Directory, ".*.csv"); @@ -72,6 +80,18 @@ public class CSVImporter { return chart; } + /** + * @param path2Directory + * @param dataOrientation + * @param width + * @param height + * @return + */ + public static Chart getChartFromCSVDir(String path2Directory, DataOrientation dataOrientation, int width, int height) { + + return getChartFromCSVDir(path2Directory, dataOrientation, width, height, null); + } + private static String[] getSeriesDataFromCSVRows(File csvFile) { String[] xAndYData = new String[2]; diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index b855d62425a3123b4b8c53ca70128766efb126b8..683efe5ee85231eb42eadb17ba00e76aabaaaeed 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -21,8 +21,12 @@ import java.util.Collection; import java.util.Date; import java.util.Map; +import com.xeiam.xchart.StyleManager.ChartTheme; import com.xeiam.xchart.internal.chartpart.ChartPainter; +import com.xeiam.xchart.internal.style.GGPlot2Theme; +import com.xeiam.xchart.internal.style.MatlabTheme; import com.xeiam.xchart.internal.style.Theme; +import com.xeiam.xchart.internal.style.XChartTheme; /** * An XChart Chart @@ -42,6 +46,27 @@ public class Chart { public Chart(int width, int height) { chartPainter = new ChartPainter(width, height); + + } + + /** + * Constructor + * + * @param width + * @param height + * @param chartTheme + */ + public Chart(int width, int height, ChartTheme chartTheme) { + + chartPainter = new ChartPainter(width, height); + + if (chartTheme == ChartTheme.XChart) { + setTheme(new XChartTheme()); + } else if (chartTheme == ChartTheme.GGPlot2) { + setTheme(new GGPlot2Theme()); + } else if (chartTheme == ChartTheme.Matlab) { + setTheme(new MatlabTheme()); + } } /** @@ -51,8 +76,7 @@ public class Chart { */ public Chart(ChartBuilder chartBuilder) { - this(chartBuilder.width, chartBuilder.height); - getStyleManager().setChartTheme(chartBuilder.chartTheme); + this(chartBuilder.width, chartBuilder.height, chartBuilder.chartTheme); setChartTitle(chartBuilder.title); setXAxisTitle(chartBuilder.xAxisTitle); setYAxisTitle(chartBuilder.yAxisTitle); diff --git a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java index ba7ba7bf2e11ceec84e6cf1670e8f10ed8c04d80..4182fffa7bf2673d1fbf5f84651c4008a666dd6a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java @@ -27,8 +27,6 @@ import java.awt.Stroke; import java.util.Locale; import java.util.TimeZone; -import com.xeiam.xchart.internal.style.GGPlot2Theme; -import com.xeiam.xchart.internal.style.MatlabTheme; import com.xeiam.xchart.internal.style.Theme; import com.xeiam.xchart.internal.style.XChartTheme; @@ -201,28 +199,12 @@ public class StyleManager { * * @param theme */ - public void setTheme(Theme theme) { + protected void setTheme(Theme theme) { this.theme = theme; setAllStyles(); } - /** - * Set the ChartTheme the style manager should use - * - * @param theme - */ - public void setChartTheme(ChartTheme chartTheme) { - - if (chartTheme == ChartTheme.XChart) { - setTheme(new XChartTheme()); - } else if (chartTheme == ChartTheme.GGPlot2) { - setTheme(new GGPlot2Theme()); - } else if (chartTheme == ChartTheme.Matlab) { - setTheme(new MatlabTheme()); - } - } - public Theme getTheme() { return theme;