Skip to content

Commit

Permalink
pyramid: Add pyramid charts
Browse files Browse the repository at this point in the history
  • Loading branch information
LordBaryhobal committed Nov 8, 2024
1 parent 9dc7972 commit b3d784e
Show file tree
Hide file tree
Showing 7 changed files with 515 additions and 1 deletion.
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

0 comments on commit b3d784e

Please sign in to comment.