Skip to content

Fix four bugs in the gmt legend records (F, S...L band, G, M) - #9277

Merged
Esteban82 merged 2 commits into
masterfrom
legend-master-fixes
Oct 22, 2026
Merged

Esteban82 merged 2 commits into
masterfrom
legend-master-fixes

Conversation

@Esteban82

Copy link
Copy Markdown
Member

Claude found a few bugs in the legend module:

  1. F red - blue: the - (no fill) did not take up its column, so the colors shifted: B got blue and C got no fill.
  2. S - L ... (confidence band) with N 2: the first pass counted the band and its line as two cells but drawing counts one, so the legend box was too short and the last symbol fell outside the frame.
  3. G 0.5l: atoi truncated the number of lines, so fractional gaps (0.5l, 1.5l) gave no gap or a shorter one.
  4. M after an S whose pen starts with f (e.g. faint): the M record read leftover arguments from the previous record and drew the fancy scale although +f was not requested.
  5. Also fixed the names used when dumping data sets in DEBUG builds (one name was missing, so they were shifted).

Tested with

gmt begin legend_bugs png
	gmt basemap -R-20/20/-20/20 -JM5c -B0
	# 1. F red - blue: esperado A rojo, B sin relleno, C azul
	printf 'N 3\nF red - blue\nS - c 0.3c black 0.5p - A\nS - c 0.3c black 0.5p - B\nS - c 0.3c black 0.5p - C\n' | gmt legend -DjTL+w4c+o0.5c/0.5c -F+p0.5p
	# 2. Banda de confianza con N 2: esperado las dos filas dentro del marco
	printf 'N 2\nS - L 0.4c lightred 0.25p - Band\nS - - 0.4c - 1p,red\nS - c 0.25c blue 0.25p - Circle\nS - t 0.25c green 0.25p - Triangle\n' | gmt legend -DjTL+w4c+o0.5c/1.5c -F+p0.5p
	# 3. G 0.5l: esperado media linea entre A y B (lineas base con +d)
	printf 'S - c 0.3c red 0.5p - A\nG 0.5l\nS - c 0.3c blue 0.5p - B\n' | gmt legend -DjTL+w4c+o0.5c/2.5c -F+p0.5p+d
	# 4. M despues de pluma "faint": esperado escala simple (sin +f)
	printf 'S - c 0.3c red faint - Circle\nM - 0 500k+u\n' | gmt legend -DjTL+w4c+o0.5c/3.8c -F+p0.5p
gmt end

Buggy / Fixed
legend_bugslegend_bugs_fixed

The bugs were found and the fixes reviewed by Claude Opus 5.5.

- F: a "-" (no fill) now keeps its column instead of shifting later fills left.
- S ... L (confidence band): the first pass counted the L and its line as two
  cells while the second pass counted one, so legends with N >= 2 got a box
  that was too short.
- G: use atof instead of atoi so fractional gaps like 0.5l are not truncated.
- M: clear the argument buffers first so leftovers from an earlier record
  (e.g. a pen starting with f) cannot turn the scale into a fancy one.
- Fix the names of the DEBUG data-set dumps (one name was missing).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Esteban82 Esteban82 added bug Something isn't working add-changelog Add PR to the changelog labels Oct 21, 2026
@Esteban82
Esteban82 requested review from joa-quim and seisman October 21, 2026 15:30
@Esteban82

Copy link
Copy Markdown
Member Author

The fix for the G record affects ex22.sh. I will take a look.

@Esteban82

Copy link
Copy Markdown
Member Author

In the example 22, the G record used to truncate "0.25l" to 0 lines, so this line never added any gap. Now that fractional line gaps are honored, it would move the text below it down by about 1 mm and the USGS logo would touch the legend frame. Removing the line keeps the figure identical to the current baseline image.

@Esteban82

Copy link
Copy Markdown
Member Author

Now the test ex22 passes.

Comment thread doc/examples/ex22/ex22.sh
@Esteban82
Esteban82 merged commit 0439a2f into master Oct 22, 2026
18 of 19 checks passed
@Esteban82
Esteban82 deleted the legend-master-fixes branch October 22, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants