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

messing around

parent e7a6cd19
Branches
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);
......@@ -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);
// 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,9 +251,7 @@ public class Axis implements ChartPart {
/**
* @return
*/
private double getSizeHint() {
if (direction == Direction.X) { // X-Axis
private double getXAxisHeightHint(double workingSpace) {
// Axis title
double titleHeight = 0.0;
......@@ -246,9 +264,14 @@ public class Axis implements ChartPart {
// 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));
// 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);
......@@ -257,10 +280,6 @@ public class Axis implements ChartPart {
}
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
public ChartPainter getChartPainter() {
......
......@@ -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()) {
......@@ -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.
Please register or to comment