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

Piechart Color Arrays #411

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/lib/chart/piechart.typ
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
/// - slice-style (function,array,gradient): Slice style of the following types:
/// - function: A function of the form `index => style` that must return a style dictionary.
/// This can be a `palette` function.
/// - array: An array of style dictionaries of at least one item. For each slice the style at the slices
/// - array: An array of style dictionaries or fill colors of at least one item. For each slice the style at the slices
/// index modulo the arrays length gets used.
/// - gradient: A gradient that gets sampled for each data item using the the slices
/// index divided by the number of slices as position.
/// index divided by the number of slices as position on the gradient.
/// If one of stroke or fill is not in the style dictionary, it is taken from the charts style.
#let piechart(data,
value-key: none,
Expand Down Expand Up @@ -209,9 +209,16 @@
let style-at = if type(slice-style) == function {
slice-style
} else if type(slice-style) == array {
i => slice-style.at(calc.rem(i, slice-style.len()))
i => {
let s = slice-style.at(calc.rem(i, slice-style.len()))
if type(s) == color {
(fill: s)
} else {
s
}
}
} else if type(slice-style) == gradient {
i => (fill: slice-style.sample(i / data.len() * 100%), stroke: style.stroke)
i => (fill: slice-style.sample(i / data.len() * 100%))
}

let start-angle = style.start
Expand Down