Merge pull request #1015 from alixander/fix-arrowhead-label
fix arrowhead label detection
This commit is contained in:
commit
de51ad919e
10 changed files with 459 additions and 177 deletions
|
|
@ -11,3 +11,4 @@
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
- Fixes `d2` erroring on malformed user paths (`fdopendir` error). [util-go#10](https://github.com/terrastruct/util-go/pull/10)
|
- 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)
|
||||||
|
|
|
||||||
|
|
@ -488,9 +488,7 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" {
|
if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" {
|
||||||
if f.Map() != nil {
|
c.compileArrowheads(edge, f)
|
||||||
c.compileArrowheads(edge, f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -508,21 +506,23 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
|
||||||
c.compileLabel(attrs, f)
|
c.compileLabel(attrs, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f2 := range f.Map().Fields {
|
if f.Map() != nil {
|
||||||
keyword := strings.ToLower(f2.Name)
|
for _, f2 := range f.Map().Fields {
|
||||||
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
|
keyword := strings.ToLower(f2.Name)
|
||||||
if isReserved {
|
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
|
||||||
c.compileReserved(attrs, f2)
|
if isReserved {
|
||||||
continue
|
c.compileReserved(attrs, f2)
|
||||||
} else if f2.Name == "style" {
|
continue
|
||||||
if f2.Map() == nil {
|
} else if f2.Name == "style" {
|
||||||
|
if f2.Map() == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c.compileStyle(attrs, f2.Map())
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
c.errorf(f2.LastRef().AST(), `source-arrowhead/target-arrowhead map keys must be reserved keywords`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.compileStyle(attrs, f2.Map())
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
c.errorf(f2.LastRef().AST(), `source-arrowhead/target-arrowhead map keys must be reserved keywords`)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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",
|
name: "edge_arrowhead_fields",
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
2
e2etests/testdata/stable/arrowhead_labels/dagre/board.exp.json
generated
vendored
2
e2etests/testdata/stable/arrowhead_labels/dagre/board.exp.json
generated
vendored
|
|
@ -91,7 +91,7 @@
|
||||||
"id": "(a -> b)[0]",
|
"id": "(a -> b)[0]",
|
||||||
"src": "a",
|
"src": "a",
|
||||||
"srcArrow": "none",
|
"srcArrow": "none",
|
||||||
"srcLabel": "",
|
"srcLabel": "1",
|
||||||
"dst": "b",
|
"dst": "b",
|
||||||
"dstArrow": "diamond",
|
"dstArrow": "diamond",
|
||||||
"dstLabel": "*",
|
"dstLabel": "*",
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 473 KiB After Width: | Height: | Size: 473 KiB |
2
e2etests/testdata/stable/arrowhead_labels/elk/board.exp.json
generated
vendored
2
e2etests/testdata/stable/arrowhead_labels/elk/board.exp.json
generated
vendored
|
|
@ -91,7 +91,7 @@
|
||||||
"id": "(a -> b)[0]",
|
"id": "(a -> b)[0]",
|
||||||
"src": "a",
|
"src": "a",
|
||||||
"srcArrow": "none",
|
"srcArrow": "none",
|
||||||
"srcLabel": "",
|
"srcLabel": "1",
|
||||||
"dst": "b",
|
"dst": "b",
|
||||||
"dstArrow": "diamond",
|
"dstArrow": "diamond",
|
||||||
"dstLabel": "*",
|
"dstLabel": "*",
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 473 KiB After Width: | Height: | Size: 473 KiB |
270
testdata/d2compiler/TestCompile/edge_arrowhead_primary.exp.json
generated
vendored
Normal file
270
testdata/d2compiler/TestCompile/edge_arrowhead_primary.exp.json
generated
vendored
Normal 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
|
||||||
|
}
|
||||||
2
testdata/d2exporter/TestExport/connection/arrowhead.exp.json
generated
vendored
2
testdata/d2exporter/TestExport/connection/arrowhead.exp.json
generated
vendored
|
|
@ -89,7 +89,7 @@
|
||||||
"id": "(x -> y)[0]",
|
"id": "(x -> y)[0]",
|
||||||
"src": "x",
|
"src": "x",
|
||||||
"srcArrow": "none",
|
"srcArrow": "none",
|
||||||
"srcLabel": "",
|
"srcLabel": "If you've done six impossible things before breakfast, why not round it",
|
||||||
"dst": "y",
|
"dst": "y",
|
||||||
"dstArrow": "filled-diamond",
|
"dstArrow": "filled-diamond",
|
||||||
"dstLabel": "A man with one watch knows what time it is.",
|
"dstLabel": "A man with one watch knows what time it is.",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue