Skip to content
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: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
with:
packages: imagemagick cargo parallel
version: 1.0
- name: Install typos-cli from crates.io
uses: baptiste0928/cargo-install@v2.2.0
with:
crate: typos-cli
- name: Install just from crates.io
uses: baptiste0928/cargo-install@v2.2.0
with:
Expand All @@ -33,9 +29,12 @@ jobs:
crate: typst-test
git: https://github.com/tingerrr/typst-test.git
tag: ci-semi-stable
- run: |
mkdir -p ~/.local/share/typst/packages/preview/cetz
git clone --depth 1 --branch v0.3.0 https://github.com/cetz-package/cetz.git ~/.local/share/typst/packages/preview/cetz/0.3.0
- uses: typst-community/setup-typst@v3
with:
typst-version: '0.11.1'
typst-version: '0.12.0-rc1'
cache-dependency-path: src/cetz.typ
- run: |
just install @local
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
**Note: cetz-plot has not been released yet! Use cetz 0.2.2 's internal plotting module.**

# CeTZ-Plot

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.3.0.

## Examples
<!-- img width is set so the table gets evenly spaced by GitHubs css -->
<table>
Expand Down Expand Up @@ -39,7 +39,7 @@ 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.2.2"
#import "@preview/cetz:0.3.0"
#import "@preview/cetz-plot:0.1.0": plot, chart

#cetz.canvas({
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,4 +1,4 @@
#import "@preview/cetz:0.2.2": canvas, draw
#import "@preview/cetz:0.3.0": canvas, draw
#import "@preview/cetz-plot:0.1.0": chart

#set page(width: auto, height: auto, margin: .5cm)
Expand All @@ -22,5 +22,5 @@
x-tick-step: 2.5,
data2,
labels: ([Low], [Medium], [High], [Very high]),
legend: "legend.inner-north-east",)
legend: "inner-north-east",)
})
Binary file removed gallery/line.pdf
Binary file not shown.
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.
2 changes: 1 addition & 1 deletion gallery/line.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.2.2": canvas, draw
#import "@preview/cetz:0.3.0": canvas, draw
#import "@preview/cetz-plot:0.1.0": plot

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
Binary file removed gallery/piechart.pdf
Binary file not shown.
Binary file modified gallery/piechart.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/piechart.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.2.2"
#import "@preview/cetz:0.3.0"
#import "@preview/cetz-plot:0.1.0": chart

#set page(width: auto, height: auto, margin: .5cm)
Expand All @@ -22,7 +22,7 @@
chart.piechart(
data,
value-key: 1,
label-key: 0,
label-key: none,
radius: 4,
slice-style: colors,
inner-radius: 1,
Expand Down
Binary file modified manual.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions manual.typ
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "/src/cetz.typ"
#import "/doc/util.typ": *
#import "/doc/example.typ": example
#import "/doc/style.typ" as doc-style
#import "/src/lib.typ": *
#import "/src/cetz.typ": *
#import "@preview/tidy:0.2.0"


Expand Down Expand Up @@ -39,7 +39,7 @@ 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.2.2"
#import "@preview/cetz:0.3.0"
#import "@preview/cetz-plot:0.1.0"
#cetz.canvas({
import cetz.draw: *
Expand Down
17 changes: 3 additions & 14 deletions src/axes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
padding: 0,
))

// Default Schoolbook Style
#let default-style-schoolbook = util.merge-dictionary(default-style, (
x: (stroke: auto, fill: none, mark: (start: none, end: "straight"),
tick: (label: (anchor: "north"))),
Expand Down Expand Up @@ -223,14 +224,13 @@
// - ticks (dictionary): Tick settings:
// - step (number): Major tic step
// - minor-step (number): Minor tic step
// - unit (content): Tick label suffix
// - decimals (int): Tick float decimal length
// - label (content): Axis label
// - mode (string): Axis scaling function. Takes `lin` or `log`
// - base (number): Base for tick labels when logarithmically scaled.
#let axis(min: -1, max: 1, label: none,
ticks: (step: auto, minor-step: none,
unit: none, decimals: 2, grid: false,
decimals: 2, grid: false,
format: "float"
),
mode: auto, base: auto) = (
Expand All @@ -243,14 +243,6 @@
// to content! Typst has negative zero floats.
if value == 0 { value = 0 }

let round(value, digits) = {
calc.round(value, digits: digits)
}

let format-float(value, digits) = {
$#round(value, digits)$
}

if type(value) != typst-content {
let format = tic-options.at("format", default: "float")
if format == none {
Expand All @@ -262,15 +254,12 @@
} else if format == "sci" {
value = formats.sci(value, digits: tic-options.at("decimals", default: 2))
} else {
value = format-float(value, tic-options.at("decimals", default: 2))
value = formats.decimal(value, digits: tic-options.at("decimals", default: 2))
}
} else if type(value) != typst-content {
value = str(value)
}

if tic-options.at("unit", default: none) != none {
value += tic-options.unit
}
return value
}

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.2.2": *
#import "@preview/cetz:0.3.0": *
10 changes: 5 additions & 5 deletions src/chart/barchart.typ
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
/// width can be set to `auto`.
/// - bar-style (style,function): Style or function (idx => style) to use for
/// each bar, accepts a palette function.
/// - x-unit (content,auto): Tick suffix added to each tick label
/// - y-label (content,none): Y axis label
/// - x-label (content,none): x axis label
/// - labels (none,content): Legend labels per x value group
Expand All @@ -67,7 +66,7 @@
size: (auto, 1),
bar-style: palette.red,
x-label: none,
x-unit: auto,
x-format: auto,
y-label: none,
labels: none,
..plot-args
Expand Down Expand Up @@ -100,9 +99,9 @@
(data.len() - i - 1, t.at(label-key))
})

let x-unit = x-unit
if x-unit == auto {
x-unit = if mode == "stacked100" {[%]} else []
let x-format = x-format
if x-format == auto {
x-format = if mode == "stacked100" {plot.formats.decimal.with(suffix: [%])} else {auto}
}

data = data.enumerate().map(((i, d)) => {
Expand All @@ -119,6 +118,7 @@
axis-style: "scientific-auto",
x-label: x-label,
x-grid: true,
x-format: x-format,
y-label: y-label,
y-min: -y-inset,
y-max: data.len() + y-inset - 1,
Expand Down
2 changes: 1 addition & 1 deletion src/chart/boxwhisker.typ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// Add one or more box or whisker plots.
///
/// #example(```
/// cetz.chart.boxwhisker(size: (2,2), label-key: none,
/// chart.boxwhisker(size: (2,2), label-key: none,
/// y-min: 0, y-max: 70, y-tick-step: 20,
/// (x: 1, min: 15, max: 60,
/// q1: 25, q2: 35, q3: 50))
Expand Down
10 changes: 5 additions & 5 deletions src/chart/columnchart.typ
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
/// width can be set to `auto`.
/// - bar-style (style,function): Style or function (idx => style) to use for
/// each bar, accepts a palette function.
/// - y-unit (content,auto): Tick suffix added to each tick label
/// - y-label (content,none): Y axis label
/// - x-label (content,none): x axis label
/// - labels (none,content): Legend labels per y value group
Expand All @@ -67,7 +66,7 @@
size: (auto, 1),
bar-style: palette.red,
x-label: none,
y-unit: auto,
y-format: auto,
y-label: none,
labels: none,
..plot-args
Expand Down Expand Up @@ -98,9 +97,9 @@
(i, t.at(label-key))
})

let y-unit = y-unit
if y-unit == auto {
y-unit = if mode == "stacked100" {[%]} else []
let y-format = y-format
if y-format == auto {
y-format = if mode == "stacked100" {plot.formats.decimal.with(suffix: [%])} else {auto}
}

data = data.enumerate().map(((i, d)) => {
Expand All @@ -117,6 +116,7 @@
axis-style: "scientific-auto",
y-grid: true,
y-label: y-label,
y-format: y-format,
x-min: -x-inset,
x-max: data.len() + x-inset - 1,
x-tick-step: none,
Expand Down
1 change: 0 additions & 1 deletion src/chart/piechart.typ
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
/// Draw a pie- or donut-chart
///
/// #example(```
/// import cetz.chart
/// let data = (24, 31, 18, 21, 23, 18, 27, 17, 26, 13)
/// let colors = gradient.linear(red, blue, green, yellow)
///
Expand Down
9 changes: 2 additions & 7 deletions src/plot.typ
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's cetz-plot that imports cetz, this version assertion only checks whether a maintainer has forgotten to update this value - not whether the end user is using a compatible cetz version.

perhaps cetz can set a state on the document indicating its version for consumer packages to check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks the cetz version used by the user, as the version is stored with the context (with cetz >= 0.3.0).

Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@
/// Number of decimals digits to display for tick labels, if the format is set
/// to `"float"`.
/// ])
/// #show-parameter-block("unit", ("none", "content"), default: "none", [
/// Suffix to append to all tick labels.
/// ])
/// #show-parameter-block("mode", ("none", "string"), default: "none", [
/// The scaling function of the axis. Takes `lin` (default) for linear scaling,
/// and `log` for logarithmic scaling.])
Expand Down Expand Up @@ -160,7 +157,7 @@
///
/// #example(```
/// let opts = (x-tick-step: none, y-tick-step: none, size: (2,1))
/// let data = cetz.plot.add(((-1,-1), (1,1),), mark: "o")
/// let data = plot.add(((-1,-1), (1,1),), mark: "o")
///
/// for name in (none, "school-book", "left", "scientific") {
/// plot.plot(axis-style: name, ..opts, data, name: "plot")
Expand Down Expand Up @@ -207,7 +204,7 @@
legend-style: (:),
..options
) = draw.group(name: name, ctx => {
// TODO: Assert cetz min version here!
draw.assert-version(version(0, 3, 0))

// Create plot context object
let make-ctx(x, y, size) = {
Expand Down Expand Up @@ -523,8 +520,6 @@
/// axis tuple to specify which axis coordinate system to use.
///
/// #example(```
/// import cetz.plot
/// import cetz.draw: *
/// plot.plot(size: (2,2), name: "plot",
/// x-tick-step: none, y-tick-step: none, {
/// plot.add(((0,0), (1,1), (2,.5), (4,3)))
Expand Down
1 change: 0 additions & 1 deletion src/plot/annotation.typ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/// by its x and y axis.
///
/// #example(```
/// import cetz.plot
/// plot.plot(size: (2,2), x-tick-step: none, y-tick-step: none, {
/// plot.add(domain: (0, 2*calc.pi), calc.sin)
/// plot.annotate({
Expand Down
4 changes: 2 additions & 2 deletions src/plot/boxwhisker.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/// Add one or more box or whisker plots
///
/// #example(```
/// cetz.plot.plot(size: (2,2), x-tick-step: none, y-tick-step: none, {
/// cetz.plot.add-boxwhisker((x: 1, // Location on x-axis
/// plot.plot(size: (2,2), x-tick-step: none, y-tick-step: none, {
/// plot.add-boxwhisker((x: 1, // Location on x-axis
/// outliers: (7, 65, 69), // Optional outlier values
/// min: 15, max: 60, // Minimum and maximum
/// q1: 25, // Quartiles: Lower
Expand Down
4 changes: 2 additions & 2 deletions src/plot/contour.typ
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@
/// Add a contour plot of a sampled function or a matrix.
///
/// #example(```
/// cetz.plot.plot(size: (2,2), x-tick-step: none, y-tick-step: none, {
/// cetz.plot.add-contour(x-domain: (-3, 3), y-domain: (-3, 3),
/// plot.plot(size: (2,2), x-tick-step: none, y-tick-step: none, {
/// plot.add-contour(x-domain: (-3, 3), y-domain: (-3, 3),
/// style: (fill: rgb(50,50,250,50)),
/// fill: true,
/// op: "<", // Find contours where data < z
Expand Down
Loading