Skip to content

Commit 06e9308

Browse files
Typos & Formatting (#43)
2 parents 8fdcf20 + e353f2e commit 06e9308

11 files changed

Lines changed: 63 additions & 49 deletions

File tree

src/axes.typ

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@
497497
}
498498

499499
// Prepares the axis post creation. The given axis
500-
// must be completely set-up, including its intervall.
500+
// must be completely set-up, including its interval.
501501
// Returns the prepared axis
502502
#let prepare-axis(ctx, axis, name) = {
503503
let style = styles.resolve(ctx.style, root: "axes",
@@ -531,15 +531,17 @@
531531
// - vec (vector): Input vector to transform
532532
// -> vector
533533
#let transform-vec(size, x-axis, y-axis, z-axis, vec) = {
534+
let axes = (x-axis, y-axis)
534535

535-
let (x,y,) = for (dim, axis) in (x-axis, y-axis).enumerate() {
536-
536+
let (x, y,) = for (dim, axis) in axes.enumerate() {
537537
let s = size.at(dim) - axis.inset.sum()
538538
let o = axis.inset.at(0)
539539

540-
let transform-func(n) = if (axis.mode == "log") {
540+
let transform-func(n) = if axis.mode == "log" {
541541
calc.log(calc.max(n, util.float-epsilon), base: axis.base)
542-
} else {n}
542+
} else {
543+
n
544+
}
543545

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

src/plot/bar.typ

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@
143143
/// - data (array): Array of data items. An item is an array containing a x an one or more y values.
144144
/// For example `(0, 1)` or `(0, 10, 5, 30)`. Depending on the `mode`, the data items
145145
/// get drawn as either clustered or stacked rects.
146-
/// - x-key: (int,string): Key to use for retreiving a bars x-value from a single data entry.
146+
/// - x-key: (int,string): Key to use for retrieving a bars x-value from a single data entry.
147147
/// This value gets passed to the `.at(...)` function of a data item.
148-
/// - y-key: (auto,int,string,array): Key to use for retreiving a bars y-value. For clustered/stacked
148+
/// - y-key: (auto,int,string,array): Key to use for retrieving a bars y-value. For clustered/stacked
149149
/// data, this must be set to a list of keys (e.g. `range(1, 4)`). If set to `auto`, att but the first
150150
/// array-values of a data item are used as y-values.
151-
/// - error-key: (none,int,string): Key to use for retreiving a bars y-error.
151+
/// - error-key: (none,int,string): Key to use for retrieving a bars y-error.
152152
/// - mode (string): The mode on how to group data items into bars:
153153
/// / basic: Add one bar per data value. If the data contains multiple values,
154154
/// group those bars next to each other.

src/plot/contour.typ

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,10 @@
209209
let (x, y) = (ctx.x, ctx.y)
210210

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

215214
if self.fill {
216-
c.fill-paths = util.compute-fill-paths(c.line-data,
217-
(x.min, y.min), (x.max, y.max))
215+
c.fill-paths = util.compute-fill-paths(c.line-data, x, y)
218216
}
219217
return c
220218
})

src/plot/formats.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
/// ```
116116
///
117117
/// - value (number): Value to format
118-
/// - digits (int): Number of digits for rouding the factor
118+
/// - digits (int): Number of digits for rounding the factor
119119
/// -> Content
120120
#let sci(value, digits: 2) = {
121121
let exponent = if value != 0 {

src/plot/line.typ

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@
8686
let (x, y) = (ctx.x, ctx.y)
8787

8888
// Generate stroke paths
89-
self.stroke-paths = util.compute-stroke-paths(self.line-data,
90-
(x.min, y.min), (x.max, y.max))
89+
self.stroke-paths = util.compute-stroke-paths(self.line-data, x, y)
9190

9291
// Compute fill paths if filling is requested
9392
self.hypograph = self.at("hypograph", default: false)
9493
self.epigraph = self.at("epigraph", default: false)
9594
self.fill = self.at("fill", default: false)
9695
if self.hypograph or self.epigraph or self.fill {
97-
self.fill-paths = util.compute-fill-paths(self.line-data,
98-
(x.min, y.min), (x.max, y.max))
96+
self.fill-paths = util.compute-fill-paths(self.line-data, x, y)
9997
}
10098

10199
return self
@@ -463,15 +461,12 @@
463461

464462
// Generate stroke paths
465463
self.stroke-paths = (
466-
a: util.compute-stroke-paths(self.line-data.a,
467-
(x.min, y.min), (x.max, y.max)),
468-
b: util.compute-stroke-paths(self.line-data.b,
469-
(x.min, y.min), (x.max, y.max))
464+
a: util.compute-stroke-paths(self.line-data.a, x, y),
465+
b: util.compute-stroke-paths(self.line-data.b, x, y),
470466
)
471467

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

476471
return self
477472
}

src/plot/util.typ

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109

110110
let is-inside = in-rect(pt)
111111

112-
let (x1, y1) = prev
113-
let (x2, y2) = pt
112+
let (x1, y1, ..) = prev
113+
let (x2, y2, ..) = pt
114114

115115
// Ignore lines if both ends are outsides the x-window and on the
116116
// same side.
@@ -173,21 +173,21 @@
173173
/// Compute clipped stroke paths
174174
///
175175
/// - points (array): X/Y data points
176-
/// - low (vector): Lower clip-window coordinate
177-
/// - high (vector): Upper clip-window coordinate
176+
/// - x (axis): X-Axis
177+
/// - y (axis): Y-Axis
178178
/// -> array List of stroke paths
179-
#let compute-stroke-paths(points, low, high) = {
180-
clipped-paths(points, low, high, fill: false)
179+
#let compute-stroke-paths(points, x, y) = {
180+
clipped-paths(points, (x.min, y.min), (x.max, y.max), fill: false)
181181
}
182182

183183
/// Compute clipped fill path
184184
///
185185
/// - points (array): X/Y data points
186-
/// - low (vector): Lower clip-window coordinate
187-
/// - high (vector): Upper clip-window coordinate
186+
/// - x (axis): X-Axis
187+
/// - y (axis): Y-Axis
188188
/// -> array List of fill paths
189-
#let compute-fill-paths(points, low, high) = {
190-
clipped-paths(points, low, high, fill: true)
189+
#let compute-fill-paths(points, x, y) = {
190+
clipped-paths(points, (x.min, y.min), (x.max, y.max), fill: true)
191191
}
192192

193193
/// Return points of a sampled catmull-rom through the

src/plot/violin.typ

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@
33
#import "sample.typ"
44

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

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

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

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

2625
for p in stroke-paths{
2726
let args = arguments(..p, closed: self.side == "both")
@@ -46,7 +45,7 @@
4645
min: min - (self.extents * range),
4746
max: max + (self.extents * range),
4847
convolve: (t) => {
49-
points.map((y)=>(self.kernel)((y - t)/self.bandwidth)).sum() / (points.len() * self.bandwidth)
48+
points.map(y => (self.kernel)((y - t) / self.bandwidth)).sum() / (points.len() * self.bandwidth)
5049
}
5150
)
5251
})
@@ -77,8 +76,8 @@
7776
///
7877
/// - data (array): Array of data items. An item is an array containing an `x` and one
7978
/// or more `y` values.
80-
/// - x-key (int, string): Key to use for retreiving the `x` position of the violin.
81-
/// - y-key (int, string): Key to use for retreiving values of points within the category.
79+
/// - x-key (int, string): Key to use for retrieving the `x` position of the violin.
80+
/// - y-key (int, string): Key to use for retrieving values of points within the category.
8281
/// - side (string): The sides of the violin to be rendered:
8382
/// / left: Plot only the left side of the violin.
8483
/// / right: Plot only the right side of the violin.
@@ -132,4 +131,4 @@
132131
plot-legend-preview: _plot-legend-preview,
133132
),)
134133

135-
}
134+
}

tests/axes/log-mode/test.typ

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,3 @@
163163
}
164164
)
165165
}))
166-

tests/plot/annotation/ref/1.png

16.6 KB
Loading

tests/plot/annotation/test.typ

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,24 @@
2323
})
2424
})
2525
})
26+
27+
#test-case({
28+
import draw: *
29+
set-style(rect: (stroke: none))
30+
31+
plot.plot(size: (6, 4), x-horizontal: false, y-horizontal: true, {
32+
plot.add(domain: (-calc.pi, 3*calc.pi), calc.sin)
33+
plot.annotate(background: true, {
34+
rect((0, -1), (calc.pi, 1), fill: blue.lighten(90%))
35+
rect((calc.pi, -1.1), (2*calc.pi, 1.1), fill: red.lighten(90%))
36+
rect((2*calc.pi, -1.5), (3.5*calc.pi, 1.5), fill: green.lighten(90%))
37+
})
38+
plot.annotate(padding: .1, {
39+
line((calc.pi / 2, 1.1), (rel: (0, .2)), (rel: (2*calc.pi, 0)), (rel: (0, -.2)))
40+
content((calc.pi * 1.5, 1.5), $ lambda $)
41+
})
42+
plot.annotate(padding: .1, {
43+
line((calc.pi / 2,-.1), (calc.pi / 2, .8), mark: (end: "stealth"))
44+
})
45+
})
46+
})

0 commit comments

Comments
 (0)