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