diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 66ae6c8f31..f11e8bb997 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -140,9 +140,11 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } mapper := NewObjectMapper() - loadScript := "" for _, obj := range g.Objects { mapper.Register(obj) + } + loadScript := "" + for _, obj := range g.Objects { loadScript += mapper.generateAddNodeLine(obj, int(obj.Width), int(obj.Height)) if obj.Parent != g.Root { loadScript += mapper.generateAddParentLine(obj, obj.Parent) diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go index 6636773a68..2bbea307db 100644 --- a/e2etests/regression_test.go +++ b/e2etests/regression_test.go @@ -1046,6 +1046,7 @@ cf many required: { loadFromFile(t, "multiple_constant_nears"), loadFromFile(t, "empty_nested_grid"), loadFromFile(t, "code_font_size"), + loadFromFile(t, "disclaimer"), } runa(t, tcs) diff --git a/e2etests/testdata/files/disclaimer.d2 b/e2etests/testdata/files/disclaimer.d2 new file mode 100644 index 0000000000..4bdca57094 --- /dev/null +++ b/e2etests/testdata/files/disclaimer.d2 @@ -0,0 +1,16 @@ +vars: { + base-constraints: [NOT NULL; UNQ] + disclaimer: DISCLAIMER { + I am not a lawyer + near: top-center + } +} + +data: { + shape: sql_table + a: int {constraint: [PK; ...${base-constraints}]} +} + +custom-disclaimer: DRAFT DISCLAIMER { + ...${disclaimer} +} diff --git a/e2etests/testdata/regression/disclaimer/dagre/board.exp.json b/e2etests/testdata/regression/disclaimer/dagre/board.exp.json new file mode 100644 index 0000000000..c6f9632d2c --- /dev/null +++ b/e2etests/testdata/regression/disclaimer/dagre/board.exp.json @@ -0,0 +1,206 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "custom-disclaimer.I am not a lawyer", + "type": "rectangle", + "pos": { + "x": 50, + "y": -116 + }, + "width": 166, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B5", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "I am not a lawyer", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 121, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "data", + "type": "sql_table", + "pos": { + "x": 0, + "y": 0 + }, + "width": 266, + "height": 72, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N1", + "stroke": "N7", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "a", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 8, + "labelHeight": 26 + }, + "type": { + "label": "int", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 23, + "labelHeight": 26 + }, + "constraint": [ + "PK", + "NOT NULL", + "UNQ" + ], + "reference": "" + } + ], + "label": "data", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 48, + "labelHeight": 31, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "B2", + "secondaryAccentColor": "AA2", + "neutralAccentColor": "N2" + }, + { + "id": "custom-disclaimer", + "type": "rectangle", + "pos": { + "x": 20, + "y": -146 + }, + "width": 226, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B4", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "DRAFT DISCLAIMER", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 224, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [], + "root": { + "id": "", + "type": "", + "pos": { + "x": 0, + "y": 0 + }, + "width": 0, + "height": 0, + "opacity": 0, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "N7", + "stroke": "", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "zIndex": 0, + "level": 0 + } +} diff --git a/e2etests/testdata/regression/disclaimer/dagre/sketch.exp.svg b/e2etests/testdata/regression/disclaimer/dagre/sketch.exp.svg new file mode 100644 index 0000000000..098d848b1c --- /dev/null +++ b/e2etests/testdata/regression/disclaimer/dagre/sketch.exp.svg @@ -0,0 +1,103 @@ +dataaintPK, NOT NULL, UNQDRAFT DISCLAIMERI am not a lawyer + + + + \ No newline at end of file diff --git a/e2etests/testdata/regression/disclaimer/elk/board.exp.json b/e2etests/testdata/regression/disclaimer/elk/board.exp.json new file mode 100644 index 0000000000..fcea2989a5 --- /dev/null +++ b/e2etests/testdata/regression/disclaimer/elk/board.exp.json @@ -0,0 +1,206 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "custom-disclaimer.I am not a lawyer", + "type": "rectangle", + "pos": { + "x": 62, + "y": -124 + }, + "width": 166, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B5", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "I am not a lawyer", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 121, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "data", + "type": "sql_table", + "pos": { + "x": 12, + "y": 12 + }, + "width": 266, + "height": 72, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N1", + "stroke": "N7", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": [ + { + "name": { + "label": "a", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 8, + "labelHeight": 26 + }, + "type": { + "label": "int", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 23, + "labelHeight": 26 + }, + "constraint": [ + "PK", + "NOT NULL", + "UNQ" + ], + "reference": "" + } + ], + "label": "data", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 48, + "labelHeight": 31, + "zIndex": 0, + "level": 1, + "primaryAccentColor": "B2", + "secondaryAccentColor": "AA2", + "neutralAccentColor": "N2" + }, + { + "id": "custom-disclaimer", + "type": "rectangle", + "pos": { + "x": 10, + "y": -174 + }, + "width": 269, + "height": 166, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B4", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "DRAFT DISCLAIMER", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 224, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [], + "root": { + "id": "", + "type": "", + "pos": { + "x": 0, + "y": 0 + }, + "width": 0, + "height": 0, + "opacity": 0, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "N7", + "stroke": "", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "zIndex": 0, + "level": 0 + } +} diff --git a/e2etests/testdata/regression/disclaimer/elk/sketch.exp.svg b/e2etests/testdata/regression/disclaimer/elk/sketch.exp.svg new file mode 100644 index 0000000000..5058d3e0c9 --- /dev/null +++ b/e2etests/testdata/regression/disclaimer/elk/sketch.exp.svg @@ -0,0 +1,103 @@ +dataaintPK, NOT NULL, UNQDRAFT DISCLAIMERI am not a lawyer + + + + \ No newline at end of file