diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java index 3a45c734ce5440a8ea784115ffb4ece16f820dec..362def1feb75512f0a3200e2940d0b1336c9a265 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java @@ -33,6 +33,7 @@ import javax.swing.tree.TreeSelectionModel; import com.xeiam.xchart.XChartPanel; import com.xeiam.xchart.demo.charts.area.AreaChart01; import com.xeiam.xchart.demo.charts.area.AreaChart02; +import com.xeiam.xchart.demo.charts.area.AreaLineChart03; import com.xeiam.xchart.demo.charts.bar.BarChart01; import com.xeiam.xchart.demo.charts.bar.BarChart02; import com.xeiam.xchart.demo.charts.bar.BarChart03; @@ -47,7 +48,12 @@ import com.xeiam.xchart.demo.charts.date.DateChart04; import com.xeiam.xchart.demo.charts.date.DateChart05; import com.xeiam.xchart.demo.charts.date.DateChart06; import com.xeiam.xchart.demo.charts.date.DateChart07; -import com.xeiam.xchart.demo.charts.line.*; +import com.xeiam.xchart.demo.charts.line.LineChart01; +import com.xeiam.xchart.demo.charts.line.LineChart02; +import com.xeiam.xchart.demo.charts.line.LineChart03; +import com.xeiam.xchart.demo.charts.line.LineChart04; +import com.xeiam.xchart.demo.charts.line.LineChart05; +import com.xeiam.xchart.demo.charts.line.LineChart06; import com.xeiam.xchart.demo.charts.realtime.RealtimeChart01; import com.xeiam.xchart.demo.charts.realtime.RealtimeChart02; import com.xeiam.xchart.demo.charts.scatter.ScatterChart01; @@ -60,7 +66,7 @@ import com.xeiam.xchart.demo.charts.theme.ThemeChart03; /** * Class containing all XChart example charts - * + * * @author timmolter */ public class XChartDemo extends JPanel implements TreeSelectionListener { @@ -169,7 +175,7 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { /** * Create the tree - * + * * @param top */ private void createNodes(DefaultMutableTreeNode top) { @@ -189,6 +195,9 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("AreaChart02 - Null Y-Axis Data Points", new AreaChart02().getChart())); category.add(defaultMutableTreeNode); + defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("AreaLineChart03 - Combination Line & Area Chart", new AreaLineChart03().getChart())); + category.add(defaultMutableTreeNode); + // Line category category = new DefaultMutableTreeNode("Line Charts"); top.add(category); @@ -211,9 +220,6 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("LineChart06 - Logarithmic Y-Axis with Error Bars", new LineChart06().getChart())); category.add(defaultMutableTreeNode); - defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("LineAreaChart07 - Line & Area Chart", new LineAreaChart07().getChart())); - category.add(defaultMutableTreeNode); - // Scatter category category = new DefaultMutableTreeNode("Scatter Charts"); top.add(category); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java index a39f8e2d19ed9b0acb5a26b4101677428edfbf1f..4fb4b5f79b9c6dbe59e1569944f2d380667646dc 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart01.java @@ -44,7 +44,7 @@ public class AreaChart01 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("AreaChart01").xAxisTitle("X").yAxisTitle("Y").build(); + Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build(); 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 }); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart02.java index 262cdc4944a2309e83620173aa5233cf2cd050ea..a5a8274dd00bdf4b9c73b3efc9c4a08c4e8948c8 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaChart02.java @@ -47,7 +47,7 @@ public class AreaChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("AreaChart02").xAxisTitle("X").yAxisTitle("Y").build(); + Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build(); List<Integer> xData = new ArrayList<Integer>(); List<Integer> yData = new ArrayList<Integer>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineAreaChart07.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaLineChart03.java similarity index 90% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineAreaChart07.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaLineChart03.java index 39776b99809cdbf13cf3ffbc8cf9c640c748a993..3b8f85c41e883b6f33de572e4705a693ea5d0331 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineAreaChart07.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/area/AreaLineChart03.java @@ -13,14 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.demo.charts.line; +package com.xeiam.xchart.demo.charts.area; -import com.xeiam.xchart.*; +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.Series; +import com.xeiam.xchart.SeriesMarker; +import com.xeiam.xchart.StyleManager; +import com.xeiam.xchart.StyleManager.ChartType; import com.xeiam.xchart.StyleManager.LegendPosition; +import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; -import java.awt.*; - /** * Combination Line & Area Chart * <p/> @@ -30,11 +33,11 @@ import java.awt.*; * <li>Axis Label Alignment * <li>Ensuring a chart axis on a tick */ -public class LineAreaChart07 implements ExampleChart { +public class AreaLineChart03 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineAreaChart07(); + ExampleChart exampleChart = new AreaLineChart03(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -46,11 +49,13 @@ public class LineAreaChart07 implements ExampleChart { Chart chart = new Chart(800, 600); // Customize Chart - chart.setChartTitle("LineAreaChart07"); + chart.setChartTitle(getClass().getSimpleName()); chart.setXAxisTitle("Age"); chart.setYAxisTitle("Amount"); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); + chart.getStyleManager().setChartType(ChartType.Line); + // @formatter:off double[] xAges = new double[]{ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, @@ -231,6 +236,7 @@ public class LineAreaChart07 implements ExampleChart { 0, 0, 0}; + // @formatter:on Series seriesLiability = chart.addSeries("Liability", xAges, yLiability); seriesLiability.setMarker(SeriesMarker.NONE); @@ -246,7 +252,7 @@ public class LineAreaChart07 implements ExampleChart { seriesPercentile25th.setMarker(SeriesMarker.NONE); chart.getStyleManager().setYAxisLabelAlignment(StyleManager.TextAlignment.Right); - chart.getStyleManager().setDecimalPattern("$ #,###.##"); // TODO need a different patter for y and x axis + chart.getStyleManager().setYAxisDecimalPattern("$ #,###.##"); chart.getStyleManager().setPlotPadding(0); chart.getStyleManager().setAxisTickSpaceRatio(1); diff --git a/xchart/src/main/java/com/xeiam/xchart/Series.java b/xchart/src/main/java/com/xeiam/xchart/Series.java index 2599fef09df202afa3476db8619079fe229304ed..47e0b315985951871bb62c8310a76bc967a21a8a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Series.java +++ b/xchart/src/main/java/com/xeiam/xchart/Series.java @@ -252,10 +252,12 @@ public class Series { } public SeriesType getSeriesType() { + return seriesType; } public void setSeriesType(SeriesType seriesType) { + this.seriesType = seriesType; } @@ -315,10 +317,12 @@ public class Series { } public Color getFillColor() { + return fillColor; } public void setFillColor(Color fillColor) { + this.fillColor = fillColor; } diff --git a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java index e3743a9882c8e3aae85673007888a8e9e90dfaa0..66420c974bb3cd6e8268a5be303910c9f090be11 100644 --- a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java @@ -28,7 +28,7 @@ import com.xeiam.xchart.internal.style.XChartTheme; /** * The StyleManager is used to manage all things related to styling of the vast number of Chart components - * + * * @author timmolter */ public class StyleManager { @@ -67,9 +67,7 @@ public class StyleManager { } public enum TextAlignment { - Left, - Centre, - Right; + Left, Centre, Right; } /** the default Theme */ @@ -150,6 +148,8 @@ public class StyleManager { private TimeZone timezone; private String datePattern; private String decimalPattern; + private String xAxisDecimalPattern; + private String yAxisDecimalPattern; /** * Constructor @@ -235,11 +235,13 @@ public class StyleManager { timezone = TimeZone.getDefault(); datePattern = null; // if not null, this override pattern will be used decimalPattern = null; + xAxisDecimalPattern = null; + yAxisDecimalPattern = null; } /** * Set the theme the style manager should use - * + * * @param theme */ protected void setTheme(Theme theme) { @@ -257,7 +259,7 @@ public class StyleManager { /** * sets the Chart Type - * + * * @param chartType */ public void setChartType(ChartType chartType) { @@ -272,7 +274,7 @@ public class StyleManager { /** * Set the chart background color - the part around the edge of the chart - * + * * @param color */ public void setChartBackgroundColor(Color color) { @@ -287,7 +289,7 @@ public class StyleManager { /** * Set the chart font color. includes: Chart title, axes label, legend - * + * * @param color */ public void setChartFontColor(Color color) { @@ -302,7 +304,7 @@ public class StyleManager { /** * Set the chart padding - * + * * @param chartPadding */ public void setChartPadding(int chartPadding) { @@ -319,7 +321,7 @@ public class StyleManager { /** * Set the chart title font - * + * * @param font */ public void setChartTitleFont(Font chartTitleFont) { @@ -334,7 +336,7 @@ public class StyleManager { /** * Set the chart title visibility - * + * * @param isChartTitleVisible */ public void setChartTitleVisible(boolean isChartTitleVisible) { @@ -349,7 +351,7 @@ public class StyleManager { /** * Set the chart title box visibility - * + * * @param isChartTitleBoxVisible */ public void setChartTitleBoxVisible(boolean isChartTitleBoxVisible) { @@ -364,7 +366,7 @@ public class StyleManager { /** * set the chart title box background color - * + * * @param chartTitleBoxBackgroundColor */ public void setChartTitleBoxBackgroundColor(Color chartTitleBoxBackgroundColor) { @@ -379,7 +381,7 @@ public class StyleManager { /** * set the chart title box border color - * + * * @param chartTitleBoxBorderColor */ public void setChartTitleBoxBorderColor(Color chartTitleBoxBorderColor) { @@ -394,7 +396,7 @@ public class StyleManager { /** * set the chart title padding; the space between the chart title and the plot area - * + * * @param chartTitlePadding */ public void setChartTitlePadding(int chartTitlePadding) { @@ -411,7 +413,7 @@ public class StyleManager { /** * Set the chart legend background color - * + * * @param color */ public void setLegendBackgroundColor(Color color) { @@ -426,7 +428,7 @@ public class StyleManager { /** * Set the chart legend border color - * + * * @return */ public Color getLegendBorderColor() { @@ -441,7 +443,7 @@ public class StyleManager { /** * Set the chart legend font - * + * * @param font */ public void setLegendFont(Font font) { @@ -456,7 +458,7 @@ public class StyleManager { /** * Set the chart legend visibility - * + * * @param isLegendVisible */ public void setLegendVisible(boolean isLegendVisible) { @@ -471,7 +473,7 @@ public class StyleManager { /** * Set the chart legend padding - * + * * @param legendPadding */ public void setLegendPadding(int legendPadding) { @@ -486,7 +488,7 @@ public class StyleManager { /** * Set the chart legend series line length - * + * * @param legendPadding */ public void setLegendSeriesLineLength(int legendSeriesLineLength) { @@ -506,7 +508,7 @@ public class StyleManager { /** * sets the legend position - * + * * @param legendPosition */ public void setLegendPosition(LegendPosition legendPosition) { @@ -523,7 +525,7 @@ public class StyleManager { /** * Set the x-axis title visibility - * + * * @param isVisible */ public void setXAxisTitleVisible(boolean xAxisTitleVisible) { @@ -538,7 +540,7 @@ public class StyleManager { /** * Set the y-axis title visibility - * + * * @param isVisible */ public void setYAxisTitleVisible(boolean yAxisTitleVisible) { @@ -553,7 +555,7 @@ public class StyleManager { /** * Set the x- and y-axis titles visibility - * + * * @param isVisible */ public void setAxisTitlesVisible(boolean isVisible) { @@ -564,7 +566,7 @@ public class StyleManager { /** * Set the x- and y-axis title font - * + * * @param axisTitleFont */ public void setAxisTitleFont(Font axisTitleFont) { @@ -579,7 +581,7 @@ public class StyleManager { /** * Set the x-axis tick marks and labels visibility - * + * * @param isVisible */ @@ -595,7 +597,7 @@ public class StyleManager { /** * Set the y-axis tick marks and labels visibility - * + * * @param isVisible */ @@ -611,7 +613,7 @@ public class StyleManager { /** * Set the x- and y-axis tick marks and labels visibility - * + * * @param isVisible */ public void setAxisTicksVisible(boolean isVisible) { @@ -622,7 +624,7 @@ public class StyleManager { /** * Set the x- and y-axis tick label font - * + * * @param foxAxisTicksFontnt */ public void setAxisTickLabelsFont(Font axisTicksFont) { @@ -637,7 +639,7 @@ public class StyleManager { /** * set the axis tick mark length - * + * * @param axisTickMarkLength */ public void setAxisTickMarkLength(int axisTickMarkLength) { @@ -652,7 +654,7 @@ public class StyleManager { /** * sets the padding between the tick labels and the tick marks - * + * * @param axisTickPadding */ public void setAxisTickPadding(int axisTickPadding) { @@ -667,7 +669,7 @@ public class StyleManager { /** * sets the axis tick mark color - * + * * @param axisTickColor */ public void setAxisTickMarksColor(Color axisTickColor) { @@ -682,7 +684,7 @@ public class StyleManager { /** * sets the axis tick marks Stroke - * + * * @param axisTickMarksStroke */ public void setAxisTickMarksStroke(Stroke axisTickMarksStroke) { @@ -697,7 +699,7 @@ public class StyleManager { /** * sets the axis tick label color - * + * * @param axisTickLabelsColor */ public void setAxisTickLabelsColor(Color axisTickLabelsColor) { @@ -712,7 +714,7 @@ public class StyleManager { /** * sets the visibility of the line parallel to the plot edges that go along with the tick marks - * + * * @param isAxisTicksLineVisible */ public void setAxisTicksLineVisible(boolean isAxisTicksLineVisible) { @@ -727,7 +729,7 @@ public class StyleManager { /** * sets the visibility of the tick marks - * + * * @param isAxisTicksMarksVisible */ public void setAxisTicksMarksVisible(boolean isAxisTicksMarksVisible) { @@ -742,7 +744,7 @@ public class StyleManager { /** * sets the padding between the tick marks and the plot area - * + * * @param plotPadding */ public void setPlotPadding(int plotPadding) { @@ -757,7 +759,7 @@ public class StyleManager { /** * sets the padding between the axis title and the tick labels - * + * * @param axisTitlePadding */ public void setAxisTitlePadding(int axisTitlePadding) { @@ -772,7 +774,7 @@ public class StyleManager { /** * set the spacing between tick marks for the X-Axis - * + * * @param xAxisTickMarkSpacingHint */ public void setXAxisTickMarkSpacingHint(int xAxisTickMarkSpacingHint) { @@ -787,7 +789,7 @@ public class StyleManager { /** * set the spacing between tick marks for the Y-Axis - * + * * @param xAxisTickMarkSpacingHint */ public void setYAxisTickMarkSpacingHint(int yAxisTickMarkSpacingHint) { @@ -802,7 +804,7 @@ public class StyleManager { /** * sets the X-Axis to be rendered with a logarithmic scale or not - * + * * @param isxAxisLogarithmic */ public void setXAxisLogarithmic(boolean isXAxisLogarithmic) { @@ -817,7 +819,7 @@ public class StyleManager { /** * sets the Y-Axis to be rendered with a logarithmic scale or not - * + * * @param isyAxisLogarithmic */ public void setYAxisLogarithmic(boolean isYAxisLogarithmic) { @@ -881,27 +883,30 @@ public class StyleManager { } public TextAlignment getXAxisLabelAlignment() { + return xAxisLabelAlignment; } public void setXAxisLabelAlignment(TextAlignment xAxisLabelAlignment) { + this.xAxisLabelAlignment = xAxisLabelAlignment; } public TextAlignment getYAxisLabelAlignment() { + return yAxisLabelAlignment; } public void setYAxisLabelAlignment(TextAlignment yAxisLabelAlignment) { + this.yAxisLabelAlignment = yAxisLabelAlignment; } - // Chart Plot Area /////////////////////////////// /** * sets the visibility of the gridlines on the plot area - * + * * @param isPlotGridLinesVisible */ public void setPlotGridLinesVisible(boolean isPlotGridLinesVisible) { @@ -916,7 +921,7 @@ public class StyleManager { /** * set the plot area's background color - * + * * @param plotBackgroundColor */ public void setPlotBackgroundColor(Color plotBackgroundColor) { @@ -931,7 +936,7 @@ public class StyleManager { /** * set the plot area's border color - * + * * @param plotBorderColor */ public void setPlotBorderColor(Color plotBorderColor) { @@ -946,7 +951,7 @@ public class StyleManager { /** * sets the visibility of the border around the plot area - * + * * @param isPlotBorderVisible */ public void setPlotBorderVisible(boolean isPlotBorderVisible) { @@ -961,7 +966,7 @@ public class StyleManager { /** * sets the visibility of the ticks marks inside the plot area - * + * * @param isPlotTicksMarksVisible */ public void setPlotTicksMarksVisible(boolean isPlotTicksMarksVisible) { @@ -976,7 +981,7 @@ public class StyleManager { /** * set the plot area's grid lines color - * + * * @param plotGridLinesColor */ public void setPlotGridLinesColor(Color plotGridLinesColor) { @@ -991,7 +996,7 @@ public class StyleManager { /** * set the plot area's grid lines Stroke - * + * * @param plotGridLinesStroke */ public void setPlotGridLinesStroke(Stroke plotGridLinesStroke) { @@ -1008,7 +1013,7 @@ public class StyleManager { /** * set the width of a single bar in a bar chart. full width is 100%, i.e. 1.0 - * + * * @param barWidthPercentage */ public void setBarWidthPercentage(double barWidthPercentage) { @@ -1023,7 +1028,7 @@ public class StyleManager { /** * set whether or no bars are overlapped. Otherwise they are places side-by-side - * + * * @param isBarsOverlapped */ public void setBarsOverlapped(boolean isBarsOverlapped) { @@ -1040,7 +1045,7 @@ public class StyleManager { /** * Sets the size of the markers in pixels - * + * * @param markerSize */ public void setMarkerSize(int markerSize) { @@ -1057,7 +1062,7 @@ public class StyleManager { /** * Sets the color of the error bars - * + * * @param errorBarsColor */ public void setErrorBarsColor(Color errorBarsColor) { @@ -1074,7 +1079,7 @@ public class StyleManager { /** * Set the locale to use for rendering the chart - * + * * @param locale - the locale to use when formatting Strings and dates for the axis tick labels */ public void setLocale(Locale locale) { @@ -1089,7 +1094,7 @@ public class StyleManager { /** * Set the timezone to use for formatting Date axis tick labels - * + * * @param timezone the timezone to use when formatting date data */ public void setTimezone(TimeZone timezone) { @@ -1104,7 +1109,7 @@ public class StyleManager { /** * Set the String formatter for Data x-axis - * + * * @param pattern - the pattern describing the date and time format */ public void setDatePattern(String datePattern) { @@ -1119,7 +1124,7 @@ public class StyleManager { /** * Set the decimal formatter for all tick labels - * + * * @param pattern - the pattern describing the decimal format */ public void setDecimalPattern(String decimalPattern) { @@ -1132,4 +1137,34 @@ public class StyleManager { return decimalPattern; } + public String getXAxisDecimalPattern() { + + return xAxisDecimalPattern; + } + + /** + * Set the decimal formatting pattern for the X-Axis + * + * @param xAxisDecimalPattern + */ + public void setXAxisDecimalPattern(String xAxisDecimalPattern) { + + this.xAxisDecimalPattern = xAxisDecimalPattern; + } + + public String getYAxisDecimalPattern() { + + return yAxisDecimalPattern; + } + + /** + * Set the decimal formatting pattern for the Y-Axis + * + * @param yAxisDecimalPattern + */ + public void setYAxisDecimalPattern(String yAxisDecimalPattern) { + + this.yAxisDecimalPattern = yAxisDecimalPattern; + } + } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java index 5f5d3e44c74cf295355b2fbc3afa3dbb9c0d2bd1..aa0531f439f5cd8e90f7ad2a9ca474bfc406973d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java @@ -15,15 +15,21 @@ */ package com.xeiam.xchart.internal.chartpart; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import com.xeiam.xchart.Series; import com.xeiam.xchart.StyleManager.ChartType; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.style.SeriesColorMarkerLineStyleCycler; -import java.awt.*; -import java.util.*; -import java.util.List; - /** * @author timmolter */ @@ -110,11 +116,11 @@ public class AxisPair implements ChartPart { } switch (chartPainter.getStyleManager().getChartType()) { - case Area: - series.setSeriesType(Series.SeriesType.Area); - break; - case Line: - series.setSeriesType(Series.SeriesType.Line); + case Area: + series.setSeriesType(Series.SeriesType.Area); + break; + case Line: + series.setSeriesType(Series.SeriesType.Line); } // Sanity check diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickBarChartCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickBarChartCalculator.java index 422bc51bd6f25ea88c16d49a1c3457f7b470ace8..7a8e647a60c3ce6eff5bc9900ed63bb2edc256ed 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickBarChartCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickBarChartCalculator.java @@ -119,7 +119,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator { for (Object category : categories) { if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { - tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf((Double) category), minValue, maxValue)); + tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf((Double) category), minValue, maxValue, axisDirection)); } else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { long span = (long) Math.abs(maxValue - minValue); // in data space @@ -150,7 +150,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator { for (double tickPosition = firstPosition; tickPosition <= maxValue + 2 * gridStep; tickPosition = tickPosition + gridStep) { if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { - tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(tickPosition), minValue, maxValue)); + tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(tickPosition), minValue, maxValue, axisDirection)); } else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { long span = (long) Math.abs(maxValue - minValue); // in data space diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java index 849de832fcee50876b100a9e5fe11545ff370a97..cc1d035877edbbff1a9486127c239137292271ef 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java @@ -15,7 +15,8 @@ */ package com.xeiam.xchart.internal.chartpart; -import java.awt.*; +import java.awt.Graphics2D; +import java.awt.Shape; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.geom.AffineTransform; @@ -96,15 +97,15 @@ public class AxisTickLabels implements ChartPart { double boundWidth = tickLabelBounds.getWidth(); double xPos; switch (getChartPainter().getStyleManager().getYAxisLabelAlignment()) { - case Right: - xPos = xOffset + maxTickLabelWidth - boundWidth; - break; - case Centre: - xPos = xOffset + (maxTickLabelWidth - boundWidth) / 2; - break; - case Left: - default: - xPos = xOffset; + case Right: + xPos = xOffset + maxTickLabelWidth - boundWidth; + break; + case Centre: + xPos = xOffset + (maxTickLabelWidth - boundWidth) / 2; + break; + case Left: + default: + xPos = xOffset; } at.translate(xPos, flippedTickLocation + tickLabelBounds.getHeight() / 2.0); g.transform(at); @@ -147,15 +148,15 @@ public class AxisTickLabels implements ChartPart { AffineTransform at = new AffineTransform(); double xPos; switch (getChartPainter().getStyleManager().getXAxisLabelAlignment()) { - case Left: - xPos = shiftedTickLocation; - break; - case Right: - xPos = shiftedTickLocation - tickLabelBounds.getWidth(); - break; - case Centre: - default: - xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0; + case Left: + xPos = shiftedTickLocation; + break; + case Right: + xPos = shiftedTickLocation - tickLabelBounds.getWidth(); + break; + case Centre: + default: + xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0; } at.translate(xPos, yOffset); g.transform(at); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java index 60bb7358802b9a5fedbe43dc794f1a559f4dbfc5..c534edc63b6fec98fb8d21dd350074771a1b69a4 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java @@ -50,7 +50,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { // a check if all axis data are the exact same values if (minValue == maxValue) { - tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue)); + tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue, axisDirection)); tickLocations.add(workingSpace / 2.0); return; } @@ -113,7 +113,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { // only add labels for the decades if (Math.abs(Math.log10(j) % 1) < 0.00000001) { - tickLabels.add(numberFormatter.formatLogNumber(j)); + tickLabels.add(numberFormatter.formatLogNumber(j, axisDirection)); } else { tickLabels.add(null); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java index dffe6f11d5e6f499460ef3e1a555c813983fbee2..b6c9fbb294c7bb69112a85cbc86fa1b6acd4e38a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java @@ -51,7 +51,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { // a check if all axis data are the exact same values if (minValue == maxValue) { - tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue)); + tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue, axisDirection)); tickLocations.add(workingSpace / 2.0); return; } @@ -74,7 +74,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { // generate all tickLabels and tickLocations from the first to last position for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) { - tickLabels.add(numberFormatter.formatNumber(tickPosition, minValue, maxValue)); + tickLabels.add(numberFormatter.formatNumber(tickPosition, minValue, maxValue, axisDirection)); // here we convert tickPosition finally to plot space, i.e. pixels double tickLabelPosition = margin + ((tickPosition.doubleValue() - minValue) / (maxValue - minValue) * tickSpace); tickLocations.add(tickLabelPosition); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java index 5685df93065350addc032e5ccf409050d174ba97..750f538be4545e74edbe2ea6f6ebca24a8e8de47 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/NumberFormatter.java @@ -20,6 +20,7 @@ import java.text.DecimalFormat; import java.text.NumberFormat; import com.xeiam.xchart.StyleManager; +import com.xeiam.xchart.internal.chartpart.Axis.Direction; /** * @author timmolter @@ -107,21 +108,31 @@ public class NumberFormatter { * Format a number value, if the override patterns are null, it uses defaults * * @param value + * @param min + * @param max + * @param axisDirection * @return */ - public String formatNumber(BigDecimal value, double min, double max) { + public String formatNumber(BigDecimal value, double min, double max, Direction axisDirection) { NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); String decimalPattern; - if (styleManager.getDecimalPattern() == null) { + if (axisDirection == Direction.X && styleManager.getXAxisDecimalPattern() != null) { - decimalPattern = getFormatPattern(value, min, max); + decimalPattern = styleManager.getXAxisDecimalPattern(); } - else { + else if (axisDirection == Direction.Y && styleManager.getYAxisDecimalPattern() != null) { + decimalPattern = styleManager.getYAxisDecimalPattern(); + } + else if (styleManager.getDecimalPattern() != null) { + decimalPattern = styleManager.getDecimalPattern(); } + else { + decimalPattern = getFormatPattern(value, min, max); + } DecimalFormat normalFormat = (DecimalFormat) numberFormat; normalFormat.applyPattern(decimalPattern); @@ -135,19 +146,26 @@ public class NumberFormatter { * @param value * @return */ - public String formatLogNumber(double value) { + public String formatLogNumber(double value, Direction axisDirection) { NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); String decimalPattern; - if (styleManager.getDecimalPattern() == null) { + if (axisDirection == Direction.X && styleManager.getXAxisDecimalPattern() != null) { - decimalPattern = "0E0"; + decimalPattern = styleManager.getXAxisDecimalPattern(); } - else { + else if (axisDirection == Direction.Y && styleManager.getYAxisDecimalPattern() != null) { + decimalPattern = styleManager.getYAxisDecimalPattern(); + } + else if (styleManager.getDecimalPattern() != null) { + decimalPattern = styleManager.getDecimalPattern(); } + else { + decimalPattern = "0E0"; + } DecimalFormat normalFormat = (DecimalFormat) numberFormat; normalFormat.applyPattern(decimalPattern);