Skip to content

Commit

Permalink
Add new tick format for log
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrswift committed Jul 14, 2024
1 parent ee09d6f commit b2ecb7b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/axes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@
$#round(value, digits)$
}

let format-log(value, base: 10) = {
let exponent = if value != 0 {
calc.log(calc.abs(value), base: base)
} else {0}
return $#base^#exponent$
}

let format-sci(value, digits) = {
let exponent = if value != 0 {
calc.floor(calc.log(calc.abs(value), base: 10))
Expand Down Expand Up @@ -278,6 +285,8 @@
value = (format)(value)
} else if format == "sci" {
value = format-sci(value, tic-options.at("decimals", default: 2))
} else if format == "log" {
value = format-log(value, base: tic-options.at("base", default: 10))
} else {
value = format-float(value, tic-options.at("decimals", default: 2))
}
Expand Down Expand Up @@ -349,7 +358,7 @@
let n-minor = range(1, 10)

for t-minor in n-minor {

let place = t + calc.log(t-minor, base: 10)

if ( place > axis.max){ continue }
Expand Down
4 changes: 2 additions & 2 deletions tests/axes/log-mode/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
axis-style: "scientific",
y-mode: "log",
y-grid: "both",
y-format: "sci",
y-format: "log",
y-tick-step: 1,
y-minor-tick-step: 1,
y-min: 0, y-max: 4,

x-mode: "log",
x-grid: "both",
x-format: "sci",
x-format: "log",
x-tick-step: 1,
x-minor-tick-step: 1,
x-min: 0.00001, x-max: 4,
Expand Down

0 comments on commit b2ecb7b

Please sign in to comment.