d2vision

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 12 Imported by: 0

README

d2vision

Go CI Go Lint Go SAST Go Report Card Docs Visualization License

Tools for D2 diagram parsing, generation, and AI-assisted creation.

Overview

d2vision provides a complete toolkit for working with D2 diagrams:

  • 🔍 Parse: Extract structure from D2-generated SVGs
  • ⚙️ Generate: Create D2 code from structured specifications
  • 📋 Template: Quick-start patterns for common diagrams
  • 🎓 Learn: Reverse engineer D2 code from existing SVGs
  • Lint: Check D2 files for common layout issues
  • ↔️ Diff: Compare two diagrams
  • 👁️ Watch: Auto-render D2 files on changes
  • 📊 Analyze: Analyze layout and provide generation hints
  • 🎨 Icons: Browse and search D2's icon library
  • 🔄 Pipeline: Generate workflow diagrams from PipelineSpec
  • 🔀 Convert: Convert Mermaid/PlantUML diagrams to D2
  • 🔃 Rotate: Rotate SVG by 90° increments (landscape ↔ portrait)

Default output format is TOON (Token-Oriented Object Notation), which uses ~40% fewer tokens than JSON - ideal for LLM consumption.

d2vision includes the D2 rendering engine as a library - no separate D2 CLI installation required.

Installation

go install github.com/grokify/d2vision/cmd/d2vision@latest

Quick Start

# Parse an SVG diagram
d2vision parse diagram.svg

# Generate D2 from a template
d2vision template network-boundary --d2 | d2 - output.svg

# List available templates
d2vision template list

Commands

Parse

Extract structure from D2-generated SVG files.

# TOON output (default, optimized for LLMs)
d2vision parse diagram.svg

# JSON output
d2vision parse diagram.svg --format json

# Natural language description
d2vision parse diagram.svg --format text

# Brief summary
d2vision parse diagram.svg --format summary

# LLM-optimized markdown
d2vision parse diagram.svg --format llm

# Generation hints for recreating the diagram
d2vision parse diagram.svg --for-generation
Generate

Create D2 code from structured TOON, JSON, or YAML specifications.

# Generate from TOON spec
d2vision generate spec.toon > diagram.d2

# Generate from JSON
d2vision generate spec.json --format json > diagram.d2

# Pipe from stdin
cat spec.toon | d2vision generate - > diagram.d2

# Full pipeline: spec → D2 → SVG
d2vision generate spec.toon | d2 - output.svg
Template

Generate common diagram patterns.

# List available templates
d2vision template list

# Get template as TOON spec (for modification)
d2vision template network-boundary

# Get template as D2 code (ready to render)
d2vision template network-boundary --d2

# Customize template
d2vision template network-boundary --clusters 3 --services 4 --d2

# Full pipeline: template → SVG
d2vision template network-boundary --d2 | d2 - output.svg
Available Templates
Template Description
network-boundary Side-by-side network zones with services and datastores
microservices Service mesh with API gateway
data-flow ETL/data pipeline
sequence Request/response sequence diagram
entity-relationship Database schema with SQL tables (alias: er)
deployment Cloud deployment architecture
pipeline Multi-stage process pipeline (LLM/agent workflow)
Pipeline

Generate workflow diagrams from PipelineSpec.

# Generate D2 code from PipelineSpec JSON
d2vision pipeline workflow.json

# Direct SVG output
d2vision pipeline workflow.json --svg -o workflow.svg

# Simple view (compact, no I/O breakdown)
d2vision pipeline workflow.json --simple --svg -o workflow.svg

# Use pipeline template
d2vision template pipeline --d2 --pipeline-type agent

Pipeline types: etl, llm, agent

Rendering modes:

  • Detailed (default): Full I/O breakdown with inputs/executor/outputs
  • Simple (--simple): Compact stage boxes with type badges
  • Swimlane (auto): Stages grouped by lane field
  • Decision (auto): Diamond shapes for stages with branches
Convert

Convert Mermaid or PlantUML diagrams to D2.

# Convert Mermaid flowchart
d2vision convert diagram.mmd

# Convert PlantUML sequence diagram
d2vision convert diagram.puml

# Lint before converting
d2vision convert --lint-only diagram.mmd
Rotate

Rotate SVG diagrams by 90° increments.

# Rotate landscape to portrait (for left-binding PDF)
d2vision rotate diagram.svg --angle 90 -o portrait.svg

# Chain with pipeline
d2vision pipeline spec.json --svg | d2vision rotate - --angle 90 > portrait.svg
Learn

Reverse engineer D2 code from existing SVG diagrams.

# Output TOON spec (can be modified and regenerated)
d2vision learn diagram.svg

# Output D2 code directly
d2vision learn diagram.svg --d2

# JSON output for programmatic use
d2vision learn diagram.svg --format json

# Round-trip workflow
d2vision learn diagram.svg > spec.toon
# ... edit spec.toon ...
d2vision generate spec.toon | d2 - new_diagram.svg
Lint

Check D2 files for common layout issues before rendering.

# Lint a D2 file
d2vision lint diagram.d2

# JSON output for CI integration
d2vision lint diagram.d2 --format json

Checks for:

  • Cross-container edges that may cause vertical stacking
  • Missing grid-columns for side-by-side layouts
  • Inconsistent direction settings
  • Deeply nested containers (performance warning)
Diff

Compare two diagrams and show differences.

# Compare two SVG files
d2vision diff old.svg new.svg

# JSON output for programmatic use
d2vision diff old.svg new.svg --format json

# Include position/bounds comparison
d2vision diff old.svg new.svg --bounds

# Adjust position threshold (default: 5 pixels)
d2vision diff old.svg new.svg --bounds --bounds-threshold 10

Reports:

  • Added, removed, and modified nodes
  • Added, removed, and modified edges
  • Label and shape changes
  • Style changes
  • Position and size changes (with --bounds flag)
Watch

Watch D2 files and automatically re-render on changes.

# Basic watch
d2vision watch diagram.d2

# Watch with explicit output
d2vision watch diagram.d2 output.svg

# Watch with linting before render
d2vision watch diagram.d2 --lint

# Watch with custom d2 arguments
d2vision watch diagram.d2 --d2-args="--theme=200"

# Watch with post-render command
d2vision watch diagram.d2 --on-success="open %s"

Features:

  • Automatic re-rendering on file save
  • Optional linting before render
  • Debouncing to prevent multiple renders
  • Custom d2 arguments
  • Post-render hooks
Analyze

Analyze diagram layout and provide generation hints.

# Analyze a diagram's layout
d2vision analyze diagram.svg

# Get analysis as JSON
d2vision analyze diagram.svg --format json

# Get analysis as TOON
d2vision analyze diagram.svg --format toon

Provides:

  • Layout type detection (side-by-side, stacked, hierarchical, flow)
  • Grid layout detection (columns and rows)
  • Container hierarchy analysis
  • Cross-container edge detection
  • Insights about what makes the layout work
  • Hints for recreating the diagram in D2
Icons

Browse and search D2's icon library (185+ SVG icons).

# List all categories
d2vision icons list

# List icons in a category
d2vision icons list --category aws

# Search for icons
d2vision icons search kubernetes

# Search with JSON output
d2vision icons search database --format json

Categories:

Category Description
essentials Common UI icons (user, database, cloud, lock)
dev Development tools & languages (docker, kubernetes, go)
infra Infrastructure (firewall, router, load-balancer)
tech Hardware & devices (laptop, server, mobile)
social Social media (twitter, github, slack)
aws Amazon Web Services (EC2, S3, Lambda, RDS)
azure Microsoft Azure (VMs, Functions, Cosmos DB)
gcp Google Cloud Platform (Compute, BigQuery, GKE)

Using icons in D2:

server {
  icon: https://icons.terrastruct.com/essentials/112-server.svg
}

aws_lambda {
  icon: https://icons.terrastruct.com/aws/Compute/AWS-Lambda.svg
}

Output Formats

Format Flag Description
TOON --format toon Token-Oriented Object Notation (default, ~40% fewer tokens)
JSON --format json Standard JSON with indentation
JSON Compact --format json-compact Minified JSON
YAML --format yaml YAML format
Text --format text Human-readable description
Summary --format summary Brief one-line summary
LLM --format llm Markdown optimized for LLMs
TOON Example
Version: 0.7.1
ViewBox: "(0.00, 0.00, 847.00, 666.00)"
Nodes[2]:
  - ID: cluster1
    Label: Cluster 1
    Shape: rectangle
    Bounds: "(0.00, 41.00, 418.00, 424.00)"
  - ID: cluster2
    Label: Cluster 2
    Shape: rectangle
    Bounds: "(458.00, 41.00, 187.00, 424.00)"
JSON Example
{
  "version": "0.7.1",
  "viewBox": {"x": 0, "y": 0, "width": 847, "height": 666},
  "nodes": [
    {"id": "cluster1", "label": "Cluster 1", "shape": "rectangle", "bounds": {"x": 0, "y": 41, "width": 418, "height": 424}},
    {"id": "cluster2", "label": "Cluster 2", "shape": "rectangle", "bounds": {"x": 458, "y": 41, "width": 187, "height": 424}}
  ]
}

Library Usage

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/grokify/d2vision"
    "github.com/grokify/d2vision/format"
    "github.com/grokify/d2vision/generate"
    "github.com/grokify/d2vision/render"
)

func main() {
    // Parse SVG
    diagram, err := d2vision.ParseFile("diagram.svg")
    if err != nil {
        log.Fatal(err)
    }

    // Output as TOON
    output, _ := format.Marshal(diagram, format.TOON)
    fmt.Println(string(output))

    // Generate D2 code
    spec := &generate.DiagramSpec{
        GridColumns: 2,
        Containers: []generate.ContainerSpec{
            {
                ID:        "cluster1",
                Label:     "Cluster 1",
                Direction: "down",
                Nodes: []generate.NodeSpec{
                    {ID: "service1", Label: "Service 1"},
                    {ID: "db1", Label: "Database", Shape: "cylinder"},
                },
                Edges: []generate.EdgeSpec{
                    {From: "service1", To: "db1"},
                },
            },
        },
    }

    gen := generate.NewGenerator()
    d2Code := gen.Generate(spec)
    fmt.Println(d2Code)

    // Render D2 to SVG (no external d2 CLI needed)
    r, _ := render.New()
    svg, _ := r.RenderSVG(context.Background(), d2Code, nil)
    os.WriteFile("output.svg", svg, 0644)
}

Diagram Spec Schema

The DiagramSpec structure for generating D2 code:

direction: right          # Layout direction: right, down, left, up
gridColumns: 2            # Force grid layout with N columns
gridRows: 2               # Force grid layout with N rows

containers:
  - id: cluster1
    label: Cluster 1
    direction: down       # Layout within container
    style:
      fill: "#f0f0f0"
      strokeWidth: 2
    nodes:
      - id: service1
        label: Service 1
        shape: rectangle  # rectangle, cylinder, circle, oval, etc.
      - id: db1
        label: Database
        shape: cylinder
    edges:
      - from: service1
        to: db1
        label: connects

nodes:                    # Top-level nodes
  - id: external
    label: External Service

edges:                    # Cross-container edges
  - from: cluster1.db1
    to: external
    label: syncs to

Examples

See the examples/ directory for complete examples:

How It Works

Parsing

D2 encodes element IDs as base64 in CSS class names within SVGs:

  • YQ==a
  • KGEgLT4gYilbMF0=(a -> b)[0]

d2vision decodes these to reconstruct the diagram structure.

Generation

The generator converts DiagramSpec to D2 code, handling:

  • Layout directives (direction, grid-columns, grid-rows)
  • Container nesting with proper indentation
  • Shape declarations
  • Edge connections with labels
  • Style properties

Supported Features

  • Node extraction with shape detection (rectangle, circle, oval, cylinder, diamond, hexagon)
  • Edge extraction with source/target identification
  • Container hierarchy (nested nodes)
  • Container-scoped edges
  • Labels and styling information
  • Positional bounds (x, y, width, height)
  • D2 version detection
  • TOON/JSON/YAML serialization

License

MIT

Documentation

Overview

Package d2vision parses D2-generated SVG diagrams and outputs structured JSON and natural language descriptions.

D2 (https://d2lang.com) is a modern diagram scripting language. This package enables programmatic analysis of D2 diagrams by extracting node and edge information from the generated SVG files.

Basic Usage

diagram, err := d2vision.ParseFile("diagram.svg")
if err != nil {
    log.Fatal(err)
}

// Get JSON output
json, _ := diagram.JSONIndent("", "  ")
fmt.Println(string(json))

// Get natural language description
fmt.Println(diagram.Describe())

How It Works

D2 encodes node and edge IDs as base64 in CSS class names within the generated SVG. For example, the class "YQ==" decodes to "a", and "(a -> b)[0]" is encoded as "KGEgLT4gYilbMF0=". By decoding these class names, d2vision reconstructs the diagram structure including:

  • Node IDs and labels
  • Edge connections (source → target)
  • Container/hierarchy relationships
  • Shape types (rectangle, circle, cylinder, etc.)
  • Visual styling information

Output Formats

The package supports multiple output formats:

  • JSON: Structured data suitable for programmatic consumption
  • Text: Human-readable natural language description
  • Summary: Brief overview of diagram contents
  • LLM: Optimized format for large language model consumption

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.1.0"

Version is the version of the d2vision package. This is set at build time by goreleaser via ldflags.

Functions

func DecodeBase64ID

func DecodeBase64ID(encoded string) (string, error)

DecodeBase64ID decodes a base64-encoded D2 element ID.

D2 HTML-encodes special characters (like >) before base64 encoding, so we must unescape HTML entities after decoding to get the original ID.

func EncodeBase64ID

func EncodeBase64ID(id string) string

EncodeBase64ID encodes a D2 element ID to base64. Note: This does NOT HTML-encode first, so it won't produce the same result as D2 for IDs containing special characters like >.

func ExtractBaseName

func ExtractBaseName(nodeID string) string

ExtractBaseName extracts the base name from a node ID (without parent prefix).

Examples:

  • "a" -> "a"
  • "container.node" -> "node"
  • "a.b.c" -> "c"

func ExtractParentID

func ExtractParentID(nodeID string) string

ExtractParentID extracts the parent container ID from a nested node ID. Returns empty string if the node has no parent (is top-level).

Examples:

  • "a" -> ""
  • "container.node" -> "container"
  • "a.b.c" -> "a.b"

func IsEdgeID

func IsEdgeID(id string) bool

IsEdgeID returns true if the decoded ID represents an edge.

func NormalizeID

func NormalizeID(id string) string

NormalizeID cleans up a D2 ID by trimming whitespace.

Types

type ArrowType

type ArrowType string

ArrowType represents the type of arrow on an edge endpoint.

const (
	ArrowNone      ArrowType = "none"
	ArrowTriangle  ArrowType = "triangle"
	ArrowDiamond   ArrowType = "diamond"
	ArrowCircle    ArrowType = "circle"
	ArrowCrowfoot  ArrowType = "crowfoot"
	ArrowCFOne     ArrowType = "cf-one"
	ArrowCFMany    ArrowType = "cf-many"
	ArrowCFOneReq  ArrowType = "cf-one-required"
	ArrowCFManyReq ArrowType = "cf-many-required"
)

Arrow type constants.

func (ArrowType) String

func (a ArrowType) String() string

String returns the string representation of the arrow type.

type Bounds

type Bounds struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

Bounds represents a rectangular bounding box.

func ParseViewBox

func ParseViewBox(s string) (Bounds, error)

ParseViewBox parses an SVG viewBox attribute string.

func (Bounds) Center

func (b Bounds) Center() Point

Center returns the center point of the bounds.

func (Bounds) Contains

func (b Bounds) Contains(p Point) bool

Contains returns true if the point is within the bounds.

func (Bounds) String

func (b Bounds) String() string

String returns a string representation of the bounds.

type Diagram

type Diagram struct {
	Version string `json:"version,omitempty"`
	Title   string `json:"title,omitempty"`
	ViewBox Bounds `json:"viewBox"`
	Nodes   []Node `json:"nodes"`
	Edges   []Edge `json:"edges"`
}

Diagram represents a parsed D2 diagram.

func Parse

func Parse(r io.Reader) (*Diagram, error)

Parse parses a D2 SVG from an io.Reader and returns a Diagram.

func ParseBytes

func ParseBytes(data []byte) (*Diagram, error)

ParseBytes parses a D2 SVG from bytes and returns a Diagram.

func ParseFile

func ParseFile(path string) (diagram *Diagram, err error)

ParseFile parses a D2 SVG file and returns a Diagram.

func ParseString

func ParseString(s string) (*Diagram, error)

ParseString parses a D2 SVG from a string and returns a Diagram.

func (*Diagram) AnalyzeLayout

func (d *Diagram) AnalyzeLayout() *LayoutAnalysis

AnalyzeLayout analyzes the diagram's layout characteristics.

func (*Diagram) ContainerCount

func (d *Diagram) ContainerCount() int

func (*Diagram) ContainerNodes

func (d *Diagram) ContainerNodes() []Node

ContainerNodes returns nodes that have children.

func (*Diagram) Describe

func (d *Diagram) Describe() string

Describe generates a natural language description of the diagram.

func (*Diagram) DescribeDetailed

func (d *Diagram) DescribeDetailed() string

DescribeDetailed generates a detailed natural language description.

func (*Diagram) DescribeForGeneration

func (d *Diagram) DescribeForGeneration() string

DescribeForGeneration generates output optimized for recreating the diagram.

func (*Diagram) DescribeForLLM

func (d *Diagram) DescribeForLLM() string

DescribeForLLM generates a description optimized for LLM consumption.

func (*Diagram) DescribeSummary

func (d *Diagram) DescribeSummary() string

DescribeSummary generates a brief summary of the diagram.

func (*Diagram) EdgeByID

func (d *Diagram) EdgeByID(id string) *Edge

EdgeByID returns the edge with the given ID, or nil if not found.

func (*Diagram) EdgesFrom

func (d *Diagram) EdgesFrom(nodeID string) []Edge

EdgesFrom returns all edges originating from the given node ID.

func (*Diagram) EdgesTo

func (d *Diagram) EdgesTo(nodeID string) []Edge

EdgesTo returns all edges terminating at the given node ID.

func (*Diagram) JSON

func (d *Diagram) JSON() ([]byte, error)

JSON returns the diagram as JSON bytes.

func (*Diagram) JSONIndent

func (d *Diagram) JSONIndent(prefix, indent string) ([]byte, error)

JSONIndent returns the diagram as indented JSON bytes.

func (*Diagram) LeafNodes

func (d *Diagram) LeafNodes() []Node

LeafNodes returns nodes that have no children.

func (*Diagram) NodeByID

func (d *Diagram) NodeByID(id string) *Node

NodeByID returns the node with the given ID, or nil if not found.

func (*Diagram) RootNodes

func (d *Diagram) RootNodes() []Node

RootNodes returns nodes that have no parent.

type Edge

type Edge struct {
	ID          string    `json:"id"`
	Source      string    `json:"source"`
	Target      string    `json:"target"`
	Label       string    `json:"label,omitempty"`
	SourceArrow ArrowType `json:"sourceArrow,omitempty"`
	TargetArrow ArrowType `json:"targetArrow"`
	Path        []Point   `json:"path,omitempty"`
	Style       EdgeStyle `json:"style,omitzero"`
}

Edge represents a connection between two nodes in a D2 diagram.

func (Edge) ConnectionDescription

func (e Edge) ConnectionDescription() string

ConnectionDescription returns a natural language description of the connection.

func (Edge) DisplayLabel

func (e Edge) DisplayLabel() string

DisplayLabel returns the label for display purposes.

func (Edge) IsBidirectional

func (e Edge) IsBidirectional() bool

IsBidirectional returns true if the edge has arrows on both ends.

type EdgeEndpoints

type EdgeEndpoints struct {
	Source    string // Source node ID (fully qualified with container prefix)
	Target    string // Target node ID (fully qualified with container prefix)
	Direction string // Arrow direction: "->", "<-", or "--"
	Index     string // Edge index, e.g., "0"
	Container string // Container scope, e.g., "container" for "container.(a -> b)[0]"
}

EdgeEndpoints represents the parsed components of an edge ID.

func ParseEdgeID

func ParseEdgeID(id string) (EdgeEndpoints, bool)

ParseEdgeID extracts source and target node IDs from an edge ID.

For container-scoped edges like "container.(a -> b)[0]", the source and target are returned with the container prefix: "container.a", "container.b"

type EdgeStyle

type EdgeStyle struct {
	Stroke        string  `json:"stroke,omitempty"`
	StrokeWidth   float64 `json:"strokeWidth,omitempty"`
	StrokeDash    string  `json:"strokeDash,omitempty"`
	Opacity       float64 `json:"opacity,omitempty"`
	Animated      bool    `json:"animated,omitempty"`
	LabelFontSize float64 `json:"labelFontSize,omitempty"`
}

EdgeStyle contains visual styling properties for an edge.

type LayoutAnalysis

type LayoutAnalysis struct {
	// Layout type detection
	LayoutType          string `json:"layoutType" toon:"LayoutType"`
	Direction           string `json:"direction,omitempty" toon:"Direction"`
	GridColumns         int    `json:"gridColumns,omitempty" toon:"GridColumns"`
	GridRows            int    `json:"gridRows,omitempty" toon:"GridRows"`
	HasContainers       bool   `json:"hasContainers" toon:"HasContainers"`
	ContainerCount      int    `json:"containerCount" toon:"ContainerCount"`
	NestingDepth        int    `json:"nestingDepth" toon:"NestingDepth"`
	CrossContainerEdges int    `json:"crossContainerEdges" toon:"CrossContainerEdges"`

	// Layout insights
	Insights []string `json:"insights" toon:"Insights"`

	// Generation hints
	GenerationHints []string `json:"generationHints" toon:"GenerationHints"`
}

LayoutAnalysis contains analysis of a diagram's layout characteristics.

type Node

type Node struct {
	ID       string    `json:"id"`
	Label    string    `json:"label,omitempty"`
	Shape    ShapeType `json:"shape"`
	Bounds   Bounds    `json:"bounds"`
	Parent   string    `json:"parent,omitempty"`
	Children []string  `json:"children,omitempty"`
	Style    NodeStyle `json:"style,omitzero"`
}

Node represents a node (shape) in a D2 diagram.

func (Node) DisplayLabel

func (n Node) DisplayLabel() string

DisplayLabel returns the label for display purposes. If no label is set, it returns the ID.

func (Node) HasChildren

func (n Node) HasChildren() bool

HasChildren returns true if the node has child nodes.

func (Node) IsContainer

func (n Node) IsContainer() bool

IsContainer returns true if the node is a container (has children).

type NodeStyle

type NodeStyle struct {
	Fill        string  `json:"fill,omitempty"`
	Stroke      string  `json:"stroke,omitempty"`
	StrokeWidth float64 `json:"strokeWidth,omitempty"`
	FontSize    float64 `json:"fontSize,omitempty"`
	FontColor   string  `json:"fontColor,omitempty"`
	Opacity     float64 `json:"opacity,omitempty"`
}

NodeStyle contains visual styling properties for a node.

type OutputFormat

type OutputFormat string

OutputFormat specifies the output format for diagram descriptions.

const (
	FormatJSON    OutputFormat = "json"
	FormatText    OutputFormat = "text"
	FormatSummary OutputFormat = "summary"
)

type Parser

type Parser struct {
	// IncludePaths controls whether edge path coordinates are included in output.
	IncludePaths bool
	// IncludeStyles controls whether style information (fill, stroke) is extracted.
	IncludeStyles bool
}

Parser parses D2-generated SVG diagrams.

D2 encodes element IDs as base64 in CSS class names. For example:

  • "YQ==" decodes to "a" (a node)
  • "KGEgLT4gYilbMF0=" decodes to "(a -> b)[0]" (an edge)

The parser decodes these class names to reconstruct the diagram structure.

func NewParser

func NewParser() *Parser

NewParser creates a new Parser with default settings.

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) (*Diagram, error)

Parse parses an SVG from the given reader.

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(data []byte) (*Diagram, error)

ParseBytes parses an SVG from bytes.

func (*Parser) ParseString

func (p *Parser) ParseString(s string) (*Diagram, error)

ParseString parses an SVG from a string.

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Point represents a 2D coordinate.

func (Point) String

func (p Point) String() string

String returns a string representation of the point.

type ShapeType

type ShapeType string

ShapeType represents the visual shape of a node.

const (
	ShapeRectangle     ShapeType = "rectangle"
	ShapeSquare        ShapeType = "square"
	ShapeCircle        ShapeType = "circle"
	ShapeOval          ShapeType = "oval"
	ShapeCylinder      ShapeType = "cylinder"
	ShapeDiamond       ShapeType = "diamond"
	ShapeHexagon       ShapeType = "hexagon"
	ShapeParallelogram ShapeType = "parallelogram"
	ShapeCloud         ShapeType = "cloud"
	ShapeDocument      ShapeType = "document"
	ShapeQueue         ShapeType = "queue"
	ShapePackage       ShapeType = "package"
	ShapePerson        ShapeType = "person"
	ShapeClass         ShapeType = "class"
	ShapeCode          ShapeType = "code"
	ShapeImage         ShapeType = "image"
	ShapeText          ShapeType = "text"
	ShapeUnknown       ShapeType = "unknown"
)

Shape type constants.

func (ShapeType) NaturalName

func (s ShapeType) NaturalName() string

NaturalName returns a human-readable name for the shape.

func (ShapeType) String

func (s ShapeType) String() string

String returns the string representation of the shape type.

Directories

Path Synopsis
cmd
d2vision command
Command d2vision parses D2-generated SVG diagrams, generates D2 code, and provides tools for AI-assisted diagram creation.
Command d2vision parses D2-generated SVG diagrams, generates D2 code, and provides tools for AI-assisted diagram creation.
Package convert provides converters for transforming Mermaid and PlantUML diagrams into D2 format via the generate.DiagramSpec intermediate representation.
Package convert provides converters for transforming Mermaid and PlantUML diagrams into D2 format via the generate.DiagramSpec intermediate representation.
mermaid
Package mermaid provides parsing and conversion of Mermaid diagrams to D2.
Package mermaid provides parsing and conversion of Mermaid diagrams to D2.
plantuml
Package plantuml provides parsing and conversion of PlantUML diagrams to D2.
Package plantuml provides parsing and conversion of PlantUML diagrams to D2.
Package format provides output format abstraction for CLI commands.
Package format provides output format abstraction for CLI commands.
Package generate provides D2 code generation from structured specifications.
Package generate provides D2 code generation from structured specifications.
Package icons provides access to D2's icon library hosted at icons.terrastruct.com.
Package icons provides access to D2's icon library hosted at icons.terrastruct.com.
Package render provides D2 diagram rendering using the d2 library.
Package render provides D2 diagram rendering using the d2 library.
Package schema provides embedded JSON Schema definitions for d2vision types.
Package schema provides embedded JSON Schema definitions for d2vision types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL