cetz-plot
cetz-plot copied to clipboard
Pie chart "bleeding" issue
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%
)
)
})
Note: The 0% slices are to blame.
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),
)
})
I also get a black stroke around the circle when only one slice as a non-zero value. Is that intentional?
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.
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.
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 ?