Skip to content

Commit 414eae7

Browse files
pyramid: Add pyramid charts (#87)
2 parents 9dc7972 + b3d784e commit 414eae7

File tree

7 files changed

+515
-1
lines changed

7 files changed

+515
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ CeTZ-Plot requires CeTZ version ≥ 0.3.1!
2828
<td>Pie Chart</td>
2929
<td>Clustered Barchart</td>
3030
</tr>
31+
<tr>
32+
<td>
33+
<a href="gallery/pyramid.typ">
34+
<img src="gallery/pyramid.png" width="250px">
35+
</a>
36+
</td>
37+
</tr><tr>
38+
<td>Pyramid</td>
39+
</tr>
3140
</table>
3241

3342
*Click on the example image to jump to the code.*

gallery/pyramid.png

36.1 KB
Loading

gallery/pyramid.typ

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#import "@preview/cetz:0.3.1"
2+
#import "@preview/cetz-plot:0.1.0": chart
3+
4+
#set page(width: auto, height: auto, margin: .5cm)
5+
6+
#let data = (
7+
([Cash], 768),
8+
([Funds], 1312),
9+
([Stocks], 3812),
10+
([Bonds], 7167),
11+
)
12+
#let total = data.map(i => i.last()).sum()
13+
14+
#cetz.canvas({
15+
let colors = gradient.linear(red, yellow)
16+
17+
chart.pyramid(
18+
data,
19+
value-key: 1,
20+
label-key: 0,
21+
mode: "AREA-HEIGHT",
22+
stroke: none,
23+
level-style: colors,
24+
inner-label: (
25+
content: (value, label) => align(center, stack(
26+
label + "\n",
27+
str(calc.round(value / total * 10000) / 100) + "%",
28+
spacing: 2pt,
29+
dir: ttb
30+
))
31+
),
32+
side-label: (
33+
content: (value, label) => "$" + str(value)
34+
),
35+
gap: 10%
36+
)
37+
})

manual.pdf

18.5 KB
Binary file not shown.

manual.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ module imported into the namespace.
6161
= Chart
6262

6363
#doc-style.parse-show-module("/src/chart.typ")
64-
#for m in ("barchart", "boxwhisker", "columnchart", "piechart") {
64+
#for m in ("barchart", "boxwhisker", "columnchart", "piechart", "pyramid") {
6565
doc-style.parse-show-module("/src/chart/" + m + ".typ")
6666
}

src/chart.typ

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
#import "chart/barchart.typ": barchart, barchart-default-style
33
#import "chart/columnchart.typ": columnchart, columnchart-default-style
44
#import "chart/piechart.typ": piechart, piechart-default-style
5+
#import "chart/pyramid.typ": pyramid, pyramid-default-style

0 commit comments

Comments
 (0)