From 64d7d5f1b6cb065792a5a855cb814ad9512d971a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 24 Dec 2022 15:56:22 -0800 Subject: [PATCH 1/4] 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 4/4] 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 + - +