From 288b2927660eb7e707ef5f88e4932318f0214855 Mon Sep 17 00:00:00 2001 From: delfino Date: Fri, 14 Feb 2025 22:47:32 +0000 Subject: [PATCH] updating readme --- ci/release/changelogs/next.md | 2 +- d2js/js/README.md | 37 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 908542d89..f152d8600 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -2,6 +2,6 @@ #### Improvements 🧹 -d2js: Support additional render options (`themeID`, `darkThemeID`, `center`, `pad`, `scale` and `forceAppendix`) [#2343](https://github.com/terrastruct/d2/pull/2343) +d2js: Support additional render options (`themeID`, `darkThemeID`, `center`, `pad`, `scale` and `forceAppendix`). Support `d2-config`. [#2343](https://github.com/terrastruct/d2/pull/2343) #### Bugfixes ⛑️ diff --git a/d2js/js/README.md b/d2js/js/README.md index 4e3c80d23..4c474e85a 100644 --- a/d2js/js/README.md +++ b/d2js/js/README.md @@ -42,19 +42,44 @@ import { D2 } from '@terrastruct/d2'; const d2 = new D2(); const result = await d2.compile('x -> y'); -const svg = await d2.render(result.diagram); +const svg = await d2.render(result.diagram, result.options); +``` + +Additional Configuration: + +```javascript +import { D2 } from '@terrastruct/d2'; + +const d2 = new D2(); + +const result = await d2.compile('x -> y', { + sketch = true, +}); +const svg = await d2.render(result.diagram, result.options); ``` ## API Reference ### `new D2()` + Creates a new D2 instance. ### `compile(input: string, options?: CompileOptions): Promise` + Compiles D2 markup into an intermediate representation. -Options: +### `render(diagram: Diagram, options?: RenderOptions): Promise` + +Renders a compiled diagram to SVG. + +### `CompileOptions` + +All `RenderOptions` properties in addition to: + - `layout`: Layout engine to use ('dagre' | 'elk') [default: 'dagre'] + +### `RenderOptions` + - `sketch`: Enable sketch mode [default: false] - `themeID`: Theme ID to use [default: 0] - `darkThemeID`: Theme ID to use when client is in dark mode @@ -63,8 +88,12 @@ Options: - `scale`: Scale the output. E.g., 0.5 to halve the default size. The default will render SVG's that will fit to screen. Setting to 1 turns off SVG fitting to screen. - `forceAppendix`: Adds an appendix for tooltips and links [default: false] -### `render(diagram: Diagram, options?: RenderOptions): Promise` -Renders a compiled diagram to SVG. +### `CompileResult` + +- `diagram`: `Diagram`: Compiled D2 diagram +- `options`: `RenderOptions`: Render options merged with configuration set in diagram +- `fs` +- `graph` ## Development