Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adrfantini opened this issue Oct 25, 2024 · 7 comments
Open
Assignees
Labels
👿 bug Something isn't working
Milestone

Comments

@adrfantini
Copy link

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 adrfantini changed the title After new package, minimum padding is now huge After new package, minimum padding for anchored content is now huge Oct 25, 2024
@johannes-wolf johannes-wolf added the 👿 bug Something isn't working label Oct 25, 2024
@johannes-wolf
Copy link
Member

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

@adrfantini
Copy link
Author

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 :(

@johannes-wolf
Copy link
Member

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 johannes-wolf self-assigned this Oct 25, 2024
@johannes-wolf
Copy link
Member

Link #52

@adrfantini
Copy link
Author

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
Copy link
Author

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?)

@johannes-wolf
Copy link
Member

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 johannes-wolf added this to the v0.1.1 milestone Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👿 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants