diff --git a/docs/tour/overrides.md b/docs/tour/overrides.md index 01da0536..afd72516 100644 --- a/docs/tour/overrides.md +++ b/docs/tour/overrides.md @@ -33,3 +33,76 @@ aws_s3: "AWS S3 San Francisco, California" { ```
+ +## Null + +You may override with the value `null` to delete the shape/connection/attribute. + +```d2 +one +two + +one: null +``` + + + +When is this useful? +- [Import](/tour/imports) a diagram from a colleague and remove the things you don't want. +- [Multi-board compositions](/tour/composition) where you inherit all the objects from a + board with some exceptions. +- (Coming soon) Use globs to define connections between a batch of objects except one in + particular you want to leave out. + +### Nulling a connection + +```d2 +one -> two + +(one -> two)[0]: null +``` + + + +### Nulling an attribute + +```d2 +one: { + style: { + fill: pink + stroke: green + } +} + +one.style.stroke: null +``` + + + + +### Implicit nulls + +If you null a shape with connections, its connections are also nulled (since every +connection in D2 needs an endpoint). + +```d2 +one -> two + +two: null +``` + + + +If you null a shape with descendents, those descendants are also nulled. + +```d2 +one: { + two: { + three + } +} + +one.two: null +``` + + diff --git a/static/d2/null-attribute.d2 b/static/d2/null-attribute.d2 new file mode 100644 index 00000000..e52b5311 --- /dev/null +++ b/static/d2/null-attribute.d2 @@ -0,0 +1,8 @@ +one: { + style: { + fill: pink + stroke: green + } +} + +one.style.stroke: null diff --git a/static/d2/null-basic.d2 b/static/d2/null-basic.d2 new file mode 100644 index 00000000..bd4f7f82 --- /dev/null +++ b/static/d2/null-basic.d2 @@ -0,0 +1,4 @@ +one +two + +one: null diff --git a/static/d2/null-connection.d2 b/static/d2/null-connection.d2 new file mode 100644 index 00000000..e11aaf16 --- /dev/null +++ b/static/d2/null-connection.d2 @@ -0,0 +1,3 @@ +one -> two + +(one -> two)[0]: null diff --git a/static/d2/null-implicit-connection.d2 b/static/d2/null-implicit-connection.d2 new file mode 100644 index 00000000..129c774b --- /dev/null +++ b/static/d2/null-implicit-connection.d2 @@ -0,0 +1,3 @@ +one -> two + +two: null diff --git a/static/d2/null-implicit-descendant.d2 b/static/d2/null-implicit-descendant.d2 new file mode 100644 index 00000000..714cc5a4 --- /dev/null +++ b/static/d2/null-implicit-descendant.d2 @@ -0,0 +1,7 @@ +one: { + two: { + three + } +} + +one.two: null diff --git a/static/img/generated/null-attribute.svg2 b/static/img/generated/null-attribute.svg2 new file mode 100644 index 00000000..f136b493 --- /dev/null +++ b/static/img/generated/null-attribute.svg2 @@ -0,0 +1,167 @@ + diff --git a/static/img/generated/null-basic.svg2 b/static/img/generated/null-basic.svg2 new file mode 100644 index 00000000..b0d6a984 --- /dev/null +++ b/static/img/generated/null-basic.svg2 @@ -0,0 +1,167 @@ +