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

drawing y-axis label differently

parent d76c2f09
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ import com.xeiam.xchart.internal.interfaces.IChartPart; ...@@ -29,7 +29,7 @@ import com.xeiam.xchart.internal.interfaces.IChartPart;
public class AxisTickLabels implements IChartPart { public class AxisTickLabels implements IChartPart {
/** parent */ /** parent */
private AxisTick axisTick; private final AxisTick axisTick;
/** the font */ /** the font */
public Font font; public Font font;
...@@ -58,6 +58,7 @@ public class AxisTickLabels implements IChartPart { ...@@ -58,6 +58,7 @@ public class AxisTickLabels implements IChartPart {
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
bounds = new Rectangle(); bounds = new Rectangle();
g.setFont(font);
g.setColor(axisTick.axis.axisPair.chart.fontColor); g.setColor(axisTick.axis.axisPair.chart.fontColor);
......
...@@ -96,6 +96,7 @@ public class AxisTitle implements IChartPart, IHideable { ...@@ -96,6 +96,7 @@ public class AxisTitle implements IChartPart, IHideable {
bounds = new Rectangle(); bounds = new Rectangle();
g.setColor(axis.axisPair.chart.fontColor); g.setColor(axis.axisPair.chart.fontColor);
g.setFont(font);
if (axis.direction == Axis.Direction.Y) { if (axis.direction == Axis.Direction.Y) {
if (isVisible) { if (isVisible) {
...@@ -105,20 +106,28 @@ public class AxisTitle implements IChartPart, IHideable { ...@@ -105,20 +106,28 @@ public class AxisTitle implements IChartPart, IHideable {
Rectangle nonRotatedRectangle = nonRotatedTextLayout.getPixelBounds(null, 0, 0); Rectangle nonRotatedRectangle = nonRotatedTextLayout.getPixelBounds(null, 0, 0);
// System.out.println(nonRotatedRectangle); // System.out.println(nonRotatedRectangle);
AffineTransform at = new AffineTransform(); // ///////////////////////////////////////////////
// Tx.translate(anchorx, anchory); // S3: final translation
double theta = Math.PI / -2.0; // AffineTransform at = new AffineTransform();
at.rotate(theta); // S2: rotate around anchor // // Tx.translate(anchorx, anchory); // S3: final translation
// Tx.translate(-anchorx, -anchory); // S1: translate anchor to origin // double theta = Math.PI / -2.0;
Font derivedFont = font.deriveFont(at); // at.rotate(theta); // S2: rotate around anchor
TextLayout rotatedTextLayout = new TextLayout(text, derivedFont, frc); // // Tx.translate(-anchorx, -anchory); // S1: translate anchor to origin
// TextLayout rotatedTextLayout = new TextLayout(text, font.deriveFont(AffineTransform.getRotateInstance(Math.PI / -2.0, 0, 0)), frc); // Font derivedFont = font.deriveFont(at);
// Rectangle rotatedRectangle = rotatedTextLayout.getPixelBounds(null, 0, 0); // TextLayout rotatedTextLayout = new TextLayout(text, derivedFont, frc);
// System.out.println(rotatedRectangle); // // TextLayout rotatedTextLayout = new TextLayout(text, font.deriveFont(AffineTransform.getRotateInstance(Math.PI / -2.0, 0, 0)), frc);
// // Rectangle rotatedRectangle = rotatedTextLayout.getPixelBounds(null, 0, 0);
// // System.out.println(rotatedRectangle);
//
int xOffset = (int) (axis.getPaintZone().getX() + nonRotatedRectangle.getHeight()); int xOffset = (int) (axis.getPaintZone().getX() + nonRotatedRectangle.getHeight());
int yOffset = (int) ((axis.getPaintZone().getHeight() + nonRotatedRectangle.getWidth()) / 2.0 + axis.getPaintZone().getY()); int yOffset = (int) ((axis.getPaintZone().getHeight() + nonRotatedRectangle.getWidth()) / 2.0 + axis.getPaintZone().getY());
rotatedTextLayout.draw(g, xOffset, yOffset); AffineTransform orig = g.getTransform();
g.transform(AffineTransform.getRotateInstance(Math.PI / -2.0, xOffset, yOffset));
g.drawString(text, xOffset, yOffset);
// rotatedTextLayout.draw(g, xOffset, yOffset);
// ///////////////////////////////////////////////
g.setTransform(orig);
// bounds // bounds
bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight() + AXIS_TITLE_PADDING, bounds = new Rectangle((int) (xOffset - nonRotatedRectangle.getHeight()), (int) (yOffset - nonRotatedRectangle.getWidth()), (int) nonRotatedRectangle.getHeight() + AXIS_TITLE_PADDING,
......
...@@ -31,7 +31,7 @@ import com.xeiam.xchart.internal.interfaces.IHideable; ...@@ -31,7 +31,7 @@ import com.xeiam.xchart.internal.interfaces.IHideable;
public class ChartTitle implements IChartPart, IHideable { public class ChartTitle implements IChartPart, IHideable {
/** parent */ /** parent */
private Chart chart; private final Chart chart;
/** the title text */ /** the title text */
protected String text = ""; // default to "" protected String text = ""; // default to ""
...@@ -76,6 +76,7 @@ public class ChartTitle implements IChartPart, IHideable { ...@@ -76,6 +76,7 @@ public class ChartTitle implements IChartPart, IHideable {
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
bounds = new Rectangle(); bounds = new Rectangle();
g.setFont(font);
if (isVisible) { if (isVisible) {
......
...@@ -38,7 +38,7 @@ public class Legend implements IChartPart, IHideable { ...@@ -38,7 +38,7 @@ public class Legend implements IChartPart, IHideable {
private static final int LEGEND_PADDING = 10; private static final int LEGEND_PADDING = 10;
/** parent */ /** parent */
private Chart chart; private final Chart chart;
/** the visibility state of legend */ /** the visibility state of legend */
protected boolean isVisible = true; // default to true protected boolean isVisible = true; // default to true
...@@ -74,6 +74,7 @@ public class Legend implements IChartPart, IHideable { ...@@ -74,6 +74,7 @@ public class Legend implements IChartPart, IHideable {
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
bounds = new Rectangle(); bounds = new Rectangle();
g.setFont(font);
if (isVisible) { if (isVisible) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment