From fc3b7286a8a0f80209f45157f0d7a2bca62863ea Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 5 Feb 2023 01:54:35 -0800 Subject: [PATCH 1/2] changes --- d2graph/d2graph.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 0b95146e9d..f74b14496d 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1241,17 +1241,25 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler s := shape.NewShape(shapeType, contentBox) paddingX, paddingY := s.GetDefaultPadding() - if desiredWidth != 0 || desiredHeight != 0 { + if desiredWidth != 0 { paddingX = 0. + } + if desiredHeight != 0 { paddingY = 0. - } else { - // give shapes with icons extra padding to fit their label - if obj.Attributes.Icon != nil { - labelHeight := float64(labelDims.Height + INNER_LABEL_PADDING) - // Evenly pad enough to fit label above icon + } + + // give shapes with icons extra padding to fit their label + if obj.Attributes.Icon != nil { + labelHeight := float64(labelDims.Height + INNER_LABEL_PADDING) + // Evenly pad enough to fit label above icon + if desiredWidth == 0 { paddingX += labelHeight + } + if desiredHeight == 0 { paddingY += labelHeight } + } + if desiredWidth == 0 { switch shapeType { case shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE, shape.IMAGE_TYPE: default: From a6086baa33482f8d5a60b8e21eadccc91e304ded Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 5 Feb 2023 01:56:43 -0800 Subject: [PATCH 2/2] test --- e2etests/regression_test.go | 8 +++ .../just-width/dagre/board.exp.json | 48 +++++++++++++++++ .../just-width/dagre/sketch.exp.svg | 52 +++++++++++++++++++ .../regression/just-width/elk/board.exp.json | 48 +++++++++++++++++ .../regression/just-width/elk/sketch.exp.svg | 52 +++++++++++++++++++ .../stable/people/dagre/board.exp.json | 32 ++++++------ .../stable/people/dagre/sketch.exp.svg | 6 +-- .../testdata/stable/people/elk/board.exp.json | 18 +++---- .../testdata/stable/people/elk/sketch.exp.svg | 6 +-- 9 files changed, 239 insertions(+), 31 deletions(-) create mode 100644 e2etests/testdata/regression/just-width/dagre/board.exp.json create mode 100644 e2etests/testdata/regression/just-width/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/regression/just-width/elk/board.exp.json create mode 100644 e2etests/testdata/regression/just-width/elk/sketch.exp.svg diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go index 4e70e1f5ba..f40d9589b8 100644 --- a/e2etests/regression_test.go +++ b/e2etests/regression_test.go @@ -473,6 +473,14 @@ class2: class without rows { } }, }, + { + name: "just-width", + script: `x: "teamwork: having someone to blame" { + width: 100 +} + +`, + }, } runa(t, tcs) diff --git a/e2etests/testdata/regression/just-width/dagre/board.exp.json b/e2etests/testdata/regression/just-width/dagre/board.exp.json new file mode 100644 index 0000000000..f688df82a4 --- /dev/null +++ b/e2etests/testdata/regression/just-width/dagre/board.exp.json @@ -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": [] +} diff --git a/e2etests/testdata/regression/just-width/dagre/sketch.exp.svg b/e2etests/testdata/regression/just-width/dagre/sketch.exp.svg new file mode 100644 index 0000000000..e5630e8d87 --- /dev/null +++ b/e2etests/testdata/regression/just-width/dagre/sketch.exp.svg @@ -0,0 +1,52 @@ + +teamwork: having someone to blame + + + \ No newline at end of file diff --git a/e2etests/testdata/regression/just-width/elk/board.exp.json b/e2etests/testdata/regression/just-width/elk/board.exp.json new file mode 100644 index 0000000000..a219c0f89b --- /dev/null +++ b/e2etests/testdata/regression/just-width/elk/board.exp.json @@ -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": [] +} diff --git a/e2etests/testdata/regression/just-width/elk/sketch.exp.svg b/e2etests/testdata/regression/just-width/elk/sketch.exp.svg new file mode 100644 index 0000000000..00cb376356 --- /dev/null +++ b/e2etests/testdata/regression/just-width/elk/sketch.exp.svg @@ -0,0 +1,52 @@ + +teamwork: having someone to blame + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/people/dagre/board.exp.json b/e2etests/testdata/stable/people/dagre/board.exp.json index 71a1256258..d352408b94 100644 --- a/e2etests/testdata/stable/people/dagre/board.exp.json +++ b/e2etests/testdata/stable/people/dagre/board.exp.json @@ -6,7 +6,7 @@ "id": "a", "type": "person", "pos": { - "x": 1054, + "x": 1077, "y": 257 }, "width": 49, @@ -47,7 +47,7 @@ "id": "b", "type": "person", "pos": { - "x": 1163, + "x": 1186, "y": 257 }, "width": 64, @@ -88,7 +88,7 @@ "id": "c", "type": "person", "pos": { - "x": 1287, + "x": 1310, "y": 257 }, "width": 89, @@ -129,7 +129,7 @@ "id": "d", "type": "person", "pos": { - "x": 1436, + "x": 1459, "y": 243 }, "width": 142, @@ -170,7 +170,7 @@ "id": "e", "type": "person", "pos": { - "x": 1638, + "x": 1661, "y": 209 }, "width": 245, @@ -211,7 +211,7 @@ "id": "f", "type": "person", "pos": { - "x": 1943, + "x": 1966, "y": 139 }, "width": 453, @@ -252,7 +252,7 @@ "id": "g", "type": "person", "pos": { - "x": 2456, + "x": 2479, "y": 0 }, "width": 870, @@ -294,10 +294,10 @@ "type": "person", "pos": { "x": 0, - "y": 280 + "y": 260 }, - "width": 18, - "height": 21, + "width": 41, + "height": 61, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -334,11 +334,11 @@ "id": "2", "type": "person", "pos": { - "x": 78, - "y": 269 + "x": 101, + "y": 260 }, "width": 64, - "height": 43, + "height": 61, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -375,7 +375,7 @@ "id": "3", "type": "person", "pos": { - "x": 202, + "x": 225, "y": 248 }, "width": 128, @@ -416,7 +416,7 @@ "id": "4", "type": "person", "pos": { - "x": 390, + "x": 413, "y": 120 }, "width": 512, @@ -457,7 +457,7 @@ "id": "5", "type": "person", "pos": { - "x": 962, + "x": 985, "y": 162 }, "width": 32, diff --git a/e2etests/testdata/stable/people/dagre/sketch.exp.svg b/e2etests/testdata/stable/people/dagre/sketch.exp.svg index 86e253a27f..7a84c20e91 100644 --- a/e2etests/testdata/stable/people/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/people/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="3530" height="784" viewBox="-102 -102 3530 784">