From 1658c05f18d4a1e95e020cfb26fc749a3cd7474d Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Fri, 17 Mar 2023 19:13:14 -0700 Subject: [PATCH 1/3] fix --- ci/release/changelogs/next.md | 2 + d2oracle/edit.go | 5 + d2oracle/edit_test.go | 21 +++ .../TestSet/replace_fill_pattern.exp.json | 164 ++++++++++++++++++ .../TestSet/set_fill_pattern.exp.json | 164 ++++++++++++++++++ 5 files changed, 356 insertions(+) create mode 100644 testdata/d2oracle/TestSet/replace_fill_pattern.exp.json create mode 100644 testdata/d2oracle/TestSet/set_fill_pattern.exp.json diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index f3c0d2a774..b87db01c1d 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -3,3 +3,5 @@ #### Improvements 🧹 #### Bugfixes ⛑️ + +- Fixes Fill Pattern replacement in the API. [#853](https://github.com/terrastruct/d2/pull/853) diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 7ec8eaefce..3891c35b80 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -433,6 +433,11 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { attrs.Style.Underline.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } + case "fill-pattern": + if attrs.Style.FillPattern != nil { + attrs.Style.FillPattern.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } } case "label": if attrs.Label.MapKey != nil { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 0d1e27f368..9322bf67cc 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -838,6 +838,27 @@ square.style.opacity: 0.2 style.stroke-width: 1 style.stroke-dash: 3 } +`, + }, + { + name: "set_fill_pattern", + text: `square`, + key: `square.style.fill-pattern`, + value: go2.Pointer(`grain`), + exp: `square: {style.fill-pattern: grain} +`, + }, + { + name: "replace_fill_pattern", + text: `square: { + style.fill-pattern: lines +} +`, + key: `square.style.fill-pattern`, + value: go2.Pointer(`grain`), + exp: `square: { + style.fill-pattern: grain +} `, }, { diff --git a/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json b/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json new file mode 100644 index 0000000000..37b84cf2a3 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json @@ -0,0 +1,164 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,0:0:0-3:0:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,0:0:0-2:1:39", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,0:8:8-2:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,1:2:12-1:27:37", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,1:2:12-1:20:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,1:2:12-1:7:17", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,1:8:18-1:20:30", + "value": [ + { + "string": "fill-pattern", + "raw_string": "fill-pattern" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,1:22:32-1:27:37", + "value": [ + { + "string": "grain", + "raw_string": "grain" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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_fill_pattern.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.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": { + "fillPattern": { + "value": "grain" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/set_fill_pattern.exp.json b/testdata/d2oracle/TestSet/set_fill_pattern.exp.json new file mode 100644 index 0000000000..b25ba4c58d --- /dev/null +++ b/testdata/d2oracle/TestSet/set_fill_pattern.exp.json @@ -0,0 +1,164 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:0:0-1:0:36", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:0:0-0:35:35", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:8:8-0:34:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:9:9-0:34:34", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:9:9-0:27:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:9:9-0:14:14", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:15:15-0:27:27", + "value": [ + { + "string": "fill-pattern", + "raw_string": "fill-pattern" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:29:29-0:34:34", + "value": [ + { + "string": "grain", + "raw_string": "grain" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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_fill_pattern.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.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": { + "fillPattern": { + "value": "grain" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From 8a240218053ee8d0abf08a28f0165000bae5d64e Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Fri, 17 Mar 2023 19:14:01 -0700 Subject: [PATCH 2/3] Update next.md --- ci/release/changelogs/next.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index b87db01c1d..afdeb36a4c 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -4,4 +4,4 @@ #### Bugfixes ⛑️ -- Fixes Fill Pattern replacement in the API. [#853](https://github.com/terrastruct/d2/pull/853) +- Fixes Fill Pattern replacement in the API. [#1051](https://github.com/terrastruct/d2/pull/1051) From fa8ce114b74eec8568107d3c916ac647be614c93 Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Fri, 17 Mar 2023 19:14:51 -0700 Subject: [PATCH 3/3] Update next.md --- ci/release/changelogs/next.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index afdeb36a4c..7dc3c7751e 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -4,4 +4,4 @@ #### Bugfixes ⛑️ -- Fixes Fill Pattern replacement in the API. [#1051](https://github.com/terrastruct/d2/pull/1051) +- Fixes fill-pattern replacement in the API. [#1051](https://github.com/terrastruct/d2/pull/1051)