Skip to content
Snippets Groups Projects
Commit a00e15cf authored by Tim Molter's avatar Tim Molter Committed by Niklas Polke
Browse files

messing around

parent 6db2a739
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,6 @@ import java.util.Random; ...@@ -25,7 +25,6 @@ import java.util.Random;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.StyleManager.TextAlignment;
import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart; import com.xeiam.xchart.demo.charts.ExampleChart;
...@@ -47,9 +46,11 @@ public class DateChart08 implements ExampleChart { ...@@ -47,9 +46,11 @@ public class DateChart08 implements ExampleChart {
// Create Chart // Create Chart
Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build(); Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build();
chart.getStyleManager().setLegendVisible(false); chart.getStyleManager().setLegendVisible(false);
chart.getStyleManager().setXAxisLabelRotation(45); // chart.getStyleManager().setXAxisLabelRotation(45);
// chart.getStyleManager().setYAxisLabelRotation(90); // chart.getStyleManager().setXAxisLabelRotation(90);
chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); // chart.getStyleManager().setXAxisLabelRotation(20);
// chart.getStyleManager().setXAxisLabelRotation(80);
// chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
chart.getStyleManager().setDatePattern("yyyy-MM-dd"); chart.getStyleManager().setDatePattern("yyyy-MM-dd");
// generate data // generate data
......
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.StyleManager.LegendPosition; import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.StyleManager.TextAlignment;
import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart; import com.xeiam.xchart.demo.charts.ExampleChart;
...@@ -60,6 +61,7 @@ public class LineChart01 implements ExampleChart { ...@@ -60,6 +61,7 @@ public class LineChart01 implements ExampleChart {
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);
chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
// Series // Series
chart.addSeries("10^x", xData, yData); chart.addSeries("10^x", xData, yData);
......
...@@ -22,8 +22,6 @@ import java.awt.font.FontRenderContext; ...@@ -22,8 +22,6 @@ import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout; import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.xeiam.xchart.StyleManager.LegendPosition; import com.xeiam.xchart.StyleManager.LegendPosition;
...@@ -152,8 +150,32 @@ public class Axis implements ChartPart { ...@@ -152,8 +150,32 @@ public class Axis implements ChartPart {
double yOffset = getChartPainter().getChartTitle().getSizeHint(); double yOffset = getChartPainter().getChartTitle().getSizeHint();
double width = 80; // arbitrary, final width depends on Axis tick labels double width = 80; // arbitrary, final width depends on Axis tick labels
double chartLegendWidth = 0;
if (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE) {
chartLegendWidth = getChartPainter().getChartLegend().getSizeHint(g)[0];
}
double approximateXAxisWidth =
getChartPainter().getWidth()
- width // y-axis approx. width
- chartLegendWidth
- 2
* getChartPainter().getStyleManager().getChartPadding()
- (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0)
- (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager()
.getChartPadding() : 0)
;
double height = double height =
getChartPainter().getHeight() - yOffset - axisPair.getXAxis().getSizeHint() - getChartPainter().getStyleManager().getPlotPadding() - getChartPainter().getStyleManager().getChartPadding(); getChartPainter().getHeight() - yOffset - axisPair.getXAxis().getXAxisHeightHint(approximateXAxisWidth) - getChartPainter().getStyleManager().getPlotPadding()
- getChartPainter().getStyleManager().getChartPadding();
Rectangle2D yAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); Rectangle2D yAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
this.paintZone = yAxisRectangle; this.paintZone = yAxisRectangle;
g.setColor(Color.green); g.setColor(Color.green);
...@@ -206,21 +228,19 @@ public class Axis implements ChartPart { ...@@ -206,21 +228,19 @@ public class Axis implements ChartPart {
; ;
double height = this.getSizeHint(); double height = this.getXAxisHeightHint(width);
Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
// the paint zone
this.paintZone = xAxisRectangle; this.paintZone = xAxisRectangle;
g.setColor(Color.green); g.setColor(Color.green);
g.draw(xAxisRectangle); g.draw(xAxisRectangle);
// now paint the X-Axis given the above paint zone
axisTitle.paint(g); axisTitle.paint(g);
axisTick.paint(g); axisTick.paint(g);
xOffset = paintZone.getX(); bounds = paintZone;
yOffset = paintZone.getY();
width = paintZone.getWidth();
height = (getChartPainter().getStyleManager().isXAxisTitleVisible() ? axisTitle.getBounds().getHeight() : 0) + axisTick.getBounds().getHeight();
bounds = new Rectangle2D.Double(xOffset, yOffset, width, height);
g.setColor(Color.yellow); g.setColor(Color.yellow);
g.draw(bounds); g.draw(bounds);
...@@ -231,9 +251,7 @@ public class Axis implements ChartPart { ...@@ -231,9 +251,7 @@ public class Axis implements ChartPart {
/** /**
* @return * @return
*/ */
private double getSizeHint() { private double getXAxisHeightHint(double workingSpace) {
if (direction == Direction.X) { // X-Axis
// Axis title // Axis title
double titleHeight = 0.0; double titleHeight = 0.0;
...@@ -246,9 +264,14 @@ public class Axis implements ChartPart { ...@@ -246,9 +264,14 @@ public class Axis implements ChartPart {
// Axis tick labels // Axis tick labels
double axisTickLabelsHeight = 0.0; double axisTickLabelsHeight = 0.0;
if (getChartPainter().getStyleManager().isXAxisTicksVisible()) { if (getChartPainter().getStyleManager().isXAxisTicksVisible()) {
String tickLabel =
getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ? new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0"; // get some real tick labels
TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); AxisTickCalculator axisTickCalculator = axisTick.getAxisTickCalculator(workingSpace);
String sampleLabel = axisTickCalculator.getTickLabels().get(0);
// String tickLabel =
// getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ? new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0";
TextLayout textLayout = new TextLayout(sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
AffineTransform rot = AffineTransform rot =
getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot); Shape shape = textLayout.getOutline(rot);
...@@ -257,10 +280,6 @@ public class Axis implements ChartPart { ...@@ -257,10 +280,6 @@ public class Axis implements ChartPart {
} }
return titleHeight + axisTickLabelsHeight; return titleHeight + axisTickLabelsHeight;
} }
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
}
}
@Override @Override
public ChartPainter getChartPainter() { public ChartPainter getChartPainter() {
......
...@@ -74,31 +74,7 @@ public class AxisTick implements ChartPart { ...@@ -74,31 +74,7 @@ public class AxisTick implements ChartPart {
// System.out.println("workingspace= " + workingSpace); // System.out.println("workingspace= " + workingSpace);
} }
if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().getChartType() == ChartType.Bar) { axisTickCalculator = getAxisTickCalculator(workingSpace);
axisTickCalculator = new AxisTickBarChartCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter());
}
else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
axisTickCalculator = 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) {
axisTickCalculator = new AxisTickLogarithmicCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
}
else if (axis.getAxisType() == AxisType.Number) {
axisTickCalculator = new AxisTickNumericalCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
}
else if (axis.getAxisType() == AxisType.Date) {
axisTickCalculator = new AxisTickDateCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
}
if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) { if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) {
...@@ -136,6 +112,35 @@ public class AxisTick implements ChartPart { ...@@ -136,6 +112,35 @@ public class AxisTick implements ChartPart {
} }
public AxisTickCalculator getAxisTickCalculator(double workingSpace) {
if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().getChartType() == ChartType.Bar) {
return new AxisTickBarChartCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter());
}
else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) {
return 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) {
return new AxisTickLogarithmicCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
}
else if (axis.getAxisType() == AxisType.Date) {
return new AxisTickDateCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
}
else { // number
return new AxisTickNumericalCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChartPainter().getStyleManager());
}
}
@Override @Override
public ChartPainter getChartPainter() { public ChartPainter getChartPainter() {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.xeiam.xchart.internal.chartpart; package com.xeiam.xchart.internal.chartpart;
import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
...@@ -170,8 +171,9 @@ public class AxisTickLabels implements ChartPart { ...@@ -170,8 +171,9 @@ public class AxisTickLabels implements ChartPart {
g.setTransform(orig); g.setTransform(orig);
// // debug box // // debug box
// g.setColor(Color.blue); g.setColor(Color.MAGENTA);
// g.draw(new Rectangle2D.Double(xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight())); g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight()));
g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor());
if (tickLabelBounds.getHeight() > maxTickLabelHeight) { if (tickLabelBounds.getHeight() > maxTickLabelHeight) {
maxTickLabelHeight = tickLabelBounds.getHeight(); maxTickLabelHeight = tickLabelBounds.getHeight();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment