diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java index a6545c33436bafb1129d9a6e5f0b6a04a5a0aa29..5a0a676344151b307ae1a6ee149b9653b14f6f65 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/pie/PieChart03.java @@ -55,6 +55,7 @@ public class PieChart03 implements ExampleChart<Chart_Pie> { chart.getStyler().setLegendVisible(false); chart.getStyler().setAnnotationType(AnnotationType.LabelAndPercentage); chart.getStyler().setAnnotationDistance(1.15); + chart.getStyler().setPieSize(.7); return chart; } diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java index fac519a9a69a6a889b849a8fe7ee3845238a53fa..0e6a78d290380fddacd19e6fa88e573a871ab0a1 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java @@ -154,7 +154,7 @@ public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotCo Shape shape = textLayout.getOutline(null); Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); - System.out.println("annotationWidth= " + annotationWidth); + // System.out.println("annotationWidth= " + annotationWidth); double annotationHeight = annotationBounds.getHeight(); // System.out.println("annotationHeight= " + annotationHeight); @@ -174,12 +174,12 @@ public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotCo // double max = Math.max(xDiff, yDiff); // System.out.println(" ================== "); boolean annotationWillFit = false; - if (xDiff > yDiff) { // assume more vertically orientated slice + if (xDiff >= yDiff) { // assume more vertically orientated slice if (annotationWidth < xDiff) { annotationWillFit = true; } } - else if (xDiff < yDiff) { // assume more horizontally orientated slice + else if (xDiff <= yDiff) { // assume more horizontally orientated slice if (annotationHeight < yDiff) { annotationWillFit = true; } @@ -205,7 +205,7 @@ public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotCo xCenter = pieBounds.getX() + pieBounds.getWidth() / 2; yCenter = pieBounds.getY() + pieBounds.getHeight() / 2; // double endPoint = Math.min((2.0 - (stylerPie.getAnnotationDistance() - 1)), 1.95); - double endPoint = (2.0 - (stylerPie.getAnnotationDistance() - 1)); + double endPoint = (3.0 - stylerPie.getAnnotationDistance()); double xOffsetStart = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / 2.01); double xOffsetEnd = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / endPoint); double yOffsetStart = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / 2.01); @@ -217,7 +217,6 @@ public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotCo // annotation at.translate(xOffset - Math.sin(Math.toRadians(angle - 90)) * annotationWidth / 2 + 3, yOffset); - // at.translate(xOffset, yOffset); } @@ -226,6 +225,14 @@ public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotCo g.setTransform(orig); } + // else { + // System.out.println("Won't fit."); + // System.out.println("xDiff= " + xDiff); + // System.out.println("yDiff= " + yDiff); + // System.out.println("annotationWidth= " + annotationWidth); + // System.out.println("annotationHeight= " + annotationHeight); + // + // } startAngle += arcAngle; }