Skip to content
Snippets Groups Projects
Commit 0c9495d6 authored by Tim Molter's avatar Tim Molter
Browse files

another big rearrange

parent 2f76d5ac
No related branches found
No related tags found
No related merge requests found
Showing
with 503 additions and 95 deletions
......@@ -72,7 +72,7 @@ public class LineChart04 implements ExampleChart {
chart.setChartTitle("LineChart04");
chart.setXAxisTitle("time of day");
chart.setYAxisTitle("gigawatts");
chart.getValueFormatter().setTimezone(TimeZone.getTimeZone("UTC"));
chart.getStyleManager().getDateFormatter().setTimezone(TimeZone.getTimeZone("UTC"));
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
Series series = chart.addDateSeries("value", xData, yData);
......
......@@ -81,9 +81,9 @@ public class LineChart09 implements ExampleChart {
chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18));
chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11));
chart.getValueFormatter().setDatePattern("dd-MMM");
chart.getValueFormatter().setNormalDecimalPattern("#.000");
chart.getValueFormatter().setLocale(Locale.GERMAN);
chart.getStyleManager().getDateFormatter().setDatePattern("dd-MMM");
chart.getStyleManager().getDecimalFormatter().setNormalDecimalPattern("#.000");
chart.getStyleManager().getDateFormatter().setLocale(Locale.GERMAN);
Series series = chart.addDateSeries("Fake Data", xData, yData);
series.setLineColor(SeriesColor.BLUE);
......
......@@ -27,7 +27,6 @@ import com.xeiam.xchart.internal.chartpart.Legend;
import com.xeiam.xchart.internal.chartpart.Plot;
import com.xeiam.xchart.style.Series;
import com.xeiam.xchart.style.StyleManager;
import com.xeiam.xchart.style.ValueFormatter;
import com.xeiam.xchart.style.theme.Theme;
/**
......@@ -41,7 +40,6 @@ public class Chart {
private int height;
private StyleManager styleManager = new StyleManager();
private ValueFormatter valueFormatter = new ValueFormatter();
// Chart Parts
private Legend chartLegend = new Legend(this);
......@@ -275,16 +273,6 @@ public class Chart {
}
/**
* Gets the Chart's value formatter, which can be used to customize the formatting of numbers and dates
*
* @return
*/
public ValueFormatter getValueFormatter() {
return valueFormatter;
}
/**
* Set the min and max value of the X axis
*
......
......@@ -164,7 +164,7 @@ public class AxisPair implements ChartPart {
* @param workingSpace
* @return
*/
protected static int getTickSpace(int workingSpace) {
public static int getTickSpace(int workingSpace) {
return (int) (workingSpace * 0.95);
}
......@@ -176,7 +176,7 @@ public class AxisPair implements ChartPart {
* @param tickSpace
* @return
*/
protected static int getTickStartOffset(int workingSpace, int tickSpace) {
public static int getTickStartOffset(int workingSpace, int tickSpace) {
int marginSpace = workingSpace - tickSpace;
return (int) (marginSpace / 2.0);
......
......@@ -20,6 +20,10 @@ import java.awt.Rectangle;
import java.util.List;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
import com.xeiam.xchart.internal.chartpart.gridstep.DateGridStep;
import com.xeiam.xchart.internal.chartpart.gridstep.DecimalGridStep;
import com.xeiam.xchart.internal.chartpart.gridstep.GridStep;
/**
* An axis tick
......@@ -41,7 +45,7 @@ public class AxisTick implements ChartPart {
/** the visibility state of axistick */
private boolean isVisible = true; // default to true
AxisTickComputer axisTickComputer;
GridStep gridStep = null;
/**
* Constructor
......@@ -77,7 +81,21 @@ public class AxisTick implements ChartPart {
// System.out.println("workingspace= " + workingSpace);
}
axisTickComputer = new AxisTickComputer(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getValueFormatter(), axis.getAxisType());
// ////////////////////////
if (axis.getAxisType() == AxisType.Number) {
gridStep = new DecimalGridStep(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager());
} else if (axis.getAxisType() == AxisType.Date) {
gridStep = new DateGridStep(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager());
} else if (axis.getAxisType() == AxisType.Logarithmic) {
}
// /////////////////////////
if (isVisible) {
......@@ -120,11 +138,11 @@ public class AxisTick implements ChartPart {
public List<Integer> getTickLocations() {
return axisTickComputer.getTickLocations();
return gridStep.getTickLocations();
}
public List<String> getTickLabels() {
return axisTickComputer.getTickLabels();
return gridStep.getTickLabels();
}
}
......@@ -19,11 +19,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.xeiam.xchart.style;
package com.xeiam.xchart.internal.chartpart.gridstep;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;
......@@ -32,10 +30,8 @@ import java.util.concurrent.TimeUnit;
/**
* @author timmolter
*/
public class ValueFormatter {
public class DateFormatter {
private String normalDecimalPattern;
private String scientificDecimalPattern;
private String datePattern;
private Locale locale;
private TimeZone timezone;
......@@ -51,43 +47,13 @@ public class ValueFormatter {
/**
* Constructor
*/
public ValueFormatter() {
public DateFormatter() {
normalDecimalPattern = "#.####";
scientificDecimalPattern = "0.##E0";
datePattern = "HHmmss";
locale = Locale.getDefault();
timezone = TimeZone.getDefault();
}
/**
* 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(locale);
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(normalDecimalPattern);
return normalFormat.format(value);
} else {
DecimalFormat scientificFormat = (DecimalFormat) numberFormat;
scientificFormat.applyPattern(scientificDecimalPattern);
return scientificFormat.format(value);
}
}
/**
* Format a date value
*
......@@ -98,6 +64,8 @@ public class ValueFormatter {
*/
public String formatDateValue(BigDecimal value, BigDecimal min, BigDecimal max) {
// TODO check if min and max are the same, then calculate this differently
// intelligently set date pattern if none is given
long diff = max.subtract(min).longValue();
......@@ -126,26 +94,6 @@ public class ValueFormatter {
}
/**
* Set the decimal formatter for all tick labels
*
* @param pattern - the pattern describing the decimal format
*/
public void setNormalDecimalPattern(String normalDecimalPattern) {
this.normalDecimalPattern = normalDecimalPattern;
}
/**
* Set the scientific notation formatter for all tick labels
*
* @param pattern - the pattern describing the scientific notation format
*/
public void setScientificDecimalPattern(String scientificDecimalPattern) {
this.scientificDecimalPattern = scientificDecimalPattern;
}
/**
* Set the String formatter for Data x-axis
*
......
......@@ -19,23 +19,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.xeiam.xchart.internal.chartpart;
package com.xeiam.xchart.internal.chartpart.gridstep;
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
import com.xeiam.xchart.internal.chartpart.gridstep.DecimalGridStep;
import com.xeiam.xchart.style.ValueFormatter;
import com.xeiam.xchart.internal.chartpart.AxisPair;
import com.xeiam.xchart.style.StyleManager;
/**
* This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks
*
* @author timmolter
*/
public class AxisTickComputer {
public class DateGridStep implements GridStep {
/** the default tick mark step hint for x axis */
private static final int DEFAULT_TICK_MARK_STEP_HINT_X = 74;
/** the default tick mark step hint for y axis */
private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44;
/** the List of tick label position in pixels */
private List<Integer> tickLocations = new LinkedList<Integer>();;
......@@ -51,9 +54,7 @@ public class AxisTickComputer {
private final BigDecimal maxValue;
private final ValueFormatter valueFormatter;
private final AxisType axisType;
private final StyleManager styleManager;
/**
* Constructor
......@@ -62,28 +63,23 @@ public class AxisTickComputer {
* @param workingSpace
* @param minValue
* @param maxValue
* @param valueFormatter
* @param axisType
*/
public AxisTickComputer(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, ValueFormatter valueFormatter, AxisType axisType) {
public DateGridStep(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, StyleManager styleManager) {
this.axisDirection = axisDirection;
this.workingSpace = workingSpace;
this.minValue = minValue;
this.maxValue = maxValue;
this.valueFormatter = valueFormatter;
this.axisType = axisType;
this.styleManager = styleManager;
computeAxisTick();
go();
}
private void computeAxisTick() {
System.out.println("workingSpace= " + workingSpace);
private void go() {
// a check if all axis data are the exact same values
if (maxValue == minValue) {
tickLabels.add(format(maxValue));
if (minValue == maxValue) {
tickLabels.add(styleManager.getDateFormatter().formatDateValue(maxValue, maxValue, maxValue));
tickLocations.add((int) (workingSpace / 2.0));
return;
}
......@@ -93,58 +89,114 @@ public class AxisTickComputer {
System.out.println("tickSpace= " + tickSpace);
// where the tick should begin in the working space in pixels
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space
// the span of the data
double span = Math.abs(maxValue.subtract(minValue).doubleValue()); // in data space
BigDecimal gridStep = null;
BigDecimal firstPosition = null;
if (axisType == AxisType.Number) {
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
DecimalGridStep decimalGridStepHelper = new DecimalGridStep();
gridStep = decimalGridStepHelper.getGridStepForDecimal(axisDirection, span, tickSpace);
firstPosition = decimalGridStepHelper.getFirstPosition(minValue, gridStep);
BigDecimal gridStep = getGridStepForDecimal(tickSpace);
} else if (axisType == AxisType.Date) {
} else if (axisType == AxisType.Logarithmic) {
}
BigDecimal firstPosition = getFirstPosition(minValue, gridStep);
// 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(format(tickPosition));
tickLabels.add(styleManager.getDateFormatter().formatDateValue(tickPosition, minValue, maxValue));
// 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);
}
}
/**
* Format the number
* Determine the grid step for the data set given the space in pixels allocated for the axis
*
* @param value The number to be formatted
* @return The formatted number in String form
* @param tickSpace in plot space
* @return
*/
private String format(BigDecimal value) {
private BigDecimal getGridStepForDecimal(int tickSpace) {
if (axisType == AxisType.Number) {
// the span of the data
double span = Math.abs(maxValue.subtract(minValue).doubleValue()); // in data space
int tickMarkSpaceHint = (axisDirection == Direction.X ? DEFAULT_TICK_MARK_STEP_HINT_X : DEFAULT_TICK_MARK_STEP_HINT_Y);
// for very short plots, squeeze some more ticks in than normal
if (axisDirection == Direction.Y && tickSpace < 160) {
tickMarkSpaceHint = 25;
}
return valueFormatter.formatNumber(value);
double gridStepHint = span / tickSpace * tickMarkSpaceHint;
// gridStepHint --> significand * 10 ** exponent
// e.g. 724.1 --> 7.241 * 10 ** 2
double significand = gridStepHint;
int exponent = 0;
if (significand == 0) {
exponent = 1;
} else if (significand < 1) {
while (significand < 1) {
significand *= 10.0;
exponent--;
}
} else {
while (significand >= 10) {
significand /= 10.0;
exponent++;
}
}
return valueFormatter.formatDateValue(value, minValue, maxValue);
// calculate the grid step with hint.
BigDecimal gridStep;
if (significand > 7.5) {
// gridStep = 10.0 * 10 ** exponent
gridStep = BigDecimal.TEN.multiply(pow(10, exponent));
} else if (significand > 3.5) {
// gridStep = 5.0 * 10 ** exponent
gridStep = new BigDecimal(new Double(5).toString()).multiply(pow(10, exponent));
} else if (significand > 1.5) {
// gridStep = 2.0 * 10 ** exponent
gridStep = new BigDecimal(new Double(2).toString()).multiply(pow(10, exponent));
} else {
// gridStep = 1.0 * 10 ** exponent
gridStep = pow(10, exponent);
}
return gridStep;
}
/**
* Calculates the value of the first argument raised to the power of the second argument.
*
* @param base the base
* @param exponent the exponent
* @return the value <tt>a<sup>b</sup></tt> in <tt>BigDecimal</tt>
*/
private BigDecimal pow(double base, int exponent) {
BigDecimal value;
if (exponent > 0) {
value = new BigDecimal(new Double(base).toString()).pow(exponent);
} else {
value = BigDecimal.ONE.divide(new BigDecimal(new Double(base).toString()).pow(-exponent));
}
return value;
}
private BigDecimal getFirstPosition(final BigDecimal min, BigDecimal gridStep) {
BigDecimal firstPosition;
if (min.remainder(gridStep).doubleValue() <= 0.0) {
firstPosition = min.subtract(min.remainder(gridStep));
} else {
firstPosition = min.subtract(min.remainder(gridStep)).add(gridStep);
}
return firstPosition;
}
@Override
public List<Integer> getTickLocations() {
return tickLocations;
}
@Override
public List<String> getTickLabels() {
return tickLabels;
......
/**
* 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.gridstep;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
/**
* @author timmolter
*/
public class DecimalFormatter {
private String normalDecimalPattern;
private String scientificDecimalPattern;
// TODO move to parent class??
private Locale locale;
/**
* Constructor
*/
public DecimalFormatter() {
normalDecimalPattern = "#.####";
scientificDecimalPattern = "0.##E0";
locale = Locale.getDefault();
}
/**
* 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(locale);
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(normalDecimalPattern);
return normalFormat.format(value);
} else {
DecimalFormat scientificFormat = (DecimalFormat) numberFormat;
scientificFormat.applyPattern(scientificDecimalPattern);
return scientificFormat.format(value);
}
}
/**
* Set the decimal formatter for all tick labels
*
* @param pattern - the pattern describing the decimal format
*/
public void setNormalDecimalPattern(String normalDecimalPattern) {
this.normalDecimalPattern = normalDecimalPattern;
}
/**
* Set the scientific notation formatter for all tick labels
*
* @param pattern - the pattern describing the scientific notation format
*/
public void setScientificDecimalPattern(String scientificDecimalPattern) {
this.scientificDecimalPattern = scientificDecimalPattern;
}
/**
* 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) {
this.locale = locale;
}
}
......@@ -22,13 +22,19 @@
package com.xeiam.xchart.internal.chartpart.gridstep;
import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
import com.xeiam.xchart.internal.chartpart.AxisPair;
import com.xeiam.xchart.style.StyleManager;
/**
* This class encapsulates the logic to generate the axis tick mark and axis tick label data for rendering the axis ticks for decimla axes
*
* @author timmolter
*/
public class DecimalGridStep {
public class DecimalGridStep implements GridStep {
/** the default tick mark step hint for x axis */
private static final int DEFAULT_TICK_MARK_STEP_HINT_X = 74;
......@@ -36,13 +42,81 @@ public class DecimalGridStep {
/** the default tick mark step hint for y axis */
private static final int DEFAULT_TICK_MARK_STEP_HINT_Y = 44;
/** the List of tick label position in pixels */
private List<Integer> tickLocations = new LinkedList<Integer>();;
/** the List of tick label values */
private List<String> tickLabels = new LinkedList<String>();
private final Direction axisDirection;
private final int workingSpace;
private final BigDecimal minValue;
private final BigDecimal maxValue;
private final StyleManager styleManager;
/**
* Constructor
*
* @param axisDirection
* @param workingSpace
* @param minValue
* @param maxValue
*/
public DecimalGridStep(Direction axisDirection, int workingSpace, BigDecimal minValue, BigDecimal maxValue, StyleManager styleManager) {
this.axisDirection = axisDirection;
this.workingSpace = workingSpace;
this.minValue = minValue;
this.maxValue = maxValue;
this.styleManager = styleManager;
go();
}
private void go() {
// a check if all axis data are the exact same values
if (minValue == maxValue) {
tickLabels.add(styleManager.getDecimalFormatter().formatNumber(maxValue));
tickLocations.add((int) (workingSpace / 2.0));
return;
}
// tick space - a percentage of the working space available for ticks, i.e. 95%
int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space
System.out.println("tickSpace= " + tickSpace);
// where the tick should begin in the working space in pixels
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
BigDecimal gridStep = getGridStepForDecimal(tickSpace);
BigDecimal firstPosition = getFirstPosition(minValue, gridStep);
// 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(styleManager.getDecimalFormatter().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);
}
}
/**
* Determine the grid step for the data set given the space in pixels allocated for the axis
*
* @param tickSpace in plot space
* @return
*/
public BigDecimal getGridStepForDecimal(Direction axisDirection, double span, int tickSpace) {
private BigDecimal getGridStepForDecimal(int tickSpace) {
// the span of the data
double span = Math.abs(maxValue.subtract(minValue).doubleValue()); // in data space
int tickMarkSpaceHint = (axisDirection == Direction.X ? DEFAULT_TICK_MARK_STEP_HINT_X : DEFAULT_TICK_MARK_STEP_HINT_Y);
......@@ -107,7 +181,7 @@ public class DecimalGridStep {
return value;
}
public BigDecimal getFirstPosition(final BigDecimal min, BigDecimal gridStep) {
private BigDecimal getFirstPosition(final BigDecimal min, BigDecimal gridStep) {
BigDecimal firstPosition;
if (min.remainder(gridStep).doubleValue() <= 0.0) {
......@@ -118,4 +192,16 @@ public class DecimalGridStep {
return firstPosition;
}
@Override
public List<Integer> getTickLocations() {
return tickLocations;
}
@Override
public List<String> getTickLabels() {
return tickLabels;
}
}
......@@ -19,46 +19,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.xeiam.xchart.unit;
package com.xeiam.xchart.internal.chartpart.gridstep;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
import com.xeiam.xchart.internal.chartpart.AxisTickComputer;
import com.xeiam.xchart.style.ValueFormatter;
/**
* @author timmolter
*/
public class XAxisTest {
// @Test
public void testNumber() {
public interface GridStep {
AxisTickComputer axisTickComputer = new AxisTickComputer(Direction.X, 1000, new BigDecimal(0), new BigDecimal(10), new ValueFormatter(), AxisType.Number);
// Labels
List<String> tickLabels = axisTickComputer.getTickLabels();
System.out.println(Arrays.toString(tickLabels.toArray()));
// Locations
List<Integer> tickLocations = axisTickComputer.getTickLocations();
System.out.println(Arrays.toString(tickLocations.toArray()));
}
@Test
public void testDateOneMinuteTimespan() {
public List<Integer> getTickLocations();
AxisTickComputer axisTickComputer = new AxisTickComputer(Direction.X, 1000, new BigDecimal(1361031254000L), new BigDecimal(1361031314000L), new ValueFormatter(), AxisType.Date);
// Labels
List<String> tickLabels = axisTickComputer.getTickLabels();
System.out.println(Arrays.toString(tickLabels.toArray()));
// Locations
List<Integer> tickLocations = axisTickComputer.getTickLocations();
System.out.println(Arrays.toString(tickLocations.toArray()));
}
public List<String> getTickLabels();
}
......@@ -25,6 +25,8 @@ import java.awt.Color;
import java.awt.Font;
import java.awt.Stroke;
import com.xeiam.xchart.internal.chartpart.gridstep.DateFormatter;
import com.xeiam.xchart.internal.chartpart.gridstep.DecimalFormatter;
import com.xeiam.xchart.style.theme.Theme;
import com.xeiam.xchart.style.theme.XChartTheme;
......@@ -94,6 +96,11 @@ public class StyleManager {
// Error Bars ///////////////////////////////
private Color errorBarsColor;
// Formatting ////////////////////////////////
private DecimalFormatter decimalFormatter;
private DateFormatter dateFormatter;
/**
* Constructor
*/
......@@ -151,6 +158,10 @@ public class StyleManager {
// Error Bars ///////////////////////////////
errorBarsColor = theme.getErrorBarsColor();
// Formatting ////////////////////////////////
decimalFormatter = new DecimalFormatter();
dateFormatter = new DateFormatter();
}
/**
......@@ -741,4 +752,17 @@ public class StyleManager {
return errorBarsColor;
}
// Formatting ////////////////////////////////
public DecimalFormatter getDecimalFormatter() {
return decimalFormatter;
}
public DateFormatter getDateFormatter() {
return dateFormatter;
}
}
......@@ -21,13 +21,8 @@
*/
package com.xeiam.xchart.unit;
import java.math.BigDecimal;
import org.junit.Test;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
import com.xeiam.xchart.internal.chartpart.gridstep.DecimalGridStep;
/**
* @author timmolter
*/
......@@ -36,11 +31,11 @@ public class DecimalGridStepTest {
@Test
public void testDateOneMinuteTimespan() {
DecimalGridStep decimalGridStep = new DecimalGridStep();
BigDecimal gridStep = decimalGridStep.getGridStepForDecimal(Direction.X, 30, 600);
System.out.println("gridStep= " + gridStep);
BigDecimal first = decimalGridStep.getFirstPosition(new BigDecimal(-15), gridStep);
System.out.println("first= " + first);
// DecimalGridStep decimalGridStep = new DecimalGridStep();
// BigDecimal gridStep = decimalGridStep.getGridStepForDecimal(Direction.X, 30, 600);
// System.out.println("gridStep= " + gridStep);
// BigDecimal first = decimalGridStep.getFirstPosition(new BigDecimal(-15), gridStep);
// System.out.println("first= " + first);
}
......
......@@ -30,7 +30,8 @@ import java.util.TimeZone;
import org.junit.Test;
import com.xeiam.xchart.style.ValueFormatter;
import com.xeiam.xchart.internal.chartpart.gridstep.DateFormatter;
import com.xeiam.xchart.internal.chartpart.gridstep.DecimalFormatter;
/**
* @author timmolter
......@@ -42,7 +43,7 @@ public class ValueFormatterTest {
@Test
public void testNumberFormatting() {
ValueFormatter axisTickLabelFormatter = new ValueFormatter();
DecimalFormatter axisTickLabelFormatter = new DecimalFormatter();
// big
axisTickLabelFormatter.setLocale(locale);
......@@ -135,7 +136,7 @@ public class ValueFormatterTest {
@Test
public void testDateFormatting() {
ValueFormatter axisTickLabelFormatter = new ValueFormatter();
DateFormatter axisTickLabelFormatter = new DateFormatter();
TimeZone timeZone = TimeZone.getTimeZone("UTC");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment