NOAA-PMEL / Ferret

The Ferret program from NOAA/PMEL
https://ferret.pmel.noaa.gov/Ferret/
The Unlicense
55 stars 21 forks source link

PyFerret contour labels spill outside of plot #1600

Open karlmsmith opened 6 years ago

karlmsmith commented 6 years ago

Reported by @AndrewWittenberg on 1 Dec 2015 00:55 UTC In vanilla Ferret the contour labels are clipped at the edge of the plot -- I think according to the value of the "PPL WINDOW" setting.

But in PyFerret with a font other than Hershey, the contour labels can spill outside of the plot:

    NOAA/PMEL TMAP
    FERRET v6.95 (PyFerret 1.2)
    Linux 2.6.32-504.23.4.el6.x86_64 - 10/07/15
    30-Nov-15 19:49     

yes? set text/font=arial; use coads_climatology
yes? contour/l=1/lev=20/hl=150:280/vl=-20:20 sst*100

Migrated-From: http://dunkel.pmel.noaa.gov/trac/ferret/ticket/2328

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 1 Dec 2015 17:29 UTC ok, I'd worked with of this kind of case, but clearly not all. PPLUS just doesn't draw outside the lines but in PyFerret we're using nice fonts for these labels so it needs to be handled in separate logic.

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 9 Dec 2015 18:25 UTC This is fixed. I compute the location of the end of the label and if it lies outside the plot box, I don't draw the label.

When classic-Ferret draws this plot, it makes the label but just displays the portion of it that lies in the plot it. I don't think this responds to the PPL WINDOW command. In PyFerret I dont' see a good way to do that, and it's not necessarily a good thing to have partial label strings anyway.

karlmsmith commented 6 years ago

Comment by @AndrewWittenberg on 13 Feb 2016 20:23 UTC Not worth reopening the ticket, but just to mention a tiny loose end.

When the label isn't plotted because it'd spill outside the plot bounds, the gap that was made for it in the contour remains -- instead of going all the way to the plot bounds as it should. See e.g. the little blue extension of the red line in the following, intersecting the bottom right edge of the plot near 105W:

    NOAA/PMEL TMAP
    FERRET v6.97 (PyFerret 1.3 beta/opt)
    Linux 2.6.32-573.1.1.el6.x86_64 - 02/13/16
    13-Feb-16 15:09     

yes? set text/font=arial; use coads_climatology
yes? contour/l=1/lev=20/hl=150:280/vl=-20:20/si=1000/col=4 sst*100
yes? contour/l=1/lev/ov/col=2 sst*100

No big deal, but would it be hard to fix? (Maybe, since vanilla Ferret applies the label but clips it at the plot edges; so the logic might be down deep in PPLUS.)

karlmsmith commented 6 years ago

Comment by @AndrewWittenberg on 13 Feb 2016 20:41 UTC Here are a couple of larger remaining bugs:

    NOAA/PMEL TMAP
    FERRET v6.97 (PyFerret 1.3 beta/opt)
    Linux 2.6.32-573.1.1.el6.x86_64 - 02/13/16
    13-Feb-16 15:31     

yes? use coads_climatology; set reg/l=1
yes? set text/font=arial; contour/lev=20/hl=150:280/vl=-20:20 sst*100

Fine so far, apart from the small gap mentioned in comment:3. But now:

yes? set text/font=hershey; contour/lev=20/hl=150:280/vl=-20:20 sst*100

All the contour labels disappear! Seems like something is not getting reset. And:

yes? set text/font=times; contour/lev=20/hl=150:280/vl=-20:20 sst*100

Now the contours labels are back -- but unlike all the other plot labels (which are now in Times font as requested), the contour labels are in Arial font!

karlmsmith commented 6 years ago

Comment by @AnsleyManke on 16 Feb 2016 17:24 UTC The partial was down deep in PPLUS. The contouring code stops drawing a line, makes a label, and continues. In classic Ferret, this meant just going and drawing some lines that make the label text, and if that happened to go outside the boundary, the lines would not be drawn. Because line drawing stops at the boundary.

In PyFerret, we instead stop drawing and make the label, at the chosen size and at an angle to run along the contour line.

So the PyFerret quick and dirty fix for this was simply to check whether the PyFerret put-text in the chosen font would extend outside the box, and if so don't make the label. The correct fix will be to make that check, and if the text would go outside the box, instead continue drawing the contour line.

karlmsmith commented 6 years ago

Attachment from @AndrewWittenberg on 1 Dec 2015 00:55 UTC The resulting plot. plot

karlmsmith commented 6 years ago

Attachment from @AnsleyManke on 9 Dec 2015 18:18 UTC

fix2328

karlmsmith commented 6 years ago

Attachment from @AndrewWittenberg on 13 Feb 2016 20:42 UTC

plot2

karlmsmith commented 6 years ago

Attachment from @AndrewWittenberg on 13 Feb 2016 20:43 UTC

plot3