Ignore BoardKeywords in d2graph and change d2ir.IDA to return from nearest board

This commit is contained in:
Anmol Sethi 2023-02-27 11:43:05 -08:00
parent f6f68518f8
commit 903bf7e206
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
8 changed files with 102 additions and 2613 deletions

View file

@ -575,6 +575,16 @@ func (obj *Object) EnsureChildIDVal(ids []string) *Object {
id := ids[0]
ids = ids[1:]
// Any IDA with layers.layer or whatever is an IR IDA.
// Such IDA's are resolved from our board root.
// See https://github.com/terrastruct/d2/pull/876
if _, ok := BoardKeywords[id]; ok {
if len(ids) == 0 {
return nil
}
return obj.EnsureChildIDVal(ids[1:])
}
var child *Object
for _, ch2 := range obj.ChildrenArray {
if ch2.IDVal == id {

View file

@ -1027,11 +1027,12 @@ func parentPrimaryKey(n Node) *d2ast.Key {
return nil
}
// IDA returns the absolute path to n from the nearest board root.
func IDA(n Node) (ida []string) {
for {
f, ok := n.(*Field)
if ok {
if f.Root() {
if f.Root() || NodeBoardKind(f) != "" {
reverseIDA(ida)
return ida
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 247 KiB

After

Width:  |  Height:  |  Size: 247 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 247 KiB

After

Width:  |  Height:  |  Size: 247 KiB

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -740,56 +740,6 @@
}
},
"zIndex": 0
},
{
"id": "layers",
"id_val": "layers",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "layers"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "one",
"id_val": "one",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "one"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
@ -1162,56 +1112,6 @@
}
},
"zIndex": 0
},
{
"id": "layers",
"id_val": "layers",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "layers"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "two",
"id_val": "two",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "two"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"steps": [
@ -1584,106 +1484,6 @@
}
},
"zIndex": 0
},
{
"id": "layers",
"id_val": "layers",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "layers"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "two",
"id_val": "two",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "two"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "steps",
"id_val": "steps",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "steps"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "seinfeld",
"id_val": "seinfeld",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "seinfeld"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
@ -2056,106 +1856,6 @@
}
},
"zIndex": 0
},
{
"id": "layers",
"id_val": "layers",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "layers"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "two",
"id_val": "two",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "two"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "steps",
"id_val": "steps",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "steps"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "missoula",
"id_val": "missoula",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "missoula"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
}

View file

@ -474,56 +474,6 @@
}
},
"zIndex": 0
},
{
"id": "layers",
"id_val": "layers",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "layers"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "one",
"id_val": "one",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "one"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
},
@ -763,56 +713,6 @@
}
},
"zIndex": 0
},
{
"id": "layers",
"id_val": "layers",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "layers"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "two",
"id_val": "two",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": "two"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
}