Re: Axis labeling and axis interaction

Hi Henner,

> - i want to label the x axis of a Gridded2DSet on my own. The samples are
> not evenly spaced multiples of the unit one year. I want 0.5 to be labeled
> as "6M", 2 as "2Y", and so on.

There are a couple of ways to create custom axis labels:

1. Extend visad.java3d.DefaultDisplayRendererJ3D, and override its
createSceneGraph() method to create your labels as part of your
"box".

2. Create your labels as VisADLineArrays and put them in
ShapeControls for some RealType mapped to Display.Shape.  There's
an example in visad/bom/TrackManipulation.java.

In a DisplayImplJ3D the "box" spans X, Y and Z coordinates from -1.0
to 1.0.  You can use the visad.PlotText.render_label() method to
help you draw text for your labels.

> - secondly i want these labels to be interactive: if the users clicks a
> label, i want the corresponding 2D data to be displayed in a seperate 2D
> display.

This is more difficult, but you can do it like this:

You can construct a DisplayListener and add it to your
DisplayImplJ3D.  In its displayChanged(DisplayEvent e)
method, if e.getId() == DisplayEvent.MOUSE_PRESSED (or
MOUSE_PRESSED_LEFT, MOUSE_PRESSED_CENTER or
MOUSE_PRESSED_RIGHT if you want to respond to a specific
mouse button), get the cursor position by
DisplayEvent.getX() and DisplayEvent.getY().  Then you must
tranlate the cursor location into a ray in 3-D and figure
out which label the user is pointing at.  You'd do this
something like:

  DisplayImplJ3D display = ...
  DisplayRenderer dr = display.getDisplayRenderer();
  MouseBehavior mouse = dr.getMouseBehavior();
  VisADRay direct_ray = behavior.findRay(cursor_x, cursor_y);

Then use code similar to DisplayRendererJ3D.findDirect(direct_ray, ...)
to figure out which label is closest to direct_ray (a 2-D cirsor
location generates a 3-D ray).

Note the DisplayRenderer.getMouseBehavior() method is new.

Cheers,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html