1

I would like to display the units in text for the values displayed on the colorbar. I have a colorbar added to my ILSurface and I'd like to show my units in text on the color bar along with the range.

Edit: I want to display text at the bottom of the color bar below the bottom tick just the one label.

I was able to get this to work this way

                        new ILColorbar()
                        {
                           Children = { new ILLabel("nm") {Position = new Vector3(.2f,.98f,0)  } }
                        }

I have to say the Position coordinates are not very intuitive. I had to basically adjust the numbers by trial and error until it fit. I knew that the values range 0..1 so the X value was 1 at the bottom but I wanted it up from the border. And the Y value would need to be indented in some but I wasn't sure what was a good value but .2 works.

enter image description here

Jeff Davis
  • 1,755
  • 2
  • 11
  • 14

1 Answers1

1

You can access the axis of ILColorbar and configure it in the usual way. Use the LabelTransformFunc on the ticks to set your own label text. You can use the default transform func and add your unit string. Example:

var cb = scene.First<ILColorbar>();
cb.Axis.Ticks.LabelTransformFunc = (ind, val) =>
{
   return ILTickCollection.DefaultLabelTransformFunc(ind, val) + "nm";
};

You can read more about the axis configuration here:

Axis Configuration

LabelTransformFunc in ApiDoc

Edit: If only one label is needed, then add a new ILLabel object in ILColorbar group as follows:

new ILColorbar() {
    new ILLabel("z(nm)") {
        Position = new Vector3(0.5,1,0),
        Anchor = new PointF(0.5f,0)
    }
}

The ILColorbar area have the relative coordinates 0..1 over the width and the height of the color bar. So we set position x in the middle of the ILColorbar, and position y at the bottom. The Anchor position is used as relative position in relation to the Position point.

ILLabel Documentation

  • Except I don't want the units next to each of the values on the color bar. I just want one units label at the bottom of the color bar – Jeff Davis Feb 22 '16 at 22:32
  • I haven't tried anything. My original question was how could it be done. I don't see a property in the ColorBar object that explicitly describes a units label or some sort of default text or title for the colorbar. The answer given above assumes that I would know the relationship between the Axis and LabelTransformFunc with the colorbar and how it would work. All I wanted to do was have a text label at the bottome of the colorbar that displayed the units that all the values were in. – Jeff Davis Feb 23 '16 at 17:33
  • What have I tried? That seems like a strange question to ask? As if I should just guess and guess until I find something that works? Wouldn't it be easier to just either say this is how I would do it. Or point to an example or documentation that shows an example? The intial answer is what I was looking for. Except I didn't specif that I only wanted one label at the bottom. – Jeff Davis Feb 23 '16 at 18:20
  • We can not release you from reading the documentation: http://ilnumerics.net/group-nodes.html http://ilnumerics.net/labels.html – user492238 Feb 24 '16 at 09:22
  • This is the problem I have with ILNumerics documentation. Of course I understand and have read about Labels. And Group Nodes. But what I don't see is how this relates to a ColorBar? How do I put a Label in a ColorBar and what are the coordinate relationships with the colorbar and its default text labels? What is the default space (margin) area of the colorbar and how do I know how to place a Label within it. The documentation makes a huge assumption that I somehow know the relationships between all the base elements of ILNumerics. – Jeff Davis Feb 25 '16 at 19:05
  • And what does the group-nodes documentation have to do with the question about how to add a units label to a color bar? There is nothing mentioned in the Group Nodes Documentation about labels or the colorbar? How would I know the relationship if there was one? – Jeff Davis Feb 25 '16 at 19:08
  • part of my original intent of my question was if there was a label already defined in the color bar that I could use for the units text? could the axis labels be used (X Axis label at bottom) or some other method without adding my own Label and figuring out where it should go? – Jeff Davis Feb 25 '16 at 19:21