Skip to content

Commit b7e311f

Browse files
committed
style: Improve code formatting and readability across multiple files
Refactor various sections of the codebase to enhance readability by applying consistent formatting. This includes adjusting line breaks, indentation, and spacing in function definitions and calls. The changes aim to make the code more maintainable and easier to understand, without altering any functionality.
1 parent d85e156 commit b7e311f

34 files changed

Lines changed: 728 additions & 228 deletions

docs/_demo.qmd

Lines changed: 0 additions & 47 deletions
This file was deleted.

docs/assets/stylesheets/theme.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,37 @@ main .showcase ~ h2,
967967
background-size: 180px 0.5em;
968968
}
969969

970+
// --- Announcement banner. -----------------------------------------------
971+
// Bootstrap 5.3 alert tokens flip on scheme change, which can leave text at
972+
// poor contrast on a bright tint. Pin each alert type to a mode-invariant
973+
// ink/background pair drawn from the brand palette so contrast is stable.
974+
#quarto-announcement {
975+
&.alert-primary { --gb-announcement-ink: #{$paper-light}; --gb-announcement-bg: #{$crayon-red}; --gb-announcement-border: #{$crayon-red}; }
976+
&.alert-secondary { --gb-announcement-ink: #{$paper-light}; --gb-announcement-bg: #{$crayon-teal}; --gb-announcement-border: #{$crayon-teal}; }
977+
&.alert-success { --gb-announcement-ink: #{$ink-light}; --gb-announcement-bg: rgb(127 200 169 / 0.28); --gb-announcement-border: #{$crayon-mint}; }
978+
&.alert-info { --gb-announcement-ink: #{$ink-light}; --gb-announcement-bg: rgb(31 122 140 / 0.18); --gb-announcement-border: #{$crayon-teal}; }
979+
&.alert-warning { --gb-announcement-ink: #{$ink-light}; --gb-announcement-bg: rgb(244 183 64 / 0.30); --gb-announcement-border: #{$crayon-mustard}; }
980+
&.alert-danger { --gb-announcement-ink: #{$paper-light}; --gb-announcement-bg: #{$danger-ink}; --gb-announcement-border: #{$danger-ink}; }
981+
&.alert-light { --gb-announcement-ink: #{$ink-light}; --gb-announcement-bg: #{$surface-light}; --gb-announcement-border: #{$muted-light}; }
982+
&.alert-dark { --gb-announcement-ink: #{$paper-light}; --gb-announcement-bg: #{$ink-light}; --gb-announcement-border: #{$ink-light}; }
983+
984+
background: var(--gb-announcement-bg) !important;
985+
border-color: var(--gb-announcement-border) !important;
986+
987+
&,
988+
.quarto-announcement-content,
989+
.quarto-announcement-content p,
990+
.quarto-announcement-content a,
991+
.quarto-announcement-icon,
992+
.quarto-announcement-action {
993+
color: var(--gb-announcement-ink) !important;
994+
}
995+
996+
.quarto-announcement-content a {
997+
text-decoration-color: var(--gb-announcement-ink);
998+
}
999+
}
1000+
9701001
// --- Responsive. --------------------------------------------------------
9711002
@media (max-width: 800px) {
9721003
.hero {

examples/bar-count.typ

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@
55
#set page(width: auto, height: auto, margin: 0.5cm)
66

77
#let items = (
8-
(cat: "A",), (cat: "A",), (cat: "A",),
9-
(cat: "B",), (cat: "B",),
10-
(cat: "C",), (cat: "C",), (cat: "C",), (cat: "C",),
11-
(cat: "D",), (cat: "D",), (cat: "D",), (cat: "D",), (cat: "D",),
8+
(cat: "A"),
9+
(cat: "A"),
10+
(cat: "A"),
11+
(cat: "B"),
12+
(cat: "B"),
13+
(cat: "C"),
14+
(cat: "C"),
15+
(cat: "C"),
16+
(cat: "C"),
17+
(cat: "D"),
18+
(cat: "D"),
19+
(cat: "D"),
20+
(cat: "D"),
21+
(cat: "D"),
1222
)
1323

1424
#plot(

examples/bar-dodged.typ

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
data: sales,
2121
mapping: aes(x: "q", y: "revenue", fill: "product"),
2222
layers: (geom-col(position: "dodge"),),
23-
labs: labs(title: "Revenue by quarter (dodged)", x: "Quarter", y: "Revenue (k$)"),
23+
labs: labs(
24+
title: "Revenue by quarter (dodged)",
25+
x: "Quarter",
26+
y: "Revenue (k$)",
27+
),
2428
width: 10cm,
2529
height: 7cm,
2630
)

examples/shape-linetype.typ

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313

1414
#plot(
1515
data: obs,
16-
mapping: aes(x: "t", y: "value", shape: "group", linetype: "group", colour: "group"),
16+
mapping: aes(
17+
x: "t",
18+
y: "value",
19+
shape: "group",
20+
linetype: "group",
21+
colour: "group",
22+
),
1723
layers: (
1824
geom-line(),
1925
geom-point(size: 5pt),

lib.typ

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636
#import "src/scale/colour.typ": scale-colour-continuous, scale-colour-discrete
3737
#import "src/scale/colour.typ": scale-fill-continuous, scale-fill-discrete
3838
#import "src/scale/colour.typ": scale-colour-manual, scale-fill-manual
39-
#import "src/scale/colour.typ": scale-colour-viridis-b, scale-colour-viridis-c, scale-colour-viridis-d
40-
#import "src/scale/colour.typ": scale-fill-viridis-b, scale-fill-viridis-c, scale-fill-viridis-d
39+
#import "src/scale/colour.typ": (
40+
scale-colour-viridis-b, scale-colour-viridis-c, scale-colour-viridis-d,
41+
)
42+
#import "src/scale/colour.typ": (
43+
scale-fill-viridis-b, scale-fill-viridis-c, scale-fill-viridis-d,
44+
)
4145
#import "src/scale/size.typ": scale-size-continuous
4246
#import "src/scale/shape.typ": scale-shape, scale-shape-manual
4347
#import "src/scale/linetype.typ": scale-linetype, scale-linetype-manual
@@ -62,5 +66,7 @@
6266
#import "src/theme/classic.typ": theme-classic
6367
#import "src/theme/void.typ": theme-void
6468
#import "src/theme/theme.typ": theme
65-
#import "src/theme/elements.typ": element-blank, element-line, element-rect, element-text
66-
#import "src/theme/current.typ": theme-set, theme-get
69+
#import "src/theme/elements.typ": (
70+
element-blank, element-line, element-rect, element-text,
71+
)
72+
#import "src/theme/current.typ": theme-get, theme-set

src/facet/shared.typ

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
new.data = layer.data.filter(row => {
99
let keep = true
1010
for (col, value) in filters {
11-
if str(row.at(col, default: "")) != value { keep = false; break }
11+
if str(row.at(col, default: "")) != value {
12+
keep = false
13+
break
14+
}
1215
}
1316
keep
1417
})

src/geom/col.typ

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@
8080
let position = layer.at("position", default: "identity")
8181
let ymin-col = mapping.at("ymin", default: none)
8282
let ymax-col = mapping.at("ymax", default: none)
83-
let use-minmax = (position == "stack" or position == "fill") and ymin-col != none and ymax-col != none
83+
let use-minmax = (
84+
(position == "stack" or position == "fill")
85+
and ymin-col != none
86+
and ymax-col != none
87+
)
8488

8589
let fill-col = mapping.at("fill", default: none)
8690
let fill-trained = ctx.trained.at("fill", default: none)
87-
let default-fill = if layer.params.fill != auto and layer.params.fill != none {
91+
let default-fill = if (
92+
layer.params.fill != auto and layer.params.fill != none
93+
) {
8894
layer.params.fill
8995
} else {
9096
rgb("#4c78a8")
@@ -97,17 +103,23 @@
97103
)
98104

99105
let (px-lo, px-hi) = ctx.px-range
100-
let category-width = if x-trained.type == "discrete" and x-trained.domain.len() > 0 {
106+
let category-width = if (
107+
x-trained.type == "discrete" and x-trained.domain.len() > 0
108+
) {
101109
(px-hi - px-lo) / x-trained.domain.len()
102110
} else {
103111
// Continuous x: infer from minimum gap between unique values.
104-
let xs = data.map(r => parse-number(r.at(mapping.x, default: none))).filter(v => v != none)
112+
let xs = data
113+
.map(r => parse-number(r.at(mapping.x, default: none)))
114+
.filter(v => v != none)
105115
let (d-lo, d-hi) = x-trained.domain
106116
if xs.len() < 2 or d-hi == d-lo {
107117
(px-hi - px-lo) / 10
108118
} else {
109119
let sorted = xs.dedup().sorted()
110-
let gaps = range(sorted.len() - 1).map(i => sorted.at(i + 1) - sorted.at(i))
120+
let gaps = range(sorted.len() - 1).map(i => (
121+
sorted.at(i + 1) - sorted.at(i)
122+
))
111123
let min-gap = calc.min(..gaps)
112124
min-gap * (px-hi - px-lo) / (d-hi - d-lo)
113125
}
@@ -116,7 +128,11 @@
116128
let half = category-width * bar-width-fraction / 2
117129

118130
for row in data {
119-
let cx = map-position(x-trained, row.at(mapping.x, default: none), ctx.px-range)
131+
let cx = map-position(
132+
x-trained,
133+
row.at(mapping.x, default: none),
134+
ctx.px-range,
135+
)
120136
if cx == none { continue }
121137

122138
let (y-lo-cy, y-hi-cy) = if use-minmax {
@@ -144,16 +160,24 @@
144160
}
145161

146162
let colour = if fill-col != none and fill-trained != none {
147-
(ctx.resolve-colour)(fill-trained, row.at(fill-col, default: none), ctx.palette)
163+
(ctx.resolve-colour)(
164+
fill-trained,
165+
row.at(fill-col, default: none),
166+
ctx.palette,
167+
)
148168
} else { default-fill }
149169
let alpha = layer.params.alpha
150-
let final-fill = if alpha < 1 { colour.transparentize((1 - alpha) * 100%) } else { colour }
170+
let final-fill = if alpha < 1 {
171+
colour.transparentize((1 - alpha) * 100%)
172+
} else { colour }
151173

152174
cetz.draw.rect(
153175
(centre - bar-half, y-lo-cy),
154176
(centre + bar-half, y-hi-cy),
155177
fill: final-fill,
156-
stroke: if layer.params.stroke == none { none } else { layer.params.stroke },
178+
stroke: if layer.params.stroke == none { none } else {
179+
layer.params.stroke
180+
},
157181
)
158182
}
159183
}

src/geom/label.typ

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,16 @@
9696
if x-trained == none or y-trained == none { return }
9797

9898
for row in data {
99-
let cx = map-position(x-trained, row.at(mapping.x, default: none), ctx.px-range)
100-
let cy = map-position(y-trained, row.at(mapping.y, default: none), ctx.py-range)
99+
let cx = map-position(
100+
x-trained,
101+
row.at(mapping.x, default: none),
102+
ctx.px-range,
103+
)
104+
let cy = map-position(
105+
y-trained,
106+
row.at(mapping.y, default: none),
107+
ctx.py-range,
108+
)
101109
if cx == none or cy == none { continue }
102110
let label = row.at(label-col, default: none)
103111
if label == none { continue }

src/geom/line.typ

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@
8080
}
8181
for aes-name in ("colour", "fill", "linetype") {
8282
let col = mapping.at(aes-name, default: none)
83-
if col != none and col != mapping.at("x", default: none) and col != mapping.at("y", default: none) {
83+
if (
84+
col != none
85+
and col != mapping.at("x", default: none)
86+
and col != mapping.at("y", default: none)
87+
) {
8488
keys.push(str(row.at(col, default: "")))
8589
}
8690
}
@@ -97,7 +101,9 @@
97101

98102
let colour-col = mapping.at("colour", default: none)
99103
let colour-trained = ctx.trained.at("colour", default: none)
100-
let default-colour = if layer.params.colour != auto and layer.params.colour != none {
104+
let default-colour = if (
105+
layer.params.colour != auto and layer.params.colour != none
106+
) {
101107
layer.params.colour
102108
} else {
103109
rgb("#222222")
@@ -110,7 +116,9 @@
110116
linetype-trained.spec.at("palette", default: default-linetypes)
111117
} else { default-linetypes }
112118
} else { default-linetypes }
113-
let default-linetype = if layer.params.linetype != auto and layer.params.linetype != none {
119+
let default-linetype = if (
120+
layer.params.linetype != auto and layer.params.linetype != none
121+
) {
114122
layer.params.linetype
115123
} else { "solid" }
116124

@@ -140,8 +148,16 @@
140148

141149
let pts = ()
142150
for p in with-x {
143-
let cx = map-position(x-trained, p.row.at(mapping.x, default: none), ctx.px-range)
144-
let cy = map-position(y-trained, p.row.at(mapping.y, default: none), ctx.py-range)
151+
let cx = map-position(
152+
x-trained,
153+
p.row.at(mapping.x, default: none),
154+
ctx.px-range,
155+
)
156+
let cy = map-position(
157+
y-trained,
158+
p.row.at(mapping.y, default: none),
159+
ctx.py-range,
160+
)
145161
if cx == none or cy == none { continue }
146162
pts.push((cx, cy))
147163
}
@@ -153,7 +169,9 @@
153169
} else { default-colour }
154170

155171
let alpha = layer.params.alpha
156-
let final-colour = if alpha < 1 { colour.transparentize((1 - alpha) * 100%) } else { colour }
172+
let final-colour = if alpha < 1 {
173+
colour.transparentize((1 - alpha) * 100%)
174+
} else { colour }
157175

158176
let dash = if linetype-col != none and linetype-trained != none {
159177
let sample = rows.first().at(linetype-col, default: none)

0 commit comments

Comments
 (0)