Skip to content

Better auto-legend horizontal spacing #6163

Closed

Description

@PaulWessel

Description of the desired feature

For historical reasons, the input to legend for a symbol has this syntax:

S [dx1 symbol size fill pen [ dx2 text ]]

where dx1 is the distance from the left margin to the center of the symbol and dx2 is the distance from the left margin to the start of the optional text. If dx1 is given as "-" then we auto-compute dx1 = 0.5 * size, while if dx2 is given as "-" then we compute dx2 = 1.5 * size. For typical geometric symbols (e.g., circle) this works great: We get a gap of half the symbol size between the symbol and the text. For lines or vectors, it works not so well. Consider placing a contour or vector that is 1 cm via -l"My vector". Then, the label will start 0.5 cm after the vector and the gap is starting to seem too big. Go to 2 cm and now you have a big gap. This is essentially one of the challenges for adding -l to grdvector and velo (there are others). Note: If you placed the label with a tight frame (no offset, i.e. +o0) then the symbol would be tangent to the left frame. In reality we have a default offset of 0.2 cm so the left gap in all the auto-legend examples is basically 0.2 cm. This also does not scale well for large posters.

I think there are two elements of scale here:

  1. The symbol size
  2. The annotation text

Seems to me it would be better if dx2 involves a mix of symbol size and font size. E.g., instead of the above definition for an auto dx2, perhaps dx2 = size + 2*annot_font_size would be better. Consider a large plot on a poster: You are not going to plot a 4 cm vector and use a 10p font label. You'll be doing 24 to 32 points and you want that gap to relate to the font size. Since characters have different widths (except in Courier and similar fonts), I will consider the width of the letter M as one unit below, but it could simply be the actual font size (e.g., 12p)

My proposal is therefore to make some changes when dx1 and/or dx2 is given as "-":

dx1 = one unit + 0.5 * size
dx2 = one unit + size + two unit = 3 units + size

This means if dx1 = dx2 = "-" (which is what we do when -l is used), we get a reasonable left-space after the margin and a getter alignment of the label text to the right of the symbol.

I will make a branch and experiment a bit with this (perhaps "one" and "two" are too little/too much and need to be adjusted). Let me know if @GenericMappingTools/core have any suggestions.

Activity

  1. added
    feature request
    on Dec 28, 2021
  2. self-assigned this
    on Dec 28, 2021
  3. PaulWessel commented on Dec 28, 2021

    @PaulWessel
    ContributorAuthor

    Because of the padding in the frame, the better solution is this:

    dx1 = 0.5 * size
    dx2 = one unit + size
    

    Here, unit is the height of the current annotation font and size is the symbol size (or contour|vector length). This works very well and I will be making a PR soon.

  4. maxrjones commented on Mar 18, 2022

    @maxrjones
    Member

    @PaulWessel, can this be closed now (based on #6165)?

  5. PaulWessel commented on Mar 18, 2022

    @PaulWessel
    ContributorAuthor

    Yes I believe so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions