From 301e692a24c3dc9ca8d6039b955b9b61fc0ecafa Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 6 Feb 2023 00:42:28 -0800 Subject: [PATCH 1/6] fix sql table font-size --- d2graph/d2graph.go | 16 +- d2target/sqltable.go | 14 +- e2etests/stable_test.go | 23 ++ .../dagre/board.exp.json | 207 ++++++++++++++++++ .../dagre/sketch.exp.svg | 60 +++++ .../elk/board.exp.json | 207 ++++++++++++++++++ .../elk/sketch.exp.svg | 60 +++++ 7 files changed, 578 insertions(+), 9 deletions(-) create mode 100644 e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json create mode 100644 e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index f74b14496..dc6ffcbbe 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -477,7 +477,7 @@ func (obj *Object) Text() *d2target.MText { } // Class and Table objects have Label set to header if obj.Class != nil || obj.SQLTable != nil { - fontSize = d2fonts.FONT_SIZE_XL + fontSize += d2target.HeaderFontAdd } if obj.Class != nil { isBold = false @@ -836,10 +836,16 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R maxTypeWidth := 0 constraintWidth := 0 + colFontSize := d2fonts.FONT_SIZE_L + if obj.Attributes.Style.FontSize != nil { + colFontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value) + } + for i := range obj.SQLTable.Columns { // Note: we want to set dimensions of actual column not the for loop copy of the struct c := &obj.SQLTable.Columns[i] - ctexts := c.Texts() + + ctexts := c.Texts(colFontSize) nameDims := GetTextDimensions(mtexts, ruler, ctexts[0], fontFamily) if nameDims == nil { @@ -1334,8 +1340,12 @@ func (g *Graph) Texts() []*d2target.MText { texts = appendTextDedup(texts, method.Text()) } } else if obj.SQLTable != nil { + colFontSize := d2fonts.FONT_SIZE_L + if obj.Attributes.Style.FontSize != nil { + colFontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value) + } for _, column := range obj.SQLTable.Columns { - for _, t := range column.Texts() { + for _, t := range column.Texts(colFontSize) { texts = appendTextDedup(texts, t) } } diff --git a/d2target/sqltable.go b/d2target/sqltable.go index 8332a34c8..6ffbddf05 100644 --- a/d2target/sqltable.go +++ b/d2target/sqltable.go @@ -1,11 +1,13 @@ package d2target -import "oss.terrastruct.com/d2/d2renderers/d2fonts" - const ( NamePadding = 10 TypePadding = 20 - HeaderPadding = 20 + HeaderPadding = 10 + + // Setting table font size sets it for columns + // The header needs to be a little larger for visual hierarchy + HeaderFontAdd = 4 ) type SQLTable struct { @@ -19,18 +21,18 @@ type SQLColumn struct { Reference string `json:"reference"` } -func (c SQLColumn) Texts() []*MText { +func (c SQLColumn) Texts(fontSize int) []*MText { return []*MText{ { Text: c.Name.Label, - FontSize: d2fonts.FONT_SIZE_L, + FontSize: fontSize, IsBold: false, IsItalic: false, Shape: "sql_table", }, { Text: c.Type.Label, - FontSize: d2fonts.FONT_SIZE_L, + FontSize: fontSize, IsBold: false, IsItalic: false, Shape: "sql_table", diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index a489f6398..de4ff5c74 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1838,6 +1838,29 @@ x.y -> a.b: { style.animated: true target-arrowhead.shape: cf-many } +`, + }, + { + name: "sql_table_column_styles", + script: `Humor in the Court: { + shape: sql_table + Could you see him from where you were standing?: "I could see his head." + And where was his head?: Just above his shoulders. + style.fill: red + style.stroke: lightgray + style.font-color: orange + style.font-size: 20 +} + +Humor in the Court2: { + shape: sql_table + Could you see him from where you were standing?: "I could see his head." + And where was his head?: Just above his shoulders. + style.fill: red + style.stroke: lightgray + style.font-color: orange + style.font-size: 30 +} `, }, { diff --git a/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json b/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json new file mode 100644 index 000000000..fb282c898 --- /dev/null +++ b/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json @@ -0,0 +1,207 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "Humor in the Court", + "type": "sql_table", + "pos": { + "x": 0, + "y": 18 + }, + "width": 678, + "height": 108, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "red", + "stroke": "lightgray", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "Could you see him from where you were standing?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 418, + "labelHeight": 26 + }, + "type": { + "label": "I could see his head.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 166, + "labelHeight": 26 + }, + "constraint": "", + "reference": "" + }, + { + "name": { + "label": "And where was his head?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 208, + "labelHeight": 26 + }, + "type": { + "label": "Just above his shoulders.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 210, + "labelHeight": 26 + }, + "constraint": "", + "reference": "" + } + ], + "label": "Humor in the Court", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "orange", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 202, + "labelHeight": 31, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + }, + { + "id": "Humor in the Court2", + "type": "sql_table", + "pos": { + "x": 738, + "y": 0 + }, + "width": 992, + "height": 144, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "red", + "stroke": "lightgray", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "Could you see him from where you were standing?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 627, + "labelHeight": 38 + }, + "type": { + "label": "I could see his head.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 248, + "labelHeight": 38 + }, + "constraint": "", + "reference": "" + }, + { + "name": { + "label": "And where was his head?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 312, + "labelHeight": 38 + }, + "type": { + "label": "Just above his shoulders.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 315, + "labelHeight": 38 + }, + "constraint": "", + "reference": "" + } + ], + "label": "Humor in the Court2", + "fontSize": 30, + "fontFamily": "DEFAULT", + "language": "", + "color": "orange", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 303, + "labelHeight": 43, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + } + ], + "connections": [] +} diff --git a/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg new file mode 100644 index 000000000..7e008d4c8 --- /dev/null +++ b/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg @@ -0,0 +1,60 @@ + +Humor in the CourtCould you see him from where you were standing? +I could see his head. +And where was his head? +Just above his shoulders. +Humor in the Court2Could you see him from where you were standing? +I could see his head. +And where was his head? +Just above his shoulders. + + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json b/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json new file mode 100644 index 000000000..633a19d2c --- /dev/null +++ b/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json @@ -0,0 +1,207 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "Humor in the Court", + "type": "sql_table", + "pos": { + "x": 12, + "y": 30 + }, + "width": 678, + "height": 108, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "red", + "stroke": "lightgray", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "Could you see him from where you were standing?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 418, + "labelHeight": 26 + }, + "type": { + "label": "I could see his head.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 166, + "labelHeight": 26 + }, + "constraint": "", + "reference": "" + }, + { + "name": { + "label": "And where was his head?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 208, + "labelHeight": 26 + }, + "type": { + "label": "Just above his shoulders.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 210, + "labelHeight": 26 + }, + "constraint": "", + "reference": "" + } + ], + "label": "Humor in the Court", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "orange", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 202, + "labelHeight": 31, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + }, + { + "id": "Humor in the Court2", + "type": "sql_table", + "pos": { + "x": 710, + "y": 12 + }, + "width": 992, + "height": 144, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "red", + "stroke": "lightgray", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "Could you see him from where you were standing?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 627, + "labelHeight": 38 + }, + "type": { + "label": "I could see his head.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 248, + "labelHeight": 38 + }, + "constraint": "", + "reference": "" + }, + { + "name": { + "label": "And where was his head?", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 312, + "labelHeight": 38 + }, + "type": { + "label": "Just above his shoulders.", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 315, + "labelHeight": 38 + }, + "constraint": "", + "reference": "" + } + ], + "label": "Humor in the Court2", + "fontSize": 30, + "fontFamily": "DEFAULT", + "language": "", + "color": "orange", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 303, + "labelHeight": 43, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + } + ], + "connections": [] +} diff --git a/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg b/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg new file mode 100644 index 000000000..5e82cf15c --- /dev/null +++ b/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg @@ -0,0 +1,60 @@ + +Humor in the CourtCould you see him from where you were standing? +I could see his head. +And where was his head? +Just above his shoulders. +Humor in the Court2Could you see him from where you were standing? +I could see his head. +And where was his head? +Just above his shoulders. + + + + \ No newline at end of file From 01445768d807409c42603585db980b0e4d62dd4a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 6 Feb 2023 00:47:13 -0800 Subject: [PATCH 2/6] fix for class --- d2graph/d2graph.go | 25 ++- d2target/class.go | 10 +- e2etests/stable_test.go | 26 +++ .../dagre/board.exp.json | 154 +++++++++++++++++- .../dagre/sketch.exp.svg | 53 ++++-- .../elk/board.exp.json | 154 +++++++++++++++++- .../elk/sketch.exp.svg | 53 ++++-- 7 files changed, 435 insertions(+), 40 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index dc6ffcbbe..3d8cf71ce 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -795,17 +795,22 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R case d2target.ShapeClass: maxWidth := go2.Max(12, labelDims.Width) + fontSize := d2fonts.FONT_SIZE_L + if obj.Attributes.Style.FontSize != nil { + fontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value) + } + for _, f := range obj.Class.Fields { - fdims := GetTextDimensions(mtexts, ruler, f.Text(), go2.Pointer(d2fonts.SourceCodePro)) + fdims := GetTextDimensions(mtexts, ruler, f.Text(fontSize), go2.Pointer(d2fonts.SourceCodePro)) if fdims == nil { - return nil, fmt.Errorf("dimensions for class field %#v not found", f.Text()) + return nil, fmt.Errorf("dimensions for class field %#v not found", f.Text(fontSize)) } maxWidth = go2.Max(maxWidth, fdims.Width) } for _, m := range obj.Class.Methods { - mdims := GetTextDimensions(mtexts, ruler, m.Text(), go2.Pointer(d2fonts.SourceCodePro)) + mdims := GetTextDimensions(mtexts, ruler, m.Text(fontSize), go2.Pointer(d2fonts.SourceCodePro)) if mdims == nil { - return nil, fmt.Errorf("dimensions for class method %#v not found", m.Text()) + return nil, fmt.Errorf("dimensions for class method %#v not found", m.Text(fontSize)) } maxWidth = go2.Max(maxWidth, mdims.Width) } @@ -820,9 +825,9 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R // All rows should be the same height var anyRowText *d2target.MText if len(obj.Class.Fields) > 0 { - anyRowText = obj.Class.Fields[0].Text() + anyRowText = obj.Class.Fields[0].Text(fontSize) } else if len(obj.Class.Methods) > 0 { - anyRowText = obj.Class.Methods[0].Text() + anyRowText = obj.Class.Methods[0].Text(fontSize) } if anyRowText != nil { rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + d2target.VerticalPadding @@ -1333,11 +1338,15 @@ func (g *Graph) Texts() []*d2target.MText { texts = appendTextDedup(texts, obj.Text()) } if obj.Class != nil { + fontSize := d2fonts.FONT_SIZE_L + if obj.Attributes.Style.FontSize != nil { + fontSize, _ = strconv.Atoi(obj.Attributes.Style.FontSize.Value) + } for _, field := range obj.Class.Fields { - texts = appendTextDedup(texts, field.Text()) + texts = appendTextDedup(texts, field.Text(fontSize)) } for _, method := range obj.Class.Methods { - texts = appendTextDedup(texts, method.Text()) + texts = appendTextDedup(texts, method.Text(fontSize)) } } else if obj.SQLTable != nil { colFontSize := d2fonts.FONT_SIZE_L diff --git a/d2target/class.go b/d2target/class.go index 3cc39921e..c08f11144 100644 --- a/d2target/class.go +++ b/d2target/class.go @@ -2,8 +2,6 @@ package d2target import ( "fmt" - - "oss.terrastruct.com/d2/d2renderers/d2fonts" ) const ( @@ -25,10 +23,10 @@ type ClassField struct { Visibility string `json:"visibility"` } -func (cf ClassField) Text() *MText { +func (cf ClassField) Text(fontSize int) *MText { return &MText{ Text: fmt.Sprintf("%s%s", cf.Name, cf.Type), - FontSize: d2fonts.FONT_SIZE_L, + FontSize: fontSize, IsBold: false, IsItalic: false, Shape: "class", @@ -52,10 +50,10 @@ type ClassMethod struct { Visibility string `json:"visibility"` } -func (cm ClassMethod) Text() *MText { +func (cm ClassMethod) Text(fontSize int) *MText { return &MText{ Text: fmt.Sprintf("%s%s", cm.Name, cm.Return), - FontSize: d2fonts.FONT_SIZE_L, + FontSize: fontSize, IsBold: false, IsItalic: false, Shape: "class", diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index de4ff5c74..957451c08 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1861,6 +1861,32 @@ Humor in the Court2: { style.font-color: orange style.font-size: 30 } + +manager: BatchManager { + shape: class + style.font-size: 20 + + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} + +manager2: BatchManager { + shape: class + style.font-size: 30 + + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} `, }, { diff --git a/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json b/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json index fb282c898..1fb2f867c 100644 --- a/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json +++ b/e2etests/testdata/stable/sql_table_column_styles/dagre/board.exp.json @@ -7,7 +7,7 @@ "type": "sql_table", "pos": { "x": 0, - "y": 18 + "y": 178 }, "width": 678, "height": 108, @@ -107,7 +107,7 @@ "type": "sql_table", "pos": { "x": 738, - "y": 0 + "y": 160 }, "width": 992, "height": 144, @@ -201,6 +201,156 @@ "primaryAccentColor": "#0D32B2", "secondaryAccentColor": "#4A6FF3", "neutralAccentColor": "#676C7E" + }, + { + "id": "manager", + "type": "class", + "pos": { + "x": 1790, + "y": 48 + }, + "width": 422, + "height": 368, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#0A0F25", + "stroke": "#FFFFFF", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": [ + { + "name": "num", + "type": "int", + "visibility": "private" + }, + { + "name": "timeout", + "type": "int", + "visibility": "private" + }, + { + "name": "pid", + "type": "", + "visibility": "private" + } + ], + "methods": [ + { + "name": "getStatus()", + "return": "Enum", + "visibility": "public" + }, + { + "name": "getJobs()", + "return": "Job[]", + "visibility": "public" + }, + { + "name": "setTimeout(seconds int)", + "return": "void", + "visibility": "public" + } + ], + "columns": null, + "label": "BatchManager", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 170, + "labelHeight": 31, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + }, + { + "id": "manager2", + "type": "class", + "pos": { + "x": 2272, + "y": 0 + }, + "width": 582, + "height": 464, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#0A0F25", + "stroke": "#FFFFFF", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": [ + { + "name": "num", + "type": "int", + "visibility": "private" + }, + { + "name": "timeout", + "type": "int", + "visibility": "private" + }, + { + "name": "pid", + "type": "", + "visibility": "private" + } + ], + "methods": [ + { + "name": "getStatus()", + "return": "Enum", + "visibility": "public" + }, + { + "name": "getJobs()", + "return": "Job[]", + "visibility": "public" + }, + { + "name": "setTimeout(seconds int)", + "return": "void", + "visibility": "public" + } + ], + "columns": null, + "label": "BatchManager", + "fontSize": 30, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 241, + "labelHeight": 43, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" } ], "connections": [] diff --git a/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg index 7e008d4c8..5b362a921 100644 --- a/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="1934" height="348" viewBox="-102 -102 1934 348"> \ No newline at end of file diff --git a/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json b/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json index 633a19d2c..a3ac11503 100644 --- a/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json +++ b/e2etests/testdata/stable/sql_table_column_styles/elk/board.exp.json @@ -7,7 +7,7 @@ "type": "sql_table", "pos": { "x": 12, - "y": 30 + "y": 190 }, "width": 678, "height": 108, @@ -107,7 +107,7 @@ "type": "sql_table", "pos": { "x": 710, - "y": 12 + "y": 172 }, "width": 992, "height": 144, @@ -201,6 +201,156 @@ "primaryAccentColor": "#0D32B2", "secondaryAccentColor": "#4A6FF3", "neutralAccentColor": "#676C7E" + }, + { + "id": "manager", + "type": "class", + "pos": { + "x": 1722, + "y": 60 + }, + "width": 422, + "height": 368, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#0A0F25", + "stroke": "#FFFFFF", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": [ + { + "name": "num", + "type": "int", + "visibility": "private" + }, + { + "name": "timeout", + "type": "int", + "visibility": "private" + }, + { + "name": "pid", + "type": "", + "visibility": "private" + } + ], + "methods": [ + { + "name": "getStatus()", + "return": "Enum", + "visibility": "public" + }, + { + "name": "getJobs()", + "return": "Job[]", + "visibility": "public" + }, + { + "name": "setTimeout(seconds int)", + "return": "void", + "visibility": "public" + } + ], + "columns": null, + "label": "BatchManager", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 170, + "labelHeight": 31, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" + }, + { + "id": "manager2", + "type": "class", + "pos": { + "x": 2164, + "y": 12 + }, + "width": 582, + "height": 464, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#0A0F25", + "stroke": "#FFFFFF", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": [ + { + "name": "num", + "type": "int", + "visibility": "private" + }, + { + "name": "timeout", + "type": "int", + "visibility": "private" + }, + { + "name": "pid", + "type": "", + "visibility": "private" + } + ], + "methods": [ + { + "name": "getStatus()", + "return": "Enum", + "visibility": "public" + }, + { + "name": "getJobs()", + "return": "Job[]", + "visibility": "public" + }, + { + "name": "setTimeout(seconds int)", + "return": "void", + "visibility": "public" + } + ], + "columns": null, + "label": "BatchManager", + "fontSize": 30, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 241, + "labelHeight": 43, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "#0D32B2", + "secondaryAccentColor": "#4A6FF3", + "neutralAccentColor": "#676C7E" } ], "connections": [] diff --git a/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg b/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg index 5e82cf15c..0473c7f13 100644 --- a/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="1894" height="348" viewBox="-90 -90 1894 348"> \ No newline at end of file From 0341fd6f3e2f4d8bc35d36f0454b47648d64658c Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 6 Feb 2023 01:10:52 -0800 Subject: [PATCH 3/6] update tests --- d2exporter/export.go | 3 - .../d2sketch/testdata/class/sketch.exp.svg | 26 +++---- .../d2sketch/testdata/opacity/sketch.exp.svg | 14 ++-- .../testdata/sql_tables/sketch.exp.svg | 70 +++++++++---------- e2etests/regression_test.go | 14 ---- .../empty_class_height/dagre/board.exp.json | 18 ++--- .../empty_class_height/dagre/sketch.exp.svg | 10 +-- .../empty_class_height/elk/board.exp.json | 18 ++--- .../empty_class_height/elk/sketch.exp.svg | 10 +-- .../dagre/board.exp.json | 64 ++++++++--------- .../dagre/sketch.exp.svg | 10 +-- .../elk/board.exp.json | 48 ++++++------- .../elk/sketch.exp.svg | 10 +-- .../sql_table_overflow/dagre/board.exp.json | 12 ++-- .../sql_table_overflow/dagre/sketch.exp.svg | 22 +++--- .../sql_table_overflow/elk/board.exp.json | 12 ++-- .../sql_table_overflow/elk/sketch.exp.svg | 22 +++--- .../dagre/board.exp.json | 16 ++--- .../dagre/sketch.exp.svg | 28 ++++---- .../elk/board.exp.json | 12 ++-- .../elk/sketch.exp.svg | 28 ++++---- .../stable/class/dagre/board.exp.json | 4 +- .../stable/class/dagre/sketch.exp.svg | 4 +- .../testdata/stable/class/elk/board.exp.json | 4 +- .../testdata/stable/class/elk/sketch.exp.svg | 4 +- .../dagre/board.exp.json | 12 ++-- .../dagre/sketch.exp.svg | 12 ++-- .../elk/board.exp.json | 12 ++-- .../elk/sketch.exp.svg | 12 ++-- .../dagre/board.exp.json | 8 +-- .../dagre/sketch.exp.svg | 66 ++++++++--------- .../elk/board.exp.json | 8 +-- .../elk/sketch.exp.svg | 66 ++++++++--------- .../dagre/board.exp.json | 22 +++--- .../dagre/sketch.exp.svg | 16 ++--- .../elk/board.exp.json | 18 ++--- .../elk/sketch.exp.svg | 16 ++--- .../stable/sql_tables/dagre/board.exp.json | 54 +++++++------- .../stable/sql_tables/dagre/sketch.exp.svg | 70 +++++++++---------- .../stable/sql_tables/elk/board.exp.json | 50 ++++++------- .../stable/sql_tables/elk/sketch.exp.svg | 70 +++++++++---------- .../unnamed_only_height/dagre/board.exp.json | 4 +- .../unnamed_only_height/dagre/sketch.exp.svg | 2 +- .../unnamed_only_height/elk/board.exp.json | 4 +- .../unnamed_only_height/elk/sketch.exp.svg | 2 +- .../unnamed_only_width/dagre/board.exp.json | 36 +++++----- .../unnamed_only_width/dagre/sketch.exp.svg | 28 ++++---- .../unnamed_only_width/elk/board.exp.json | 24 +++---- .../unnamed_only_width/elk/sketch.exp.svg | 28 ++++---- .../dagre/board.exp.json | 8 +-- .../dagre/sketch.exp.svg | 6 +- .../shape_set_width_height/elk/board.exp.json | 8 +-- .../shape_set_width_height/elk/sketch.exp.svg | 6 +- 53 files changed, 567 insertions(+), 584 deletions(-) diff --git a/d2exporter/export.go b/d2exporter/export.go index 5a57f0881..2a34ed64a 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -135,11 +135,8 @@ func toShape(obj *d2graph.Object, theme *d2themes.Theme) d2target.Shape { shape.Label = obj.Attributes.Label.Value case d2target.ShapeClass: shape.Class = *obj.Class - // The label is the header for classes and tables, which is set in client to be 4 px larger than the object's set font size - shape.FontSize -= 4 case d2target.ShapeSQLTable: shape.SQLTable = *obj.SQLTable - shape.FontSize -= 4 } shape.Label = text.Text shape.LabelWidth = text.Dimensions.Width diff --git a/d2renderers/d2sketch/testdata/class/sketch.exp.svg b/d2renderers/d2sketch/testdata/class/sketch.exp.svg index 69bb477fa..8c30a5e75 100644 --- a/d2renderers/d2sketch/testdata/class/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/class/sketch.exp.svg @@ -51,19 +51,19 @@ width="626" height="572" viewBox="-102 -102 626 572">containerscloudtall cylinderclass- +containerscloudtall cylinderclass- num int- timeout @@ -808,7 +808,7 @@ width="2482" height="2672" viewBox="-102 -102 2482 2672">containerscloudtall cylinderclass- +containerscloudtall cylinderclass- num int- timeout @@ -808,7 +808,7 @@ width="2622" height="2644" viewBox="-90 -90 2622 2644"> \ No newline at end of file diff --git a/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json b/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json index 296451a21..f6fec0464 100644 --- a/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json +++ b/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json @@ -30,7 +30,7 @@ "methods": null, "columns": null, "label": "", - "fontSize": 20, + "fontSize": 16, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", diff --git a/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg b/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg index 53a789b51..4d951fc2d 100644 --- a/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg +++ b/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg @@ -39,7 +39,7 @@ width="254" height="216" viewBox="-102 -102 254 216"> \ No newline at end of file diff --git a/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json b/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json index ae5cad2dc..2f0ed2f93 100644 --- a/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json +++ b/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json @@ -41,7 +41,7 @@ "methods": null, "columns": null, "label": "class with rows", - "fontSize": 20, + "fontSize": 16, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", @@ -84,7 +84,7 @@ "methods": null, "columns": null, "label": "class without rows", - "fontSize": 20, + "fontSize": 16, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", diff --git a/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg b/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg index e69b90472..e62d41570 100644 --- a/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg +++ b/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg @@ -39,11 +39,11 @@ width="866" height="388" viewBox="-102 -102 866 388">containerscloudtall cylinderclass- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -voidusersid -int -name -string -email -string -password -string -last_login -datetime -container

markdown text expanded to 800x400

+containerscloudtall cylinderclass- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +voidusersid +int +name +string +email +string +password +string +last_login +datetime +container

markdown text expanded to 800x400

:= 5 := a + 7 fmt.Printf("%d", b):= 5 := a + 7 -fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval +fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval containerscloudtall cylinderclass- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -voidusersid -int -name -string -email -string -password -string -last_login -datetime -container

markdown text expanded to 800x400

+containerscloudtall cylinderclass- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +voidusersid +int +name +string +email +string +password +string +last_login +datetime +container

markdown text expanded to 800x400

:= 5 := a + 7 fmt.Printf("%d", b):= 5 := a + 7 -fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval +fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval \ No newline at end of file diff --git a/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json b/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json index f6fec0464..4bd68c182 100644 --- a/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json +++ b/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json @@ -30,7 +30,7 @@ "methods": null, "columns": null, "label": "", - "fontSize": 16, + "fontSize": 24, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", diff --git a/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg b/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg index 4d951fc2d..b37f64c2c 100644 --- a/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg +++ b/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg @@ -39,7 +39,7 @@ width="254" height="216" viewBox="-102 -102 254 216"> \ No newline at end of file diff --git a/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json b/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json index 2f0ed2f93..afdf1799a 100644 --- a/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json +++ b/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json @@ -9,7 +9,7 @@ "x": 0, "y": 0 }, - "width": 283, + "width": 354, "height": 184, "opacity": 1, "strokeDash": 0, @@ -41,15 +41,15 @@ "methods": null, "columns": null, "label": "class with rows", - "fontSize": 16, + "fontSize": 24, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", "italic": false, "bold": false, "underline": false, - "labelWidth": 178, - "labelHeight": 26, + "labelWidth": 249, + "labelHeight": 36, "zIndex": 0, "level": 1, "primaryAccentColor": "#0D32B2", @@ -60,11 +60,11 @@ "id": "class2", "type": "class", "pos": { - "x": 343, - "y": 51 + "x": 414, + "y": 41 }, - "width": 319, - "height": 82, + "width": 404, + "height": 102, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -84,15 +84,15 @@ "methods": null, "columns": null, "label": "class without rows", - "fontSize": 16, + "fontSize": 24, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", "italic": false, "bold": false, "underline": false, - "labelWidth": 214, - "labelHeight": 26, + "labelWidth": 299, + "labelHeight": 36, "zIndex": 0, "level": 1, "primaryAccentColor": "#0D32B2", diff --git a/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg b/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg index e62d41570..d1a01b426 100644 --- a/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg +++ b/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="866" height="388" viewBox="-102 -102 866 388">containerscloudtall cylinderclass- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -voidusersid -int -name -string -email -string -password -string -last_login -datetime -container

markdown text expanded to 800x400

+containerscloudtall cylinderclass- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +voidusersid +int +name +string +email +string +password +string +last_login +datetime +container

markdown text expanded to 800x400

:= 5 := a + 7 fmt.Printf("%d", b):= 5 := a + 7 -fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval +fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval containerscloudtall cylinderclass- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -voidusersid -int -name -string -email -string -password -string -last_login -datetime -container

markdown text expanded to 800x400

+containerscloudtall cylinderclass- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +voidusersid +int +name +string +email +string +password +string +last_login +datetime +container

markdown text expanded to 800x400

:= 5 := a + 7 fmt.Printf("%d", b):= 5 := a + 7 -fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval +fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval \ No newline at end of file diff --git a/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json b/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json index 4bd68c182..296451a21 100644 --- a/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json +++ b/e2etests/testdata/measured/empty-sql_table/dagre/board.exp.json @@ -30,7 +30,7 @@ "methods": null, "columns": null, "label": "", - "fontSize": 24, + "fontSize": 20, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", diff --git a/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg b/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg index b37f64c2c..53a789b51 100644 --- a/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg +++ b/e2etests/testdata/measured/empty-sql_table/dagre/sketch.exp.svg @@ -39,7 +39,7 @@ width="254" height="216" viewBox="-102 -102 254 216"> \ No newline at end of file diff --git a/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json b/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json index afdf1799a..8ba549b2c 100644 --- a/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json +++ b/e2etests/testdata/regression/empty_class_height/dagre/board.exp.json @@ -9,7 +9,7 @@ "x": 0, "y": 0 }, - "width": 354, + "width": 319, "height": 184, "opacity": 1, "strokeDash": 0, @@ -41,15 +41,15 @@ "methods": null, "columns": null, "label": "class with rows", - "fontSize": 24, + "fontSize": 20, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", "italic": false, "bold": false, "underline": false, - "labelWidth": 249, - "labelHeight": 36, + "labelWidth": 214, + "labelHeight": 31, "zIndex": 0, "level": 1, "primaryAccentColor": "#0D32B2", @@ -60,11 +60,11 @@ "id": "class2", "type": "class", "pos": { - "x": 414, - "y": 41 + "x": 379, + "y": 46 }, - "width": 404, - "height": 102, + "width": 362, + "height": 92, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -84,15 +84,15 @@ "methods": null, "columns": null, "label": "class without rows", - "fontSize": 24, + "fontSize": 20, "fontFamily": "DEFAULT", "language": "", "color": "#0A0F25", "italic": false, "bold": false, "underline": false, - "labelWidth": 299, - "labelHeight": 36, + "labelWidth": 257, + "labelHeight": 31, "zIndex": 0, "level": 1, "primaryAccentColor": "#0D32B2", diff --git a/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg b/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg index d1a01b426..e27a99065 100644 --- a/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg +++ b/e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg @@ -3,7 +3,7 @@ id="d2-svg" style="background: white;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" -width="1022" height="388" viewBox="-102 -102 1022 388">containerscloudtall cylinderclass- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -voidusersid -int -name -string -email -string -password -string -last_login -datetime -container

markdown text expanded to 800x400

+containerscloudtall cylinderclass- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +voidusersid +int +name +string +email +string +password +string +last_login +datetime +container

markdown text expanded to 800x400

:= 5 := a + 7 fmt.Printf("%d", b):= 5 := a + 7 -fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval +fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval containerscloudtall cylinderclass- -num -int- -timeout -int- -pid -+ -getStatus() -Enum+ -getJobs() -Job[]+ -setTimeout(seconds int) -voidusersid -int -name -string -email -string -password -string -last_login -datetime -container

markdown text expanded to 800x400

+containerscloudtall cylinderclass- +num +int- +timeout +int- +pid ++ +getStatus() +Enum+ +getJobs() +Job[]+ +setTimeout(seconds int) +voidusersid +int +name +string +email +string +password +string +last_login +datetime +container

markdown text expanded to 800x400

:= 5 := a + 7 fmt.Printf("%d", b):= 5 := a + 7 -fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval +fmt.Printf("%d", b)circle containerdiamond containeroval containerhexagon containerdiamondcirclehexagonoval