From 6f8017d16cc10f0beffc1f7028f6eb45fc8d533d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 21 Nov 2022 13:25:14 -0800 Subject: [PATCH] 2022-11-21 01:25:14PM --- d2layouts/d2dagrelayout/layout.go | 2 + e2etests/stable_test.go | 13 ++ .../stable/images/dagre/board.exp.json | 154 ++++++++++++++++++ .../stable/images/dagre/sketch.exp.svg | 24 +++ .../testdata/stable/images/elk/board.exp.json | 145 +++++++++++++++++ .../testdata/stable/images/elk/sketch.exp.svg | 24 +++ .../stable/investigate/dagre/board.exp.json | 2 + .../stable/investigate/elk/board.exp.json | 2 + 8 files changed, 366 insertions(+) create mode 100644 e2etests/testdata/stable/images/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/images/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/images/elk/board.exp.json create mode 100644 e2etests/testdata/stable/images/elk/sketch.exp.svg diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 14e77f164..51f30bf09 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -135,6 +135,8 @@ func Layout(ctx context.Context, d2graph *d2graph.Graph) (err error) { if obj.LabelWidth != nil && obj.LabelHeight != nil { if len(obj.ChildrenArray) > 0 { obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) + } else if obj.Attributes.Shape.Value == d2target.ShapeImage { + obj.LabelPosition = go2.Pointer(string(label.OutsideTopCenter)) } else { obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) } diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index ab7d770a9..e628e0333 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -868,6 +868,19 @@ shipments: { users.id <-> orders.user_id products.id <-> orders.product_id shipments.order_id <-> orders.id`, + }, { + name: "images", + script: `a: { + shape: image + icon: https://icons.terrastruct.com/essentials/004-picture.svg +} + +b: { + shape: image + icon: https://icons.terrastruct.com/essentials/004-picture.svg +} +a -> b +`, }, } diff --git a/e2etests/testdata/stable/images/dagre/board.exp.json b/e2etests/testdata/stable/images/dagre/board.exp.json new file mode 100644 index 000000000..e06473f0f --- /dev/null +++ b/e2etests/testdata/stable/images/dagre/board.exp.json @@ -0,0 +1,154 @@ +{ + "name": "", + "shapes": [ + { + "id": "a", + "type": "image", + "pos": { + "x": 0, + "y": 0 + }, + "width": 128, + "height": 128, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#FFFFFF", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": { + "Scheme": "https", + "Opaque": "", + "User": null, + "Host": "icons.terrastruct.com", + "Path": "/essentials/004-picture.svg", + "RawPath": "", + "OmitHost": false, + "ForceQuery": false, + "RawQuery": "", + "Fragment": "", + "RawFragment": "" + }, + "iconPosition": "INSIDE_MIDDLE_CENTER", + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "OUTSIDE_TOP_CENTER" + }, + { + "id": "b", + "type": "image", + "pos": { + "x": 0, + "y": 228 + }, + "width": 128, + "height": 128, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#FFFFFF", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": { + "Scheme": "https", + "Opaque": "", + "User": null, + "Host": "icons.terrastruct.com", + "Path": "/essentials/004-picture.svg", + "RawPath": "", + "OmitHost": false, + "ForceQuery": false, + "RawQuery": "", + "Fragment": "", + "RawFragment": "" + }, + "iconPosition": "INSIDE_MIDDLE_CENTER", + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "OUTSIDE_TOP_CENTER" + } + ], + "connections": [ + { + "id": "(a -> b)[0]", + "src": "a", + "srcArrow": "none", + "srcLabel": "", + "dst": "b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 64, + "y": 128 + }, + { + "x": 64, + "y": 168 + }, + { + "x": 64, + "y": 188 + }, + { + "x": 64, + "y": 228 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null + } + ] +} diff --git a/e2etests/testdata/stable/images/dagre/sketch.exp.svg b/e2etests/testdata/stable/images/dagre/sketch.exp.svg new file mode 100644 index 000000000..d02c1fa21 --- /dev/null +++ b/e2etests/testdata/stable/images/dagre/sketch.exp.svg @@ -0,0 +1,24 @@ + +ab \ No newline at end of file diff --git a/e2etests/testdata/stable/images/elk/board.exp.json b/e2etests/testdata/stable/images/elk/board.exp.json new file mode 100644 index 000000000..af5875466 --- /dev/null +++ b/e2etests/testdata/stable/images/elk/board.exp.json @@ -0,0 +1,145 @@ +{ + "name": "", + "shapes": [ + { + "id": "a", + "type": "image", + "pos": { + "x": 12, + "y": 12 + }, + "width": 128, + "height": 128, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#FFFFFF", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": { + "Scheme": "https", + "Opaque": "", + "User": null, + "Host": "icons.terrastruct.com", + "Path": "/essentials/004-picture.svg", + "RawPath": "", + "OmitHost": false, + "ForceQuery": false, + "RawQuery": "", + "Fragment": "", + "RawFragment": "" + }, + "iconPosition": "INSIDE_MIDDLE_CENTER", + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + }, + { + "id": "b", + "type": "image", + "pos": { + "x": 240, + "y": 12 + }, + "width": 128, + "height": 128, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#FFFFFF", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": { + "Scheme": "https", + "Opaque": "", + "User": null, + "Host": "icons.terrastruct.com", + "Path": "/essentials/004-picture.svg", + "RawPath": "", + "OmitHost": false, + "ForceQuery": false, + "RawQuery": "", + "Fragment": "", + "RawFragment": "" + }, + "iconPosition": "INSIDE_MIDDLE_CENTER", + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + } + ], + "connections": [ + { + "id": "(a -> b)[0]", + "src": "a", + "srcArrow": "none", + "srcLabel": "", + "dst": "b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 140, + "y": 76 + }, + { + "x": 240, + "y": 76 + } + ], + "animated": false, + "tooltip": "", + "icon": null + } + ] +} diff --git a/e2etests/testdata/stable/images/elk/sketch.exp.svg b/e2etests/testdata/stable/images/elk/sketch.exp.svg new file mode 100644 index 000000000..d0d315ec7 --- /dev/null +++ b/e2etests/testdata/stable/images/elk/sketch.exp.svg @@ -0,0 +1,24 @@ + +ab \ No newline at end of file diff --git a/e2etests/testdata/stable/investigate/dagre/board.exp.json b/e2etests/testdata/stable/investigate/dagre/board.exp.json index 4c216559b..c109a89fa 100644 --- a/e2etests/testdata/stable/investigate/dagre/board.exp.json +++ b/e2etests/testdata/stable/investigate/dagre/board.exp.json @@ -447,6 +447,7 @@ "Host": "icons.terrastruct.com", "Path": "/essentials/time.svg", "RawPath": "", + "OmitHost": false, "ForceQuery": false, "RawQuery": "", "Fragment": "", @@ -534,6 +535,7 @@ "Host": "icons.terrastruct.com", "Path": "/essentials/time.svg", "RawPath": "", + "OmitHost": false, "ForceQuery": false, "RawQuery": "", "Fragment": "", diff --git a/e2etests/testdata/stable/investigate/elk/board.exp.json b/e2etests/testdata/stable/investigate/elk/board.exp.json index 143daffbc..45f03e418 100644 --- a/e2etests/testdata/stable/investigate/elk/board.exp.json +++ b/e2etests/testdata/stable/investigate/elk/board.exp.json @@ -447,6 +447,7 @@ "Host": "icons.terrastruct.com", "Path": "/essentials/time.svg", "RawPath": "", + "OmitHost": false, "ForceQuery": false, "RawQuery": "", "Fragment": "", @@ -534,6 +535,7 @@ "Host": "icons.terrastruct.com", "Path": "/essentials/time.svg", "RawPath": "", + "OmitHost": false, "ForceQuery": false, "RawQuery": "", "Fragment": "",