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

format [ci skip]

parent 71275ae7
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@ public class DateChart08 implements ExampleChart {
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().setYAxisLabelRotation(90);
chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
chart.getStyleManager().setDatePattern("yyyy-MM-dd");
......
......@@ -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;
......@@ -28,7 +29,7 @@ import com.xeiam.xchart.StyleManager.LegendPosition;
/**
* Axis
*
*
* @author timmolter
*/
public class Axis implements ChartPart {
......@@ -75,7 +76,7 @@ public class Axis implements ChartPart {
/**
* Constructor
*
*
* @param direction the axis direction (X or Y)
* @param chart the chart
*/
......@@ -129,40 +130,6 @@ public class Axis implements ChartPart {
return bounds;
}
/**
* @return
*/
protected 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;
}
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 void paint(Graphics2D g) {
......@@ -188,8 +155,8 @@ public class Axis implements ChartPart {
Rectangle2D yAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
this.paintZone = yAxisRectangle;
// g.setColor(Color.green);
// g.draw(yAxisRectangle);
g.setColor(Color.green);
g.draw(yAxisRectangle);
// fill in Axis with sub-components
axisTitle.paint(g);
......@@ -201,8 +168,8 @@ public class Axis implements ChartPart {
height = paintZone.getHeight();
bounds = new Rectangle2D.Double(xOffset, yOffset, width, height);
// g.setColor(Color.yellow);
// g.draw(bounds);
g.setColor(Color.yellow);
g.draw(bounds);
}
else { // X-Axis
......@@ -242,8 +209,8 @@ public class Axis implements ChartPart {
Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
this.paintZone = xAxisRectangle;
// g.setColor(Color.green);
// g.draw(xAxisRectangle);
g.setColor(Color.green);
g.draw(xAxisRectangle);
axisTitle.paint(g);
axisTick.paint(g);
......@@ -253,12 +220,49 @@ public class Axis implements ChartPart {
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.draw(bounds);
g.setColor(Color.yellow);
g.draw(bounds);
}
}
/**
* @return
*/
private double getSizeHint() {
System.out.println(axisTick.getTickLabels());
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;
}
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() {
......
......@@ -15,6 +15,7 @@
*/
package com.xeiam.xchart.internal.chartpart;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.List;
......@@ -43,7 +44,7 @@ public class AxisTick implements ChartPart {
/**
* Constructor
*
*
* @param axis
*/
protected AxisTick(Axis axis) {
......@@ -115,8 +116,8 @@ public class AxisTick implements ChartPart {
);
// g.setColor(Color.red);
// g.draw(bounds);
g.setColor(Color.red);
g.draw(bounds);
}
else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) {
......
......@@ -68,6 +68,7 @@ public class AxisTickLabels implements ChartPart {
Map<Double, TextLayout> axisLabelTextLayouts = new HashMap<Double, TextLayout>();
for (int i = 0; i < axisTick.getTickLabels().size(); i++) {
String tickLabel = axisTick.getTickLabels().get(i);
// System.out.println("** " + tickLabel);
double tickLocation = axisTick.getTickLocations().get(i);
......
......@@ -78,6 +78,7 @@ public class ChartTitle implements ChartPart {
return chartPainter.getStyleManager().getChartPadding() + 2 * chartPainter.getStyleManager().getChartTitlePadding() + titleHeight;
}
else {
// TODO make this zero
return chartPainter.getStyleManager().getChartPadding();
}
}
......
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