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

Axis Styling #36

Merged
merged 2 commits into from
Aug 7, 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
5 changes: 1 addition & 4 deletions src/charts/bar/plotter.typ
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
axes: ("x", "y"),
..plot-args,
) = {

draw.group(ctx => {

// Setup styles
let style = styles.resolve(
ctx.style,
Expand All @@ -29,7 +27,6 @@
draw.set-style(..style)

plot(

// To do: Is there a better way to setup the x-axis using custom axis-style
x-min: -0.75, x-max: data.len() - 0.25,
x-tick-step: if label-key == none {1},
Expand Down Expand Up @@ -68,4 +65,4 @@
}
)
})
}
}
8 changes: 3 additions & 5 deletions src/charts/bar/simple.typ
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "/src/cetz.typ": canvas, palette, draw, styles
#import "/src/plot.typ": plot
#import "/src/plot/add.typ" as add: series, bar, errorbar
#import "/src/plot/axis-style.typ"
#import "style.typ": barchart-default-style

/// Render a single series as a barchart
Expand Down Expand Up @@ -67,9 +68,8 @@
base: barchart-default-style
)
draw.set-style(..style)

plot(

// To do: Is there a better way to setup the x-axis using custom axis-style
x-min: -0.75, x-max: data.len() - 0.25,
x-tick-step: if label-key == none {1},
Expand All @@ -81,7 +81,6 @@

plot-style: bar-style,
..plot-args,

{
add.series(
label: label,
Expand All @@ -108,5 +107,4 @@
}
)
})

}
}
18 changes: 13 additions & 5 deletions src/charts/bar/style.typ
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#let barchart-default-style = (
axes: (tick: (length: 0), grid: (stroke: (dash: "dotted"))),
bar-width: .8,
cluster-gap: 0,
axes: (
// Hide ticks
tick: (length: 0),

// Show a dotted grid
grid: (stroke: (dash: "dotted")),

// Hide top and right axis
top: (hidden: true),
right: (hidden: true),
),

error: (
whisker-size: .25,
),
y-inset: 1,
)
)
4 changes: 2 additions & 2 deletions src/plot/axis-styles/orthorect-2d/impl.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#let orthorect-2d() = {
#let orthorect-2d(..args) = {
import "orthorect-2d.typ": make-ctx, data-viewport, draw-axes,
import "transforms.typ": transform-vec

return (
make-ctx: make-ctx,
data-viewport: data-viewport,
draw-axes: draw-axes,
draw-axes: draw-axes.with(..args),
transform-vec: transform-vec,
)
}
10 changes: 6 additions & 4 deletions src/plot/axis-styles/orthorect-2d/orthorect-2d.typ
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
top: (tick: (label: (anchor: "south"))),
stroke: (cap: "square"),
padding: 0,
draw-unset: false,
hidden: false,
)
)

Expand Down Expand Up @@ -45,7 +47,7 @@
}

#let draw-axes(
(w,h),
(w, h),
axis-dict,
name: none,
..style
Expand Down Expand Up @@ -144,10 +146,10 @@
let path = draw-axis-line(start, end, axis, is-horizontal, style)
draw.on-layer(style.axis-layer, {
draw.group(name: "axis", {
// if draw-unset or axis != none {
if not style.hidden and (style.draw-unset or axis != none) {
path;
place-ticks-on-line(ticks, data-start, data-end, style, flip: flip, is-mirror: is-mirror)
// }
}
})

if axis != none and axis.label != none and not is-mirror {
Expand All @@ -170,4 +172,4 @@
}
})
})
}
}
4 changes: 2 additions & 2 deletions src/plot/axis-styles/polar-2d/impl.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#let polar-2d() = {
#let polar-2d(..args) = {
import "polar-2d.typ": make-ctx, data-viewport, draw-axes
import "transforms.typ": transform-vec

return (
make-ctx: make-ctx,
data-viewport: data-viewport,
draw-axes: draw-axes,
draw-axes: draw-axes.with(..args),
transform-vec: transform-vec,
)
}
10 changes: 5 additions & 5 deletions src/plot/axis-styles/polar-2d/polar-2d.typ
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
distal: (tick: (label: (anchor: "north-east", offset: -0.2))),
angular: (tick: (label: (anchor: "center", offset: 0.35,), length: 5pt)),
stroke: (cap: "square"),
padding: 0,
)
)

Expand Down Expand Up @@ -92,7 +91,7 @@
})
}
})

// Draw axes
draw.group(name: "axes", {
// Render distal
Expand All @@ -109,16 +108,17 @@
place-ticks-on-line(
distal-ticks,
(radius, radius),
(radius, radius*2),
(radius, radius * 2),
prepare-style(ctx, style.distal),
)
}
})
})

draw.on-layer(style.axis-layer, {
draw.group(name: "axis", {
draw.group(name: "axis", ctx => {
if angular != none {

// To do: Allow finer control over placement
draw.circle(
"origin",
Expand All @@ -129,7 +129,7 @@

place-ticks-on-radius(
angular-ticks,
(radius),
radius,
prepare-style(ctx, style.angular),
)
}
Expand Down
Loading