Skip to content

Commit ba0aea2

Browse files
committed
Merge branch 'develop' of https://github.com/knowm/XChart into develop
2 parents 952a3dd + 609b69d commit ba0aea2

File tree

4 files changed

+9
-60
lines changed

4 files changed

+9
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package org.knowm.xchart.demo.charts.pie;
22

33
import java.awt.Color;
4-
import java.util.Collection;
5-
64
import org.knowm.xchart.PieChart;
75
import org.knowm.xchart.PieChartBuilder;
8-
import org.knowm.xchart.PieSeries;
96
import org.knowm.xchart.SwingWrapper;
107
import org.knowm.xchart.demo.charts.ExampleChart;
11-
import org.knowm.xchart.style.LabelGenerator;
128
import org.knowm.xchart.style.PieStyler.LabelType;
139

1410
/**
@@ -20,7 +16,6 @@
2016
* <li>Pie Chart
2117
* <li>PieChartBuilder
2218
* <li>Custom series palette
23-
* <li>Custom label type
2419
* <li>Value Annotations
2520
* <li>Tooltips
2621
*/
@@ -40,13 +35,6 @@ public PieChart getChart() {
4035
PieChart chart =
4136
new PieChartBuilder().width(800).height(600).title(getClass().getSimpleName()).build();
4237

43-
// Series
44-
chart.addSeries("Gold", 24);
45-
chart.addSeries("Silver", 21);
46-
chart.addSeries("Platinum", 39);
47-
chart.addSeries("Copper", 17);
48-
chart.addSeries("Zinc", 40);
49-
5038
// Customize Chart
5139
Color[] sliceColors =
5240
new Color[] {
@@ -57,12 +45,18 @@ public PieChart getChart() {
5745
new Color(246, 199, 182)
5846
};
5947
chart.getStyler().setSeriesColors(sliceColors);
60-
chart.getStyler().setLabelType(LabelType.Custom);
61-
chart.getStyler().setLabelGenerator(new CustomLabelGenerator(chart.getSeriesMap().values()));
48+
chart.getStyler().setLabelType(LabelType.Value);
6249
// chart.getStyler().setDecimalPattern("#0.000");
6350
chart.getStyler().setToolTipsEnabled(true);
6451
// chart.getStyler().setToolTipsAlwaysVisible(true);
6552

53+
// Series
54+
chart.addSeries("Gold", 24);
55+
chart.addSeries("Silver", 21);
56+
chart.addSeries("Platinum", 39);
57+
chart.addSeries("Copper", 17);
58+
chart.addSeries("Zinc", 40);
59+
6660
return chart;
6761
}
6862

@@ -71,21 +65,4 @@ public String getExampleChartName() {
7165

7266
return getClass().getSimpleName() + " - Pie Chart Custom Color Palette";
7367
}
74-
75-
private static class CustomLabelGenerator implements LabelGenerator {
76-
77-
private final double total;
78-
79-
public CustomLabelGenerator(Collection<PieSeries> values) {
80-
81-
this.total = values.stream().map(PieSeries::getValue).mapToDouble(Number::doubleValue).sum();
82-
}
83-
84-
@Override
85-
public String generateSeriesLabel(PieSeries series) {
86-
87-
double percent = (series.getValue().doubleValue() / total) * 100;
88-
return String.format("%s (%.2f%%)", series.getValue(), percent);
89-
}
90-
}
9168
}

xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_Pie.java

-2
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ private void paintLabels(Graphics2D g, Rectangle2D pieBounds, double total, doub
290290
} else {
291291
label = series.getName() + " (" + y.toString() + ")";
292292
}
293-
} else if (pieStyler.getLabelType() == LabelType.Custom) {
294-
label = pieStyler.getLabelGenerator().generateSeriesLabel(series);
295293
}
296294

297295
TextLayout textLayout =

xchart/src/main/java/org/knowm/xchart/style/LabelGenerator.java

-7
This file was deleted.

xchart/src/main/java/org/knowm/xchart/style/PieStyler.java

+1-20
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class PieStyler extends Styler {
2525
private Color labelsFontColor;
2626
private double labelsDistance;
2727
private LabelType labelType;
28-
private LabelGenerator labelGenerator;
2928
private boolean isForceAllLabelsVisible;
3029
private boolean isLabelsFontColorAutomaticEnabled;
3130
private Color labelsFontColorAutomaticLight;
@@ -143,23 +142,6 @@ public PieStyler setLabelType(LabelType labelType) {
143142
return this;
144143
}
145144

146-
public LabelGenerator getLabelGenerator() {
147-
148-
return labelGenerator;
149-
}
150-
151-
/**
152-
* Sets the Pie custom label generator
153-
*
154-
* @param labelGenerator
155-
*/
156-
public PieStyler setLabelGenerator(LabelGenerator labelGenerator) {
157-
158-
this.labelType = LabelType.Custom;
159-
this.labelGenerator = labelGenerator;
160-
return this;
161-
}
162-
163145
public boolean isForceAllLabelsVisible() {
164146

165147
return isForceAllLabelsVisible;
@@ -380,8 +362,7 @@ public enum LabelType {
380362
Percentage,
381363
Name,
382364
NameAndPercentage,
383-
NameAndValue,
384-
Custom
365+
NameAndValue
385366
}
386367

387368
public enum ClockwiseDirectionType {

0 commit comments

Comments
 (0)