Skip to content

Commit

Permalink
Fixed params for stroke in Docs
Browse files Browse the repository at this point in the history
Replaced stoke/fill with marking
  • Loading branch information
Pegacraft committed Jul 9, 2023
1 parent cf81a9c commit 810ebf1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
Binary file modified docs/Docs.pdf
Binary file not shown.
12 changes: 6 additions & 6 deletions docs/docs.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import "typst-doc.typ": parse-module, show-module
#show link: underline


#show "(deprecated)": block(box(fill: red, "deprecated", inset: 3pt, radius: 3pt))
// Take a look at the file `template.typ` in the file panel
// to customize this template and discover how it works.
#show: project.with(
Expand Down Expand Up @@ -41,12 +41,12 @@
#{
let options = (allow-breaking: false)
let modules = (
"Axes": "/typst-plotting/axis.typ",
"Plots": "/typst-plotting/plotting.typ",
"Classification": "/typst-plotting/util/classify.typ",
"Axes": "/plotst/axis.typ",
"Plots": "/plotst/plotting.typ",
"Classification": "/plotst/util/classify.typ",
)
set heading(numbering: "1.1.")
outline(indent: auto, depth: 2)
//set heading(numbering: "1.1.")
outline(indent: 2em, depth: 2)
align(center)[Docs were created with #link("https://github.com/Mc-Zen/typst-doc")[typst-doc]]
pagebreak()
for (name, path) in modules {
Expand Down
34 changes: 13 additions & 21 deletions plotst/plotting.typ
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@
/// - `data:` An array of `x` and `y` pairs. \ _Example:_ `((0, 0), (1, 2), (2, 4), …)`
/// - size (length, array): The size as array of `(width, height)` or as a single value for both `width` and `height`
/// - caption (content): The name of the figure
/// - stroke (color): The stroke color of the dots
/// - fill (color): The fill color of the dots
/// - stroke (none, auto, length, color, dictionary, stroke): The stroke color of the dots (deprecated)
/// - fill (color): The fill color of the dots (deprecated)
/// - render_axes (boolean): If the axes should be visible or not
#let scatter_plot(plot, size, caption: [Scatter Plot], stroke: black, fill: none, render_axes: true) = {
/// - markings (string, content): how the data points should be shown: "square", "circle", "cross", otherwise manually specify any shape (gets overwritten by stroke/fill)
#let scatter_plot(plot, size, caption: [Scatter Plot], stroke: none, fill: none, render_axes: true, markings: "square") = {
let x_axis = plot.axes.at(0)
let y_axis = plot.axes.at(1)
// The code rendering the plot
Expand All @@ -81,8 +82,12 @@
if type(y) == "string" {
y = y_axis.values.position(c => c == y)
}
place(dx: (x - x_axis.min) * step_size_x - 1pt, dy: -(y - y_axis.min) * step_size_y - 1pt, square(width: 2pt, height: 2pt, fill: fill, stroke: stroke))
if stroke != none or fill != none { // DELETEME deprecation, only keep else
draw_marking(((x - x_axis.min) * step_size_x, -(y - y_axis.min) * step_size_y), square(width: 2pt, height: 2pt, fill: fill, stroke: stroke))
} else {
draw_marking(((x - x_axis.min) * step_size_x, -(y - y_axis.min) * step_size_y), markings)
}
}
}

// Sets outline for a plot and defines width and height and executes the plot code
Expand All @@ -106,7 +111,7 @@
/// - size (length, array): The size as array of `(width, height)` or as a single value for both `width` and `height`
/// - caption (content): The name of the figure
/// - rounding (ratio): The rounding of the graph, 0% means sharp edges, 100% will make it as smooth as possible (Bézier)
/// - stroke (color): The stroke color of the graph
/// - stroke (none, auto, length, color, dictionary, stroke): The stroke color of the graph
/// - fill (color): The fill color for the graph. Can be used to display the area beneath the graph.
/// - render_axes (boolean): If the axes should be visible or not
/// - markings (none, string, content): how the data points should be shown: "square", "circle", "cross", otherwise manually specify any shape
Expand Down Expand Up @@ -137,20 +142,7 @@

place(dx: 0pt, dy: 0pt, path(fill: fill, stroke: stroke, ..data.zip(delta)))
for p in data {
if markings == none {
} else if markings == "square" {
place(dx: p.at(0) - 1pt, dy: p.at(1) - 1pt, square(size: 2pt, fill: black, stroke: none))
} else if markings == "circle" {
place(dx: p.at(0) - 1pt, dy: p.at(1) - 1pt, circle(radius: 1pt, fill: black, stroke: none))
} else if markings == "cross" {
place(dx: p.at(0) - 1pt, dy: p.at(1) - 1pt, line(length: 2.82pt, angle: 45deg))
place(dx: p.at(0) - 1pt, dy: p.at(1) + 1pt, line(length: 2.82pt, angle: -45deg))
} else if type(markings) == "content" {
style(s => {
let (width, height) = measure(markings, s)
place(dx: p.at(0)-width/2, dy: p.at(1)-height/2, markings)
})
}
draw_marking(p, markings)
}
}

Expand Down Expand Up @@ -184,7 +176,7 @@
/// - `data:` An array of `x` and `y` pairs. \ _Example:_ `((0, 0), (1, 2), (2, 4), …)`
/// - size (length, array): The size as array of `(width, height)` or as a single value for both `width` and `height`
/// - caption (content): The name of the figure
/// - stroke (color, array): The stroke color of a bar or an `array` of colors, where every entry stands for the stroke color of one bar
/// - stroke (none, auto, length, color, dictionary, stroke, array): The stroke color of a bar or an `array` of colors, where every entry stands for the stroke color of one bar
/// - fill (color, array): The fill color of a bar or an `array` of colors, where every entry stands for the fill color of one bar
/// - render_axes (boolean): If the axes should be visible or not
#let histogram(plot, size, caption: [Histogram], stroke: black, fill: gray, render_axes: true) = {
Expand Down Expand Up @@ -402,7 +394,7 @@
/// - `data:` An array of single values or an array of `(amount, value)` tuples. \ _Example:_ `((10, "Male"), (5, "Female"), (2, "Divers"), …)` or `("Male", "Male", "Male", "Female", "Female", "Divers", "Divers", …)`
/// - size (length, array): The size as array of `(width, height)` or as a single value for both `width` and `height`
/// - caption (content): The name of the figure
/// - stroke (color, array): The stroke color of a bar or an `array` of colors, where every entry stands for the stroke color of one bar
/// - stroke (none, auto, length, color, dictionary, stroke, array): The stroke color of a bar or an `array` of colors, where every entry stands for the stroke color of one bar
/// - fill (color, array): The fill color of a bar or an `array` of colors, where every entry stands for the fill color of one bar
/// - centered_bars (boolean): If the bars should be on the number its corresponding to
/// - bar_width (ratio): how thick the bars should be in percent. (default: 100%)
Expand Down
20 changes: 20 additions & 0 deletions plotst/util/util.typ
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,24 @@
#let convert_size(size) = {
if type(size) == "int" { return (width: size, height: size) }
if size.len() == 2 { return (width: size.at(0), height: size.at(1)) }
}

#let draw_marking(data, markings) = {
if markings == none { return }
if markings == "square" {
markings = square(size: 2pt, fill: black, stroke: none)
} else if markings == "circle" {
markings = circle(radius: 1pt, fill: black, stroke: none)
} else if markings == "cross" {
markings = {
place(line(angle: 45deg, length: 1pt))
place(line(angle: -45deg, length: 1pt))
place(line(angle: 135deg, length: 1pt))
place(line(angle: -135deg, length: 1pt))
}
}
style(s => {
let (width, height) = measure(markings, s)
place(dx: data.at(0) - width/2, dy: data.at(1) - height/2, markings)
})
}

0 comments on commit 810ebf1

Please sign in to comment.