From 2bf01fa5407c52824621863d1774b5902b2e4f88 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Sun, 24 Feb 2013 14:20:14 +0100 Subject: [PATCH] more bar chart work --- .../xchart/demo/charts/area/AreaChart01.java | 1 - .../xchart/demo/charts/bar/BarChart02.java | 31 ++++- .../xchart/demo/charts/bar/BarChart03.java | 2 +- .../xchart/demo/charts/bar/BarChart04.java | 2 +- .../xchart/demo/charts/bar/BarChart05.java | 61 +++++++++ .../xchart/demo/charts/date/DateChart01.java | 2 +- .../xchart/demo/charts/date/DateChart02.java | 2 +- .../xchart/demo/charts/date/DateChart03.java | 2 +- .../xchart/demo/charts/date/DateChart04.java | 2 +- .../xchart/demo/charts/date/DateChart05.java | 2 +- .../xchart/demo/charts/date/DateChart06.java | 2 +- .../xchart/demo/charts/date/DateChart07.java | 5 +- .../src/main/java/com/xeiam/xchart/Chart.java | 23 ++-- .../java/com/xeiam/xchart/ChartBuilder.java | 14 +- .../xchart/internal/chartpart/AxisTitle.java | 5 + .../xchart/internal/chartpart/ChartTitle.java | 8 +- .../AxisTickCalculator.java | 30 ----- .../BarChartAxisTickCalculator.java | 14 +- .../DateAxisTickCalculator.java | 85 +----------- .../axistickcalculator/DateFormatter.java | 122 ++++++++++++++++++ .../LogarithmicAxisTickCalculator.java | 7 +- .../NumberAxisTickCalculator.java | 7 +- .../axistickcalculator/NumberFormatter.java | 72 +++++++++++ .../com/xeiam/xchart/style/StyleManager.java | 2 +- .../xeiam/xchart/unit/ValueFormatterTest.java | 37 +++--- 25 files changed, 366 insertions(+), 174 deletions(-) create mode 100644 xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart05.java create mode 100644 xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java create mode 100644 xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberFormatter.java 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 2176779e..6f6db67d 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 @@ -46,7 +46,6 @@ public class AreaChart01 implements ExampleChart { chart.addSeries("c", new double[] { 0, 1, 3, 8, 9 }, new double[] { -2, -1, 1, 0, 1 }); // Customize Chart - chart.getStyleManager().setChartTitleVisible(false); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); return chart; diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java index 19f4dbd2..91645670 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart02.java @@ -21,6 +21,14 @@ */ package com.xeiam.xchart.demo.charts.bar; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Random; + import com.xeiam.xchart.Chart; import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.SwingWrapper; @@ -32,7 +40,7 @@ import com.xeiam.xchart.style.StyleManager.ChartType; * <p> * Demonstrates the following: * <ul> - * <li>Number categories + * <li>Date categories * <li>All negative values * <li>Single series */ @@ -49,11 +57,24 @@ public class BarChart02 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); - chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { -40, -30, -20, -60 }); + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Units Sold Per Year").xAxisTitle("Year").yAxisTitle("Units Sold").build(); + + Collection<Date> xData = new ArrayList<Date>(); + Collection<Number> yData = new ArrayList<Number>(); - // Customize Chart - chart.getStyleManager().setChartTitleVisible(false); + Random random = new Random(); + DateFormat sdf = new SimpleDateFormat("yyyy"); + Date date = null; + for (int i = 1; i <= 8; i++) { + try { + date = sdf.parse("" + (2000 + i)); + } catch (ParseException e) { + e.printStackTrace(); + } + xData.add(date); + yData.add(random.nextInt(i) + 1); + } + chart.addDateSeries("Model 77", xData, yData); return chart; } diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java index 2a3ccdb4..77dfe5b6 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart03.java @@ -49,7 +49,7 @@ public class BarChart03 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart03").xAxisTitle("X").yAxisTitle("Y").build(); chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { 40, -30, -20, -60 }); // Customize Chart diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java index 19de7682..58c5eb0c 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart04.java @@ -49,7 +49,7 @@ public class BarChart04 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart01").xAxisTitle("X").yAxisTitle("Y").build(); + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart04").xAxisTitle("X").yAxisTitle("Y").build(); chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { 40, 30, 20, 60 }); chart.addSeries("b", new double[] { 10, 20, 30, 40 }, new double[] { 50, 10, 20, 40 }); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart05.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart05.java new file mode 100644 index 00000000..92b0ef3f --- /dev/null +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/bar/BarChart05.java @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.demo.charts.bar; + +import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; +import com.xeiam.xchart.SwingWrapper; +import com.xeiam.xchart.demo.charts.ExampleChart; +import com.xeiam.xchart.style.StyleManager.ChartType; + +/** + * Basic Bar Chart + * <p> + * Demonstrates the following: + * <ul> + * <li>Number categories + * <li>Positive and negative values + * <li>Multiple series + */ +public class BarChart05 implements ExampleChart { + + public static void main(String[] args) { + + ExampleChart exampleChart = new BarChart05(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + + // Create Chart + Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("BarChart05").xAxisTitle("X").yAxisTitle("Y").build(); + chart.addSeries("a", new double[] { 10, 20, 30, 40 }, new double[] { -40, 30, 20, 60 }); + chart.addSeries("b", new double[] { 10, 20, 30, 40 }, new double[] { 50, 10, -20, 40 }); + + // Customize Chart + chart.getStyleManager().setChartTitleVisible(false); + + return chart; + } +} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart01.java index d100041d..6625e9aa 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart01.java @@ -50,7 +50,7 @@ public class DateChart01 implements ExampleChart { Random random = new Random(); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart02.java index 00d1e956..b3627c3b 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart02.java @@ -48,7 +48,7 @@ public class DateChart02 implements ExampleChart { // Create Chart Chart chart = new Chart(800, 600); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart03.java index b13aaacc..2e2dbb33 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart03.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart03.java @@ -48,7 +48,7 @@ public class DateChart03 implements ExampleChart { // Create Chart Chart chart = new Chart(800, 600); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart04.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart04.java index bb3e9901..9e281745 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart04.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart04.java @@ -48,7 +48,7 @@ public class DateChart04 implements ExampleChart { // Create Chart Chart chart = new Chart(800, 600); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart05.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart05.java index 7277b3b8..d0d4b481 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart05.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart05.java @@ -48,7 +48,7 @@ public class DateChart05 implements ExampleChart { // Create Chart Chart chart = new Chart(800, 600); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart06.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart06.java index c574840c..785c5904 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart06.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart06.java @@ -48,7 +48,7 @@ public class DateChart06 implements ExampleChart { // Create Chart Chart chart = new Chart(800, 600); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart07.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart07.java index 305fd2f0..b9d2ad54 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart07.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart07.java @@ -24,7 +24,6 @@ import java.util.Date; import java.util.Random; import com.xeiam.xchart.Chart; -import com.xeiam.xchart.Series; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; @@ -48,7 +47,7 @@ public class DateChart07 implements ExampleChart { // Create Chart Chart chart = new Chart(800, 600); - // generates linear data + // generate data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); @@ -69,7 +68,7 @@ public class DateChart07 implements ExampleChart { // Customize Chart chart.setChartTitle("DateChart06"); chart.getStyleManager().setLegendVisible(false); - Series series = chart.addDateSeries("value", xData, yData); + chart.addDateSeries("value", xData, yData); return chart; diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index ac5fa6df..01fcd349 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -38,13 +38,13 @@ public class Chart { private int width; private int height; - private StyleManager styleManager = new StyleManager(); + private final StyleManager styleManager; // Chart Parts - private Legend chartLegend = new Legend(this); - private AxisPair axisPair = new AxisPair(this); - private Plot plot = new Plot(this); - private ChartTitle chartTitle = new ChartTitle(this); + private Legend chartLegend; + private AxisPair axisPair; + private Plot plot; + private ChartTitle chartTitle; /** * Constructor @@ -54,6 +54,11 @@ public class Chart { */ public Chart(int width, int height) { + styleManager = new StyleManager(); + chartLegend = new Legend(this); + axisPair = new AxisPair(this); + plot = new Plot(this); + chartTitle = new ChartTitle(this); this.width = width; this.height = height; @@ -67,10 +72,10 @@ public class Chart { public Chart(ChartBuilder chartBuilder) { this(chartBuilder.width, chartBuilder.height); + setTheme(chartBuilder.theme); setChartTitle(chartBuilder.title); setXAxisTitle(chartBuilder.xAxisTitle); setYAxisTitle(chartBuilder.yAxisTitle); - setTheme(chartBuilder.theme); getStyleManager().setChartType(chartBuilder.chartType); } @@ -228,11 +233,6 @@ public class Chart { */ public void setXAxisTitle(String title) { - if (title == null || title.trim().equalsIgnoreCase("")) { - styleManager.setxAxisTitleVisible(false); - } else { - styleManager.setxAxisTitleVisible(true); - } this.axisPair.getxAxis().getAxisTitle().setText(title); } @@ -269,7 +269,6 @@ public class Chart { public void setTheme(Theme theme) { styleManager.setTheme(theme); - } /** diff --git a/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java b/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java index f095bf0b..bb01df2d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java +++ b/xchart/src/main/java/com/xeiam/xchart/ChartBuilder.java @@ -30,13 +30,13 @@ import com.xeiam.xchart.style.theme.XChartTheme; */ public class ChartBuilder { - protected ChartType chartType = ChartType.Line; - protected int width = 800; - protected int height = 600; - protected String title = ""; - protected String xAxisTitle = ""; - protected String yAxisTitle = ""; - protected Theme theme = new XChartTheme(); + ChartType chartType = ChartType.Line; + int width = 800; + int height = 600; + String title = ""; + String xAxisTitle = ""; + String yAxisTitle = ""; + Theme theme = new XChartTheme(); public ChartBuilder chartType(ChartType chartType) { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java index 434952b6..3d0e7554 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTitle.java @@ -144,6 +144,11 @@ public class AxisTitle implements ChartPart { public void setText(String text) { + if (text == null || text.trim().equalsIgnoreCase("")) { + getChart().getStyleManager().setxAxisTitleVisible(false); + } else { + getChart().getStyleManager().setxAxisTitleVisible(true); + } this.text = text; } } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java index 5ac128bb..1af3af99 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java @@ -30,8 +30,8 @@ public class ChartTitle implements ChartPart { /** parent */ private final Chart chart; - /** the bounds */ - private Rectangle bounds; + // /** the bounds */ + // private Rectangle bounds; /** the title text */ private String text = ""; // default to "" @@ -82,7 +82,7 @@ public class ChartTitle implements ChartPart { @Override public void paint(Graphics2D g) { - bounds = new Rectangle(); + // bounds = new Rectangle(); g.setFont(chart.getStyleManager().getChartTitleFont()); if (chart.getStyleManager().isChartTitleVisible()) { @@ -107,7 +107,7 @@ public class ChartTitle implements ChartPart { xOffset = (int) (chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0); yOffset = (int) (chart.getStyleManager().getChartPadding() - rectangle.getY() + chart.getStyleManager().getChartTitlePadding()); - bounds = new Rectangle(xOffset, yOffset + ((int) rectangle.getY()), (int) rectangle.getWidth(), (int) (rectangle.getHeight())); + // bounds = new Rectangle(xOffset, yOffset + ((int) rectangle.getY()), (int) rectangle.getWidth(), (int) (rectangle.getHeight())); // g.setColor(Color.green); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java index 2aa22592..637a21d4 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/AxisTickCalculator.java @@ -22,8 +22,6 @@ package com.xeiam.xchart.internal.chartpart.axistickcalculator; import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.text.NumberFormat; import java.util.LinkedList; import java.util.List; @@ -97,34 +95,6 @@ public abstract class AxisTickCalculator { } } - /** - * Format a number value, if the override patterns are null, it uses defaults - * - * @param value - * @return - */ - public String formatNumber(BigDecimal value) { - - NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); - - BigDecimal absoluteValue = value.abs(); - - if (absoluteValue.compareTo(new BigDecimal("10000.000001")) == -1 && absoluteValue.compareTo(new BigDecimal(".0009999999")) == 1 || BigDecimal.ZERO.compareTo(value) == 0) { - - DecimalFormat normalFormat = (DecimalFormat) numberFormat; - normalFormat.applyPattern(styleManager.getNormalDecimalPattern()); - return normalFormat.format(value); - - } else { - - DecimalFormat scientificFormat = (DecimalFormat) numberFormat; - scientificFormat.applyPattern(styleManager.getScientificDecimalPattern()); - return scientificFormat.format(value); - - } - - } - BigDecimal getFirstPosition(BigDecimal gridStep) { BigDecimal firstPosition; diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java index 92eea63c..25fdfab3 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/BarChartAxisTickCalculator.java @@ -90,9 +90,21 @@ public class BarChartAxisTickCalculator extends AxisTickCalculator { int firstPosition = (int) (gridStep / 2.0); // generate all tickLabels and tickLocations from the first to last position + NumberFormatter numberFormatter = null; + DateFormatter dateFormatter = null; + + if (chart.getAxisPair().getxAxis().getAxisType() == AxisType.Number) { + numberFormatter = new NumberFormatter(styleManager); + } else if (chart.getAxisPair().getxAxis().getAxisType() == AxisType.Date) { + dateFormatter = new DateFormatter(chart.getStyleManager()); + } int counter = 0; for (BigDecimal category : categories) { - tickLabels.add(formatNumber(category)); + if (chart.getAxisPair().getxAxis().getAxisType() == AxisType.Number) { + tickLabels.add(numberFormatter.formatNumber(category)); + } else if (chart.getAxisPair().getxAxis().getAxisType() == AxisType.Date) { + tickLabels.add(dateFormatter.formatDate(category)); + } int tickLabelPosition = margin + firstPosition + gridStep * counter++; tickLocations.add(tickLabelPosition); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java index 21e2ee12..ca216ce0 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateAxisTickCalculator.java @@ -22,11 +22,6 @@ package com.xeiam.xchart.internal.chartpart.axistickcalculator; import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; -import java.util.concurrent.TimeUnit; import com.xeiam.xchart.internal.chartpart.Axis.Direction; import com.xeiam.xchart.internal.chartpart.AxisPair; @@ -39,16 +34,7 @@ import com.xeiam.xchart.style.StyleManager; */ public class DateAxisTickCalculator extends AxisTickCalculator { - public static final long MILLIS_SCALE = TimeUnit.MILLISECONDS.toMillis(1L); - public static final long SEC_SCALE = TimeUnit.SECONDS.toMillis(1L); - public static final long MIN_SCALE = TimeUnit.MINUTES.toMillis(1L); - public static final long HOUR_SCALE = TimeUnit.HOURS.toMillis(1L); - public static final long DAY_SCALE = TimeUnit.DAYS.toMillis(1L); - public static final long MONTH_SCALE = TimeUnit.DAYS.toMillis(1L) * 31; - public static final long YEAR_SCALE = TimeUnit.DAYS.toMillis(1L) * 365; - - private Map<Long, int[]> validTickStepsMap; - private long timeUnit; + DateFormatter dateFormatter; /** * Constructor @@ -62,15 +48,7 @@ public class DateAxisTickCalculator extends AxisTickCalculator { public DateAxisTickCalculator(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, StyleManager styleManager) { super(axisDirection, workingSpace, minValue, maxValue, styleManager); - - validTickStepsMap = new TreeMap<Long, int[]>(); - validTickStepsMap.put(MILLIS_SCALE, new int[] { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }); - validTickStepsMap.put(SEC_SCALE, new int[] { 1, 2, 5, 10, 15, 20, 30, 60 }); - validTickStepsMap.put(MIN_SCALE, new int[] { 1, 2, 3, 5, 10, 15, 20, 30, 60 }); - validTickStepsMap.put(HOUR_SCALE, new int[] { 1, 2, 4, 6, 12, 24 }); - validTickStepsMap.put(DAY_SCALE, new int[] { 1, 2, 3, 5, 10, 15, 31 }); - validTickStepsMap.put(MONTH_SCALE, new int[] { 1, 2, 3, 4, 6, 12 }); - validTickStepsMap.put(YEAR_SCALE, new int[] { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }); + dateFormatter = new DateFormatter(styleManager); calculate(); } @@ -78,7 +56,7 @@ public class DateAxisTickCalculator extends AxisTickCalculator { // a check if all axis data are the exact same values if (minValue == maxValue) { - tickLabels.add(formatDateValue(maxValue)); + tickLabels.add(dateFormatter.formatDate(maxValue)); tickLocations.add((int) (workingSpace / 2.0)); return; } @@ -95,7 +73,7 @@ public class DateAxisTickCalculator extends AxisTickCalculator { // generate all tickLabels and tickLocations from the first to last position for (BigDecimal tickPosition = firstPosition; tickPosition.compareTo(maxValue) <= 0; tickPosition = tickPosition.add(gridStep)) { - tickLabels.add(formatDateValue(tickPosition)); + tickLabels.add(dateFormatter.formatDate(tickPosition)); // here we convert tickPosition finally to plot space, i.e. pixels int tickLabelPosition = (int) (margin + ((tickPosition.subtract(minValue)).doubleValue() / (maxValue.subtract(minValue)).doubleValue() * tickSpace)); tickLocations.add(tickLabelPosition); @@ -115,9 +93,9 @@ public class DateAxisTickCalculator extends AxisTickCalculator { long gridStepHint = (long) (span / (double) tickSpace * DEFAULT_TICK_MARK_STEP_HINT_X); - timeUnit = getTimeUnit(gridStepHint); + long timeUnit = dateFormatter.getTimeUnit(gridStepHint); BigDecimal gridStep = null; - int[] steps = validTickStepsMap.get(timeUnit); + int[] steps = dateFormatter.getValidTickStepsMap().get(timeUnit); for (int i = 0; i < steps.length - 1; i++) { if (gridStepHint < (timeUnit * steps[i] + timeUnit * steps[i + 1]) / 2.0) { gridStep = new BigDecimal(timeUnit * steps[i]); @@ -128,55 +106,4 @@ public class DateAxisTickCalculator extends AxisTickCalculator { return gridStep; } - private long getTimeUnit(long gridStepHint) { - - for (Entry<Long, int[]> entry : validTickStepsMap.entrySet()) { - - long groupMagnitude = entry.getKey(); - int[] steps = entry.getValue(); - long validTickStepMagnitude = (long) ((groupMagnitude * steps[steps.length - 2] + groupMagnitude * steps[steps.length - 1]) / 2.0); - if (gridStepHint < validTickStepMagnitude) { - return groupMagnitude; - } - } - - return YEAR_SCALE; - } - - /** - * Format a date value - * - * @param value - * @param min - * @param max - * @return - */ - public String formatDateValue(BigDecimal value) { - - String datePattern; - - // intelligently set date pattern if none is given - if (timeUnit == MILLIS_SCALE) { - datePattern = "ss.SSS"; - } else if (timeUnit == SEC_SCALE) { - datePattern = "mm:ss"; - } else if (timeUnit == MIN_SCALE) { - datePattern = "HH:mm"; - } else if (timeUnit == HOUR_SCALE) { - datePattern = "dd-HH"; - } else if (timeUnit == DAY_SCALE) { - datePattern = "MM-dd"; - } else if (timeUnit == MONTH_SCALE) { - datePattern = "yyyy-MM"; - } else { - datePattern = "yyyy"; - } - - SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale()); - simpleDateformat.setTimeZone(styleManager.getTimezone()); - simpleDateformat.applyPattern(datePattern); - - return simpleDateformat.format(value.longValueExact()); - } - } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java new file mode 100644 index 00000000..d1d6ba71 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java @@ -0,0 +1,122 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.internal.chartpart.axistickcalculator; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; + +import com.xeiam.xchart.style.StyleManager; + +/** + * @author timmolter + */ +public class DateFormatter { + + public static final long MILLIS_SCALE = TimeUnit.MILLISECONDS.toMillis(1L); + public static final long SEC_SCALE = TimeUnit.SECONDS.toMillis(1L); + public static final long MIN_SCALE = TimeUnit.MINUTES.toMillis(1L); + public static final long HOUR_SCALE = TimeUnit.HOURS.toMillis(1L); + public static final long DAY_SCALE = TimeUnit.DAYS.toMillis(1L); + public static final long MONTH_SCALE = TimeUnit.DAYS.toMillis(1L) * 31; + public static final long YEAR_SCALE = TimeUnit.DAYS.toMillis(1L) * 365; + + private Map<Long, int[]> validTickStepsMap; + private long timeUnit; + + private final StyleManager styleManager; + + /** + * Constructor + */ + public DateFormatter(StyleManager styleManager) { + + this.styleManager = styleManager; + + validTickStepsMap = new TreeMap<Long, int[]>(); + validTickStepsMap.put(MILLIS_SCALE, new int[] { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }); + validTickStepsMap.put(SEC_SCALE, new int[] { 1, 2, 5, 10, 15, 20, 30, 60 }); + validTickStepsMap.put(MIN_SCALE, new int[] { 1, 2, 3, 5, 10, 15, 20, 30, 60 }); + validTickStepsMap.put(HOUR_SCALE, new int[] { 1, 2, 4, 6, 12, 24 }); + validTickStepsMap.put(DAY_SCALE, new int[] { 1, 2, 3, 5, 10, 15, 31 }); + validTickStepsMap.put(MONTH_SCALE, new int[] { 1, 2, 3, 4, 6, 12 }); + validTickStepsMap.put(YEAR_SCALE, new int[] { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }); + } + + long getTimeUnit(long gridStepHint) { + + for (Entry<Long, int[]> entry : validTickStepsMap.entrySet()) { + + long groupMagnitude = entry.getKey(); + int[] steps = entry.getValue(); + long validTickStepMagnitude = (long) ((groupMagnitude * steps[steps.length - 2] + groupMagnitude * steps[steps.length - 1]) / 2.0); + if (gridStepHint < validTickStepMagnitude) { + return groupMagnitude; + } + } + return YEAR_SCALE; + } + + /** + * Format a date value + * + * @param value + * @param min + * @param max + * @return + */ + String formatDate(BigDecimal value) { + + String datePattern; + + // intelligently set date pattern if none is given + if (timeUnit == MILLIS_SCALE) { + datePattern = "ss.SSS"; + } else if (timeUnit == SEC_SCALE) { + datePattern = "mm:ss"; + } else if (timeUnit == MIN_SCALE) { + datePattern = "HH:mm"; + } else if (timeUnit == HOUR_SCALE) { + datePattern = "dd-HH"; + } else if (timeUnit == DAY_SCALE) { + datePattern = "MM-dd"; + } else if (timeUnit == MONTH_SCALE) { + datePattern = "yyyy-MM"; + } else { + datePattern = "yyyy"; + } + + SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale()); + simpleDateformat.setTimeZone(styleManager.getTimezone()); + simpleDateformat.applyPattern(datePattern); + + return simpleDateformat.format(value.longValueExact()); + } + + Map<Long, int[]> getValidTickStepsMap() { + + return validTickStepsMap; + } +} diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java index 0265869e..0345a559 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/LogarithmicAxisTickCalculator.java @@ -34,6 +34,8 @@ import com.xeiam.xchart.style.StyleManager; */ public class LogarithmicAxisTickCalculator extends AxisTickCalculator { + NumberFormatter numberFormatter = null; + /** * Constructor * @@ -46,6 +48,7 @@ public class LogarithmicAxisTickCalculator extends AxisTickCalculator { public LogarithmicAxisTickCalculator(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, StyleManager styleManager) { super(axisDirection, workingSpace, minValue, maxValue, styleManager); + numberFormatter = new NumberFormatter(styleManager); calculate(); } @@ -53,7 +56,7 @@ public class LogarithmicAxisTickCalculator extends AxisTickCalculator { // a check if all axis data are the exact same values if (minValue == maxValue) { - tickLabels.add(formatNumber(maxValue)); + tickLabels.add(numberFormatter.formatNumber(maxValue)); tickLocations.add((int) (workingSpace / 2.0)); return; } @@ -84,7 +87,7 @@ public class LogarithmicAxisTickCalculator extends AxisTickCalculator { // only add labels for the decades if (Math.log10(j.doubleValue()) % 1 == 0.0) { - tickLabels.add(formatNumber(j)); + tickLabels.add(numberFormatter.formatNumber(j)); } else { tickLabels.add(null); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java index f9db45bc..ed398a30 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberAxisTickCalculator.java @@ -34,6 +34,8 @@ import com.xeiam.xchart.style.StyleManager; */ public class NumberAxisTickCalculator extends AxisTickCalculator { + NumberFormatter numberFormatter = null; + /** * Constructor * @@ -46,6 +48,7 @@ public class NumberAxisTickCalculator extends AxisTickCalculator { public NumberAxisTickCalculator(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, StyleManager styleManager) { super(axisDirection, workingSpace, minValue, maxValue, styleManager); + numberFormatter = new NumberFormatter(styleManager); calculate(); } @@ -53,7 +56,7 @@ public class NumberAxisTickCalculator extends AxisTickCalculator { // a check if all axis data are the exact same values if (minValue == maxValue) { - tickLabels.add(formatNumber(maxValue)); + tickLabels.add(numberFormatter.formatNumber(maxValue)); tickLocations.add((int) (workingSpace / 2.0)); return; } @@ -70,7 +73,7 @@ public class NumberAxisTickCalculator extends AxisTickCalculator { // generate all tickLabels and tickLocations from the first to last position for (BigDecimal tickPosition = firstPosition; tickPosition.compareTo(maxValue) <= 0; tickPosition = tickPosition.add(gridStep)) { - tickLabels.add(formatNumber(tickPosition)); + tickLabels.add(numberFormatter.formatNumber(tickPosition)); // here we convert tickPosition finally to plot space, i.e. pixels int tickLabelPosition = (int) (margin + ((tickPosition.subtract(minValue)).doubleValue() / (maxValue.subtract(minValue)).doubleValue() * tickSpace)); tickLocations.add(tickLabelPosition); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberFormatter.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberFormatter.java new file mode 100644 index 00000000..7113bbb2 --- /dev/null +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/NumberFormatter.java @@ -0,0 +1,72 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.internal.chartpart.axistickcalculator; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.NumberFormat; + +import com.xeiam.xchart.style.StyleManager; + +/** + * @author timmolter + */ +public class NumberFormatter { + + private final StyleManager styleManager; + + /** + * Constructor + */ + public NumberFormatter(StyleManager styleManager) { + + this.styleManager = styleManager; + } + + /** + * Format a number value, if the override patterns are null, it uses defaults + * + * @param value + * @return + */ + public String formatNumber(BigDecimal value) { + + NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); + + BigDecimal absoluteValue = value.abs(); + + if (absoluteValue.compareTo(new BigDecimal("10000.000001")) == -1 && absoluteValue.compareTo(new BigDecimal(".0009999999")) == 1 || BigDecimal.ZERO.compareTo(value) == 0) { + + DecimalFormat normalFormat = (DecimalFormat) numberFormat; + normalFormat.applyPattern(styleManager.getNormalDecimalPattern()); + return normalFormat.format(value); + + } else { + + DecimalFormat scientificFormat = (DecimalFormat) numberFormat; + scientificFormat.applyPattern(styleManager.getScientificDecimalPattern()); + return scientificFormat.format(value); + + } + + } +} diff --git a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java index b840eff4..5e8a2b3c 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java @@ -266,7 +266,7 @@ public class StyleManager { /** * Set the chart title visibility * - * @param isVisible + * @param isChartTitleVisible */ public void setChartTitleVisible(boolean isChartTitleVisible) { diff --git a/xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java b/xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java index 020a6745..748406d1 100644 --- a/xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java +++ b/xchart/src/test/java/com/xeiam/xchart/unit/ValueFormatterTest.java @@ -29,8 +29,7 @@ import java.util.Locale; import org.junit.Test; -import com.xeiam.xchart.internal.chartpart.Axis.Direction; -import com.xeiam.xchart.internal.chartpart.axistickcalculator.NumberAxisTickCalculator; +import com.xeiam.xchart.internal.chartpart.axistickcalculator.NumberFormatter; import com.xeiam.xchart.style.StyleManager; /** @@ -44,59 +43,59 @@ public class ValueFormatterTest { public void testNumberFormatting() { StyleManager styleManager = new StyleManager(); - NumberAxisTickCalculator numberAxisTickCalculator = new NumberAxisTickCalculator(Direction.X, 1000, new BigDecimal(10), new BigDecimal(90), styleManager); + NumberFormatter numberFormatter = new NumberFormatter(styleManager); // big styleManager.setLocale(locale); BigDecimal value = new BigDecimal("1"); - String stringValue = numberAxisTickCalculator.formatNumber(value); + String stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("1")); value = new BigDecimal(1000L); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("1000")); value = new BigDecimal("9999"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("9999")); value = new BigDecimal(20000L); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("2E4")); value = new BigDecimal("200.23"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("200.23")); // small value = new BigDecimal("0.01"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("0.01")); value = new BigDecimal("0.001"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("0.001")); value = new BigDecimal("0.0012"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("0.0012")); value = new BigDecimal("0.0001"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("1E-4")); value = new BigDecimal(".00012"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("1.2E-4")); value = new BigDecimal("0.0"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("0")); value = new BigDecimal("0"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("0")); // other case @@ -115,21 +114,21 @@ public class ValueFormatterTest { styleManager.setLocale(Locale.GERMANY); value = new BigDecimal("0.01"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("0,01")); value = new BigDecimal("200.23"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("200,23")); styleManager.setNormalDecimalPattern("#.#"); value = new BigDecimal("200.23"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("200,2")); styleManager.setScientificDecimalPattern("0.#E0"); value = new BigDecimal("2009764.23"); - stringValue = numberAxisTickCalculator.formatNumber(value); + stringValue = numberFormatter.formatNumber(value); assertThat(stringValue, equalTo("2E6")); } -- GitLab