Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Refactoring I #81

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:3.20

RUN apk update
RUN apk add git
RUN apk add curl
RUN apk add just

RUN apk add --no-cache rust cargo

ENV PATH="/root/.cargo/bin:$PATH"
RUN apk add openssl openssl-dev
RUN cargo install --locked typst-cli
RUN cargo install --locked --git https://github.com/tingerrr/typst-test --tag ci-semi-stable
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"build": { "dockerfile": "Dockerfile" },

"customizations": {
"vscode": {
"extensions": ["myriad-dreamin.tinymist"]
}
},

"forwardPorts": [3000]
}
3 changes: 2 additions & 1 deletion manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ module imported into the namespace.
= Plot

#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", "comb", "legend") {
doc-style.parse-show-module("/src/plot/" + m + ".typ")
}

Expand Down
63 changes: 35 additions & 28 deletions src/axes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
format: "float"
),
mode: auto, base: auto) = (
min: min, max: max, ticks: ticks, label: label, inset: (0, 0), show-break: false, mode: mode, base: base
min: min, max: max, ticks: ticks, label: label, inset: (0, 0), show-break: false, mode: mode, base: base,
kind: "cartesian",
)

// Format a tick value
Expand Down Expand Up @@ -509,44 +510,50 @@
return axis
}

// Transform a single value along a cartesian axis
#let transform-cartesian(axis, v) = {
let a = axis.origin
let b = axis.target

let length = vector.dist(a, b) - axis.inset.sum()
let offset = axis.inset.at(0)

let transform-func(n) = if axis.mode == "log" {
calc.log(calc.max(n, util.float-epsilon), base: axis.base)
} else {
n
}

let factor = length / (transform-func(axis.max) - transform-func(axis.min))
return vector.scale(
vector.norm(vector.sub(b, a)),
(transform-func(v) - transform-func(axis.min)) * factor + offset)
}

// Transform a single vector along a x, y and z axis
//
// - size (vector): Coordinate system size
// - x-axis (axis): X axis
// - y-axis (axis): Y axis
// - z-axis (axis): Z axis
// - axes (list): List of axes
// - vec (vector): Input vector to transform
// -> vector
#let transform-vec(size, x-axis, y-axis, z-axis, vec) = {
let axes = (x-axis, y-axis)

let (x, y,) = for (dim, axis) in axes.enumerate() {
let s = size.at(dim) - axis.inset.sum()
let o = axis.inset.at(0)
#let transform-vec(axes, vec) = {
let res = (0, 0, 0)
for (dim, axis) in axes.enumerate() {
let v = vec.at(dim, default: 0)

let transform-func(n) = if axis.mode == "log" {
calc.log(calc.max(n, util.float-epsilon), base: axis.base)
if axis.kind == "cartesian" {
res = vector.add(res, transform-cartesian(axis, v))
} else {
n
panic("Unknown axit type " + repr(axis.kind))
}

let range = transform-func(axis.max) - transform-func(axis.min)

let f = s / range
((transform-func(vec.at(dim)) - transform-func(axis.min)) * f + o,)
}

return (x, y, 0)
return res
}

// Draw inside viewport coordinates of two axes
//
// - size (vector): Axis canvas size (relative to origin)
// - x (axis): Horizontal axis
// - y (axis): Vertical axis
// - z (axis): Z axis
// - axes (list): List of axes
// - name (string,none): Group name
#let axis-viewport(size, x, y, z, body, name: none) = {
#let axis-viewport(axes, body, name: none) = {
draw.group(name: name, (ctx => {
let transform = ctx.transform

Expand All @@ -559,12 +566,12 @@
if "segments" in d {
d.segments = d.segments.map(((kind, ..pts)) => {
(kind, ..pts.map(pt => {
transform-vec(size, x, y, none, pt)
transform-vec(axes, pt)
}))
})
}
if "pos" in d {
d.pos = transform-vec(size, x, y, none, d.pos)
d.pos = transform-vec(axes, d.pos)
}
return d
})
Expand Down
Loading
Loading