d2/docs/examples/lib
2022-12-11 23:39:21 -08:00
..
1-d2lib add pad option 2022-12-11 23:39:21 -08:00
2-d2oracle Move textmeasure into lib 2022-12-01 06:51:17 -08:00
3-lowlevel add pad option 2022-12-11 23:39:21 -08:00
README.md README: Cleanup examples to make them runnable and testable 2022-11-30 22:54:47 -08:00

D2 library examples

We have a few examples in this directory on how to use the D2 library to turn D2 scripts into rendered svg diagrams and more.

Each example is runnable though does not include error handling for readability.

./1-d2lib

A minimal example showing you how to compile the diagram x -> y into an svg.

./2-d2oracle

D2 is built to be hackable -- the language has an API built on top of it to make edits programmatically.

Modifying the previous example, this example demonstrates how d2oracle can be used to create a new shape, style it programatically and then output the modified d2 script.

This makes it easy to build functionality on top of D2. Terrastruct uses the d2oracle API to implement editing of D2 from mouse actions in a visual interface.

./3-lowlevel

d2lib from the first example is just a wrapper around the lower level APIs. They can be used directly and this example demonstrates such usage.

This shouldn't be necessary for most usecases.