replace arrowhead

This commit is contained in:
Alexander Wang 2023-02-20 17:00:37 -08:00
parent d082d97469
commit fdb6133f04
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
4 changed files with 609 additions and 3 deletions

View file

@ -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)
}
}

View file

@ -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
}
}
`,
},
{

280
testdata/d2oracle/TestSet/replace_arrowhead.exp.json generated vendored Normal file
View file

@ -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": "<nil>"
}

View file

@ -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": "<nil>"
}