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;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.StyleManager.TextAlignment;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart;
......@@ -47,9 +46,11 @@ public class DateChart08 implements ExampleChart {
// Create Chart
Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build();
chart.getStyleManager().setLegendVisible(false);
chart.getStyleManager().setXAxisLabelRotation(45);
// chart.getStyleManager().setYAxisLabelRotation(90);
chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
// chart.getStyleManager().setXAxisLabelRotation(45);
// chart.getStyleManager().setXAxisLabelRotation(90);
// chart.getStyleManager().setXAxisLabelRotation(20);
// chart.getStyleManager().setXAxisLabelRotation(80);
// chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
chart.getStyleManager().setDatePattern("yyyy-MM-dd");
// generate data
......
......@@ -21,6 +21,7 @@ import java.util.List;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartBuilder;
import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.StyleManager.TextAlignment;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart;
......@@ -60,6 +61,7 @@ public class LineChart01 implements ExampleChart {
chart.getStyleManager().setChartTitleVisible(false);
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setYAxisLogarithmic(true);
chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
// Series
chart.addSeries("10^x", xData, yData);
......
......@@ -22,8 +22,6 @@ import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.xeiam.xchart.StyleManager.LegendPosition;
......@@ -152,8 +150,32 @@ public class Axis implements ChartPart {
double yOffset = getChartPainter().getChartTitle().getSizeHint();
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 =
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);
this.paintZone = yAxisRectangle;
g.setColor(Color.green);
......@@ -180,7 +202,7 @@ public class Axis implements ChartPart {
double xOffset =
axisPair.getYAxis().getBounds().getWidth() + (getChartPainter().getStyleManager().isYAxisTicksVisible() ? getChartPainter().getStyleManager().getPlotPadding() : 0)
+ getChartPainter().getStyleManager().getChartPadding();
+ getChartPainter().getStyleManager().getChartPadding();
double yOffset = axisPair.getYAxis().getBounds().getY() + axisPair.getYAxis().getBounds().getHeight() + getChartPainter().getStyleManager().getPlotPadding();
double chartLegendWidth = 0;
......@@ -192,35 +214,33 @@ public class Axis implements ChartPart {
getChartPainter().getWidth()
- axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted
- axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted
- 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)
;
;
double height = this.getSizeHint();
double height = this.getXAxisHeightHint(width);
Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
// the paint zone
this.paintZone = xAxisRectangle;
g.setColor(Color.green);
g.draw(xAxisRectangle);
// now paint the X-Axis given the above paint zone
axisTitle.paint(g);
axisTick.paint(g);
xOffset = paintZone.getX();
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);
bounds = paintZone;
g.setColor(Color.yellow);
g.draw(bounds);
......@@ -231,35 +251,34 @@ public class Axis implements ChartPart {
/**
* @return
*/
private double getSizeHint() {
if (direction == Direction.X) { // X-Axis
// Axis title
double titleHeight = 0.0;
if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) {
TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartPainter().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false));
Rectangle2D rectangle = textLayout.getBounds();
titleHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding();
}
// Axis tick labels
double axisTickLabelsHeight = 0.0;
if (getChartPainter().getStyleManager().isXAxisTicksVisible()) {
String tickLabel =
getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ? new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0";
TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
AffineTransform rot =
getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength();
}
return titleHeight + axisTickLabelsHeight;
private double getXAxisHeightHint(double workingSpace) {
// Axis title
double titleHeight = 0.0;
if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) {
TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartPainter().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false));
Rectangle2D rectangle = textLayout.getBounds();
titleHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding();
}
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
// Axis tick labels
double axisTickLabelsHeight = 0.0;
if (getChartPainter().getStyleManager().isXAxisTicksVisible()) {
// get some real tick labels
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 =
getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength();
}
return titleHeight + axisTickLabelsHeight;
}
@Override
......
......@@ -74,31 +74,7 @@ public class AxisTick implements ChartPart {
// System.out.println("workingspace= " + workingSpace);
}
if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().getChartType() == ChartType.Bar) {
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());
}
axisTickCalculator = getAxisTickCalculator(workingSpace);
if (axis.getDirection() == Axis.Direction.Y && getChartPainter().getStyleManager().isYAxisTicksVisible()) {
......@@ -107,15 +83,15 @@ public class AxisTick implements ChartPart {
bounds = new Rectangle2D.Double(
axisTickLabels.getBounds().getX(),
axisTickLabels.getBounds().getX(),
axisTickLabels.getBounds().getY(),
axisTickLabels.getBounds().getY(),
axisTickLabels.getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(),
axisTickLabels.getBounds().getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + axisTickMarks.getBounds().getWidth(),
axisTickMarks.getBounds().getHeight()
axisTickMarks.getBounds().getHeight()
);
);
// g.setColor(Color.red);
// g.draw(bounds);
......@@ -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
public ChartPainter getChartPainter() {
......
......@@ -15,6 +15,7 @@
*/
package com.xeiam.xchart.internal.chartpart;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
......@@ -170,8 +171,9 @@ public class AxisTickLabels implements ChartPart {
g.setTransform(orig);
// // debug box
// g.setColor(Color.blue);
// g.draw(new Rectangle2D.Double(xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight()));
g.setColor(Color.MAGENTA);
g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight()));
g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor());
if (tickLabelBounds.getHeight() > maxTickLabelHeight) {
maxTickLabelHeight = tickLabelBounds.getHeight();
......
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