Skip to content

Commit

Permalink
Move grid to background, better colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrswift committed Aug 1, 2024
1 parent 648bccc commit b06bc20
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/plot.typ
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@

// TODO: Refactor this into a better way of providing palettes

#let default-colors = (blue, red, green, yellow, black)
#let default-colors = (
rgb("#1982c4"),
rgb("#ff595e"),
rgb("#ffca3a"),
rgb("#8ac926"),
rgb("#6a4c93")
)

#let default-plot-style(i) = {
let color = default-colors.at(calc.rem(i, default-colors.len()))
return (
stroke: color,
fill: color.lighten(75%)
fill: color.transparentize(80%)
)
}

Expand Down
6 changes: 4 additions & 2 deletions src/plot/elements/xy.typ
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@
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 = (ctx.compute-fill-paths)(
self.line-data,
ctx,
)
}

return self
Expand Down
4 changes: 2 additions & 2 deletions src/plot/styles.typ
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
anchor: auto, // Axis label anchor
angle: auto, // Axis label angle
),
axis-layer: 0,
grid-layer: 0,
axis-layer: 2,
grid-layer: -1,
background-layer: 0,
padding: 0,
tick: (
Expand Down
27 changes: 23 additions & 4 deletions tests/plots/orthorect-2d/scatter/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,33 @@
cetz-plot.plot(
axis-style: cetz-plot.axis-style.orthorect-2d,
size: (12,7),
// x-min: 1, x-max: 100, x-tick-step: 1, x-minor-tick-step: 1,
// x-mode: "log",

x-tick-step: calc.pi / 4,
x-minor-tick-step: calc.pi / 16,
x-grid: "both",
y-min: 0, y-max: 10,
x-min: 0, x-max: 2 * calc.pi,
x-format: cetz-plot.axes.format.multiple-of,

y-min: -1, y-max: 1, y-tick-step: 0.5, y-minor-tick-step: 0.1,
y-grid: "both",
{
cetz-plot.add.xy((x)=>{- 0.5*x*x + 3*x + 0.025*x*x*x }, domain: (0,10), label: $y=x$, line: "raw")
cetz-plot.add.xy(
calc.sin,
domain: (0,2*calc.pi),
label: $y=x$,
line: "raw",
samples: 100,
epigraph: true,
)

cetz-plot.add.xy(
(t)=>calc.pow(calc.sin(t),2),
domain: (0, 2* calc.pi),
line: "raw",
samples: 100,
hypograph: true,
label: $sin^2 (x)$
)
}
)
})
6 changes: 4 additions & 2 deletions tests/plots/polar-2d/scatter/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
domain: (0,2*calc.pi),
label: $y=x$,
line: "raw",
samples: 50
samples: 100,
epigraph: true,
)

cetz-plot.add.xy(
(t)=>calc.pow(calc.sin(t),2),
domain: (0, 2* calc.pi),
line: "raw",
samples: 50,
samples: 100,
hypograph: true,
label: $sin^2 (x)$
)
}
Expand Down

0 comments on commit b06bc20

Please sign in to comment.