das-developers / das2java

The original das2 library. Provides interactive publication-ready 2-D plotting
https://das2.org
GNU Lesser General Public License v3.0
4 stars 0 forks source link

Maybe tweak how vertical space is computed for OutsideNE legends in DasPlot #66

Closed DiamondJim87 closed 8 months ago

DiamondJim87 commented 11 months ago

In DasPlot.java around line 476 is a block for computing the space necessary for legends for the case "OutsideNE". The vertical space is set as follows:

               mrect.y= yAxis.getRow().getDMinimum(); // em/5 determined by experiment.

I am finding that the tops of larger letters, like capital C, are slightly cut off with this rectangle size. Just to confirm this is the source of my problem, I added 5 pixels to this vertical extent, and voila, the letters look fine.

Is there a different way to set this spacing, perhaps somehow based on font metrics?

jbfaden commented 11 months ago

My recollection is this needs to be studied on many different platforms. Many of the fonts seem to have incorrect metrics. I don't see what I was referring to with "em/5", but the way, do you? Clearly the top of the legend should be the top of the GrannyTextRenderer, so it's probably the GrannyTextRenderer which needs tweaking.

Could you post screenshots, and id the platform (Java version too)?

DiamondJim87 commented 11 months ago

Thanks for the rapid response!

Java version is 1.8. I'm running on a Mac. These are Larry's "StatusLineRenderer" plots, where the only significant axis is the X axis. The Y is just 0 to 1 and we suppress the axis and color it just to show whether there are data in that time range (red) or not (white).

The idea of emsize / 5 doesn't make sense to me either. Maybe it was something different and when the code got changed the comment didn't?

Here's a screen shot. You can most easily see the effect on the bottom two legends, where the C and S in SpaceCraftEngineering and CorruptPacket are cut off. The level of zoom or the size of the canvas do not affect the cut-off effect.

Screenshot 2023-07-24 at 6 06 00 PM
jbfaden commented 11 months ago

They definitely look a little high to me. The goal is to line up top of an M or T with the DasRow top. I do remember experimenting a lot here, so much that I have no idea what the final solution was. Another thought would be to have a legendLabel position which is OutsideSE, since it's very easy to know the baseline for a font. I think I'll look into this now, and I'll let you know what I find out.

jbfaden commented 11 months ago

You can see here how the title ends up low on Linux: image

jbfaden commented 11 months ago

And those are legend labels, not annotations, right? You must have found my kludge which lets you turn off the symbol drawing, right? Note with annotations you would have a lot more control, but it would also be quite a bit more code. Do you add things in a loop?

DiamondJim87 commented 11 months ago

Yes, legend labels, not annotations. Yes, it's in a loop, the number of plots on any given canvas is arbitrary.

jbfaden commented 11 months ago

I think the best solution is for me to add OutsideSE to the legendPosition property.

DiamondJim87 commented 11 months ago

That probably would do the trick for this case.

jbfaden commented 11 months ago

Give it a pull and let me know how that looks. On Linux it's actually 1-2 pixels too high, and I need to set the bounding box since there may be a descender (y or p).

DiamondJim87 commented 11 months ago

Ah, much better. Thanks again, this meets my needs perfectly!

Screenshot 2023-07-24 at 9 42 18 PM
jbfaden commented 11 months ago

I need to play with this on a mac. It still draws 4-5 pixels too high with this font, even though it's not clipping now. I'm going to reopen the ticket, just so I remember to look at this on different platforms. (But I'm happy this takes care of the clipping problem you were seeing.)

jbfaden commented 11 months ago

image

jbfaden commented 8 months ago

I've added a .vap which demos the problem where multi-line legend is incorrectly positioned. See https://github.com/autoplot/dev/blob/master/bugs/ghdas2/0066/demoBug.vap

jbfaden commented 8 months ago

Multi-line, outsideSE legends are fixed.