Skip to content

[add] type legend-icon - #122

Draft
Mc-Zen wants to merge 5 commits into
mainfrom
legend-image
Draft

Mc-Zen wants to merge 5 commits into
mainfrom
legend-image

Conversation

@Mc-Zen

@Mc-Zen Mc-Zen commented Oct 6, 2025

Copy link
Copy Markdown
Member

To make it possible to modify the appearance of legend icons, a type legend-icon (in the future legend.icon) is introduced.

The type can be used

  1. to configure the size of the legend icons
#show: lq.set-legend-icon(width: 1em, height: .5em)
  1. to override the styles used to generate the legend icon:
#show: lq.show_(lq.legend-icon.with(kind: lq.scatter), it => {
  show lq.mark: set lq.mark(inset: 5pt)
  it
})

In this example, the mark size for all legend icons for scatter plots is set to 5pt. The pattern show mark: set mark grants priority to this rule over potential other rules that are invoked within scatter, e.g., due to setting lq.scatter(.., size: 7pt)

  1. to override the legend icon altogether:
#show: lq.show_(lq.legend-icon.with(kind: lq.scatter), it => rect(width: 100%, height: 100%, fill: blue))

This closes #100 .

@Mc-Zen Mc-Zen changed the title [add] type legend-image [add] type legend-icon Oct 6, 2025
@Mc-Zen
Mc-Zen marked this pull request as draft October 14, 2025 15:35
@Mc-Zen

Mc-Zen commented Oct 14, 2025

Copy link
Copy Markdown
Member Author

There still remain issues with the current design. For example it is not possible to create an lq.mark in a show rule like

#show: lq.show_(lq.legend-icon.with(kind: lq.scatter), it => {
  lq.mark()
})

and have it adapt to the color if the color is overridden explicitly through lq.scatter.color. This is due to the fact that the internal rules that are applied before plotting are basically inside it and thus "ignored" in the example above where it is not used (only the rules from the cycle style are applied because they are applied outside the legend icon).

On the one hand, the current behavior in this PR is useful for overriding the color, size etc. of the default icon. On the other hand, it is not suitable for creating a differently shaped icon but with the styles inherited from the plot. I deem such behavior very desirable if one wants to draw a rectangle instead of a mark and so on.

I am not yet sure whether there even is a good solution for this. However, a potential solution will likely depend on a set of special drawing primitives for lines, rectangles, ellipses etc. defined by Lilaq and most likely this will only make sense with user-defined types for Typst.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

change legend "icon" size

1 participant