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

tentatively fixed axis label rotation with correct translation

parent a00e15cf
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ 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().setXAxisLabelRotation(45);
// chart.getStyleManager().setXAxisLabelRotation(90);
// chart.getStyleManager().setXAxisLabelRotation(20);
// chart.getStyleManager().setXAxisLabelRotation(80);
......
......@@ -21,7 +21,6 @@ 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;
......@@ -61,7 +60,10 @@ public class LineChart01 implements ExampleChart {
chart.getStyleManager().setChartTitleVisible(false);
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setYAxisLogarithmic(true);
chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
// chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right);
chart.getStyleManager().setXAxisLabelRotation(45);
// chart.getStyleManager().setXAxisLabelRotation(90);
// chart.getStyleManager().setXAxisLabelRotation(0);
// Series
chart.addSeries("10^x", xData, yData);
......
......@@ -144,10 +144,10 @@ public class AxisTickLabels implements ChartPart {
FontRenderContext frc = g.getFontRenderContext();
TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc);
System.out.println(textLayout.getOutline(null).getBounds().toString());
// Shape shape = v.getOutline();
AffineTransform rot =
getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()), 0, 0);
Shape shape = textLayout.getOutline(rot);
Rectangle2D tickLabelBounds = shape.getBounds2D();
......@@ -165,12 +165,23 @@ public class AxisTickLabels implements ChartPart {
default:
xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0;
}
at.translate(xPos, yOffset);
System.out.println("tickLabelBounds: " + tickLabelBounds.toString());
// double shift = tickLabelBounds.getWidth() * Math.sin(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
double shiftX = -1 * tickLabelBounds.getX() * Math.sin(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
// double shiftY = textLayout.getOutline(null).getBounds().getHeight() * Math.cos(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
// double shiftY = 0;
double shiftY = -1 * (tickLabelBounds.getY() + tickLabelBounds.getHeight());
// double shift = tickLabelBounds.getWidth() / 2.0;
// double shift = 0;
System.out.println(shiftX);
System.out.println("shiftY: " + shiftY);
at.translate(xPos + shiftX, yOffset + shiftY);
g.transform(at);
g.fill(shape);
g.setTransform(orig);
// // debug box
// debug box
g.setColor(Color.MAGENTA);
g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight()));
g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor());
......
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