### Run D2 Development Server Source: https://github.com/silverbullet069/d2-docs/blob/master/README.md Installs project dependencies and starts the development server for D2. ```sh yarn yarn run dev ``` -------------------------------- ### Install D2 from Source Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/install.md Installs the latest version of D2 from source using the Go package manager. ```go go install oss.terrastruct.com/d2@latest ``` -------------------------------- ### Docker Installation Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.2.md Instructions for installing and using D2 via its official Docker image. ```bash docker run -it --rm -v $(pwd):/src terrastruct/d2 ``` -------------------------------- ### D2 Windows Support Installation Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.0.md Instructions for installing D2 on Windows. Refer to the INSTALL.md file for detailed usage. ```bash # Example installation command (refer to docs for specifics) # curl -fsSL https://d2lang.com/install.sh | bash ``` -------------------------------- ### D2 Installation from Source Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Shows how to install D2 directly from source using Go or by downloading precompiled binaries from GitHub releases. ```go go install oss.terrastruct.com/d2@latest ``` -------------------------------- ### D2 Installation from Source Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.0.md D2 is now located in the root folder of the repository. Install from source using `go install`. ```bash go install oss.terrastruct.com/d2@latest ``` -------------------------------- ### Windows MSI Installer Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.2.md Information regarding the availability of an MSI installer for convenient installation of D2 on Windows systems. ```bash Download and run the .msi installer from the official D2 releases page. ``` -------------------------------- ### macOS Installation with Homebrew Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.0.13.md Shows how to install D2 on macOS using Homebrew, provided Homebrew is installed on the system. This script automates the installation process. ```bash # Assumes Homebrew is installed brew install d2 ``` -------------------------------- ### D2 Installation Script Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Provides bash commands to install D2 using an official installation script, including options for dry runs and uninstallation. ```bash # With --dry-run the install script will print the commands it will use # to install without actually installing so you know what it's going to do. curl -fsSL https://d2lang.com/install.sh | sh -s -- --dry-run # If things look good, install for real. curl -fsSL https://d2lang.com/install.sh | sh -s -- curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall ``` -------------------------------- ### D2 Studio Screenshot Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/studio.md This snippet shows an example of a multi-layer D2 diagram presented in D2 Studio's web interface, linking to an interactive demo. ```html D2 Studio screenshot ``` -------------------------------- ### Try D2 Installation Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/install.md Creates a simple D2 input file and renders it to an SVG file. It also demonstrates the watch mode (-w) which automatically refreshes the output when the input file changes. ```shell echo 'x -> y' > input.d2 d2 -w input.d2 out.svg ``` -------------------------------- ### D2 Install Script Prefix Option Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.0.md The `install.sh` script defaults to `/usr/local` but will use `~/.local` if `/usr/local` is not accessible. Use `--prefix` to force installation location. ```bash ./install.sh --prefix /usr/local ``` -------------------------------- ### Example with Multiple Containers and Connections Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/containers.md Provides a comprehensive example showcasing the use of multiple containers, nested structures, and connections between them. This example demonstrates how to define cloud providers (AWS, Google Cloud) with their respective services and establish relationships between different parts of the diagram. ```d2 clouds: { aws: AWS { load_balancer -> api api -> db } gcloud: Google Cloud { auth -> db } gcloud -> aws } users -> clouds.aws.load_balancer users -> clouds.gcloud.auth ci.deploys -> clouds ``` -------------------------------- ### Install TALA with Install Script Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Installs TALA using the official install script. The `--dry-run` flag can be used to preview the installation commands without executing them. Re-running the script upgrades TALA. ```sh curl -fsSL https://d2lang.com/install.sh | sh -s -- --tala --dry-run curl -fsSL https://d2lang.com/install.sh | sh -s -- --tala ``` -------------------------------- ### Example Connections Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Provides a set of example connections showcasing various scenarios, including long shape IDs and different connection styles. ```d2 Write Replica Canada <-> Write Replica Australia Read Replica <- Master x -- y super long shape id here -> super long shape id even longer here ``` -------------------------------- ### Install D2 using Install Script Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/install.md Installs D2 using a shell script. The --dry-run option shows the commands that will be executed without performing the installation. The --uninstall option removes D2. ```shell curl -fsSL https://d2lang.com/install.sh | sh -s -- --dry-run curl -fsSL https://d2lang.com/install.sh | sh -s -- curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall ``` -------------------------------- ### Install Confluence App Button Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/confluence.md This snippet provides the HTML and inline styles for a button that links to the Atlassian Marketplace to install the Confluence app. It includes styling for appearance and layout. ```html Install Confluence app ``` -------------------------------- ### D2 Hello World Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/hello-world.md This snippet shows the basic D2 syntax for creating two shapes, 'x' and 'y', and connecting them with a label 'hello world'. It's a fundamental example for understanding D2's declarative diagramming. ```d2 x -> y: hello world ``` -------------------------------- ### Grid Diagrams - Basic Setup Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Demonstrates the fundamental setup of a grid diagram using `grid-rows` and `grid-columns`. This allows for arranging elements in a structured grid format. ```d2 grid-rows: 5 style.fill: black classes: { white square: { label: "" width: 120 style: { fill: white stroke: cornflowerblue stroke-width: 10 } } block: { style: { text-transform: uppercase font-color: white fill: darkcyan stroke: black } } } flow1.class: white square flow2.class: white square flow3.class: white square flow4.class: white square flow5.class: white square flow6.class: white square flow7.class: white square flow8.class: white square flow9.class: white square dagger engine: { width: 800 class: block style: { fill: beige stroke: darkcyan font-color: blue stroke-width: 8 } } any docker compatible runtime: { width: 800 class: block style: { fill: lightcyan stroke: darkcyan font-color: black stroke-width: 8 } icon: https://icons.terrastruct.com/dev%2Fdocker.svg } any ci: { class: block style: { fill: gold stroke: maroon font-color: maroon stroke-width: 8 } } windows.class: block linux.class: block macos.class: block kubernetes.class: block ``` -------------------------------- ### D2 CLI Command Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md An example of how to use the D2 command-line interface (CLI) to render a diagram. This command specifies a theme, a dark theme, a layout engine (ELK), and padding. ```bash d2 --theme=300 --dark-theme=200 -l elk --pad 0 ./input.d2 ``` -------------------------------- ### Example Connections Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/connections.md Provides various examples of connection definitions, including complex shape IDs and multi-line definitions. ```d2 Write Replica Canada <-> Write Replica Australia Read Replica <- Master x -- y super long shape id here --\ -> super long shape id even longer here ``` -------------------------------- ### Vim Plugin Installation Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Instructions for installing the official D2 Vim plugin using a plugin manager like vim-plug. This enables syntax highlighting and automatic indentation for D2 files. ```vim Plug 'terrastruct/d2-vim' ``` -------------------------------- ### LaTeX Braket Plugin Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Demonstrates the usage of the `braket` LaTeX plugin for rendering quantum mechanical bra-ket notation in D2 diagrams. ```tex braket plugin: { ex: |tex \bra{a}\ket{b} | } ``` -------------------------------- ### Graphviz Styling Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Demonstrates how to apply styles and configurations to a Graphviz diagram, highlighting the separation of concerns that D2 aims for. ```graphviz digraph "Linux_kernel_diagram" { fontname="Helvetica,Arial,sans-serif" node [fontname="Helvetica,Arial,sans-serif"] edge [fontname="Helvetica,Arial,sans-serif"] graph [ newrank = true, nodesep = 0.3, ranksep = 0.2, overlap = true, splines = false, ] node [ fixedsize = false, fontsize = 24, height = 1, shape = box, style = "filled,setlinewidth(5)", width = 2.2 ] edge [ arrowhead = none, arrowsize = 0.5, labelfontname = "Ubuntu", weight = 10, style = "filled,setlinewidth(5)" ] } ``` -------------------------------- ### LaTeX Mhchem Plugin Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Provides an example of the `mhchem` LaTeX plugin, designed for rendering chemical equations and formulas clearly and accurately within D2 diagrams. ```tex mhchem plugin: { ex: |tex \ce{SO4^2- + Ba^2+ -> BaSO4 v} | } ``` -------------------------------- ### D2 Example Diagram Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md A comprehensive example showcasing multiple shape declarations with custom labels and types, including a 'cloud' shape. ```d2 pg: PostgreSQL Cloud: my cloud Cloud.shape: cloud SQLite Cassandra ``` -------------------------------- ### LaTeX AMSCD Plugin Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Provides an example of using the `amscd` LaTeX plugin in D2 to render commutative diagrams. It showcases the `\begin{CD}` environment and its syntax for defining arrows and labels. ```tex amscd plugin: { ex: |tex \begin{CD} B @>{\text{very long label}}>> C S^{\mathcal{W}_\Lambda}\otimes T @>j>> T\\ @VVV V \end{CD} | } ``` -------------------------------- ### Container Example with Nesting and Referencing Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Provides a comprehensive example of using containers, nested syntax, and referencing shapes within containers, including cross-container references and styling. ```d2 clouds: { aws: AWS { load_balancer -> api api -> db } gcloud: Google Cloud { auth -> db } gcloud -> aws } users -> clouds.aws.load_balancer users -> clouds.gcloud.auth ci.deploys -> clouds ``` -------------------------------- ### Internal Link Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/linking.md Demonstrates how to create an internal link to another D2 board. This example shows a simple link to a board named 'cat'. ```d2-incomplete a.link: "cat" ``` -------------------------------- ### Root Board Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md A minimal D2 diagram representing a single root board. ```d2 # Root board x -> y ``` -------------------------------- ### Dagre Layout Gallery Examples Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/dagre.md Visual examples of layouts rendered using the Dagre engine. These are embedded SVGs showcasing different diagram structures and how Dagre handles them. ```html
``` -------------------------------- ### LaTeX Physics Plugin Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Illustrates the `physics` LaTeX plugin, which offers commands for typesetting physics-related mathematical notation, including variables and derivatives. ```tex physics plugin: { ex: |tex \var{F[g(x)]} \dd(\cos\theta) | } ``` -------------------------------- ### Simple PowerPoint Generation with D2 Source: https://github.com/silverbullet069/d2-docs/blob/master/blog/powerpoint.md Demonstrates creating a basic PowerPoint presentation from a D2 file. Requires D2 installation. The output is a view-only presentation. ```d2-incomplete direction: right # Slide 1 slide: intro "Text to PowerPoint" -> "D2 is versatile" "D2 is versatile" -> "Create presentations" # Slide 2 slide: simple_example "Simple Example" -> "Text only" "Text only" -> "Download: cult.pptx" "Text only" -> "Google Slides: link" # Slide 3 slide: complex_example "Complex Example" -> "Diagrams and Images" "Diagrams and Images" -> "Download: wcc.pptx" "Diagrams and Images" -> "Google Slides: link" ``` -------------------------------- ### D2 CLI Command Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/intro.md Demonstrates how to use the D2 CLI to generate a diagram from an input file with specified theme, dark theme, layout engine, and padding. ```sh d2 --theme=300 --dark-theme=200 -l elk --pad 0 ./input.d2 ``` -------------------------------- ### D2 Image and Dimension Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Illustrates how to define nodes with images and specify their dimensions (width and height) in D2. This example shows a sequence of 'jerry' nodes with varying sizes. ```d2 direction: right small jerry: "" { shape: image icon: https://static.wikia.nocookie.net/tomandjerry/images/4/46/JerryJumbo3-1-.jpg width: 200 height: 200 } med jerry: "" { shape: image icon: https://static.wikia.nocookie.net/tomandjerry/images/4/46/JerryJumbo3-1-.jpg width: 300 height: 300 } big jerry: "" { shape: image icon: https://static.wikia.nocookie.net/tomandjerry/images/4/46/JerryJumbo3-1-.jpg width: 500 height: 400 } big jerry -> med jerry -> small jerry ``` -------------------------------- ### Install D2 Vim Plugin Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/vim.md Instructions for installing the official D2 Vim plugin using a plugin manager. This enables syntax highlighting and indentation for D2 files within Vim. ```vim Plug 'terrastruct/d2-vim' ``` -------------------------------- ### D2 Formatting Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/auto-formatter.md Demonstrates how D2's auto-formatter transforms unformatted D2 code into a consistent and readable format. ```d2 aws_s3: AWS S3 California{ Monitoring ---------->California } ``` ```d2 aws_s3: AWS S3 California { Monitoring -> California } ``` -------------------------------- ### Basic Container Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/containers.md Demonstrates the fundamental usage of containers in D2 diagrams. This snippet shows how to define a basic container and its contents. ```d2 Containers1 ``` -------------------------------- ### Install TALA with Homebrew Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Installs TALA using Homebrew, a package manager for macOS and Linux. This is an alternative installation method. ```sh brew install terrastruct/tap/tala ``` -------------------------------- ### D2 Basic Usage and Live Preview Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Demonstrates the basic command-line usage of D2 to render a simple diagram to an SVG file and enable live preview mode. ```bash echo 'x -> y' > input.d2 d2 -w input.d2 out.svg ``` -------------------------------- ### Create and render a basic D2 diagram Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/install.md This snippet demonstrates how to create a simple D2 diagram file and then render it to an SVG image. The `-w` flag enables a local web server that automatically refreshes the diagram in your browser upon changes to the input file. ```shell echo 'x -> y' > input.d2 d2 -w input.d2 out.svg ``` -------------------------------- ### D2 Shapes Example 1 Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/shapes.md An example D2 code snippet illustrating the declaration of multiple shapes and their properties. ```d2 { // Define shapes with custom labels and types "shape1": { "label": "Shape One", "shape": "circle" }, "shape2": { "label": "Shape Two", "shape": "square" }, "shape3": { "label": "Shape Three", "shape": "rectangle" } } ``` -------------------------------- ### D2 Shapes Example 2 Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/shapes.md A second example D2 code snippet showcasing more complex shape definitions and relationships. ```d2 { // Define shapes with different types and connections "A": { "label": "Start", "shape": "diamond" }, "B": { "label": "Process", "shape": "rectangle" }, "C": { "label": "End", "shape": "circle" }, "A" -> "B" -> "C" } ``` -------------------------------- ### Basic D2 Hello World Diagram Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/hello-world.md This snippet demonstrates the basic syntax for creating a D2 diagram. It defines two shapes, 'x' and 'y', and connects them with a label 'hello world'. This is the simplest way to start visualizing relationships in D2. ```d2 x -> y: hello world ``` -------------------------------- ### D2 CLI Options Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/man.md Detailed explanation of the various options available for the D2 CLI, controlling aspects like live reloading, theming, styling, output scaling, font paths, and more. ```APIDOC -w, --watch false Watch for changes to input and live reload. Use $PORT and $HOST to specify the listening address. -h, --host localhost Host listening address when used with watch. -p, --port 0 Port listening address when used with watch. -t, --theme 0 Set the diagram theme ID. --dark-theme -1 The theme to use when the viewer's browser is in dark mode. When left unset --theme is used for both light and dark mode. Be aware that explicit styles set in D2 code will still be applied and this may produce unexpected results. We plan on resolving this by making style maps in D2 light/dark mode specific. See https://github.com/terrastruct/d2/issues/831. -s, --sketch false Renders the diagram to look like it was sketched by hand. --center flag Center the SVG in the containing viewbox, such as your browser screen. --scale -1 Scale the output. E.g., 0.5 to halve the default size. Default -1 means that SVG's will fit to screen and all others will use their default render size. Setting to 1 turns off SVG fitting to screen. --font-regular Path to .ttf file to use for the regular font. If none provided, Source Sans Pro Regular is used. --font-italic Path to .ttf file to use for the italic font. If none provided, Source Sans Pro Regular-Italic is used. --font-bold Path to .ttf file to use for the bold font. If none provided, Source Sans Pro Bold is used. --pad 100 Pixels padded around the rendered diagram. --animate-interval 0 If given, multiple boards are packaged as 1 SVG which transitions through each board at the interval (in milliseconds). Can only be used with SVG and GIF exports. --browser true Browser executable that watch opens. Setting to 0 opens no browser. -l, --layout dagre Set the diagram layout engine to the passed string. For a list of available options, run layout. -b, --bundle true Bundle all assets and layers into the output svg. --force-appendix false An appendix for tooltips and links is added to PNG exports since they are not interactive. Setting this to true adds an appendix to SVG exports as well. --target Target board to render. Pass an empty string to target root board. If target ends with '*', it will be rendered with all of its scenarios, steps, and layers. Otherwise, only the target board will be rendered. E.g. --target='' to render root board only or --target='layers.x.*' to render layer 'x' with all of its children. -d, --debug Print debug logs. --img-cache true In watch mode, images used in icons are cached for subsequent compilations. This should be disabled if images might change. --timeout 120 The maximum number of seconds that D2 runs for before timing out and exiting. When rendering a large diagram, it is recommended to increase this value. --check false Check that the specified files are formatted correctly. --salt string Add a salt value to ensure the output uses unique IDs. This is useful when generating multiple identical diagrams to be included in the same HTML doc, so that duplicate id's do not cause invalid HTML. The salt value is a string that will be appended to IDs in the output.. -h, --help Print usage information and exit. -v, --version Print version information and exit. --stdout-format string Set the output format when writing to stdout. Supported formats are: png, svg. Only used when output is set to stdout (-). --no-xml-tag false Omit XML tag () from output SVG files. Useful when generating SVGs for direct HTML embedding. ``` -------------------------------- ### Comprehensive D2 Shapes Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/shapes.md Presents a more complex example demonstrating various shape declarations and their relationships, showcasing how different shapes can be combined to form a diagram. ```d2 backend: { shape: rectangle label: "Backend Service" } database: { shape: cylinder label: "User Data" } frontend: { shape: rectangle label: "Web App" } frontend -> backend backend -> database ``` -------------------------------- ### Graph Example Screenshot Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/design.md This snippet displays an example of a diagram that might be considered a 'graph' rather than a simple architectural diagram, illustrating the concept of fitting on a whiteboard. ```html graph example ``` -------------------------------- ### Advanced Container Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/containers.md Provides a more comprehensive example of container usage, potentially including multiple levels of nesting or complex relationships between elements within containers. ```d2 Containers3 ``` -------------------------------- ### D2 Globs Introduction Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/globs.md Introduces the basic concept and syntax of D2 globs for applying global changes to diagram elements. This is a foundational example for understanding how globs work. ```d2 { GlobsIntro } ``` -------------------------------- ### Unaligned Grid Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/grid-diagrams.md Shows an example of an unaligned grid, where elements might not perfectly align due to specific configurations or lack of explicit alignment properties. ```d2 import GridUnaligned from '@site/static/d2/grid-unaligned.d2'; ``` -------------------------------- ### D2 소스 파일로 설치 Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/install.md Go 언어를 사용하여 D2를 소스 파일로부터 직접 설치합니다. ```go go install oss.terrastruct.com/d2 ``` -------------------------------- ### D2 CLI: List Available Layouts Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/layouts.md Command to list all available layout engines supported by D2 on the current system. ```bash d2 layout ``` -------------------------------- ### List Available Themes Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/themes.md Command to display all available themes that can be used with D2. ```shell d2 themes ``` -------------------------------- ### Verify TALA Installation and D2 Integration Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Checks if the TALA binary is installed and accessible in the system's PATH, and verifies that D2 can locate and use TALA as a layout engine. ```sh d2plugin-tala --version d2 layout tala ``` -------------------------------- ### TALA Introduction Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md An introduction to TALA (Terrastruct's AutoLayout Approach), a proprietary layout engine for software architecture diagrams written in Go. It details TALA's multi-algorithm approach and encourages user feedback via GitHub and Discord. ```go // TALA is comprised of many algorithms in multiple stages. // It identifies parts of the diagram that are structurally like trees, or hierarchies, clusters, etc, // and runs different algorithms for each. // We used a combination of ideas from the decades of research done in the field of graph visualization, // with modifications and new additions to tailor it to software architecture diagrams. ``` -------------------------------- ### Tax Diagram Example Source: https://github.com/silverbullet069/d2-docs/blob/master/blog/animation.md Demonstrates embedding a D2-generated SVG diagram for visualizing tax-related information. This example highlights the use of D2 for creating clear and structured diagrams. ```javascript require('@site/static/img/generated/tax.svg2') ``` -------------------------------- ### Clone Repositories and Prepare D2 Files for Comparison Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/version-visualization.md Shell commands to clone two different Git repositories (apple/team-alpha and apple/team-charlie) and copy their respective `schema.d2` and `api.d2` files. These prepared files can then be imported into a D2 diagram for comparative analysis. ```Shell gh repo clone apple/team-alpha gh repo clone apple/team-charlie cp apple/team-alpha/schema.d2 alpha-schema.d2 cp apple/team-charlie/schema.d2 charlie-schema.d2 cp apple/team-alpha/api.d2 alpha-api.d2 cp apple/team-charlie/api.d2 charlie-api.d2 ``` -------------------------------- ### D2 Globs: Recursive Targeting Example 2 Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/globs.md Provides a second example of recursive globs in D2, further illustrating how the `**` pattern can be used to match elements in a hierarchical manner, particularly in connection definitions. ```d2 { GlobsRecursive2 } ``` -------------------------------- ### D2 플러그인 시스템 Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/future.md D2의 플러그인 시스템을 통해 사용자는 D2 컴파일 과정의 여러 단계에 '훅(hooks)'을 추가할 수 있습니다. 이를 통해 스타일이 있는 테두리 추가, 사용자 서명/크레딧 추가, 대비 증가 등 다양한 사용자 정의 기능을 구현할 수 있습니다. ```APIDOC D2 Plugin System: Functionality: - Allows users to add 'hooks' at various stages of the D2 compilation process. - Enables extension of D2's core features. Capabilities: - Adding styled borders. - Including user signatures or credits. - Increasing contrast for accessibility. - Implementing custom transformations during compilation. Example Use Cases: - Customizing visual styles beyond default options. - Automating the addition of metadata to diagrams. - Enhancing accessibility features. ``` -------------------------------- ### D2 설치 스크립트 실행 Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/install.md D2 설치 스크립트를 다운로드하고 실행하여 D2를 설치합니다. `--dry-run` 옵션을 사용하여 설치 전에 실행될 명령어를 확인할 수 있습니다. 설치 제거 시에도 동일한 스크립트를 사용합니다. ```shell curl -fsSL https://d2lang.com/install.sh | sh -s -- --dry-run curl -fsSL https://d2lang.com/install.sh | sh -s -- curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall ``` -------------------------------- ### Move Example Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md Illustrates moving elements between containers, including moving an element out of a container, back into it, and into a different container. Demonstrates renaming by moving within the same scope. ```go g, _, _ := d2oracle.Create(g, "a.b.c -> x.y.z") // Move c out of b into a g, _ = d2oracle.Move(g, "a.b.c", "a.c") // Move c back into b g, _ = d2oracle.Move(g, "a.c", "a.b.c") // Move c into x.y.z g, _ = d2oracle.Move(g, "a.b.c", "x.y.z.c") ``` -------------------------------- ### D2 Connection Class Application Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/classes.md Shows how to apply a class to a connection in D2, both during initial declaration and afterwards. ```d2 a -> b: { class: something } # Targeting after declaration (a -> b)[0].class: something ``` -------------------------------- ### D2 Full UML Class Diagram Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/uml-classes.md A comprehensive example showcasing the full capabilities of D2 for creating complex UML Class diagrams, including various visibilities, methods, and types. ```d2 Classes3 ``` -------------------------------- ### Pizza Diagram Example Source: https://github.com/silverbullet069/d2-docs/blob/master/blog/animation.md Shows the embedding of a D2-generated SVG diagram, possibly representing a pizza or a process related to it. This example further emphasizes D2's capability in creating diverse visual content. ```javascript require('@site/static/img/generated/pizza.svg2') ``` -------------------------------- ### D2 Step Inheritance Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/steps.md Demonstrates how D2 steps inherit properties from preceding steps. In this example, 'Approach road' is implicitly defined in Step 3 due to inheritance from Step 2 and Step 1. ```d2 { direction: right } Step: 1 A: "Start" B: "Middle" Step: 2 C: "End" Step: 3 D: "Approach road" ``` -------------------------------- ### D2 구성 가능한 린터 구축 계획 Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/future.md 코드의 일관성과 품질을 유지하기 위해 사용자가 설정할 수 있는 린터를 구축할 계획입니다. 이를 통해 개발자는 자신의 코딩 스타일과 규칙에 맞춰 코드를 검사하고 수정할 수 있습니다. ```APIDOC D2 Configurable Linter (Planned): Purpose: - To maintain code consistency and quality. - To allow users to enforce their own coding styles and rules. Functionality: - User-configurable linting rules. - Code analysis to identify and suggest corrections for style violations. - Integration into the development workflow for real-time feedback. Benefits: - Ensures adherence to project-specific coding standards. - Improves the maintainability and readability of D2 diagrams. ``` -------------------------------- ### D2 Grid Padding Troubleshooting Example 1 Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/grid-diagrams.md Shows an example where extra padding appears in a grid cell due to differing element label lengths. This highlights the automatic width adjustment in grid columns. ```d2 grid:{ "Backend Node":{ } "Next Pod":{ } "Flask Pod":{ } } ``` -------------------------------- ### D2 기본 사용법 Source: https://github.com/silverbullet069/d2-docs/blob/master/i18n/ko/docusaurus-plugin-content-docs/current/tour/install.md 간단한 D2 코드를 작성하고 SVG 파일로 렌더링하는 방법을 보여줍니다. `-w` 옵션을 사용하면 파일 변경 시 자동으로 새로고침되는 로컬 웹 서버가 실행됩니다. ```shell echo 'x -> y' > input.d2 d2 -w input.d2 out.svg ``` -------------------------------- ### Comprehensive UML Class Diagram Example in D2 Source: https://github.com/silverbullet069/d2-docs/blob/master/llms-full.md A detailed example showcasing multiple interconnected classes (DebitCard, Bank, ATMInfo, Customer, Account, etc.) with various fields, methods, and relationships, including cardinality and inheritance. ```d2 DebitCard: Debit card { shape: class +cardno +ownedBy +access() } Bank: { shape: class +code +address +manages() +maintains() } ATMInfo: ATM info { shape: class +location +manageBy +identifies() +transactions() } Customer: { shape: class +name +address +dob +owns() } Account: { shape: class +type +owner } ATMTransaction: ATM Transaction { shape: class +transactionId +date +type +modifies() } CurrentAccount: Current account { shape: class +accountNo +balance +debit() +credit() } SavingAccount: Saving account { shape: class +accountNo +balance +debit() +credit() } WidthdrawlTransaction: Withdrawl transaction { shape: class +amount +Withdrawl() } QueryTransaction: Query transaction { shape: class +query +type +queryProcessing() } TransferTransaction: Transfer transaction { shape: class +account +accountNo } PinValidation: Pin validation transaction { shape: class +oldPin +newPin +pinChange() } DebitCard -- Bank: manages { source-arrowhead: 1..* target-arrowhead: 1 } Bank -- ATMInfo: maintains { source-arrowhead: 1 target-arrowhead: 1 } Bank -- Customer: +has { source-arrowhead: 1 target-arrowhead: 1 } DebitCard -- Customer: +owns { source-arrowhead: 0..* target-arrowhead: 1..* } DebitCard -- Account: +provides access to { source-arrowhead: * target-arrowhead: 1..* } Customer -- Account: owns { source-arrowhead: 1..* target-arrowhead: 1..* } ATMInfo -- ATMTransaction: +identifies { source-arrowhead: 1 target-arrowhead: * } ATMTransaction -> Account: modifies { source-arrowhead: * target-arrowhead: 1 } CurrentAccount -> Account: { target-arrowhead.shape: triangle target-arrowhead.style.filled: false } SavingAccount -> Account: { target-arrowhead.shape: triangle target-arrowhead.style.filled: false } WidthdrawlTransaction -> ATMTransaction: { target-arrowhead.shape: triangle target-arrowhead.style.filled: false } QueryTransaction -> ATMTransaction: { target-arrowhead.shape: triangle target-arrowhead.style.filled: false } TransferTransaction -> ATMTransaction: { target-arrowhead.shape: triangle target-arrowhead.style.filled: false } PinValidation -> ATMTransaction: { target-arrowhead.shape: triangle target-arrowhead.style.filled: false } ``` -------------------------------- ### Preview D2 Documentation Translations Source: https://github.com/silverbullet069/d2-docs/blob/master/README.md This command starts the development server for the D2 documentation, specifically configured to preview content in a specified locale, such as Korean ('ko'). This is useful for reviewing and verifying translation efforts before deployment. ```sh yarn dev --locale ko ``` -------------------------------- ### Example SQL Table Diagram with Nesting Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/sql-tables.md Presents a more complex example of SQL table diagrams, including nesting tables within containers and defining edges between them, showcasing D2's flexibility in diagramming complex relationships. ```d2 container: { User: sql_table { id: int { constraint: primary_key } name: string email: string } Post: sql_table { id: int { constraint: primary_key } title: string user_id: int { constraint: foreign_key } } User -> Post: { label: "writes" } } ``` -------------------------------- ### D2 Plugin System Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/future.md Illustrates the extensibility of D2 through its plugin system. Plugins can hook into different stages of the D2 compilation process to modify diagrams, such as adding borders, signatures, or adjusting contrast for accessibility. ```d2 // Hypothetical plugin usage example: // This is conceptual and not actual D2 code. // A plugin might be configured like this: // d2 compile --plugin hand-drawn --plugin signature --plugin accessibility input.d2 output.svg ``` -------------------------------- ### D2 CLI Formatting Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.0.md Formats D2 scripts using the `fmt` subcommand. Refer to `man d2` or `d2 --help` for detailed usage instructions. ```bash d2 fmt ``` -------------------------------- ### Spread Import Example Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/imports.md Illustrates a spread import, where the contents of an imported file are merged into a map. ```d2-incomplete x: { shape: circle } ``` ```d2-incomplete a: { ...@x.d2 } a -> b ``` -------------------------------- ### Initialize Git Submodules Source: https://github.com/silverbullet069/d2-docs/blob/master/README.md Updates and initializes Git submodules required for the project development. ```sh git submodule update --init ``` -------------------------------- ### D2 Install Script Dry Run Alias Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/releases/0.1.0.md The `install.sh` script now accepts `-d` as an alias for `--dry-run`. ```bash ./install.sh -d ``` -------------------------------- ### Export to PNG Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/exports.md Exports a D2 diagram to a PNG file using Playwright. Requires Playwright and its dependencies to be installed. ```shell d2 in.d2 out.png ``` -------------------------------- ### Cloning Repositories and Copying D2 Files Source: https://github.com/silverbullet069/d2-docs/blob/master/docs/tour/version-visualization.md Shell commands to clone repositories for different teams and copy their respective schema and API D2 files for comparison. ```sh gh repo clone apple/team-alpha gh repo clone apple/team-charlie cp apple/team-alpha/schema.d2 alpha-schema.d2 cp apple/team-charlie/schema.d2 charlie-schema.d2 cp apple/team-alpha/api.d2 alpha-api.d2 cp apple/team-charlie/api.d2 charlie-api.d2 ```