Skip to content

Commit

Permalink
add grid tip
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed May 20, 2024
1 parent 512f660 commit 664aafa
Show file tree
Hide file tree
Showing 5 changed files with 428 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/tour/grid-diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import GridDimensions from '@site/static/d2/grid-dimensions.d2';
import GridFill from '@site/static/d2/grid-fill.d2';
import GridNestedGrid from '@site/static/d2/grid-nested-grid.d2';
import Table from '@site/static/d2/table.d2';
import GridUnaligned from '@site/static/d2/grid-unaligned.d2';
import GridAligned from '@site/static/d2/grid-aligned.d2';

# Grid Diagrams

Expand Down Expand Up @@ -168,6 +170,27 @@ soon.

<div className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/grid-nested-grid.svg2')}}></div>

## Aligning with invisible elements

A common technique to align grid elements to your liking is to pad the grid with invisible
elements.

Consider the following diagram.

<CodeBlock className="language-d2">
{GridUnaligned}
</CodeBlock>

<div className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/grid-unaligned.svg2')}}></div>

It'd be nicer if it were centered. This can be achieved by adding 2 invisible elements.

<CodeBlock className="language-d2">
{GridAligned}
</CodeBlock>

<div className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/grid-aligned.svg2')}}></div>

## Source code

This is the script for the image at the top of this page.
Expand Down
27 changes: 27 additions & 0 deletions static/d2/grid-aligned.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
classes: {
invisible: {
style.opacity: 0
label: a
}
}

grid-columns: 1
us-east-1: {
grid-rows: 1
a
b
c
d
e
}

us-west-1: {
grid-rows: 1
pad1.class: invisible
pad2.class: invisible
a
# Move the label so it doesn't go through the connection
label.near: bottom-center
}

us-east-1.c -> us-west-1.a
16 changes: 16 additions & 0 deletions static/d2/grid-unaligned.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
grid-columns: 1
us-east-1: {
grid-rows: 1
a
b
c
d
e
}

us-west-1: {
grid-rows: 1
a
}

us-east-1.c -> us-west-1.a
Loading

0 comments on commit 664aafa

Please sign in to comment.