From 2f545e3f61342afec6b1ee828201ace3c0dbc5d0 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 22 Dec 2022 11:06:57 -0800 Subject: [PATCH 01/41] tables --- d2renderers/d2sketch/sketch.go | 170 ++++++++++++++++-- d2renderers/d2sketch/sketch_test.go | 52 ++++++ .../d2sketch/testdata/class/sketch.exp.svg | 55 ++++++ .../testdata/sql_tables/sketch.exp.svg | 75 ++++++++ d2renderers/d2svg/class.go | 7 +- d2renderers/d2svg/d2svg.go | 27 +-- d2renderers/d2svg/table.go | 26 +-- d2target/sqltable.go | 13 ++ lib/svg/text.go | 12 ++ 9 files changed, 386 insertions(+), 51 deletions(-) create mode 100644 d2renderers/d2sketch/testdata/class/sketch.exp.svg create mode 100644 d2renderers/d2sketch/testdata/sql_tables/sketch.exp.svg create mode 100644 lib/svg/text.go diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go index a8b6326b1..cbd696505 100644 --- a/d2renderers/d2sketch/sketch.go +++ b/d2renderers/d2sketch/sketch.go @@ -3,13 +3,17 @@ package d2sketch import ( "encoding/json" "fmt" + "strings" _ "embed" "github.com/dop251/goja" "oss.terrastruct.com/d2/d2target" + "oss.terrastruct.com/d2/lib/geo" + "oss.terrastruct.com/d2/lib/label" "oss.terrastruct.com/d2/lib/svg" + "oss.terrastruct.com/util-go/go2" ) //go:embed fillpattern.svg @@ -81,10 +85,7 @@ func Rect(r *Runner, shape d2target.Shape) (string, error) { strokeWidth: %d, %s });`, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) - if _, err := r.run(js); err != nil { - return "", err - } - paths, err := extractPaths(r) + paths, err := computeRoughPaths(r, js) if err != nil { return "", err } @@ -109,10 +110,7 @@ func Oval(r *Runner, shape d2target.Shape) (string, error) { strokeWidth: %d, %s });`, shape.Width/2, shape.Height/2, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) - if _, err := r.run(js); err != nil { - return "", err - } - paths, err := extractPaths(r) + paths, err := computeRoughPaths(r, js) if err != nil { return "", err } @@ -140,10 +138,7 @@ func Paths(r *Runner, shape d2target.Shape, paths []string) (string, error) { strokeWidth: %d, %s });`, path, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) - if _, err := r.run(js); err != nil { - return "", err - } - sketchPaths, err := extractPaths(r) + sketchPaths, err := computeRoughPaths(r, js) if err != nil { return "", err } @@ -180,10 +175,7 @@ func connectionStyle(connection d2target.Connection) string { func Connection(r *Runner, connection d2target.Connection, path, attrs string) (string, error) { roughness := 1.0 js := fmt.Sprintf(`node = rc.path("%s", {roughness: %f, seed: 1});`, path, roughness) - if _, err := r.run(js); err != nil { - return "", err - } - paths, err := extractPaths(r) + paths, err := computeRoughPaths(r, js) if err != nil { return "", err } @@ -197,6 +189,152 @@ func Connection(r *Runner, connection d2target.Connection, path, attrs string) ( return output, nil } +// TODO cleanup +func Table(r *Runner, shape d2target.Shape) (string, error) { + output := "" + js := fmt.Sprintf(`node = rc.rectangle(0, 0, %d, %d, { + fill: "%s", + stroke: "%s", + strokeWidth: %d, + %s + });`, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) + paths, err := computeRoughPaths(r, js) + if err != nil { + return "", err + } + for _, p := range paths { + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape), + ) + } + + box := geo.NewBox( + geo.NewPoint(float64(shape.Pos.X), float64(shape.Pos.Y)), + float64(shape.Width), + float64(shape.Height), + ) + rowHeight := box.Height / float64(1+len(shape.SQLTable.Columns)) + headerBox := geo.NewBox(box.TopLeft, box.Width, rowHeight) + + js = fmt.Sprintf(`node = rc.rectangle(0, 0, %d, %f, { + fill: "%s", + %s + });`, shape.Width, rowHeight, shape.Fill, baseRoughProps) + paths, err = computeRoughPaths(r, js) + if err != nil { + return "", err + } + for _, p := range paths { + // TODO header fill + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, "#0a0f25", + ) + } + + if shape.Label != "" { + tl := label.InsideMiddleLeft.GetPointOnBox( + headerBox, + 20, + float64(shape.LabelWidth), + float64(shape.LabelHeight), + ) + + // TODO header font color + output += fmt.Sprintf(`%s`, + "text", + tl.X, + tl.Y+float64(shape.LabelHeight)*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", + "start", + 4+shape.FontSize, + "white", + ), + svg.EscapeText(shape.Label), + ) + } + + var longestNameWidth int + for _, f := range shape.Columns { + longestNameWidth = go2.Max(longestNameWidth, f.Name.LabelWidth) + } + + rowBox := geo.NewBox(box.TopLeft.Copy(), box.Width, rowHeight) + rowBox.TopLeft.Y += headerBox.Height + for _, f := range shape.Columns { + nameTL := label.InsideMiddleLeft.GetPointOnBox( + rowBox, + d2target.NamePadding, + rowBox.Width, + float64(shape.FontSize), + ) + constraintTR := label.InsideMiddleRight.GetPointOnBox( + rowBox, + d2target.TypePadding, + 0, + float64(shape.FontSize), + ) + + // TODO theme based + primaryColor := "rgb(13, 50, 178)" + accentColor := "rgb(74, 111, 243)" + neutralColor := "rgb(103, 108, 126)" + + output += strings.Join([]string{ + fmt.Sprintf(`%s`, + nameTL.X, + nameTL.Y+float64(shape.FontSize)*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", float64(shape.FontSize), primaryColor), + svg.EscapeText(f.Name.Label), + ), + + // TODO light font + fmt.Sprintf(`%s`, + nameTL.X+float64(longestNameWidth)+2*d2target.NamePadding, + nameTL.Y+float64(shape.FontSize)*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", float64(shape.FontSize), neutralColor), + svg.EscapeText(f.Type.Label), + ), + + fmt.Sprintf(`%s`, + constraintTR.X, + constraintTR.Y+float64(shape.FontSize)*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s;letter-spacing:2px;", "end", float64(shape.FontSize), accentColor), + f.ConstraintAbbr(), + ), + }, "\n") + + rowBox.TopLeft.Y += rowHeight + + js = fmt.Sprintf(`node = rc.line(%f, %f, %f, %f, { + %s + });`, rowBox.TopLeft.X, rowBox.TopLeft.Y, rowBox.TopLeft.X+rowBox.Width, rowBox.TopLeft.Y, baseRoughProps) + paths, err = computeRoughPaths(r, js) + if err != nil { + return "", err + } + for _, p := range paths { + output += fmt.Sprintf( + ``, + p, "#0a0f25", + ) + } + } + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, shape.Width, shape.Height, + ) + return output, nil +} + +func computeRoughPaths(r *Runner, js string) ([]string, error) { + if _, err := r.run(js); err != nil { + return nil, err + } + return extractPaths(r) +} + type attrs struct { D string `json:"d"` } diff --git a/d2renderers/d2sketch/sketch_test.go b/d2renderers/d2sketch/sketch_test.go index cfcb5abdb..87a2e17a2 100644 --- a/d2renderers/d2sketch/sketch_test.go +++ b/d2renderers/d2sketch/sketch_test.go @@ -223,6 +223,58 @@ queue -> package -> step callout -> stored_data -> person diamond -> oval -> circle hexagon -> cloud +`, + }, + { + name: "sql_tables", + script: `users: { + shape: sql_table + id: int + name: string + email: string + password: string + last_login: datetime +} + +products: { + shape: sql_table + id: int + price: decimal + sku: string + name: string +} + +orders: { + shape: sql_table + id: int + user_id: int + product_id: int +} + +shipments: { + shape: sql_table + id: int + order_id: int + tracking_number: string + status: string +} + +users.id <-> orders.user_id +products.id <-> orders.product_id +shipments.order_id <-> orders.id`, + }, + { + name: "class", + script: `manager: BatchManager { + shape: class + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} `, }, } diff --git a/d2renderers/d2sketch/testdata/class/sketch.exp.svg b/d2renderers/d2sketch/testdata/class/sketch.exp.svg new file mode 100644 index 000000000..6c8175350 --- /dev/null +++ b/d2renderers/d2sketch/testdata/class/sketch.exp.svg @@ -0,0 +1,55 @@ + + + + + + +BatchManager- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +void + + + \ No newline at end of file diff --git a/d2renderers/d2sketch/testdata/sql_tables/sketch.exp.svg b/d2renderers/d2sketch/testdata/sql_tables/sketch.exp.svg new file mode 100644 index 000000000..5509ac7ab --- /dev/null +++ b/d2renderers/d2sketch/testdata/sql_tables/sketch.exp.svg @@ -0,0 +1,75 @@ + + + + + + +usersid +int +name +string +email +string +password +string +last_login +datetime +productsid +int +price +decimal +sku +string +name +string +ordersid +int +user_id +int +product_id +int +shipmentsid +int +order_id +int +tracking_number +string +status +string + + + + \ No newline at end of file diff --git a/d2renderers/d2svg/class.go b/d2renderers/d2svg/class.go index af71ac1af..64ac62bab 100644 --- a/d2renderers/d2svg/class.go +++ b/d2renderers/d2svg/class.go @@ -8,6 +8,7 @@ import ( "oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/label" + "oss.terrastruct.com/d2/lib/svg" ) func classHeader(box *geo.Box, text string, textWidth, textHeight, fontSize float64) string { @@ -32,7 +33,7 @@ func classHeader(box *geo.Box, text string, textWidth, textHeight, fontSize floa 4+fontSize, "white", ), - escapeText(text), + svg.EscapeText(text), ) } return str @@ -73,14 +74,14 @@ func classRow(box *geo.Box, prefix, nameText, typeText string, fontSize float64) prefixTL.X+prefixWidth, prefixTL.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, "black"), - escapeText(nameText), + svg.EscapeText(nameText), ), fmt.Sprintf(`%s`, typeTR.X, typeTR.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "end", fontSize, accentColor), - escapeText(typeText), + svg.EscapeText(typeText), ), }, "\n") } diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 7bd081068..896d1178e 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -5,7 +5,6 @@ package d2svg import ( "bytes" _ "embed" - "encoding/xml" "errors" "fmt" "hash/fnv" @@ -357,7 +356,7 @@ func makeLabelMask(labelTL *geo.Point, width, height int) string { } func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Connection, markers map[string]struct{}, idToShape map[string]d2target.Shape, sketchRunner *d2sketch.Runner) (labelMask string, _ error) { - fmt.Fprintf(writer, ``, escapeText(connection.ID)) + fmt.Fprintf(writer, ``, svg.EscapeText(connection.ID)) var markerStart string if connection.SrcArrow != d2target.NoArrowhead { id := arrowheadMarkerID(false, connection) @@ -536,7 +535,7 @@ func render3dRect(targetShape d2target.Shape) string { strings.Join(borderSegments, " "), borderStyle) // create mask from border stroke, to cut away from the shape fills - maskID := fmt.Sprintf("border-mask-%v", escapeText(targetShape.ID)) + maskID := fmt.Sprintf("border-mask-%v", svg.EscapeText(targetShape.ID)) borderMask := strings.Join([]string{ fmt.Sprintf(``, maskID, targetShape.Pos.X, targetShape.Pos.Y-threeDeeOffset, targetShape.Width+threeDeeOffset, targetShape.Height+threeDeeOffset, @@ -583,7 +582,7 @@ func render3dRect(targetShape d2target.Shape) string { } func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2sketch.Runner) (labelMask string, err error) { - fmt.Fprintf(writer, ``, escapeText(targetShape.ID)) + fmt.Fprintf(writer, ``, svg.EscapeText(targetShape.ID)) tl := geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)) width := float64(targetShape.Width) height := float64(targetShape.Height) @@ -622,7 +621,15 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske fmt.Fprintf(writer, ``) return labelMask, nil case d2target.ShapeSQLTable: - drawTable(writer, targetShape) + if sketchRunner != nil { + out, err := d2sketch.Table(sketchRunner, targetShape) + if err != nil { + return "", err + } + fmt.Fprintf(writer, out) + } else { + drawTable(writer, targetShape) + } fmt.Fprintf(writer, ``) return labelMask, nil case d2target.ShapeOval: @@ -823,15 +830,9 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske return labelMask, nil } -func escapeText(text string) string { - buf := new(bytes.Buffer) - _ = xml.EscapeText(buf, []byte(text)) - return buf.String() -} - func renderText(text string, x, height float64) string { if !strings.Contains(text, "\n") { - return escapeText(text) + return svg.EscapeText(text) } rendered := []string{} lines := strings.Split(text, "\n") @@ -840,7 +841,7 @@ func renderText(text string, x, height float64) string { if i == 0 { dy = 0 } - escaped := escapeText(line) + escaped := svg.EscapeText(line) if escaped == "" { // if there are multiple newlines in a row we still need text for the tspan to render escaped = " " diff --git a/d2renderers/d2svg/table.go b/d2renderers/d2svg/table.go index 9407c0b82..5b4abaed9 100644 --- a/d2renderers/d2svg/table.go +++ b/d2renderers/d2svg/table.go @@ -8,6 +8,7 @@ import ( "oss.terrastruct.com/d2/d2target" "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/label" + "oss.terrastruct.com/d2/lib/svg" "oss.terrastruct.com/util-go/go2" ) @@ -32,7 +33,7 @@ func tableHeader(box *geo.Box, text string, textWidth, textHeight, fontSize floa 4+fontSize, "white", ), - escapeText(text), + svg.EscapeText(text), ) } return str @@ -64,7 +65,7 @@ func tableRow(box *geo.Box, nameText, typeText, constraintText string, fontSize, nameTL.X, nameTL.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, primaryColor), - escapeText(nameText), + svg.EscapeText(nameText), ), // TODO light font @@ -72,7 +73,7 @@ func tableRow(box *geo.Box, nameText, typeText, constraintText string, fontSize, nameTL.X+longestNameWidth+2*d2target.NamePadding, nameTL.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, neutralColor), - escapeText(typeText), + svg.EscapeText(typeText), ), fmt.Sprintf(`%s`, @@ -84,19 +85,6 @@ func tableRow(box *geo.Box, nameText, typeText, constraintText string, fontSize, }, "\n") } -func constraintAbbr(constraint string) string { - switch constraint { - case "primary_key": - return "PK" - case "foreign_key": - return "FK" - case "unique": - return "UNQ" - default: - return "" - } -} - func drawTable(writer io.Writer, targetShape d2target.Shape) { fmt.Fprintf(writer, ``, targetShape.Pos.X, targetShape.Pos.Y, targetShape.Width, targetShape.Height, shapeStyle(targetShape)) @@ -114,15 +102,15 @@ func drawTable(writer io.Writer, targetShape d2target.Shape) { ) var longestNameWidth int - for _, f := range targetShape.SQLTable.Columns { + for _, f := range targetShape.Columns { longestNameWidth = go2.Max(longestNameWidth, f.Name.LabelWidth) } rowBox := geo.NewBox(box.TopLeft.Copy(), box.Width, rowHeight) rowBox.TopLeft.Y += headerBox.Height - for _, f := range targetShape.SQLTable.Columns { + for _, f := range targetShape.Columns { fmt.Fprint(writer, - tableRow(rowBox, f.Name.Label, f.Type.Label, constraintAbbr(f.Constraint), float64(targetShape.FontSize), float64(longestNameWidth)), + tableRow(rowBox, f.Name.Label, f.Type.Label, f.ConstraintAbbr(), float64(targetShape.FontSize), float64(longestNameWidth)), ) rowBox.TopLeft.Y += rowHeight fmt.Fprintf(writer, ``, diff --git a/d2target/sqltable.go b/d2target/sqltable.go index 8642e77a0..ad6b6f61b 100644 --- a/d2target/sqltable.go +++ b/d2target/sqltable.go @@ -31,3 +31,16 @@ func (c SQLColumn) Text() *MText { Shape: "sql_table", } } + +func (c SQLColumn) ConstraintAbbr() string { + switch c.Constraint { + case "primary_key": + return "PK" + case "foreign_key": + return "FK" + case "unique": + return "UNQ" + default: + return "" + } +} diff --git a/lib/svg/text.go b/lib/svg/text.go new file mode 100644 index 000000000..a729d5675 --- /dev/null +++ b/lib/svg/text.go @@ -0,0 +1,12 @@ +package svg + +import ( + "bytes" + "encoding/xml" +) + +func EscapeText(text string) string { + buf := new(bytes.Buffer) + _ = xml.EscapeText(buf, []byte(text)) + return buf.String() +} From c828d2c8251374ebb510e41c6384a77999c907da Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 22 Dec 2022 11:32:41 -0800 Subject: [PATCH 02/41] classes --- d2renderers/d2sketch/sketch.go | 143 ++++++++++++++++++ .../d2sketch/testdata/class/sketch.exp.svg | 14 +- d2renderers/d2svg/class.go | 31 +--- d2renderers/d2svg/d2svg.go | 10 +- d2target/class.go | 27 ++++ 5 files changed, 193 insertions(+), 32 deletions(-) diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go index cbd696505..ea3eb941c 100644 --- a/d2renderers/d2sketch/sketch.go +++ b/d2renderers/d2sketch/sketch.go @@ -328,6 +328,149 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { return output, nil } +func Class(r *Runner, shape d2target.Shape) (string, error) { + output := "" + js := fmt.Sprintf(`node = rc.rectangle(0, 0, %d, %d, { + fill: "%s", + stroke: "%s", + strokeWidth: %d, + %s + });`, shape.Width, shape.Height, shape.Fill, shape.Stroke, shape.StrokeWidth, baseRoughProps) + paths, err := computeRoughPaths(r, js) + if err != nil { + return "", err + } + for _, p := range paths { + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, shapeStyle(shape), + ) + } + + box := geo.NewBox( + geo.NewPoint(float64(shape.Pos.X), float64(shape.Pos.Y)), + float64(shape.Width), + float64(shape.Height), + ) + + rowHeight := box.Height / float64(2+len(shape.Class.Fields)+len(shape.Class.Methods)) + headerBox := geo.NewBox(box.TopLeft, box.Width, 2*rowHeight) + + js = fmt.Sprintf(`node = rc.rectangle(0, 0, %d, %f, { + fill: "%s", + %s + });`, shape.Width, headerBox.Height, shape.Fill, baseRoughProps) + paths, err = computeRoughPaths(r, js) + if err != nil { + return "", err + } + for _, p := range paths { + // TODO header fill + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, p, "#0a0f25", + ) + } + + output += fmt.Sprintf( + ``, + shape.Pos.X, shape.Pos.Y, shape.Width, headerBox.Height, + ) + + if shape.Label != "" { + tl := label.InsideMiddleLeft.GetPointOnBox( + headerBox, + 0, + float64(shape.LabelWidth), + float64(shape.LabelHeight), + ) + + // TODO header font color + output += fmt.Sprintf(`%s`, + "text", + tl.X+float64(shape.LabelWidth)/2, + tl.Y+float64(shape.LabelHeight)*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", + "middle", + 4+shape.FontSize, + "white", + ), + svg.EscapeText(shape.Label), + ) + } + + rowBox := geo.NewBox(box.TopLeft.Copy(), box.Width, rowHeight) + rowBox.TopLeft.Y += headerBox.Height + for _, f := range shape.Fields { + output += classRow(rowBox, f.VisibilityToken(), f.Name, f.Type, float64(shape.FontSize)) + rowBox.TopLeft.Y += rowHeight + } + + js = fmt.Sprintf(`node = rc.line(%f, %f, %f, %f, { +%s + });`, rowBox.TopLeft.X, rowBox.TopLeft.Y, rowBox.TopLeft.X+rowBox.Width, rowBox.TopLeft.Y, baseRoughProps) + paths, err = computeRoughPaths(r, js) + if err != nil { + return "", err + } + for _, p := range paths { + output += fmt.Sprintf( + ``, + p, "#0a0f25", + ) + } + + for _, m := range shape.Methods { + output += classRow(rowBox, m.VisibilityToken(), m.Name, m.Return, float64(shape.FontSize)) + rowBox.TopLeft.Y += rowHeight + } + + return output, nil +} + +func classRow(box *geo.Box, prefix, nameText, typeText string, fontSize float64) string { + output := "" + prefixTL := label.InsideMiddleLeft.GetPointOnBox( + box, + d2target.PrefixPadding, + box.Width, + fontSize, + ) + typeTR := label.InsideMiddleRight.GetPointOnBox( + box, + d2target.TypePadding, + 0, + fontSize, + ) + + // TODO theme based + accentColor := "rgb(13, 50, 178)" + + output += strings.Join([]string{ + fmt.Sprintf(`%s`, + prefixTL.X, + prefixTL.Y+fontSize*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, accentColor), + prefix, + ), + + fmt.Sprintf(`%s`, + prefixTL.X+d2target.PrefixWidth, + prefixTL.Y+fontSize*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, "black"), + svg.EscapeText(nameText), + ), + + fmt.Sprintf(`%s`, + typeTR.X, + typeTR.Y+fontSize*3/4, + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s;", "end", fontSize, accentColor), + svg.EscapeText(typeText), + ), + }, "\n") + return output +} + func computeRoughPaths(r *Runner, js string) ([]string, error) { if _, err := r.run(js); err != nil { return nil, err diff --git a/d2renderers/d2sketch/testdata/class/sketch.exp.svg b/d2renderers/d2sketch/testdata/class/sketch.exp.svg index 6c8175350..ed2b21d25 100644 --- a/d2renderers/d2sketch/testdata/class/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/class/sketch.exp.svg @@ -30,19 +30,19 @@ width="553" height="584" viewBox="-100 -100 553 584">abcdggggroup 1group bchoonested guy lalaeyokayokaywhat would arnold saythis note +abcdggggroup 1group bchoonested guy lalaeyokayokaywhat would arnold saythis note - - - - - + + + + + diff --git a/e2etests/testdata/stable/sequence_diagram_groups/elk/board.exp.json b/e2etests/testdata/stable/sequence_diagram_groups/elk/board.exp.json index 270198f16..776b8ddfb 100644 --- a/e2etests/testdata/stable/sequence_diagram_groups/elk/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_groups/elk/board.exp.json @@ -198,6 +198,7 @@ "underline": false, "labelWidth": 30, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, @@ -237,6 +238,7 @@ "underline": false, "labelWidth": 57, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, @@ -276,6 +278,7 @@ "underline": false, "labelWidth": 78, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, @@ -315,6 +318,7 @@ "underline": false, "labelWidth": 58, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, @@ -394,6 +398,7 @@ "underline": false, "labelWidth": 38, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, diff --git a/e2etests/testdata/stable/sequence_diagram_groups/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_groups/elk/sketch.exp.svg index 0afcfd18a..d3ed45a1a 100644 --- a/e2etests/testdata/stable/sequence_diagram_groups/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_groups/elk/sketch.exp.svg @@ -18,13 +18,13 @@ width="1147" height="2268" viewBox="-76 -26 1147 2268">abcdggggroup 1group bchoonested guy lalaeyokayokaywhat would arnold saythis note +abcdggggroup 1group bchoonested guy lalaeyokayokaywhat would arnold saythis note - - - - - + + + + + diff --git a/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/board.exp.json b/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/board.exp.json index 21f56fb8a..772cc63c2 100644 --- a/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/board.exp.json @@ -158,6 +158,7 @@ "underline": false, "labelWidth": 160, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, @@ -197,6 +198,7 @@ "underline": false, "labelWidth": 238, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, @@ -236,6 +238,7 @@ "underline": false, "labelWidth": 173, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 3 }, @@ -275,6 +278,7 @@ "underline": false, "labelWidth": 77, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 4 }, @@ -354,6 +358,7 @@ "underline": false, "labelWidth": 41, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 5 }, @@ -393,6 +398,7 @@ "underline": false, "labelWidth": 24, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, @@ -432,6 +438,7 @@ "underline": false, "labelWidth": 47, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, @@ -471,6 +478,7 @@ "underline": false, "labelWidth": 47, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, @@ -510,6 +518,7 @@ "underline": false, "labelWidth": 47, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, @@ -549,6 +558,7 @@ "underline": false, "labelWidth": 47, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, diff --git a/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/sketch.exp.svg index 0dbb0afaa..48b328e86 100644 --- a/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_nested_groups/dagre/sketch.exp.svg @@ -18,18 +18,18 @@ width="1116" height="2458" viewBox="-197 -26 1116 2458">abjust an actorthis is a message groupaltand this is a nested message groupcase 1case 2case 3case 4what about more nestingcrazy townwhoa a notea note here to remember that padding must consider notes toojustalongnotehere +abjust an actorthis is a message groupaltand this is a nested message groupcase 1case 2case 3case 4what about more nestingcrazy townwhoa a notea note here to remember that padding must consider notes toojustalongnotehere - - - - - - - - - - + + + + + + + + + + abjust an actorthis is a message groupaltand this is a nested message groupcase 1case 2case 3case 4what about more nestingcrazy townwhoa a notea note here to remember that padding must consider notes toojustalongnotehere +abjust an actorthis is a message groupaltand this is a nested message groupcase 1case 2case 3case 4what about more nestingcrazy townwhoa a notea note here to remember that padding must consider notes toojustalongnotehere - - - - - - - - - - + + + + + + + + + + How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutonly if root is not sequence 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVGmeasurements also take place +How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutonly if root is not sequence 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVGmeasurements also take place - + diff --git a/e2etests/testdata/stable/sequence_diagram_real/elk/board.exp.json b/e2etests/testdata/stable/sequence_diagram_real/elk/board.exp.json index d20a6d846..3945edf3f 100644 --- a/e2etests/testdata/stable/sequence_diagram_real/elk/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_real/elk/board.exp.json @@ -478,6 +478,7 @@ "underline": false, "labelWidth": 185, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, diff --git a/e2etests/testdata/stable/sequence_diagram_real/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_real/elk/sketch.exp.svg index 364fb5549..5f4dd359a 100644 --- a/e2etests/testdata/stable/sequence_diagram_real/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_real/elk/sketch.exp.svg @@ -18,9 +18,9 @@ width="2447" height="2536" viewBox="-88 -88 2447 2536">How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutonly if root is not sequence 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVGmeasurements also take place +How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutonly if root is not sequence 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVGmeasurements also take place - + diff --git a/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/board.exp.json b/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/board.exp.json index c0f384c07..d20401f87 100644 --- a/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/board.exp.json +++ b/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/board.exp.json @@ -158,6 +158,7 @@ "underline": false, "labelWidth": 160, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 1 }, @@ -197,6 +198,7 @@ "underline": false, "labelWidth": 238, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 2 }, @@ -236,6 +238,7 @@ "underline": false, "labelWidth": 173, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 3 }, @@ -275,6 +278,7 @@ "underline": false, "labelWidth": 21, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 4 }, @@ -314,6 +318,7 @@ "underline": false, "labelWidth": 21, "labelHeight": 26, + "labelPosition": "INSIDE_TOP_LEFT", "zIndex": 3, "level": 5 } diff --git a/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/sketch.exp.svg b/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/sketch.exp.svg index 288cab1f2..5bcd47f78 100644 --- a/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/sketch.exp.svg +++ b/e2etests/testdata/todo/sequence_diagram_actor_padding_nested_groups/dagre/sketch.exp.svg @@ -18,13 +18,13 @@ width="921" height="1242" viewBox="-147 -26 921 1242">bacthis is a message groupand this is a nested message groupwhat about more nestingyoyo +bacthis is a message groupand this is a nested message groupwhat about more nestingyoyo - - - - - + + + + + bacthis is a message groupand this is a nested message groupwhat about more nestingyoyo +bacthis is a message groupand this is a nested message groupwhat about more nestingyoyo - - - - - + + + + + my network + + + \ No newline at end of file diff --git a/e2etests/testdata/regression/query_param_escape/elk/board.exp.json b/e2etests/testdata/regression/query_param_escape/elk/board.exp.json new file mode 100644 index 000000000..bce062b6f --- /dev/null +++ b/e2etests/testdata/regression/query_param_escape/elk/board.exp.json @@ -0,0 +1,58 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "my network", + "type": "", + "pos": { + "x": 12, + "y": 12 + }, + "width": 190, + "height": 152, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": { + "Scheme": "https", + "Opaque": "", + "User": null, + "Host": "icons.terrastruct.com", + "Path": "/infra/019-network.svg", + "RawPath": "", + "ForceQuery": false, + "RawQuery": "fuga=1&hoge", + "Fragment": "", + "RawFragment": "" + }, + "iconPosition": "INSIDE_MIDDLE_CENTER", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "my network", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 90, + "labelHeight": 26, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [] +} diff --git a/e2etests/testdata/regression/query_param_escape/elk/sketch.exp.svg b/e2etests/testdata/regression/query_param_escape/elk/sketch.exp.svg new file mode 100644 index 000000000..0a13f7b0b --- /dev/null +++ b/e2etests/testdata/regression/query_param_escape/elk/sketch.exp.svg @@ -0,0 +1,31 @@ + +my network + + + \ No newline at end of file From 0fa4ee84aa5b8ca5be3689204f49d951343792aa Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 12:47:25 -0800 Subject: [PATCH 15/41] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index dded33175..f96223703 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -16,5 +16,6 @@ - Fixed an issue where text could overflow in sql_table shapes. [#458](https://github.com/terrastruct/d2/pull/458) - Fixed an issue with elk layouts accounting for edge labels as if they were placed on the side of the edge. [#483](https://github.com/terrastruct/d2/pull/483) - Fixed an issue where dagre layouts may not have enough spacing for all edge labels. [#484](https://github.com/terrastruct/d2/pull/484) +- Icons with query parameters are now being escaped to valid SVG XML. [#438](https://github.com/terrastruct/d2/issues/438) - Fixed connections being clipped if they were at the very top or left edges of the diagram. [#493](https://github.com/terrastruct/d2/pull/493) - Fixed edge case where style being defined in same scope as sql_table caused compiler to skip compiling sql_table. [#506](https://github.com/terrastruct/d2/issues/506) From 3a6834662dca19902d342185181d9846c62f087b Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 13:11:45 -0800 Subject: [PATCH 16/41] fix sql constraint array panic --- d2compiler/compile.go | 4 ++++ d2compiler/compile_test.go | 10 ++++++++++ testdata/d2compiler/TestCompile/sql-panic.exp.json | 12 ++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/sql-panic.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 819dae9e3..9ca656098 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -688,6 +688,10 @@ func (c *compiler) compileSQLTable(obj *d2graph.Object) { continue } if n.MapKey.Key.Path[0].Unbox().ScalarString() == "constraint" { + if n.MapKey.Value.StringBox().Unbox() == nil { + c.errorf(n.MapKey.GetRange().Start, n.MapKey.GetRange().End, "constraint value must be a string") + return + } d2Col.Constraint = n.MapKey.Value.StringBox().Unbox().ScalarString() } } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 4009aa68b..afe9ceec4 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1668,6 +1668,16 @@ choo: { tassert.Equal(t, 3, len(g.Objects)) }, }, + { + name: "sql-panic", + text: `test { + shape: sql_table + test_id: varchar(64) {constraint: [primary_key, foreign_key]} +} +`, + expErr: `d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string +`, + }, } for _, tc := range testCases { diff --git a/testdata/d2compiler/TestCompile/sql-panic.exp.json b/testdata/d2compiler/TestCompile/sql-panic.exp.json new file mode 100644 index 000000000..c65b828a6 --- /dev/null +++ b/testdata/d2compiler/TestCompile/sql-panic.exp.json @@ -0,0 +1,12 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/sql-panic.d2,2:26:54-2:64:92", + "errmsg": "d2/testdata/d2compiler/TestCompile/sql-panic.d2:3:27: constraint value must be a string" + } + ] + } +} From fb2e0827d33cb635aeb5b8317b55f49909c8a1d5 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 13:12:53 -0800 Subject: [PATCH 17/41] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index f96223703..0f99d4538 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -19,3 +19,4 @@ - Icons with query parameters are now being escaped to valid SVG XML. [#438](https://github.com/terrastruct/d2/issues/438) - Fixed connections being clipped if they were at the very top or left edges of the diagram. [#493](https://github.com/terrastruct/d2/pull/493) - Fixed edge case where style being defined in same scope as sql_table caused compiler to skip compiling sql_table. [#506](https://github.com/terrastruct/d2/issues/506) +- Fixed panic when `constraint` value was not a string value. [#248](https://github.com/terrastruct/d2/issues/248) From 03e27abb5429155b5d4653ee3d235841fbbbe7c3 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 13:34:23 -0800 Subject: [PATCH 18/41] elk force order --- d2layouts/d2elklayout/layout.go | 32 +- e2etests/regression_test.go | 37 + .../dagre_special_ids/elk/board.exp.json | 34 +- .../dagre_special_ids/elk/sketch.exp.svg | 2 +- .../elk_alignment/elk/board.exp.json | 60 +- .../elk_alignment/elk/sketch.exp.svg | 18 +- .../regression/elk_order/dagre/board.exp.json | 675 ++++++ .../regression/elk_order/dagre/sketch.exp.svg | 799 +++++++ .../regression/elk_order/elk/board.exp.json | 639 ++++++ .../regression/elk_order/elk/sketch.exp.svg | 799 +++++++ .../stable/all_shapes/elk/board.exp.json | 78 +- .../stable/all_shapes/elk/sketch.exp.svg | 6 +- .../all_shapes_multiple/elk/board.exp.json | 78 +- .../all_shapes_multiple/elk/sketch.exp.svg | 6 +- .../all_shapes_shadow/elk/board.exp.json | 78 +- .../all_shapes_shadow/elk/sketch.exp.svg | 6 +- .../stable/binary_tree/elk/board.exp.json | 150 +- .../stable/binary_tree/elk/sketch.exp.svg | 2 +- .../testdata/stable/chaos2/elk/board.exp.json | 236 +- .../testdata/stable/chaos2/elk/sketch.exp.svg | 28 +- .../testdata/stable/dense/elk/board.exp.json | 404 ++-- .../testdata/stable/dense/elk/sketch.exp.svg | 6 +- .../different_subgraphs/elk/board.exp.json | 164 +- .../different_subgraphs/elk/sketch.exp.svg | 6 +- .../stable/font_sizes/elk/board.exp.json | 36 +- .../stable/font_sizes/elk/sketch.exp.svg | 12 +- .../stable/investigate/elk/board.exp.json | 392 ++-- .../stable/investigate/elk/sketch.exp.svg | 18 +- .../stable/large_arch/elk/board.exp.json | 324 ++- .../stable/large_arch/elk/sketch.exp.svg | 6 +- .../testdata/stable/latex/elk/board.exp.json | 60 +- .../testdata/stable/latex/elk/sketch.exp.svg | 4 +- .../stable/multiple_trees/elk/board.exp.json | 226 +- .../stable/multiple_trees/elk/sketch.exp.svg | 6 +- .../stable/n22_e32/elk/board.exp.json | 412 ++-- .../stable/n22_e32/elk/sketch.exp.svg | 6 +- .../one_container_loop/elk/board.exp.json | 58 +- .../one_container_loop/elk/sketch.exp.svg | 2 +- .../elk/board.exp.json | 44 +- .../elk/sketch.exp.svg | 2 +- .../self-referencing/elk/board.exp.json | 54 +- .../self-referencing/elk/sketch.exp.svg | 8 +- .../stable/sql_tables/elk/board.exp.json | 28 +- .../stable/sql_tables/elk/sketch.exp.svg | 66 +- .../elk/board.exp.json | 214 +- .../elk/sketch.exp.svg | 6 +- .../testdata/stable/us_map/elk/board.exp.json | 1900 ++++++++--------- .../testdata/stable/us_map/elk/sketch.exp.svg | 6 +- 48 files changed, 5589 insertions(+), 2644 deletions(-) create mode 100644 e2etests/testdata/regression/elk_order/dagre/board.exp.json create mode 100644 e2etests/testdata/regression/elk_order/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/regression/elk_order/elk/board.exp.json create mode 100644 e2etests/testdata/regression/elk_order/elk/sketch.exp.svg diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index be40c6bff..18dd392f7 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -79,14 +79,16 @@ type ELKGraph struct { } type ELKLayoutOptions struct { - Algorithm string `json:"elk.algorithm,omitempty"` - HierarchyHandling string `json:"elk.hierarchyHandling,omitempty"` - NodeSpacing float64 `json:"spacing.nodeNodeBetweenLayers,omitempty"` - Padding string `json:"elk.padding,omitempty"` - EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"` - Direction string `json:"elk.direction"` - SelfLoopSpacing float64 `json:"elk.spacing.nodeSelfLoop"` - InlineEdgeLabels bool `json:"elk.edgeLabels.inline,omitempty"` + Algorithm string `json:"elk.algorithm,omitempty"` + HierarchyHandling string `json:"elk.hierarchyHandling,omitempty"` + NodeSpacing float64 `json:"spacing.nodeNodeBetweenLayers,omitempty"` + Padding string `json:"elk.padding,omitempty"` + EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"` + Direction string `json:"elk.direction"` + SelfLoopSpacing float64 `json:"elk.spacing.nodeSelfLoop"` + InlineEdgeLabels bool `json:"elk.edgeLabels.inline,omitempty"` + ConsiderModelOrder string `json:"elk.layered.considerModelOrder.strategy,omitempty"` + ForceNodeModelOrder bool `json:"elk.layered.crossingMinimization.forceNodeModelOrder,omitempty"` } func Layout(ctx context.Context, g *d2graph.Graph) (err error) { @@ -109,11 +111,12 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { elkGraph := &ELKGraph{ ID: "root", LayoutOptions: &ELKLayoutOptions{ - Algorithm: "layered", - HierarchyHandling: "INCLUDE_CHILDREN", - NodeSpacing: 100.0, - EdgeNodeSpacing: 50.0, - SelfLoopSpacing: 50.0, + Algorithm: "layered", + HierarchyHandling: "INCLUDE_CHILDREN", + NodeSpacing: 100.0, + EdgeNodeSpacing: 50.0, + SelfLoopSpacing: 50.0, + ConsiderModelOrder: "NODES_AND_EDGES", }, } switch g.Root.Attributes.Direction.Value { @@ -157,7 +160,8 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { if len(obj.ChildrenArray) > 0 { n.LayoutOptions = &ELKLayoutOptions{ - Padding: "[top=75,left=75,bottom=75,right=75]", + Padding: "[top=75,left=75,bottom=75,right=75]", + ForceNodeModelOrder: true, } } diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go index 966e03af2..d3fe777b6 100644 --- a/e2etests/regression_test.go +++ b/e2etests/regression_test.go @@ -178,6 +178,43 @@ build_workflow: lambda-build.yaml { script: `my network: { icon: https://icons.terrastruct.com/infra/019-network.svg?fuga=1&hoge } +`, + }, + { + name: "elk_order", + script: `queue: { + shape: queue + label: '' + + M0 + M1 + M2 + M3 + M4 + M5 + M6 +} + +m0_desc: |md + Oldest message +| +m0_desc -> queue.M0 + +m2_desc: |md + Offset +| +m2_desc -> queue.M2 + +m5_desc: |md + Last message +| +m5_desc -> queue.M5 + +m6_desc: |md + Next message will be\ + inserted here +| +m6_desc -> queue.M6 `, }, } diff --git a/e2etests/testdata/regression/dagre_special_ids/elk/board.exp.json b/e2etests/testdata/regression/dagre_special_ids/elk/board.exp.json index bd21d8cc7..d74b1feb5 100644 --- a/e2etests/testdata/regression/dagre_special_ids/elk/board.exp.json +++ b/e2etests/testdata/regression/dagre_special_ids/elk/board.exp.json @@ -6,7 +6,7 @@ "id": "\"ninety\\nnine\"", "type": "", "pos": { - "x": 714, + "x": 12, "y": 12 }, "width": 151, @@ -46,7 +46,7 @@ "id": "eighty\reight", "type": "", "pos": { - "x": 194, + "x": 183, "y": 20 }, "width": 151, @@ -86,7 +86,7 @@ "id": "\"seventy\r\\nseven\"", "type": "", "pos": { - "x": 12, + "x": 354, "y": 12 }, "width": 162, @@ -126,7 +126,7 @@ "id": "\"a\\\\yode\"", "type": "", "pos": { - "x": 885, + "x": 536, "y": 28 }, "width": 154, @@ -166,7 +166,7 @@ "id": "there", "type": "", "pos": { - "x": 546, + "x": 716, "y": 254 }, "width": 143, @@ -206,7 +206,7 @@ "id": "'a\\\"ode'", "type": "", "pos": { - "x": 540, + "x": 710, "y": 28 }, "width": 154, @@ -246,7 +246,7 @@ "id": "\"a\\\\node\"", "type": "", "pos": { - "x": 365, + "x": 884, "y": 28 }, "width": 155, @@ -310,19 +310,19 @@ "labelPercentage": 0, "route": [ { - "x": 962, + "x": 613, "y": 154 }, { - "x": 962, + "x": 613, "y": 204 }, { - "x": 652.75, + "x": 751.25, "y": 204 }, { - "x": 652.75, + "x": 751.25, "y": 254 } ], @@ -357,11 +357,11 @@ "labelPercentage": 0, "route": [ { - "x": 617, + "x": 787, "y": 154 }, { - "x": 617, + "x": 787, "y": 254 } ], @@ -396,19 +396,19 @@ "labelPercentage": 0, "route": [ { - "x": 442.5, + "x": 961.5, "y": 154 }, { - "x": 442.5, + "x": 961.5, "y": 204 }, { - "x": 581.25, + "x": 822.75, "y": 204 }, { - "x": 581.25, + "x": 822.75, "y": 254 } ], diff --git a/e2etests/testdata/regression/dagre_special_ids/elk/sketch.exp.svg b/e2etests/testdata/regression/dagre_special_ids/elk/sketch.exp.svg index fb14b30ee..985f6ad4e 100644 --- a/e2etests/testdata/regression/dagre_special_ids/elk/sketch.exp.svg +++ b/e2etests/testdata/regression/dagre_special_ids/elk/sketch.exp.svg @@ -18,7 +18,7 @@ width="1227" height="568" viewBox="-88 -88 1227 568">ninetynineeighty eightseventy sevena\yodetherea\"odea\node +ninetynineeighty eightseventy sevena\yodetherea\"odea\node lambda-build.yamllambda-deploy.yamlapollo-deploy.yamlPush to main branchGitHub ActionsS3TerraformAWSManual TriggerGitHub ActionsAWSApollo RepoGitHub ActionsAWS TriggersBuilds zip and pushes it Pulls zip to deployChanges live lambdasLaunchesBuilds zippushes them to S3. Deploys lambdasusing TerraformTriggered manually/push to master test test test test test test testtest +lambda-build.yamllambda-deploy.yamlapollo-deploy.yamlPush to main branchGitHub ActionsS3TerraformAWSManual TriggerGitHub ActionsAWSApollo RepoGitHub ActionsAWS TriggersBuilds zip and pushes it Pulls zip to deployChanges live lambdasLaunchesBuilds zippushes them to S3. Deploys lambdasusing TerraformTriggered manually/push to master test test test test test test testtest - - - - - - - - + + + + + + + +

Oldest message

+

Offset

+

Last message

+

Next message will be
+inserted here

+
M0M1M2M3M4M5M6 + + + \ No newline at end of file diff --git a/e2etests/testdata/regression/elk_order/elk/board.exp.json b/e2etests/testdata/regression/elk_order/elk/board.exp.json new file mode 100644 index 000000000..10c667ae8 --- /dev/null +++ b/e2etests/testdata/regression/elk_order/elk/board.exp.json @@ -0,0 +1,639 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "queue", + "type": "queue", + "pos": { + "x": 12, + "y": 165 + }, + "width": 1146, + "height": 276, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#DEE1EB", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "zIndex": 0, + "level": 1 + }, + { + "id": "queue.M0", + "type": "", + "pos": { + "x": 87, + "y": 240 + }, + "width": 125, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M0", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 25, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "queue.M1", + "type": "", + "pos": { + "x": 232, + "y": 240 + }, + "width": 125, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M1", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 25, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "queue.M2", + "type": "", + "pos": { + "x": 377, + "y": 240 + }, + "width": 125, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M2", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 25, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "queue.M3", + "type": "", + "pos": { + "x": 522, + "y": 240 + }, + "width": 125, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M3", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 25, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "queue.M4", + "type": "", + "pos": { + "x": 667, + "y": 240 + }, + "width": 126, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M4", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 26, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "queue.M5", + "type": "", + "pos": { + "x": 813, + "y": 240 + }, + "width": 125, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M5", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 25, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "queue.M6", + "type": "", + "pos": { + "x": 958, + "y": 240 + }, + "width": 125, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "M6", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 25, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "m0_desc", + "type": "text", + "pos": { + "x": 97, + "y": 36 + }, + "width": 106, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "Oldest message", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 106, + "labelHeight": 24, + "zIndex": 0, + "level": 1 + }, + { + "id": "m2_desc", + "type": "text", + "pos": { + "x": 419, + "y": 36 + }, + "width": 41, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "Offset", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 41, + "labelHeight": 24, + "zIndex": 0, + "level": 1 + }, + { + "id": "m5_desc", + "type": "text", + "pos": { + "x": 831, + "y": 36 + }, + "width": 90, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "Last message", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 90, + "labelHeight": 24, + "zIndex": 0, + "level": 1 + }, + { + "id": "m6_desc", + "type": "text", + "pos": { + "x": 951, + "y": 12 + }, + "width": 140, + "height": 48, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "Next message will be\\\ninserted here", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 140, + "labelHeight": 48, + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(m0_desc -> queue.M0)[0]", + "src": "m0_desc", + "srcArrow": "none", + "srcLabel": "", + "dst": "queue.M0", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 149.5, + "y": 60 + }, + { + "x": 149.5, + "y": 240 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(m2_desc -> queue.M2)[0]", + "src": "m2_desc", + "srcArrow": "none", + "srcLabel": "", + "dst": "queue.M2", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 439.5, + "y": 60 + }, + { + "x": 439.5, + "y": 240 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(m5_desc -> queue.M5)[0]", + "src": "m5_desc", + "srcArrow": "none", + "srcLabel": "", + "dst": "queue.M5", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 875.5, + "y": 60 + }, + { + "x": 875.5, + "y": 240 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(m6_desc -> queue.M6)[0]", + "src": "m6_desc", + "srcArrow": "none", + "srcLabel": "", + "dst": "queue.M6", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 1020.5, + "y": 60 + }, + { + "x": 1020.5, + "y": 240 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg b/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg new file mode 100644 index 000000000..63a3b016e --- /dev/null +++ b/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg @@ -0,0 +1,799 @@ + +

Oldest message

+

Offset

+

Last message

+

Next message will be
+inserted here

+
M0M1M2M3M4M5M6 + + +
\ No newline at end of file diff --git a/e2etests/testdata/stable/all_shapes/elk/board.exp.json b/e2etests/testdata/stable/all_shapes/elk/board.exp.json index bb4e1b59a..1e9044c30 100644 --- a/e2etests/testdata/stable/all_shapes/elk/board.exp.json +++ b/e2etests/testdata/stable/all_shapes/elk/board.exp.json @@ -6,7 +6,7 @@ "id": "rectangle", "type": "rectangle", "pos": { - "x": 769, + "x": 12, "y": 12 }, "width": 171, @@ -46,7 +46,7 @@ "id": "square", "type": "rectangle", "pos": { - "x": 778, + "x": 21, "y": 238 }, "width": 154, @@ -86,7 +86,7 @@ "id": "page", "type": "page", "pos": { - "x": 785, + "x": 28, "y": 492 }, "width": 139, @@ -126,7 +126,7 @@ "id": "parallelogram", "type": "parallelogram", "pos": { - "x": 960, + "x": 203, "y": 12 }, "width": 204, @@ -166,7 +166,7 @@ "id": "document", "type": "document", "pos": { - "x": 974, + "x": 217, "y": 252 }, "width": 177, @@ -206,7 +206,7 @@ "id": "cylinder", "type": "cylinder", "pos": { - "x": 980, + "x": 223, "y": 492 }, "width": 164, @@ -246,7 +246,7 @@ "id": "queue", "type": "queue", "pos": { - "x": 19, + "x": 427, "y": 12 }, "width": 149, @@ -286,7 +286,7 @@ "id": "package", "type": "package", "pos": { - "x": 12, + "x": 420, "y": 252 }, "width": 163, @@ -326,7 +326,7 @@ "id": "step", "type": "step", "pos": { - "x": 26, + "x": 434, "y": 492 }, "width": 136, @@ -366,7 +366,7 @@ "id": "callout", "type": "callout", "pos": { - "x": 213, + "x": 621, "y": 12 }, "width": 155, @@ -406,7 +406,7 @@ "id": "stored_data", "type": "stored_data", "pos": { - "x": 195, + "x": 603, "y": 252 }, "width": 191, @@ -446,7 +446,7 @@ "id": "person", "type": "person", "pos": { - "x": 214, + "x": 622, "y": 492 }, "width": 153, @@ -486,7 +486,7 @@ "id": "diamond", "type": "diamond", "pos": { - "x": 581, + "x": 798, "y": 12 }, "width": 168, @@ -526,7 +526,7 @@ "id": "oval", "type": "oval", "pos": { - "x": 597, + "x": 814, "y": 252 }, "width": 136, @@ -566,7 +566,7 @@ "id": "circle", "type": "oval", "pos": { - "x": 593, + "x": 810, "y": 492 }, "width": 144, @@ -606,7 +606,7 @@ "id": "hexagon", "type": "hexagon", "pos": { - "x": 396, + "x": 986, "y": 12 }, "width": 165, @@ -646,7 +646,7 @@ "id": "cloud", "type": "cloud", "pos": { - "x": 406, + "x": 996, "y": 238 }, "width": 145, @@ -710,11 +710,11 @@ "labelPercentage": 0, "route": [ { - "x": 854.5, + "x": 97.5, "y": 138 }, { - "x": 854.5, + "x": 97.5, "y": 238 } ], @@ -749,11 +749,11 @@ "labelPercentage": 0, "route": [ { - "x": 854.5, + "x": 97.5, "y": 392 }, { - "x": 855, + "x": 98, "y": 492 } ], @@ -788,11 +788,11 @@ "labelPercentage": 0, "route": [ { - "x": 1062, + "x": 305, "y": 138 }, { - "x": 1062, + "x": 305, "y": 252 } ], @@ -827,11 +827,11 @@ "labelPercentage": 0, "route": [ { - "x": 1062, + "x": 305, "y": 361 }, { - "x": 1062, + "x": 305, "y": 492 } ], @@ -866,11 +866,11 @@ "labelPercentage": 0, "route": [ { - "x": 93, + "x": 501, "y": 138 }, { - "x": 94, + "x": 502, "y": 252 } ], @@ -905,11 +905,11 @@ "labelPercentage": 0, "route": [ { - "x": 93, + "x": 501, "y": 378 }, { - "x": 94, + "x": 502, "y": 492 } ], @@ -944,11 +944,11 @@ "labelPercentage": 0, "route": [ { - "x": 291, + "x": 699, "y": 138 }, { - "x": 291, + "x": 699, "y": 252 } ], @@ -983,11 +983,11 @@ "labelPercentage": 0, "route": [ { - "x": 290, + "x": 698, "y": 378 }, { - "x": 291, + "x": 699, "y": 492 } ], @@ -1022,11 +1022,11 @@ "labelPercentage": 0, "route": [ { - "x": 665, + "x": 882, "y": 138 }, { - "x": 665, + "x": 882, "y": 252 } ], @@ -1061,11 +1061,11 @@ "labelPercentage": 0, "route": [ { - "x": 665, + "x": 882, "y": 378 }, { - "x": 665, + "x": 882, "y": 492 } ], @@ -1100,11 +1100,11 @@ "labelPercentage": 0, "route": [ { - "x": 478, + "x": 1068, "y": 138 }, { - "x": 479, + "x": 1069, "y": 240 } ], diff --git a/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg b/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg index 197d3d968..bbdb6ed74 100644 --- a/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/all_shapes/elk/sketch.exp.svg @@ -2,7 +2,7 @@ rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud + rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud - +rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud + abcdefghijklmno +abcdefghijklmno abcdefghijklmnopq - +abcdefghijklmnopq + finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot - +finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot + size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 - - - - +size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 + + + + aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 - - - - - - - +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 + + + + + + + abcdefghiqrjmnoszaabbeeffggklptuwxyccddv - +abcdefghiqrjmnoszaabbeeffggklptuwxyccddv + abcdefghijklmnopqrstuvw - +abcdefghijklmnopqrstuvw + abcdefghijklmnopqrstu - +abcdefghijklmnopqrstu + acdefgbh +acdefgbh topabcbottomstartend +topabcbottomstartend xyz hello - - +xyz hello + + usersid -int -name -string -email -string -password -string -last_login -datetime -productsid -int -price -decimal -sku -string -name -string -ordersid -int -user_id -int -product_id -int -shipmentsid -int -order_id -int -tracking_number -string -status -string - +usersid +int +name +string +email +string +password +string +last_login +datetime +productsid +int +price +decimal +sku +string +name +string +ordersid +int +user_id +int +product_id +int +shipmentsid +int +order_id +int +tracking_number +string +status +string + acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc - +acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc + AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTND - +AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTND + ninetynineeighty eightseventy sevena\yodetherea\"odea\node +ninetynineeighty eightseventy sevena\yodetherea\"odea\node lambda-build.yamllambda-deploy.yamlapollo-deploy.yamlPush to main branchGitHub ActionsS3TerraformAWSManual TriggerGitHub ActionsAWSApollo RepoGitHub ActionsAWS TriggersBuilds zip and pushes it Pulls zip to deployChanges live lambdasLaunchesBuilds zippushes them to S3. Deploys lambdasusing TerraformTriggered manually/push to master test test test test test test testtest +lambda-build.yamllambda-deploy.yamlapollo-deploy.yamlPush to main branchGitHub ActionsS3TerraformAWSManual TriggerGitHub ActionsAWSApollo RepoGitHub ActionsAWS TriggersBuilds zip and pushes it Pulls zip to deployChanges live lambdasLaunchesBuilds zippushes them to S3. Deploys lambdasusing TerraformTriggered manually/push to master test test test test test test testtest diff --git a/e2etests/testdata/regression/elk_order/elk/board.exp.json b/e2etests/testdata/regression/elk_order/elk/board.exp.json index 10c667ae8..e17d4ca0f 100644 --- a/e2etests/testdata/regression/elk_order/elk/board.exp.json +++ b/e2etests/testdata/regression/elk_order/elk/board.exp.json @@ -325,7 +325,7 @@ "id": "m0_desc", "type": "text", "pos": { - "x": 97, + "x": 96, "y": 36 }, "width": 106, @@ -403,7 +403,7 @@ "id": "m5_desc", "type": "text", "pos": { - "x": 831, + "x": 830, "y": 36 }, "width": 90, @@ -442,7 +442,7 @@ "id": "m6_desc", "type": "text", "pos": { - "x": 951, + "x": 950, "y": 12 }, "width": 140, diff --git a/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg b/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg index 63a3b016e..1088ee5a3 100644 --- a/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg +++ b/e2etests/testdata/regression/elk_order/elk/sketch.exp.svg @@ -774,12 +774,12 @@ width="1346" height="629" viewBox="-88 -88 1346 629">

Oldest message

+

Oldest message

Offset

-

Last message

-

Next message will be
+

Last message

+

Next message will be
inserted here

-
M0M1M2M3M4M5M6 +
M0M1M2M3M4M5M6 abc +abc acbd +acbd rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud +rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud +rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud cba * +cba * abcdefghijklmno +abcdefghijklmno acfbdhg +acfbdhg abcdefghijklmnopq +abcdefghijklmnopq finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot - +finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot + bacde21345abcde +bacde21345abcde alphabeta gamma +alphabeta gamma size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 - +size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 + diff --git a/e2etests/testdata/stable/hr/elk/board.exp.json b/e2etests/testdata/stable/hr/elk/board.exp.json index 81bb926e0..b2afa8a49 100644 --- a/e2etests/testdata/stable/hr/elk/board.exp.json +++ b/e2etests/testdata/stable/hr/elk/board.exp.json @@ -45,7 +45,7 @@ "id": "a", "type": "", "pos": { - "x": 325, + "x": 324, "y": 12 }, "width": 113, @@ -85,7 +85,7 @@ "id": "b", "type": "", "pos": { - "x": 325, + "x": 324, "y": 472 }, "width": 113, diff --git a/e2etests/testdata/stable/hr/elk/sketch.exp.svg b/e2etests/testdata/stable/hr/elk/sketch.exp.svg index d4f060f54..d7373ac08 100644 --- a/e2etests/testdata/stable/hr/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/hr/elk/sketch.exp.svg @@ -778,7 +778,7 @@ width="938" height="786" viewBox="-88 -88 938 786">

Overview

-ab +ab aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 - +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 + - + diff --git a/e2etests/testdata/stable/large_arch/elk/board.exp.json b/e2etests/testdata/stable/large_arch/elk/board.exp.json index d8dcaec74..ca38024d5 100644 --- a/e2etests/testdata/stable/large_arch/elk/board.exp.json +++ b/e2etests/testdata/stable/large_arch/elk/board.exp.json @@ -166,7 +166,7 @@ "id": "e", "type": "", "pos": { - "x": 856, + "x": 855, "y": 2394 }, "width": 113, @@ -326,7 +326,7 @@ "id": "i", "type": "", "pos": { - "x": 665, + "x": 664, "y": 1301 }, "width": 683, @@ -366,7 +366,7 @@ "id": "i.j", "type": "", "pos": { - "x": 879, + "x": 878, "y": 1376 }, "width": 392, @@ -406,7 +406,7 @@ "id": "i.j.k", "type": "", "pos": { - "x": 954, + "x": 953, "y": 1451 }, "width": 113, @@ -446,7 +446,7 @@ "id": "i.j.l", "type": "", "pos": { - "x": 1087, + "x": 1086, "y": 1451 }, "width": 109, @@ -486,8 +486,8 @@ "id": "i.m", "type": "", "pos": { - "x": 740, - "y": 1774 + "x": 739, + "y": 1773 }, "width": 117, "height": 126, @@ -526,7 +526,7 @@ "id": "i.n", "type": "", "pos": { - "x": 877, + "x": 876, "y": 1832 }, "width": 113, @@ -566,7 +566,7 @@ "id": "i.o", "type": "", "pos": { - "x": 1010, + "x": 1009, "y": 1682 }, "width": 263, @@ -606,7 +606,7 @@ "id": "i.o.p", "type": "", "pos": { - "x": 1085, + "x": 1084, "y": 1757 }, "width": 113, @@ -887,7 +887,7 @@ "type": "", "pos": { "x": 710, - "y": 687 + "y": 686 }, "width": 118, "height": 126, @@ -926,7 +926,7 @@ "id": "r.s.x", "type": "", "pos": { - "x": 694, + "x": 693, "y": 463 }, "width": 113, @@ -966,7 +966,7 @@ "id": "r.s.y", "type": "", "pos": { - "x": 827, + "x": 826, "y": 463 }, "width": 114, @@ -1046,7 +1046,7 @@ "id": "r.aa", "type": "", "pos": { - "x": 262, + "x": 261, "y": 237 }, "width": 122, @@ -1086,7 +1086,7 @@ "id": "r.bb", "type": "", "pos": { - "x": 404, + "x": 403, "y": 87 }, "width": 415, @@ -1126,7 +1126,7 @@ "id": "r.bb.cc", "type": "", "pos": { - "x": 479, + "x": 478, "y": 162 }, "width": 121, @@ -1166,7 +1166,7 @@ "id": "r.bb.dd", "type": "", "pos": { - "x": 620, + "x": 619, "y": 162 }, "width": 124, @@ -1246,7 +1246,7 @@ "id": "r.ff", "type": "", "pos": { - "x": 1036, + "x": 1035, "y": 388 }, "width": 117, @@ -1350,19 +1350,19 @@ "labelPercentage": 0, "route": [ { - "x": 1010.5, + "x": 1010.25, "y": 1577 }, { - "x": 1010.5, + "x": 1010.25, "y": 1667 }, { - "x": 827.75, + "x": 827.5, "y": 1667 }, { - "x": 827.75, + "x": 827.5, "y": 1773.875 } ], @@ -1397,11 +1397,11 @@ "labelPercentage": 0, "route": [ { - "x": 1141.5, + "x": 1141.25, "y": 1577 }, { - "x": 1141.5, + "x": 1141.25, "y": 1757 } ], diff --git a/e2etests/testdata/stable/large_arch/elk/sketch.exp.svg b/e2etests/testdata/stable/large_arch/elk/sketch.exp.svg index c8f91e3ba..f1dae3dd3 100644 --- a/e2etests/testdata/stable/large_arch/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/large_arch/elk/sketch.exp.svg @@ -18,7 +18,7 @@ width="1694" height="2708" viewBox="-88 -88 1694 2708">abcdefghiqrjmnoszaabbeeffggklptuwxyccddv +abcdefghiqrjmnoszaabbeeffggklptuwxyccddv mixed togethersugarsolution we get +mixed togethersugarsolution we get

Markdown: Syntax

-
ab +ab

code

-
ab +

code

+
ab abcdefghijklmnopqrstuvw - +abcdefghijklmnopqrstuvw + abcdefghijklmnopqrstu +abcdefghijklmnopqrstu Foo Baz12hello - +Foo Baz12hello + acdefgbh +acdefgbh topabcbottomstartend - +topabcbottomstartend + rootcontainerrootleftrightrootinnerrootinnerleftrightleftright to inner leftto inner rightto inner leftto inner rightto left container rootto right container root +rootcontainerrootleftrightrootinnerrootinnerleftrightleftright to inner leftto inner rightto inner leftto inner rightto left container rootto right container root diff --git a/e2etests/testdata/stable/pre/elk/board.exp.json b/e2etests/testdata/stable/pre/elk/board.exp.json index df945bd32..f04cb489d 100644 --- a/e2etests/testdata/stable/pre/elk/board.exp.json +++ b/e2etests/testdata/stable/pre/elk/board.exp.json @@ -45,7 +45,7 @@ "id": "a", "type": "", "pos": { - "x": 257, + "x": 256, "y": 12 }, "width": 113, @@ -85,7 +85,7 @@ "id": "b", "type": "", "pos": { - "x": 257, + "x": 256, "y": 508 }, "width": 113, diff --git a/e2etests/testdata/stable/pre/elk/sketch.exp.svg b/e2etests/testdata/stable/pre/elk/sketch.exp.svg index 440472676..2d38f4dc0 100644 --- a/e2etests/testdata/stable/pre/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/pre/elk/sketch.exp.svg @@ -781,7 +781,7 @@ end tell

A code block continues until it reaches a line that is not indented (or the end of the article).

-ab +ab xyz hello +xyz hello a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) +a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/square_3d/elk/board.exp.json b/e2etests/testdata/stable/square_3d/elk/board.exp.json index e1679a64f..dbcd20694 100644 --- a/e2etests/testdata/stable/square_3d/elk/board.exp.json +++ b/e2etests/testdata/stable/square_3d/elk/board.exp.json @@ -46,7 +46,7 @@ "id": "square", "type": "rectangle", "pos": { - "x": 21, + "x": 20, "y": 238 }, "width": 154, diff --git a/e2etests/testdata/stable/square_3d/elk/sketch.exp.svg b/e2etests/testdata/stable/square_3d/elk/sketch.exp.svg index 6c9a95e26..c052bafe0 100644 --- a/e2etests/testdata/stable/square_3d/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/square_3d/elk/sketch.exp.svg @@ -20,9 +20,9 @@ width="371" height="580" viewBox="-88 -88 371 580"> -rectangle - -square +rectangle + +square AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTND +AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTND eightsixteenthirty twosixty fourninety nine twelvetwenty fourforty eighteighty one +eightsixteenthirty twosixty fourninety nine twelvetwenty fourforty eighteighty one From 4e7665b2520c957446ee2ee094bfca466922d39a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 13:42:34 -0800 Subject: [PATCH 20/41] add changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 0f99d4538..79c22bf5f 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -9,6 +9,7 @@ - Improved label placements for shapes with images to avoid overlapping container labels. [#474](https://github.com/terrastruct/d2/pull/474) - Sequence diagram edge group labels have more reasonable padding. [#512](https://github.com/terrastruct/d2/pull/512) +- ELK layout engine preserves order of nodes. [#282](https://github.com/terrastruct/d2/issues/282) #### Bugfixes ⛑️ From 64d7d5f1b6cb065792a5a855cb814ad9512d971a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 15:56:22 -0800 Subject: [PATCH 21/41] apply themes to tables and classes --- d2exporter/export.go | 5 ++ d2graph/d2graph.go | 10 ++- d2renderers/d2sketch/sketch.go | 56 ++++++-------- d2renderers/d2sketch/sketch_test.go | 2 +- .../d2sketch/testdata/class/sketch.exp.svg | 26 +++---- .../testdata/sql_tables/sketch.exp.svg | 70 +++++++++--------- d2renderers/d2svg/class.go | 25 +++---- d2renderers/d2svg/d2svg.go | 12 ++- d2renderers/d2svg/table.go | 28 +++---- d2target/d2target.go | 5 ++ e2etests/stable_test.go | 2 +- .../sql_table_overflow/dagre/board.exp.json | 18 +++-- .../sql_table_overflow/dagre/sketch.exp.svg | 18 ++--- .../sql_table_overflow/elk/board.exp.json | 18 +++-- .../sql_table_overflow/elk/sketch.exp.svg | 18 ++--- .../stable/class/dagre/board.exp.json | 9 ++- .../stable/class/dagre/sketch.exp.svg | 26 +++---- .../testdata/stable/class/elk/board.exp.json | 9 ++- .../testdata/stable/class/elk/sketch.exp.svg | 26 +++---- .../dagre/board.exp.json | 14 +++- .../dagre/sketch.exp.svg | 20 ++--- .../elk/board.exp.json | 14 +++- .../elk/sketch.exp.svg | 20 ++--- .../stable/sql_tables/dagre/board.exp.json | 74 +++++++++++-------- .../stable/sql_tables/dagre/sketch.exp.svg | 70 +++++++++--------- .../stable/sql_tables/elk/board.exp.json | 66 ++++++++++------- .../stable/sql_tables/elk/sketch.exp.svg | 70 +++++++++--------- 27 files changed, 397 insertions(+), 334 deletions(-) diff --git a/d2exporter/export.go b/d2exporter/export.go index 73a6e37bd..1eb2e6445 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -40,6 +40,11 @@ func applyTheme(shape *d2target.Shape, obj *d2graph.Object, theme *d2themes.Them if obj.Attributes.Shape.Value == d2target.ShapeText { shape.Color = theme.Colors.Neutrals.N1 } + if obj.Attributes.Shape.Value == d2target.ShapeSQLTable || obj.Attributes.Shape.Value == d2target.ShapeClass { + shape.PrimaryAccentColor = theme.Colors.B2 + shape.SecondaryAccentColor = theme.Colors.AA2 + shape.NeutralAccentColor = theme.Colors.Neutrals.N2 + } } func applyStyles(shape *d2target.Shape, obj *d2graph.Object) { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index f0ad6e1f7..9f7d6fd3a 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -392,17 +392,23 @@ func (obj *Object) GetFill(theme *d2themes.Theme) string { return theme.Colors.Neutrals.N5 } + if strings.EqualFold(shape, d2target.ShapeSQLTable) || strings.EqualFold(shape, d2target.ShapeClass) { + return theme.Colors.Neutrals.N1 + } + return theme.Colors.Neutrals.N7 } func (obj *Object) GetStroke(theme *d2themes.Theme, dashGapSize interface{}) string { shape := obj.Attributes.Shape.Value if strings.EqualFold(shape, d2target.ShapeCode) || - strings.EqualFold(shape, d2target.ShapeClass) || - strings.EqualFold(shape, d2target.ShapeSQLTable) || strings.EqualFold(shape, d2target.ShapeText) { return theme.Colors.Neutrals.N1 } + if strings.EqualFold(shape, d2target.ShapeClass) || + strings.EqualFold(shape, d2target.ShapeSQLTable) { + return theme.Colors.Neutrals.N7 + } if dashGapSize != 0.0 { return theme.Colors.B2 } diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go index ea3eb941c..afb71c87f 100644 --- a/d2renderers/d2sketch/sketch.go +++ b/d2renderers/d2sketch/sketch.go @@ -66,8 +66,13 @@ func DefineFillPattern() string { func shapeStyle(shape d2target.Shape) string { out := "" - out += fmt.Sprintf(`fill:%s;`, shape.Fill) - out += fmt.Sprintf(`stroke:%s;`, shape.Stroke) + if shape.Type == d2target.ShapeSQLTable || shape.Type == d2target.ShapeClass { + out += fmt.Sprintf(`fill:%s;`, shape.Stroke) + out += fmt.Sprintf(`stroke:%s;`, shape.Fill) + } else { + out += fmt.Sprintf(`fill:%s;`, shape.Fill) + out += fmt.Sprintf(`stroke:%s;`, shape.Stroke) + } out += fmt.Sprintf(`opacity:%f;`, shape.Opacity) out += fmt.Sprintf(`stroke-width:%d;`, shape.StrokeWidth) if shape.StrokeDash != 0 { @@ -226,10 +231,9 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { return "", err } for _, p := range paths { - // TODO header fill output += fmt.Sprintf( ``, - shape.Pos.X, shape.Pos.Y, p, "#0a0f25", + shape.Pos.X, shape.Pos.Y, p, shape.Fill, ) } @@ -241,7 +245,6 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { float64(shape.LabelHeight), ) - // TODO header font color output += fmt.Sprintf(`%s`, "text", tl.X, @@ -249,7 +252,7 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", 4+shape.FontSize, - "white", + shape.Stroke, ), svg.EscapeText(shape.Label), ) @@ -276,31 +279,23 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { float64(shape.FontSize), ) - // TODO theme based - primaryColor := "rgb(13, 50, 178)" - accentColor := "rgb(74, 111, 243)" - neutralColor := "rgb(103, 108, 126)" - output += strings.Join([]string{ fmt.Sprintf(`%s`, nameTL.X, nameTL.Y+float64(shape.FontSize)*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", float64(shape.FontSize), primaryColor), + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", float64(shape.FontSize), shape.PrimaryAccentColor), svg.EscapeText(f.Name.Label), ), - - // TODO light font fmt.Sprintf(`%s`, nameTL.X+float64(longestNameWidth)+2*d2target.NamePadding, nameTL.Y+float64(shape.FontSize)*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", float64(shape.FontSize), neutralColor), + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", float64(shape.FontSize), shape.NeutralAccentColor), svg.EscapeText(f.Type.Label), ), - fmt.Sprintf(`%s`, constraintTR.X, constraintTR.Y+float64(shape.FontSize)*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s;letter-spacing:2px;", "end", float64(shape.FontSize), accentColor), + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s;letter-spacing:2px;", "end", float64(shape.FontSize), shape.SecondaryAccentColor), f.ConstraintAbbr(), ), }, "\n") @@ -316,8 +311,8 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { } for _, p := range paths { output += fmt.Sprintf( - ``, - p, "#0a0f25", + ``, + p, shape.Fill, ) } } @@ -365,10 +360,9 @@ func Class(r *Runner, shape d2target.Shape) (string, error) { return "", err } for _, p := range paths { - // TODO header fill output += fmt.Sprintf( ``, - shape.Pos.X, shape.Pos.Y, p, "#0a0f25", + shape.Pos.X, shape.Pos.Y, p, shape.Fill, ) } @@ -385,7 +379,6 @@ func Class(r *Runner, shape d2target.Shape) (string, error) { float64(shape.LabelHeight), ) - // TODO header font color output += fmt.Sprintf(`%s`, "text", tl.X+float64(shape.LabelWidth)/2, @@ -393,7 +386,7 @@ func Class(r *Runner, shape d2target.Shape) (string, error) { fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", 4+shape.FontSize, - "white", + shape.Stroke, ), svg.EscapeText(shape.Label), ) @@ -402,7 +395,7 @@ func Class(r *Runner, shape d2target.Shape) (string, error) { rowBox := geo.NewBox(box.TopLeft.Copy(), box.Width, rowHeight) rowBox.TopLeft.Y += headerBox.Height for _, f := range shape.Fields { - output += classRow(rowBox, f.VisibilityToken(), f.Name, f.Type, float64(shape.FontSize)) + output += classRow(shape, rowBox, f.VisibilityToken(), f.Name, f.Type, float64(shape.FontSize)) rowBox.TopLeft.Y += rowHeight } @@ -416,19 +409,19 @@ func Class(r *Runner, shape d2target.Shape) (string, error) { for _, p := range paths { output += fmt.Sprintf( ``, - p, "#0a0f25", + p, shape.Fill, ) } for _, m := range shape.Methods { - output += classRow(rowBox, m.VisibilityToken(), m.Name, m.Return, float64(shape.FontSize)) + output += classRow(shape, rowBox, m.VisibilityToken(), m.Name, m.Return, float64(shape.FontSize)) rowBox.TopLeft.Y += rowHeight } return output, nil } -func classRow(box *geo.Box, prefix, nameText, typeText string, fontSize float64) string { +func classRow(shape d2target.Shape, box *geo.Box, prefix, nameText, typeText string, fontSize float64) string { output := "" prefixTL := label.InsideMiddleLeft.GetPointOnBox( box, @@ -443,28 +436,25 @@ func classRow(box *geo.Box, prefix, nameText, typeText string, fontSize float64) fontSize, ) - // TODO theme based - accentColor := "rgb(13, 50, 178)" - output += strings.Join([]string{ fmt.Sprintf(`%s`, prefixTL.X, prefixTL.Y+fontSize*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, accentColor), + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, shape.PrimaryAccentColor), prefix, ), fmt.Sprintf(`%s`, prefixTL.X+d2target.PrefixWidth, prefixTL.Y+fontSize*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, "black"), + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, shape.Fill), svg.EscapeText(nameText), ), fmt.Sprintf(`%s`, typeTR.X, typeTR.Y+fontSize*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s;", "end", fontSize, accentColor), + fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s;", "end", fontSize, shape.SecondaryAccentColor), svg.EscapeText(typeText), ), }, "\n") diff --git a/d2renderers/d2sketch/sketch_test.go b/d2renderers/d2sketch/sketch_test.go index 87a2e17a2..e033bedfe 100644 --- a/d2renderers/d2sketch/sketch_test.go +++ b/d2renderers/d2sketch/sketch_test.go @@ -255,7 +255,7 @@ shipments: { shape: sql_table id: int order_id: int - tracking_number: string + tracking_number: string {constraint: primary_key} status: string } diff --git a/d2renderers/d2sketch/testdata/class/sketch.exp.svg b/d2renderers/d2sketch/testdata/class/sketch.exp.svg index ed2b21d25..827658e48 100644 --- a/d2renderers/d2sketch/testdata/class/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/class/sketch.exp.svg @@ -30,19 +30,19 @@ width="553" height="584" viewBox="-100 -100 553 584">sql_table_overflowshort -loooooooooooooooooooong -loooooooooooooooooooong -short -sql_table_constrained_overflowshort -loooooooooooooooooooong -UNQloooooooooooooooooooong -short -FK +sql_table_overflowshort +loooooooooooooooooooong +loooooooooooooooooooong +short +sql_table_constrained_overflowshort +loooooooooooooooooooong +UNQloooooooooooooooooooong +short +FK sql_table_overflowshort -loooooooooooooooooooong -loooooooooooooooooooong -short -sql_table_constrained_overflowshort -loooooooooooooooooooong -UNQloooooooooooooooooooong -short -FK +sql_table_overflowshort +loooooooooooooooooooong +loooooooooooooooooooong +short +sql_table_constrained_overflowshort +loooooooooooooooooooong +UNQloooooooooooooooooooong +short +FK BatchManager- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -void +BatchManager- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +void BatchManager- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -void +BatchManager- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +void a labelblabelsa class+ -public() bool -void- -private() int -voidcloudyyyy:= 5 +a labelblabelsa class+ +public() bool +void- +private() int +voidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid -int -name -varchar - result := callThisFunction(obj, 5) midthis sideother side +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid +int +name +varchar + result := callThisFunction(obj, 5) midthis sideother side diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json index 61504c34e..4b77fb8ae 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json @@ -96,7 +96,7 @@ "strokeWidth": 2, "borderRadius": 0, "fill": "#EDF0FD", - "stroke": "#0A0F25", + "stroke": "#FFFFFF", "shadow": false, "3d": false, "multiple": false, @@ -131,7 +131,10 @@ "labelHeight": 36, "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, - "level": 1 + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" }, { "id": "d", @@ -798,7 +801,7 @@ "strokeWidth": 2, "borderRadius": 0, "fill": "#EDF0FD", - "stroke": "#0A0F25", + "stroke": "#FFFFFF", "shadow": false, "3d": false, "multiple": false, @@ -879,7 +882,10 @@ "labelHeight": 36, "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, - "level": 1 + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" } ], "connections": [ diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg index c23490a3e..c059492d0 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg @@ -18,17 +18,17 @@ width="5120" height="2984" viewBox="-76 -26 5120 2984">a labelblabelsa class+ -public() bool -void- -private() int -voidcloudyyyy:= 5 +a labelblabelsa class+ +public() bool +void- +private() int +voidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid -int -name -varchar - result := callThisFunction(obj, 5) midthis sideother side +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid +int +name +varchar + result := callThisFunction(obj, 5) midthis sideother side diff --git a/e2etests/testdata/stable/sql_tables/dagre/board.exp.json b/e2etests/testdata/stable/sql_tables/dagre/board.exp.json index a3b85c40e..0fd37e978 100644 --- a/e2etests/testdata/stable/sql_tables/dagre/board.exp.json +++ b/e2etests/testdata/stable/sql_tables/dagre/board.exp.json @@ -9,14 +9,14 @@ "x": 0, "y": 0 }, - "width": 208, + "width": 268, "height": 216, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "#FFFFFF", - "stroke": "#0A0F25", + "fill": "#0A0F25", + "stroke": "#FFFFFF", "shadow": false, "3d": false, "multiple": false, @@ -165,7 +165,7 @@ "labelWidth": 77, "labelHeight": 26 }, - "constraint": "", + "constraint": "primary_key", "reference": "" } ], @@ -180,13 +180,16 @@ "labelWidth": 61, "labelHeight": 36, "zIndex": 0, - "level": 1 + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" }, { "id": "products", "type": "sql_table", "pos": { - "x": 268, + "x": 328, "y": 18 }, "width": 164, @@ -195,8 +198,8 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "#FFFFFF", - "stroke": "#0A0F25", + "fill": "#0A0F25", + "stroke": "#FFFFFF", "shadow": false, "3d": false, "multiple": false, @@ -332,13 +335,16 @@ "labelWidth": 99, "labelHeight": 36, "zIndex": 0, - "level": 1 + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" }, { "id": "orders", "type": "sql_table", "pos": { - "x": 268, + "x": 328, "y": 316 }, "width": 164, @@ -347,8 +353,8 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "#FFFFFF", - "stroke": "#0A0F25", + "fill": "#0A0F25", + "stroke": "#FFFFFF", "shadow": false, "3d": false, "multiple": false, @@ -456,13 +462,16 @@ "labelWidth": 74, "labelHeight": 36, "zIndex": 0, - "level": 1 + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" }, { "id": "shipments", "type": "sql_table", "pos": { - "x": 492, + "x": 552, "y": 18 }, "width": 244, @@ -471,8 +480,8 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "#FFFFFF", - "stroke": "#0A0F25", + "fill": "#0A0F25", + "stroke": "#FFFFFF", "shadow": false, "3d": false, "multiple": false, @@ -608,7 +617,10 @@ "labelWidth": 116, "labelHeight": 36, "zIndex": 0, - "level": 1 + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" } ], "connections": [ @@ -638,20 +650,20 @@ "labelPercentage": 0, "route": [ { - "x": 104, + "x": 134, "y": 216 }, { - "x": 104, + "x": 134, "y": 256 }, { - "x": 136.8, - "y": 282.2 + "x": 172.8, + "y": 283.2 }, { - "x": 268, - "y": 347 + "x": 328, + "y": 352 } ], "isCurve": true, @@ -686,19 +698,19 @@ "labelPercentage": 0, "route": [ { - "x": 350, + "x": 410, "y": 198 }, { - "x": 350, + "x": 410, "y": 252.4 }, { - "x": 350, + "x": 410, "y": 276 }, { - "x": 350, + "x": 410, "y": 316 } ], @@ -734,19 +746,19 @@ "labelPercentage": 0, "route": [ { - "x": 614, + "x": 674, "y": 198 }, { - "x": 614, + "x": 674, "y": 252.4 }, { - "x": 577.6, + "x": 637.6, "y": 282.8 }, { - "x": 432, + "x": 492, "y": 350 } ], diff --git a/e2etests/testdata/stable/sql_tables/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_tables/dagre/sketch.exp.svg index d6087ea8a..8b78b0f66 100644 --- a/e2etests/testdata/stable/sql_tables/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_tables/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ usersid +int +name +string +email +string +password +string +last_login +datetime +PKproductsid +int +price +decimal +sku +string +name +string +ordersid +int +user_id +int +product_id +int +shipmentsid +int +order_id +int +tracking_number +string +status +string + + usersid -int -name -string -email -string -password -string -last_login -datetime -productsid -int -price -decimal -sku -string -name -string -ordersid -int -user_id -int -product_id -int -shipmentsid -int -order_id -int -tracking_number -string -status -string - - +usersid +int +name +string +email +string +password +string +last_login +datetime +PKproductsid +int +price +decimal +sku +string +name +string +ordersid +int +user_id +int +product_id +int +shipmentsid +int +order_id +int +tracking_number +string +status +string + + \ No newline at end of file diff --git a/d2renderers/d2svg/class.go b/d2renderers/d2svg/class.go index 8e8f707ed..85205db32 100644 --- a/d2renderers/d2svg/class.go +++ b/d2renderers/d2svg/class.go @@ -24,11 +24,10 @@ func classHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex ) str += fmt.Sprintf(`%s`, - // TODO use monospace font - "text", + "text-mono", tl.X+textWidth/2, tl.Y+textHeight*3/4, - fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", + fmt.Sprintf(`text-anchor:%s;font-size:%vpx;fill:%s`, "middle", 4+fontSize, shape.Stroke, @@ -56,21 +55,21 @@ func classRow(shape d2target.Shape, box *geo.Box, prefix, nameText, typeText str ) return strings.Join([]string{ - fmt.Sprintf(`%s`, + fmt.Sprintf(`%s`, prefixTL.X, prefixTL.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, shape.PrimaryAccentColor), prefix, ), - fmt.Sprintf(`%s`, + fmt.Sprintf(`%s`, prefixTL.X+d2target.PrefixWidth, prefixTL.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "start", fontSize, shape.Fill), svg.EscapeText(nameText), ), - fmt.Sprintf(`%s`, + fmt.Sprintf(`%s`, typeTR.X, typeTR.Y+fontSize*3/4, fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "end", fontSize, shape.SecondaryAccentColor), diff --git a/e2etests/testdata/stable/class/dagre/board.exp.json b/e2etests/testdata/stable/class/dagre/board.exp.json index 41edbb9ad..ada2bfc60 100644 --- a/e2etests/testdata/stable/class/dagre/board.exp.json +++ b/e2etests/testdata/stable/class/dagre/board.exp.json @@ -9,7 +9,7 @@ "x": 0, "y": 0 }, - "width": 339, + "width": 422, "height": 368, "opacity": 1, "strokeDash": 0, @@ -68,7 +68,7 @@ "italic": false, "bold": false, "underline": false, - "labelWidth": 150, + "labelWidth": 175, "labelHeight": 36, "zIndex": 0, "level": 1, diff --git a/e2etests/testdata/stable/class/dagre/sketch.exp.svg b/e2etests/testdata/stable/class/dagre/sketch.exp.svg index e016700c8..f47e1aea0 100644 --- a/e2etests/testdata/stable/class/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/class/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ BatchManager- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +void + \ No newline at end of file diff --git a/e2etests/testdata/stable/class/elk/board.exp.json b/e2etests/testdata/stable/class/elk/board.exp.json index b6a2b2864..438953ee7 100644 --- a/e2etests/testdata/stable/class/elk/board.exp.json +++ b/e2etests/testdata/stable/class/elk/board.exp.json @@ -9,7 +9,7 @@ "x": 12, "y": 12 }, - "width": 339, + "width": 422, "height": 368, "opacity": 1, "strokeDash": 0, @@ -68,7 +68,7 @@ "italic": false, "bold": false, "underline": false, - "labelWidth": 150, + "labelWidth": 175, "labelHeight": 36, "zIndex": 0, "level": 1, diff --git a/e2etests/testdata/stable/class/elk/sketch.exp.svg b/e2etests/testdata/stable/class/elk/sketch.exp.svg index 522347026..a433f42f0 100644 --- a/e2etests/testdata/stable/class/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/class/elk/sketch.exp.svg @@ -2,7 +2,7 @@ BatchManager- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +void + \ No newline at end of file From ae2f75890bf7ed8351753e637fbded53df5de9d0 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 16:19:09 -0800 Subject: [PATCH 24/41] fix class header --- d2graph/d2graph.go | 3 + .../dagre/board.exp.json | 182 +++++++++--------- .../dagre/sketch.exp.svg | 26 +-- .../elk/board.exp.json | 182 +++++++++--------- .../elk/sketch.exp.svg | 26 +-- 5 files changed, 211 insertions(+), 208 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 956244dc9..e60aa17c0 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -457,6 +457,9 @@ func (obj *Object) Text() *d2target.MText { if obj.Class != nil || obj.SQLTable != nil { fontSize = d2fonts.FONT_SIZE_XL } + if obj.Class != nil { + isBold = false + } return &d2target.MText{ Text: obj.Attributes.Label.Value, FontSize: fontSize, diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json index 4b77fb8ae..42c5c962e 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json @@ -86,10 +86,10 @@ "id": "c", "type": "class", "pos": { - "x": 486, + "x": 481, "y": 74 }, - "width": 241, + "width": 302, "height": 184, "opacity": 1, "strokeDash": 0, @@ -127,7 +127,7 @@ "italic": false, "bold": false, "underline": false, - "labelWidth": 71, + "labelWidth": 104, "labelHeight": 36, "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, @@ -140,7 +140,7 @@ "id": "d", "type": "cloud", "pos": { - "x": 777, + "x": 833, "y": 132 }, "width": 174, @@ -180,7 +180,7 @@ "id": "e", "type": "code", "pos": { - "x": 1016, + "x": 1072, "y": 188 }, "width": 196, @@ -220,7 +220,7 @@ "id": "f", "type": "cylinder", "pos": { - "x": 1289, + "x": 1345, "y": 132 }, "width": 150, @@ -260,7 +260,7 @@ "id": "g", "type": "diamond", "pos": { - "x": 1539, + "x": 1595, "y": 132 }, "width": 150, @@ -300,7 +300,7 @@ "id": "h", "type": "document", "pos": { - "x": 1789, + "x": 1845, "y": 132 }, "width": 150, @@ -340,7 +340,7 @@ "id": "i", "type": "hexagon", "pos": { - "x": 2025, + "x": 2082, "y": 132 }, "width": 177, @@ -380,7 +380,7 @@ "id": "j", "type": "image", "pos": { - "x": 2289, + "x": 2345, "y": 109 }, "width": 150, @@ -431,7 +431,7 @@ "id": "k", "type": "oval", "pos": { - "x": 2539, + "x": 2595, "y": 132 }, "width": 150, @@ -471,7 +471,7 @@ "id": "l", "type": "package", "pos": { - "x": 2789, + "x": 2845, "y": 132 }, "width": 150, @@ -511,7 +511,7 @@ "id": "m", "type": "page", "pos": { - "x": 3027, + "x": 3084, "y": 132 }, "width": 173, @@ -551,7 +551,7 @@ "id": "n", "type": "parallelogram", "pos": { - "x": 3275, + "x": 3332, "y": 116 }, "width": 177, @@ -591,7 +591,7 @@ "id": "o", "type": "person", "pos": { - "x": 3538, + "x": 3595, "y": 79 }, "width": 151, @@ -631,7 +631,7 @@ "id": "p", "type": "queue", "pos": { - "x": 3784, + "x": 3841, "y": 132 }, "width": 159, @@ -671,7 +671,7 @@ "id": "q", "type": "rectangle", "pos": { - "x": 4032, + "x": 4089, "y": 95 }, "width": 163, @@ -711,7 +711,7 @@ "id": "r", "type": "step", "pos": { - "x": 4260, + "x": 4317, "y": 132 }, "width": 207, @@ -751,7 +751,7 @@ "id": "s", "type": "stored_data", "pos": { - "x": 4539, + "x": 4595, "y": 132 }, "width": 150, @@ -791,7 +791,7 @@ "id": "t", "type": "sql_table", "pos": { - "x": 4783, + "x": 4840, "y": 150 }, "width": 161, @@ -958,7 +958,7 @@ "y": 518 }, { - "x": 606.5, + "x": 632, "y": 518 } ], @@ -993,11 +993,11 @@ "labelPercentage": 0, "route": [ { - "x": 606.5, + "x": 632, "y": 648 }, { - "x": 864, + "x": 920, "y": 648 } ], @@ -1032,11 +1032,11 @@ "labelPercentage": 0, "route": [ { - "x": 864, + "x": 920, "y": 778 }, { - "x": 1114, + "x": 1170, "y": 778 } ], @@ -1071,11 +1071,11 @@ "labelPercentage": 0, "route": [ { - "x": 1114, + "x": 1170, "y": 908 }, { - "x": 1364, + "x": 1420, "y": 908 } ], @@ -1110,11 +1110,11 @@ "labelPercentage": 0, "route": [ { - "x": 1364, + "x": 1420, "y": 1038 }, { - "x": 1614, + "x": 1670, "y": 1038 } ], @@ -1149,11 +1149,11 @@ "labelPercentage": 0, "route": [ { - "x": 1614, + "x": 1670, "y": 1168 }, { - "x": 1864, + "x": 1920, "y": 1168 } ], @@ -1188,11 +1188,11 @@ "labelPercentage": 0, "route": [ { - "x": 1864, + "x": 1920, "y": 1298 }, { - "x": 2113.5, + "x": 2170.5, "y": 1298 } ], @@ -1227,11 +1227,11 @@ "labelPercentage": 0, "route": [ { - "x": 2113.5, + "x": 2170.5, "y": 1428 }, { - "x": 2364, + "x": 2420, "y": 1428 } ], @@ -1266,11 +1266,11 @@ "labelPercentage": 0, "route": [ { - "x": 2364, + "x": 2420, "y": 1558 }, { - "x": 2614, + "x": 2670, "y": 1558 } ], @@ -1305,11 +1305,11 @@ "labelPercentage": 0, "route": [ { - "x": 2614, + "x": 2670, "y": 1688 }, { - "x": 2864, + "x": 2920, "y": 1688 } ], @@ -1344,11 +1344,11 @@ "labelPercentage": 0, "route": [ { - "x": 2864, + "x": 2920, "y": 1818 }, { - "x": 3113.5, + "x": 3170.5, "y": 1818 } ], @@ -1383,11 +1383,11 @@ "labelPercentage": 0, "route": [ { - "x": 3113.5, + "x": 3170.5, "y": 1948 }, { - "x": 3363.5, + "x": 3420.5, "y": 1948 } ], @@ -1422,11 +1422,11 @@ "labelPercentage": 0, "route": [ { - "x": 3363.5, + "x": 3420.5, "y": 2078 }, { - "x": 3613.5, + "x": 3670.5, "y": 2078 } ], @@ -1461,11 +1461,11 @@ "labelPercentage": 0, "route": [ { - "x": 3613.5, + "x": 3670.5, "y": 2208 }, { - "x": 3863.5, + "x": 3920.5, "y": 2208 } ], @@ -1500,11 +1500,11 @@ "labelPercentage": 0, "route": [ { - "x": 3863.5, + "x": 3920.5, "y": 2338 }, { - "x": 4113.5, + "x": 4170.5, "y": 2338 } ], @@ -1539,11 +1539,11 @@ "labelPercentage": 0, "route": [ { - "x": 4113.5, + "x": 4170.5, "y": 2468 }, { - "x": 4363.5, + "x": 4420.5, "y": 2468 } ], @@ -1578,11 +1578,11 @@ "labelPercentage": 0, "route": [ { - "x": 4363.5, + "x": 4420.5, "y": 2598 }, { - "x": 4614, + "x": 4670, "y": 2598 } ], @@ -1617,11 +1617,11 @@ "labelPercentage": 0, "route": [ { - "x": 4614, + "x": 4670, "y": 2728 }, { - "x": 4863.5, + "x": 4920.5, "y": 2728 } ], @@ -1734,11 +1734,11 @@ "labelPercentage": 0, "route": [ { - "x": 606.5, + "x": 632, "y": 258 }, { - "x": 606.5, + "x": 632, "y": 2858 } ], @@ -1773,11 +1773,11 @@ "labelPercentage": 0, "route": [ { - "x": 864, + "x": 920, "y": 258 }, { - "x": 864, + "x": 920, "y": 2858 } ], @@ -1812,11 +1812,11 @@ "labelPercentage": 0, "route": [ { - "x": 1114, + "x": 1170, "y": 258 }, { - "x": 1114, + "x": 1170, "y": 2858 } ], @@ -1851,11 +1851,11 @@ "labelPercentage": 0, "route": [ { - "x": 1364, + "x": 1420, "y": 258 }, { - "x": 1364, + "x": 1420, "y": 2858 } ], @@ -1890,11 +1890,11 @@ "labelPercentage": 0, "route": [ { - "x": 1614, + "x": 1670, "y": 258 }, { - "x": 1614, + "x": 1670, "y": 2858 } ], @@ -1929,11 +1929,11 @@ "labelPercentage": 0, "route": [ { - "x": 1864, + "x": 1920, "y": 258 }, { - "x": 1864, + "x": 1920, "y": 2858 } ], @@ -1968,11 +1968,11 @@ "labelPercentage": 0, "route": [ { - "x": 2113.5, + "x": 2170.5, "y": 258 }, { - "x": 2113.5, + "x": 2170.5, "y": 2858 } ], @@ -2007,11 +2007,11 @@ "labelPercentage": 0, "route": [ { - "x": 2364, + "x": 2420, "y": 263 }, { - "x": 2364, + "x": 2420, "y": 2858 } ], @@ -2046,11 +2046,11 @@ "labelPercentage": 0, "route": [ { - "x": 2614, + "x": 2670, "y": 258 }, { - "x": 2614, + "x": 2670, "y": 2858 } ], @@ -2085,11 +2085,11 @@ "labelPercentage": 0, "route": [ { - "x": 2864, + "x": 2920, "y": 258 }, { - "x": 2864, + "x": 2920, "y": 2858 } ], @@ -2124,11 +2124,11 @@ "labelPercentage": 0, "route": [ { - "x": 3113.5, + "x": 3170.5, "y": 258 }, { - "x": 3113.5, + "x": 3170.5, "y": 2858 } ], @@ -2163,11 +2163,11 @@ "labelPercentage": 0, "route": [ { - "x": 3363.5, + "x": 3420.5, "y": 258 }, { - "x": 3363.5, + "x": 3420.5, "y": 2858 } ], @@ -2202,11 +2202,11 @@ "labelPercentage": 0, "route": [ { - "x": 3613.5, + "x": 3670.5, "y": 263 }, { - "x": 3613.5, + "x": 3670.5, "y": 2858 } ], @@ -2241,11 +2241,11 @@ "labelPercentage": 0, "route": [ { - "x": 3863.5, + "x": 3920.5, "y": 258 }, { - "x": 3863.5, + "x": 3920.5, "y": 2858 } ], @@ -2280,11 +2280,11 @@ "labelPercentage": 0, "route": [ { - "x": 4113.5, + "x": 4170.5, "y": 258 }, { - "x": 4113.5, + "x": 4170.5, "y": 2858 } ], @@ -2319,11 +2319,11 @@ "labelPercentage": 0, "route": [ { - "x": 4363.5, + "x": 4420.5, "y": 258 }, { - "x": 4363.5, + "x": 4420.5, "y": 2858 } ], @@ -2358,11 +2358,11 @@ "labelPercentage": 0, "route": [ { - "x": 4614, + "x": 4670, "y": 258 }, { - "x": 4614, + "x": 4670, "y": 2858 } ], @@ -2397,11 +2397,11 @@ "labelPercentage": 0, "route": [ { - "x": 4863.5, + "x": 4920.5, "y": 258 }, { - "x": 4863.5, + "x": 4920.5, "y": 2858 } ], diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg index c059492d0..2b86d5324 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ a labelblabelsa class+ +public() bool +void- +private() int +voidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid -int -name -varchar - result := callThisFunction(obj, 5) midthis sideother side - +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid +int +name +varchar + result := callThisFunction(obj, 5) midthis sideother side + - + a labelblabelsa class+ -public() bool -void- -private() int -voidcloudyyyy:= 5 +a labelblabelsa class+ +public() bool +void- +private() int +voidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid -int -name -varchar - result := callThisFunction(obj, 5) midthis sideother side - +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersid +int +name +varchar + result := callThisFunction(obj, 5) midthis sideother side + - + xy

The top of the mountain

+
JoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

+

If we can't fix it, it ain't broke.

+

Dieters live life in the fasting lane.

+

i am top left

+

i am top right

+

i am bottom left

+

i am bottom right

+
+ + +
\ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near/elk/board.exp.json b/e2etests/testdata/stable/constant_near/elk/board.exp.json new file mode 100644 index 000000000..2b2e89b8e --- /dev/null +++ b/e2etests/testdata/stable/constant_near/elk/board.exp.json @@ -0,0 +1,447 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "", + "pos": { + "x": 1961, + "y": 16 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "", + "pos": { + "x": 1960, + "y": 242 + }, + "width": 114, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "The top of the mountain", + "type": "text", + "pos": { + "x": 1936, + "y": -28 + }, + "width": 162, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "The top of the mountain", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 162, + "labelHeight": 24, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "Joe", + "type": "person", + "pos": { + "x": 1809, + "y": 129 + }, + "width": 131, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "Joe", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 31, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "Donald", + "type": "person", + "pos": { + "x": 2094, + "y": 129 + }, + "width": 155, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "Donald", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 55, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "bottom", + "type": "text", + "pos": { + "x": 1546, + "y": 388 + }, + "width": 943, + "height": 130, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "# Cats, no less liquid than their shadows, offer no angles to the wind.\n\nIf we can't fix it, it ain't broke.\n\nDieters live life in the fasting lane.", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 943, + "labelHeight": 130, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "i am top left", + "type": "text", + "pos": { + "x": 1445, + "y": -28 + }, + "width": 81, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "i am top left", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 81, + "labelHeight": 24, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "i am top right", + "type": "text", + "pos": { + "x": 2509, + "y": -28 + }, + "width": 91, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "i am top right", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 91, + "labelHeight": 24, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "i am bottom left", + "type": "text", + "pos": { + "x": 1418, + "y": 388 + }, + "width": 108, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "i am bottom left", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 108, + "labelHeight": 24, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "i am bottom right", + "type": "text", + "pos": { + "x": 2509, + "y": 388 + }, + "width": 118, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "i am bottom right", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 118, + "labelHeight": 24, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(x -> y)[0]", + "src": "x", + "srcArrow": "none", + "srcLabel": "", + "dst": "y", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 2017.5, + "y": 142 + }, + { + "x": 2017.5, + "y": 242 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg new file mode 100644 index 000000000..a9a1c7387 --- /dev/null +++ b/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg @@ -0,0 +1,802 @@ + +xy

The top of the mountain

+
JoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

+

If we can't fix it, it ain't broke.

+

Dieters live life in the fasting lane.

+

i am top left

+

i am top right

+

i am bottom left

+

i am bottom right

+
+ + +
\ No newline at end of file From 9eaa4e98c4839c49c4d9aea1a04a8f9948646970 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 25 Dec 2022 16:49:19 -0800 Subject: [PATCH 28/41] cleanup --- d2layouts/d2near/layout.go | 41 ++++++++-------- .../stable/constant_near/elk/board.exp.json | 48 +++++++++---------- .../stable/constant_near/elk/sketch.exp.svg | 18 +++---- 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 8a735c4c0..954e6af30 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -22,30 +22,22 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje return nil } - // Imagine the grpah has two long texts, one at top center and one at top left. + // Imagine the graph has two long texts, one at top center and one at top left. // Top left should go left enough to not collide with center. // So place the center ones first, then the later ones will consider them for bounding box - for _, obj := range constantNears { - if strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") { - obj.TopLeft = geo.NewPoint(place(obj)) + for _, processCenters := range []bool{true, false} { + for _, obj := range constantNears { + if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") { + obj.TopLeft = geo.NewPoint(place(obj)) + } } - } - for _, obj := range constantNears { - if strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") { - // The z-index for constant nears does not matter, as it will not collide - g.Objects = append(g.Objects, obj) - } - } - - for _, obj := range constantNears { - if !strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") { - obj.TopLeft = geo.NewPoint(place(obj)) - } - } - for _, obj := range constantNears { - if !strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") { - // The z-index for constant nears does not matter, as it will not collide - g.Objects = append(g.Objects, obj) + for _, obj := range constantNears { + if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "center") { + // The z-index for constant nears does not matter, as it will not collide + g.Objects = append(g.Objects, obj) + obj.Parent.Children[obj.ID] = obj + obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray, obj) + } } } @@ -106,6 +98,13 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra nears = append(nears, obj) g.Objects = append(g.Objects[:i], g.Objects[i+1:]...) i-- + delete(obj.Parent.Children, obj.ID) + for i := 0; i < len(obj.Parent.ChildrenArray); i++ { + if obj.Parent.ChildrenArray[i] == obj { + obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray[:i], obj.Parent.ChildrenArray[i+1:]...) + break + } + } } } return nears diff --git a/e2etests/testdata/stable/constant_near/elk/board.exp.json b/e2etests/testdata/stable/constant_near/elk/board.exp.json index 2b2e89b8e..3bde4523c 100644 --- a/e2etests/testdata/stable/constant_near/elk/board.exp.json +++ b/e2etests/testdata/stable/constant_near/elk/board.exp.json @@ -6,8 +6,8 @@ "id": "x", "type": "", "pos": { - "x": 1961, - "y": 16 + "x": 12, + "y": 12 }, "width": 113, "height": 126, @@ -46,8 +46,8 @@ "id": "y", "type": "", "pos": { - "x": 1960, - "y": 242 + "x": 12, + "y": 238 }, "width": 114, "height": 126, @@ -86,8 +86,8 @@ "id": "The top of the mountain", "type": "text", "pos": { - "x": 1936, - "y": -28 + "x": -12, + "y": -32 }, "width": 162, "height": 24, @@ -126,8 +126,8 @@ "id": "Joe", "type": "person", "pos": { - "x": 1809, - "y": 129 + "x": -139, + "y": 125 }, "width": 131, "height": 126, @@ -166,8 +166,8 @@ "id": "Donald", "type": "person", "pos": { - "x": 2094, - "y": 129 + "x": 146, + "y": 125 }, "width": 155, "height": 126, @@ -206,8 +206,8 @@ "id": "bottom", "type": "text", "pos": { - "x": 1546, - "y": 388 + "x": -402, + "y": 384 }, "width": 943, "height": 130, @@ -246,8 +246,8 @@ "id": "i am top left", "type": "text", "pos": { - "x": 1445, - "y": -28 + "x": -503, + "y": -32 }, "width": 81, "height": 24, @@ -286,8 +286,8 @@ "id": "i am top right", "type": "text", "pos": { - "x": 2509, - "y": -28 + "x": 560, + "y": -32 }, "width": 91, "height": 24, @@ -326,8 +326,8 @@ "id": "i am bottom left", "type": "text", "pos": { - "x": 1418, - "y": 388 + "x": -530, + "y": 384 }, "width": 108, "height": 24, @@ -366,8 +366,8 @@ "id": "i am bottom right", "type": "text", "pos": { - "x": 2509, - "y": 388 + "x": 560, + "y": 384 }, "width": 118, "height": 24, @@ -430,12 +430,12 @@ "labelPercentage": 0, "route": [ { - "x": 2017.5, - "y": 142 + "x": 69, + "y": 138 }, { - "x": 2017.5, - "y": 242 + "x": 69, + "y": 238 } ], "animated": false, diff --git a/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg index a9a1c7387..c2022876a 100644 --- a/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near/elk/sketch.exp.svg @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_title/elk/board.exp.json b/e2etests/testdata/stable/constant_near_title/elk/board.exp.json new file mode 100644 index 000000000..cfd0c8a4f --- /dev/null +++ b/e2etests/testdata/stable/constant_near_title/elk/board.exp.json @@ -0,0 +1,459 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "poll the people", + "type": "", + "pos": { + "x": 81, + "y": 12 + }, + "width": 210, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "poll the people", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 110, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "results", + "type": "", + "pos": { + "x": 74, + "y": 238 + }, + "width": 153, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "results", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 53, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "unfavorable", + "type": "", + "pos": { + "x": 232, + "y": 464 + }, + "width": 191, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "unfavorable", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 91, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "favorable", + "type": "", + "pos": { + "x": 39, + "y": 464 + }, + "width": 173, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "favorable", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 73, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "will of the people", + "type": "", + "pos": { + "x": 12, + "y": 690 + }, + "width": 227, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "will of the people", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 127, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "title", + "type": "text", + "pos": { + "x": 84, + "y": -58 + }, + "width": 266, + "height": 50, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "# A winning strategy", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 266, + "labelHeight": 50, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(poll the people -> results)[0]", + "src": "poll the people", + "srcArrow": "none", + "srcLabel": "", + "dst": "results", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 151, + "y": 138 + }, + { + "x": 151, + "y": 238 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(results -> unfavorable)[0]", + "src": "results", + "srcArrow": "none", + "srcLabel": "", + "dst": "unfavorable", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 176.5, + "y": 364 + }, + { + "x": 176.5, + "y": 414 + }, + { + "x": 295.6666666666667, + "y": 414 + }, + { + "x": 295.6666666666667, + "y": 464 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(unfavorable -> poll the people)[0]", + "src": "unfavorable", + "srcArrow": "none", + "srcLabel": "", + "dst": "poll the people", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 359.3333333333333, + "y": 464 + }, + { + "x": 359.3333333333333, + "y": 188 + }, + { + "x": 221, + "y": 188 + }, + { + "x": 221, + "y": 138 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(results -> favorable)[0]", + "src": "results", + "srcArrow": "none", + "srcLabel": "", + "dst": "favorable", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 125.5, + "y": 364 + }, + { + "x": 125.5, + "y": 464 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(favorable -> will of the people)[0]", + "src": "favorable", + "srcArrow": "none", + "srcLabel": "", + "dst": "will of the people", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 125.5, + "y": 590 + }, + { + "x": 125.5, + "y": 690 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg new file mode 100644 index 000000000..e5ea8add8 --- /dev/null +++ b/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg @@ -0,0 +1,796 @@ + +poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

+
+ + +
\ No newline at end of file From 36e221a6f5649bbf1e6b38324cec7c600ed963c5 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 25 Dec 2022 17:24:48 -0800 Subject: [PATCH 31/41] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 425aab01c..fbd621f5d 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -18,6 +18,7 @@ Hope everyone is enjoying the holidays this week! - `class` shapes use monospaced font. [#521](https://github.com/terrastruct/d2/pull/521) - Sequence diagram edge group labels have more reasonable padding. [#512](https://github.com/terrastruct/d2/pull/512) - ELK layout engine preserves order of nodes. [#282](https://github.com/terrastruct/d2/issues/282) +- Markdown headings set font-family explicitly, so that external stylesheets with more specific targeting don't override it. [#525](https://github.com/terrastruct/d2/pull/525) #### Bugfixes ⛑️ From 409717b40d97c88525b6e9475afc98cb896c4a5d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 25 Dec 2022 17:25:35 -0800 Subject: [PATCH 32/41] more specific doc --- ci/release/changelogs/next.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index fbd621f5d..2fe46e9ac 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -9,7 +9,7 @@ Hope everyone is enjoying the holidays this week! #### Features 🚀 - `sketch` flag renders the diagram to look like it was sketched by hand. [#492](https://github.com/terrastruct/d2/pull/492) -- `near` now takes constants like `top-center`, particularly useful for diagram titles. See [docs](https://d2lang.com/tour/text#how-do-i-position-text) for more. [#525](https://github.com/terrastruct/d2/pull/525) +- `near` now takes constants like `top-center`, particularly useful for diagram titles. See [docs](http://localhost:8888/tour/text#near-a-constant) for more. [#525](https://github.com/terrastruct/d2/pull/525) #### Improvements 🧹 From a09f614f5f66a2d3bd4de3c1fd6a357ca22901a6 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 25 Dec 2022 17:30:48 -0800 Subject: [PATCH 33/41] update tests --- d2renderers/d2sketch/testdata/twitter/sketch.exp.svg | 1 + e2etests/testdata/regression/elk_order/dagre/sketch.exp.svg | 1 + e2etests/testdata/regression/elk_order/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/chaos2/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/chaos2/elk/sketch.exp.svg | 1 + .../testdata/stable/giant_markdown_test/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/giant_markdown_test/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/hr/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/hr/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/latex/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/latex/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/li1/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/li1/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/li2/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/li2/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/li3/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/li3/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/li4/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/li4/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/lone_h1/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/lone_h1/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/markdown/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/markdown/elk/sketch.exp.svg | 1 + .../testdata/stable/markdown_stroke_fill/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/markdown_stroke_fill/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/md_2space_newline/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/md_2space_newline/elk/sketch.exp.svg | 1 + .../testdata/stable/md_backslash_newline/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/md_backslash_newline/elk/sketch.exp.svg | 1 + .../testdata/stable/md_code_block_fenced/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/md_code_block_fenced/elk/sketch.exp.svg | 1 + .../testdata/stable/md_code_block_indented/dagre/sketch.exp.svg | 1 + .../testdata/stable/md_code_block_indented/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/md_code_inline/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/md_code_inline/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/p/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/p/elk/sketch.exp.svg | 1 + e2etests/testdata/stable/pre/dagre/sketch.exp.svg | 1 + e2etests/testdata/stable/pre/elk/sketch.exp.svg | 1 + 39 files changed, 39 insertions(+) diff --git a/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg b/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg index 471e8fa0a..f93b93c1f 100644 --- a/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg @@ -282,6 +282,7 @@ width="3454" height="2449" viewBox="-100 -100 3454 2449">bearmama bearpapa bear + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/text_font_sizes/elk/board.exp.json b/e2etests/testdata/stable/text_font_sizes/elk/board.exp.json new file mode 100644 index 000000000..ae4e7c84e --- /dev/null +++ b/e2etests/testdata/stable/text_font_sizes/elk/board.exp.json @@ -0,0 +1,211 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "bear", + "type": "text", + "pos": { + "x": 64, + "y": 153 + }, + "width": 44, + "height": 28, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "bear", + "fontSize": 22, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 44, + "labelHeight": 28, + "zIndex": 0, + "level": 1 + }, + { + "id": "mama bear", + "type": "text", + "pos": { + "x": 12, + "y": 17 + }, + "width": 135, + "height": 36, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "mama bear", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 135, + "labelHeight": 36, + "zIndex": 0, + "level": 1 + }, + { + "id": "papa bear", + "type": "text", + "pos": { + "x": 167, + "y": 12 + }, + "width": 134, + "height": 41, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "#0A0F25", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "papa bear", + "fontSize": 32, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": true, + "labelWidth": 134, + "labelHeight": 41, + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(mama bear -> bear)[0]", + "src": "mama bear", + "srcArrow": "none", + "srcLabel": "", + "dst": "bear", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 79.5, + "y": 53 + }, + { + "x": 79.5, + "y": 153 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(papa bear -> bear)[0]", + "src": "papa bear", + "srcArrow": "none", + "srcLabel": "", + "dst": "bear", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 234, + "y": 53 + }, + { + "x": 234, + "y": 103 + }, + { + "x": 94.16666666666666, + "y": 103 + }, + { + "x": 94.16666666666666, + "y": 153 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/text_font_sizes/elk/sketch.exp.svg b/e2etests/testdata/stable/text_font_sizes/elk/sketch.exp.svg new file mode 100644 index 000000000..506609593 --- /dev/null +++ b/e2etests/testdata/stable/text_font_sizes/elk/sketch.exp.svg @@ -0,0 +1,805 @@ + +bearmama bearpapa bear + + + \ No newline at end of file From 9e658adf089c33d04eaf93c906d7352e15c62a94 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 25 Dec 2022 21:50:40 -0800 Subject: [PATCH 38/41] update tests --- .../d2sketch/testdata/twitter/sketch.exp.svg | 2 +- .../regression/elk_order/dagre/board.exp.json | 8 +- .../regression/elk_order/dagre/sketch.exp.svg | 2 +- .../regression/elk_order/elk/board.exp.json | 8 +- .../regression/elk_order/elk/sketch.exp.svg | 2 +- .../stable/chaos2/dagre/board.exp.json | 132 +++++++++--------- .../stable/chaos2/dagre/sketch.exp.svg | 13 +- .../testdata/stable/chaos2/elk/board.exp.json | 50 +++---- .../testdata/stable/chaos2/elk/sketch.exp.svg | 15 +- .../constant_near_stress/dagre/board.exp.json | 58 ++++---- .../constant_near_stress/dagre/sketch.exp.svg | 13 +- .../constant_near_stress/elk/board.exp.json | 58 ++++---- .../constant_near_stress/elk/sketch.exp.svg | 13 +- .../constant_near_title/dagre/board.exp.json | 2 +- .../constant_near_title/dagre/sketch.exp.svg | 2 +- .../constant_near_title/elk/board.exp.json | 2 +- .../constant_near_title/elk/sketch.exp.svg | 2 +- .../giant_markdown_test/dagre/board.exp.json | 2 +- .../giant_markdown_test/dagre/sketch.exp.svg | 2 +- .../giant_markdown_test/elk/board.exp.json | 2 +- .../giant_markdown_test/elk/sketch.exp.svg | 2 +- .../testdata/stable/hr/dagre/board.exp.json | 2 +- .../testdata/stable/hr/dagre/sketch.exp.svg | 2 +- .../testdata/stable/hr/elk/board.exp.json | 2 +- .../testdata/stable/hr/elk/sketch.exp.svg | 2 +- .../stable/latex/dagre/board.exp.json | 6 +- .../stable/latex/dagre/sketch.exp.svg | 2 +- .../testdata/stable/latex/elk/board.exp.json | 6 +- .../testdata/stable/latex/elk/sketch.exp.svg | 2 +- .../testdata/stable/li1/dagre/board.exp.json | 2 +- .../testdata/stable/li1/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li1/elk/board.exp.json | 2 +- .../testdata/stable/li1/elk/sketch.exp.svg | 2 +- .../testdata/stable/li2/dagre/board.exp.json | 2 +- .../testdata/stable/li2/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li2/elk/board.exp.json | 2 +- .../testdata/stable/li2/elk/sketch.exp.svg | 2 +- .../testdata/stable/li3/dagre/board.exp.json | 2 +- .../testdata/stable/li3/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li3/elk/board.exp.json | 2 +- .../testdata/stable/li3/elk/sketch.exp.svg | 2 +- .../testdata/stable/li4/dagre/board.exp.json | 2 +- .../testdata/stable/li4/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li4/elk/board.exp.json | 2 +- .../testdata/stable/li4/elk/sketch.exp.svg | 2 +- .../stable/lone_h1/dagre/board.exp.json | 2 +- .../stable/lone_h1/dagre/sketch.exp.svg | 2 +- .../stable/lone_h1/elk/board.exp.json | 2 +- .../stable/lone_h1/elk/sketch.exp.svg | 2 +- .../stable/markdown/dagre/board.exp.json | 2 +- .../stable/markdown/dagre/sketch.exp.svg | 2 +- .../stable/markdown/elk/board.exp.json | 2 +- .../stable/markdown/elk/sketch.exp.svg | 2 +- .../markdown_stroke_fill/dagre/board.exp.json | 4 +- .../markdown_stroke_fill/dagre/sketch.exp.svg | 2 +- .../markdown_stroke_fill/elk/board.exp.json | 4 +- .../markdown_stroke_fill/elk/sketch.exp.svg | 2 +- .../md_2space_newline/dagre/board.exp.json | 2 +- .../md_2space_newline/dagre/sketch.exp.svg | 2 +- .../md_2space_newline/elk/board.exp.json | 2 +- .../md_2space_newline/elk/sketch.exp.svg | 2 +- .../md_backslash_newline/dagre/board.exp.json | 2 +- .../md_backslash_newline/dagre/sketch.exp.svg | 2 +- .../md_backslash_newline/elk/board.exp.json | 2 +- .../md_backslash_newline/elk/sketch.exp.svg | 2 +- .../md_code_block_fenced/dagre/board.exp.json | 2 +- .../md_code_block_fenced/dagre/sketch.exp.svg | 2 +- .../md_code_block_fenced/elk/board.exp.json | 2 +- .../md_code_block_fenced/elk/sketch.exp.svg | 2 +- .../dagre/board.exp.json | 2 +- .../dagre/sketch.exp.svg | 2 +- .../md_code_block_indented/elk/board.exp.json | 2 +- .../md_code_block_indented/elk/sketch.exp.svg | 2 +- .../md_code_inline/dagre/board.exp.json | 2 +- .../md_code_inline/dagre/sketch.exp.svg | 2 +- .../stable/md_code_inline/elk/board.exp.json | 2 +- .../stable/md_code_inline/elk/sketch.exp.svg | 2 +- .../testdata/stable/p/dagre/board.exp.json | 2 +- .../testdata/stable/p/dagre/sketch.exp.svg | 2 +- e2etests/testdata/stable/p/elk/board.exp.json | 2 +- e2etests/testdata/stable/p/elk/sketch.exp.svg | 2 +- .../testdata/stable/pre/dagre/board.exp.json | 2 +- .../testdata/stable/pre/dagre/sketch.exp.svg | 2 +- .../testdata/stable/pre/elk/board.exp.json | 2 +- .../testdata/stable/pre/elk/sketch.exp.svg | 2 +- .../TestExport/shape/text_color.exp.json | 2 +- 86 files changed, 258 insertions(+), 274 deletions(-) diff --git a/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg b/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg index f93b93c1f..a45b29f99 100644 --- a/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/twitter/sketch.exp.svg @@ -796,7 +796,7 @@ width="3454" height="2449" viewBox="-100 -100 3454 2449">aabbllmm

nn

-
oocciikkdd

gg

-
hhjj

ee

-
ff1122 334455667788 - +aabbllmmnnoocciikkddgghhjjeeff1122 334455667788 + - + - + aabbllmm

nn

-
oocciikkdd

gg

-
hhjj

ee

-
ff1122 334455667788 - +aabbllmmnnoocciikkddgghhjjeeff1122 334455667788 + - + - - + + xy

The top of the mountain

-
JoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

+xyThe top of the mountainJoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

If we can't fix it, it ain't broke.

Dieters live life in the fasting lane.

-

i am top left

-

i am top right

-

i am bottom left

-

i am bottom right

-
- +
i am top lefti am top righti am bottom lefti am bottom right + xy

The top of the mountain

-
JoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

+xyThe top of the mountainJoeDonald

Cats, no less liquid than their shadows, offer no angles to the wind.

If we can't fix it, it ain't broke.

Dieters live life in the fasting lane.

-

i am top left

-

i am top right

-

i am bottom left

-

i am bottom right

-
- +
i am top lefti am top righti am bottom lefti am bottom right + poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

-
+ poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

-
+ mixed togethersugarsolution we get +mixed togethersugarsolution we get mixed togethersugarsolution we get +mixed togethersugarsolution we get

Markdown: Syntax

-
ab +ab

Markdown: Syntax

-
ab +ab markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+ markdown

Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

-
+

code

-
ab +ab

code

-
ab +ab