### Install Pixi Source: https://github.com/jollywatt/typst-fletcher/blob/main/CONTRIBUTING.md Command to install the Pixi package manager. ```sh curl -fsSL https://pixi.sh/install.sh | bash ``` -------------------------------- ### Create a simple flowchart Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md A basic flowchart example with node strokes defined. ```typst #diagram( node-stroke: 1pt, node((0,0), "Start"), edge("->"), node((1,0), "Process"), edge("->"), node((2,0), "End"), ) ``` -------------------------------- ### Common Mark Object Examples Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md Provides practical examples of mark object definitions and inheritance patterns. ```typst // Simple arrowhead (kind: "head", pos: 1.0, rev: false) // Filled circle at midpoint (kind: "circle", pos: 0.5, fill: auto) // Custom-sized arrowhead (kind: "head", size: 15, sharpness: 40deg, rev: false) // Inherited from another mark with modifications (inherit: "head", rev: true) // Inherited with apostrophe flip modifier "head'" // Equivalent to (inherit: "head", flip: true) ``` -------------------------------- ### Basic Diagram Creation Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md A simple example showing how to define nodes and connect them with an edge. ```typst #import "@preview/fletcher:0.5.9" as fletcher: diagram, node, edge #diagram( node((0,0), $A$), node((1,0), $B$), edge((0,0), (1,0), "->"), ) ``` -------------------------------- ### Edge Shorthand Example Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/coordinates.md Demonstrates the use of shorthand strings within a diagram edge. ```typst #diagram( node((0,0), "A"), edge("r,d,r", "->"), node((2,1), "B"), ) ``` -------------------------------- ### Import fletcher package Source: https://github.com/jollywatt/typst-fletcher/blob/main/README.md Import the necessary components from the fletcher package to start creating diagrams. ```typ #import "@preview/fletcher:0.5.9" as fletcher: diagram, node, edge ``` -------------------------------- ### Define node coordinates Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Examples of different coordinate systems for positioning nodes. ```typst node((0, 0), "Text") // Row 0, column 0 ``` ```typst node((2cm, 3cm), "Text") ``` ```typst node((rel: (1cm, 0), to: (0,0)), "Text") ``` -------------------------------- ### Elastic Coordinate Diagram Example Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/coordinates.md A diagram demonstrating node placement and edge connections using elastic grid coordinates. ```typst #diagram( spacing: 2em, cell-size: 1.5cm, node((0,0), "A"), node((1,0), "B"), node((1,1), "C"), edge((0,0), (1,0), "->"), edge((1,0), (1,1), "->"), ) ``` -------------------------------- ### Simplified stroke shorthand syntax Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/types.md Examples of shorthand syntax for defining strokes with varying levels of detail. ```typst - `stroke: 1pt` — Black 1pt line - `stroke: red` — Red line with default thickness - `stroke: 1pt + red` — Red 1pt line - `stroke: (paint: red, thickness: 2pt, dash: "dashed")` ``` -------------------------------- ### Edge Usage Examples Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/edge.md Various ways to define edges using coordinates, marks, and labels. ```typst edge((0,0), (1,0), "->") // explicit from/to with marks edge("->") // auto from/to with marks edge((1,0), "->", "Label") // to, marks, label edge((1,0), "Label", "->") // to, label, marks (order doesn't matter) edge("r,u,r", "=>") // relative path with marks ``` -------------------------------- ### Common Syntax Mistakes Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Examples of incorrect syntax patterns and their corrected counterparts. ```typst ❌ node((0,0), text, name: ) ✓ node((0,0), text, name: ) ``` ```typst ❌ node((0,0), "A", name: "node-a") ✓ node((0,0), "A", name: ) ``` ```typst ❌ (0 1) ✓ (0, 1) ``` ```typst ❌ node("r,d") // Only works in edges ✓ edge("r,d", "->") // Correct ``` -------------------------------- ### Define diagram coordinates Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/00-START-HERE.md Examples of grid, absolute, relative, and CeTZ-style coordinate formats. ```typst (0, 1) // Grid position (elastic) (2cm, 3cm) // Physical length (absolute) "r,d,r" // Direction shorthand (relative) (rel: (1cm, 0)) // CeTZ-style (relative) ``` -------------------------------- ### diagram(..args, ...) Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md The main function for creating diagrams with nodes and arrows. It handles coordinate system setup, grid layout computation, and final rendering of all elements. ```APIDOC ## diagram(..args, ...) ### Description The main function for creating diagrams with nodes and arrows. It handles coordinate system setup, grid layout computation, and final rendering of all elements. ### Parameters - **..args** (array) - Required - Content arguments including nodes (created with `node()`) and edges (created with `edge()`). - **debug** (bool, int) - Optional - Debug level for visualization (default: `false`). - **axes** ((direction, direction)) - Optional - Orientation of the coordinate system (default: `(ltr, ttb)`). - **spacing** (length or (length, length)) - Optional - Gap between rows and columns (default: `3em`). - **cell-size** (length or (length, length)) - Optional - Minimum size of grid cells (default: `0pt`). - **edge-stroke** (stroke) - Optional - Default stroke style for edges (default: `0.048em`). - **node-stroke** (stroke, none) - Optional - Default stroke style for node outlines (default: `none`). - **edge-corner-radius** (length, none) - Optional - Default corner radius for rounded bends (default: `2.5pt`). - **node-corner-radius** (length, none) - Optional - Default corner radius for nodes (default: `none`). - **node-inset** (length or (length, length)) - Optional - Padding between node content and outline (default: `6pt`). - **node-outset** (length or (length, length)) - Optional - Margin from node boundary to edge connection points (default: `0pt`). - **node-shape** (rect, circle, function, auto) - Optional - Default node shape function (default: `auto`). - **node-fill** (paint, none) - Optional - Default fill color for nodes (default: `none`). - **node-defocus** (number) - Optional - Default defocus adjustment for edges (default: `0.2`). - **label-sep** (length) - Optional - Separation between edge and label (default: `0.4em`). - **label-size** (length) - Optional - Text size for edge labels (default: `1em`). - **label-wrapper** (function) - Optional - Callback function to wrap edge labels. - **mark-scale** (percentage) - Optional - Scale factor for arrowheads (default: `100%`). - **crossing-fill** (paint) - Optional - Color used behind crossing edges (default: `white`). - **crossing-thickness** (number) - Optional - Thickness of crossing occlusion (default: `5`). - **render** (function) - Optional - Custom render callback. ### Return Value A canvas element containing the rendered diagram. ``` -------------------------------- ### Absolute Coordinate Diagram Example Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/coordinates.md A diagram mixing absolute physical coordinates with elastic grid coordinates. ```typst #diagram( node((2cm, 3cm), "Absolute"), node((0, 0), "Elastic"), edge((2cm, 3cm), (0, 0), "->"), ) ``` -------------------------------- ### Build Manual Source: https://github.com/jollywatt/typst-fletcher/blob/main/CONTRIBUTING.md Commands to build the manual PDF or watch for changes. ```sh pixi run compile manual ``` ```sh pixi run manual ``` -------------------------------- ### Create self-loop edges Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/edge.md Draws an edge that starts and ends at the same node. ```typst #diagram( node((0,0), "Loop"), edge((), "->", (), bend: 120deg, loop-angle: 45deg, label: "self"), ) ``` -------------------------------- ### View Project File Structure Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/00-START-HERE.md Displays the directory layout of the documentation files within the project. ```text output/ ├── 00-START-HERE.md # ← You are here ├── README.md # Overview of docs ├── INDEX.md # Main entry point ├── CHEAT-SHEET.md # Copy-paste patterns ├── MODULE-STRUCTURE.md # Architecture ├── coordinates.md # Positioning guide ├── marks.md # Arrows & symbols ├── types.md # Data types ├── utilities.md # Helper functions └── api-reference/ ├── diagram.md # Main function ├── node.md # Node function ├── edge.md # Edge function └── shapes.md # Shape functions ``` -------------------------------- ### Import Main Functions Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/MODULE-STRUCTURE.md Import the primary diagramming functions from the package entry point. ```typst #import "exports.typ": diagram, node, edge ``` -------------------------------- ### Create a basic diagram with nodes and edges Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/00-START-HERE.md Initializes a simple diagram with two nodes connected by a directed edge. Requires importing the fletcher package. ```typst #import "@preview/fletcher:0.5.9" as fletcher: diagram, node, edge #diagram( node((0,0), "Start"), edge("->"), node((1,0), "End"), ) ``` -------------------------------- ### Import Utility Functions Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/MODULE-STRUCTURE.md Import helper functions for layout manipulation and debugging. ```typst #import "exports.typ": hide, mark-debug ``` -------------------------------- ### Custom Spacing and Styling Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md Demonstrates how to adjust grid spacing, cell size, and node appearance. ```typst #diagram( spacing: 4em, cell-size: 2cm, node-stroke: 1pt, node-fill: blue.lighten(80%), node((0,0), "Start"), edge("->"), node((1,0), "End"), ) ``` -------------------------------- ### Invoke Error Function Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/utilities.md Example usage of the error function with a message string and interpolation arguments. ```typst error("Expected #0, got #1", "array", typeof(value)) ``` -------------------------------- ### Create a database schema diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Illustrates entity relationships with custom spacing and labels. ```typst #diagram( spacing: 4em, node((0,0), "User"), edge((0,0), (1,0), "1--n", label: "has"), node((1,0), "Post"), node((1,1), "Comment"), edge((1,0), (1,1), "1--n", label: "has"), ) ``` -------------------------------- ### Create an advanced diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/00-START-HERE.md Demonstrates math mode, curved edges, multi-segment paths, and node grouping. ```typst #diagram( spacing: 3em, cell-size: 1.5cm, node-stroke: 1.5pt, // Using math mode $ A edge(f, ->) & B \ C edge(g, ->>) & D $, // Curved edges with bending edge((2, 0), (3, 0.5), "=>", label: "curve", bend: 30deg), // Multi-segment paths edge((0, 2), (1, 2), (1, 3), (2, 3), "->", corner-radius: 5pt), // Node groups node((0,2), "Group item", name: ), node((1,2), "Group item", name: ), node((0.5, 1.5), "Group", enclose: (, ), stroke: red), ) ``` -------------------------------- ### edge(start, end, marks) Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md Defines the marks (arrowheads or symbols) at the ends or along an edge in a diagram. ```APIDOC ## edge(start, end, marks) ### Description Defines the visual markers at the start, end, or middle of an edge. Marks can be provided as a string shorthand, an array of strings, or an array of configuration objects. ### Parameters - **start** (coordinate) - Required - The starting position of the edge. - **end** (coordinate) - Required - The ending position of the edge. - **marks** (string|array) - Optional - The mark configuration. Can be a string (e.g., "->", "<=>"), an array of strings, or an array of objects defining (kind, pos, rev, fill). ### Examples ```typst // String shorthand edge((0,0), (1,0), "->") // Array of strings edge((0,0), (1,0), marks: ("head", none, "head")) // Array of objects edge((0,0), (1,0), marks: ( (kind: "solid", pos: 0, rev: true), (kind: "circle", pos: 0.5, fill: auto) )) ``` ``` -------------------------------- ### Create a State Machine Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Demonstrates curved edges and self-looping paths between nodes. ```typst #diagram( node((0,0), "State A"), edge("->", bend: 30deg), node((1,1), "State B"), edge((), "->", (), bend: 120deg), // Self-loop ) ``` -------------------------------- ### Create a Feynman diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/README.md Render a particle physics diagram using wave edges and directional arrow markers. ```typ #diagram($ e^- edge("rd", "-<|-") & & & edge("ld", "-|>-") e^+ \ & edge(gamma, "wave") \ e^+ edge("ru", "-|>-") & & & edge("lu", "-<|-") e^- \ $) ``` -------------------------------- ### Import fletcher components Source: https://github.com/jollywatt/typst-fletcher/blob/main/README.src.md Initializes the fletcher package by importing the diagram, node, and edge components. ```typ #import "@preview/fletcher:{VERSION}" as fletcher: diagram, node, edge ``` -------------------------------- ### Create a flowchart Source: https://github.com/jollywatt/typst-fletcher/blob/main/README.md Construct a flowchart using custom shapes like diamonds and styled nodes. ```typ // https://xkcd.com/1195/ #import fletcher.shapes: diamond #set text(font: "Comic Neue", weight: 600) // testing: omit #diagram( node-stroke: 1pt, node((0,0), [Start], corner-radius: 2pt, extrude: (0, 3)), edge("-|>"), node((0,1), align(center)[ Hey, wait,\ this flowchart\ is a trap! ], shape: diamond), edge("d,r,u,l", "-|>", [Yes], label-pos: 0.1) ) ``` -------------------------------- ### Import Marks and Flags Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/MODULE-STRUCTURE.md Import constants for mark definitions, edge flags, and line style aliases. ```typst #import "exports.typ": MARKS, EDGE_FLAGS, LINE_ALIASES ``` -------------------------------- ### Define Marks with Array Format Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/edge.md Advanced mark configuration using dictionaries for specific properties. ```typst (kind: "solid", pos: 0.5, fill: auto) (inherit: "doublehead", rev: false) ``` -------------------------------- ### Update README Source: https://github.com/jollywatt/typst-fletcher/blob/main/CONTRIBUTING.md Command to regenerate the README.md file from the template. ```sh pixi run readme ``` -------------------------------- ### View Project File Structure Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Displays the directory layout of the fletcher documentation repository. ```text output/ ├── README.md # This file ├── INDEX.md # Main documentation entry point ├── CHEAT-SHEET.md # Quick reference guide ├── MODULE-STRUCTURE.md # Architecture and organization ├── coordinates.md # Coordinate systems ├── marks.md # Marks and arrowheads ├── types.md # Type definitions ├── utilities.md # Utility functions └── api-reference/ ├── diagram.md # diagram() function ├── node.md # node() function ├── edge.md # edge() function └── shapes.md # Shape functions ``` -------------------------------- ### Create organization charts Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Build hierarchical organization charts using nodes and directed edges. ```typst #diagram( node((0,0), "CEO"), edge("->"), node((1,0), "Manager"), edge("->"), node((2,0), "Engineer"), ) ``` -------------------------------- ### Run Tytanic Tests Source: https://github.com/jollywatt/typst-fletcher/blob/main/CONTRIBUTING.md Command to execute the project test suite. ```sh pixi run test ``` -------------------------------- ### Apply multiple edge styles Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/edge.md Demonstrates using different arrowheads and line styles like double or dashed lines. ```typst #diagram( spacing: 3em, { node((0,0), "A") edge("=>", "double") node((1,0), "B") }, { node((0,1), "C") edge("<=>", "dashed") node((1,1), "D") }, ) ``` -------------------------------- ### Create a diagram with named nodes and references Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Uses labels to reference nodes by name for edge connections. ```typst #diagram( node((0,0), $A$, name: ), node((1,0.5), $B$, name: ), edge(, , "=>", label: $f$), ) ``` -------------------------------- ### Create a simple node with a label Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/node.md Basic usage of the node function to place content at specific coordinates. ```typst #diagram( node((0,0), "Start"), node((1,0), "End"), edge("->"), ) ``` -------------------------------- ### Activate Pixi Shell Source: https://github.com/jollywatt/typst-fletcher/blob/main/CONTRIBUTING.md Command to enter the development environment and access tools directly. ```sh pixi shell ``` -------------------------------- ### Create a Flowchart Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Uses a grid-based layout to connect nodes in a linear sequence. ```typst #diagram( spacing: 2em, node((0,0), "Start"), edge("->"), node((1,0), "Process"), edge("->"), node((2,0), "End"), ) ``` -------------------------------- ### Default Mark Parameters Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md View the default configuration applied to marks when specific parameters are omitted. ```typst ( rev: false, // Not reversed flip: false, // Not flipped scale: 100%, // 100% scale extrude: (0,), // No multi-stroke tip-end: 0, // Tip endpoint offset tail-end: 0, // Tail endpoint offset tip-origin: 0, // Tip origin offset tail-origin: 0, // Tail origin offset ) ``` -------------------------------- ### Create a math diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Uses math mode syntax to define nodes and edges within a diagram. ```typst #diagram( $ A edge(f, ->) & B \ C edge(g, ->>) & D \ & edge(h) & $ ) ``` -------------------------------- ### Define Styling Defaults Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Sets global styles for nodes and edges. ```typst node-stroke: 1pt node-fill: blue.lighten(80%) node-shape: fletcher.shapes.circle edge-stroke: 1.5pt ``` -------------------------------- ### Common diagram options Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/00-START-HERE.md Configuration options for diagrams, nodes, and edges. ```typst // On diagram(): spacing: 3em node-stroke: 1pt edge-stroke: 2pt // On node(): shape: fletcher.shapes.circle fill: blue.lighten(80%) name: // On edge(): label: "text" bend: 30deg marks: "->" ``` -------------------------------- ### Configure custom shape parameters Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/node.md Pass additional configuration to shapes using the .with() method. ```typst #diagram( node((0,0), "Text", shape: fletcher.shapes.parallelogram.with(angle: 20deg, fit: 0.8)), node((1,0), "Text", shape: fletcher.shapes.triangle.with(dir: bottom, angle: 60deg)), ) ``` -------------------------------- ### house(node, extrude, dir, angle) Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/shapes.md Creates a pentagon house shape with a roof. ```APIDOC ## house(node, extrude, dir, angle) ### Description Pentagon resembling a house with a roof. Useful for representing data or processes. ### Parameters - **node** (dict) - Required - Node data including size - **extrude** (length) - Required - Outward extrusion amount - **dir** (top, bottom, left, right) - Optional - Direction of the roof (default: top) - **angle** (angle) - Optional - Roof slant angle; 0deg is rectangle (default: 10deg) ``` -------------------------------- ### Enable Debug Visualization Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Toggles grid and anchor visibility for debugging purposes. ```typst debug: true // Show grid debug: 2 // Show bounds and anchors debug: 3 // More detail ``` -------------------------------- ### Create commutative diagrams Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Use the diagram environment to define commutative diagrams with edges and nodes. ```typst #diagram( $ A edge(f, ->) & B \ C edge(g, ->) & D \ & edge(h, "->") & $ ) ``` -------------------------------- ### Create state machines Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Define state machines using nodes and edges with bends. ```typst #diagram( node((0,0), "State A"), edge("->", bend: 30deg), node((1,1), "State B"), edge((), "->", (), bend: 120deg, label: "loop"), ) ``` -------------------------------- ### Import Shapes Module Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/MODULE-STRUCTURE.md Import the shapes submodule to access geometric and custom node shapes. ```typst #import "exports.typ": shapes ``` -------------------------------- ### Configure Debugging Levels Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Set the debug parameter to visualize grid, bounds, anchors, or detailed node information. ```typst debug: 1 // or debug: true ``` ```typst debug: 2 ``` ```typst debug: 3 ``` -------------------------------- ### Create a loop diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Draws an edge that loops back to the same node. ```typst #diagram( node((0,0), "State"), edge((), "->", (), bend: 120deg, loop-angle: 45deg), ) ``` -------------------------------- ### Project File Structure Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Displays the directory layout and core modules of the fletcher project. ```text fletcher/ src/ exports.typ # Public API exports diagram.typ # Main diagram() function node.typ # node() function edge.typ # edge() function shapes.typ # Shape definitions marks.typ # Mark system default-marks.typ # Default mark styles coords.typ # Coordinate system draw.typ # Rendering backend utils.typ # Utilities deps.typ # Dependencies (CeTZ) ``` -------------------------------- ### Mark Object Dictionary Configuration Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md Defines the structure for advanced mark customization using a dictionary format. ```typst (kind: "solid", // Mark type (from default-marks.typ) pos: 0.5, // Position along edge: 0=start, 1=end rev: false, // Reverse mark direction size: 10, // Mark size sharpness: 45deg, // Arrowhead angle (for arrows) fill: auto, // Fill color or `auto` inherit: "head", // Inherit properties from another mark scale: 100%, // Scale multiplier for mark size ) ``` -------------------------------- ### Create a Commutative Diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Utilizes math mode syntax to define nodes and edges within a matrix-like structure. ```typst #diagram( $ A edge(f, ->) & B \ C edge(g, ->>) & D $ ) ``` -------------------------------- ### Create a minimal diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Define a simple diagram with two nodes connected by an edge. ```typst #diagram( node((0,0), "A"), edge("->"), node((1,0), "B"), ) ``` -------------------------------- ### Enable debug mode in diagrams Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Set the debug parameter to visualize grid, bounds, and anchors. ```typst #diagram( debug: 2, // Shows grid, bounds, and anchors ... ) ``` -------------------------------- ### Debug Visualization Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md Enabling debug mode to visualize the coordinate grid and bounding boxes. ```typst #diagram( debug: 2, // Shows grid and bounding boxes node((0,0), "Node 1"), node((1,1), "Node 2"), edge((0,0), (1,1), "->"), ) ``` -------------------------------- ### Create a state machine diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/README.md Define a state machine with radial fills, specific node spacing, and curved edges. ```typ #set text(10pt) #diagram( node-stroke: .1em, node-fill: gradient.radial(blue.lighten(80%), blue, center: (30%, 20%), radius: 80%), spacing: 4em, edge((-1,0), "r", "-|>", `open(path)`, label-pos: 0, label-side: center), node((0,0), `reading`, radius: 2em), edge(`read()`, "-|>"), node((1,0), `eof`, radius: 2em), edge(`close()`, "-|>"), node((2,0), `closed`, radius: 2em, extrude: (-2.5, 0)), edge((0,0), (0,0), `read()`, "--|>", bend: 130deg), edge((0,0), (2,0), `close()`, "-|>", bend: -40deg), ) ``` -------------------------------- ### Define Edge Marks using String Shorthand Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md Use string shorthands to quickly define common arrow styles and complex mark combinations. ```typst edge((0,0), (1,0), "->") // Right arrow edge((0,0), (1,0), "<=>") // Bidirectional double arrow edge((0,0), (1,0), "x-/-@") // Complex marks edge((0,0), (1,0), "hook->") // Hooked arrow ``` -------------------------------- ### Create a horizontal chain diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Connects nodes in a horizontal line using arrows. ```typst #diagram( node((0,0), "A"), edge("->"), node((1,0), "B"), edge("->"), node((2,0), "C"), ) ``` -------------------------------- ### Convert to array with as-array Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/utilities.md Forces a value into an array format. If the input is already an array, it is returned as-is. ```typst #let as-array(obj) = if type(obj) == array { obj } else { (obj,) } ``` ```typst as-array("dashed") // → ("dashed",) as-array((1, 2)) // → ((1, 2),) as-array(("a", "b")) // → ("a", "b") ``` -------------------------------- ### Create a commutative diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/README.md Define a diagram using grid coordinates and edge labels to represent mathematical isomorphisms. ```typ #diagram(cell-size: 15mm, $ G edge(f, ->) edge("d", pi, ->>) & im(f) \ G slash ker(f) edge("ur", tilde(f), "hook-->") $) ``` -------------------------------- ### Convert to label with as-label Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/utilities.md Normalizes strings or labels into a label type. Throws an error if the input is neither a string nor a label. ```typst #let as-label(x) = { if type(x) == label { x } else if type(x) == str { label(x) } else { error(...) } } ``` ```typst as-label("node-a") // → as-label() // → ``` -------------------------------- ### Arrow and Mark Notation Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Common arrow styles and ERD-specific notations. ```typst "->" // Right arrow "<-" // Left arrow "<->" // Bidirectional "=>" // Double "<=>" // Double bidirectional "->>" // Double head "|->|" // Barred ``` ```typst "1--1" // One-to-one "1--n" // One-to-many "n--1" // Many-to-one "n--n" // Many-to-many "1?--1" // Optional ``` ```typst "hook->" "x-/-@" "|..|" "->>-" ``` -------------------------------- ### Create an Entity Relationship Diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/README.md Connects nodes using explicit coordinate references to represent relationships. ```typst #diagram( node((0,0), "User"), edge((0,0), (1,0), "1--n"), node((1,0), "Order"), ) ``` -------------------------------- ### Create a vertical chain diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Connects nodes in a vertical line using arrows. ```typst #diagram( node((0,0), "A"), edge("->"), node((0,1), "B"), edge("->"), node((0,2), "C"), ) ``` -------------------------------- ### brace(node, extrude, side) Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/shapes.md Creates a brace or bracket outline on one side. ```APIDOC ## brace(node, extrude, side) ### Description Brace/bracket outline on one side. Useful for annotating or grouping elements. ### Parameters - **node** (dict) - Required - Node data including size - **extrude** (length) - Required - Outward extrusion amount - **side** (left, right, top, bottom) - Optional - Bracket side (default: left) ``` -------------------------------- ### Relative Shorthand Strings Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/coordinates.md Uses direction abbreviations to define edge paths. ```typst "r" // One unit right "d" // One unit down "r,u,r" // Right, up, right (polyline) "l,l,d,r" // Complex path "r,r" // Two units right (separated by commas) ``` -------------------------------- ### Define arrows and marks Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/00-START-HERE.md Common arrow shorthand strings for edges. ```typst "->" // Right arrow "<=>" // Bidirectional double "hook->" // Hooked arrow "1--n" // One-to-many (ERD) ``` -------------------------------- ### Define Edge with Positional Arguments Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/edge.md General syntax for defining edges using coordinates, marks, and labels. ```typst edge(.., .., ..) ``` -------------------------------- ### Create a commutative square diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Arranges nodes in a 2x2 grid to represent a commutative square. ```typst #diagram( node((0,0), "A"), edge("->"), node((1,0), "B"), node((0,1), "C"), edge("->"), node((1,1), "D"), ) ``` -------------------------------- ### bracket(node, extrude, side) Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/shapes.md Creates a square-corner bracket outline on one side. ```APIDOC ## bracket(node, extrude, side) ### Description Square bracket outline on one side, similar to brace but with sharp corners. ### Parameters - **node** (dict) - Required - Node data including size - **extrude** (length) - Required - Outward extrusion amount - **side** (left, right, top, bottom) - Optional - Bracket side (default: left) ``` -------------------------------- ### Apply Diagram Defaults and Overrides Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Set global defaults for nodes and edges, with the ability to override them on individual elements. ```typst #diagram( node-stroke: 1pt, // Default for all nodes node-fill: blue.lighten(80%), // Default for all nodes edge-stroke: 2pt, // Default for all edges node((0,0), "A"), // Uses defaults node((1,0), "B", stroke: red), // Overrides stroke edge("->", stroke: 2.5pt), // Overrides stroke ) ``` -------------------------------- ### Convert to pair with as-pair Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/utilities.md Ensures a value is returned as an array of length 2. If the input is not an array, it returns an array containing the input twice. ```typst #let as-pair(obj) = { if type(obj) == array { if obj.len() == 2 { obj } else { error(...) } } else { (obj, obj) } } ``` ```typst as-pair(5pt) // → (5pt, 5pt) as-pair((2em, 3em)) // → (2em, 3em) ``` -------------------------------- ### Custom Coordinate System Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md Configuring the axes to change the orientation of the coordinate system. ```typst #diagram( axes: (ltr, btt), // y increases upward node((0,0), "Bottom"), node((0,1), "Top"), edge("->"), ) ``` -------------------------------- ### Math Mode with Implicit Positions Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md Using math mode syntax to define diagram structure implicitly. ```typst #diagram( node-stroke: 1pt, $ A edge(->) & B \ C edge(<=) & D $ ) ``` -------------------------------- ### Add Mixed Content to Nodes Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Renders formatted text or aligned content inside nodes. ```typst node((0,0), [*Bold* or _italic_]) node((0,0), align(center)[Multiple\ lines]) ``` -------------------------------- ### Batch Nodes and Edges Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Group nodes and edges within a diagram block to organize complex layouts. ```typst #diagram( { node((0,0), "A") node((1,0), "B") edge("->") }, { node((0,1), "C") edge("->") node((1,1), "D") }, ) ``` -------------------------------- ### Convert to stroke with as-stroke Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/utilities.md A wrapper around the built-in Typst stroke function for consistent usage. ```typst #let as-stroke(x) = stroke(x) ``` -------------------------------- ### node() Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/DOCUMENTATION-SUMMARY.txt Creates a node within a diagram. Supports various shapes and styling parameters. ```APIDOC ## node() ### Description Defines a node element within the diagram. Nodes can be positioned using coordinate systems and styled with various shapes. ### Parameters - **pos** (coordinate) - Required - The position of the node in the diagram grid. - **content** (content) - Required - The visual content to display inside the node. - **shape** (string) - Optional - The shape of the node (e.g., rect, circle, ellipse, etc.). - **options** (dictionary) - Optional - 15+ parameters for styling, sizing, and behavior. ``` -------------------------------- ### Configure Edge Dash Patterns Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Sets the dash style for edges. ```typst dash: "dashed" dash: "dotted" // Or via marks: edge("--") // Dashed edge("..") // Dotted ``` -------------------------------- ### Position nodes using relative coordinates Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/node.md Place nodes relative to other nodes using the rel and to parameters. ```typst #diagram( spacing: 4em, node((0,0), "A", name: ), node((rel: (2cm, 0.5cm), to: ), "B"), edge(, "->"), ) ``` -------------------------------- ### Define Mark Shorthand Syntax Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md The syntax for defining marks on edges using a string-based format. ```text --...- ``` -------------------------------- ### Define Shapes Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md List of available shape constants for nodes. ```typst shape: fletcher.shapes.rect // Rectangle shape: fletcher.shapes.circle // Circle shape: fletcher.shapes.ellipse // Ellipse shape: fletcher.shapes.pill // Rounded rectangle shape: fletcher.shapes.diamond // Diamond shape: fletcher.shapes.triangle // Triangle shape: fletcher.shapes.parallelogram // Slanted rectangle shape: fletcher.shapes.trapezium // Trapezoid shape: fletcher.shapes.house // Pentagon with roof shape: fletcher.shapes.chevron // Arrow/chevron shape: fletcher.shapes.hexagon // Hexagon shape: fletcher.shapes.octagon // Octagon shape: fletcher.shapes.cylinder // Cylinder ``` -------------------------------- ### Create a category theory diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Displays a triangular relationship between three nodes. ```typst #diagram( node((0,0), $A$), node((1,0), $B$), node((1,1), $C$), edge((0,0), (1,0), "->", label: $f$), edge((1,0), (1,1), "->", label: $g$), edge((0,0), (1,1), "-->", label: $h$), ) ``` -------------------------------- ### diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/DOCUMENTATION-SUMMARY.txt The main container function for creating a Fletcher diagram. ```APIDOC ## diagram ### Description The `diagram` function is the primary container for all Fletcher elements. It initializes the coordinate system and renders the nodes and edges defined within its body. ### Parameters - **...args** (content) - Required - The content of the diagram, typically consisting of `node` and `edge` calls. - **options** (dictionary) - Optional - Configuration options for the diagram, including grid spacing, axes, and debug modes. ``` -------------------------------- ### Create a simple two-node diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Defines two nodes at specific grid coordinates connected by a directed edge. ```typst #diagram( node((0,0), "A"), node((1,0), "B"), edge("->"), ) ``` -------------------------------- ### octagon(node, extrude, fit) Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/shapes.md Creates a regular octagon shape. ```APIDOC ## octagon(node, extrude, fit) ### Description Regular octagon shape. ### Parameters - **node** (dict) - Required - Node data including size - **extrude** (length) - Required - Outward extrusion amount - **fit** (number) - Optional - Comfort of fit (0-1, default: 0.8) ``` -------------------------------- ### Create a basic arrow edge Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/edge.md Defines a simple directed edge between two nodes. ```typst #diagram( node((0,0), $A$), node((1,0), $B$), edge((0,0), (1,0), "->"), ) ``` -------------------------------- ### Define Diagram Nodes Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Create nodes at specific grid coordinates with defined shapes. ```typst node((0,0), "Box", shape: fletcher.shapes.rect) node((1,0), "Circle", shape: fletcher.shapes.circle) node((2,0), "Diamond", shape: fletcher.shapes.diamond) ``` -------------------------------- ### Coordinates Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Methods for defining positions using grid-based, absolute, relative, and named coordinate systems. ```APIDOC ## Coordinate Systems ### Elastic (Grid-Based) Uses integer coordinates for grid positioning: `(0, 0)`, `(1, 2)`, `(-1, 1)` ### Absolute (Physical) Uses standard length units: `(2cm, 3cm)`, `(5pt, 10pt)`, `(1em, 0.5in)` ### Relative Shorthand (Edges) Uses directional characters: `u`, `d`, `l`, `r`, `t`, `b`, `n`, `s`, `e`, `w`. Examples: `"r"`, `"d"`, `"r,u,r"`, `"rd"` ### Named References Assign names to nodes to reference them in edges: ```typst node((0,0), "A", name: ) edge(, (1,0), "->") ``` ### CeTZ-Style Advanced relative positioning: `(rel: (1cm, 0), to: (0,0))` `(rel: (45deg, 2cm))` `(rel: (0.5, 0.5), to: )` ``` -------------------------------- ### Diagram Function Signature Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/api-reference/diagram.md The full parameter list for the diagram function, defining default behaviors for layout, styling, and rendering. ```typst #let diagram( ..args, debug: false, axes: (ltr, ttb), spacing: 3em, cell-size: 0pt, edge-stroke: 0.048em, node-stroke: none, edge-corner-radius: 2.5pt, node-corner-radius: none, node-inset: 6pt, node-outset: 0pt, node-shape: auto, node-fill: none, node-defocus: 0.2, label-sep: 0.4em, label-size: 1em, label-wrapper: edge => box([#edge.label], inset: .2em, radius: .2em, fill: edge.label-fill), mark-scale: 100%, crossing-fill: white, crossing-thickness: 5, render: (grid, nodes, edges, options) => { cetz.canvas(draw-diagram(grid, nodes, edges, debug: options.debug)) }, ) ``` -------------------------------- ### Perform Type Conversions Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Utility functions to safely cast inputs to required diagram types. ```typst as-pair(5pt) // → (5pt, 5pt) as-array("item") // → ("item",) as-label("name") // → as-length(5pt) // → 5pt as-angle(45deg) // → 45deg as-relative(0.5) // → 50% + 0pt ``` -------------------------------- ### Add Math Content to Nodes Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Renders mathematical expressions inside nodes. ```typst node((0,0), $A$) node((0,0), $f: A to B$) ``` -------------------------------- ### Apply Edge Decorations Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Adds decorative patterns to edges. ```typst decorations: "wave" decorations: "zigzag" decorations: "coil" // Or as positional argument: edge("->", "wave") edge("->", "zigzag") ``` -------------------------------- ### fletcher.mark-debug Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/utilities.md Visualizes mark geometry with offsets for debugging purposes. ```APIDOC ## fletcher.mark-debug(mark-name) ### Description Visualizes the geometry of a specific mark, including offset curves. ### Parameters - **mark-name** (String) - Required - The name of the mark to visualize. ### Returns - Diagram - A diagram showing the mark geometry. ### Example ```typst fletcher.mark-debug("head") ``` ``` -------------------------------- ### Style a flowchart diagram Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/INDEX.md Applies global node styling and spacing to a sequence of nodes. ```typst #diagram( node-stroke: 1pt, node-fill: blue.lighten(80%), spacing: 3em, node((0,0), "Start"), edge("-|>"), node((1,0), "Process"), edge("-|>"), node((2,0), "End"), ) ``` -------------------------------- ### Edge Definitions Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/CHEAT-SHEET.md Methods for creating edges, including labels, segments, and styling. ```typst edge("->") ``` ```typst edge((0,0), (1,0), "->") ``` ```typst edge("->", label: $f$) edge((0,0), (1,0), $f$, "->") // Alternative ``` ```typst edge((0,0), (1,0), (1,1), "->") edge("r,u,r", "->") // Relative shorthand ``` ```typst edge("->", bend: 30deg) ``` ```typst edge("->", corner: right) edge("->", corner: left) ``` ```typst edge("->", label: $f$, label-pos: 0.3) edge("->", label: $f$, label-pos: 0.7) edge("->", label: $f$, label-side: top) edge("->", label: $f$, label-side: center) ``` -------------------------------- ### Define Edge Marks using Array of Objects Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/marks.md Use an array of objects for granular control over mark kind, position, and styling properties. ```typst edge((0,0), (1,0), marks: ( (kind: "solid", pos: 0, rev: true), // Arrowhead at start (kind: "circle", pos: 0.5, fill: auto), // Circle at middle (kind: "solid", pos: 1, rev: false) // Arrowhead at end )) ``` -------------------------------- ### Automatic Node Positioning Source: https://github.com/jollywatt/typst-fletcher/blob/main/_autodocs/coordinates.md Use auto positioning to connect nodes sequentially without explicit coordinate definitions. ```typst #diagram( node((0,0), "Start"), edge("->"), // auto from start node((1,0), "End"), edge("->"), // auto to next node node((2,0), "Final"), ) ```