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

Pie chart "bleeding" issue #61

Open
RubyflameWarrior opened this issue Oct 21, 2024 · 6 comments · Fixed by #70
Open

Pie chart "bleeding" issue #61

RubyflameWarrior opened this issue Oct 21, 2024 · 6 comments · Fixed by #70
Assignees
Labels
👿 bug Something isn't working

Comments

@RubyflameWarrior
Copy link

When you try to create a pie chart where all the labels except one have a value of 0, the chart bugs out (as shown in the image). Below is a code sample to replicate the issue.

  cetz.canvas({
    import cetz.draw: *
    import cetz.chart

    chart.piechart(
      (
       ("Over-\nperformed", 0),
       ("Satisfactory", 0),
       ("Disabled", 0),
       ("Under-\nperformed", 10),
      ),
      start: 90deg,
      stop: 450deg,
      gap: 1deg,
      value-key: 1,
      label-key: 0,
      radius: 3.5,
      slice-style: (
       (fill: rgb("#abebb3"), stroke: none),
       (fill: rgb("#fff199"), stroke: none),
       (fill: luma(86.67%), stroke: none),
       (fill: rgb("#ff4136"), stroke: none),
      ),
      inner-radius: 0,
      inner-label: (
        content: "%",
        radius: 120%
      ),
      outer-label: (
        content: (value, label) => {
          let string = label + " (" + str(value)
          string = string.replace(" ", "\n")
          string = string + " " + "mts" + ")"
          align(center)[#string]
        },
        radius: 125%
      )
    )
  })

image

@johannes-wolf johannes-wolf transferred this issue from cetz-package/cetz Oct 21, 2024
@johannes-wolf johannes-wolf added the 👿 bug Something isn't working label Oct 21, 2024
@johannes-wolf johannes-wolf self-assigned this Oct 21, 2024
@johannes-wolf
Copy link
Member

Note: The 0% slices are to blame.

@johannes-wolf johannes-wolf linked a pull request Oct 25, 2024 that will close this issue
@cskeeters
Copy link

I'm still getting bleed when one of the values is way larger than the rest.

cetz.canvas({
  chart.piechart(
    ((100000,), (1,), (1,)),
    value-key: 0,
    label-key: none,
    radius: 2,
    slice-style: (red, black, green),
  )
})

@cskeeters
Copy link

I also get a black stroke around the circle when only one slice as a non-zero value. Is that intentional?

@johannes-wolf
Copy link
Member

I also get a black stroke around the circle when only one slice as a non-zero value. Is that intentional?

With the current master? Note that the current release 0.1.0 does not contain the fix.

@cskeeters
Copy link

Yes, I cloned the repo into Library/Application Support/typst/packages/local/cetz-plot/0.1.1, changed the version in typst.toml to 0.1.1 (fake) and used #import "@local/cetz-plot:0.1.1": chart to access it. It includes e618c25 in the git history.

BTW, If there is a better way of using master, I'm all ears.

@johannes-wolf
Copy link
Member

Ah, ok. Right now, I am working on refactoring plots. I guess this is a rounding error… maybe we can add some calc.max(0, ...) somewhere or filter out segments smaller than cetz.util.float-epsilon. Maybe add something here: https://github.com/cetz-package/cetz-plot/blob/master/src/chart/piechart.typ#L218 ?

@johannes-wolf johannes-wolf reopened this Nov 25, 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

Successfully merging a pull request may close this issue.

3 participants