add error for dagre container-child edge

This commit is contained in:
Gavin Nishizawa 2023-02-22 12:15:59 -08:00
parent cb48ebdb81
commit a346542465
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
3 changed files with 21 additions and 0 deletions

View file

@ -1586,3 +1586,13 @@ func (g *Graph) SortEdgesByAST() {
})
g.Edges = edges
}
func (obj *Object) IsDescendantOf(ancestor *Object) bool {
if obj == ancestor {
return true
}
if obj.Parent == nil {
return false
}
return obj.Parent.IsDescendantOf(ancestor)
}

View file

@ -89,6 +89,7 @@ func (p elkPlugin) Info(ctx context.Context) (*PluginInfo, error) {
Type: "bundled",
Features: []PluginFeature{
CONTAINER_DIMENSIONS,
DESCENDANT_EDGES,
},
ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.",
LongHelp: fmt.Sprintf(`ELK is a layout engine offered by Eclipse.

View file

@ -18,6 +18,9 @@ const CONTAINER_DIMENSIONS PluginFeature = "container_dimensions"
// When this is true, objects can specify their `top` and `left` keywords
const TOP_LEFT PluginFeature = "top_left"
// When this is true, containers can have connections to descendants
const DESCENDANT_EDGES PluginFeature = "descendant_edges"
func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error {
// Older version of plugin. Skip checking.
if info.Features == nil {
@ -50,5 +53,12 @@ func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error {
}
}
}
if _, ok := featureMap[DESCENDANT_EDGES]; !ok {
for _, e := range g.Edges {
if e.Src.IsDescendantOf(e.Dst) || e.Dst.IsDescendantOf(e.Src) {
return fmt.Errorf(`Connection "%s" goes from a container to a descendant, but layout engine "%s" does not support this.`, e.AbsID(), info.Name)
}
}
}
return nil
}