From 0c0e7d6134a45acd72a3052e2dc7c6b47e9acd88 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 14:08:56 -0800 Subject: [PATCH 1/8] set and replace position and dimensions --- d2oracle/edit.go | 20 +++ d2oracle/edit_test.go | 48 ++++++ .../TestSet/replace_dimensions.exp.json | 147 ++++++++++++++++++ .../d2oracle/TestSet/set_dimensions.exp.json | 147 ++++++++++++++++++ .../d2oracle/TestSet/set_position.exp.json | 147 ++++++++++++++++++ 5 files changed, 509 insertions(+) create mode 100644 testdata/d2oracle/TestSet/replace_dimensions.exp.json create mode 100644 testdata/d2oracle/TestSet/set_dimensions.exp.json create mode 100644 testdata/d2oracle/TestSet/set_position.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 3537677b3..fb63fd419 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -234,6 +234,26 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { attrs.Shape.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } + case "width": + if attrs.Width != nil && attrs.Width.MapKey != nil { + attrs.Width.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } + case "height": + if attrs.Height != nil && attrs.Height.MapKey != nil { + attrs.Height.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } + case "top": + if attrs.Top != nil && attrs.Top.MapKey != nil { + attrs.Top.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } + case "left": + if attrs.Left != nil && attrs.Left.MapKey != nil { + attrs.Left.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } case "style": if len(mk.Key.Path[reservedIndex:]) != 2 { return errors.New("malformed style setting, expected 2 part path") diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 6dd62ffec..d01f44b5e 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -695,6 +695,54 @@ square.style.opacity: 0.2 } }, }, + { + name: "set_position", + text: `square +`, + key: `square.top`, + value: go2.Pointer(`200`), + exp: `square: {top: 200} +`, + }, + { + name: "replace_position", + text: `square: { + width: 100 + top: 32 + left: 44 +} +`, + key: `square.top`, + value: go2.Pointer(`200`), + exp: `square: { + width: 100 + top: 200 + left: 44 +} +`, + }, + { + name: "set_dimensions", + text: `square +`, + key: `square.width`, + value: go2.Pointer(`200`), + exp: `square: {width: 200} +`, + }, + { + name: "replace_dimensions", + text: `square: { + width: 100 +} +`, + key: `square.width`, + value: go2.Pointer(`200`), + exp: `square: { + width: 200 +} +`, + }, { name: "label_unset", text: `square: "Always try to do things in chronological order; it's less confusing that way." diff --git a/testdata/d2oracle/TestSet/replace_dimensions.exp.json b/testdata/d2oracle/TestSet/replace_dimensions.exp.json new file mode 100644 index 000000000..cfb65d1c3 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_dimensions.exp.json @@ -0,0 +1,147 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-3:0:25", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-2:1:24", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:8:8-2:0:23", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:2:12-1:12:22", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:2:12-1:7:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:2:12-1:7:17", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,1:9:19-1:12:22", + "raw": "200", + "value": "200" + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "square", + "id_val": "square", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_dimensions.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "square" + }, + "style": {}, + "width": { + "value": "200" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/set_dimensions.exp.json b/testdata/d2oracle/TestSet/set_dimensions.exp.json new file mode 100644 index 000000000..073461ca1 --- /dev/null +++ b/testdata/d2oracle/TestSet/set_dimensions.exp.json @@ -0,0 +1,147 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-1:0:21", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:20:20", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:8:8-0:19:19", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:9:9-0:19:19", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:9:9-0:14:14", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:9:9-0:14:14", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:16:16-0:19:19", + "raw": "200", + "value": "200" + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "square", + "id_val": "square", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_dimensions.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "square" + }, + "style": {}, + "width": { + "value": "200" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/set_position.exp.json b/testdata/d2oracle/TestSet/set_position.exp.json new file mode 100644 index 000000000..321da083b --- /dev/null +++ b/testdata/d2oracle/TestSet/set_position.exp.json @@ -0,0 +1,147 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-1:0:19", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:18:18", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:8:8-0:17:17", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:9:9-0:17:17", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:9:9-0:12:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:9:9-0:12:12", + "value": [ + { + "string": "top", + "raw_string": "top" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:14:14-0:17:17", + "raw": "200", + "value": "200" + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "square", + "id_val": "square", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_position.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "square" + }, + "style": {}, + "top": { + "value": "200" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From d31c7e37bbbd9dd82a6e636cac0dd13543bb5e00 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 14:10:10 -0800 Subject: [PATCH 2/8] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index e07c71298..7519eeeca 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -7,6 +7,7 @@ - Cleaner watch mode logs without timestamps. [830](https://github.com/terrastruct/d2/pull/830) - `near` key set to direct parent or ancestor throws an appropriate error message. [#851](https://github.com/terrastruct/d2/pull/851) +- Dimensions and positions are able to be set from API. [#853](https://github.com/terrastruct/d2/pull/853) #### Bugfixes ⛑️ From 2951a7d8780d88ec87bcc3bed69092d8c6fecba8 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 18:52:00 -0800 Subject: [PATCH 3/8] test --- .../TestSet/replace_position.exp.json | 211 ++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 testdata/d2oracle/TestSet/replace_position.exp.json diff --git a/testdata/d2oracle/TestSet/replace_position.exp.json b/testdata/d2oracle/TestSet/replace_position.exp.json new file mode 100644 index 000000000..8a0cfec54 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_position.exp.json @@ -0,0 +1,211 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-5:0:47", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-4:1:46", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:8:8-4:0:45", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:2:12-1:12:22", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:2:12-1:7:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:2:12-1:7:17", + "value": [ + { + "string": "width", + "raw_string": "width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,1:9:19-1:12:22", + "raw": "100", + "value": "100" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:2:25-2:10:33", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:2:25-2:5:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:2:25-2:5:28", + "value": [ + { + "string": "top", + "raw_string": "top" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,2:7:30-2:10:33", + "raw": "200", + "value": "200" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:2:36-3:10:44", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:2:36-3:6:40", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:2:36-3:6:40", + "value": [ + { + "string": "left", + "raw_string": "left" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,3:8:42-3:10:44", + "raw": "44", + "value": "44" + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "square", + "id_val": "square", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_position.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "square" + }, + "style": {}, + "width": { + "value": "100" + }, + "top": { + "value": "200" + }, + "left": { + "value": "44" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From aa49c9c1b8474e5bbcb0baa664408a9a546135fd Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 19:38:49 -0800 Subject: [PATCH 4/8] update contributing --- docs/CONTRIBUTING.md | 78 ++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 9c3fb421d..1ae29d85f 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -1,8 +1,8 @@ # Contributing +- Welcome - CI -- Flow - Logistics - Dev - Content @@ -10,12 +10,46 @@ - Documentation - Questions +## Welcome + +D2's [long-term mission](https://d2lang.com/tour/future/) is to significantly reduce the +amount of time and effort it takes to create and maintain high-quality diagrams for every +software team. We started this because we love the idea of creating diagrams with text -- +but it was clear the existing solutions were inadequete in their state and speed of +execution for this idea to be mainstream. + +We've tried our best to avoid the mistakes of the past and take inspiration from the most +successful modern programming and configuration languages. + +D2 has built up each step of the text-to-diagram pipeline from scratch, rethinking each +one from first principles, from the dead simple syntax, to the readable compiler, our own +SVG renderer, etc. + +D2 is committed to making something people want to use. That means contributions don't +only have to be in the form of pull requests. Your bug reports, plugins, examples, +discussions of new ideas, help a great deal. + +If you'd like to get involved, we're also committed to helping you merge that first +pull request. You should be able to freely pick up Issues tagged as "good first issue". If +you need help getting started, please don't hesitate to pop into Discord -- if you want to +help, I'm sure we'll find the perfect task (complexity matches your appetite and +programming experience, in an area you're interested in, etc). + ## CI Most of D2's CI is open sourced in its own -[repository](https://github.com/terrastruct/ci). You can find commands in the Github -workflows. E.g. run `./make.sh fmt` to run the formatter. Please make sure all CI is -passing for any PRs. +[repository](https://github.com/terrastruct/ci). + +`./make.sh` runs everything. Subcommands to run individual parts of the CI: + +- `./make.sh fmt` +- `./make.sh lint` +- `./make.sh test` +- `./make.sh race` +- `./make.sh build` + + +Please make sure CI is passing for any PRs submitted for review. Most of the CI scripts rely on a submodule shared between many D2 repositories: [https://github.com/terrastruct/ci](https://github.com/terrastruct/ci). You should fetch @@ -31,21 +65,14 @@ If running for the first time for a repo (e.g. new clone), add `--init`: git submodule update --init --recursive ``` -## Flow - -The simplified D2 flow at a package level looks like: - -D2 flow - ## Logistics - Use Go 1.18. Go 1.19's autofmt inexplicably strips spacing from ASCII art in comments. + We're working on it. - Please sign your commits ([https://github.com/terrastruct/d2/pull/557#issuecomment-1367468730](https://github.com/terrastruct/d2/pull/557#issuecomment-1367468730)). - D2 uses Issues as TODOs. No auto-closing on staleness. - Branch off `master`. -- Prefix pull request titles with a short descriptor of the domain, e.g. `d2renderer: Add - x`. - If there's an Issue related, include it by adding "[one-word] #[issue]", e.g. "Fixes #123" somewhere in the description. - Whenever possible and relevant, include a screenshot or screen-recording. @@ -54,25 +81,34 @@ The simplified D2 flow at a package level looks like: ### Content -Please choose an Issue with a "TODO" label. If you'd like to propose new functionality or -change to current functionality, please create an Issue first with a proposal. When you -start work on an Issue, please leave a comment so others know that it's being worked on. +Unless you've contributed before, it's safest to choose an Issue with a "good first issue" +label. If you'd like to propose new functionality or change to current functionality, +please create an Issue first with a proposal. When you start work on an Issue, please +leave a comment so others know that it's being worked on. ### Tests -All code changes must include tests. D2 mostly has functional tests, and uses -[diff](https://github.com/terrastruct/diff) as a framework that gives Git-style -comparisons of expected vs actual output for each stage. There are ample examples in each -package of this -- try changing some test and run it to see. +D2 has extensive tests, and all code changes must include tests. With the exception of changes to the renderer, all code should include a package-specific -test. If it's a visual change, an e2e test should accompany. +test. If it's a visual change, an end-to-end (e2e) test should accompany. + +Let's say I make some code changes. I can easily see how this affects the end result by +running: + +``` +./ci/e2ereport.sh -delta +``` + +This gives me a nice HMTL output of what the test expected vs what it got: + +![screencapture-file-Users-alexanderwang-dev-alixander-d2-e2etests-out-e2e-report-html-2023-02-14-10_15_07](https://user-images.githubusercontent.com/3120367/218822836-bcc517f2-ae3e-4e0d-83f6-2cbaa2fd9275.png) If you're testing labels and strings, it's encouraged to use 1-letter strings (`x`) in small functional tests to minimally pinpoint issues. If you are testing something that exercises variations in strings, or want to mimic more realistic diagram text, it's encouraged you generate random strings and words from `fortune`. It gives a good range of the English -language. Sometimes it gives controversial sentences -- don't use those. +language. (Sometimes it gives controversial sentences -- don't use those.) Script to generate one line of random text: ``` From 95cf986928560dde98454af6fecad4983ef80669 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 19:45:21 -0800 Subject: [PATCH 5/8] update --- docs/CONTRIBUTING.md | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 1ae29d85f..20f84d078 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -16,29 +16,32 @@ D2's [long-term mission](https://d2lang.com/tour/future/) is to significantly re amount of time and effort it takes to create and maintain high-quality diagrams for every software team. We started this because we love the idea of creating diagrams with text -- but it was clear the existing solutions were inadequete in their state and speed of -execution for this idea to be mainstream. +execution for this idea to be widely usable. We've tried our best to avoid the mistakes of the past and take inspiration from the most -successful modern programming and configuration languages. - -D2 has built up each step of the text-to-diagram pipeline from scratch, rethinking each -one from first principles, from the dead simple syntax, to the readable compiler, our own -SVG renderer, etc. +successful modern programming and configuration languages. D2 has built up each step of +the text-to-diagram pipeline from scratch, rethinking each one from first principles, from +the dead simple syntax, to the readable compiler, our own SVG renderer, etc. D2 is committed to making something people want to use. That means contributions don't only have to be in the form of pull requests. Your bug reports, plugins, examples, discussions of new ideas, help a great deal. -If you'd like to get involved, we're also committed to helping you merge that first -pull request. You should be able to freely pick up Issues tagged as "good first issue". If -you need help getting started, please don't hesitate to pop into Discord -- if you want to -help, I'm sure we'll find the perfect task (complexity matches your appetite and +If you'd like to get involved, we're also committed to helping you merge that first pull +request. You should be able to freely pick up Issues tagged as "good first issue". If you +need help getting started, please don't hesitate to pop into Discord -- as long as you +want to help, we'll find the perfect task (complexity matches your appetite and programming experience, in an area you're interested in, etc). ## CI Most of D2's CI is open sourced in its own -[repository](https://github.com/terrastruct/ci). +[repository](https://github.com/terrastruct/ci), included as a submodule. After you clone +D2, make sure you initialize the submodules: + +```sh +git submodule update --init --recursive +``` `./make.sh` runs everything. Subcommands to run individual parts of the CI: @@ -51,20 +54,12 @@ Most of D2's CI is open sourced in its own Please make sure CI is passing for any PRs submitted for review. -Most of the CI scripts rely on a submodule shared between many D2 repositories: -[https://github.com/terrastruct/ci](https://github.com/terrastruct/ci). You should fetch -the submodule whenever it differs: +Be sure to update the submodule whenever there are changes: ```sh git submodule update --recursive ``` -If running for the first time for a repo (e.g. new clone), add `--init`: - -```sh -git submodule update --init --recursive -``` - ## Logistics - Use Go 1.18. Go 1.19's autofmt inexplicably strips spacing from ASCII art in comments. @@ -100,7 +95,8 @@ running: ./ci/e2ereport.sh -delta ``` -This gives me a nice HMTL output of what the test expected vs what it got: +This gives me a nice HMTL output of what the test expected vs what it got (this was a PR +fixing multi-byte character labels): ![screencapture-file-Users-alexanderwang-dev-alixander-d2-e2etests-out-e2e-report-html-2023-02-14-10_15_07](https://user-images.githubusercontent.com/3120367/218822836-bcc517f2-ae3e-4e0d-83f6-2cbaa2fd9275.png) From eac0c5361027a38ccabae0ad97203500361083d2 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 19:48:16 -0800 Subject: [PATCH 6/8] Update CONTRIBUTING.md --- docs/CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 20f84d078..8f2cc1917 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -51,6 +51,10 @@ git submodule update --init --recursive - `./make.sh race` - `./make.sh build` +Here's what a successful run should look like: + +Screen Shot 2023-02-19 at 7 46 34 PM + Please make sure CI is passing for any PRs submitted for review. From b40eb5a4d86497dc151085e16715e55cfe9a13db Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 21:33:37 -0800 Subject: [PATCH 7/8] d2oracle: delete dimensions and positions --- d2oracle/edit.go | 4 + d2oracle/edit_test.go | 24 +++++ testdata/d2oracle/TestDelete/left.exp.json | 109 ++++++++++++++++++++ testdata/d2oracle/TestDelete/width.exp.json | 109 ++++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 testdata/d2oracle/TestDelete/left.exp.json create mode 100644 testdata/d2oracle/TestDelete/width.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index fb63fd419..8813755bf 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -687,6 +687,10 @@ func deleteReserved(g *d2graph.Graph, mk *d2ast.Key) (*d2graph.Graph, error) { if id == "near" || id == "tooltip" || id == "icon" || + id == "width" || + id == "height" || + id == "left" || + id == "top" || id == "link" { err := deleteObjField(g, obj, id) if err != nil { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index d01f44b5e..f6dc0cf3a 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -4507,6 +4507,30 @@ A -> B: {style.stroke: "#2b50c2"} exp: `A: {style.stroke: "#000e3d"} B A -> B +`, + }, + { + name: "width", + + text: `x: { + width: 200 +} +`, + key: `x.width`, + + exp: `x +`, + }, + { + name: "left", + + text: `x: { + left: 200 +} +`, + key: `x.left`, + + exp: `x `, }, } diff --git a/testdata/d2oracle/TestDelete/left.exp.json b/testdata/d2oracle/TestDelete/left.exp.json new file mode 100644 index 000000000..0be52a3ad --- /dev/null +++ b/testdata/d2oracle/TestDelete/left.exp.json @@ -0,0 +1,109 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-1:0:2", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/left.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestDelete/width.exp.json b/testdata/d2oracle/TestDelete/width.exp.json new file mode 100644 index 000000000..c1c010bcb --- /dev/null +++ b/testdata/d2oracle/TestDelete/width.exp.json @@ -0,0 +1,109 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-1:0:2", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/width.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From 16679e8d6950d5ce6c79de1b665b2284167bf4f4 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 19 Feb 2023 22:24:10 -0800 Subject: [PATCH 8/8] [ci-base] update contributing --- docs/CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 8f2cc1917..c074c4235 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -104,6 +104,8 @@ fixing multi-byte character labels): ![screencapture-file-Users-alexanderwang-dev-alixander-d2-e2etests-out-e2e-report-html-2023-02-14-10_15_07](https://user-images.githubusercontent.com/3120367/218822836-bcc517f2-ae3e-4e0d-83f6-2cbaa2fd9275.png) +Run `./ci/e2ereport.sh -help` for flags, including how to get deltas for a single test. + If you're testing labels and strings, it's encouraged to use 1-letter strings (`x`) in small functional tests to minimally pinpoint issues. If you are testing something that exercises variations in strings, or want to mimic more realistic diagram text, it's encouraged you