D2 is a modern diagram scripting language that turns text to diagrams.
Find a file
Anmol Sethi c4ef432daf
Move textmeasure into lib
It's not a d2renderer.
2022-12-01 06:51:17 -08:00
.github daily.yml: Simplify 2022-12-01 05:34:34 -08:00
ci ci/sub: Update 2022-11-30 22:55:42 -08:00
cmd/d2plugin-dagre d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00
d2ast [ci-base] cleanup 2022-11-14 19:05:23 -08:00
d2chaos Move textmeasure into lib 2022-12-01 06:51:17 -08:00
d2compiler 2022-11-29 05:59:27PM 2022-11-29 17:59:27 -08:00
d2exporter Move textmeasure into lib 2022-12-01 06:51:17 -08:00
d2format oss 2022-11-03 06:54:49 -07:00
d2graph Move textmeasure into lib 2022-12-01 06:51:17 -08:00
d2layouts Fix span rendering order 2022-11-30 13:41:20 -08:00
d2lib Move textmeasure into lib 2022-12-01 06:51:17 -08:00
d2oracle oss 2022-11-03 06:54:49 -07:00
d2parser Fix trailing whitespace 2022-11-28 10:44:18 -08:00
d2plugin 2022-11-16 04:48:46PM 2022-11-16 16:48:46 -08:00
d2renderers Move textmeasure into lib 2022-12-01 06:51:17 -08:00
d2target PR comments 2022-11-30 13:15:33 -08:00
d2themes 2022-11-24 08:07:22AM 2022-11-24 08:07:22 -08:00
docs Move textmeasure into lib 2022-12-01 06:51:17 -08:00
e2etests Move textmeasure into lib 2022-12-01 06:51:17 -08:00
lib Move textmeasure into lib 2022-12-01 06:51:17 -08:00
out Add arrowhead label test case from #169 2022-11-23 19:47:07 -08:00
static d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00
testdata Update tests 2022-11-30 11:23:30 -08:00
.gitattributes .gitattributes: Add testdata 2022-11-28 15:47:31 -08:00
.gitignore oss 2022-11-03 06:54:49 -07:00
.gitmodules oss 2022-11-03 06:54:49 -07:00
go.mod Update cmdlog 2022-12-01 02:11:11 -08:00
go.sum go mod tidy 2022-12-01 02:19:12 -08:00
help.go d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00
install.sh ci/sub: Update 2022-11-30 22:55:42 -08:00
LICENSE.txt oss 2022-11-03 06:54:49 -07:00
main.go Move textmeasure into lib 2022-12-01 06:51:17 -08:00
main_test.go d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00
make.sh make.sh: Clone submodules automatically 2022-11-29 13:54:11 -08:00
Makefile ci: Consolidate github actions into one main job 2022-11-29 13:09:12 -08:00
README.md README: Update 2022-12-01 03:51:06 -08:00
watch.go d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00
watch_dev.go d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00

D2

A modern diagram scripting language that turns text to diagrams.

Language docs | Cheat sheet | Comparisons

ci release discord twitter license

D2 CLI

Table of Contents

What does D2 look like?

# Actors
hans: Hans Niemann

defendants: {
  mc: Magnus Carlsen
  playmagnus: Play Magnus Group
  chesscom: Chess.com
  naka: Hikaru Nakamura

  mc -> playmagnus: Owns majority
  playmagnus <-> chesscom: Merger talks
  chesscom -> naka: Sponsoring
}

# Accusations
hans -> defendants: 'sueing for $100M'

# Offense
defendants.naka -> hans: Accused of cheating on his stream
defendants.mc -> hans: Lost then withdrew with accusations
defendants.chesscom -> hans: 72 page report of cheating

There is syntax highlighting with the editor plugins linked below.

D2 render example

Rendered with the TALA layout engine.

For more examples, see ./docs/examples.

Quickstart

The most convenient way to use D2 is to just run it as a CLI executable to produce SVGs from .d2 files.

# First, install D2
curl -fsSL https://d2lang.com/install.sh | sh -s --

echo 'x -> y -> z' > in.d2
d2 --watch in.d2 out.svg

A browser window will open with out.svg and live-reload on changes to in.d2.

Install

The easiest way to install is with our install script:

curl -fsSL https://d2lang.com/install.sh | sh -s --

You can run the install script with --dry-run to see the commands that will be used to install without executing them.

To uninstall:

curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall

For detailed installation docs, with alternative methods and examples for each OS, see ./docs/INSTALL.md.

D2 as a library

In addition to being a runnable CLI tool, D2 can also be used to produce diagrams from Go programs.

For examples, see ./docs/examples/lib.

Themes

D2 includes a variety of official themes to style your diagrams beautifully right out of the box. See ./d2themes to browse the available themes and make or contribute your own creation.

Fonts

D2 ships with "Source Sans Pro" as the font in renders. If you wish to use a different one, please see ./d2renderers/d2fonts.

Export file types

D2 currently supports SVG exports. More coming soon.

Language tooling

D2 is designed with language tooling in mind. D2's parser can parse multiple errors from a broken program, has an autoformatter, syntax highlighting, and we have plans for LSP's and more. Good language tooling is necessary for creating and maintaining large diagrams.

The extensions for VSCode and Vim can be found in the Related section.

Plugins

D2 is designed to be extensible and composable. The plugin system allows you to change out layout engines and customize the rendering pipeline. Plugins can either be bundled with the build or separately installed as a standalone binary.

Layout engines:

  • dagre (default, bundled): A fast, directed graph layout engine that produces layered/hierarchical layouts. Based on Graphviz's DOT algorithm.
  • ELK (bundled): A directed graph layout engine particularly suited for node-link diagrams with an inherent direction and ports.
  • TALA (binary): Novel layout engine designed specifically for software architecture diagrams. Requires separate install, visit the Github page for more.

D2 intends to integrate with a variety of layout engines, e.g. dot, as well as single-purpose layout types like sequence diagrams. You can choose whichever layout engine you like and works best for the diagram you're making.

Comparison

For a comparison against other popular text-to-diagram tools, see https://text-to-diagram.com.

Contributing

Contributions are welcome! See ./docs/CONTRIBUTING.md.

License

Open sourced under the Mozilla Public License 2.0. See ./LICENSE.txt.

VSCode extension

https://github.com/terrastruct/d2-vscode

Vim extension

https://github.com/terrastruct/d2-vim

Language docs

https://github.com/terrastruct/d2-docs

Misc

FAQ

  • Does D2 collect telemetry?
    • No, D2 does not use an internet connection after installation, except to check for version updates from Github periodically.
  • Does D2 need a browser to run?
    • No, D2 can run entirely server-side.
  • What's coming in the next release?
  • I have a question or need help.
    • The best way to get help is to ask on D2 Discord
  • I have a feature request, proposal, or bug report.
    • Please open up a Github Issue.
  • I have a private inquiry.