summaryrefslogtreecommitdiff
path: root/library/src/visualize
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-21 16:28:54 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-21 16:32:14 +0100
commit038f9b015ee1248c3636c5e1b2edb5c4767ed837 (patch)
tree0f6b0a00ffefe8ff25ca1ddb2ec740499c109531 /library/src/visualize
parent31f904a2c406953cbce334e02b37a712b9b9d016 (diff)
Document `line` function
Diffstat (limited to 'library/src/visualize')
-rw-r--r--library/src/visualize/image.rs4
-rw-r--r--library/src/visualize/line.rs47
-rw-r--r--library/src/visualize/shape.rs4
3 files changed, 37 insertions, 18 deletions
diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs
index 1744f389..bbb54576 100644
--- a/library/src/visualize/image.rs
+++ b/library/src/visualize/image.rs
@@ -5,14 +5,14 @@ use typst::image::{Image, ImageFormat, RasterFormat, VectorFormat};
use crate::prelude::*;
/// # Image
-/// Show a raster or vector graphic.
+/// A raster or vector graphic.
///
/// Supported formats are PNG, JPEG, GIF and SVG.
///
/// ## Example
/// ```
/// #align(center)[
-/// #image("molecular.jpg", width: 2in)
+/// #image("molecular.jpg", width: 80%)
///
/// *A step in the molecular testing
/// pipeline of our lab*
diff --git a/library/src/visualize/line.rs b/library/src/visualize/line.rs
index 7fed90ce..18877842 100644
--- a/library/src/visualize/line.rs
+++ b/library/src/visualize/line.rs
@@ -1,22 +1,29 @@
use crate::prelude::*;
/// # Line
-/// Display a line without affecting the layout.
+/// A line from one point to another.
///
-/// You should only provide either an endpoint or an angle and a length.
+/// ## Example
+/// ```
+/// #set page(height: 100pt)
+/// #line(end: (50%, 50%))
+/// ```
///
/// ## Parameters
-/// - origin: Axes<Rel<Length>> (named)
+/// - start: Axes<Rel<Length>> (named)
/// The start point of the line.
+/// Must be an array of exactly two relative lengths.
///
-/// - to: Axes<Rel<Length>> (named)
+/// - end: Axes<Rel<Length>> (named)
/// The end point of the line.
+/// Must be an array of exactly two relative lengths.
///
/// - length: Rel<Length> (named)
-/// The line's length.
+/// The line's length. Mutually exclusive with `end`.
///
/// - angle: Angle (named)
-/// The angle at which the line points away from the origin.
+/// The angle at which the line points away from the origin. Mutually
+/// exclusive with `end`.
///
/// ## Category
/// visualize
@@ -25,22 +32,34 @@ use crate::prelude::*;
#[derive(Debug, Hash)]
pub struct LineNode {
/// Where the line starts.
- pub origin: Axes<Rel<Length>>,
- /// The offset from the `origin` where the line ends.
+ pub start: Axes<Rel<Length>>,
+ /// The offset from `start` where the line ends.
pub delta: Axes<Rel<Length>>,
}
#[node]
impl LineNode {
- /// How to stroke the line.
+ /// How to stroke the line. This can be:
+ ///
+ /// - A length specifying the stroke's thickness. The color is inherited,
+ /// defaulting to black.
+ /// - A color to use for the stroke. The thickness is inherited, defaulting
+ /// to `{1pt}`.
+ /// - A stroke combined from color and thickness using the `+` operator as
+ /// in `{2pt + red}`.
+ ///
+ /// # Example
+ /// ```
+ /// #line(length: 100%, stroke: 2pt + red)
+ /// ```
#[property(resolve, fold)]
pub const STROKE: PartialStroke = PartialStroke::default();
fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
- let origin = args.named("origin")?.unwrap_or_default();
+ let start = args.named("start")?.unwrap_or_default();
- let delta = match args.named::<Axes<Rel<Length>>>("to")? {
- Some(to) => to.zip(origin).map(|(to, from)| to - from),
+ let delta = match args.named::<Axes<Rel<Length>>>("end")? {
+ Some(end) => end.zip(start).map(|(to, from)| to - from),
None => {
let length =
args.named::<Rel<Length>>("length")?.unwrap_or(Abs::cm(1.0).into());
@@ -53,7 +72,7 @@ impl LineNode {
}
};
- Ok(Self { origin, delta }.pack())
+ Ok(Self { start, delta }.pack())
}
}
@@ -67,7 +86,7 @@ impl Layout for LineNode {
let stroke = styles.get(Self::STROKE).unwrap_or_default();
let origin = self
- .origin
+ .start
.resolve(styles)
.zip(regions.base)
.map(|(l, b)| l.relative_to(b));
diff --git a/library/src/visualize/shape.rs b/library/src/visualize/shape.rs
index 9bf2bbab..2a733368 100644
--- a/library/src/visualize/shape.rs
+++ b/library/src/visualize/shape.rs
@@ -205,7 +205,7 @@ impl Inline for RectNode {}
/// ## Example
/// ```
/// // Without content.
-/// #square(size: 30pt)
+/// #square(size: 40pt)
///
/// // With content.
/// #square[
@@ -428,7 +428,7 @@ impl Inline for EllipseNode {}
/// ## Example
/// ```
/// // Without content.
-/// #circle(radius: 15pt)
+/// #circle(radius: 25pt)
///
/// // With content.
/// #circle[