Skip to content
Merged

0.1.4 #181

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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CeTZ-Plot is a library that adds plots and charts to [CeTZ](https://github.com/cetz-package/cetz), a library for drawing with [Typst](https://typst.app).

CeTZ-Plot requires CeTZ version ≥ 0.4.2!
CeTZ-Plot requires CeTZ version ≥ 0.5.0!

## Examples
<!-- img width is set so the table gets evenly spaced by GitHubs css -->
Expand Down Expand Up @@ -63,8 +63,8 @@ For information, see the [manual (stable)](https://github.com/cetz-package/cetz-

To use this package, simply add the following code to your document:
```
#import "@preview/cetz:0.4.2"
#import "@preview/cetz-plot:0.1.3": plot, chart
#import "@preview/cetz:0.5.2"
#import "@preview/cetz-plot:0.1.4": plot, chart

#cetz.canvas({
// Your plot/chart code goes here
Expand Down
4 changes: 2 additions & 2 deletions doc/style.typ
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#import "/src/lib.typ"

#import "@preview/tidy:0.4.3"
#import "@preview/t4t:0.3.2": is
#import "@preview/t4t:0.3.2": is as is_

#let show-function(fn, style-args) = {
[
#heading(fn.name, level: style-args.first-heading-level + 1)
#label(style-args.label-prefix + fn.name + "()")
]
let description = if is.sequence(fn.description) {
let description = if is_.sequence(fn.description) {
fn.description.children
} else {
(fn.description,)
Expand Down
Binary file modified gallery/barchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions gallery/barchart.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "@preview/cetz:0.4.2": canvas, draw
#import "@preview/cetz-plot:0.1.3": chart
#import "@preview/cetz:0.5.2": canvas, draw
#import "@preview/cetz-plot:0.1.4": chart

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

Expand Down
2 changes: 1 addition & 1 deletion gallery/bending.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.4.2" as cetz: draw
#import "@preview/cetz:0.5.2" as cetz: draw
#import "/src/lib.typ": smartart

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
Binary file modified gallery/chevron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gallery/chevron.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.4.2" as cetz: draw
#import "@preview/cetz:0.5.2" as cetz: draw
#import "/src/lib.typ": smartart

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
2 changes: 1 addition & 1 deletion gallery/circular.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.4.2" as cetz: draw
#import "@preview/cetz:0.5.2" as cetz: draw
#import "/src/lib.typ": smartart

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
2 changes: 1 addition & 1 deletion gallery/cycles.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.4.2": canvas, draw
#import "@preview/cetz:0.5.2": canvas, draw
#import "/src/lib.typ": smartart

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
Binary file modified gallery/line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions gallery/line.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "@preview/cetz:0.4.2": canvas, draw
#import "@preview/cetz-plot:0.1.3": plot
#import "@preview/cetz:0.5.2": canvas, draw
#import "@preview/cetz-plot:0.1.4": plot

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

Expand Down
Binary file added gallery/normal-dist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions gallery/normal-dist.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#import "@preview/cetz:0.5.2": canvas, draw
#import "@preview/cetz-plot:0.1.4": plot

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

#let style = (stroke: black, fill: rgb(0, 0, 200, 75))

#let f(x, rho: .4, sigma: 0) = 1 / calc.sqrt(2 * calc.pi * rho * rho) * calc.exp(-calc.pow(x - sigma, 2)/(2 * rho * rho))

#set text(size: 10pt, fill: white)

#canvas(background: gray.darken(80%), {
import draw: *

set-style(
axes: (
stroke: 1pt + white,
tick: (stroke: 1pt + white),
fill: gray.darken(60%),
minor-tick: (stroke: white),
grid: (stroke: (thickness: .5pt, paint: white, dash: "dotted")),
),
legend: (
fill: black.transparentize(60%),
stroke: none,
padding: .3cm,
offset: (-.1, -.1)
)
)

let x-format = x => {
if x > 0 { $mu + #{x}sigma$ }
else if x < 0 { $mu - #{calc.abs(x)}sigma$ }
else { $mu$ }
}

plot.plot(size: (12, 8),
x-tick-step: 1,
y-tick-step: 1,
x-format: x-format,
y-max: 1.1,
y-min: -.1,
x-grid: true,
y-grid: true,
x-label: none,
y-label: none,
legend: "inner-north-east",
{
plot.add(f, domain: (-3, +3),
style: (stroke: green),
label: $y = 1/sqrt(2 pi sigma^2) exp(-(x - mu)^2/(2 sigma^2)) $,
samples: 200,
)
})

// Add some padding
rect((-1, -1), (13, 9))
})
4 changes: 2 additions & 2 deletions gallery/piechart.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "@preview/cetz:0.4.2"
#import "@preview/cetz-plot:0.1.3": chart
#import "@preview/cetz:0.5.2"
#import "@preview/cetz-plot:0.1.4": chart

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

Expand Down
2 changes: 1 addition & 1 deletion gallery/process.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.4.2" as cetz: draw
#import "@preview/cetz:0.5.2" as cetz: draw
#import "/src/lib.typ": smartart

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
4 changes: 2 additions & 2 deletions gallery/pyramid.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "@preview/cetz:0.4.2"
#import "@preview/cetz-plot:0.1.3": chart
#import "@preview/cetz:0.5.2"
#import "@preview/cetz-plot:0.1.4": chart

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

Expand Down
Binary file added gallery/radarchart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions gallery/radarchart.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#import "@preview/cetz:0.5.2"
#import "/src/lib.typ": chart

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

#cetz.canvas({
chart.radarchart(
(
[A],
[B],
[C],
[D],
[E],
[F],
),
(
(0.3, 1, 0.3, 0.8, 0.8, 1),
(0.9, 0.3, 0.9, 0.5, 0.5, 0.4),
),
radius: 3,
web-label-offset: 0.6,
data-style: (
blue.transparentize(10%),
red.transparentize(30%),
),
)
})

Binary file modified manual.pdf
Binary file not shown.
29 changes: 23 additions & 6 deletions manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#set terms(indent: 1em)
#set par(justify: true)
#set heading(numbering: (..num) => if num.pos().len() < 4 {
numbering("1.1", ..num)
})
numbering("1.1", ..num)
})
#show link: set text(blue)

// Outline
Expand All @@ -42,8 +42,8 @@ CeTZ-Plot is a simple plotting library for use with CeTZ.

This is the minimal starting point:
#pad(left: 1em)[```typ
#import "@preview/cetz:0.4.2"
#import "@preview/cetz-plot:0.1.3"
#import "@preview/cetz:0.5.2"
#import "@preview/cetz-plot:0.1.4"
#cetz.canvas({
import cetz.draw: *
import cetz-plot: *
Expand All @@ -58,7 +58,17 @@ module imported into the namespace.

#doc-style.parse-show-module("/src/plot.typ")

#for m in ("line", "bar", "boxwhisker", "contour", "errorbar", "annotation", "formats", "violin", "legend") {
#for m in (
"line",
"bar",
"boxwhisker",
"contour",
"errorbar",
"annotation",
"formats",
"violin",
"legend",
) {
doc-style.parse-show-module("/src/plot/" + m + ".typ")
}

Expand Down Expand Up @@ -87,7 +97,14 @@ plot.plot(size: (5, 4), axis-style: "school-book", y-tick-step: none, {
= Chart

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

Expand Down
2 changes: 1 addition & 1 deletion src/cetz.typ
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Import cetz into the root scope. Import cetz by importing this file only!
#import "@preview/cetz:0.4.2": *
#import "@preview/cetz:0.5.2": *
3 changes: 2 additions & 1 deletion src/chart.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#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
#import "chart/radarchart.typ": radarchart, radarchart-default-style
#import "chart/pyramid.typ": pyramid, pyramid-default-style
6 changes: 4 additions & 2 deletions src/chart/piechart.typ
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#import "/src/cetz.typ": draw, styles, palette, util, vector, intersection
#import util: circle-arclen

#import "/src/plot/legend.typ"

// Piechart Label Kind
Expand Down Expand Up @@ -344,6 +342,10 @@
continue
}

let circle-arclen(radius, angle: 90deg) = {
calc.abs(angle / 360deg * 2 * calc.pi * radius)
}

// A sharp item is an item that should be round but is sharp due to the gap being big
let is-sharp = inner-radius == 0 or circle-arclen(inner-radius, angle: inner-angle) > circle-arclen(radius, angle: outer-angle)

Expand Down
Loading
Loading