I played around with PiePlot to get a better result than screenshot0 (label
link overlapping). Rotating the by by -90 degrees didn't help much
(screenshot1). Then I subclassed PieLabelDistributor and tried using
spreadEvenly() first:
--------------------
public void distributeLabels(double minY, double height) {
sort(); // sorts the label records into ascending order by baseY
if (isOverlap()) {
spreadEvenly(minY, height);
}
if (isOverlap()) {
adjustInwards();
}
// if still overlapping, do something else...
if (isOverlap()) {
adjustDownwards(minY, height);
}
if (isOverlap()) {
adjustUpwards(minY, height);
}
}
--------------------
as this "sounded" good, but the labels just had much too big spaces between
the label boxes. So I changed it a bit:
--------------------------------
/**
* Labels are spaced evenly in the available space in an attempt to
* eliminate the overlaps.
*
* @param minY the minimum y value (in Java2D coordinate space).
* @param height the height available for all labels.
*/
protected void spreadEvenly2(double minY, double height) {
double y = minY;
double sumOfLabelHeights = 0.0;
for (int i = 0; i < this.labels.size(); i++) {
sumOfLabelHeights += getPieLabelRecord(i).getLabelHeight();
}
double gap = Math.max(0, height - sumOfLabelHeights);
y += gap / 2;
if (this.labels.size() > 1) {
gap = gap / (this.labels.size() - 1);
}
gap = Math.min(5, gap);
for (int i = 0; i < this.labels.size(); i++) {
PieLabelRecord record = getPieLabelRecord(i);
y = y + record.getLabelHeight() / 2.0;
record.setAllocatedY(y);
y = y + record.getLabelHeight() / 2.0 + gap;
}
}
----------------------------------------
and got a much better result as the default one (screenshot2). Could you
please
a) use this as the default distribution or make this as an alternative and
offer a method to explicitaly choose between the misc alternatives?
File Added: screenshot1.png
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Bad thing is also that PieLabelDistributor is not subclass friendly: all is private and I had to copy the whole source just to make my little adjustments.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
screenshot1 (default behaviour)
screenshot 1 (rotation -90)
Logged In: YES
user_id=667728
Originator: YES
I played around with PiePlot to get a better result than screenshot0 (label
link overlapping). Rotating the by by -90 degrees didn't help much
(screenshot1). Then I subclassed PieLabelDistributor and tried using
spreadEvenly() first:
--------------------
public void distributeLabels(double minY, double height) {
sort(); // sorts the label records into ascending order by baseY
if (isOverlap()) {
spreadEvenly(minY, height);
}
if (isOverlap()) {
adjustInwards();
}
// if still overlapping, do something else...
if (isOverlap()) {
adjustDownwards(minY, height);
}
if (isOverlap()) {
adjustUpwards(minY, height);
}
}
--------------------
as this "sounded" good, but the labels just had much too big spaces between
the label boxes. So I changed it a bit:
--------------------------------
/**
* Labels are spaced evenly in the available space in an attempt to
* eliminate the overlaps.
*
* @param minY the minimum y value (in Java2D coordinate space).
* @param height the height available for all labels.
*/
protected void spreadEvenly2(double minY, double height) {
double y = minY;
double sumOfLabelHeights = 0.0;
for (int i = 0; i < this.labels.size(); i++) {
sumOfLabelHeights += getPieLabelRecord(i).getLabelHeight();
}
double gap = Math.max(0, height - sumOfLabelHeights);
y += gap / 2;
if (this.labels.size() > 1) {
gap = gap / (this.labels.size() - 1);
}
gap = Math.min(5, gap);
for (int i = 0; i < this.labels.size(); i++) {
PieLabelRecord record = getPieLabelRecord(i);
y = y + record.getLabelHeight() / 2.0;
record.setAllocatedY(y);
y = y + record.getLabelHeight() / 2.0 + gap;
}
}
----------------------------------------
and got a much better result as the default one (screenshot2). Could you
please
a) use this as the default distribution or make this as an alternative and
offer a method to explicitaly choose between the misc alternatives?
File Added: screenshot1.png
screenshot2 (custom PieLabelDistributor)
Logged In: YES
user_id=667728
Originator: YES
File Added: screenshot2.png
Logged In: YES
user_id=667728
Originator: YES
Bad thing is also that PieLabelDistributor is not subclass friendly: all is private and I had to copy the whole source just to make my little adjustments.