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

misc cleanup

parent ebe7a6ad
No related branches found
No related tags found
No related merge requests found
......@@ -137,7 +137,9 @@ public class Axis implements ChartPart {
bounds = new Rectangle2D.Double();
// determine Axis bounds
if (direction == Direction.Y) { // Y-Axis
if (direction == Direction.Y) { // Y-Axis - gets called first
// first determine the height of
// calculate paint zone
// ----
......@@ -153,7 +155,6 @@ public class Axis implements ChartPart {
double height =
getChartPainter().getHeight() - yOffset - axisPair.getXAxis().getSizeHint() - getChartPainter().getStyleManager().getPlotPadding() - getChartPainter().getStyleManager().getChartPadding();
Rectangle2D yAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
this.paintZone = yAxisRectangle;
g.setColor(Color.green);
g.draw(yAxisRectangle);
......@@ -179,7 +180,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;
......@@ -191,19 +192,19 @@ public class Axis implements ChartPart {
getChartPainter().getWidth()
- axisPair.getYAxis().getBounds().getWidth()
- axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted
- chartLegendWidth
- chartLegendWidth
- 2
- 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();
Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height);
......@@ -232,8 +233,6 @@ public class Axis implements ChartPart {
*/
private double getSizeHint() {
System.out.println(axisTick.getTickLabels());
if (direction == Direction.X) { // X-Axis
// Axis title
......@@ -249,12 +248,12 @@ public class Axis implements ChartPart {
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();
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;
}
......
......@@ -15,7 +15,6 @@
*/
package com.xeiam.xchart.internal.chartpart;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.List;
......@@ -64,10 +63,12 @@ public class AxisTick implements ChartPart {
public void paint(Graphics2D g) {
double workingSpace = 0.0;
// Y-Axis
if (axis.getDirection() == Axis.Direction.Y) {
workingSpace = axis.getPaintZone().getHeight(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace);
}
// X-Axis
else if (axis.getDirection() == Axis.Direction.X) {
workingSpace = axis.getPaintZone().getWidth(); // number of pixels the axis has to work with for drawing AxisTicks
// System.out.println("workingspace= " + workingSpace);
......@@ -116,8 +117,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()) {
......
......@@ -102,13 +102,8 @@ public abstract class AxisTickCalculator {
// System.out.println("******");
// double firstPosition = minValue - (minValue % gridStep) + gridStep;
double absoluteMinValue = minValue <= maxValue ? minValue : maxValue;
double firstPosition = absoluteMinValue - (absoluteMinValue % gridStep) - gridStep;
//
// if ((firstPosition - minValue) > gridStep) {
// firstPosition = minValue - (minValue % gridStep);
// }
return firstPosition;
}
......
......@@ -70,11 +70,11 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
double firstPosition = getFirstPosition(gridStep);
// generate all tickLabels and tickLocations from the first to last position
for (double tickPosition = firstPosition; tickPosition <= maxValue + 2 * gridStep; tickPosition = tickPosition + gridStep) {
for (double value = firstPosition; value <= maxValue + 2 * gridStep; value = value + gridStep) {
tickLabels.add(dateFormatter.formatDate(tickPosition, timeUnit));
tickLabels.add(dateFormatter.formatDate(value, timeUnit));
// here we convert tickPosition finally to plot space, i.e. pixels
double tickLabelPosition = margin + ((tickPosition - minValue) / (maxValue - minValue) * tickSpace);
double tickLabelPosition = margin + ((value - minValue) / (maxValue - minValue) * tickSpace);
tickLocations.add(tickLabelPosition);
}
}
......
......@@ -73,15 +73,15 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
// generate all tickLabels and tickLocations from the first to last position
double absoluteMaxValue = minValue <= maxValue ? maxValue : minValue;
for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(absoluteMaxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) {
for (BigDecimal value = cleanedFirstPosition; value.compareTo(BigDecimal.valueOf(absoluteMaxValue + 2 * cleanedGridStep.doubleValue())) < 0; value = value.add(cleanedGridStep)) {
// System.out.println(tickPosition);
String tickLabel = numberFormatter.formatNumber(tickPosition, minValue, maxValue, axisDirection);
String tickLabel = numberFormatter.formatNumber(value, minValue, maxValue, axisDirection);
// System.out.println(tickLabel);
tickLabels.add(tickLabel);
// here we convert tickPosition finally to plot space, i.e. pixels
double tickLabelPosition = margin + ((tickPosition.doubleValue() - minValue) / (maxValue - minValue) * tickSpace);
double tickLabelPosition = margin + ((value.doubleValue() - minValue) / (maxValue - minValue) * tickSpace);
tickLocations.add(tickLabelPosition);
}
}
......
......@@ -109,6 +109,7 @@ public class ChartPainter {
axisPair.paint(g);
plot.paint(g);
// TODO why not just paint them first and skip the size hinting?
chartTitle.paint(g);
chartLegend.paint(g);
......
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