Merge pull request #1015 from alixander/fix-arrowhead-label

fix arrowhead label detection
This commit is contained in:
Alexander Wang 2023-03-11 21:36:17 -08:00 committed by GitHub
commit de51ad919e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 459 additions and 177 deletions

View file

@ -11,3 +11,4 @@
#### Bugfixes ⛑️
- Fixes `d2` erroring on malformed user paths (`fdopendir` error). [util-go#10](https://github.com/terrastruct/util-go/pull/10)
- Arrowhead labels being set without maps wasn't being picked up. [#1015](https://github.com/terrastruct/d2/pull/1015)

View file

@ -488,10 +488,8 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
}
if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" {
if f.Map() != nil {
c.compileArrowheads(edge, f)
}
}
}
func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
@ -508,6 +506,7 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
c.compileLabel(attrs, f)
}
if f.Map() != nil {
for _, f2 := range f.Map().Fields {
keyword := strings.ToLower(f2.Name)
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
@ -525,6 +524,7 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
continue
}
}
}
}
// TODO add more, e.g. C, bash

View file

@ -971,6 +971,17 @@ x -> y: {
}
},
},
{
name: "edge_arrowhead_primary",
text: `x -> y: {
source-arrowhead: Reisner's Rule of Conceptual Inertia
}
`,
assertions: func(t *testing.T, g *d2graph.Graph) {
assert.String(t, "Reisner's Rule of Conceptual Inertia", g.Edges[0].SrcArrowhead.Label.Value)
},
},
{
name: "edge_arrowhead_fields",

View file

@ -91,7 +91,7 @@
"id": "(a -> b)[0]",
"src": "a",
"srcArrow": "none",
"srcLabel": "",
"srcLabel": "1",
"dst": "b",
"dstArrow": "diamond",
"dstLabel": "*",

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 473 KiB

After

Width:  |  Height:  |  Size: 473 KiB

View file

@ -91,7 +91,7 @@
"id": "(a -> b)[0]",
"src": "a",
"srcArrow": "none",
"srcLabel": "",
"srcLabel": "1",
"dst": "b",
"dstArrow": "diamond",
"dstLabel": "*",

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 473 KiB

After

Width:  |  Height:  |  Size: 473 KiB

View file

@ -0,0 +1,270 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:0:0-3:0:69",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:0:0-2:1:68",
"edges": [
{
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:0:0-0:6:6",
"src": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:0:0-0:2:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:4:4-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:5:5-0:6:6",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:8:8-2:0:67",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,1:2:12-1:56:66",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,1:2:12-1:18:28",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,1:2:12-1:18:28",
"value": [
{
"string": "source-arrowhead",
"raw_string": "source-arrowhead"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,1:20:30-1:56:66",
"value": [
{
"string": "Reisner's Rule of Conceptual Inertia",
"raw_string": "Reisner's Rule of Conceptual Inertia"
}
]
}
}
}
}
]
}
}
}
}
]
},
"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,
"srcArrowhead": {
"label": {
"value": "Reisner's Rule of Conceptual Inertia"
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"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/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:0:0-0:2:2",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.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/d2compiler/TestCompile/edge_arrowhead_primary.d2,0:4:4-0:6:6",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.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": null
}

View file

@ -89,7 +89,7 @@
"id": "(x -> y)[0]",
"src": "x",
"srcArrow": "none",
"srcLabel": "",
"srcLabel": "If you've done six impossible things before breakfast, why not round it",
"dst": "y",
"dstArrow": "filled-diamond",
"dstLabel": "A man with one watch knows what time it is.",