Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

graphviz - How to add the direction field to a NewGroup in go-diagrams

There is a package that came out for Golang that is similar to the diagrams library in python. It generates diagrams in .dot files and then you use Graphviz to compile them.

In the beginning of a new diagram you can specify the flow direction of the whole diagram like this:

d, err := diagram.New(
    diagram.Filename("app"),
    diagram.Label("App"),
    diagram.Direction("LR"), // LR stands for LeftToRight
)

Then you can create a NewGroup like this:

db := diagram.NewGroup("DB")

The confusing part is per the codebase of go-diagrams we can add options to the func (g *Group) NewGroup(name string, opts ...GroupOption) *Group. The GroupOptions are defined as such

type GroupOptions struct {
    Label           string
    LabelJustify    string
    Direction       string
    PenColor        string
    BackgroundColor string
    Shape           string
    Style           string
    Font            Font
    Attributes      map[string]string
}

But whenever I make a new instance of that struct and pass it in as an option setting the Golang compiler crashes saying it cannot make conversion between types. How can I pass in at least a new Direction option to alter the direction of the children in a NewGroup() so that my diagram looks different?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...