From 57fa903fe6e8cc385dd20bd8ed7f6e659984423c Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Tue, 31 Jan 2023 15:58:06 -0800 Subject: [PATCH] also limit person AR with width/height attributes unless both are entered --- d2graph/d2graph.go | 4 + e2etests/stable_test.go | 15 ++ .../stable/people/dagre/board.exp.json | 223 +++++++++++++++++- .../stable/people/dagre/sketch.exp.svg | 6 +- .../testdata/stable/people/elk/board.exp.json | 207 +++++++++++++++- .../testdata/stable/people/elk/sketch.exp.svg | 6 +- lib/shape/shape.go | 9 + lib/shape/shape_person.go | 8 +- 8 files changed, 457 insertions(+), 21 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index c9d662198..8ccc88f7f 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1187,6 +1187,10 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler sideLength := math.Max(obj.Width, obj.Height) obj.Width = sideLength obj.Height = sideLength + } else if desiredHeight == 0 || desiredWidth == 0 { + if s.GetType() == shape.PERSON_TYPE { + obj.Width, obj.Height = shape.LimitAR(obj.Width, obj.Height, shape.PERSON_AR_LIMIT) + } } } for _, edge := range g.Edges { diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 2f8f332d0..516ce239f 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1895,6 +1895,21 @@ d: -------- e: ---------------- f: -------------------------------- g: ---------------------------------------------------------------- + +1.shape: person +2.shape: person +3.shape: person +4.shape: person +5.shape: person + +1.width: 16 +2.width: 64 +3.width: 128 +4.width: 512 + +# entering both width and height overrides aspect ratio limit +5.height: 256 +5.width: 32 `, }, } diff --git a/e2etests/testdata/stable/people/dagre/board.exp.json b/e2etests/testdata/stable/people/dagre/board.exp.json index dd9f25d4c..fdd71af4c 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": 0, + "x": 1054, "y": 257 }, "width": 49, @@ -47,7 +47,7 @@ "id": "b", "type": "person", "pos": { - "x": 109, + "x": 1163, "y": 257 }, "width": 64, @@ -88,7 +88,7 @@ "id": "c", "type": "person", "pos": { - "x": 233, + "x": 1287, "y": 257 }, "width": 89, @@ -129,7 +129,7 @@ "id": "d", "type": "person", "pos": { - "x": 382, + "x": 1436, "y": 243 }, "width": 142, @@ -170,11 +170,11 @@ "id": "e", "type": "person", "pos": { - "x": 584, - "y": 208 + "x": 1638, + "y": 209 }, "width": 245, - "height": 164, + "height": 163, "opacity": 1, "strokeDash": 0, "strokeWidth": 2, @@ -211,7 +211,7 @@ "id": "f", "type": "person", "pos": { - "x": 889, + "x": 1943, "y": 139 }, "width": 453, @@ -252,7 +252,7 @@ "id": "g", "type": "person", "pos": { - "x": 1402, + "x": 2456, "y": 0 }, "width": 870, @@ -288,6 +288,211 @@ "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 + }, + { + "id": "1", + "type": "person", + "pos": { + "x": 0, + "y": 280 + }, + "width": 18, + "height": 21, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "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": "1", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 12, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "2", + "type": "person", + "pos": { + "x": 78, + "y": 269 + }, + "width": 64, + "height": 43, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "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": "2", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "3", + "type": "person", + "pos": { + "x": 202, + "y": 248 + }, + "width": 128, + "height": 85, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "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": "3", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "4", + "type": "person", + "pos": { + "x": 390, + "y": 120 + }, + "width": 512, + "height": 341, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "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": "4", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "5", + "type": "person", + "pos": { + "x": 962, + "y": 162 + }, + "width": 32, + "height": 256, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "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": "5", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 } ], "connections": [] diff --git a/e2etests/testdata/stable/people/dagre/sketch.exp.svg b/e2etests/testdata/stable/people/dagre/sketch.exp.svg index ae5c71990..a18227e49 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="2476" height="784" viewBox="-102 -102 2476 784">