cetz-plot icon indicating copy to clipboard operation
cetz-plot copied to clipboard

After new package, minimum padding for anchored content is now huge

Open adrfantini opened this issue 1 year ago • 14 comments

See this project: https://typst.app/project/rBvXqvt6N2I7RKIuLiKV_A

When using CeTZ 0.3.1 and cetz-plot 0.1.0, plotting a simple circle with an anchored content label leads to: image

When using CeTZ 0.2.2 and the built-in plot, the behaviour was: image


Switch between the two behaviours by uncommenting the import lines. In the new behaviour, it is impossible to place the anchored text closer to the red dot. If padding is set to a negative value, the compiler crashes.

adrfantini avatar Oct 25 '24 10:10 adrfantini

The best option to finally fix this, is introducing custom coordinate systems to cetz. The issue & PR is here: https://github.com/cetz-package/cetz/pull/719

johannes-wolf avatar Oct 25 '24 12:10 johannes-wolf

The best option to finally fix this, is introducing custom coordinate systems to cetz. The issue & PR is here: cetz-package/cetz#719

is there any short-term workaround for this right now, that you can think of? Other than using an older cetz version of course.

Currently this broke all of my plots :(

adrfantini avatar Oct 25 '24 21:10 adrfantini

The best option to finally fix this, is introducing custom coordinate systems to cetz. The issue & PR is here: cetz-package/cetz#719

is there any short-term workaround for this right now, that you can think of? Other than using an older cetz version of course.

Currently this broke all of my plots :(

I am sorry :(. You can use plot.add-anchor(...) to place an anchor and use content(...) with that anchor outsides the plot environment to get the correct placing.

Example:

#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0": plot

// Uncomment the following to see the behaviour for old CeTZ
// #import "@preview/cetz:0.2.2"
// #import cetz.plot

#cetz.canvas({
  import cetz.draw: *
  
  plot.plot(
    name: "plot",
    size: (14,8),
    axis-style: "scientific-auto",

    x-min: 0,
    x-max: 1,
    x-tick-step: none,

    y-min: 0,
    y-max: 1,
    y-tick-step: none, {
    
    plot.annotate({
      circle((0.5, 0.5),
        radius: (0.1, 0.1),
        fill: red,
        stroke: none
      ) 
    })
    
    plot.add-anchor("label", (.5, .5))
  })
  content("plot.label", [Hello], anchor: "south")
})

johannes-wolf avatar Oct 25 '24 22:10 johannes-wolf

Link #52

johannes-wolf avatar Oct 26 '24 16:10 johannes-wolf

I am sorry :(

No worries, it happens! And after all this is version 0.x, it's bound to break things!

You can use plot.add-anchor(...) to place an anchor and use content(...) with that anchor outsides the plot environment to get the correct placing.

Example:

#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0": plot

// Uncomment the following to see the behaviour for old CeTZ
// #import "@preview/cetz:0.2.2"
// #import cetz.plot

#cetz.canvas({
  import cetz.draw: *
  
  plot.plot(
    name: "plot",
    size: (14,8),
    axis-style: "scientific-auto",

    x-min: 0,
    x-max: 1,
    x-tick-step: none,

    y-min: 0,
    y-max: 1,
    y-tick-step: none, {
    
    plot.annotate({
      circle((0.5, 0.5),
        radius: (0.1, 0.1),
        fill: red,
        stroke: none
      ) 
    })
    
    plot.add-anchor("label", (.5, .5))
  })
  content("plot.label", [Hello], anchor: "south")
})

Thanks for that, I'll try it out.

adrfantini avatar Oct 28 '24 13:10 adrfantini

I'm not sure if it's related, but I noticed that now even lines seem to have a weird padding.

Before: image

After: image (ignore the fact that I removed the shading to simplify debugging)

Other than the vertical alignement of the anchors (which can be fixed with your above workaround), the arrowheads also do not touch each other anymore, and are separated from their line (which might have been done for aesthetic reasons?)

adrfantini avatar Oct 28 '24 14:10 adrfantini

It is a bug and can be fixed the same way the anchors can be.

I've changed the plot canvas to not use linear scaling anymore, because this does not work with log-plots.

I suggest not using annotate at all right now and use add-anchor and draw everything outsides the plot. This should work fine.

johannes-wolf avatar Oct 29 '24 09:10 johannes-wolf

Sorry to bother, was this fixed by 0.1.1 in the end? I don't see anything related to this in the release notes. 🙏

adrfantini avatar Jan 26 '25 10:01 adrfantini

Sorry to bother, was this fixed by 0.1.1 in the end? I don't see anything related to this in the release notes. 🙏

Sorry, not yet fixed. This needs some work in cetz first and cetz 0.3.2 + plot 0.1.1 are releases to make both packages compatible with Typst versions > 12. Planning to finish up the refactoring on March (fingers crossed).

johannes-wolf avatar Jan 26 '25 17:01 johannes-wolf

Wrong milestone.

johannes-wolf avatar Jan 26 '25 17:01 johannes-wolf

No problem. Thank you for the responsiveness and great work!

adrfantini avatar Jan 26 '25 17:01 adrfantini

@johannes-wolf sorry to bother, is this planned to be fixed soon? I'm trying to understand whether I should migrate my plots entirely out of Typst, try to workaround this or maybe something else

adrfantini avatar Mar 03 '25 10:03 adrfantini

@johannes-wolf sorry to bother, is this planned to be fixed soon? I'm trying to understand whether I should migrate my plots entirely out of Typst, try to workaround this or maybe something else

Hi, I am planning to work on that this month. But it requires changes it cetz itself and thus a cetz release. Is using anchors not working for you?

johannes-wolf avatar Mar 04 '25 16:03 johannes-wolf

@johannes-wolf sorry to bother, is this planned to be fixed soon? I'm trying to understand whether I should migrate my plots entirely out of Typst, try to workaround this or maybe something else

Hi, I am planning to work on that this month. But it requires changes it cetz itself and thus a cetz release. Is using anchors not working for you?

To be frank I have started migrating all my plots to using anchors, but I got sidetracked and did not complete it yet.

Anyway thanks for your effort and time! 🙏

adrfantini avatar Mar 05 '25 18:03 adrfantini