diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 456c3cbad..56002678d 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -78,7 +78,7 @@ type PluginInfo struct { // If Type == binary then this contains the absolute path to the binary. Path string `json:"path"` - Features map[PluginFeature]struct{} `json:"features"` + Features []PluginFeature `json:"features"` } const binaryPrefix = "d2plugin-" diff --git a/d2plugin/plugin_dagre.go b/d2plugin/plugin_dagre.go index 478aca5bf..6c0237060 100644 --- a/d2plugin/plugin_dagre.go +++ b/d2plugin/plugin_dagre.go @@ -67,7 +67,6 @@ func (p dagrePlugin) Info(ctx context.Context) (*PluginInfo, error) { return &PluginInfo{ Name: "dagre", Type: "bundled", - Features: make(map[PluginFeature]struct{}), ShortHelp: "The directed graph layout library Dagre", LongHelp: fmt.Sprintf(`dagre is a directed graph layout library for JavaScript. See https://d2lang.com/tour/dagre for more. diff --git a/d2plugin/plugin_elk.go b/d2plugin/plugin_elk.go index f67af65ab..3b2113c6d 100644 --- a/d2plugin/plugin_elk.go +++ b/d2plugin/plugin_elk.go @@ -87,8 +87,8 @@ func (p elkPlugin) Info(ctx context.Context) (*PluginInfo, error) { return &PluginInfo{ Name: "elk", Type: "bundled", - Features: map[PluginFeature]struct{}{ - CONTAINER_DIMENSIONS: {}, + Features: []PluginFeature{ + CONTAINER_DIMENSIONS, }, ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.", LongHelp: fmt.Sprintf(`ELK is a layout engine offered by Eclipse. diff --git a/d2plugin/plugin_features.go b/d2plugin/plugin_features.go index 5ea4518b0..f41462b37 100644 --- a/d2plugin/plugin_features.go +++ b/d2plugin/plugin_features.go @@ -24,14 +24,19 @@ func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error { return nil } + featureMap := make(map[PluginFeature]struct{}, len(info.Features)) + for _, f := range info.Features { + featureMap[f] = struct{}{} + } + for _, obj := range g.Objects { if obj.Attributes.Top != nil || obj.Attributes.Left != nil { - if _, ok := info.Features[TOP_LEFT]; !ok { + if _, ok := featureMap[TOP_LEFT]; !ok { return fmt.Errorf(`Object "%s" has attribute "top" and/or "left" set, but layout engine "%s" does not support locked positions.`, obj.AbsID(), info.Name) } } if (obj.Attributes.Width != nil || obj.Attributes.Height != nil) && len(obj.ChildrenArray) > 0 { - if _, ok := info.Features[CONTAINER_DIMENSIONS]; !ok { + if _, ok := featureMap[CONTAINER_DIMENSIONS]; !ok { return fmt.Errorf(`Object "%s" has attribute "width" and/or "height" set, but layout engine "%s" does not support dimensions set on containers.`, obj.AbsID(), info.Name) } } @@ -39,7 +44,7 @@ func FeatureSupportCheck(info *PluginInfo, g *d2graph.Graph) error { if obj.Attributes.NearKey != nil { _, isKey := g.Root.HasChild(d2graph.Key(obj.Attributes.NearKey)) if isKey { - if _, ok := info.Features[NEAR_OBJECT]; !ok { + if _, ok := featureMap[NEAR_OBJECT]; !ok { return fmt.Errorf(`Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near".`, obj.AbsID(), info.Name) } }