Merge pull request #763 from alixander/fix-padding

Fix padding
This commit is contained in:
Alexander Wang 2023-02-05 02:02:53 -08:00 committed by GitHub
commit 0da4e150cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 253 additions and 37 deletions

View file

@ -1241,17 +1241,25 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
s := shape.NewShape(shapeType, contentBox) s := shape.NewShape(shapeType, contentBox)
paddingX, paddingY := s.GetDefaultPadding() paddingX, paddingY := s.GetDefaultPadding()
if desiredWidth != 0 || desiredHeight != 0 { if desiredWidth != 0 {
paddingX = 0. paddingX = 0.
}
if desiredHeight != 0 {
paddingY = 0. paddingY = 0.
} else { }
// give shapes with icons extra padding to fit their label
if obj.Attributes.Icon != nil { // give shapes with icons extra padding to fit their label
labelHeight := float64(labelDims.Height + INNER_LABEL_PADDING) if obj.Attributes.Icon != nil {
// Evenly pad enough to fit label above icon labelHeight := float64(labelDims.Height + INNER_LABEL_PADDING)
// Evenly pad enough to fit label above icon
if desiredWidth == 0 {
paddingX += labelHeight paddingX += labelHeight
}
if desiredHeight == 0 {
paddingY += labelHeight paddingY += labelHeight
} }
}
if desiredWidth == 0 {
switch shapeType { switch shapeType {
case shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE, shape.IMAGE_TYPE: case shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE, shape.IMAGE_TYPE:
default: default:

View file

@ -473,6 +473,14 @@ class2: class without rows {
} }
}, },
}, },
{
name: "just-width",
script: `x: "teamwork: having someone to blame" {
width: 100
}
`,
},
} }
runa(t, tcs) runa(t, tcs)

View file

@ -0,0 +1,48 @@
{
"name": "",
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "rectangle",
"pos": {
"x": 0,
"y": 0
},
"width": 262,
"height": 61,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#F7F8FE",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "teamwork: having someone to blame",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 262,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": []
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -0,0 +1,48 @@
{
"name": "",
"fontFamily": "SourceSansPro",
"shapes": [
{
"id": "x",
"type": "rectangle",
"pos": {
"x": 12,
"y": 12
},
"width": 262,
"height": 61,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#F7F8FE",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "teamwork: having someone to blame",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": true,
"underline": false,
"labelWidth": 262,
"labelHeight": 21,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
}
],
"connections": []
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 324 KiB

View file

@ -6,7 +6,7 @@
"id": "a", "id": "a",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 1054, "x": 1077,
"y": 257 "y": 257
}, },
"width": 49, "width": 49,
@ -47,7 +47,7 @@
"id": "b", "id": "b",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 1163, "x": 1186,
"y": 257 "y": 257
}, },
"width": 64, "width": 64,
@ -88,7 +88,7 @@
"id": "c", "id": "c",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 1287, "x": 1310,
"y": 257 "y": 257
}, },
"width": 89, "width": 89,
@ -129,7 +129,7 @@
"id": "d", "id": "d",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 1436, "x": 1459,
"y": 243 "y": 243
}, },
"width": 142, "width": 142,
@ -170,7 +170,7 @@
"id": "e", "id": "e",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 1638, "x": 1661,
"y": 209 "y": 209
}, },
"width": 245, "width": 245,
@ -211,7 +211,7 @@
"id": "f", "id": "f",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 1943, "x": 1966,
"y": 139 "y": 139
}, },
"width": 453, "width": 453,
@ -252,7 +252,7 @@
"id": "g", "id": "g",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 2456, "x": 2479,
"y": 0 "y": 0
}, },
"width": 870, "width": 870,
@ -294,10 +294,10 @@
"type": "person", "type": "person",
"pos": { "pos": {
"x": 0, "x": 0,
"y": 280 "y": 260
}, },
"width": 18, "width": 41,
"height": 21, "height": 61,
"opacity": 1, "opacity": 1,
"strokeDash": 0, "strokeDash": 0,
"strokeWidth": 2, "strokeWidth": 2,
@ -334,11 +334,11 @@
"id": "2", "id": "2",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 78, "x": 101,
"y": 269 "y": 260
}, },
"width": 64, "width": 64,
"height": 43, "height": 61,
"opacity": 1, "opacity": 1,
"strokeDash": 0, "strokeDash": 0,
"strokeWidth": 2, "strokeWidth": 2,
@ -375,7 +375,7 @@
"id": "3", "id": "3",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 202, "x": 225,
"y": 248 "y": 248
}, },
"width": 128, "width": 128,
@ -416,7 +416,7 @@
"id": "4", "id": "4",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 390, "x": 413,
"y": 120 "y": 120
}, },
"width": 512, "width": 512,
@ -457,7 +457,7 @@
"id": "5", "id": "5",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 962, "x": 985,
"y": 162 "y": 162
}, },
"width": 32, "width": 32,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 329 KiB

After

Width:  |  Height:  |  Size: 329 KiB

View file

@ -294,10 +294,10 @@
"type": "person", "type": "person",
"pos": { "pos": {
"x": 2064, "x": 2064,
"y": 291 "y": 271
}, },
"width": 18, "width": 41,
"height": 21, "height": 61,
"opacity": 1, "opacity": 1,
"strokeDash": 0, "strokeDash": 0,
"strokeWidth": 2, "strokeWidth": 2,
@ -334,11 +334,11 @@
"id": "2", "id": "2",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 2102, "x": 2125,
"y": 280 "y": 271
}, },
"width": 64, "width": 64,
"height": 43, "height": 61,
"opacity": 1, "opacity": 1,
"strokeDash": 0, "strokeDash": 0,
"strokeWidth": 2, "strokeWidth": 2,
@ -375,7 +375,7 @@
"id": "3", "id": "3",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 2186, "x": 2209,
"y": 259 "y": 259
}, },
"width": 128, "width": 128,
@ -416,7 +416,7 @@
"id": "4", "id": "4",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 2334, "x": 2357,
"y": 131 "y": 131
}, },
"width": 512, "width": 512,
@ -457,7 +457,7 @@
"id": "5", "id": "5",
"type": "person", "type": "person",
"pos": { "pos": {
"x": 2866, "x": 2889,
"y": 174 "y": 174
}, },
"width": 32, "width": 32,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 329 KiB

After

Width:  |  Height:  |  Size: 329 KiB