From b1cfeb19e63430d2e915b6e0dad53dd47ea4ec51 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 28 Nov 2022 21:39:36 -0800 Subject: [PATCH] 2022-11-28 09:39:36PM --- d2compiler/compile.go | 7 + d2compiler/compile_test.go | 27 + d2graph/d2graph.go | 21 +- d2layouts/d2dagrelayout/layout.go | 10 +- d2layouts/d2elklayout/layout.go | 5 + e2etests/stable_test.go | 14 + .../child_parent_edges/dagre/board.exp.json | 80 +- .../child_parent_edges/dagre/sketch.exp.svg | 4 +- .../stable/orientation/dagre/board.exp.json | 1141 +++++++++++++++++ .../stable/orientation/dagre/sketch.exp.svg | 24 + .../stable/orientation/elk/board.exp.json | 1033 +++++++++++++++ .../stable/orientation/elk/sketch.exp.svg | 24 + .../TestCompile/invalid_orientation.exp.json | 12 + .../TestCompile/root_orientation.exp.json | 66 + .../TestCompile/set_orientation.exp.json | 139 ++ 15 files changed, 2552 insertions(+), 55 deletions(-) create mode 100644 e2etests/testdata/stable/orientation/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/orientation/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/orientation/elk/board.exp.json create mode 100644 e2etests/testdata/stable/orientation/elk/sketch.exp.svg create mode 100644 testdata/d2compiler/TestCompile/invalid_orientation.exp.json create mode 100644 testdata/d2compiler/TestCompile/root_orientation.exp.json create mode 100644 testdata/d2compiler/TestCompile/set_orientation.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index f865bfb9b..7516fa9fe 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -356,6 +356,13 @@ func (c *compiler) applyScalar(attrs *d2graph.Attributes, reserved string, box d case "link": attrs.Link = scalar.ScalarString() return + case "orientation": + if scalar.ScalarString() != "horizontal" && scalar.ScalarString() != "vertical" { + c.errorf(scalar.GetRange().Start, scalar.GetRange().End, `expected "horizontal" or "vertical" orientation, got %q`, scalar.ScalarString()) + return + } + attrs.Orientation.Value = scalar.ScalarString() + return } if _, ok := d2graph.StyleKeywords[reserved]; ok { diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 9da6c3c14..294503a56 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1521,6 +1521,14 @@ dst.id <-> src.dst_id diff.AssertStringEq(t, "sequence_diagram", g.Root.Attributes.Shape.Value) }, }, + { + name: "root_orientation", + + text: `orientation: horizontal`, + assertions: func(t *testing.T, g *d2graph.Graph) { + diff.AssertStringEq(t, "horizontal", g.Root.Attributes.Orientation.Value) + }, + }, { name: "default_orientation", @@ -1529,6 +1537,25 @@ dst.id <-> src.dst_id diff.AssertStringEq(t, "vertical", g.Objects[0].Attributes.Orientation.Value) }, }, + { + name: "set_orientation", + + text: `x: { + orientation: horizontal +}`, + assertions: func(t *testing.T, g *d2graph.Graph) { + diff.AssertStringEq(t, "horizontal", g.Objects[0].Attributes.Orientation.Value) + }, + }, + { + name: "invalid_orientation", + + text: `x: { + orientation: diagonal +}`, + expErr: `d2/testdata/d2compiler/TestCompile/invalid_orientation.d2:2:16: expected "horizontal" or "vertical" orientation, got "diagonal" +`, + }, } for _, tc := range testCases { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 376c59177..a2261686e 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1052,16 +1052,17 @@ func Key(k *d2ast.KeyPath) []string { } var ReservedKeywords = map[string]struct{}{ - "label": {}, - "desc": {}, - "shape": {}, - "icon": {}, - "constraint": {}, - "tooltip": {}, - "link": {}, - "near": {}, - "width": {}, - "height": {}, + "label": {}, + "desc": {}, + "shape": {}, + "icon": {}, + "constraint": {}, + "tooltip": {}, + "link": {}, + "near": {}, + "width": {}, + "height": {}, + "orientation": {}, } // ReservedKeywordHolders are reserved keywords that are meaningless on its own and exist solely to hold a set of reserved keywords diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index 51f30bf09..1edc17f1e 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -60,12 +60,16 @@ func Layout(ctx context.Context, d2graph *d2graph.Graph) (err error) { return err } - configJS := setGraphAttrs(dagreGraphAttrs{ + rootAttrs := dagreGraphAttrs{ ranksep: 100, edgesep: 40, nodesep: 60, - rankdir: "tb", - }) + rankdir: "TB", + } + if d2graph.Root.Attributes.Orientation.Value == "horizontal" { + rootAttrs.rankdir = "LR" + } + configJS := setGraphAttrs(rootAttrs) if _, err := v8ctx.RunScript(configJS, "config.js"); err != nil { return err } diff --git a/d2layouts/d2elklayout/layout.go b/d2layouts/d2elklayout/layout.go index 47904d6cc..209a73856 100644 --- a/d2layouts/d2elklayout/layout.go +++ b/d2layouts/d2elklayout/layout.go @@ -80,6 +80,7 @@ type ELKLayoutOptions struct { NodeSpacing float64 `json:"spacing.nodeNodeBetweenLayers,omitempty"` Padding string `json:"elk.padding,omitempty"` EdgeNodeSpacing float64 `json:"spacing.edgeNodeBetweenLayers,omitempty"` + Direction string `json:"elk.direction"` } func Layout(ctx context.Context, g *d2graph.Graph) (err error) { @@ -119,8 +120,12 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) { HierarchyHandling: "INCLUDE_CHILDREN", NodeSpacing: 100.0, EdgeNodeSpacing: 50.0, + Direction: "DOWN", }, } + if g.Root.Attributes.Orientation.Value == "horizontal" { + elkGraph.LayoutOptions.Direction = "RIGHT" + } elkNodes := make(map[*d2graph.Object]*ELKNode) elkEdges := make(map[*d2graph.Edge]*ELKEdge) diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index d72801cd4..16c43f434 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -986,6 +986,20 @@ sugar -> c c: mixed together c -> solution: we get +`, + }, + { + name: "orientation", + script: `a -> b -> c -> d -> e +b: { + orientation: horizontal + 1 -> 2 -> 3 -> 4 -> 5 + + 2: { + orientation: vertical + a -> b -> c -> d -> e + } +} `, }, } diff --git a/e2etests/testdata/stable/child_parent_edges/dagre/board.exp.json b/e2etests/testdata/stable/child_parent_edges/dagre/board.exp.json index 031c791b9..8c3d30dfc 100644 --- a/e2etests/testdata/stable/child_parent_edges/dagre/board.exp.json +++ b/e2etests/testdata/stable/child_parent_edges/dagre/board.exp.json @@ -8,7 +8,7 @@ "x": 0, "y": 0 }, - "width": 494, + "width": 524, "height": 426, "level": 1, "opacity": 1, @@ -46,7 +46,7 @@ "x": 40, "y": 50 }, - "width": 414, + "width": 444, "height": 326, "level": 2, "opacity": 1, @@ -84,7 +84,7 @@ "x": 80, "y": 100 }, - "width": 334, + "width": 364, "height": 226, "level": 3, "opacity": 1, @@ -182,55 +182,55 @@ "route": [ { "x": 244, - "y": 173.24723247232473 + "y": 174.66192170818505 }, { - "x": 270.66666666666663, - "y": 154.64944649446494 + "x": 273.33333333333337, + "y": 154.932384341637 }, { - "x": 279, + "x": 282.5, "y": 150 }, { - "x": 281.5, + "x": 285.25, "y": 150 }, { - "x": 284, + "x": 288, "y": 150 }, { - "x": 287.33333333333337, + "x": 291.66666666666663, "y": 162.6 }, { - "x": 289.83333333333337, + "x": 294.41666666666663, "y": 181.5 }, { - "x": 292.3333333333333, + "x": 297.1666666666667, "y": 200.4 }, { - "x": 292.3333333333333, + "x": 297.1666666666667, "y": 225.6 }, { - "x": 289.83333333333337, + "x": 294.41666666666663, "y": 244.5 }, { - "x": 287.33333333333337, + "x": 291.66666666666663, "y": 263.4 }, { - "x": 270.66666666666663, - "y": 271.35055350553506 + "x": 273.33333333333337, + "y": 271.06761565836297 }, { "x": 244, - "y": 252.75276752767527 + "y": 251.33807829181495 } ], "isCurve": true, @@ -265,55 +265,55 @@ "route": [ { "x": 244, - "y": 182.30769230769232 + "y": 184.7244094488189 }, { - "x": 292, - "y": 156.46153846153845 + "x": 300, + "y": 156.9448818897638 }, { - "x": 307, + "x": 317.5, "y": 150 }, { - "x": 311.5, + "x": 322.75, "y": 150 }, { - "x": 316, + "x": 328, "y": 150 }, { - "x": 322, + "x": 335, "y": 162.6 }, { - "x": 326.5, + "x": 340.25, "y": 181.5 }, { - "x": 331, + "x": 345.5, "y": 200.4 }, { - "x": 331, + "x": 345.5, "y": 225.6 }, { - "x": 326.5, + "x": 340.25, "y": 244.5 }, { - "x": 322, + "x": 335, "y": 263.4 }, { - "x": 292, - "y": 269.53846153846155 + "x": 300, + "y": 269.0551181102362 }, { "x": 244, - "y": 243.69230769230768 + "y": 241.2755905511811 } ], "isCurve": true, @@ -347,20 +347,20 @@ "labelPercentage": 0, "route": [ { - "x": 243.66666666666669, - "y": 238 + "x": 244.33333333333331, + "y": 235 }, { - "x": 243.93333333333334, - "y": 237.99628770301624 + "x": 244.06666666666666, + "y": 235.3176715176715 }, { - "x": 243.73333333333335, - "y": 237.99907192575407 + "x": 244.26666666666665, + "y": 235.0794178794179 }, { "x": 244, - "y": 237.9953596287703 + "y": 235.3970893970894 } ], "isCurve": true, diff --git a/e2etests/testdata/stable/child_parent_edges/dagre/sketch.exp.svg b/e2etests/testdata/stable/child_parent_edges/dagre/sketch.exp.svg index 1ea56dd9d..54341ea30 100644 --- a/e2etests/testdata/stable/child_parent_edges/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/child_parent_edges/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/e2etests/testdata/stable/orientation/elk/board.exp.json b/e2etests/testdata/stable/orientation/elk/board.exp.json new file mode 100644 index 000000000..a6a3230e0 --- /dev/null +++ b/e2etests/testdata/stable/orientation/elk/board.exp.json @@ -0,0 +1,1033 @@ +{ + "name": "", + "shapes": [ + { + "id": "b", + "type": "", + "pos": { + "x": 225, + "y": 12 + }, + "width": 1478, + "height": 426, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#E3E9FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 18, + "labelHeight": 41, + "labelPosition": "INSIDE_TOP_CENTER" + }, + { + "id": "b.2", + "type": "", + "pos": { + "x": 432, + "y": 87 + }, + "width": 796, + "height": 276, + "level": 2, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "2", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 16, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER" + }, + { + "id": "a", + "type": "", + "pos": { + "x": 12, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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": "c", + "type": "", + "pos": { + "x": 1803, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + }, + { + "id": "d", + "type": "", + "pos": { + "x": 2016, + "y": 162 + }, + "width": 114, + "height": 126, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + }, + { + "id": "e", + "type": "", + "pos": { + "x": 2230, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 1, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "e", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + }, + { + "id": "b.1", + "type": "", + "pos": { + "x": 300, + "y": 162 + }, + "width": 112, + "height": 126, + "level": 2, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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" + }, + { + "id": "b.3", + "type": "", + "pos": { + "x": 1248, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 2, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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" + }, + { + "id": "b.4", + "type": "", + "pos": { + "x": 1381, + "y": 162 + }, + "width": 114, + "height": 126, + "level": 2, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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" + }, + { + "id": "b.5", + "type": "", + "pos": { + "x": 1515, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 2, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#EDF0FD", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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" + }, + { + "id": "b.2.a", + "type": "", + "pos": { + "x": 507, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 3, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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.2.b", + "type": "", + "pos": { + "x": 640, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 3, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "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" + }, + { + "id": "b.2.c", + "type": "", + "pos": { + "x": 773, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 3, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + }, + { + "id": "b.2.d", + "type": "", + "pos": { + "x": 906, + "y": 162 + }, + "width": 114, + "height": 126, + "level": 3, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER" + }, + { + "id": "b.2.e", + "type": "", + "pos": { + "x": 1040, + "y": 162 + }, + "width": 113, + "height": 126, + "level": 3, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "fields": null, + "methods": null, + "columns": null, + "label": "e", + "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": 125, + "y": 225 + }, + { + "x": 225, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "(b -> c)[0]", + "src": "b", + "srcArrow": "none", + "srcLabel": "", + "dst": "c", + "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": 1703, + "y": 225 + }, + { + "x": 1803, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "(c -> d)[0]", + "src": "c", + "srcArrow": "none", + "srcLabel": "", + "dst": "d", + "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": 1916, + "y": 225 + }, + { + "x": 2016, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "(d -> e)[0]", + "src": "d", + "srcArrow": "none", + "srcLabel": "", + "dst": "e", + "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": 2130, + "y": 225 + }, + { + "x": 2230, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.(1 -> 2)[0]", + "src": "b.1", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.2", + "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": 412, + "y": 225 + }, + { + "x": 432, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.(2 -> 3)[0]", + "src": "b.2", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.3", + "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": 1228, + "y": 225 + }, + { + "x": 1248, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.(3 -> 4)[0]", + "src": "b.3", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.4", + "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": 1361, + "y": 225 + }, + { + "x": 1381, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.(4 -> 5)[0]", + "src": "b.4", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.5", + "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": 1495, + "y": 225 + }, + { + "x": 1515, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.2.(a -> b)[0]", + "src": "b.2.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.2.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": 620, + "y": 225 + }, + { + "x": 640, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.2.(b -> c)[0]", + "src": "b.2.b", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.2.c", + "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": 753, + "y": 225 + }, + { + "x": 773, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.2.(c -> d)[0]", + "src": "b.2.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.2.d", + "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": 886, + "y": 225 + }, + { + "x": 906, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + }, + { + "id": "b.2.(d -> e)[0]", + "src": "b.2.d", + "srcArrow": "none", + "srcLabel": "", + "dst": "b.2.e", + "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": 1020, + "y": 225 + }, + { + "x": 1040, + "y": 225 + } + ], + "animated": false, + "tooltip": "", + "icon": null + } + ] +} diff --git a/e2etests/testdata/stable/orientation/elk/sketch.exp.svg b/e2etests/testdata/stable/orientation/elk/sketch.exp.svg new file mode 100644 index 000000000..49447fa1b --- /dev/null +++ b/e2etests/testdata/stable/orientation/elk/sketch.exp.svg @@ -0,0 +1,24 @@ + +bacde21345abcde \ No newline at end of file diff --git a/testdata/d2compiler/TestCompile/invalid_orientation.exp.json b/testdata/d2compiler/TestCompile/invalid_orientation.exp.json new file mode 100644 index 000000000..07a7adc83 --- /dev/null +++ b/testdata/d2compiler/TestCompile/invalid_orientation.exp.json @@ -0,0 +1,12 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/invalid_orientation.d2,1:15:20-1:23:28", + "errmsg": "d2/testdata/d2compiler/TestCompile/invalid_orientation.d2:2:16: expected \"horizontal\" or \"vertical\" orientation, got \"diagonal\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile/root_orientation.exp.json b/testdata/d2compiler/TestCompile/root_orientation.exp.json new file mode 100644 index 000000000..61ef8d9b2 --- /dev/null +++ b/testdata/d2compiler/TestCompile/root_orientation.exp.json @@ -0,0 +1,66 @@ +{ + "graph": { + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/root_orientation.d2,0:0:0-0:23:23", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/root_orientation.d2,0:0:0-0:23:23", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/root_orientation.d2,0:0:0-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/root_orientation.d2,0:0:0-0:11:11", + "value": [ + { + "string": "orientation", + "raw_string": "orientation" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/root_orientation.d2,0:13:13-0:23:23", + "value": [ + { + "string": "horizontal", + "raw_string": "horizontal" + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "orientation": { + "value": "horizontal" + } + } + }, + "edges": null, + "objects": null + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/set_orientation.exp.json b/testdata/d2compiler/TestCompile/set_orientation.exp.json new file mode 100644 index 000000000..c25958113 --- /dev/null +++ b/testdata/d2compiler/TestCompile/set_orientation.exp.json @@ -0,0 +1,139 @@ +{ + "graph": { + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:0:0-2:1:32", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:0:0-2:1:32", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:3:3-2:0:31", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,1:2:7-1:25:30", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,1:2:7-1:13:18", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,1:2:7-1:13:18", + "value": [ + { + "string": "orientation", + "raw_string": "orientation" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,1:15:20-1:25:30", + "value": [ + { + "string": "horizontal", + "raw_string": "horizontal" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "orientation": { + "value": "" + } + } + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/set_orientation.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "orientation": { + "value": "horizontal" + } + } + } + ] + }, + "err": null +}