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

Typos & Formatting #43

Merged
merged 3 commits into from
Sep 8, 2024
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
12 changes: 7 additions & 5 deletions src/axes.typ
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
}

// Prepares the axis post creation. The given axis
// must be completely set-up, including its intervall.
// must be completely set-up, including its interval.
// Returns the prepared axis
#let prepare-axis(ctx, axis, name) = {
let style = styles.resolve(ctx.style, root: "axes",
Expand Down Expand Up @@ -531,15 +531,17 @@
// - 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 (x-axis, y-axis).enumerate() {

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-func(n) = if (axis.mode == "log") {
let transform-func(n) = if axis.mode == "log" {
calc.log(calc.max(n, util.float-epsilon), base: axis.base)
} else {n}
} else {
n
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/plot/bar.typ
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@
/// - data (array): Array of data items. An item is an array containing a x an one or more y values.
/// For example `(0, 1)` or `(0, 10, 5, 30)`. Depending on the `mode`, the data items
/// get drawn as either clustered or stacked rects.
/// - x-key: (int,string): Key to use for retreiving a bars x-value from a single data entry.
/// - x-key: (int,string): Key to use for retrieving a bars x-value from a single data entry.
/// This value gets passed to the `.at(...)` function of a data item.
/// - y-key: (auto,int,string,array): Key to use for retreiving a bars y-value. For clustered/stacked
/// - y-key: (auto,int,string,array): Key to use for retrieving a bars y-value. For clustered/stacked
/// data, this must be set to a list of keys (e.g. `range(1, 4)`). If set to `auto`, att but the first
/// array-values of a data item are used as y-values.
/// - error-key: (none,int,string): Key to use for retreiving a bars y-error.
/// - error-key: (none,int,string): Key to use for retrieving a bars y-error.
/// - mode (string): The mode on how to group data items into bars:
/// / basic: Add one bar per data value. If the data contains multiple values,
/// group those bars next to each other.
Expand Down
6 changes: 2 additions & 4 deletions src/plot/contour.typ
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,10 @@
let (x, y) = (ctx.x, ctx.y)

self.contours = self.contours.map(c => {
c.stroke-paths = util.compute-stroke-paths(c.line-data,
(x.min, y.min), (x.max, y.max))
c.stroke-paths = util.compute-stroke-paths(c.line-data, x, y)

if self.fill {
c.fill-paths = util.compute-fill-paths(c.line-data,
(x.min, y.min), (x.max, y.max))
c.fill-paths = util.compute-fill-paths(c.line-data, x, y)
}
return c
})
Expand Down
2 changes: 1 addition & 1 deletion src/plot/formats.typ
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
/// ```
///
/// - value (number): Value to format
/// - digits (int): Number of digits for rouding the factor
/// - digits (int): Number of digits for rounding the factor
/// -> Content
#let sci(value, digits: 2) = {
let exponent = if value != 0 {
Expand Down
15 changes: 5 additions & 10 deletions src/plot/line.typ
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,14 @@
let (x, y) = (ctx.x, ctx.y)

// Generate stroke paths
self.stroke-paths = util.compute-stroke-paths(self.line-data,
(x.min, y.min), (x.max, y.max))
self.stroke-paths = util.compute-stroke-paths(self.line-data, x, y)

// Compute fill paths if filling is requested
self.hypograph = self.at("hypograph", default: false)
self.epigraph = self.at("epigraph", default: false)
self.fill = self.at("fill", default: false)
if self.hypograph or self.epigraph or self.fill {
self.fill-paths = util.compute-fill-paths(self.line-data,
(x.min, y.min), (x.max, y.max))
self.fill-paths = util.compute-fill-paths(self.line-data, x, y)
}

return self
Expand Down Expand Up @@ -463,15 +461,12 @@

// Generate stroke paths
self.stroke-paths = (
a: util.compute-stroke-paths(self.line-data.a,
(x.min, y.min), (x.max, y.max)),
b: util.compute-stroke-paths(self.line-data.b,
(x.min, y.min), (x.max, y.max))
a: util.compute-stroke-paths(self.line-data.a, x, y),
b: util.compute-stroke-paths(self.line-data.b, x, y),
)

// Generate fill paths
self.fill-paths = util.compute-fill-paths(self.line-data.a + self.line-data.b.rev(),
(x.min, y.min), (x.max, y.max))
self.fill-paths = util.compute-fill-paths(self.line-data.a + self.line-data.b.rev(), x, y)

return self
}
Expand Down
20 changes: 10 additions & 10 deletions src/plot/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@

let is-inside = in-rect(pt)

let (x1, y1) = prev
let (x2, y2) = pt
let (x1, y1, ..) = prev
let (x2, y2, ..) = pt

// Ignore lines if both ends are outsides the x-window and on the
// same side.
Expand Down Expand Up @@ -173,21 +173,21 @@
/// Compute clipped stroke paths
///
/// - points (array): X/Y data points
/// - low (vector): Lower clip-window coordinate
/// - high (vector): Upper clip-window coordinate
/// - x (axis): X-Axis
/// - y (axis): Y-Axis
/// -> array List of stroke paths
#let compute-stroke-paths(points, low, high) = {
clipped-paths(points, low, high, fill: false)
#let compute-stroke-paths(points, x, y) = {
clipped-paths(points, (x.min, y.min), (x.max, y.max), fill: false)
}

/// Compute clipped fill path
///
/// - points (array): X/Y data points
/// - low (vector): Lower clip-window coordinate
/// - high (vector): Upper clip-window coordinate
/// - x (axis): X-Axis
/// - y (axis): Y-Axis
/// -> array List of fill paths
#let compute-fill-paths(points, low, high) = {
clipped-paths(points, low, high, fill: true)
#let compute-fill-paths(points, x, y) = {
clipped-paths(points, (x.min, y.min), (x.max, y.max), fill: true)
}

/// Return points of a sampled catmull-rom through the
Expand Down
25 changes: 12 additions & 13 deletions src/plot/violin.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
#import "sample.typ"

#let kernel-normal(x, stdev: 1.5) = {
(1/calc.sqrt(2*calc.pi*calc.pow(stdev,2))) * calc.exp( - (x*x)/(2*calc.pow(stdev,2)))
(1 / calc.sqrt(2 * calc.pi*calc.pow(stdev, 2))) * calc.exp(-(x*x) / (2 * calc.pow(stdev, 2)))
}

#let _violin-render(self, ctx, violin, filling: true) = {
let path = range(self.samples)
.map((t)=>violin.min + (violin.max - violin.min) * (t /self.samples ))
.map((u)=>(u, (violin.convolve)(u)))
.map(((u,v)) => {
(violin.x-position + v, u)
})
.map((t)=>violin.min + (violin.max - violin.min) * (t / self.samples ))
.map((u)=>(u, (violin.convolve)(u)))
.map(((u,v)) => {
(violin.x-position + v, u)
})

if self.side == "both"{
path += path.rev().map(((x,y))=> {(2 * violin.x-position - x,y)})
} else if self.side == "left"{
path = path.map( ((x,y))=>{(2 * violin.x-position - x,y)})
path = path.map(((x,y)) => (2 * violin.x-position - x,y))
}

let (x, y) = (ctx.x, ctx.y)
let stroke-paths = util.compute-stroke-paths(path, (x.min, y.min), (x.max, y.max))
let stroke-paths = util.compute-stroke-paths(path, ctx.x, ctx.y)

for p in stroke-paths{
let args = arguments(..p, closed: self.side == "both")
Expand All @@ -46,7 +45,7 @@
min: min - (self.extents * range),
max: max + (self.extents * range),
convolve: (t) => {
points.map((y)=>(self.kernel)((y - t)/self.bandwidth)).sum() / (points.len() * self.bandwidth)
points.map(y => (self.kernel)((y - t) / self.bandwidth)).sum() / (points.len() * self.bandwidth)
}
)
})
Expand Down Expand Up @@ -77,8 +76,8 @@
///
/// - data (array): Array of data items. An item is an array containing an `x` and one
/// or more `y` values.
/// - x-key (int, string): Key to use for retreiving the `x` position of the violin.
/// - y-key (int, string): Key to use for retreiving values of points within the category.
/// - x-key (int, string): Key to use for retrieving the `x` position of the violin.
/// - y-key (int, string): Key to use for retrieving values of points within the category.
/// - side (string): The sides of the violin to be rendered:
/// / left: Plot only the left side of the violin.
/// / right: Plot only the right side of the violin.
Expand Down Expand Up @@ -132,4 +131,4 @@
plot-legend-preview: _plot-legend-preview,
),)

}
}
1 change: 0 additions & 1 deletion tests/axes/log-mode/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,3 @@
}
)
}))

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.
21 changes: 21 additions & 0 deletions tests/plot/annotation/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@
})
})
})

#test-case({
import draw: *
set-style(rect: (stroke: none))

plot.plot(size: (6, 4), x-horizontal: false, y-horizontal: true, {
plot.add(domain: (-calc.pi, 3*calc.pi), calc.sin)
plot.annotate(background: true, {
rect((0, -1), (calc.pi, 1), fill: blue.lighten(90%))
rect((calc.pi, -1.1), (2*calc.pi, 1.1), fill: red.lighten(90%))
rect((2*calc.pi, -1.5), (3.5*calc.pi, 1.5), fill: green.lighten(90%))
})
plot.annotate(padding: .1, {
line((calc.pi / 2, 1.1), (rel: (0, .2)), (rel: (2*calc.pi, 0)), (rel: (0, -.2)))
content((calc.pi * 1.5, 1.5), $ lambda $)
})
plot.annotate(padding: .1, {
line((calc.pi / 2,-.1), (calc.pi / 2, .8), mark: (end: "stealth"))
})
})
})
4 changes: 2 additions & 2 deletions tests/plot/violin/test.typ
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#set page(width: auto, height: auto)
#import "/src/lib.typ": *
#import "/src/cetz.typ": *
#import "/src/lib.typ": *
#import "/tests/helper.typ": *

/* Empty plot */
Expand Down Expand Up @@ -60,4 +60,4 @@
label: [Female]
)
})
})
})
Loading