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

allowing setting of annotation distance from center on pie chart, as well as...

allowing setting of annotation distance from center on pie chart, as well as the pie chart annotation font
parent 40a3bbb0
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,8 @@
*/
package org.knowm.xchart;
import java.awt.Font;
import org.knowm.xchart.Series_Pie.ChartPieSeriesRenderStyle;
import org.knowm.xchart.internal.style.Styler;
import org.knowm.xchart.internal.style.Theme_;
......@@ -30,6 +32,8 @@ public class Styler_Pie extends Styler {
private double pieFillPercentage;
private boolean isCircular;
private double startAngleInDegrees;
private Font pieFont;
private double annotationDistance;
/**
* Constructor
......@@ -46,6 +50,8 @@ public class Styler_Pie extends Styler {
chartPieSeriesRenderStyle = ChartPieSeriesRenderStyle.Pie; // set default to pie, donut may be a future one
pieFillPercentage = theme.getPieFillPercentage();
isCircular = theme.isCircular();
pieFont = theme.getPieFont();
annotationDistance = theme.getAnnotationDistance();
}
public ChartPieSeriesRenderStyle getChartPieSeriesRenderStyle() {
......@@ -108,6 +114,36 @@ public class Styler_Pie extends Styler {
this.startAngleInDegrees = startAngleInDegrees;
}
public Font getPieFont() {
return pieFont;
}
/**
* Sets the font used on the Pie Chart's annotations
*
* @param pieFont
*/
public void setPieFont(Font pieFont) {
this.pieFont = pieFont;
}
public double getAnnotationDistance() {
return annotationDistance;
}
/**
* Sets the distance of the pie chart's annotation where 0 is the center, 1 is at the edge and greater than 1 is outside of the pie chart.
*
* @param annotationDistance
*/
public void setAnnotationDistance(double annotationDistance) {
this.annotationDistance = annotationDistance;
}
/**
* Set the theme the styler should use
*
......
......@@ -127,14 +127,14 @@ public class PlotContent_Pie<ST extends Styler, S extends Series> extends PlotCo
// draw percentage on slice
double percentage = y.doubleValue() / total * 100;
TextLayout textLayout = new TextLayout(df.format(percentage) + "%", chart.getStyler().getLegendFont(), new FontRenderContext(null, true, false));
TextLayout textLayout = new TextLayout(df.format(percentage) + "%", stylerPie.getPieFont(), new FontRenderContext(null, true, false));
Rectangle2D percentageRectangle = textLayout.getBounds();
double xCenter = pieBounds.getX() + pieBounds.getWidth() / 2 - percentageRectangle.getWidth() / 2;
double yCenter = pieBounds.getY() + pieBounds.getHeight() / 2 + percentageRectangle.getHeight() / 2;
double angle = (arcAngle + startAngle) - arcAngle / 2;
double xOffset = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / 3.33);
double yOffset = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / 3.33);
double xOffset = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / 2 * stylerPie.getAnnotationDistance());
double yOffset = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / 2 * stylerPie.getAnnotationDistance());
g.setColor(stylerPie.getChartFontColor());
g.setFont(stylerPie.getChartTitleFont());
......
......@@ -140,6 +140,10 @@ public interface Theme_ extends SeriesMarkers, SeriesLines, SeriesColors {
public double getStartAngleInDegrees();
public Font getPieFont();
public double getAnnotationDistance();
// Line, Scatter, Area Charts ///////////////////////////////
public int getMarkerSize();
......
......@@ -354,6 +354,18 @@ public class Theme_GGPlot2 implements Theme_ {
return 0;
}
@Override
public Font getPieFont() {
return new Font(Font.SANS_SERIF, Font.PLAIN, 15);
}
@Override
public double getAnnotationDistance() {
return .67;
}
// Line, Scatter, Area Charts ///////////////////////////////
@Override
......
......@@ -358,6 +358,18 @@ public class Theme_Matlab implements Theme_ {
return 0;
}
@Override
public Font getPieFont() {
return new Font(Font.SANS_SERIF, Font.PLAIN, 15);
}
@Override
public double getAnnotationDistance() {
return .67;
}
// Line, Scatter, Area Charts ///////////////////////////////
@Override
......
......@@ -354,6 +354,18 @@ public class Theme_XChart implements Theme_ {
return 0;
}
@Override
public Font getPieFont() {
return new Font(Font.SANS_SERIF, Font.PLAIN, 15);
}
@Override
public double getAnnotationDistance() {
return .67;
}
// Line, Scatter, Area Charts ///////////////////////////////
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment