Skip to content

Commit

Permalink
Release 0.1.0 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf authored Oct 19, 2024
2 parents 532970c + 62a63c2 commit af06f27
Show file tree
Hide file tree
Showing 45 changed files with 37 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ jobs:
packages: imagemagick cargo parallel
version: 1.0
- name: Install just from crates.io
uses: baptiste0928/cargo-install@v2.2.0
uses: baptiste0928/cargo-install@v3
with:
crate: just
- name: Install typst-test from github
uses: baptiste0928/cargo-install@v2.2.0
uses: baptiste0928/cargo-install@v3
with:
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
git clone --depth 1 --branch v0.3.1 https://github.com/cetz-package/cetz.git ~/.local/share/typst/packages/preview/cetz/0.3.1
- uses: typst-community/setup-typst@v3
with:
typst-version: '0.12.0-rc1'
typst-version: '0.12.0-rc2'
cache-dependency-path: src/cetz.typ
- run: |
just install @local
Expand Down
4 changes: 2 additions & 2 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.3.0.
CeTZ-Plot requires CeTZ version ≥ 0.3.1!

## Examples
<!-- img width is set so the table gets evenly spaced by GitHubs css -->
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.3.0"
#import "@preview/cetz:0.3.1"
#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.
2 changes: 1 addition & 1 deletion gallery/barchart.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.3.0": canvas, draw
#import "@preview/cetz:0.3.1": canvas, draw
#import "@preview/cetz-plot:0.1.0": chart

#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.
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.3.0": canvas, draw
#import "@preview/cetz:0.3.1": canvas, draw
#import "@preview/cetz-plot:0.1.0": plot

#set page(width: auto, height: auto, margin: .5cm)
Expand Down
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.
2 changes: 1 addition & 1 deletion gallery/piechart.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/cetz:0.3.0"
#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0": chart

#set page(width: auto, height: auto, margin: .5cm)
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
Expand Up @@ -3,7 +3,7 @@
#import "/doc/example.typ": example
#import "/doc/style.typ" as doc-style
#import "/src/lib.typ": *
#import "@preview/tidy:0.2.0"
#import "@preview/tidy:0.3.0"


// Usage:
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.3.0"
#import "@preview/cetz:0.3.1"
#import "@preview/cetz-plot:0.1.0"
#cetz.canvas({
import cetz.draw: *
Expand Down
10 changes: 4 additions & 6 deletions src/axes.typ
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#import "/src/cetz.typ": util, draw, vector, matrix, styles, process, drawable, path-util, process
#import "/src/plot/formats.typ"

#let typst-content = content

/// Default axis style
///
/// #show-parameter-block("tick-limit", "int", default: 100, [Upper major tick limit.])
Expand Down Expand Up @@ -243,11 +241,11 @@
// to content! Typst has negative zero floats.
if value == 0 { value = 0 }

if type(value) != typst-content {
if type(value) != std.content {
let format = tic-options.at("format", default: "float")
if format == none {
value = []
} else if type(format) == typst-content {
} else if type(format) == std.content {
value = format
} else if type(format) == function {
value = (format)(value)
Expand All @@ -256,7 +254,7 @@
} else {
value = formats.decimal(value, digits: tic-options.at("decimals", default: 2))
}
} else if type(value) != typst-content {
} else if type(value) != std.content {
value = str(value)
}

Expand Down Expand Up @@ -902,7 +900,7 @@
if shared-zero {
let pt = (rel: (-style.tick.label.offset, -style.tick.label.offset),
to: (y-x, x-y))
let zero = if type(style.shared-zero) == typst-content {
let zero = if type(style.shared-zero) == std.content {
style.shared-zero
} else {
$0$
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.3.0": *
#import "@preview/cetz:0.3.1": *
11 changes: 9 additions & 2 deletions src/plot.typ
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
legend-style: (:),
..options
) = draw.group(name: name, ctx => {
draw.assert-version(version(0, 3, 0))
draw.assert-version(version(0, 3, 1))

// Create plot context object
let make-ctx(x, y, size) = {
Expand Down Expand Up @@ -450,7 +450,14 @@
})

if "mark" in d and d.mark != none {
draw.group({
draw.scope({
if y.horizontal {
draw.set-ctx(ctx => {
ctx.transform = matrix.swap-cols(ctx.transform, 0, 1)
return ctx
})
}

draw.set-style(..d.style, ..d.mark-style)
mark.draw-mark(d.data, x, y, d.mark, d.mark-size, size)
})
Expand Down
1 change: 1 addition & 0 deletions src/plot/boxwhisker.typ
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
) + (if "outliers" in data { (
type: "boxwhisker-outliers",
data: data.outliers.map(it => (data.x, it)),
axes: axes,
mark: mark,
mark-size: mark-size,
mark-style: (:)
Expand Down
21 changes: 9 additions & 12 deletions src/plot/formats.typ
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Temporary fix Typst measure bug
#let _block-eq(body) = math.equation(block: true, numbering: none, body)

// Compare two floats
#let _compare(a, b, eps: 1e-6) = {
return calc.abs(a - b) <= eps
Expand Down Expand Up @@ -59,7 +56,7 @@
/// - eps (number): Epsilon used for comparison
/// -> Content if a matching fraction could be found or none
#let fraction(value, denom: auto, eps: 1e-6) = {
return _block-eq(_find-fraction(value, denom: denom, eps: eps))
return _find-fraction(value, denom: denom, eps: eps)
}

/// Multiple of tick formatter
Expand Down Expand Up @@ -88,24 +85,24 @@
/// -> Content if a matching fraction could be found or none
#let multiple-of(value, factor: calc.pi, symbol: $pi$, fraction: true, digits: 2, eps: 1e-6, prefix: [], suffix: []) = {
if _compare(value, 0, eps: eps) {
return _block-eq($0$)
return $0$
}

let a = value / factor
if _compare(a, 1, eps: eps) {
return _block-eq(prefix + symbol + suffix)
return prefix + symbol + suffix
} else if _compare(a, -1, eps: eps) {
return _block-eq(prefix + $-$ + symbol + suffix)
return prefix + $-$ + symbol + suffix
}

if fraction != none {
let frac = _find-fraction(a, denom: if fraction == true { auto } else { fraction })
if frac != none {
return _block-eq(prefix + frac + symbol + suffix)
return prefix + frac + symbol + suffix
}
}

return _block-eq(prefix + $#calc.round(a, digits: digits)$ + symbol + suffix)
return prefix + $#calc.round(a, digits: digits)$ + symbol + suffix
}

/// Scientific notation tick formatter
Expand Down Expand Up @@ -140,10 +137,10 @@

value = calc.round(value, digits: digits)
if exponent <= -1 or exponent >= 1 {
return _block-eq(prefix + $#value times 10^#exponent$ + suffix)
return prefix + $#value times 10^#exponent$ + suffix
}

return _block-eq(prefix + $#value$ + suffix)
return prefix + $#value$ + suffix
}

/// Rounded decimal number formatter
Expand All @@ -163,5 +160,5 @@
/// - suffix (content): Content to append
/// -> Content
#let decimal(value, digits: 2, prefix: [], suffix: []) = {
_block-eq(prefix + $#calc.round(value, digits: digits)$ + suffix)
prefix + $#calc.round(value, digits: digits)$ + suffix
}
2 changes: 1 addition & 1 deletion src/plot/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@

for (name, axis) in axis-dict {
if not "ticks" in axis { axis.ticks = () }
axis.label = get-axis-option(name, "label", math.equation(block: true, numbering: none, $#name$))
axis.label = get-axis-option(name, "label", $#name$)

// Configure axis bounds
axis.min = get-axis-option(name, "min", axis.min)
Expand Down
Binary file modified tests/axes/log-mode/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/axes/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/chart/boxwhisker/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/chart/piechart/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/chart/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/annotation/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/bar/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/boxwhisker/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/broken-axes/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/contour/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/equal-axis/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/format/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/grid/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/hvline/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/legend/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/line/between/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/line/fill/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/line/line-type/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/line/linearization/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/line/mark/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/line/spline/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/marks/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plot/mirror-axes/ref/1.png
Binary file modified tests/plot/parametric/ref/1.png
Binary file modified tests/plot/ref/1.png
Binary file modified tests/plot/reverse-axis/ref/1.png
Binary file modified tests/plot/vertical/ref/1.png
2 changes: 1 addition & 1 deletion tests/plot/vertical/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

plot.plot(size: (10, 10),
{
plot.add(domain: (0, 4*calc.pi), calc.sin, axes: ("y", "x"))
plot.add(domain: (0, 4*calc.pi), calc.sin, axes: ("y", "x"), mark: "+")
})
})

Expand Down
Binary file modified tests/plot/violin/ref/1.png

0 comments on commit af06f27

Please sign in to comment.