From aff6723d38fa22a0092eb70d6b01fdfd71cad3c2 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 14:15:47 -0800 Subject: [PATCH 1/8] replace link and tooltip --- d2compiler/compile.go | 8 +- d2graph/d2graph.go | 8 +- d2oracle/edit.go | 29 +- d2oracle/edit_test.go | 94 +++++ .../d2oracle/TestDelete/arrowhead.exp.json | 214 +++++++++++ .../TestDelete/arrowhead_shape.exp.json | 214 +++++++++++ .../d2oracle/TestDelete/delete_icon.exp.json | 4 +- .../TestDelete/edge-only-style.exp.json | 214 +++++++++++ .../TestSet/edge_replace_arrowhead.exp.json | 280 ++++++++++++++ .../edge_replace_arrowhead_indexed.exp.json | 361 ++++++++++++++++++ .../TestSet/edge_replace_style.exp.json | 280 ++++++++++++++ .../TestSet/edge_set_arrowhead.exp.json | 280 ++++++++++++++ .../d2oracle/TestSet/replace_link.exp.json | 151 ++++++++ .../d2oracle/TestSet/replace_tooltip.exp.json | 151 ++++++++ 14 files changed, 2280 insertions(+), 8 deletions(-) create mode 100644 testdata/d2oracle/TestDelete/arrowhead.exp.json create mode 100644 testdata/d2oracle/TestDelete/arrowhead_shape.exp.json create mode 100644 testdata/d2oracle/TestDelete/edge-only-style.exp.json create mode 100644 testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json create mode 100644 testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json create mode 100644 testdata/d2oracle/TestSet/edge_replace_style.exp.json create mode 100644 testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json create mode 100644 testdata/d2oracle/TestSet/replace_link.exp.json create mode 100644 testdata/d2oracle/TestSet/replace_tooltip.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index b2df640da..2a2e3becd 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -266,7 +266,9 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) { nearKey.Range = scalar.GetRange() attrs.NearKey = nearKey case "tooltip": - attrs.Tooltip = scalar.ScalarString() + attrs.Tooltip = &d2graph.Scalar{} + attrs.Tooltip.Value = scalar.ScalarString() + attrs.Tooltip.MapKey = f.LastPrimaryKey() case "width": _, err := strconv.Atoi(scalar.ScalarString()) if err != nil { @@ -304,7 +306,9 @@ func (c *compiler) compileReserved(attrs *d2graph.Attributes, f *d2ir.Field) { attrs.Left.Value = scalar.ScalarString() attrs.Left.MapKey = f.LastPrimaryKey() case "link": - attrs.Link = scalar.ScalarString() + attrs.Link = &d2graph.Scalar{} + attrs.Link.Value = scalar.ScalarString() + attrs.Link.MapKey = f.LastPrimaryKey() case "direction": dirs := []string{"up", "down", "right", "left"} if !go2.Contains(dirs, scalar.ScalarString()) { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 30bdedcbf..385a6b2ed 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -95,8 +95,8 @@ type Attributes struct { Label Scalar `json:"label"` Style Style `json:"style"` Icon *url.URL `json:"icon,omitempty"` - Tooltip string `json:"tooltip,omitempty"` - Link string `json:"link,omitempty"` + Tooltip *Scalar `json:"tooltip,omitempty"` + Link *Scalar `json:"link,omitempty"` Width *Scalar `json:"width,omitempty"` Height *Scalar `json:"height,omitempty"` @@ -1313,10 +1313,10 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler switch shapeType { case shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE, shape.IMAGE_TYPE: default: - if obj.Attributes.Link != "" { + if obj.Attributes.Link != nil { paddingX += 32 } - if obj.Attributes.Tooltip != "" { + if obj.Attributes.Tooltip != nil { paddingX += 32 } } diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 8813755bf..669443541 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -37,6 +37,7 @@ func Create(g *d2graph.Graph, key string) (_ *d2graph.Graph, newKey string, err if err != nil { return nil, "", err } + g, err = recompile(g) if err != nil { return nil, "", err @@ -195,6 +196,20 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { reserved = true toSkip = 1 + if len(mk.EdgeKey.Path) > 1 { + switch mk.EdgeKey.Path[len(mk.EdgeKey.Path)-2].Unbox().ScalarString() { + case "source-arrowhead": + if edge.SrcArrowhead != nil { + toSkip++ + attrs = edge.SrcArrowhead + } + case "target-arrowhead": + if edge.DstArrowhead != nil { + toSkip++ + attrs = edge.DstArrowhead + } + } + } mk = &d2ast.Key{ Key: cloneKey(mk.EdgeKey), Value: mk.Value, @@ -234,6 +249,16 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { attrs.Shape.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } + case "link": + if attrs.Link.MapKey != nil { + attrs.Link.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } + case "tooltip": + if attrs.Tooltip.MapKey != nil { + attrs.Tooltip.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } case "width": if attrs.Width != nil && attrs.Width.MapKey != nil { attrs.Width.MapKey.SetScalar(mk.Value.ScalarBox()) @@ -714,7 +739,9 @@ func deleteMapField(m *d2ast.Map, field string) { if n.MapKey != nil && n.MapKey.Key != nil { if n.MapKey.Key.Path[0].Unbox().ScalarString() == field { deleteFromMap(m, n.MapKey) - } else if n.MapKey.Key.Path[0].Unbox().ScalarString() == "style" { + } else if n.MapKey.Key.Path[0].Unbox().ScalarString() == "style" || + n.MapKey.Key.Path[0].Unbox().ScalarString() == "source-arrowhead" || + n.MapKey.Key.Path[0].Unbox().ScalarString() == "target-arrowhead" { if n.MapKey.Value.Map != nil { deleteMapField(n.MapKey.Value.Map, field) if len(n.MapKey.Value.Map.Nodes) == 0 { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index f6dc0cf3a..c5116b925 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -741,6 +741,32 @@ square.style.opacity: 0.2 exp: `square: { width: 200 } +`, + }, + { + name: "replace_tooltip", + text: `square: { + tooltip: x +} +`, + key: `square.tooltip`, + value: go2.Pointer(`y`), + exp: `square: { + tooltip: y +} +`, + }, + { + name: "replace_link", + text: `square: { + link: https://google.com +} +`, + key: `square.link`, + value: go2.Pointer(`https://apple.com`), + exp: `square: { + link: https://apple.com +} `, }, { @@ -1072,6 +1098,38 @@ a.b -> a.c: {style.animated: true} value: go2.Pointer(`true`), exp: `x -> y: {style.animated: true} +`, + }, + { + name: "edge_set_arrowhead", + text: `x -> y +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`diamond`), + + exp: `x -> y: {target-arrowhead.shape: diamond} +`, + }, + { + name: "edge_replace_arrowhead", + text: `x -> y: {target-arrowhead.shape: circle} +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`diamond`), + + exp: `x -> y: {target-arrowhead.shape: diamond} +`, + }, + { + name: "edge_replace_arrowhead_indexed", + text: `x -> y +(x -> y)[0].target-arrowhead.shape: circle +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`diamond`), + + exp: `x -> y +(x -> y)[0].target-arrowhead.shape: diamond `, }, { @@ -3459,6 +3517,42 @@ x key: `x`, exp: `y +`, + }, + { + name: "arrowhead", + + text: `x -> y: { + target-arrowhead.shape: diamond +} +`, + key: `(x -> y)[0].target-arrowhead`, + + exp: `x -> y +`, + }, + { + name: "arrowhead_shape", + + text: `x -> y: { + target-arrowhead.shape: diamond +} +`, + key: `(x -> y)[0].target-arrowhead.shape`, + + exp: `x -> y +`, + }, + { + name: "edge-only-style", + + text: `x -> y: { + style.stroke: red +} +`, + key: `(x -> y)[0].style.stroke`, + + exp: `x -> y `, }, { diff --git a/testdata/d2oracle/TestDelete/arrowhead.exp.json b/testdata/d2oracle/TestDelete/arrowhead.exp.json new file mode 100644 index 000000000..eb4cd6ebb --- /dev/null +++ b/testdata/d2oracle/TestDelete/arrowhead.exp.json @@ -0,0 +1,214 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-1:0:7", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestDelete/arrowhead_shape.exp.json b/testdata/d2oracle/TestDelete/arrowhead_shape.exp.json new file mode 100644 index 000000000..6ad6f3824 --- /dev/null +++ b/testdata/d2oracle/TestDelete/arrowhead_shape.exp.json @@ -0,0 +1,214 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-1:0:7", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_shape.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestDelete/delete_icon.exp.json b/testdata/d2oracle/TestDelete/delete_icon.exp.json index 374b88cb2..66fcdfb72 100644 --- a/testdata/d2oracle/TestDelete/delete_icon.exp.json +++ b/testdata/d2oracle/TestDelete/delete_icon.exp.json @@ -209,7 +209,9 @@ "value": "x" }, "style": {}, - "link": "https://google.com", + "link": { + "value": "https://google.com" + }, "near_key": null, "shape": { "value": "rectangle" diff --git a/testdata/d2oracle/TestDelete/edge-only-style.exp.json b/testdata/d2oracle/TestDelete/edge-only-style.exp.json new file mode 100644 index 000000000..50846ea3b --- /dev/null +++ b/testdata/d2oracle/TestDelete/edge-only-style.exp.json @@ -0,0 +1,214 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-1:0:7", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/edge-only-style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json new file mode 100644 index 000000000..2099babb4 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json @@ -0,0 +1,280 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-1:0:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-0:41:41", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:8:8-0:40:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:9:9-0:40:40", + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:9:9-0:31:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:9:9-0:25:25", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:26:26-0:31:31", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:33:33-0:40:40", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json b/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json new file mode 100644 index 000000000..17bc34333 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json @@ -0,0 +1,361 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-2:0:51", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:0:7-1:43:50", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:1:8-1:7:14", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:1:8-1:3:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:1:8-1:2:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:5:12-1:7:14", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:6:13-1:7:14", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "edge_index": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:8:15-1:11:18", + "int": 0, + "glob": false + }, + "edge_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:12:19-1:34:41", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:12:19-1:28:35", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:29:36-1:34:41", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:36:43-1:43:50", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + }, + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:1:8-1:3:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:1:8-1:2:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:5:12-1:7:14", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:6:13-1:7:14", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/edge_replace_style.exp.json b/testdata/d2oracle/TestSet/edge_replace_style.exp.json new file mode 100644 index 000000000..f15dc4109 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_replace_style.exp.json @@ -0,0 +1,280 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-1:0:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-0:41:41", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:8:8-0:40:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:9:9-0:40:40", + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:9:9-0:31:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:9:9-0:25:25", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:26:26-0:31:31", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:33:33-0:40:40", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_replace_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json new file mode 100644 index 000000000..0c3855cc9 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json @@ -0,0 +1,280 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-1:0:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-0:41:41", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:8:8-0:40:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:9:9-0:40:40", + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:9:9-0:31:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:9:9-0:25:25", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:26:26-0:31:31", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:33:33-0:40:40", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/replace_link.exp.json b/testdata/d2oracle/TestSet/replace_link.exp.json new file mode 100644 index 000000000..a6ad42efe --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_link.exp.json @@ -0,0 +1,151 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,0:0:0-3:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,0:0:0-2:1:37", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,0:8:8-2:0:36", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,1:2:12-1:25:35", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,1:2:12-1:6:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,1:2:12-1:6:16", + "value": [ + { + "string": "link", + "raw_string": "link" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,1:8:18-1:25:35", + "value": [ + { + "string": "https://apple.com", + "raw_string": "https://apple.com" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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_link.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_link.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": {}, + "link": { + "value": "https://apple.com" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/replace_tooltip.exp.json b/testdata/d2oracle/TestSet/replace_tooltip.exp.json new file mode 100644 index 000000000..7aab2f7e2 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_tooltip.exp.json @@ -0,0 +1,151 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,0:0:0-3:0:25", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,0:0:0-2:1:24", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,0:8:8-2:0:23", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,1:2:12-1:12:22", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,1:2:12-1:9:19", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,1:2:12-1:9:19", + "value": [ + { + "string": "tooltip", + "raw_string": "tooltip" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,1:11:21-1:12:22", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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_tooltip.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.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": {}, + "tooltip": { + "value": "y" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From f7a5689280e3a5f8ef3b631f7110fb70669006de Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 14:18:55 -0800 Subject: [PATCH 2/8] fix --- d2compiler/compile_test.go | 8 ++++---- d2exporter/export.go | 12 +++++++++--- testdata/d2compiler/TestCompile/path_link.exp.json | 4 +++- testdata/d2compiler/TestCompile/url_link.exp.json | 4 +++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 4623190b4..85a27d860 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1364,8 +1364,8 @@ x -> y: { if len(g.Objects) != 1 { t.Fatal(g.Objects) } - if g.Objects[0].Attributes.Link != "https://google.com" { - t.Fatal(g.Objects[0].Attributes.Link) + if g.Objects[0].Attributes.Link.Value != "https://google.com" { + t.Fatal(g.Objects[0].Attributes.Link.Value) } }, }, @@ -1380,8 +1380,8 @@ x -> y: { if len(g.Objects) != 1 { t.Fatal(g.Objects) } - if g.Objects[0].Attributes.Link != "Overview.Untitled board 7.zzzzz" { - t.Fatal(g.Objects[0].Attributes.Link) + if g.Objects[0].Attributes.Link.Value != "Overview.Untitled board 7.zzzzz" { + t.Fatal(g.Objects[0].Attributes.Link.Value) } }, }, diff --git a/d2exporter/export.go b/d2exporter/export.go index 0237d554a..1dcf55179 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -152,8 +152,12 @@ func toShape(obj *d2graph.Object, theme *d2themes.Theme) d2target.Shape { } } - shape.Tooltip = obj.Attributes.Tooltip - shape.Link = obj.Attributes.Link + if obj.Attributes.Tooltip != nil { + shape.Tooltip = obj.Attributes.Tooltip.Value + } + if obj.Attributes.Link != nil { + shape.Link = obj.Attributes.Link.Value + } shape.Icon = obj.Attributes.Icon if obj.IconPosition != nil { shape.IconPosition = *obj.IconPosition @@ -232,7 +236,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection connection.Animated, _ = strconv.ParseBool(edge.Attributes.Style.Animated.Value) } - connection.Tooltip = edge.Attributes.Tooltip + if edge.Attributes.Tooltip != nil { + connection.Tooltip = edge.Attributes.Tooltip.Value + } connection.Icon = edge.Attributes.Icon if edge.Attributes.Style.Italic != nil { diff --git a/testdata/d2compiler/TestCompile/path_link.exp.json b/testdata/d2compiler/TestCompile/path_link.exp.json index 9a1cb6fc3..7c96d68c6 100644 --- a/testdata/d2compiler/TestCompile/path_link.exp.json +++ b/testdata/d2compiler/TestCompile/path_link.exp.json @@ -129,7 +129,9 @@ "value": "x" }, "style": {}, - "link": "Overview.Untitled board 7.zzzzz", + "link": { + "value": "Overview.Untitled board 7.zzzzz" + }, "near_key": null, "shape": { "value": "rectangle" diff --git a/testdata/d2compiler/TestCompile/url_link.exp.json b/testdata/d2compiler/TestCompile/url_link.exp.json index b0ebf8a9d..eca980a30 100644 --- a/testdata/d2compiler/TestCompile/url_link.exp.json +++ b/testdata/d2compiler/TestCompile/url_link.exp.json @@ -129,7 +129,9 @@ "value": "x" }, "style": {}, - "link": "https://google.com", + "link": { + "value": "https://google.com" + }, "near_key": null, "shape": { "value": "rectangle" From dab8215f9efc2bba00cecb605aac1693381fe4b7 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 14:21:51 -0800 Subject: [PATCH 3/8] more tests --- d2oracle/edit.go | 1 - d2oracle/edit_test.go | 29 ++ .../TestDelete/arrowhead_label.exp.json | 280 ++++++++++++++++++ .../TestDelete/arrowhead_map.exp.json | 214 +++++++++++++ 4 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 testdata/d2oracle/TestDelete/arrowhead_label.exp.json create mode 100644 testdata/d2oracle/TestDelete/arrowhead_map.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 669443541..1df240a70 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -37,7 +37,6 @@ func Create(g *d2graph.Graph, key string) (_ *d2graph.Graph, newKey string, err if err != nil { return nil, "", err } - g, err = recompile(g) if err != nil { return nil, "", err diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index c5116b925..2ab778cc0 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -3542,6 +3542,35 @@ x exp: `x -> y `, + }, + { + name: "arrowhead_label", + + text: `x -> y: { + target-arrowhead.shape: diamond + target-arrowhead.label: 1 +} +`, + key: `(x -> y)[0].target-arrowhead.label`, + + exp: `x -> y: { + target-arrowhead.shape: diamond +} +`, + }, + { + name: "arrowhead_map", + + text: `x -> y: { + target-arrowhead: { + shape: diamond + } +} +`, + key: `(x -> y)[0].target-arrowhead.shape`, + + exp: `x -> y +`, }, { name: "edge-only-style", diff --git a/testdata/d2oracle/TestDelete/arrowhead_label.exp.json b/testdata/d2oracle/TestDelete/arrowhead_label.exp.json new file mode 100644 index 000000000..30ff73b25 --- /dev/null +++ b/testdata/d2oracle/TestDelete/arrowhead_label.exp.json @@ -0,0 +1,280 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-3:0:46", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-2:1:45", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:8:8-2:0:44", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,1:2:12-1:33:43", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,1:2:12-1:24:34", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,1:2:12-1:18:28", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,1:19:29-1:24:34", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,1:26:36-1:33:43", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestDelete/arrowhead_map.exp.json b/testdata/d2oracle/TestDelete/arrowhead_map.exp.json new file mode 100644 index 000000000..9fab0d94b --- /dev/null +++ b/testdata/d2oracle/TestDelete/arrowhead_map.exp.json @@ -0,0 +1,214 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-1:0:7", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-0:6:6", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/arrowhead_map.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From d082d97469b7898529016ace5b64f6937a104895 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 14:31:26 -0800 Subject: [PATCH 4/8] [ci-base] fix last pr --- d2oracle/edit.go | 4 +- d2oracle/edit_test.go | 9 ++ .../d2oracle/TestSet/set_tooltip.exp.json | 151 ++++++++++++++++++ 3 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 testdata/d2oracle/TestSet/set_tooltip.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index ec27b63a2..76f34c240 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -249,12 +249,12 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { return nil } case "link": - if attrs.Link.MapKey != nil { + if attrs.Link != nil && attrs.Link.MapKey != nil { attrs.Link.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } case "tooltip": - if attrs.Tooltip.MapKey != nil { + if attrs.Tooltip != nil && attrs.Tooltip.MapKey != nil { attrs.Tooltip.MapKey.SetScalar(mk.Value.ScalarBox()) return nil } diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 4da115a8e..965ce4826 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -741,6 +741,15 @@ square.style.opacity: 0.2 exp: `square: { width: 200 } +`, + }, + { + name: "set_tooltip", + text: `square +`, + key: `square.tooltip`, + value: go2.Pointer(`y`), + exp: `square: {tooltip: y} `, }, { diff --git a/testdata/d2oracle/TestSet/set_tooltip.exp.json b/testdata/d2oracle/TestSet/set_tooltip.exp.json new file mode 100644 index 000000000..15cd02ebd --- /dev/null +++ b/testdata/d2oracle/TestSet/set_tooltip.exp.json @@ -0,0 +1,151 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:0:0-1:0:21", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:0:0-0:20:20", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:0:0-0:6:6", + "value": [ + { + "string": "square", + "raw_string": "square" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:8:8-0:19:19", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:9:9-0:19:19", + "key": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:9:9-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:9:9-0:16:16", + "value": [ + { + "string": "tooltip", + "raw_string": "tooltip" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:18:18-0:19:19", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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_tooltip.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/set_tooltip.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": {}, + "tooltip": { + "value": "y" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From fdb6133f04c7f422ae2f27e0b772b90138996efb Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 17:00:37 -0800 Subject: [PATCH 5/8] replace arrowhead --- d2oracle/edit.go | 4 +- d2oracle/edit_test.go | 30 ++ .../TestSet/replace_arrowhead.exp.json | 280 ++++++++++++++++ .../TestSet/replace_arrowhead_map.exp.json | 298 ++++++++++++++++++ 4 files changed, 609 insertions(+), 3 deletions(-) create mode 100644 testdata/d2oracle/TestSet/replace_arrowhead.exp.json create mode 100644 testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 76f34c240..8e6b81c27 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -194,17 +194,14 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { } reserved = true - toSkip = 1 if len(mk.EdgeKey.Path) > 1 { switch mk.EdgeKey.Path[len(mk.EdgeKey.Path)-2].Unbox().ScalarString() { case "source-arrowhead": if edge.SrcArrowhead != nil { - toSkip++ attrs = edge.SrcArrowhead } case "target-arrowhead": if edge.DstArrowhead != nil { - toSkip++ attrs = edge.DstArrowhead } } @@ -236,6 +233,7 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { attrs.Label.MapKey.Value = d2ast.MakeValueBox(edgeMap) scope = edgeMap } + toSkip = len(mk.Key.Path) } } diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 965ce4826..3e738fd9d 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -776,6 +776,36 @@ square.style.opacity: 0.2 exp: `square: { link: https://apple.com } +`, + }, + { + name: "replace_arrowhead", + text: `x -> y: { + target-arrowhead.shape: diamond +} +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`circle`), + exp: `x -> y: { + target-arrowhead.shape: circle +} +`, + }, + { + name: "replace_arrowhead_map", + text: `x -> y: { + target-arrowhead: { + shape: diamond + } +} +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`circle`), + exp: `x -> y: { + target-arrowhead: { + shape: circle + } +} `, }, { diff --git a/testdata/d2oracle/TestSet/replace_arrowhead.exp.json b/testdata/d2oracle/TestSet/replace_arrowhead.exp.json new file mode 100644 index 000000000..dcc2c7bdc --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_arrowhead.exp.json @@ -0,0 +1,280 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-3:0:45", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-2:1:44", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:8:8-2:0:43", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,1:2:12-1:32:42", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,1:2:12-1:24:34", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,1:2:12-1:18:28", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,1:19:29-1:24:34", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,1:26:36-1:32:42", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "circle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json b/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json new file mode 100644 index 000000000..dcabb24e7 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json @@ -0,0 +1,298 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-5:0:56", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-4:1:55", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:8:8-4:0:54", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,1:2:12-3:3:53", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,1:2:12-1:18:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,1:2:12-1:18:28", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,1:20:30-3:2:52", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,2:4:36-2:17:49", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,2:4:36-2:9:41", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,2:4:36-2:9:41", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,2:11:43-2:17:49", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "circle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From b5d2dba267cc45c91699418b2cf2b3dc9d7e4283 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 19:34:38 -0800 Subject: [PATCH 6/8] fix edge keying --- d2oracle/edit.go | 83 +++-- d2oracle/edit_test.go | 51 +++ .../TestSet/edge_merge_arrowhead.exp.json | 327 ++++++++++++++++++ .../TestSet/replace_edge_style.exp.json | 307 ++++++++++++++++ .../TestSet/replace_edge_style_map.exp.json | 282 +++++++++++++++ 5 files changed, 1027 insertions(+), 23 deletions(-) create mode 100644 testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json create mode 100644 testdata/d2oracle/TestSet/replace_edge_style.exp.json create mode 100644 testdata/d2oracle/TestSet/replace_edge_style_map.exp.json diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 8e6b81c27..5761f2250 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -111,6 +111,8 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { toSkip := 1 reserved := false + reservedKey := "" + reservedTargetKey := "" if mk.Key != nil { found := true for _, idel := range d2graph.Key(mk.Key) { @@ -162,12 +164,14 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { } attrs := obj.Attributes + var edge *d2graph.Edge if len(mk.Edges) == 1 { if mk.EdgeIndex == nil { appendMapKey(scope, mk) return nil } - edge, ok := obj.HasEdge(mk) + var ok bool + edge, ok = obj.HasEdge(mk) if !ok { return errors.New("edge not found") } @@ -194,18 +198,7 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { } reserved = true - if len(mk.EdgeKey.Path) > 1 { - switch mk.EdgeKey.Path[len(mk.EdgeKey.Path)-2].Unbox().ScalarString() { - case "source-arrowhead": - if edge.SrcArrowhead != nil { - attrs = edge.SrcArrowhead - } - case "target-arrowhead": - if edge.DstArrowhead != nil { - attrs = edge.DstArrowhead - } - } - } + toSkip = 1 mk = &d2ast.Key{ Key: cloneKey(mk.EdgeKey), Value: mk.Value, @@ -217,10 +210,26 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { if ref.MapKey.Value.Map != nil { foundMap = true scope = ref.MapKey.Value.Map - // TODO when edges can have more fields, search for style - if len(scope.Nodes) == 1 && scope.Nodes[0].MapKey.Value.Map != nil { - scope = scope.Nodes[0].MapKey.Value.Map - mk.Key.Path = mk.Key.Path[1:] + for _, n := range scope.Nodes { + if n.MapKey.Value.Map == nil { + continue + } + if n.MapKey.Key == nil || len(n.MapKey.Key.Path) != 1 { + continue + } + if n.MapKey.Key.Path[0].Unbox().ScalarString() == mk.Key.Path[toSkip-1].Unbox().ScalarString() { + scope = n.MapKey.Value.Map + if mk.Key.Path[0].Unbox().ScalarString() == "source-arrowhead" && edge.SrcArrowhead != nil { + attrs = edge.SrcArrowhead + } + if mk.Key.Path[0].Unbox().ScalarString() == "target-arrowhead" && edge.DstArrowhead != nil { + attrs = edge.DstArrowhead + } + reservedKey = mk.Key.Path[0].Unbox().ScalarString() + mk.Key.Path = mk.Key.Path[1:] + reservedTargetKey = mk.Key.Path[0].Unbox().ScalarString() + break + } } break } @@ -233,14 +242,16 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { attrs.Label.MapKey.Value = d2ast.MakeValueBox(edgeMap) scope = edgeMap } - toSkip = len(mk.Key.Path) } } if reserved { reservedIndex := toSkip - 1 if mk.Key != nil && len(mk.Key.Path) > 0 { - switch mk.Key.Path[reservedIndex].Unbox().ScalarString() { + if reservedKey == "" { + reservedKey = mk.Key.Path[reservedIndex].Unbox().ScalarString() + } + switch reservedKey { case "shape": if attrs.Shape.MapKey != nil { attrs.Shape.MapKey.SetScalar(mk.Value.ScalarBox()) @@ -276,11 +287,34 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { 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") + case "source-arrowhead", "target-arrowhead": + if reservedKey == "source-arrowhead" { + attrs = edge.SrcArrowhead + } else { + attrs = edge.DstArrowhead } - switch mk.Key.Path[reservedIndex+1].Unbox().ScalarString() { + if attrs != nil { + if reservedTargetKey == "" { + reservedTargetKey = mk.Key.Path[reservedIndex+1].Unbox().ScalarString() + } + switch reservedTargetKey { + case "shape": + if attrs.Shape.MapKey != nil { + attrs.Shape.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } + case "label": + if attrs.Label.MapKey != nil { + attrs.Label.MapKey.SetScalar(mk.Value.ScalarBox()) + return nil + } + } + } + case "style": + if reservedTargetKey == "" { + reservedTargetKey = mk.Key.Path[reservedIndex+1].Unbox().ScalarString() + } + switch reservedTargetKey { case "opacity": if attrs.Style.Opacity != nil { attrs.Style.Opacity.MapKey.SetScalar(mk.Value.ScalarBox()) @@ -382,6 +416,9 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { return nil } +// func setStyleAttr(attr *d2graph.Attributes, k string, v *d2ast.Key) { +// } + func appendUniqueMapKey(m *d2ast.Map, mk *d2ast.Key) { for _, n := range m.Nodes { if n.MapKey != nil && n.MapKey.Equals(mk) { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 3e738fd9d..ab67b090e 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -806,6 +806,38 @@ square.style.opacity: 0.2 shape: circle } } +`, + }, + { + name: "replace_edge_style_map", + text: `x -> y: { + style: { + stroke-dash: 3 + } +} +`, + key: `(x -> y)[0].style.stroke-dash`, + value: go2.Pointer(`4`), + exp: `x -> y: { + style: { + stroke-dash: 4 + } +} +`, + }, + { + name: "replace_edge_style", + text: `x -> y: { + style.stroke-width: 1 + style.stroke-dash: 4 +} +`, + key: `(x -> y)[0].style.stroke-dash`, + value: go2.Pointer(`3`), + exp: `x -> y: { + style.stroke-width: 1 + style.stroke-dash: 3 +} `, }, { @@ -1169,6 +1201,25 @@ a.b -> a.c: {style.animated: true} exp: `x -> y (x -> y)[0].target-arrowhead.shape: diamond +`, + }, + { + name: "edge_merge_arrowhead", + text: `x -> y: { + target-arrowhead: { + label: 1 + } +} +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`diamond`), + + exp: `x -> y: { + target-arrowhead: { + label: 1 + shape: diamond + } +} `, }, { diff --git a/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json new file mode 100644 index 000000000..5ab8b6250 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json @@ -0,0 +1,327 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-6:0:70", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-5:1:69", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:8:8-5:0:68", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,1:2:12-4:3:67", + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,1:2:12-1:18:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,1:2:12-1:18:28", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,1:20:30-4:2:66", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,2:4:36-2:12:44", + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,2:4:36-2:9:41", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,2:4:36-2:9:41", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,2:11:43-2:12:44", + "raw": "1", + "value": "1" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,3:4:49-3:18:63", + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,3:4:49-3:9:54", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,3:4:49-3:9:54", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,3:11:56-3:18:63", + "value": [ + { + "string": "diamond", + "raw_string": "diamond" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "1" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "diamond" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/replace_edge_style.exp.json b/testdata/d2oracle/TestSet/replace_edge_style.exp.json new file mode 100644 index 000000000..0b015d938 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_edge_style.exp.json @@ -0,0 +1,307 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-4:0:59", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-3:1:58", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:8:8-3:0:57", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,1:2:12-1:23:33", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,1:2:12-1:20:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,1:2:12-1:7:17", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,1:8:18-1:20:30", + "value": [ + { + "string": "stroke-width", + "raw_string": "stroke-width" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,1:22:32-1:23:33", + "raw": "1", + "value": "1" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,2:2:36-2:22:56", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,2:2:36-2:19:53", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,2:2:36-2:7:41", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,2:8:42-2:19:53", + "value": [ + { + "string": "stroke-dash", + "raw_string": "stroke-dash" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,2:21:55-2:22:56", + "raw": "3", + "value": "3" + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": { + "strokeWidth": { + "value": "1" + }, + "strokeDash": { + "value": "3" + } + }, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/replace_edge_style_map.exp.json b/testdata/d2oracle/TestSet/replace_edge_style_map.exp.json new file mode 100644 index 000000000..5bacdac19 --- /dev/null +++ b/testdata/d2oracle/TestSet/replace_edge_style_map.exp.json @@ -0,0 +1,282 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-5:0:46", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-4:1:45", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-0:6:6", + "src": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:8:8-4:0:44", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,1:2:12-3:3:43", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,1:2:12-1:7:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,1:2:12-1:7:17", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,1:9:19-3:2:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,2:4:25-2:18:39", + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,2:4:25-2:15:36", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,2:4:25-2:15:36", + "value": [ + { + "string": "stroke-dash", + "raw_string": "stroke-dash" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,2:17:38-2:18:39", + "raw": "4", + "value": "4" + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": { + "strokeDash": { + "value": "4" + } + }, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:4:4-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/replace_edge_style_map.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} From f15614066b884cdd2fc31720d494f9195a67a25a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 19:41:40 -0800 Subject: [PATCH 7/8] comment --- d2oracle/edit.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 5761f2250..7dd142f79 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -111,6 +111,23 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { toSkip := 1 reserved := false + + // If you're setting `(x -> y)[0].style.opacity` + // There's 3 cases you need to handle: + // 1. The edge has no map. + // 2. The edge has a style map with opacity not existing + // 3. The edge has a style map with opacity existing + // + // How each case is handled: + // 1. Append that mapkey to edge. + // 2. Append opacity to the style map + // 3. Set opacity + // + // There's certainly cleaner code to achieve this, but currently, there's a lot of logic to correctly scope, merge, append. + // The tests should be comprehensive enough for a safe refactor someday + // + // reservedKey = "style" + // reservedTargetKey = "opacity" reservedKey := "" reservedTargetKey := "" if mk.Key != nil { @@ -295,6 +312,9 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { } if attrs != nil { if reservedTargetKey == "" { + if len(mk.Key.Path[reservedIndex:]) != 2 { + return errors.New("malformed style setting, expected 2 part path") + } reservedTargetKey = mk.Key.Path[reservedIndex+1].Unbox().ScalarString() } switch reservedTargetKey { @@ -312,6 +332,9 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { } case "style": if reservedTargetKey == "" { + if len(mk.Key.Path[reservedIndex:]) != 2 { + return errors.New("malformed style setting, expected 2 part path") + } reservedTargetKey = mk.Key.Path[reservedIndex+1].Unbox().ScalarString() } switch reservedTargetKey { @@ -416,9 +439,6 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { return nil } -// func setStyleAttr(attr *d2graph.Attributes, k string, v *d2ast.Key) { -// } - func appendUniqueMapKey(m *d2ast.Map, mk *d2ast.Key) { for _, n := range m.Nodes { if n.MapKey != nil && n.MapKey.Equals(mk) { From e91a046990ba4041c48dddf741379393112349e6 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 20 Feb 2023 20:17:17 -0800 Subject: [PATCH 8/8] fix edge key index value --- d2ast/d2ast.go | 15 +- d2oracle/edit.go | 12 +- d2oracle/edit_test.go | 24 + .../edge_flat_merge_arrowhead.exp.json | 499 ++++++++++++++++++ .../TestSet/edge_index_merge_style.exp.json | 483 +++++++++++++++++ 5 files changed, 1031 insertions(+), 2 deletions(-) create mode 100644 testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json create mode 100644 testdata/d2oracle/TestSet/edge_index_merge_style.exp.json diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index 85d6f8620..3d209be6a 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -593,8 +593,11 @@ type Key struct { Value ValueBox `json:"value"` } -// TODO there's more stuff to compare +// TODO maybe need to compare Primary func (mk1 *Key) Equals(mk2 *Key) bool { + if mk1.Ampersand != mk2.Ampersand { + return false + } if (mk1.Key == nil) != (mk2.Key == nil) { return false } @@ -624,6 +627,16 @@ func (mk1 *Key) Equals(mk2 *Key) bool { } } } + if mk1.EdgeKey != nil { + if len(mk1.EdgeKey.Path) != len(mk2.EdgeKey.Path) { + return false + } + for i, id := range mk1.EdgeKey.Path { + if id.Unbox().ScalarString() != mk2.EdgeKey.Path[i].Unbox().ScalarString() { + return false + } + } + } if mk1.Value.Map != nil { if len(mk1.Value.Map.Nodes) != len(mk2.Value.Map.Nodes) { diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 7dd142f79..8905450a7 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -200,7 +200,17 @@ func _set(g *d2graph.Graph, key string, tag, value *string) error { // (y -> z)[0].style.animated: true if len(ref.MapKey.Edges) == 1 && ref.MapKey.EdgeIndex == nil { onlyInChain = false - break + } + // If a ref has an exact match on this key, just change the value + tmp1 := *ref.MapKey + tmp2 := *mk + noVal1 := &tmp1 + noVal2 := &tmp2 + noVal1.Value = d2ast.ValueBox{} + noVal2.Value = d2ast.ValueBox{} + if noVal1.Equals(noVal2) { + ref.MapKey.Value = mk.Value + return nil } } if onlyInChain { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index ab67b090e..7cd1ef697 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -1239,6 +1239,30 @@ a.b -> a.c: {style.animated: true} animated: true } } +`, + }, + { + name: "edge_flat_merge_arrowhead", + text: `x -> y -> z +(x -> y)[0].target-arrowhead.shape: diamond +`, + key: `(x -> y)[0].target-arrowhead.shape`, + value: go2.Pointer(`circle`), + + exp: `x -> y -> z +(x -> y)[0].target-arrowhead.shape: circle +`, + }, + { + name: "edge_index_merge_style", + text: `x -> y -> z +(x -> y)[0].style.opacity: 0.4 +`, + key: `(x -> y)[0].style.opacity`, + value: go2.Pointer(`0.5`), + + exp: `x -> y -> z +(x -> y)[0].style.opacity: 0.5 `, }, { diff --git a/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json new file mode 100644 index 000000000..36c828de4 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json @@ -0,0 +1,499 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-2:0:55", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-0:11:11", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-0:7:7", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:4:4-0:11:11", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:9:9-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:10:10-0:11:11", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:0:12-1:42:54", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:1:13-1:7:19", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:1:13-1:3:15", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:1:13-1:2:14", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:5:17-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:6:18-1:7:19", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "edge_index": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:8:20-1:11:23", + "int": 0, + "glob": false + }, + "edge_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:12:24-1:34:46", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:12:24-1:28:40", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:29:41-1:34:46", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:36:48-1:42:54", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "circle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "references": [ + { + "map_key_edge_index": 0 + }, + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 1 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:1:13-1:3:15", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:1:13-1:2:14", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 1 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:5:17-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:6:18-1:7:19", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:9:9-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,0:10:10-0:11:11", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestSet/edge_index_merge_style.exp.json b/testdata/d2oracle/TestSet/edge_index_merge_style.exp.json new file mode 100644 index 000000000..d8dcf3782 --- /dev/null +++ b/testdata/d2oracle/TestSet/edge_index_merge_style.exp.json @@ -0,0 +1,483 @@ +{ + "graph": { + "name": "", + "ast": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-2:0:43", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-0:11:11", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-0:7:7", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + }, + { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:4:4-0:11:11", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:9:9-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:10:10-0:11:11", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:0:12-1:30:42", + "edges": [ + { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:1:13-1:7:19", + "src": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:1:13-1:3:15", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:1:13-1:2:14", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:5:17-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:6:18-1:7:19", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "edge_index": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:8:20-1:11:23", + "int": 0, + "glob": false + }, + "edge_key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:12:24-1:25:37", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:12:24-1:17:29", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:18:30-1:25:37", + "value": [ + { + "string": "opacity", + "raw_string": "opacity" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:27:39-1:30:42", + "raw": "0.5", + "value": "1/2" + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + }, + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": { + "opacity": { + "value": "0.5" + } + }, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 1 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-0:2:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:1:13-1:3:15", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:1:13-1:2:14", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:4:4-0:7:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:5:5-0:6:6", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 1 + }, + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:5:17-1:7:19", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,1:6:18-1:7:19", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:9:9-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestSet/edge_index_merge_style.d2,0:10:10-0:11:11", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +}