From 28f4f2d7ed3044aa3cafbc5e1687666b108e2e6c Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Wed, 29 Mar 2023 15:12:00 -0700 Subject: [PATCH] Update d2target.go --- d2target/d2target.go | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/d2target/d2target.go b/d2target/d2target.go index 203c2ca09..5729354e1 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -237,6 +237,62 @@ func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point) { return Point{x1, y1}, Point{x2, y2} } +func (diagram Diagram) GetNestedCorpus() string { + corpus := diagram.GetCorpus() + for _, d := range diagram.Layers { + corpus += d.GetNestedCorpus() + } + for _, d := range diagram.Scenarios { + corpus += d.GetNestedCorpus() + } + for _, d := range diagram.Steps { + corpus += d.GetNestedCorpus() + } + + return corpus +} + +func (diagram Diagram) GetCorpus() string { + var corpus string + appendixCount := 0 + for _, s := range diagram.Shapes { + corpus += s.Label + if s.Tooltip != "" { + corpus += s.Tooltip + appendixCount++ + corpus += fmt.Sprint(appendixCount) + } + if s.Link != "" { + corpus += s.Link + appendixCount++ + corpus += fmt.Sprint(appendixCount) + } + if s.Type == ShapeClass { + for _, cf := range s.Fields { + corpus += cf.Text(0).Text + cf.VisibilityToken() + } + for _, cm := range s.Methods { + corpus += cm.Text(0).Text + cm.VisibilityToken() + } + } + if s.Type == ShapeSQLTable { + for _, c := range s.Columns { + for _, t := range c.Texts(0) { + corpus += t.Text + } + corpus += c.ConstraintAbbr() + } + } + } + for _, c := range diagram.Connections { + corpus += c.Label + corpus += c.SrcLabel + corpus += c.DstLabel + } + + return corpus +} + func NewDiagram() *Diagram { return &Diagram{ Root: Shape{