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

format

parent 6a4d487e
No related branches found
No related tags found
No related merge requests found
Showing
with 98 additions and 59 deletions
......@@ -62,9 +62,11 @@ public class Chart {
if (chartTheme == ChartTheme.XChart) {
setTheme(new XChartTheme());
} else if (chartTheme == ChartTheme.GGPlot2) {
}
else if (chartTheme == ChartTheme.GGPlot2) {
setTheme(new GGPlot2Theme());
} else if (chartTheme == ChartTheme.Matlab) {
}
else if (chartTheme == ChartTheme.Matlab) {
setTheme(new MatlabTheme());
}
}
......
......@@ -17,7 +17,6 @@ package com.xeiam.xchart;
import java.util.Collection;
/**
* A convenience class for making Charts with one line of code
*
......@@ -51,7 +50,8 @@ public final class QuickChart {
double[][] yData2d = { yData };
if (seriesName == null) {
return getChart(chartTitle, xTitle, yTitle, null, xData, yData2d);
} else {
}
else {
return getChart(chartTitle, xTitle, yTitle, new String[] { seriesName }, xData, yData2d);
}
}
......@@ -82,7 +82,8 @@ public final class QuickChart {
Series series;
if (seriesNames != null) {
series = chart.addSeries(seriesNames[i], xData, yData[i]);
} else {
}
else {
chart.getStyleManager().setLegendVisible(false);
series = chart.addSeries(" " + i, xData, yData[i]);
}
......
......@@ -99,7 +99,8 @@ public class Series {
BigDecimal[] yMinMax = null;
if (errorBars == null) {
yMinMax = findMinMax(yData, yAxisType);
} else {
}
else {
yMinMax = findMinMaxWithErrorBars(yData, errorBars);
}
yMin = yMinMax[0];
......@@ -130,10 +131,12 @@ public class Series {
if (axisType == AxisType.Number) {
bigDecimal = new BigDecimal(((Number) dataPoint).toString());
} else if (axisType == AxisType.Date) {
}
else if (axisType == AxisType.Date) {
Date date = (Date) dataPoint;
bigDecimal = new BigDecimal(date.getTime());
} else if (axisType == AxisType.String) {
}
else if (axisType == AxisType.String) {
return new BigDecimal[] { null, null };
}
if (min == null || bigDecimal.compareTo(min) < 0) {
......
......@@ -116,7 +116,8 @@ public class SwingWrapper {
if (chart != null) {
JPanel chartPanel = new XChartPanel(chart);
frame.add(chartPanel);
} else {
}
else {
JPanel chartPanel = new JPanel();
frame.getContentPane().add(chartPanel);
}
......
......@@ -140,7 +140,8 @@ public class Axis implements ChartPart {
axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength();
}
return titleHeight + axisTickLabelsHeight;
} else { // Y-Axis
}
else { // Y-Axis
return 0; // We layout the yAxis first depending in the xAxis height hint. We don't care about the yAxis height hint
}
}
......@@ -165,8 +166,8 @@ public class Axis implements ChartPart {
double yOffset = getChartPainter().getChartTitle().getSizeHint();
double width = 80; // arbitrary, final width depends on Axis tick labels
double height = getChartPainter().getHeight() - yOffset - axisPair.getxAxis().getSizeHint() - getChartPainter().getStyleManager().getPlotPadding()
- getChartPainter().getStyleManager().getChartPadding();
double height =
getChartPainter().getHeight() - yOffset - axisPair.getxAxis().getSizeHint() - getChartPainter().getStyleManager().getPlotPadding() - getChartPainter().getStyleManager().getChartPadding();
Rectangle2D yAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
this.paintZone = yAxisRectangle;
......@@ -186,13 +187,15 @@ public class Axis implements ChartPart {
// g.setColor(Color.yellow);
// g.draw(bounds);
} else { // X-Axis
}
else { // X-Axis
// calculate paint zone
// |____________________|
double xOffset = axisPair.getyAxis().getBounds().getWidth() + (getChartPainter().getStyleManager().isYAxisTicksVisible() ? getChartPainter().getStyleManager().getPlotPadding() : 0)
+ getChartPainter().getStyleManager().getChartPadding();
double xOffset =
axisPair.getyAxis().getBounds().getWidth() + (getChartPainter().getStyleManager().isYAxisTicksVisible() ? getChartPainter().getStyleManager().getPlotPadding() : 0)
+ getChartPainter().getStyleManager().getChartPadding();
double yOffset = axisPair.getyAxis().getBounds().getY() + axisPair.getyAxis().getBounds().getHeight() + getChartPainter().getStyleManager().getPlotPadding();
double chartLegendWidth = 0;
......@@ -202,19 +205,19 @@ public class Axis implements ChartPart {
double width =
getChartPainter().getWidth()
getChartPainter().getWidth()
- axisPair.getyAxis().getBounds().getWidth()
- axisPair.getyAxis().getBounds().getWidth()
- chartLegendWidth
- chartLegendWidth
- 2
* getChartPainter().getStyleManager().getChartPadding()
- 2
* getChartPainter().getStyleManager().getChartPadding()
- (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0)
- (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0)
- (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager()
.getChartPadding() : 0)
- (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager()
.getChartPadding() : 0)
;
......
......@@ -87,14 +87,17 @@ public class AxisPair implements ChartPart {
Object dataPoint = itr.next();
if (dataPoint instanceof Number) {
xAxis.setAxisType(AxisType.Number);
} else if (dataPoint instanceof Date) {
}
else if (dataPoint instanceof Date) {
xAxis.setAxisType(AxisType.Date);
} else if (dataPoint instanceof String) {
}
else if (dataPoint instanceof String) {
xAxis.setAxisType(AxisType.String);
}
yAxis.setAxisType(AxisType.Number);
series = new Series(seriesName, xData, xAxis.getAxisType(), yData, yAxis.getAxisType(), errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle());
} else { // generate xData
}
else { // generate xData
Collection<Number> generatedXData = new ArrayList<Number>();
for (int i = 1; i < yData.size() + 1; i++) {
generatedXData.add(i);
......
......@@ -66,7 +66,8 @@ public class AxisTick implements ChartPart {
if (axis.getDirection() == Axis.Direction.Y) {
workingSpace = (int) axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace);
} else if (axis.getDirection() == Axis.Direction.X) {
}
else if (axis.getDirection() == Axis.Direction.X) {
workingSpace = (int) axis.getPaintZone().getWidth(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace);
}
......@@ -75,19 +76,23 @@ public class AxisTick implements ChartPart {
gridStep = new AxisTickBarChartCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter());
} else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
}
else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
gridStep = new AxisTickLogarithmicCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
} else if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
}
else if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
gridStep = new AxisTickLogarithmicCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
} else if (axis.getAxisType() == AxisType.Number) {
}
else if (axis.getAxisType() == AxisType.Number) {
gridStep = new AxisTickNumericalCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
} else if (axis.getAxisType() == AxisType.Date) {
}
else if (axis.getAxisType() == AxisType.Date) {
gridStep = new AxisTickDateCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
......@@ -113,13 +118,15 @@ public class AxisTick implements ChartPart {
// g.setColor(Color.red);
// g.draw(bounds);
} else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) {
}
else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) {
axisTickLabels.paint(g);
axisTickMarks.paint(g);
bounds = new Rectangle2D.Double(axisTickMarks.getBounds().getX(), axisTickMarks.getBounds().getY(), axisTickLabels.getBounds().getWidth(), axisTickMarks.getBounds().getHeight()
+ getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight());
bounds =
new Rectangle2D.Double(axisTickMarks.getBounds().getX(), axisTickMarks.getBounds().getY(), axisTickLabels.getBounds().getWidth(), axisTickMarks.getBounds().getHeight()
+ getChartPainter().getStyleManager().getAxisTickPadding() + axisTickLabels.getBounds().getHeight());
// g.setColor(Color.red);
// g.draw(bounds);
......
......@@ -83,7 +83,8 @@ public class AxisTickLabels implements ChartPart {
// g.setColor(Color.blue);
// g.draw(bounds);
} else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis
}
else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis
double xOffset = axisTick.getAxis().getPaintZone().getX();
double yOffset = axisTick.getAxis().getAxisTitle().getBounds().getY();
......
......@@ -65,8 +65,9 @@ public class AxisTickMarks implements ChartPart {
int tickLocation = axisTick.getTickLocations().get(i);
Shape line = new Line2D.Double(xOffset, yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(),
yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation);
Shape line =
new Line2D.Double(xOffset, yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset
+ axisTick.getAxis().getPaintZone().getHeight() - tickLocation);
g.draw(line);
}
......@@ -74,8 +75,9 @@ public class AxisTickMarks implements ChartPart {
// Line
if (getChartPainter().getStyleManager().isAxisTicksLineVisible()) {
Shape line = new Line2D.Double(xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset
+ axisTick.getAxis().getPaintZone().getHeight());
Shape line =
new Line2D.Double(xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset, xOffset + getChartPainter().getStyleManager().getAxisTickMarkLength(), yOffset
+ axisTick.getAxis().getPaintZone().getHeight());
g.draw(line);
}
......@@ -85,7 +87,8 @@ public class AxisTickMarks implements ChartPart {
// g.setColor(Color.yellow);
// g.draw(bounds);
} else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis
}
else if (axisTick.getAxis().getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { // X-Axis
double xOffset = axisTick.getAxis().getPaintZone().getX();
double yOffset = axisTick.getAxisTickLabels().getBounds().getY() - getChartPainter().getStyleManager().getAxisTickPadding();
......@@ -104,14 +107,16 @@ public class AxisTickMarks implements ChartPart {
// Line
if (getChartPainter().getStyleManager().isAxisTicksLineVisible()) {
Shape line = new Line2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), xOffset + axisTick.getAxis().getPaintZone().getWidth(), yOffset
- getChartPainter().getStyleManager().getAxisTickMarkLength());
Shape line =
new Line2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), xOffset + axisTick.getAxis().getPaintZone().getWidth(), yOffset
- getChartPainter().getStyleManager().getAxisTickMarkLength());
g.draw(line);
}
// bounds
bounds = new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getWidth(), getChartPainter().getStyleManager()
.getAxisTickMarkLength());
bounds =
new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTickMarkLength(), axisTick.getAxis().getPaintZone().getWidth(), getChartPainter().getStyleManager()
.getAxisTickMarkLength());
// g.setColor(Color.yellow);
// g.draw(bounds);
}
......
......@@ -80,15 +80,18 @@ public class AxisTitle implements ChartPart {
// System.out.println(nonRotatedRectangle.getHeight());
// bounds
bounds = new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight()
+ getChartPainter().getStyleManager().getAxisTitlePadding(), nonRotatedRectangle.getWidth());
bounds =
new Rectangle2D.Double(xOffset - nonRotatedRectangle.getHeight(), yOffset - nonRotatedRectangle.getWidth(), nonRotatedRectangle.getHeight()
+ getChartPainter().getStyleManager().getAxisTitlePadding(), nonRotatedRectangle.getWidth());
// g.setColor(Color.blue);
// g.draw(bounds);
} else {
}
else {
bounds = new Rectangle2D.Double(axis.getPaintZone().getX(), axis.getPaintZone().getY(), 0, axis.getPaintZone().getHeight());
}
} else {
}
else {
if (text != null && !text.trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) {
......@@ -102,12 +105,14 @@ public class AxisTitle implements ChartPart {
textLayout.draw(g, (float) xOffset, (float) (yOffset - rectangle.getY()));
bounds = new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight()
+ getChartPainter().getStyleManager().getAxisTitlePadding());
bounds =
new Rectangle2D.Double(xOffset, yOffset - getChartPainter().getStyleManager().getAxisTitlePadding(), rectangle.getWidth(), rectangle.getHeight()
+ getChartPainter().getStyleManager().getAxisTitlePadding());
// g.setColor(Color.blue);
// g.draw(bounds);
} else {
}
else {
bounds = new Rectangle2D.Double(axis.getPaintZone().getX(), axis.getPaintZone().getY() + axis.getPaintZone().getHeight(), axis.getPaintZone().getWidth(), 0);
// g.setColor(Color.blue);
// g.draw(bounds);
......
......@@ -55,7 +55,8 @@ public class ChartTitle implements ChartPart {
if (text.trim().equalsIgnoreCase("")) {
chartPainter.getStyleManager().setChartTitleVisible(false);
} else {
}
else {
chartPainter.getStyleManager().setChartTitleVisible(true);
}
this.text = text;
......@@ -74,7 +75,8 @@ public class ChartTitle implements ChartPart {
Rectangle2D rectangle = textLayout.getBounds();
int titleHeight = (int) ((chartPainter.getStyleManager().isChartTitleVisible() ? rectangle.getHeight() : 0));
return chartPainter.getStyleManager().getChartPadding() + 2 * chartPainter.getStyleManager().getChartTitlePadding() + titleHeight;
} else {
}
else {
return chartPainter.getStyleManager().getChartPadding();
}
}
......
......@@ -84,7 +84,8 @@ public class Legend implements ChartPart {
double maxContentHeight = 0;
if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) {
maxContentHeight = Math.max(legendTextContentMaxHeight, Marker.SIZE);
} else {
}
else {
maxContentHeight = Math.max(legendTextContentMaxHeight, BOX_SIZE);
}
double legendContentHeight = maxContentHeight * seriesMap.size() + chartPainter.getStyleManager().getLegendPadding() * (seriesMap.size() - 1);
......@@ -93,14 +94,16 @@ public class Legend implements ChartPart {
double legendContentWidth = 0;
if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) {
legendContentWidth = 3.0 * Marker.SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
} else {
}
else {
legendContentWidth = BOX_SIZE + chartPainter.getStyleManager().getLegendPadding() + legendTextContentMaxWidth;
}
// Legend Box
double legendBoxWidth = legendContentWidth + 2 * chartPainter.getStyleManager().getLegendPadding();
double legendBoxHeight = legendContentHeight + 2 * chartPainter.getStyleManager().getLegendPadding();
return new double[] { legendBoxWidth, legendBoxHeight, maxContentHeight };
} else {
}
else {
return new double[] { 0, 0, 0 };
}
}
......@@ -175,7 +178,8 @@ public class Legend implements ChartPart {
g.setColor(series.getMarkerColor());
series.getMarker().paint(g, startx + (Marker.SIZE * 1.5), starty + maxContentHeight / 2.0);
}
} else {
}
else {
// paint little box
if (series.getStroke() != null) {
g.setColor(series.getStrokeColor());
......@@ -191,7 +195,8 @@ public class Legend implements ChartPart {
if (getChartPainter().getStyleManager().getChartType() != ChartType.Bar) {
layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + chartPainter.getStyleManager().getLegendPadding()), (float) (starty + (maxContentHeight - 1 + layout.getBounds()
.getHeight()) / 2.0));
} else {
}
else {
layout.draw(g, (float) (startx + BOX_SIZE + chartPainter.getStyleManager().getLegendPadding()), (float) (starty + (maxContentHeight + layout.getBounds().getHeight()) / 2.0));
}
starty = starty + maxContentHeight + chartPainter.getStyleManager().getLegendPadding();
......
......@@ -77,7 +77,8 @@ public class Plot implements ChartPart {
plotSurface.paint(g);
if (getChartPainter().getStyleManager().getChartType() == ChartType.Bar) {
this.plotContent = new PlotContentBarChart(this);
} else {
}
else {
this.plotContent = new PlotContentLineChart(this);
}
plotContent.paint(g);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment