Skip to content

Commit a0cf09d

Browse files
authored
Merge pull request terrastruct#217 from terrastruct/grid-inv
add grid tip
2 parents 512f660 + 664aafa commit a0cf09d

File tree

5 files changed

+428
-0
lines changed

5 files changed

+428
-0
lines changed

docs/tour/grid-diagrams.md

+23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import GridDimensions from '@site/static/d2/grid-dimensions.d2';
77
import GridFill from '@site/static/d2/grid-fill.d2';
88
import GridNestedGrid from '@site/static/d2/grid-nested-grid.d2';
99
import Table from '@site/static/d2/table.d2';
10+
import GridUnaligned from '@site/static/d2/grid-unaligned.d2';
11+
import GridAligned from '@site/static/d2/grid-aligned.d2';
1012

1113
# Grid Diagrams
1214

@@ -168,6 +170,27 @@ soon.
168170

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

173+
## Aligning with invisible elements
174+
175+
A common technique to align grid elements to your liking is to pad the grid with invisible
176+
elements.
177+
178+
Consider the following diagram.
179+
180+
<CodeBlock className="language-d2">
181+
{GridUnaligned}
182+
</CodeBlock>
183+
184+
<div className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/grid-unaligned.svg2')}}></div>
185+
186+
It'd be nicer if it were centered. This can be achieved by adding 2 invisible elements.
187+
188+
<CodeBlock className="language-d2">
189+
{GridAligned}
190+
</CodeBlock>
191+
192+
<div className="embedSVG" dangerouslySetInnerHTML={{__html: require('@site/static/img/generated/grid-aligned.svg2')}}></div>
193+
171194
## Source code
172195

173196
This is the script for the image at the top of this page.

static/d2/grid-aligned.d2

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
classes: {
2+
invisible: {
3+
style.opacity: 0
4+
label: a
5+
}
6+
}
7+
8+
grid-columns: 1
9+
us-east-1: {
10+
grid-rows: 1
11+
a
12+
b
13+
c
14+
d
15+
e
16+
}
17+
18+
us-west-1: {
19+
grid-rows: 1
20+
pad1.class: invisible
21+
pad2.class: invisible
22+
a
23+
# Move the label so it doesn't go through the connection
24+
label.near: bottom-center
25+
}
26+
27+
us-east-1.c -> us-west-1.a

static/d2/grid-unaligned.d2

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
grid-columns: 1
2+
us-east-1: {
3+
grid-rows: 1
4+
a
5+
b
6+
c
7+
d
8+
e
9+
}
10+
11+
us-west-1: {
12+
grid-rows: 1
13+
a
14+
}
15+
16+
us-east-1.c -> us-west-1.a

0 commit comments

Comments
 (0)