D2 is a modern diagramming scripting language that converts text into diagrams.
It stands for declarative diagrams, users just need to use descriptive text and it will automatically generate images.
Here’s its Hello World:
For example, to download the CLI, create a file called
input.d2 file, copy and paste the following content, and run this command:
d2 --theme=300 --dark-theme=200 -l elk --pad 0 ./input.d2
You will get the image below:
The most convenient way to use D2 is to run it as a CLI executable to run from
.d2The file generates SVG.
# 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,
out.svgand live reload for
The easiest way to install is to use the install script:
curl -fsSL https://d2lang.com/install.sh | sh -s --
You can run the install script to
--dry-runView the commands that will be used for installation without executing them.
Alternatively, if you have Go installed, you can install from source, but you won’t get the manpages:
go install oss.terrastruct.com/d2@latest
There is also a version that includes a manpage that can be installed from source.see./docs/INSTALL.md#source-release .
Uninstall using the install script:
curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall
For detailed installation documentation, see./docs/INSTALL.md which demonstrates alternatives and examples for each operating system.
Additionally, the functionality of the installation script is described in detail to remove any concerns about its use.
It is recommended to use the operating system’s package manager directly for increased 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 generate graphs from Go programs.
D2 includes a variety of official themes to design diagrams beautifully out of the box.see./d2themesto browse available themes and make or contribute your own creations.
D2 comes with “Source Sans Pro” as the font in the renders.If you want to use a different font, see./d2renderers/d2fonts .
Export file type
D2 currently supports SVG, PNG and PDF export. More coming soon.
D2 was designed with language tools in mind. D2’s parser can parse multiple errors from broken programs, has an auto-formatter, syntax highlighting, has plans for LSP, and more.
Extensions for VSCode and Vim can be found atrelevantpartially found.
D2 is designed to be extensible and composable. A plugin system allows changing the layout engine and customizing the rendering pipeline.
Plugins can be bundled with the build or installed separately as standalone binaries.
- dagre (default, bundled): A fast directed graph layout engine that generates hierarchical/hierarchical layouts. DOT algorithm based on Graphviz.
- ELK (bundle): A directed graph layout engine, especially for node-link graphs with inherent directions and ports.
- TALA (binary): A new layout engine designed for software architecture diagrams. A separate installation is required, visit the Github page for more information.
D2 is designed to integrate with various layout engines such as
dotand single-purpose layout types such as sequence diagrams.
#Homepage #Documentation #Downloads #Diagram #Scripting #Language #News Fast Delivery