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

bug fixes: date formatter not getting override value, missing plot padding in...

bug fixes: date formatter not getting override value, missing plot padding in plot width calculation
parent 824a708c
Branches
Tags
No related merge requests found
Showing
with 55 additions and 44 deletions
...@@ -44,8 +44,8 @@ import com.xeiam.xchart.demo.charts.date.DateChart06; ...@@ -44,8 +44,8 @@ import com.xeiam.xchart.demo.charts.date.DateChart06;
import com.xeiam.xchart.demo.charts.date.DateChart07; import com.xeiam.xchart.demo.charts.date.DateChart07;
import com.xeiam.xchart.demo.charts.line.LineChart01; import com.xeiam.xchart.demo.charts.line.LineChart01;
import com.xeiam.xchart.demo.charts.line.LineChart02; import com.xeiam.xchart.demo.charts.line.LineChart02;
import com.xeiam.xchart.demo.charts.line.LineChart09; import com.xeiam.xchart.demo.charts.line.LineChart03;
import com.xeiam.xchart.demo.charts.line.LineChart10; import com.xeiam.xchart.demo.charts.line.LineChart04;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart01; import com.xeiam.xchart.demo.charts.scatter.ScatterChart01;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart02; import com.xeiam.xchart.demo.charts.scatter.ScatterChart02;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart03; import com.xeiam.xchart.demo.charts.scatter.ScatterChart03;
...@@ -147,10 +147,10 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { ...@@ -147,10 +147,10 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart02 - Customized Series Style", new LineChart02().getChart())); chart = new DefaultMutableTreeNode(new ChartInfo("LineChart02 - Customized Series Style", new LineChart02().getChart()));
category.add(chart); category.add(chart);
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart09 - Extensive chart customization", new LineChart09().getChart())); chart = new DefaultMutableTreeNode(new ChartInfo("LineChart03 - Extensive Chart Customization", new LineChart03().getChart()));
category.add(chart); category.add(chart);
chart = new DefaultMutableTreeNode(new ChartInfo("LineChart10 - Plots Hundreds of Series on One Plot", new LineChart10().getChart())); chart = new DefaultMutableTreeNode(new ChartInfo("LineChart04 - Plots Hundreds of Series on One Plot", new LineChart04().getChart()));
category.add(chart); category.add(chart);
// Scatter category // Scatter category
......
...@@ -60,7 +60,7 @@ public class LineChart01 implements ExampleChart { ...@@ -60,7 +60,7 @@ public class LineChart01 implements ExampleChart {
// Customize Chart // Customize Chart
chart.getStyleManager().setChartTitleVisible(false); chart.getStyleManager().setChartTitleVisible(false);
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setYAxisLogarithmic(true); chart.getStyleManager().setyAxisLogarithmic(true);
// Series // Series
Series series = chart.addSeries("10^x", xData1, yData1); Series series = chart.addSeries("10^x", xData1, yData1);
......
...@@ -33,15 +33,16 @@ import com.xeiam.xchart.style.ChartColor; ...@@ -33,15 +33,16 @@ import com.xeiam.xchart.style.ChartColor;
import com.xeiam.xchart.style.SeriesColor; import com.xeiam.xchart.style.SeriesColor;
import com.xeiam.xchart.style.SeriesLineStyle; import com.xeiam.xchart.style.SeriesLineStyle;
import com.xeiam.xchart.style.SeriesMarker; import com.xeiam.xchart.style.SeriesMarker;
import com.xeiam.xchart.style.StyleManager.LegendPosition;
/** /**
* Extensive chart customization * Extensive Chart Customization
*/ */
public class LineChart09 implements ExampleChart { public class LineChart03 implements ExampleChart {
public static void main(String[] args) { public static void main(String[] args) {
ExampleChart exampleChart = new LineChart09(); ExampleChart exampleChart = new LineChart03();
Chart chart = exampleChart.getChart(); Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart(); new SwingWrapper(chart).displayChart();
} }
...@@ -70,7 +71,7 @@ public class LineChart09 implements ExampleChart { ...@@ -70,7 +71,7 @@ public class LineChart09 implements ExampleChart {
} }
// Customize Chart // Customize Chart
chart.setChartTitle("LineChart09"); chart.setChartTitle("LineChart03");
chart.setXAxisTitle("X"); chart.setXAxisTitle("X");
chart.setYAxisTitle("Y"); chart.setYAxisTitle("Y");
chart.getStyleManager().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY)); chart.getStyleManager().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY));
...@@ -78,12 +79,18 @@ public class LineChart09 implements ExampleChart { ...@@ -78,12 +79,18 @@ public class LineChart09 implements ExampleChart {
chart.getStyleManager().setChartBackgroundColor(Color.WHITE); chart.getStyleManager().setChartBackgroundColor(Color.WHITE);
chart.getStyleManager().setLegendBackgroundColor(Color.PINK); chart.getStyleManager().setLegendBackgroundColor(Color.PINK);
chart.getStyleManager().setChartFontColor(Color.MAGENTA); chart.getStyleManager().setChartFontColor(Color.MAGENTA);
chart.getStyleManager().setChartTitleBackgroundColor(new Color(0, 222, 0));
chart.getStyleManager().setPlotGridLinesVisible(false);
chart.getStyleManager().setAxisTickPadding(20);
chart.getStyleManager().setAxisTickMarkLength(15);
chart.getStyleManager().setPlotPadding(20);
chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24));
chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18));
chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE);
chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11));
chart.getStyleManager().setDatePattern("dd-MMM"); chart.getStyleManager().setDatePattern("dd-MMM");
chart.getStyleManager().setNormalDecimalPattern("#.000"); chart.getStyleManager().setNormalDecimalPattern("#0.000");
chart.getStyleManager().setLocale(Locale.GERMAN); chart.getStyleManager().setLocale(Locale.GERMAN);
Series series = chart.addDateSeries("Fake Data", xData, yData); Series series = chart.addDateSeries("Fake Data", xData, yData);
......
...@@ -26,11 +26,11 @@ import com.xeiam.xchart.style.SeriesMarker; ...@@ -26,11 +26,11 @@ import com.xeiam.xchart.style.SeriesMarker;
/** /**
* Plots Hundreds of Series on One Plot * Plots Hundreds of Series on One Plot
*/ */
public class LineChart10 implements ExampleChart { public class LineChart04 implements ExampleChart {
public static void main(String[] args) { public static void main(String[] args) {
ExampleChart exampleChart = new LineChart10(); ExampleChart exampleChart = new LineChart04();
Chart chart = exampleChart.getChart(); Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart(); new SwingWrapper(chart).displayChart();
} }
...@@ -42,7 +42,7 @@ public class LineChart10 implements ExampleChart { ...@@ -42,7 +42,7 @@ public class LineChart10 implements ExampleChart {
Chart chart = new Chart(800, 600); Chart chart = new Chart(800, 600);
// Customize Chart // Customize Chart
chart.setChartTitle("LineChart10"); chart.setChartTitle("LineChart04");
chart.setXAxisTitle("X"); chart.setXAxisTitle("X");
chart.setYAxisTitle("Y"); chart.setYAxisTitle("Y");
chart.getStyleManager().setLegendVisible(false); chart.getStyleManager().setLegendVisible(false);
......
...@@ -62,7 +62,7 @@ public class ScatterChart02 implements ExampleChart { ...@@ -62,7 +62,7 @@ public class ScatterChart02 implements ExampleChart {
Chart chart = new Chart(800, 600); Chart chart = new Chart(800, 600);
chart.setChartTitle("Logarithmic Data"); chart.setChartTitle("Logarithmic Data");
chart.getStyleManager().setChartType(ChartType.Scatter); chart.getStyleManager().setChartType(ChartType.Scatter);
chart.getStyleManager().setXAxisLogarithmic(true); chart.getStyleManager().setxAxisLogarithmic(true);
// Customize Chart // Customize Chart
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
......
...@@ -203,7 +203,7 @@ public class Axis implements ChartPart { ...@@ -203,7 +203,7 @@ public class Axis implements ChartPart {
} }
int width = (int) (getChart().getWidth() - axisPair.getyAxis().getBounds().getWidth() - chartLegendWidth - (getChart().getStyleManager().isLegendVisible() ? 3 : 2) int width = (int) (getChart().getWidth() - axisPair.getyAxis().getBounds().getWidth() - chartLegendWidth - (getChart().getStyleManager().isLegendVisible() ? 3 : 2)
* getChart().getStyleManager().getChartPadding()); * getChart().getStyleManager().getChartPadding() - getChart().getStyleManager().getPlotPadding());
int height = this.getSizeHint(); int height = this.getSizeHint();
Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height);
this.paintZone = xAxisRectangle; this.paintZone = xAxisRectangle;
......
...@@ -88,11 +88,11 @@ public class AxisTick implements ChartPart { ...@@ -88,11 +88,11 @@ public class AxisTick implements ChartPart {
gridStep = new BarChartAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart()); gridStep = new BarChartAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart());
} else if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { } else if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().isxAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager()); gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager());
} else if (axis.getDirection() == Axis.Direction.Y && getChart().getStyleManager().isYAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { } else if (axis.getDirection() == Axis.Direction.Y && getChart().getStyleManager().isyAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager()); gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager());
......
...@@ -64,14 +64,14 @@ public class PlotContentLineChart extends PlotContent { ...@@ -64,14 +64,14 @@ public class PlotContentLineChart extends PlotContent {
Collection<?> xData = series.getxData(); Collection<?> xData = series.getxData();
BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin(); BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin();
BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax(); BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax();
if (getChart().getStyleManager().isXAxisLogarithmic()) { if (getChart().getStyleManager().isxAxisLogarithmic()) {
xMin = new BigDecimal(Math.log10(xMin.doubleValue())); xMin = new BigDecimal(Math.log10(xMin.doubleValue()));
xMax = new BigDecimal(Math.log10(xMax.doubleValue())); xMax = new BigDecimal(Math.log10(xMax.doubleValue()));
} }
Collection<Number> yData = series.getyData(); Collection<Number> yData = series.getyData();
BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin();
BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax();
if (getChart().getStyleManager().isYAxisLogarithmic()) { if (getChart().getStyleManager().isyAxisLogarithmic()) {
yMin = new BigDecimal(Math.log10(yMin.doubleValue())); yMin = new BigDecimal(Math.log10(yMin.doubleValue()));
yMax = new BigDecimal(Math.log10(yMax.doubleValue())); yMax = new BigDecimal(Math.log10(yMax.doubleValue()));
} }
...@@ -97,13 +97,13 @@ public class PlotContentLineChart extends PlotContent { ...@@ -97,13 +97,13 @@ public class PlotContentLineChart extends PlotContent {
// System.out.println(x); // System.out.println(x);
} }
if (getChart().getStyleManager().isXAxisLogarithmic()) { if (getChart().getStyleManager().isxAxisLogarithmic()) {
x = new BigDecimal(Math.log10(x.doubleValue())); x = new BigDecimal(Math.log10(x.doubleValue()));
} }
BigDecimal y = new BigDecimal(yItr.next().doubleValue()); BigDecimal y = new BigDecimal(yItr.next().doubleValue());
if (getChart().getStyleManager().isYAxisLogarithmic()) { if (getChart().getStyleManager().isyAxisLogarithmic()) {
y = new BigDecimal(Math.log10(y.doubleValue())); y = new BigDecimal(Math.log10(y.doubleValue()));
} }
......
...@@ -90,6 +90,7 @@ public class DateFormatter { ...@@ -90,6 +90,7 @@ public class DateFormatter {
String datePattern; String datePattern;
if (styleManager.getDatePattern() == null) {
// intelligently set date pattern if none is given // intelligently set date pattern if none is given
if (timeUnit == MILLIS_SCALE) { if (timeUnit == MILLIS_SCALE) {
datePattern = "ss.SSS"; datePattern = "ss.SSS";
...@@ -106,6 +107,9 @@ public class DateFormatter { ...@@ -106,6 +107,9 @@ public class DateFormatter {
} else { } else {
datePattern = "yyyy"; datePattern = "yyyy";
} }
} else {
datePattern = styleManager.getDatePattern();
}
SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale()); SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale());
simpleDateformat.setTimeZone(styleManager.getTimezone()); simpleDateformat.setTimeZone(styleManager.getTimezone());
......
...@@ -166,7 +166,7 @@ public class StyleManager { ...@@ -166,7 +166,7 @@ public class StyleManager {
errorBarsColor = theme.getErrorBarsColor(); errorBarsColor = theme.getErrorBarsColor();
// Formatting //////////////////////////////// // Formatting ////////////////////////////////
datePattern = "HHmmss"; datePattern = null; // if not null, this override pattern will be used
locale = Locale.getDefault(); locale = Locale.getDefault();
timezone = TimeZone.getDefault(); timezone = TimeZone.getDefault();
normalDecimalPattern = "#.####"; normalDecimalPattern = "#.####";
...@@ -656,14 +656,14 @@ public class StyleManager { ...@@ -656,14 +656,14 @@ public class StyleManager {
/** /**
* sets the X-Axis to be rendered with a logarithmic scale or not * sets the X-Axis to be rendered with a logarithmic scale or not
* *
* @param isXAxisLogarithmic * @param isxAxisLogarithmic
*/ */
public void setXAxisLogarithmic(boolean isXAxisLogarithmic) { public void setxAxisLogarithmic(boolean isxAxisLogarithmic) {
this.isXAxisLogarithmic = isXAxisLogarithmic; this.isXAxisLogarithmic = isxAxisLogarithmic;
} }
public boolean isXAxisLogarithmic() { public boolean isxAxisLogarithmic() {
return isXAxisLogarithmic; return isXAxisLogarithmic;
} }
...@@ -671,14 +671,14 @@ public class StyleManager { ...@@ -671,14 +671,14 @@ public class StyleManager {
/** /**
* sets the Y-Axis to be rendered with a logarithmic scale or not * sets the Y-Axis to be rendered with a logarithmic scale or not
* *
* @param isYAxisLogarithmic * @param isyAxisLogarithmic
*/ */
public void setYAxisLogarithmic(boolean isYAxisLogarithmic) { public void setyAxisLogarithmic(boolean isyAxisLogarithmic) {
this.isYAxisLogarithmic = isYAxisLogarithmic; this.isYAxisLogarithmic = isyAxisLogarithmic;
} }
public boolean isYAxisLogarithmic() { public boolean isyAxisLogarithmic() {
return isYAxisLogarithmic; return isYAxisLogarithmic;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment