D2 is a modern diagram scripting language that turns text to diagrams.
Find a file
Anmol Sethi e4fac7840f
cli: Improve multiboard output
- Boards with subboards are now selfcontained folders with index.svg/png as
  the root board render.
- Boards that are only containers of other boards are not rendered. For example a
  scenario with no modifications and only steps only has its steps
  rendered.
- Boards with sibling boards of another type are rendered under a
  subdirectory indicating their type to separate them. For example a
  board with layers and scenarios has its layers rendered into subfolder
  layers and scenarios into subfolder scenarios.

cc @berniexie see BoardContainer field on d2target.Board for the field
you were looking for to skip renders for PDFs too.
2023-02-27 13:50:03 -08:00
.github ci: Update [ci-force] 2023-01-24 15:07:42 -08:00
ci cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
cmd/d2plugin-dagre default layouts 2022-12-30 13:36:49 -08:00
d2ast fix edge key index value 2023-02-20 20:17:17 -08:00
d2chaos merge updates 2023-02-19 12:32:44 +01:00
d2compiler cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
d2exporter cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
d2format d2ir: Review fixes #714 2023-01-27 17:19:12 -08:00
d2graph cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
d2ir cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
d2layouts check for no actors in sequence diagram 2023-02-23 23:17:45 -08:00
d2lib merge updates 2023-02-19 12:32:44 +01:00
d2oracle ensure 2023-02-27 10:33:35 -08:00
d2parser d2ir: IR Root wip 2023-01-24 03:24:24 -08:00
d2plugin check for plugin feature errors in e2e tests 2023-02-22 12:47:39 -08:00
d2renderers cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
d2target cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
d2themes implement background styles 2023-02-26 16:23:51 -08:00
docs Merge branch 'terrastruct:master' into master 2023-02-20 10:27:44 +01:00
e2etests cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
lib changelog 2023-02-27 12:58:21 -08:00
static update d2 watch mode 2023-02-24 19:36:09 -08:00
testdata cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
.gitattributes .gitattributes: Add testdata 2022-11-28 15:47:31 -08:00
.gitignore ci/cov.sh: Add 2023-01-24 02:56:31 -08:00
.gitmodules oss 2022-11-03 06:54:49 -07:00
.prettierignore Add rough.js to .prettierignore 2022-12-30 21:12:52 +01:00
fmt.go fmt: Accept multiple files to be formatted 2023-01-27 07:31:12 -08:00
go.mod cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
go.sum cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
help.go update layout link 2023-02-05 00:41:00 -08:00
install.sh install.sh: Handle empty GITHUB_TOKEN correctly 2023-02-12 07:37:14 -08:00
LICENSE.txt oss 2022-11-03 06:54:49 -07:00
main.go cli: Improve multiboard output 2023-02-27 13:50:03 -08:00
main_test.go d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00
make.sh ci/release/build.sh: Automatically clone ci submodule 2022-12-18 12:41:22 -08:00
Makefile Makefile: Revert unset GITHUB_TOKEN 2023-02-12 07:45:29 -08:00
README.md revert space 2023-02-24 13:59:21 -08:00
watch.go Merge branch 'master' into 120/pdf-export 2023-02-23 12:55:58 -08:00
watch_dev.go d2: Move cmd to repo root 2022-11-30 21:16:02 -08:00

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.

Or if you have Go installed you can install from source though you won't get the manpage:

go install oss.terrastruct.com/d2@latest

You can also install a release from source which will include manpages. See ./docs/INSTALL.md#source-release.

To uninstall with the install script:

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

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

As well, the functioning of the install script is described in detail to alleviate any concern of its use. We recommend using your OS's package manager directly instead for improved security but the install script is by no means insecure.

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. This blog post also demos a complete, runnable example of using D2 as a library for a real-world use case.

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, PNG and PDF 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.

We are constantly working on new plugins, integrations, extensions. Contributions are welcome in any official or community plugins. If you have somewhere in your workflow that you want to use D2, feel free to open a discussion. We have limited bandwidth and usually choose the most high-demand ones to work on. If you make something cool with D2 yourself, let us know and we'll be happy to include it here!

Official plugins

Community plugins

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.

Open-source projects documenting with D2

Do you have or see an open-source project with .d2 files? Please submit a PR adding to this list (ordered by star count, desc).

  • Block Protocol - The Block Protocol is an open standard for building and using data-driven blocks.
  • Ivy Wallet - Ivy Wallet is an open-source money manager app for Android.
  • Learn EVM Attacks - Learn & Contribute on previously exploited vulnerabilities across several EVM projects.
  • BYCEPS - BYCEPS is a self-hosted web platform to run LAN parties.
  • Re:Earth - A free, open and highly extensible WebGIS platform.
  • Terraform OCI VSCode Server - Terraform project that deploys VSCode Server on Oracle Cloud Infrastructure.