Menu

#351 Better Pie Label Layout

open
nobody
None
5
2008-02-11
2008-02-11
m.hilpert
No

screenshot1 (default behaviour)

Discussion

  • m.hilpert

    m.hilpert - 2008-02-11

    screenshot1 (default behaviour)

     
  • m.hilpert

    m.hilpert - 2008-02-11

    screenshot 1 (rotation -90)

     
  • m.hilpert

    m.hilpert - 2008-02-11
    • summary: screenshot1 (default behaviour) --> Better Pie Label Layout
     
  • m.hilpert

    m.hilpert - 2008-02-11

    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

     
  • m.hilpert

    m.hilpert - 2008-02-11

    screenshot2 (custom PieLabelDistributor)

     
  • m.hilpert

    m.hilpert - 2008-02-11

    Logged In: YES
    user_id=667728
    Originator: YES

    File Added: screenshot2.png

     
  • m.hilpert

    m.hilpert - 2008-02-11

    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.

     

Log in to post a comment.