Skip to content

Commit

Permalink
release: Use std module, revert equation workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Oct 19, 2024
1 parent 34d5a11 commit 4525c9e
Show file tree
Hide file tree
Showing 32 changed files with 14 additions and 19 deletions.
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.
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.
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
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/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
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/parametric/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/ref/1.png
Binary file modified tests/plot/reverse-axis/ref/1.png
Binary file modified tests/plot/vertical/ref/1.png
Binary file modified tests/plot/violin/ref/1.png

0 comments on commit 4525c9e

Please sign in to comment.