change to array

This commit is contained in:
Alexander Wang 2023-02-20 09:05:00 -08:00
parent 3803107c6e
commit c174efb9c4
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
4 changed files with 11 additions and 7 deletions

View file

@ -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-"

View file

@ -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.

View file

@ -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.

View file

@ -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)
}
}