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

pyramid: Add pyramid charts #87

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ CeTZ-Plot requires CeTZ version ≥ 0.3.1!
<td>Pie Chart</td>
<td>Clustered Barchart</td>
</tr>
<tr>
<td>
<a href="gallery/pyramid.typ">
<img src="gallery/pyramid.png" width="250px">
</a>
</td>
</tr><tr>
<td>Pyramid</td>
</tr>
</table>

*Click on the example image to jump to the code.*
Expand Down
Binary file added gallery/pyramid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions gallery/pyramid.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0": chart

#set page(width: auto, height: auto, margin: .5cm)

#let data = (
([Cash], 768),
([Funds], 1312),
([Stocks], 3812),
([Bonds], 7167),
)
#let total = data.map(i => i.last()).sum()

#cetz.canvas({
let colors = gradient.linear(red, yellow)

chart.pyramid(
data,
value-key: 1,
label-key: 0,
mode: "AREA-HEIGHT",
stroke: none,
level-style: colors,
inner-label: (
content: (value, label) => align(center, stack(
label + "\n",
str(calc.round(value / total * 10000) / 100) + "%",
spacing: 2pt,
dir: ttb
))
),
side-label: (
content: (value, label) => "$" + str(value)
),
gap: 10%
)
})
Binary file modified manual.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ module imported into the namespace.
= Chart

#doc-style.parse-show-module("/src/chart.typ")
#for m in ("barchart", "boxwhisker", "columnchart", "piechart") {
#for m in ("barchart", "boxwhisker", "columnchart", "piechart", "pyramid") {
doc-style.parse-show-module("/src/chart/" + m + ".typ")
}
1 change: 1 addition & 0 deletions src/chart.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#import "chart/barchart.typ": barchart, barchart-default-style
#import "chart/columnchart.typ": columnchart, columnchart-default-style
#import "chart/piechart.typ": piechart, piechart-default-style
#import "chart/pyramid.typ": pyramid, pyramid-default-style
Loading
Loading