Long Axis Labels getting clipped - No success setting insets

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
wendygross
Posts: 2
Joined: Sun Oct 03, 2004 5:44 pm

Long Axis Labels getting clipped - No success setting insets

Post by wendygross » Wed Jun 29, 2005 6:02 pm

I am using JFreeChart-0.9.21. to develop a CombinedDomainXYPlot - which will ultimately display a parent plot with 17 child plots - most with long labels. Orientation for Range Axis is Horizontal, labels are displayed located on top.
The labels are rotated 45 degrees as follows:

Code: Select all

  NumberAxis2 rangeAxis1 = new NumberAxis2("Range 17777444444444444444444444444444444444444444444444555");
  rangeAxis1.setLabelAngle(-1 * (Math.PI / 4.0));
NumberAxis2 is a subclass of ValueAxis class. It overrides the drawLabel(...) method (of ValueAxis super class, Axis). The drawLabel method override draws the rotated label so that it is left justified (with respect to the plots dataRect), rather than center justified, as is done in Axis.drawLabel(...).

The translation and rotation of the labels works great, but, long labels, that extend to the right past the dataRect of the right-most child plot (of the combinedDomain parent plot), get clipped .

I have tried setting the insets of the parent plot to increase real estate on right - (as necessary to allow the full label to be displayed) - but, little joy... :cry:

I am doing the inset reset on the parentPlot in the drawLabel(...) method right after the top axis label is drawn. The following snippet is what I have tried:

Code: Select all

public class NumberAxis2 extends ValueAxis implements Cloneable, Serializable {
  . . .
protected AxisState drawLabel(String label,
                                  Graphics2D g2, 
                                  Rectangle2D plotArea, 
                                  Rectangle2D dataArea,
                                  RectangleEdge edge, 
                                  AxisState state) {
  . . .

  if (edge == RectangleEdge.TOP) {
    // Draw the label so that is is left justified with respect to dataRect.
    AffineTransform t = AffineTransform.getRotateInstance(
      getLabelAngle(), labelBounds.getMinX(), labelBounds.getCenterY()
    );
    Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
    labelBounds = rotatedLabelBounds.getBounds2D();
    double labelx = dataArea.getMinX() + (labelBounds.getWidth() / 2.0);
    double labely = state.getCursor() - insets.bottom - labelBounds.getHeight() / 2.0;
    RefineryUtilities.drawRotatedString(
                label, g2, (float) labelx, (float) labely,
                TextAnchor.CENTER, TextAnchor.CENTER, getLabelAngle()
    );
    state.cursorUp(insets.top + labelBounds.getHeight() + insets.bottom);

    // Adjust insets of parent plot to accomodate this label.
    Plot parentPlot = this.getPlot().getParent();
    Insets currentInsets = parentPlot.getInsets();
    int newRightInset = currentInsets.right;
    if (labelBounds.getWidth() > dataArea.getWidth()) {
      newRightInset = (int)(labelBounds.getWidth() - dataArea.getWidth());
    }
    Insets newInsets = new Insets(currentInsets.bottom,
      currentInsets.left,
      newRightInset,
      currentInsets.top);
    parentPlot.setInsets(newInsets, false);
  }
  . . .
}
  . . .
}
The above snippet has no effect on insets and labels get clipped. Further upon resizing, display of plot gets messed up and does not appear correctly.
If I change the last line of code:

Code: Select all

 parentPlot.setInsets(newInsets, false);
to

Code: Select all

 parentPlot.setInsets(newInsets, true);
I do get insets and the labels do not get clipped. But, most of the time, initially and upon resizing, the display gets messed up in a number of ways. The plot series wiggles are not shown, and/or top axis is displayed on bottom axis. Also, sometimes an infinite drawing update loop occurs and hangs the system. However, every once I get the proper inset, the label displays completely, and the whole display is correct.

How else can I attack this problem? Please let me know what else would be helpful for me to provide.

All this said, I am new to JFreeChart - have only been using it for a month, off and on. But, I am enjoying using it immensely - it is very powerful and will be a great asset to our organization and users.

Thanks in advance for your help.
Cheers,
Wendy

Wendy Gross
NOAA Paleoclimatology Program
325 Broadway MC E/GC
Boulder, Colorado 80305
Email: wendy.gross@noaa.gov
http://www.ncdc.noaa.gov/paleo

Locked