fix height of class with no rows
This commit is contained in:
parent
40dd617b64
commit
220351d48d
6 changed files with 348 additions and 1 deletions
|
|
@ -828,7 +828,7 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R
|
||||||
rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + d2target.VerticalPadding
|
rowHeight := GetTextDimensions(mtexts, ruler, anyRowText, go2.Pointer(d2fonts.SourceCodePro)).Height + d2target.VerticalPadding
|
||||||
dims.Height = rowHeight * (len(obj.Class.Fields) + len(obj.Class.Methods) + 2)
|
dims.Height = rowHeight * (len(obj.Class.Fields) + len(obj.Class.Methods) + 2)
|
||||||
} else {
|
} else {
|
||||||
dims.Height = go2.Max(12, labelDims.Height)
|
dims.Height = 2*go2.Max(12, labelDims.Height) + d2target.VerticalPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
case d2target.ShapeSQLTable:
|
case d2target.ShapeSQLTable:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package e2etests
|
package e2etests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"oss.terrastruct.com/d2/d2target"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testRegression(t *testing.T) {
|
func testRegression(t *testing.T) {
|
||||||
|
|
@ -446,6 +449,30 @@ b -> c
|
||||||
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "empty_class_height",
|
||||||
|
script: `
|
||||||
|
class1: class with rows {
|
||||||
|
shape: class
|
||||||
|
-num: int
|
||||||
|
-timeout: int
|
||||||
|
}
|
||||||
|
|
||||||
|
class2: class without rows {
|
||||||
|
shape: class
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
assertions: func(t *testing.T, g *d2target.Diagram) {
|
||||||
|
if len(g.Shapes) != 2 {
|
||||||
|
t.Fatal("expected 2 shapes")
|
||||||
|
}
|
||||||
|
c1Height := float64(g.Shapes[0].Height)
|
||||||
|
c2Height := float64(g.Shapes[1].Height)
|
||||||
|
if math.Round(c1Height/2.) != c2Height {
|
||||||
|
t.Fatal("expected rowless class to be 1/2 height of class with 2 rows")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
runa(t, tcs)
|
runa(t, tcs)
|
||||||
|
|
|
||||||
104
e2etests/testdata/regression/empty_class_height/dagre/board.exp.json
generated
vendored
Normal file
104
e2etests/testdata/regression/empty_class_height/dagre/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"fontFamily": "SourceSansPro",
|
||||||
|
"shapes": [
|
||||||
|
{
|
||||||
|
"id": "class1",
|
||||||
|
"type": "class",
|
||||||
|
"pos": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"width": 319,
|
||||||
|
"height": 184,
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "class with rows",
|
||||||
|
"fontSize": 20,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": false,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 214,
|
||||||
|
"labelHeight": 31,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1,
|
||||||
|
"primaryAccentColor": "#0D32B2",
|
||||||
|
"secondaryAccentColor": "#4A6FF3",
|
||||||
|
"neutralAccentColor": "#676C7E"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "class2",
|
||||||
|
"type": "class",
|
||||||
|
"pos": {
|
||||||
|
"x": 379,
|
||||||
|
"y": 46
|
||||||
|
},
|
||||||
|
"width": 362,
|
||||||
|
"height": 92,
|
||||||
|
"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": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "class without rows",
|
||||||
|
"fontSize": 20,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": false,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 257,
|
||||||
|
"labelHeight": 31,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1,
|
||||||
|
"primaryAccentColor": "#0D32B2",
|
||||||
|
"secondaryAccentColor": "#4A6FF3",
|
||||||
|
"neutralAccentColor": "#676C7E"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": []
|
||||||
|
}
|
||||||
56
e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg
vendored
Normal file
56
e2etests/testdata/regression/empty_class_height/dagre/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 184 KiB |
104
e2etests/testdata/regression/empty_class_height/elk/board.exp.json
generated
vendored
Normal file
104
e2etests/testdata/regression/empty_class_height/elk/board.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"fontFamily": "SourceSansPro",
|
||||||
|
"shapes": [
|
||||||
|
{
|
||||||
|
"id": "class1",
|
||||||
|
"type": "class",
|
||||||
|
"pos": {
|
||||||
|
"x": 12,
|
||||||
|
"y": 12
|
||||||
|
},
|
||||||
|
"width": 319,
|
||||||
|
"height": 184,
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "class with rows",
|
||||||
|
"fontSize": 20,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": false,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 214,
|
||||||
|
"labelHeight": 31,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1,
|
||||||
|
"primaryAccentColor": "#0D32B2",
|
||||||
|
"secondaryAccentColor": "#4A6FF3",
|
||||||
|
"neutralAccentColor": "#676C7E"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "class2",
|
||||||
|
"type": "class",
|
||||||
|
"pos": {
|
||||||
|
"x": 351,
|
||||||
|
"y": 58
|
||||||
|
},
|
||||||
|
"width": 362,
|
||||||
|
"height": 92,
|
||||||
|
"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": null,
|
||||||
|
"methods": null,
|
||||||
|
"columns": null,
|
||||||
|
"label": "class without rows",
|
||||||
|
"fontSize": 20,
|
||||||
|
"fontFamily": "DEFAULT",
|
||||||
|
"language": "",
|
||||||
|
"color": "#0A0F25",
|
||||||
|
"italic": false,
|
||||||
|
"bold": false,
|
||||||
|
"underline": false,
|
||||||
|
"labelWidth": 257,
|
||||||
|
"labelHeight": 31,
|
||||||
|
"zIndex": 0,
|
||||||
|
"level": 1,
|
||||||
|
"primaryAccentColor": "#0D32B2",
|
||||||
|
"secondaryAccentColor": "#4A6FF3",
|
||||||
|
"neutralAccentColor": "#676C7E"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": []
|
||||||
|
}
|
||||||
56
e2etests/testdata/regression/empty_class_height/elk/sketch.exp.svg
vendored
Normal file
56
e2etests/testdata/regression/empty_class_height/elk/sketch.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 184 KiB |
Loading…
Reference in a new issue