d2/d2plugin/plugin_elk.go

52 lines
1.2 KiB
Go
Raw Normal View History

2022-12-03 20:15:54 +00:00
//go:build !noelk
2022-11-11 19:43:56 +00:00
package d2plugin
import (
"context"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2layouts/d2elklayout"
2022-12-30 05:09:53 +00:00
"oss.terrastruct.com/util-go/xmain"
2022-11-11 19:43:56 +00:00
)
var ELKPlugin = elkPlugin{}
func init() {
plugins = append(plugins, ELKPlugin)
}
2022-12-30 05:09:53 +00:00
type elkPlugin struct {
opts *d2elklayout.ELKLayoutOptions
}
func (p elkPlugin) HydrateOpts(ctx context.Context, opts interface{}) error {
if opts != nil {
elkOpts, ok := opts.(d2elklayout.ELKLayoutOptions)
if !ok {
return xmain.UsageErrorf("non-dagre layout options given for dagre")
}
p.opts = &elkOpts
}
return nil
}
2022-11-11 19:43:56 +00:00
func (p elkPlugin) Info(context.Context) (*PluginInfo, error) {
return &PluginInfo{
2022-11-13 03:45:36 +00:00
Name: "elk",
2022-11-11 19:43:56 +00:00
ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.",
LongHelp: `ELK is a layout engine offered by Eclipse.
Originally written in Java, it has been ported to Javascript and cross-compiled into D2.
See https://github.com/kieler/elkjs for more.`,
}, nil
}
func (p elkPlugin) Layout(ctx context.Context, g *d2graph.Graph) error {
2022-12-30 05:09:53 +00:00
return d2elklayout.Layout(ctx, g, p.opts)
2022-11-11 19:43:56 +00:00
}
func (p elkPlugin) PostProcess(ctx context.Context, in []byte) ([]byte, error) {
return in, nil
}