From 115f46f4289565194db41570f98d7cdcbcefa59d Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 21 Mar 2023 20:42:10 +0800 Subject: [PATCH 01/42] feat: descendants now is allowed for container with near attribute --- d2compiler/compile.go | 4 -- d2layouts/d2near/layout.go | 92 ++++++++++++++++++++++++++++++++------ d2lib/d2.go | 19 +++++++- 3 files changed, 95 insertions(+), 20 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 0654e1567..0900072f9 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -735,10 +735,6 @@ func (c *compiler) validateNear(g *d2graph.Graph) { c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes") continue } - if len(obj.ChildrenArray) > 0 { - c.errorf(obj.Attributes.NearKey, "constant near keys cannot be set on shapes with children") - continue - } } else { c.errorf(obj.Attributes.NearKey, "near key %#v must be the absolute path to a shape or one of the following constants: %s", d2format.Format(obj.Attributes.NearKey), strings.Join(d2graph.NearConstantsArray, ", ")) continue diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 082a0e296..67ce01009 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -10,13 +10,12 @@ import ( "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/label" - "oss.terrastruct.com/util-go/go2" ) const pad = 20 // Layout finds the shapes which are assigned constant near keywords and places them. -func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Object) error { +func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Object, descendantObjectMap map[*d2graph.Object][]*d2graph.Object, descendantEdgeMap map[*d2graph.Object][]*d2graph.Edge) error { if len(constantNears) == 0 { return nil } @@ -27,7 +26,27 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje for _, processCenters := range []bool{true, false} { for _, obj := range constantNears { if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") { + preX, preY := obj.TopLeft.X, obj.TopLeft.Y obj.TopLeft = geo.NewPoint(place(obj)) + dx, dy := obj.TopLeft.X-preX, obj.TopLeft.Y-preY + + subObjects, subEdges := descendantObjectMap[obj], descendantEdgeMap[obj] + for _, subObject := range subObjects { + // `obj` already been replaced above by `place(obj)` + if subObject == obj { + continue + } + subObject.TopLeft.X += dx + subObject.TopLeft.Y += dy + } + for _, subEdge := range subEdges { + for _, point := range subEdge.Route { + point.X += dx + point.Y += dy + } + } + + g.Edges = append(g.Edges, subEdges...) } } for _, obj := range constantNears { @@ -36,27 +55,38 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje g.Objects = append(g.Objects, obj) obj.Parent.Children[obj.ID] = obj obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray, obj) + attachChildren(g, obj) } } } // These shapes skipped core layout, which means they also skipped label placements - for _, obj := range constantNears { - if obj.HasOutsideBottomLabel() { - obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter)) - } else if obj.Attributes.Icon != nil { - obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) - } else { - obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) - } - } + // for _, obj := range constantNears { + // if obj.HasOutsideBottomLabel() { + // obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter)) + // } else if obj.Attributes.Icon != nil { + // obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) + // } else { + // obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) + // } + // } return nil } +func attachChildren(g *d2graph.Graph, obj *d2graph.Object) { + if obj.ChildrenArray != nil && len(obj.ChildrenArray) != 0 { + for _, child := range obj.ChildrenArray { + g.Objects = append(g.Objects, child) + attachChildren(g, child) + } + } +} + // place returns the position of obj, taking into consideration its near value and the diagram func place(obj *d2graph.Object) (float64, float64) { tl, br := boundingBox(obj.Graph) + w := br.X - tl.X h := br.Y - tl.Y switch d2graph.Key(obj.Attributes.NearKey)[0] { @@ -77,12 +107,16 @@ func place(obj *d2graph.Object) (float64, float64) { case "bottom-right": return br.X + pad, br.Y + pad } + return 0, 0 } // WithoutConstantNears plucks out the graph objects which have "near" set to a constant value // This is to be called before layout engines so they don't take part in regular positioning -func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object) { +func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object, descendantObjectMap map[*d2graph.Object][]*d2graph.Object, descendantEdgeMap map[*d2graph.Object][]*d2graph.Edge) { + descendantObjectMap = make(map[*d2graph.Object][]*d2graph.Object) + descendantEdgeMap = make(map[*d2graph.Object][]*d2graph.Edge) + for i := 0; i < len(g.Objects); i++ { obj := g.Objects[i] if obj.Attributes.NearKey == nil { @@ -94,8 +128,11 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra } _, isConst := d2graph.NearConstants[d2graph.Key(obj.Attributes.NearKey)[0]] if isConst { + descendantObjects, edges := pluckOutNearObjectAndEdges(g, obj) + descendantObjectMap[obj] = descendantObjects + descendantEdgeMap[obj] = edges + nears = append(nears, obj) - g.Objects = append(g.Objects[:i], g.Objects[i+1:]...) i-- delete(obj.Parent.Children, strings.ToLower(obj.ID)) for i := 0; i < len(obj.Parent.ChildrenArray); i++ { @@ -106,7 +143,34 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra } } } - return nears + return nears, descendantObjectMap, descendantEdgeMap +} + +func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descendantsObjects []*d2graph.Object, edges []*d2graph.Edge) { + for i := 0; i < len(g.Edges); i++ { + edge := g.Edges[i] + if edge.Src == obj || edge.Dst == obj { + edges = append(edges, edge) + g.Edges = append(g.Edges[:i], g.Edges[i+1:]...) + i-- + } + } + + for i := 0; i < len(g.Objects); i++ { + temp := g.Objects[i] + if temp.AbsID() == obj.AbsID() { + descendantsObjects = append(descendantsObjects, obj) + g.Objects = append(g.Objects[:i], g.Objects[i+1:]...) + for _, child := range obj.ChildrenArray { + subObjects, subEdges := pluckOutNearObjectAndEdges(g, child) + descendantsObjects = append(descendantsObjects, subObjects...) + edges = append(edges, subEdges...) + } + break + } + } + + return descendantsObjects, edges } // boundingBox gets the center of the graph as defined by shapes diff --git a/d2lib/d2.go b/d2lib/d2.go index 060204ea9..0cdd9cc99 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -68,14 +68,29 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta return nil, err } - constantNears := d2near.WithoutConstantNears(ctx, g) + constantNears, descendantObjectMap, descendantEdgeMap := d2near.WithoutConstantNears(ctx, g) + + // run core layout for constantNears + for _, nearObject := range constantNears { + tempGraph := d2graph.NewGraph() + tempGraph.Root.ChildrenArray = []*d2graph.Object{nearObject} + tempGraph.Root.Children[nearObject.ID] = nearObject + tempGraph.Objects = descendantObjectMap[nearObject] + tempGraph.Edges = descendantEdgeMap[nearObject] + + nearObject.Parent = tempGraph.Root + if err = coreLayout(ctx, tempGraph); err != nil { + return nil, err + } + nearObject.Parent = g.Root + } err = d2sequence.Layout(ctx, g, coreLayout) if err != nil { return nil, err } - err = d2near.Layout(ctx, g, constantNears) + err = d2near.Layout(ctx, g, constantNears, descendantObjectMap, descendantEdgeMap) if err != nil { return nil, err } From f62304dac961d2e4ecd77454a8b735c6e742d56c Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 21 Mar 2023 21:04:06 +0800 Subject: [PATCH 02/42] chore: add e2e testcase --- e2etests/stable_test.go | 20 + .../dagre/board.exp.json | 958 ++++++++++++++++++ .../dagre/sketch.exp.svg | 102 ++ .../elk/board.exp.json | 904 +++++++++++++++++ .../elk/sketch.exp.svg | 102 ++ 5 files changed, 2086 insertions(+) create mode 100644 e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json create mode 100644 e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 38641da9f..80cd086c2 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -12,6 +12,26 @@ var testMarkdown string func testStable(t *testing.T) { tcs := []testCase{ + { + name: "near_keys_for_container", + script: ` + x: { + near: top-left + a -> b + c -> d + } + y: { + near: top-right + a -> b + c -> d + } + z: { + near: bottom-center + a -> b + c -> d + } + `, + }, { name: "class_and_sqlTable_border_radius", script: ` diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json new file mode 100644 index 000000000..a2fe1b328 --- /dev/null +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json @@ -0,0 +1,958 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "z", + "type": "rectangle", + "pos": { + "x": -123, + "y": 20 + }, + "width": 247, + "height": 291, + "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": "z", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "z.a", + "type": "rectangle", + "pos": { + "x": -83, + "y": 49 + }, + "width": 53, + "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": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "z.b", + "type": "rectangle", + "pos": { + "x": -83, + "y": 215 + }, + "width": 53, + "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": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "z.c", + "type": "rectangle", + "pos": { + "x": 30, + "y": 49 + }, + "width": 53, + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "z.d", + "type": "rectangle", + "pos": { + "x": 29, + "y": 215 + }, + "width": 54, + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x", + "type": "rectangle", + "pos": { + "x": -390, + "y": -261 + }, + "width": 247, + "height": 291, + "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": "x", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "x.a", + "type": "rectangle", + "pos": { + "x": -350, + "y": -232 + }, + "width": 53, + "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": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x.b", + "type": "rectangle", + "pos": { + "x": -350, + "y": -66 + }, + "width": 53, + "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": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x.c", + "type": "rectangle", + "pos": { + "x": -236, + "y": -232 + }, + "width": 53, + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x.d", + "type": "rectangle", + "pos": { + "x": -237, + "y": -66 + }, + "width": 54, + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 143, + "y": -261 + }, + "width": 247, + "height": 291, + "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": "y", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y.a", + "type": "rectangle", + "pos": { + "x": 183, + "y": -232 + }, + "width": 53, + "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": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y.b", + "type": "rectangle", + "pos": { + "x": 183, + "y": -66 + }, + "width": 53, + "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": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y.c", + "type": "rectangle", + "pos": { + "x": 297, + "y": -232 + }, + "width": 53, + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y.d", + "type": "rectangle", + "pos": { + "x": 296, + "y": -66 + }, + "width": 54, + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + } + ], + "connections": [ + { + "id": "z.(a -> b)[0]", + "src": "z.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "z.b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": -57, + "y": 115.5 + }, + { + "x": -57, + "y": 155.5 + }, + { + "x": -57, + "y": 175.5 + }, + { + "x": -57, + "y": 215.5 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "z.(c -> d)[0]", + "src": "z.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "z.d", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 56.5, + "y": 115.5 + }, + { + "x": 56.5, + "y": 155.5 + }, + { + "x": 56.5, + "y": 175.5 + }, + { + "x": 56.5, + "y": 215.5 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "x.(a -> b)[0]", + "src": "x.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "x.b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": -324, + "y": -166 + }, + { + "x": -324, + "y": -126 + }, + { + "x": -324, + "y": -106 + }, + { + "x": -324, + "y": -66 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "x.(c -> d)[0]", + "src": "x.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "x.d", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": -210.5, + "y": -166 + }, + { + "x": -210.5, + "y": -126 + }, + { + "x": -210.5, + "y": -106 + }, + { + "x": -210.5, + "y": -66 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "y.(a -> b)[0]", + "src": "y.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "y.b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 210, + "y": -166 + }, + { + "x": 210, + "y": -126 + }, + { + "x": 210, + "y": -106 + }, + { + "x": 210, + "y": -66 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "y.(c -> d)[0]", + "src": "y.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "y.d", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 323.5, + "y": -166 + }, + { + "x": 323.5, + "y": -126 + }, + { + "x": 323.5, + "y": -106 + }, + { + "x": 323.5, + "y": -66 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ], + "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/stable/near_keys_for_container/dagre/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg new file mode 100644 index 000000000..7d789cef0 --- /dev/null +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg @@ -0,0 +1,102 @@ +zxyabcdabcdabcd + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json new file mode 100644 index 000000000..3d4d70132 --- /dev/null +++ b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json @@ -0,0 +1,904 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "z", + "type": "rectangle", + "pos": { + "x": -113, + "y": 20 + }, + "width": 227, + "height": 302, + "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": "z", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "z.a", + "type": "rectangle", + "pos": { + "x": -63, + "y": 70 + }, + "width": 53, + "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": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "z.b", + "type": "rectangle", + "pos": { + "x": -63, + "y": 206 + }, + "width": 53, + "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": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "z.c", + "type": "rectangle", + "pos": { + "x": 10, + "y": 70 + }, + "width": 53, + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "z.d", + "type": "rectangle", + "pos": { + "x": 9, + "y": 206 + }, + "width": 54, + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x", + "type": "rectangle", + "pos": { + "x": -360, + "y": -252 + }, + "width": 227, + "height": 302, + "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": "x", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "x.a", + "type": "rectangle", + "pos": { + "x": -310, + "y": -202 + }, + "width": 53, + "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": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x.b", + "type": "rectangle", + "pos": { + "x": -310, + "y": -66 + }, + "width": 53, + "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": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x.c", + "type": "rectangle", + "pos": { + "x": -237, + "y": -202 + }, + "width": 53, + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "x.d", + "type": "rectangle", + "pos": { + "x": -237, + "y": -66 + }, + "width": 54, + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 133, + "y": -252 + }, + "width": 227, + "height": 302, + "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": "y", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y.a", + "type": "rectangle", + "pos": { + "x": 183, + "y": -202 + }, + "width": 53, + "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": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y.b", + "type": "rectangle", + "pos": { + "x": 183, + "y": -66 + }, + "width": 53, + "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": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y.c", + "type": "rectangle", + "pos": { + "x": 257, + "y": -202 + }, + "width": 53, + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "y.d", + "type": "rectangle", + "pos": { + "x": 256, + "y": -66 + }, + "width": 54, + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 2 + } + ], + "connections": [ + { + "id": "z.(a -> b)[0]", + "src": "z.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "z.b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": -37, + "y": 136 + }, + { + "x": -37, + "y": 206 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "z.(c -> d)[0]", + "src": "z.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "z.d", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 36.5, + "y": 136 + }, + { + "x": 36.5, + "y": 206 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "x.(a -> b)[0]", + "src": "x.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "x.b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": -284, + "y": -136 + }, + { + "x": -284, + "y": -66 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "x.(c -> d)[0]", + "src": "x.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "x.d", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": -210.5, + "y": -136 + }, + { + "x": -210.5, + "y": -66 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "y.(a -> b)[0]", + "src": "y.a", + "srcArrow": "none", + "srcLabel": "", + "dst": "y.b", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 210, + "y": -136 + }, + { + "x": 210, + "y": -66 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "y.(c -> d)[0]", + "src": "y.c", + "srcArrow": "none", + "srcLabel": "", + "dst": "y.d", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 283.5, + "y": -136 + }, + { + "x": 283.5, + "y": -66 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ], + "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/stable/near_keys_for_container/elk/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg new file mode 100644 index 000000000..bc3c2fa80 --- /dev/null +++ b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg @@ -0,0 +1,102 @@ +zxyabcdabcdabcd + + + \ No newline at end of file From 4df88649171e8320518957ad42dca98a0cdda8c8 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 21 Mar 2023 21:16:43 +0800 Subject: [PATCH 03/42] chore: regenerate testcases --- .../constant_near_title/dagre/board.exp.json | 1 - .../constant_near_title/dagre/sketch.exp.svg | 170 +++++++++--------- .../constant_near_title/elk/board.exp.json | 1 - .../constant_near_title/elk/sketch.exp.svg | 170 +++++++++--------- 4 files changed, 170 insertions(+), 172 deletions(-) diff --git a/e2etests/testdata/stable/constant_near_title/dagre/board.exp.json b/e2etests/testdata/stable/constant_near_title/dagre/board.exp.json index e1edce8c6..ecde77955 100644 --- a/e2etests/testdata/stable/constant_near_title/dagre/board.exp.json +++ b/e2etests/testdata/stable/constant_near_title/dagre/board.exp.json @@ -245,7 +245,6 @@ "underline": false, "labelWidth": 266, "labelHeight": 51, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 } diff --git a/e2etests/testdata/stable/constant_near_title/dagre/sketch.exp.svg b/e2etests/testdata/stable/constant_near_title/dagre/sketch.exp.svg index fb40652c3..353a90174 100644 --- a/e2etests/testdata/stable/constant_near_title/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_title/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

-
+
\ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_title/elk/board.exp.json b/e2etests/testdata/stable/constant_near_title/elk/board.exp.json index 30d2251bd..5ce0d864e 100644 --- a/e2etests/testdata/stable/constant_near_title/elk/board.exp.json +++ b/e2etests/testdata/stable/constant_near_title/elk/board.exp.json @@ -245,7 +245,6 @@ "underline": false, "labelWidth": 266, "labelHeight": 51, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 } diff --git a/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg index b73c01174..9f093e624 100644 --- a/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_title/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -poll the peopleresultsunfavorablefavorablewill of the people

A winning strategy

-
+
\ No newline at end of file From 5820ba5889b54aec2f4a6a5700dd0e366c434b28 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 21 Mar 2023 22:51:16 +0800 Subject: [PATCH 04/42] chore: regenerate testcases --- .../d2sketch/testdata/animated/sketch.exp.svg | 2 +- .../testdata/animated_dark/sketch.exp.svg | 2 +- .../testdata/root-fill/sketch.exp.svg | 170 +++++++++--------- .../unconnected/dagre/board.exp.json | 1 - .../unconnected/dagre/sketch.exp.svg | 170 +++++++++--------- .../regression/unconnected/elk/board.exp.json | 1 - .../regression/unconnected/elk/sketch.exp.svg | 170 +++++++++--------- .../constant_near_stress/dagre/board.exp.json | 6 - .../constant_near_stress/dagre/sketch.exp.svg | 170 +++++++++--------- .../constant_near_stress/elk/board.exp.json | 6 - .../constant_near_stress/elk/sketch.exp.svg | 170 +++++++++--------- 11 files changed, 427 insertions(+), 441 deletions(-) diff --git a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg index 5436e2231..becd23be5 100644 --- a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg @@ -110,7 +110,7 @@ -wintersummertreessnowsun +wintersummertreessnowsun \ No newline at end of file diff --git a/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg b/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg index 94d2f4ef0..52de585df 100644 --- a/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg @@ -108,7 +108,7 @@ -wintersummertreessnowsun +wintersummertreessnowsun \ No newline at end of file diff --git a/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg b/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg index a359762ab..c9b08dfe4 100644 --- a/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg @@ -1,16 +1,16 @@ -
  • Staging
  • Dispatch to Site
  • - + \ No newline at end of file diff --git a/e2etests/testdata/regression/unconnected/dagre/board.exp.json b/e2etests/testdata/regression/unconnected/dagre/board.exp.json index b878f6fe1..6567131b6 100644 --- a/e2etests/testdata/regression/unconnected/dagre/board.exp.json +++ b/e2etests/testdata/regression/unconnected/dagre/board.exp.json @@ -531,7 +531,6 @@ "underline": false, "labelWidth": 639, "labelHeight": 51, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 } diff --git a/e2etests/testdata/regression/unconnected/dagre/sketch.exp.svg b/e2etests/testdata/regression/unconnected/dagre/sketch.exp.svg index 1be62e4ef..4b464ef8c 100644 --- a/e2etests/testdata/regression/unconnected/dagre/sketch.exp.svg +++ b/e2etests/testdata/regression/unconnected/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -
  • Staging
  • Dispatch to Site
  • -InstallationSupport +InstallationSupport \ No newline at end of file diff --git a/e2etests/testdata/regression/unconnected/elk/board.exp.json b/e2etests/testdata/regression/unconnected/elk/board.exp.json index 77c176dbb..f954eb796 100644 --- a/e2etests/testdata/regression/unconnected/elk/board.exp.json +++ b/e2etests/testdata/regression/unconnected/elk/board.exp.json @@ -531,7 +531,6 @@ "underline": false, "labelWidth": 639, "labelHeight": 51, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 } diff --git a/e2etests/testdata/regression/unconnected/elk/sketch.exp.svg b/e2etests/testdata/regression/unconnected/elk/sketch.exp.svg index 1b026374b..3959bdcb6 100644 --- a/e2etests/testdata/regression/unconnected/elk/sketch.exp.svg +++ b/e2etests/testdata/regression/unconnected/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -
  • Staging
  • Dispatch to Site
  • -InstallationSupport +InstallationSupport \ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json b/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json index 43eed6303..5b41f8c97 100644 --- a/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json +++ b/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json @@ -122,7 +122,6 @@ "underline": false, "labelWidth": 162, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -163,7 +162,6 @@ "underline": false, "labelWidth": 943, "labelHeight": 131, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -286,7 +284,6 @@ "underline": false, "labelWidth": 80, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -327,7 +324,6 @@ "underline": false, "labelWidth": 90, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -368,7 +364,6 @@ "underline": false, "labelWidth": 107, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -409,7 +404,6 @@ "underline": false, "labelWidth": 117, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 } diff --git a/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg b/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg index f8d742476..7f6cf158c 100644 --- a/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -xyThe top of the mountain

    Cats, no less liquid than their shadows, offer no angles to the wind.

    If we can't fix it, it ain't broke.

    Dieters live life in the fasting lane.

    -
    JoeDonaldi am top lefti am top righti am bottom lefti am bottom right +JoeDonaldi am top lefti am top righti am bottom lefti am bottom right
    \ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json b/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json index 12a29e999..340654717 100644 --- a/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json +++ b/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json @@ -122,7 +122,6 @@ "underline": false, "labelWidth": 162, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -163,7 +162,6 @@ "underline": false, "labelWidth": 943, "labelHeight": 131, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -286,7 +284,6 @@ "underline": false, "labelWidth": 80, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -327,7 +324,6 @@ "underline": false, "labelWidth": 90, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -368,7 +364,6 @@ "underline": false, "labelWidth": 107, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 }, @@ -409,7 +404,6 @@ "underline": false, "labelWidth": 117, "labelHeight": 21, - "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 } diff --git a/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg index ba0d24faf..85d7b032e 100644 --- a/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -xyThe top of the mountain

    Cats, no less liquid than their shadows, offer no angles to the wind.

    If we can't fix it, it ain't broke.

    Dieters live life in the fasting lane.

    -
    JoeDonaldi am top lefti am top righti am bottom lefti am bottom right +JoeDonaldi am top lefti am top righti am bottom lefti am bottom right
    \ No newline at end of file From 597385e19cff5780b5ee63eecea43631912aac38 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 21 Mar 2023 22:57:01 +0800 Subject: [PATCH 05/42] fix: delete redundant testcases --- d2compiler/compile_test.go | 20 ------------------- .../TestCompile/near_bad_connected.exp.json | 12 ----------- .../TestCompile/near_bad_container.exp.json | 12 ----------- 3 files changed, 44 deletions(-) delete mode 100644 testdata/d2compiler/TestCompile/near_bad_connected.exp.json delete mode 100644 testdata/d2compiler/TestCompile/near_bad_container.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 584dd5115..122ea4874 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1524,26 +1524,6 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set `, expErr: `d2/testdata/d2compiler/TestCompile/near_bad_constant.d2:1:9: near key "txop-center" must be the absolute path to a shape or one of the following constants: top-left, top-center, top-right, center-left, center-right, bottom-left, bottom-center, bottom-right`, }, - { - name: "near_bad_container", - - text: `x: { - near: top-center - y -} -`, - expErr: `d2/testdata/d2compiler/TestCompile/near_bad_container.d2:2:9: constant near keys cannot be set on shapes with children`, - }, - { - name: "near_bad_connected", - - text: `x: { - near: top-center -} -x -> y -`, - expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:2:9: constant near keys cannot be set on connected shapes`, - }, { name: "nested_near_constant", diff --git a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json deleted file mode 100644 index 76c9d6301..000000000 --- a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "graph": null, - "err": { - "ioerr": null, - "errs": [ - { - "range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,1:8:13-1:18:23", - "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:2:9: constant near keys cannot be set on connected shapes" - } - ] - } -} diff --git a/testdata/d2compiler/TestCompile/near_bad_container.exp.json b/testdata/d2compiler/TestCompile/near_bad_container.exp.json deleted file mode 100644 index 07269f631..000000000 --- a/testdata/d2compiler/TestCompile/near_bad_container.exp.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "graph": null, - "err": { - "ioerr": null, - "errs": [ - { - "range": "d2/testdata/d2compiler/TestCompile/near_bad_container.d2,1:8:13-1:18:23", - "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_container.d2:2:9: constant near keys cannot be set on shapes with children" - } - ] - } -} From 1af68968833675bebf907b099326cf4e206708d5 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 22 Mar 2023 12:12:04 +0800 Subject: [PATCH 06/42] fix: revert near_bad_connected compile_test --- d2compiler/compile_test.go | 11 +++++++++++ .../TestCompile/near_bad_connected.exp.json | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/near_bad_connected.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 122ea4874..a7d40329e 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1524,6 +1524,17 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set `, expErr: `d2/testdata/d2compiler/TestCompile/near_bad_constant.d2:1:9: near key "txop-center" must be the absolute path to a shape or one of the following constants: top-left, top-center, top-right, center-left, center-right, bottom-left, bottom-center, bottom-right`, }, + { + name: "near_bad_connected", + + text: ` + x: { + near: top-center + } + x -> y + `, + expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:2:9: constant near keys cannot be set on connected shapes`, + }, { name: "nested_near_constant", diff --git a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json new file mode 100644 index 000000000..76c9d6301 --- /dev/null +++ b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json @@ -0,0 +1,12 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,1:8:13-1:18:23", + "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:2:9: constant near keys cannot be set on connected shapes" + } + ] + } +} From 3d32611a01b6c0db2abd589c063590601b404875 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 22 Mar 2023 12:12:30 +0800 Subject: [PATCH 07/42] fix: cr delete extra blank line --- d2layouts/d2near/layout.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 67ce01009..f1139a1ff 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -86,7 +86,6 @@ func attachChildren(g *d2graph.Graph, obj *d2graph.Object) { // place returns the position of obj, taking into consideration its near value and the diagram func place(obj *d2graph.Object) (float64, float64) { tl, br := boundingBox(obj.Graph) - w := br.X - tl.X h := br.Y - tl.Y switch d2graph.Key(obj.Attributes.NearKey)[0] { @@ -107,7 +106,6 @@ func place(obj *d2graph.Object) (float64, float64) { case "bottom-right": return br.X + pad, br.Y + pad } - return 0, 0 } From 72253e892fd45d0b951c453939d6e1ed4443869d Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 22 Mar 2023 12:20:36 +0800 Subject: [PATCH 08/42] fix: compile_test testcase --- d2compiler/compile_test.go | 2 +- testdata/d2compiler/TestCompile/near_bad_connected.exp.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index a7d40329e..2cc385bc9 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1533,7 +1533,7 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set } x -> y `, - expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:2:9: constant near keys cannot be set on connected shapes`, + expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:3:12: constant near keys cannot be set on connected shapes`, }, { name: "nested_near_constant", diff --git a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json index 76c9d6301..03c55a204 100644 --- a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json +++ b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json @@ -4,8 +4,8 @@ "ioerr": null, "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,1:8:13-1:18:23", - "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:2:9: constant near keys cannot be set on connected shapes" + "range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,2:11:21-2:21:31", + "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:3:12: constant near keys cannot be set on connected shapes" } ] } From 22cce86892eba35f4dc8b36e9c46676254c06166 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 22 Mar 2023 13:43:25 +0800 Subject: [PATCH 09/42] fix: cr, add validation for near connectioins --- d2compiler/compile.go | 32 ++ d2compiler/compile_test.go | 11 + ...near_descendant_conent_to_outside.exp.json | 387 ++++++++++++++++++ ...ear_descendant_connect_to_outside.exp.json | 12 + 4 files changed, 442 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json create mode 100644 testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 0900072f9..424c2795d 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -735,6 +735,20 @@ func (c *compiler) validateNear(g *d2graph.Graph) { c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes") continue } + + descendantsMap := getNearDescendants(obj) + connectToOutside := false + for _, edge := range g.Edges { + if (descendantsMap[edge.Src] && !descendantsMap[edge.Dst]) || + (!descendantsMap[edge.Src] && descendantsMap[edge.Dst]) { + connectToOutside = true + } + } + + if connectToOutside { + c.errorf(obj.Attributes.NearKey, "a child of a near container cannot connect to outside") + continue + } } else { c.errorf(obj.Attributes.NearKey, "near key %#v must be the absolute path to a shape or one of the following constants: %s", d2format.Format(obj.Attributes.NearKey), strings.Join(d2graph.NearConstantsArray, ", ")) continue @@ -743,6 +757,24 @@ func (c *compiler) validateNear(g *d2graph.Graph) { } } +func getNearDescendants(nearObj *d2graph.Object) map[*d2graph.Object]bool { + descendantsMap := make(map[*d2graph.Object]bool) + + var helper func(obj *d2graph.Object) + + helper = func(obj *d2graph.Object) { + if obj.ChildrenArray != nil { + for _, child := range obj.ChildrenArray { + descendantsMap[child] = true + helper(child) + } + } + } + + helper(nearObj) + return descendantsMap +} + func (c *compiler) validateBoardLinks(g *d2graph.Graph) { for _, obj := range g.Objects { if obj.Attributes.Link == nil { diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 2cc385bc9..c8636dd5d 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1535,6 +1535,17 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set `, expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:3:12: constant near keys cannot be set on connected shapes`, }, + { + name: "near_descendant_connect_to_outside", + text: ` + x: { + near: top-left + y + } + x.y -> z + `, + expErr: "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2:3:12: a child of a near container cannot connect to outside", + }, { name: "nested_near_constant", diff --git a/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json b/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json new file mode 100644 index 000000000..3af3dc2c5 --- /dev/null +++ b/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json @@ -0,0 +1,387 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,0:0:0-5:3:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-3:5:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:7:8-3:4:21", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:12:35", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:12:35", + "src": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:8:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:5:28", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:6:29-4:7:30", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:10:33-4:12:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:11:34-4:12:35", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:8:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:5:28", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:6:29-4:7:30", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:8:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:5:28", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:6:29-4:7:30", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:10:33-4:12:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:11:34-4:12:35", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json b/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json new file mode 100644 index 000000000..d43007599 --- /dev/null +++ b/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json @@ -0,0 +1,12 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2,2:11:21-2:19:29", + "errmsg": "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2:3:12: a child of a near container cannot connect to outside" + } + ] + } +} From b9a94ca11f14235ab9ea406db64d5b531e9e6c8a Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 22 Mar 2023 13:45:24 +0800 Subject: [PATCH 10/42] fix: cr, more testcase --- e2etests/stable_test.go | 7 + .../dagre/board.exp.json | 175 +++++++++++++--- .../dagre/sketch.exp.svg | 160 +++++++------- .../elk/board.exp.json | 195 ++++++++++++++---- .../elk/sketch.exp.svg | 160 +++++++------- 5 files changed, 475 insertions(+), 222 deletions(-) diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 80cd086c2..d843aaf25 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -30,6 +30,13 @@ func testStable(t *testing.T) { a -> b c -> d } + + a: { + near: top-center + b: { + c + } + } `, }, { diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json index a2fe1b328..b8cdf7a2e 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json @@ -208,12 +208,135 @@ "zIndex": 0, "level": 2 }, + { + "id": "a", + "type": "rectangle", + "pos": { + "x": -86, + "y": -245 + }, + "width": 173, + "height": 225, + "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": "a", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "a.b", + "type": "rectangle", + "pos": { + "x": -66, + "y": -179 + }, + "width": 133, + "height": 130, + "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": "b", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 31, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "a.b.c", + "type": "rectangle", + "pos": { + "x": -26, + "y": -147 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 3 + }, { "id": "x", "type": "rectangle", "pos": { "x": -390, - "y": -261 + "y": -526 }, "width": 247, "height": 291, @@ -254,7 +377,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -232 + "y": -497 }, "width": 53, "height": 66, @@ -295,7 +418,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -66 + "y": -331 }, "width": 53, "height": 66, @@ -336,7 +459,7 @@ "type": "rectangle", "pos": { "x": -236, - "y": -232 + "y": -497 }, "width": 53, "height": 66, @@ -377,7 +500,7 @@ "type": "rectangle", "pos": { "x": -237, - "y": -66 + "y": -331 }, "width": 54, "height": 66, @@ -418,7 +541,7 @@ "type": "rectangle", "pos": { "x": 143, - "y": -261 + "y": -526 }, "width": 247, "height": 291, @@ -459,7 +582,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -232 + "y": -497 }, "width": 53, "height": 66, @@ -500,7 +623,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -66 + "y": -331 }, "width": 53, "height": 66, @@ -541,7 +664,7 @@ "type": "rectangle", "pos": { "x": 297, - "y": -232 + "y": -497 }, "width": 53, "height": 66, @@ -582,7 +705,7 @@ "type": "rectangle", "pos": { "x": 296, - "y": -66 + "y": -331 }, "width": 54, "height": 66, @@ -746,19 +869,19 @@ "route": [ { "x": -324, - "y": -166 + "y": -431 }, { "x": -324, - "y": -126 + "y": -391 }, { "x": -324, - "y": -106 + "y": -371 }, { "x": -324, - "y": -66 + "y": -331 } ], "isCurve": true, @@ -795,19 +918,19 @@ "route": [ { "x": -210.5, - "y": -166 + "y": -431 }, { "x": -210.5, - "y": -126 + "y": -391 }, { "x": -210.5, - "y": -106 + "y": -371 }, { "x": -210.5, - "y": -66 + "y": -331 } ], "isCurve": true, @@ -844,19 +967,19 @@ "route": [ { "x": 210, - "y": -166 + "y": -431 }, { "x": 210, - "y": -126 + "y": -391 }, { "x": 210, - "y": -106 + "y": -371 }, { "x": 210, - "y": -66 + "y": -331 } ], "isCurve": true, @@ -893,19 +1016,19 @@ "route": [ { "x": 323.5, - "y": -166 + "y": -431 }, { "x": 323.5, - "y": -126 + "y": -391 }, { "x": 323.5, - "y": -106 + "y": -371 }, { "x": 323.5, - "y": -66 + "y": -331 } ], "isCurve": true, diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg index 7d789cef0..d45f9472d 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -zxyabcdabcdabcd - + .d2-620617940 .fill-N1{fill:#0A0F25;} + .d2-620617940 .fill-N2{fill:#676C7E;} + .d2-620617940 .fill-N3{fill:#9499AB;} + .d2-620617940 .fill-N4{fill:#CFD2DD;} + .d2-620617940 .fill-N5{fill:#DEE1EB;} + .d2-620617940 .fill-N6{fill:#EEF1F8;} + .d2-620617940 .fill-N7{fill:#FFFFFF;} + .d2-620617940 .fill-B1{fill:#0D32B2;} + .d2-620617940 .fill-B2{fill:#0D32B2;} + .d2-620617940 .fill-B3{fill:#E3E9FD;} + .d2-620617940 .fill-B4{fill:#E3E9FD;} + .d2-620617940 .fill-B5{fill:#EDF0FD;} + .d2-620617940 .fill-B6{fill:#F7F8FE;} + .d2-620617940 .fill-AA2{fill:#4A6FF3;} + .d2-620617940 .fill-AA4{fill:#EDF0FD;} + .d2-620617940 .fill-AA5{fill:#F7F8FE;} + .d2-620617940 .fill-AB4{fill:#EDF0FD;} + .d2-620617940 .fill-AB5{fill:#F7F8FE;} + .d2-620617940 .stroke-N1{stroke:#0A0F25;} + .d2-620617940 .stroke-N2{stroke:#676C7E;} + .d2-620617940 .stroke-N3{stroke:#9499AB;} + .d2-620617940 .stroke-N4{stroke:#CFD2DD;} + .d2-620617940 .stroke-N5{stroke:#DEE1EB;} + .d2-620617940 .stroke-N6{stroke:#EEF1F8;} + .d2-620617940 .stroke-N7{stroke:#FFFFFF;} + .d2-620617940 .stroke-B1{stroke:#0D32B2;} + .d2-620617940 .stroke-B2{stroke:#0D32B2;} + .d2-620617940 .stroke-B3{stroke:#E3E9FD;} + .d2-620617940 .stroke-B4{stroke:#E3E9FD;} + .d2-620617940 .stroke-B5{stroke:#EDF0FD;} + .d2-620617940 .stroke-B6{stroke:#F7F8FE;} + .d2-620617940 .stroke-AA2{stroke:#4A6FF3;} + .d2-620617940 .stroke-AA4{stroke:#EDF0FD;} + .d2-620617940 .stroke-AA5{stroke:#F7F8FE;} + .d2-620617940 .stroke-AB4{stroke:#EDF0FD;} + .d2-620617940 .stroke-AB5{stroke:#F7F8FE;} + .d2-620617940 .background-color-N1{background-color:#0A0F25;} + .d2-620617940 .background-color-N2{background-color:#676C7E;} + .d2-620617940 .background-color-N3{background-color:#9499AB;} + .d2-620617940 .background-color-N4{background-color:#CFD2DD;} + .d2-620617940 .background-color-N5{background-color:#DEE1EB;} + .d2-620617940 .background-color-N6{background-color:#EEF1F8;} + .d2-620617940 .background-color-N7{background-color:#FFFFFF;} + .d2-620617940 .background-color-B1{background-color:#0D32B2;} + .d2-620617940 .background-color-B2{background-color:#0D32B2;} + .d2-620617940 .background-color-B3{background-color:#E3E9FD;} + .d2-620617940 .background-color-B4{background-color:#E3E9FD;} + .d2-620617940 .background-color-B5{background-color:#EDF0FD;} + .d2-620617940 .background-color-B6{background-color:#F7F8FE;} + .d2-620617940 .background-color-AA2{background-color:#4A6FF3;} + .d2-620617940 .background-color-AA4{background-color:#EDF0FD;} + .d2-620617940 .background-color-AA5{background-color:#F7F8FE;} + .d2-620617940 .background-color-AB4{background-color:#EDF0FD;} + .d2-620617940 .background-color-AB5{background-color:#F7F8FE;} + .d2-620617940 .color-N1{color:#0A0F25;} + .d2-620617940 .color-N2{color:#676C7E;} + .d2-620617940 .color-N3{color:#9499AB;} + .d2-620617940 .color-N4{color:#CFD2DD;} + .d2-620617940 .color-N5{color:#DEE1EB;} + .d2-620617940 .color-N6{color:#EEF1F8;} + .d2-620617940 .color-N7{color:#FFFFFF;} + .d2-620617940 .color-B1{color:#0D32B2;} + .d2-620617940 .color-B2{color:#0D32B2;} + .d2-620617940 .color-B3{color:#E3E9FD;} + .d2-620617940 .color-B4{color:#E3E9FD;} + .d2-620617940 .color-B5{color:#EDF0FD;} + .d2-620617940 .color-B6{color:#F7F8FE;} + .d2-620617940 .color-AA2{color:#4A6FF3;} + .d2-620617940 .color-AA4{color:#EDF0FD;} + .d2-620617940 .color-AA5{color:#F7F8FE;} + .d2-620617940 .color-AB4{color:#EDF0FD;} + .d2-620617940 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxyabcdbabcdabcdc + \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json index 3d4d70132..cd6e34370 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json @@ -208,12 +208,135 @@ "zIndex": 0, "level": 2 }, + { + "id": "a", + "type": "rectangle", + "pos": { + "x": -126, + "y": -286 + }, + "width": 253, + "height": 266, + "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": "a", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "a.b", + "type": "rectangle", + "pos": { + "x": -76, + "y": -236 + }, + "width": 153, + "height": 166, + "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": "b", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 12, + "labelHeight": 31, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "a.b.c", + "type": "rectangle", + "pos": { + "x": -26, + "y": -186 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 3 + }, { "id": "x", "type": "rectangle", "pos": { - "x": -360, - "y": -252 + "x": -373, + "y": -558 }, "width": 227, "height": 302, @@ -253,8 +376,8 @@ "id": "x.a", "type": "rectangle", "pos": { - "x": -310, - "y": -202 + "x": -323, + "y": -508 }, "width": 53, "height": 66, @@ -294,8 +417,8 @@ "id": "x.b", "type": "rectangle", "pos": { - "x": -310, - "y": -66 + "x": -323, + "y": -372 }, "width": 53, "height": 66, @@ -335,8 +458,8 @@ "id": "x.c", "type": "rectangle", "pos": { - "x": -237, - "y": -202 + "x": -250, + "y": -508 }, "width": 53, "height": 66, @@ -376,8 +499,8 @@ "id": "x.d", "type": "rectangle", "pos": { - "x": -237, - "y": -66 + "x": -250, + "y": -372 }, "width": 54, "height": 66, @@ -417,8 +540,8 @@ "id": "y", "type": "rectangle", "pos": { - "x": 133, - "y": -252 + "x": 146, + "y": -558 }, "width": 227, "height": 302, @@ -458,8 +581,8 @@ "id": "y.a", "type": "rectangle", "pos": { - "x": 183, - "y": -202 + "x": 196, + "y": -508 }, "width": 53, "height": 66, @@ -499,8 +622,8 @@ "id": "y.b", "type": "rectangle", "pos": { - "x": 183, - "y": -66 + "x": 196, + "y": -372 }, "width": 53, "height": 66, @@ -540,8 +663,8 @@ "id": "y.c", "type": "rectangle", "pos": { - "x": 257, - "y": -202 + "x": 270, + "y": -508 }, "width": 53, "height": 66, @@ -581,8 +704,8 @@ "id": "y.d", "type": "rectangle", "pos": { - "x": 256, - "y": -66 + "x": 269, + "y": -372 }, "width": 54, "height": 66, @@ -727,12 +850,12 @@ "labelPercentage": 0, "route": [ { - "x": -284, - "y": -136 + "x": -297, + "y": -442 }, { - "x": -284, - "y": -66 + "x": -297, + "y": -372 } ], "animated": false, @@ -767,12 +890,12 @@ "labelPercentage": 0, "route": [ { - "x": -210.5, - "y": -136 + "x": -223.5, + "y": -442 }, { - "x": -210.5, - "y": -66 + "x": -223.5, + "y": -372 } ], "animated": false, @@ -807,12 +930,12 @@ "labelPercentage": 0, "route": [ { - "x": 210, - "y": -136 + "x": 223, + "y": -442 }, { - "x": 210, - "y": -66 + "x": 223, + "y": -372 } ], "animated": false, @@ -847,12 +970,12 @@ "labelPercentage": 0, "route": [ { - "x": 283.5, - "y": -136 + "x": 296.5, + "y": -442 }, { - "x": 283.5, - "y": -66 + "x": 296.5, + "y": -372 } ], "animated": false, diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg index bc3c2fa80..697c8220e 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -zxyabcdabcdabcd - + .d2-857458616 .fill-N1{fill:#0A0F25;} + .d2-857458616 .fill-N2{fill:#676C7E;} + .d2-857458616 .fill-N3{fill:#9499AB;} + .d2-857458616 .fill-N4{fill:#CFD2DD;} + .d2-857458616 .fill-N5{fill:#DEE1EB;} + .d2-857458616 .fill-N6{fill:#EEF1F8;} + .d2-857458616 .fill-N7{fill:#FFFFFF;} + .d2-857458616 .fill-B1{fill:#0D32B2;} + .d2-857458616 .fill-B2{fill:#0D32B2;} + .d2-857458616 .fill-B3{fill:#E3E9FD;} + .d2-857458616 .fill-B4{fill:#E3E9FD;} + .d2-857458616 .fill-B5{fill:#EDF0FD;} + .d2-857458616 .fill-B6{fill:#F7F8FE;} + .d2-857458616 .fill-AA2{fill:#4A6FF3;} + .d2-857458616 .fill-AA4{fill:#EDF0FD;} + .d2-857458616 .fill-AA5{fill:#F7F8FE;} + .d2-857458616 .fill-AB4{fill:#EDF0FD;} + .d2-857458616 .fill-AB5{fill:#F7F8FE;} + .d2-857458616 .stroke-N1{stroke:#0A0F25;} + .d2-857458616 .stroke-N2{stroke:#676C7E;} + .d2-857458616 .stroke-N3{stroke:#9499AB;} + .d2-857458616 .stroke-N4{stroke:#CFD2DD;} + .d2-857458616 .stroke-N5{stroke:#DEE1EB;} + .d2-857458616 .stroke-N6{stroke:#EEF1F8;} + .d2-857458616 .stroke-N7{stroke:#FFFFFF;} + .d2-857458616 .stroke-B1{stroke:#0D32B2;} + .d2-857458616 .stroke-B2{stroke:#0D32B2;} + .d2-857458616 .stroke-B3{stroke:#E3E9FD;} + .d2-857458616 .stroke-B4{stroke:#E3E9FD;} + .d2-857458616 .stroke-B5{stroke:#EDF0FD;} + .d2-857458616 .stroke-B6{stroke:#F7F8FE;} + .d2-857458616 .stroke-AA2{stroke:#4A6FF3;} + .d2-857458616 .stroke-AA4{stroke:#EDF0FD;} + .d2-857458616 .stroke-AA5{stroke:#F7F8FE;} + .d2-857458616 .stroke-AB4{stroke:#EDF0FD;} + .d2-857458616 .stroke-AB5{stroke:#F7F8FE;} + .d2-857458616 .background-color-N1{background-color:#0A0F25;} + .d2-857458616 .background-color-N2{background-color:#676C7E;} + .d2-857458616 .background-color-N3{background-color:#9499AB;} + .d2-857458616 .background-color-N4{background-color:#CFD2DD;} + .d2-857458616 .background-color-N5{background-color:#DEE1EB;} + .d2-857458616 .background-color-N6{background-color:#EEF1F8;} + .d2-857458616 .background-color-N7{background-color:#FFFFFF;} + .d2-857458616 .background-color-B1{background-color:#0D32B2;} + .d2-857458616 .background-color-B2{background-color:#0D32B2;} + .d2-857458616 .background-color-B3{background-color:#E3E9FD;} + .d2-857458616 .background-color-B4{background-color:#E3E9FD;} + .d2-857458616 .background-color-B5{background-color:#EDF0FD;} + .d2-857458616 .background-color-B6{background-color:#F7F8FE;} + .d2-857458616 .background-color-AA2{background-color:#4A6FF3;} + .d2-857458616 .background-color-AA4{background-color:#EDF0FD;} + .d2-857458616 .background-color-AA5{background-color:#F7F8FE;} + .d2-857458616 .background-color-AB4{background-color:#EDF0FD;} + .d2-857458616 .background-color-AB5{background-color:#F7F8FE;} + .d2-857458616 .color-N1{color:#0A0F25;} + .d2-857458616 .color-N2{color:#676C7E;} + .d2-857458616 .color-N3{color:#9499AB;} + .d2-857458616 .color-N4{color:#CFD2DD;} + .d2-857458616 .color-N5{color:#DEE1EB;} + .d2-857458616 .color-N6{color:#EEF1F8;} + .d2-857458616 .color-N7{color:#FFFFFF;} + .d2-857458616 .color-B1{color:#0D32B2;} + .d2-857458616 .color-B2{color:#0D32B2;} + .d2-857458616 .color-B3{color:#E3E9FD;} + .d2-857458616 .color-B4{color:#E3E9FD;} + .d2-857458616 .color-B5{color:#EDF0FD;} + .d2-857458616 .color-B6{color:#F7F8FE;} + .d2-857458616 .color-AA2{color:#4A6FF3;} + .d2-857458616 .color-AA4{color:#EDF0FD;} + .d2-857458616 .color-AA5{color:#F7F8FE;} + .d2-857458616 .color-AB4{color:#EDF0FD;} + .d2-857458616 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxyabcdbabcdabcdc + \ No newline at end of file From 69532df6aa2c13103548c44a72fd30633d58d9b7 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 22 Mar 2023 15:14:30 +0800 Subject: [PATCH 11/42] fix: cr, integrate logic of construct sub graph inside WithoutConstantNears --- d2layouts/d2near/layout.go | 26 ++++++++++++++++++-------- d2lib/d2.go | 14 ++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index f1139a1ff..183b8dadc 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -15,7 +15,7 @@ import ( const pad = 20 // Layout finds the shapes which are assigned constant near keywords and places them. -func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Object, descendantObjectMap map[*d2graph.Object][]*d2graph.Object, descendantEdgeMap map[*d2graph.Object][]*d2graph.Edge) error { +func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error { if len(constantNears) == 0 { return nil } @@ -30,7 +30,12 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje obj.TopLeft = geo.NewPoint(place(obj)) dx, dy := obj.TopLeft.X-preX, obj.TopLeft.Y-preY - subObjects, subEdges := descendantObjectMap[obj], descendantEdgeMap[obj] + tempGraph := constantNearGraphs[obj] + if tempGraph == nil { + continue + } + + subObjects, subEdges := tempGraph.Objects, tempGraph.Edges for _, subObject := range subObjects { // `obj` already been replaced above by `place(obj)` if subObject == obj { @@ -111,9 +116,8 @@ func place(obj *d2graph.Object) (float64, float64) { // WithoutConstantNears plucks out the graph objects which have "near" set to a constant value // This is to be called before layout engines so they don't take part in regular positioning -func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object, descendantObjectMap map[*d2graph.Object][]*d2graph.Object, descendantEdgeMap map[*d2graph.Object][]*d2graph.Edge) { - descendantObjectMap = make(map[*d2graph.Object][]*d2graph.Object) - descendantEdgeMap = make(map[*d2graph.Object][]*d2graph.Edge) +func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) { + constantNearGraphs = make(map[*d2graph.Object]*d2graph.Graph) for i := 0; i < len(g.Objects); i++ { obj := g.Objects[i] @@ -127,8 +131,14 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra _, isConst := d2graph.NearConstants[d2graph.Key(obj.Attributes.NearKey)[0]] if isConst { descendantObjects, edges := pluckOutNearObjectAndEdges(g, obj) - descendantObjectMap[obj] = descendantObjects - descendantEdgeMap[obj] = edges + + tempGraph := d2graph.NewGraph() + tempGraph.Root.ChildrenArray = []*d2graph.Object{obj} + tempGraph.Root.Children[obj.ID] = obj + tempGraph.Objects = descendantObjects + tempGraph.Edges = edges + + constantNearGraphs[obj] = tempGraph nears = append(nears, obj) i-- @@ -141,7 +151,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra } } } - return nears, descendantObjectMap, descendantEdgeMap + return nears, constantNearGraphs } func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descendantsObjects []*d2graph.Object, edges []*d2graph.Edge) { diff --git a/d2lib/d2.go b/d2lib/d2.go index 0cdd9cc99..377fb7cde 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -68,15 +68,13 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta return nil, err } - constantNears, descendantObjectMap, descendantEdgeMap := d2near.WithoutConstantNears(ctx, g) + constantNears, constantNearGraphs := d2near.WithoutConstantNears(ctx, g) // run core layout for constantNears - for _, nearObject := range constantNears { - tempGraph := d2graph.NewGraph() - tempGraph.Root.ChildrenArray = []*d2graph.Object{nearObject} - tempGraph.Root.Children[nearObject.ID] = nearObject - tempGraph.Objects = descendantObjectMap[nearObject] - tempGraph.Edges = descendantEdgeMap[nearObject] + for nearObject, tempGraph := range constantNearGraphs { + if tempGraph == nil { + continue + } nearObject.Parent = tempGraph.Root if err = coreLayout(ctx, tempGraph); err != nil { @@ -90,7 +88,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta return nil, err } - err = d2near.Layout(ctx, g, constantNears, descendantObjectMap, descendantEdgeMap) + err = d2near.Layout(ctx, g, constantNears, constantNearGraphs) if err != nil { return nil, err } From 17c48516187d88d41af22bea4f48315957ba81d0 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Thu, 23 Mar 2023 12:39:22 +0800 Subject: [PATCH 12/42] fix: calc labelDimension --- d2layouts/d2near/layout.go | 60 +- e2etests/stable_test.go | 570 ------------------ .../constant_near_stress/dagre/board.exp.json | 4 +- .../constant_near_stress/dagre/sketch.exp.svg | 170 +++--- .../constant_near_stress/elk/board.exp.json | 4 +- .../constant_near_stress/elk/sketch.exp.svg | 170 +++--- .../dagre/board.exp.json | 84 +-- .../dagre/sketch.exp.svg | 160 ++--- .../elk/board.exp.json | 60 +- .../elk/sketch.exp.svg | 160 ++--- 10 files changed, 457 insertions(+), 985 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 183b8dadc..747a0b1be 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -93,25 +93,67 @@ func place(obj *d2graph.Object) (float64, float64) { tl, br := boundingBox(obj.Graph) w := br.X - tl.X h := br.Y - tl.Y + + var x, y float64 switch d2graph.Key(obj.Attributes.NearKey)[0] { case "top-left": - return tl.X - obj.Width - pad, tl.Y - obj.Height - pad + x, y = tl.X-obj.Width-pad, tl.Y-obj.Height-pad + break case "top-center": - return tl.X + w/2 - obj.Width/2, tl.Y - obj.Height - pad + x, y = tl.X+w/2-obj.Width/2, tl.Y-obj.Height-pad + break case "top-right": - return br.X + pad, tl.Y - obj.Height - pad + x, y = br.X+pad, tl.Y-obj.Height-pad + break case "center-left": - return tl.X - obj.Width - pad, tl.Y + h/2 - obj.Height/2 + x, y = tl.X-obj.Width-pad, tl.Y+h/2-obj.Height/2 + break case "center-right": - return br.X + pad, tl.Y + h/2 - obj.Height/2 + x, y = br.X+pad, tl.Y+h/2-obj.Height/2 + break case "bottom-left": - return tl.X - obj.Width - pad, br.Y + pad + x, y = tl.X-obj.Width-pad, br.Y+pad + break case "bottom-center": - return br.X - w/2 - obj.Width/2, br.Y + pad + x, y = br.X-w/2-obj.Width/2, br.Y+pad + break case "bottom-right": - return br.X + pad, br.Y + pad + x, y = br.X+pad, br.Y+pad + break } - return 0, 0 + + return calcLabelDimension(obj, x, y) +} + +func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, float64) { + var position string + if obj.LabelPosition != nil { + if strings.Contains(*obj.LabelPosition, "INSIDE") { + return x, y + } + if strings.Contains(*obj.LabelPosition, "_TOP_") { + position = "TOP" + } else if strings.Contains(*obj.LabelPosition, "_LEFT_") { + position = "LEFT" + } else if strings.Contains(*obj.LabelPosition, "_RIGHT_") { + position = "RIGHT" + } else if strings.Contains(*obj.LabelPosition, "_BOTTOM_") { + position = "BOTTOM" + } + + switch position { + case "TOP": + return x, y - float64(*obj.LabelHeight) + case "BOTTOM": + return x, y + float64(*obj.LabelHeight) + case "LEFT": + return x - float64(*obj.LabelWidth), y + case "RIGHT": + return x + float64(*obj.LabelWidth), y + } + } + + return x, y } // WithoutConstantNears plucks out the graph objects which have "near" set to a constant value diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index d843aaf25..5b8594221 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1921,576 +1921,6 @@ i am bottom left: { shape: text; near: bottom-left } i am bottom right: { shape: text; near: bottom-right } `, }, - { - name: "constant_near_title", - script: `title: |md - # A winning strategy -| { near: top-center } - -poll the people -> results -results -> unfavorable -> poll the people -results -> favorable -> will of the people -`, - }, - { - name: "text_font_sizes", - script: `bear: { shape: text; style.font-size: 22; style.bold: true } -mama bear: { shape: text; style.font-size: 28; style.italic: true } -papa bear: { shape: text; style.font-size: 32; style.underline: true } -mama bear -> bear -papa bear -> bear -`, - }, - { - name: "tooltips", - script: `x: { tooltip: Total abstinence is easier than perfect moderation } -y: { tooltip: Gee, I feel kind of LIGHT in the head now,\nknowing I can't make my satellite dish PAYMENTS! } -x -> y -`, - }, - { - name: "links", - script: `x: { link: https://d2lang.com } - y: { link: https://terrastruct.com; tooltip: Gee, I feel kind of LIGHT in the head now,\nknowing I can't make my satellite dish PAYMENTS! } -x -> y -`, - }, - { - name: "unnamed_only_width", - script: ` - -class -> users -> code -> package -> no width - -class: "" { - shape: class - -num: int - -timeout: int - -pid - - +getStatus(): Enum - +getJobs(): "Job[]" - +setTimeout(seconds int) -} - -users: "" { - shape: sql_table - id: int - name: string - email: string - password: string - last_login: datetime -} - -code: |go - a := 5 - b := a + 7 - fmt.Printf("%d", b) -| - -package: "" { shape: package } -no width: "" - - -class.width: 512 -users.width: 512 -code.width: 512 -package.width: 512 -`, - }, - { - name: "unnamed_only_height", - script: ` - -class -> users -> code -> package -> no height - -class: "" { - shape: class - -num: int - -timeout: int - -pid - - +getStatus(): Enum - +getJobs(): "Job[]" - +setTimeout(seconds int) -} - -users: "" { - shape: sql_table - id: int - name: string - email: string - password: string - last_login: datetime -} - -code: |go - a := 5 - b := a + 7 - fmt.Printf("%d", b) -| - -package: "" { shape: package } -no height: "" - - -class.height: 512 -users.height: 512 -code.height: 512 -package.height: 512 -`, - }, - { - name: "container_dimensions", - script: `a: { - width: 500 - b -> c - b.width: 400 - c.width: 600 -} - -b: { - width: 700 - b -> c - e: { - height: 300 - } -} - -c: { - width: 200 - height: 300 - a -} -`, - dagreFeatureError: `Object "a" has attribute "width" and/or "height" set, but layout engine "dagre" does not support dimensions set on containers.`, - }, - { - name: "crow_foot_arrowhead", - script: ` -a1 <-> b1: { - style.stroke-width: 1 - source-arrowhead: { - shape: cf-many - } - target-arrowhead: { - shape: cf-many - } -} -a2 <-> b2: { - style.stroke-width: 3 - source-arrowhead: { - shape: cf-many - } - target-arrowhead: { - shape: cf-many - } -} -a3 <-> b3: { - style.stroke-width: 6 - source-arrowhead: { - shape: cf-many - } - target-arrowhead: { - shape: cf-many - } -} - -c1 <-> d1: { - style.stroke-width: 1 - source-arrowhead: { - shape: cf-many-required - } - target-arrowhead: { - shape: cf-many-required - } -} -c2 <-> d2: { - style.stroke-width: 3 - source-arrowhead: { - shape: cf-many-required - } - target-arrowhead: { - shape: cf-many-required - } -} -c3 <-> d3: { - style.stroke-width: 6 - source-arrowhead: { - shape: cf-many-required - } - target-arrowhead: { - shape: cf-many-required - } -} - -e1 <-> f1: { - style.stroke-width: 1 - source-arrowhead: { - shape: cf-one - } - target-arrowhead: { - shape: cf-one - } -} -e2 <-> f2: { - style.stroke-width: 3 - source-arrowhead: { - shape: cf-one - } - target-arrowhead: { - shape: cf-one - } -} -e3 <-> f3: { - style.stroke-width: 6 - source-arrowhead: { - shape: cf-one - } - target-arrowhead: { - shape: cf-one - } -} - -g1 <-> h1: { - style.stroke-width: 1 - source-arrowhead: { - shape: cf-one-required - } - target-arrowhead: { - shape: cf-one-required - } -} -g2 <-> h2: { - style.stroke-width: 3 - source-arrowhead: { - shape: cf-one-required - } - target-arrowhead: { - shape: cf-one-required - } -} -g3 <-> h3: { - style.stroke-width: 6 - source-arrowhead: { - shape: cf-one-required - } - target-arrowhead: { - shape: cf-one-required - } -} - -c <-> d <-> f: { - style.stroke-width: 1 - style.stroke: "orange" - source-arrowhead: { - shape: cf-many-required - } - target-arrowhead: { - shape: cf-one - } -} -`, - }, - { - name: "circle_arrowhead", - script: ` -a <-> b: circle { - source-arrowhead: { - shape: circle - } - target-arrowhead: { - shape: circle - } -} - -c <-> d: filled-circle { - source-arrowhead: { - shape: circle - style.filled: true - } - target-arrowhead: { - shape: circle - style.filled: true - } -}`, - }, - { - name: "animated", - script: ` -your love life will be -> happy: { style.animated: true } -your love life will be -> harmonious: { style.animated: true } - -boredom <- immortality: { style.animated: true } - -Friday <-> Monday: { style.animated: true } - -Insomnia -- Sleep: { style.animated: true } -Insomnia -- Wake: { - style: { - animated: true - stroke-width: 2 - } -} - -Insomnia -- Dream: { - style: { - animated: true - stroke-width: 8 - } -} - -Listen <-> Talk: { - style.animated: true - source-arrowhead.shape: cf-one - target-arrowhead.shape: diamond - label: hear -} -`, - }, - { - name: "sql_table_tooltip_animated", - script: ` -x: { - shape: sql_table - y - tooltip: I like turtles -} - -a: { - shape: sql_table - b -} - -x.y -> a.b: { - style.animated: true - target-arrowhead.shape: cf-many -} -`, - }, - { - name: "sql_table_column_styles", - script: `Humor in the Court: { - shape: sql_table - Could you see him from where you were standing?: "I could see his head." - And where was his head?: Just above his shoulders. - style.fill: red - style.stroke: lightgray - style.font-color: orange - style.font-size: 20 -} - -Humor in the Court2: { - shape: sql_table - Could you see him from where you were standing?: "I could see his head." - And where was his head?: Just above his shoulders. - style.fill: red - style.stroke: lightgray - style.font-color: orange - style.font-size: 30 -} - -manager: BatchManager { - shape: class - style.font-size: 20 - - -num: int - -timeout: int - -pid - - +getStatus(): Enum - +getJobs(): "Job[]" - +setTimeout(seconds int) -} - -manager2: BatchManager { - shape: class - style.font-size: 30 - - -num: int - -timeout: int - -pid - - +getStatus(): Enum - +getJobs(): "Job[]" - +setTimeout(seconds int) -} -`, - }, - { - name: "near-alone", - script: ` -x: { - near: top-center -} -y: { - near: bottom-center -} -z: { - near: center-left -} -`, - }, - { - name: "border-radius", - script: ` -x: { - style.border-radius: 4 -} -y: { - style.border-radius: 10 -} -multiple2: { - style.border-radius: 6 - style.multiple: true -} -double: { - style.border-radius: 6 - style.double-border: true -} -three-dee: { - style.border-radius: 6 - style.3d: true -} -`, - }, - { - name: "sequence-inter-span-self", - script: ` -shape: sequence_diagram -a: A -b: B - -a.sp1 -> b: foo -a.sp1 -> a.sp2: redirect -a.sp2 -> b: bar -`, - }, - { - name: "people", - script: ` -a.shape: person -b.shape: person -c.shape: person -d.shape: person -e.shape: person -f.shape: person -g.shape: person - -a: - -b: -- -c: ---- -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 -`, - }, - { - name: "ovals", - script: ` -a.shape: oval -b.shape: oval -c.shape: oval -d.shape: oval -e.shape: oval -f.shape: oval -g.shape: oval - -a: - -b: -- -c: ---- -d: -------- -e: ---------------- -f: -------------------------------- -g: ---------------------------------------------------------------- - -1.shape: oval -2.shape: oval -3.shape: oval -4.shape: oval -5.shape: oval - -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 -`, - }, - { - name: "complex-layers", - script: ` -desc: Multi-layer diagram of a home. - -window: { - style.double-border: true -} -roof -garage - -layers: { - window: { - blinds - glass - } - roof: { - shingles - starlink - utility hookup - } - garage: { - tools - vehicles - } - repair: { - desc: How to repair a home. - - steps: { - 1: { - find contractors: { - craigslist - facebook - } - } - 2: { - find contractors -> solicit quotes - } - 3: { - obtain quotes -> negotiate - } - 4: { - negotiate -> book the best bid - } - } - } -} - -scenarios: { - storm: { - water - rain - thunder - } -}`, - }, } runa(t, tcs) diff --git a/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json b/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json index 5b41f8c97..cafa765c0 100644 --- a/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json +++ b/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json @@ -170,7 +170,7 @@ "type": "person", "pos": { "x": -508, - "y": 83 + "y": 104 }, "width": 44, "height": 66, @@ -211,7 +211,7 @@ "type": "person", "pos": { "x": 518, - "y": 83 + "y": 104 }, "width": 65, "height": 66, diff --git a/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg b/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg index 7f6cf158c..62f1a6897 100644 --- a/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -xyThe top of the mountain

    Cats, no less liquid than their shadows, offer no angles to the wind.

    If we can't fix it, it ain't broke.

    Dieters live life in the fasting lane.

    -
    JoeDonaldi am top lefti am top righti am bottom lefti am bottom right +JoeDonaldi am top lefti am top righti am bottom lefti am bottom right
    \ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json b/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json index 340654717..cc89d016a 100644 --- a/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json +++ b/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json @@ -170,7 +170,7 @@ "type": "person", "pos": { "x": -496, - "y": 80 + "y": 101 }, "width": 44, "height": 66, @@ -211,7 +211,7 @@ "type": "person", "pos": { "x": 530, - "y": 80 + "y": 101 }, "width": 65, "height": 66, diff --git a/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg index 85d7b032e..16049be97 100644 --- a/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -xyThe top of the mountain

    Cats, no less liquid than their shadows, offer no angles to the wind.

    If we can't fix it, it ain't broke.

    Dieters live life in the fasting lane.

    -
    JoeDonaldi am top lefti am top righti am bottom lefti am bottom right +JoeDonaldi am top lefti am top righti am bottom lefti am bottom right
    \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json index b8cdf7a2e..61ddbe7b4 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json @@ -8,7 +8,7 @@ "type": "rectangle", "pos": { "x": -123, - "y": 20 + "y": -16 }, "width": 247, "height": 291, @@ -49,7 +49,7 @@ "type": "rectangle", "pos": { "x": -83, - "y": 49 + "y": 13 }, "width": 53, "height": 66, @@ -90,7 +90,7 @@ "type": "rectangle", "pos": { "x": -83, - "y": 215 + "y": 179 }, "width": 53, "height": 66, @@ -131,7 +131,7 @@ "type": "rectangle", "pos": { "x": 30, - "y": 49 + "y": 13 }, "width": 53, "height": 66, @@ -172,7 +172,7 @@ "type": "rectangle", "pos": { "x": 29, - "y": 215 + "y": 179 }, "width": 54, "height": 66, @@ -213,7 +213,7 @@ "type": "rectangle", "pos": { "x": -86, - "y": -245 + "y": -281 }, "width": 173, "height": 225, @@ -254,7 +254,7 @@ "type": "rectangle", "pos": { "x": -66, - "y": -179 + "y": -215 }, "width": 133, "height": 130, @@ -295,7 +295,7 @@ "type": "rectangle", "pos": { "x": -26, - "y": -147 + "y": -183 }, "width": 53, "height": 66, @@ -336,7 +336,7 @@ "type": "rectangle", "pos": { "x": -390, - "y": -526 + "y": -598 }, "width": 247, "height": 291, @@ -377,7 +377,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -497 + "y": -569 }, "width": 53, "height": 66, @@ -418,7 +418,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -331 + "y": -403 }, "width": 53, "height": 66, @@ -459,7 +459,7 @@ "type": "rectangle", "pos": { "x": -236, - "y": -497 + "y": -569 }, "width": 53, "height": 66, @@ -500,7 +500,7 @@ "type": "rectangle", "pos": { "x": -237, - "y": -331 + "y": -403 }, "width": 54, "height": 66, @@ -541,7 +541,7 @@ "type": "rectangle", "pos": { "x": 143, - "y": -526 + "y": -598 }, "width": 247, "height": 291, @@ -582,7 +582,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -497 + "y": -569 }, "width": 53, "height": 66, @@ -623,7 +623,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -331 + "y": -403 }, "width": 53, "height": 66, @@ -664,7 +664,7 @@ "type": "rectangle", "pos": { "x": 297, - "y": -497 + "y": -569 }, "width": 53, "height": 66, @@ -705,7 +705,7 @@ "type": "rectangle", "pos": { "x": 296, - "y": -331 + "y": -403 }, "width": 54, "height": 66, @@ -771,19 +771,19 @@ "route": [ { "x": -57, - "y": 115.5 + "y": 79.5 }, { "x": -57, - "y": 155.5 + "y": 119.5 }, { "x": -57, - "y": 175.5 + "y": 139.5 }, { "x": -57, - "y": 215.5 + "y": 179.5 } ], "isCurve": true, @@ -820,19 +820,19 @@ "route": [ { "x": 56.5, - "y": 115.5 + "y": 79.5 }, { "x": 56.5, - "y": 155.5 + "y": 119.5 }, { "x": 56.5, - "y": 175.5 + "y": 139.5 }, { "x": 56.5, - "y": 215.5 + "y": 179.5 } ], "isCurve": true, @@ -869,19 +869,19 @@ "route": [ { "x": -324, - "y": -431 + "y": -503 }, { "x": -324, - "y": -391 + "y": -463 }, { "x": -324, - "y": -371 + "y": -443 }, { "x": -324, - "y": -331 + "y": -403 } ], "isCurve": true, @@ -918,19 +918,19 @@ "route": [ { "x": -210.5, - "y": -431 + "y": -503 }, { "x": -210.5, - "y": -391 + "y": -463 }, { "x": -210.5, - "y": -371 + "y": -443 }, { "x": -210.5, - "y": -331 + "y": -403 } ], "isCurve": true, @@ -967,19 +967,19 @@ "route": [ { "x": 210, - "y": -431 + "y": -503 }, { "x": 210, - "y": -391 + "y": -463 }, { "x": 210, - "y": -371 + "y": -443 }, { "x": 210, - "y": -331 + "y": -403 } ], "isCurve": true, @@ -1016,19 +1016,19 @@ "route": [ { "x": 323.5, - "y": -431 + "y": -503 }, { "x": 323.5, - "y": -391 + "y": -463 }, { "x": 323.5, - "y": -371 + "y": -443 }, { "x": 323.5, - "y": -331 + "y": -403 } ], "isCurve": true, diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg index d45f9472d..e4cd7b3ab 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxyabcdbabcdabcdc - + .d2-2153435409 .fill-N1{fill:#0A0F25;} + .d2-2153435409 .fill-N2{fill:#676C7E;} + .d2-2153435409 .fill-N3{fill:#9499AB;} + .d2-2153435409 .fill-N4{fill:#CFD2DD;} + .d2-2153435409 .fill-N5{fill:#DEE1EB;} + .d2-2153435409 .fill-N6{fill:#EEF1F8;} + .d2-2153435409 .fill-N7{fill:#FFFFFF;} + .d2-2153435409 .fill-B1{fill:#0D32B2;} + .d2-2153435409 .fill-B2{fill:#0D32B2;} + .d2-2153435409 .fill-B3{fill:#E3E9FD;} + .d2-2153435409 .fill-B4{fill:#E3E9FD;} + .d2-2153435409 .fill-B5{fill:#EDF0FD;} + .d2-2153435409 .fill-B6{fill:#F7F8FE;} + .d2-2153435409 .fill-AA2{fill:#4A6FF3;} + .d2-2153435409 .fill-AA4{fill:#EDF0FD;} + .d2-2153435409 .fill-AA5{fill:#F7F8FE;} + .d2-2153435409 .fill-AB4{fill:#EDF0FD;} + .d2-2153435409 .fill-AB5{fill:#F7F8FE;} + .d2-2153435409 .stroke-N1{stroke:#0A0F25;} + .d2-2153435409 .stroke-N2{stroke:#676C7E;} + .d2-2153435409 .stroke-N3{stroke:#9499AB;} + .d2-2153435409 .stroke-N4{stroke:#CFD2DD;} + .d2-2153435409 .stroke-N5{stroke:#DEE1EB;} + .d2-2153435409 .stroke-N6{stroke:#EEF1F8;} + .d2-2153435409 .stroke-N7{stroke:#FFFFFF;} + .d2-2153435409 .stroke-B1{stroke:#0D32B2;} + .d2-2153435409 .stroke-B2{stroke:#0D32B2;} + .d2-2153435409 .stroke-B3{stroke:#E3E9FD;} + .d2-2153435409 .stroke-B4{stroke:#E3E9FD;} + .d2-2153435409 .stroke-B5{stroke:#EDF0FD;} + .d2-2153435409 .stroke-B6{stroke:#F7F8FE;} + .d2-2153435409 .stroke-AA2{stroke:#4A6FF3;} + .d2-2153435409 .stroke-AA4{stroke:#EDF0FD;} + .d2-2153435409 .stroke-AA5{stroke:#F7F8FE;} + .d2-2153435409 .stroke-AB4{stroke:#EDF0FD;} + .d2-2153435409 .stroke-AB5{stroke:#F7F8FE;} + .d2-2153435409 .background-color-N1{background-color:#0A0F25;} + .d2-2153435409 .background-color-N2{background-color:#676C7E;} + .d2-2153435409 .background-color-N3{background-color:#9499AB;} + .d2-2153435409 .background-color-N4{background-color:#CFD2DD;} + .d2-2153435409 .background-color-N5{background-color:#DEE1EB;} + .d2-2153435409 .background-color-N6{background-color:#EEF1F8;} + .d2-2153435409 .background-color-N7{background-color:#FFFFFF;} + .d2-2153435409 .background-color-B1{background-color:#0D32B2;} + .d2-2153435409 .background-color-B2{background-color:#0D32B2;} + .d2-2153435409 .background-color-B3{background-color:#E3E9FD;} + .d2-2153435409 .background-color-B4{background-color:#E3E9FD;} + .d2-2153435409 .background-color-B5{background-color:#EDF0FD;} + .d2-2153435409 .background-color-B6{background-color:#F7F8FE;} + .d2-2153435409 .background-color-AA2{background-color:#4A6FF3;} + .d2-2153435409 .background-color-AA4{background-color:#EDF0FD;} + .d2-2153435409 .background-color-AA5{background-color:#F7F8FE;} + .d2-2153435409 .background-color-AB4{background-color:#EDF0FD;} + .d2-2153435409 .background-color-AB5{background-color:#F7F8FE;} + .d2-2153435409 .color-N1{color:#0A0F25;} + .d2-2153435409 .color-N2{color:#676C7E;} + .d2-2153435409 .color-N3{color:#9499AB;} + .d2-2153435409 .color-N4{color:#CFD2DD;} + .d2-2153435409 .color-N5{color:#DEE1EB;} + .d2-2153435409 .color-N6{color:#EEF1F8;} + .d2-2153435409 .color-N7{color:#FFFFFF;} + .d2-2153435409 .color-B1{color:#0D32B2;} + .d2-2153435409 .color-B2{color:#0D32B2;} + .d2-2153435409 .color-B3{color:#E3E9FD;} + .d2-2153435409 .color-B4{color:#E3E9FD;} + .d2-2153435409 .color-B5{color:#EDF0FD;} + .d2-2153435409 .color-B6{color:#F7F8FE;} + .d2-2153435409 .color-AA2{color:#4A6FF3;} + .d2-2153435409 .color-AA4{color:#EDF0FD;} + .d2-2153435409 .color-AA5{color:#F7F8FE;} + .d2-2153435409 .color-AB4{color:#EDF0FD;} + .d2-2153435409 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxyabcdbabcdabcdc + \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json index cd6e34370..dc910ddbb 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json @@ -8,7 +8,7 @@ "type": "rectangle", "pos": { "x": -113, - "y": 20 + "y": -16 }, "width": 227, "height": 302, @@ -49,7 +49,7 @@ "type": "rectangle", "pos": { "x": -63, - "y": 70 + "y": 34 }, "width": 53, "height": 66, @@ -90,7 +90,7 @@ "type": "rectangle", "pos": { "x": -63, - "y": 206 + "y": 170 }, "width": 53, "height": 66, @@ -131,7 +131,7 @@ "type": "rectangle", "pos": { "x": 10, - "y": 70 + "y": 34 }, "width": 53, "height": 66, @@ -172,7 +172,7 @@ "type": "rectangle", "pos": { "x": 9, - "y": 206 + "y": 170 }, "width": 54, "height": 66, @@ -213,7 +213,7 @@ "type": "rectangle", "pos": { "x": -126, - "y": -286 + "y": -322 }, "width": 253, "height": 266, @@ -254,7 +254,7 @@ "type": "rectangle", "pos": { "x": -76, - "y": -236 + "y": -272 }, "width": 153, "height": 166, @@ -295,7 +295,7 @@ "type": "rectangle", "pos": { "x": -26, - "y": -186 + "y": -222 }, "width": 53, "height": 66, @@ -336,7 +336,7 @@ "type": "rectangle", "pos": { "x": -373, - "y": -558 + "y": -630 }, "width": 227, "height": 302, @@ -377,7 +377,7 @@ "type": "rectangle", "pos": { "x": -323, - "y": -508 + "y": -580 }, "width": 53, "height": 66, @@ -418,7 +418,7 @@ "type": "rectangle", "pos": { "x": -323, - "y": -372 + "y": -444 }, "width": 53, "height": 66, @@ -459,7 +459,7 @@ "type": "rectangle", "pos": { "x": -250, - "y": -508 + "y": -580 }, "width": 53, "height": 66, @@ -500,7 +500,7 @@ "type": "rectangle", "pos": { "x": -250, - "y": -372 + "y": -444 }, "width": 54, "height": 66, @@ -541,7 +541,7 @@ "type": "rectangle", "pos": { "x": 146, - "y": -558 + "y": -630 }, "width": 227, "height": 302, @@ -582,7 +582,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": -508 + "y": -580 }, "width": 53, "height": 66, @@ -623,7 +623,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": -372 + "y": -444 }, "width": 53, "height": 66, @@ -664,7 +664,7 @@ "type": "rectangle", "pos": { "x": 270, - "y": -508 + "y": -580 }, "width": 53, "height": 66, @@ -705,7 +705,7 @@ "type": "rectangle", "pos": { "x": 269, - "y": -372 + "y": -444 }, "width": 54, "height": 66, @@ -771,11 +771,11 @@ "route": [ { "x": -37, - "y": 136 + "y": 100 }, { "x": -37, - "y": 206 + "y": 170 } ], "animated": false, @@ -811,11 +811,11 @@ "route": [ { "x": 36.5, - "y": 136 + "y": 100 }, { "x": 36.5, - "y": 206 + "y": 170 } ], "animated": false, @@ -851,11 +851,11 @@ "route": [ { "x": -297, - "y": -442 + "y": -514 }, { "x": -297, - "y": -372 + "y": -444 } ], "animated": false, @@ -891,11 +891,11 @@ "route": [ { "x": -223.5, - "y": -442 + "y": -514 }, { "x": -223.5, - "y": -372 + "y": -444 } ], "animated": false, @@ -931,11 +931,11 @@ "route": [ { "x": 223, - "y": -442 + "y": -514 }, { "x": 223, - "y": -372 + "y": -444 } ], "animated": false, @@ -971,11 +971,11 @@ "route": [ { "x": 296.5, - "y": -442 + "y": -514 }, { "x": 296.5, - "y": -372 + "y": -444 } ], "animated": false, diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg index 697c8220e..2f3211cd1 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxyabcdbabcdabcdc - + .d2-2351067076 .fill-N1{fill:#0A0F25;} + .d2-2351067076 .fill-N2{fill:#676C7E;} + .d2-2351067076 .fill-N3{fill:#9499AB;} + .d2-2351067076 .fill-N4{fill:#CFD2DD;} + .d2-2351067076 .fill-N5{fill:#DEE1EB;} + .d2-2351067076 .fill-N6{fill:#EEF1F8;} + .d2-2351067076 .fill-N7{fill:#FFFFFF;} + .d2-2351067076 .fill-B1{fill:#0D32B2;} + .d2-2351067076 .fill-B2{fill:#0D32B2;} + .d2-2351067076 .fill-B3{fill:#E3E9FD;} + .d2-2351067076 .fill-B4{fill:#E3E9FD;} + .d2-2351067076 .fill-B5{fill:#EDF0FD;} + .d2-2351067076 .fill-B6{fill:#F7F8FE;} + .d2-2351067076 .fill-AA2{fill:#4A6FF3;} + .d2-2351067076 .fill-AA4{fill:#EDF0FD;} + .d2-2351067076 .fill-AA5{fill:#F7F8FE;} + .d2-2351067076 .fill-AB4{fill:#EDF0FD;} + .d2-2351067076 .fill-AB5{fill:#F7F8FE;} + .d2-2351067076 .stroke-N1{stroke:#0A0F25;} + .d2-2351067076 .stroke-N2{stroke:#676C7E;} + .d2-2351067076 .stroke-N3{stroke:#9499AB;} + .d2-2351067076 .stroke-N4{stroke:#CFD2DD;} + .d2-2351067076 .stroke-N5{stroke:#DEE1EB;} + .d2-2351067076 .stroke-N6{stroke:#EEF1F8;} + .d2-2351067076 .stroke-N7{stroke:#FFFFFF;} + .d2-2351067076 .stroke-B1{stroke:#0D32B2;} + .d2-2351067076 .stroke-B2{stroke:#0D32B2;} + .d2-2351067076 .stroke-B3{stroke:#E3E9FD;} + .d2-2351067076 .stroke-B4{stroke:#E3E9FD;} + .d2-2351067076 .stroke-B5{stroke:#EDF0FD;} + .d2-2351067076 .stroke-B6{stroke:#F7F8FE;} + .d2-2351067076 .stroke-AA2{stroke:#4A6FF3;} + .d2-2351067076 .stroke-AA4{stroke:#EDF0FD;} + .d2-2351067076 .stroke-AA5{stroke:#F7F8FE;} + .d2-2351067076 .stroke-AB4{stroke:#EDF0FD;} + .d2-2351067076 .stroke-AB5{stroke:#F7F8FE;} + .d2-2351067076 .background-color-N1{background-color:#0A0F25;} + .d2-2351067076 .background-color-N2{background-color:#676C7E;} + .d2-2351067076 .background-color-N3{background-color:#9499AB;} + .d2-2351067076 .background-color-N4{background-color:#CFD2DD;} + .d2-2351067076 .background-color-N5{background-color:#DEE1EB;} + .d2-2351067076 .background-color-N6{background-color:#EEF1F8;} + .d2-2351067076 .background-color-N7{background-color:#FFFFFF;} + .d2-2351067076 .background-color-B1{background-color:#0D32B2;} + .d2-2351067076 .background-color-B2{background-color:#0D32B2;} + .d2-2351067076 .background-color-B3{background-color:#E3E9FD;} + .d2-2351067076 .background-color-B4{background-color:#E3E9FD;} + .d2-2351067076 .background-color-B5{background-color:#EDF0FD;} + .d2-2351067076 .background-color-B6{background-color:#F7F8FE;} + .d2-2351067076 .background-color-AA2{background-color:#4A6FF3;} + .d2-2351067076 .background-color-AA4{background-color:#EDF0FD;} + .d2-2351067076 .background-color-AA5{background-color:#F7F8FE;} + .d2-2351067076 .background-color-AB4{background-color:#EDF0FD;} + .d2-2351067076 .background-color-AB5{background-color:#F7F8FE;} + .d2-2351067076 .color-N1{color:#0A0F25;} + .d2-2351067076 .color-N2{color:#676C7E;} + .d2-2351067076 .color-N3{color:#9499AB;} + .d2-2351067076 .color-N4{color:#CFD2DD;} + .d2-2351067076 .color-N5{color:#DEE1EB;} + .d2-2351067076 .color-N6{color:#EEF1F8;} + .d2-2351067076 .color-N7{color:#FFFFFF;} + .d2-2351067076 .color-B1{color:#0D32B2;} + .d2-2351067076 .color-B2{color:#0D32B2;} + .d2-2351067076 .color-B3{color:#E3E9FD;} + .d2-2351067076 .color-B4{color:#E3E9FD;} + .d2-2351067076 .color-B5{color:#EDF0FD;} + .d2-2351067076 .color-B6{color:#F7F8FE;} + .d2-2351067076 .color-AA2{color:#4A6FF3;} + .d2-2351067076 .color-AA4{color:#EDF0FD;} + .d2-2351067076 .color-AA5{color:#F7F8FE;} + .d2-2351067076 .color-AB4{color:#EDF0FD;} + .d2-2351067076 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxyabcdbabcdabcdc + \ No newline at end of file From df19311f9bd0ccc1c1efd987861bdc633a6bf022 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Fri, 24 Mar 2023 12:08:19 +0800 Subject: [PATCH 13/42] fix: ignore objects inside near container when calc boundingBox --- d2graph/d2graph.go | 11 ++++++----- d2layouts/d2near/layout.go | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 54c658a21..74d238b9c 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -90,11 +90,12 @@ type Object struct { LabelDimensions d2target.TextDimensions `json:"label_dimensions"` References []Reference `json:"references,omitempty"` - *geo.Box `json:"box,omitempty"` - LabelPosition *string `json:"labelPosition,omitempty"` - LabelWidth *int `json:"labelWidth,omitempty"` - LabelHeight *int `json:"labelHeight,omitempty"` - IconPosition *string `json:"iconPosition,omitempty"` + *geo.Box `json:"box,omitempty"` + LabelPosition *string `json:"labelPosition,omitempty"` + LabelWidth *int `json:"labelWidth,omitempty"` + LabelHeight *int `json:"labelHeight,omitempty"` + IconPosition *string `json:"iconPosition,omitempty"` + IsInsideNearContainer bool `json:"isInsideNearContainer,omitempty"` Class *d2target.Class `json:"class,omitempty"` SQLTable *d2target.SQLTable `json:"sql_table,omitempty"` diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 747a0b1be..42e60c1c2 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -128,9 +128,6 @@ func place(obj *d2graph.Object) (float64, float64) { func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, float64) { var position string if obj.LabelPosition != nil { - if strings.Contains(*obj.LabelPosition, "INSIDE") { - return x, y - } if strings.Contains(*obj.LabelPosition, "_TOP_") { position = "TOP" } else if strings.Contains(*obj.LabelPosition, "_LEFT_") { @@ -211,6 +208,7 @@ func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descenda if temp.AbsID() == obj.AbsID() { descendantsObjects = append(descendantsObjects, obj) g.Objects = append(g.Objects[:i], g.Objects[i+1:]...) + obj.IsInsideNearContainer = true for _, child := range obj.ChildrenArray { subObjects, subEdges := pluckOutNearObjectAndEdges(g, child) descendantsObjects = append(descendantsObjects, subObjects...) @@ -248,6 +246,9 @@ func boundingBox(g *d2graph.Graph) (tl, br *geo.Point) { y2 = math.Max(y2, obj.TopLeft.Y+obj.Height) } } else { + if obj.IsInsideNearContainer { + continue + } x1 = math.Min(x1, obj.TopLeft.X) y1 = math.Min(y1, obj.TopLeft.Y) x2 = math.Max(x2, obj.TopLeft.X+obj.Width) From 2ae163614055686914dbbab60de911c0d0e59ec6 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Fri, 24 Mar 2023 12:09:21 +0800 Subject: [PATCH 14/42] fix: regenerate testcases --- .../dagre/board.exp.json | 52 +++--- .../dagre/sketch.exp.svg | 160 +++++++++--------- .../elk/board.exp.json | 36 ++-- .../elk/sketch.exp.svg | 160 +++++++++--------- 4 files changed, 204 insertions(+), 204 deletions(-) diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json index 61ddbe7b4..6778de2cd 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json @@ -336,7 +336,7 @@ "type": "rectangle", "pos": { "x": -390, - "y": -598 + "y": -347 }, "width": 247, "height": 291, @@ -377,7 +377,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -569 + "y": -317 }, "width": 53, "height": 66, @@ -418,7 +418,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -403 + "y": -151 }, "width": 53, "height": 66, @@ -459,7 +459,7 @@ "type": "rectangle", "pos": { "x": -236, - "y": -569 + "y": -317 }, "width": 53, "height": 66, @@ -500,7 +500,7 @@ "type": "rectangle", "pos": { "x": -237, - "y": -403 + "y": -151 }, "width": 54, "height": 66, @@ -541,7 +541,7 @@ "type": "rectangle", "pos": { "x": 143, - "y": -598 + "y": -347 }, "width": 247, "height": 291, @@ -582,7 +582,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -569 + "y": -317 }, "width": 53, "height": 66, @@ -623,7 +623,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -403 + "y": -151 }, "width": 53, "height": 66, @@ -664,7 +664,7 @@ "type": "rectangle", "pos": { "x": 297, - "y": -569 + "y": -317 }, "width": 53, "height": 66, @@ -705,7 +705,7 @@ "type": "rectangle", "pos": { "x": 296, - "y": -403 + "y": -151 }, "width": 54, "height": 66, @@ -869,19 +869,19 @@ "route": [ { "x": -324, - "y": -503 + "y": -251.5 }, { "x": -324, - "y": -463 + "y": -211.5 }, { "x": -324, - "y": -443 + "y": -191.5 }, { "x": -324, - "y": -403 + "y": -151.5 } ], "isCurve": true, @@ -918,19 +918,19 @@ "route": [ { "x": -210.5, - "y": -503 + "y": -251.5 }, { "x": -210.5, - "y": -463 + "y": -211.5 }, { "x": -210.5, - "y": -443 + "y": -191.5 }, { "x": -210.5, - "y": -403 + "y": -151.5 } ], "isCurve": true, @@ -967,19 +967,19 @@ "route": [ { "x": 210, - "y": -503 + "y": -251.5 }, { "x": 210, - "y": -463 + "y": -211.5 }, { "x": 210, - "y": -443 + "y": -191.5 }, { "x": 210, - "y": -403 + "y": -151.5 } ], "isCurve": true, @@ -1016,19 +1016,19 @@ "route": [ { "x": 323.5, - "y": -503 + "y": -251.5 }, { "x": 323.5, - "y": -463 + "y": -211.5 }, { "x": 323.5, - "y": -443 + "y": -191.5 }, { "x": 323.5, - "y": -403 + "y": -151.5 } ], "isCurve": true, diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg index e4cd7b3ab..0d96c0adc 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxyabcdbabcdabcdc - + .d2-3193456249 .fill-N1{fill:#0A0F25;} + .d2-3193456249 .fill-N2{fill:#676C7E;} + .d2-3193456249 .fill-N3{fill:#9499AB;} + .d2-3193456249 .fill-N4{fill:#CFD2DD;} + .d2-3193456249 .fill-N5{fill:#DEE1EB;} + .d2-3193456249 .fill-N6{fill:#EEF1F8;} + .d2-3193456249 .fill-N7{fill:#FFFFFF;} + .d2-3193456249 .fill-B1{fill:#0D32B2;} + .d2-3193456249 .fill-B2{fill:#0D32B2;} + .d2-3193456249 .fill-B3{fill:#E3E9FD;} + .d2-3193456249 .fill-B4{fill:#E3E9FD;} + .d2-3193456249 .fill-B5{fill:#EDF0FD;} + .d2-3193456249 .fill-B6{fill:#F7F8FE;} + .d2-3193456249 .fill-AA2{fill:#4A6FF3;} + .d2-3193456249 .fill-AA4{fill:#EDF0FD;} + .d2-3193456249 .fill-AA5{fill:#F7F8FE;} + .d2-3193456249 .fill-AB4{fill:#EDF0FD;} + .d2-3193456249 .fill-AB5{fill:#F7F8FE;} + .d2-3193456249 .stroke-N1{stroke:#0A0F25;} + .d2-3193456249 .stroke-N2{stroke:#676C7E;} + .d2-3193456249 .stroke-N3{stroke:#9499AB;} + .d2-3193456249 .stroke-N4{stroke:#CFD2DD;} + .d2-3193456249 .stroke-N5{stroke:#DEE1EB;} + .d2-3193456249 .stroke-N6{stroke:#EEF1F8;} + .d2-3193456249 .stroke-N7{stroke:#FFFFFF;} + .d2-3193456249 .stroke-B1{stroke:#0D32B2;} + .d2-3193456249 .stroke-B2{stroke:#0D32B2;} + .d2-3193456249 .stroke-B3{stroke:#E3E9FD;} + .d2-3193456249 .stroke-B4{stroke:#E3E9FD;} + .d2-3193456249 .stroke-B5{stroke:#EDF0FD;} + .d2-3193456249 .stroke-B6{stroke:#F7F8FE;} + .d2-3193456249 .stroke-AA2{stroke:#4A6FF3;} + .d2-3193456249 .stroke-AA4{stroke:#EDF0FD;} + .d2-3193456249 .stroke-AA5{stroke:#F7F8FE;} + .d2-3193456249 .stroke-AB4{stroke:#EDF0FD;} + .d2-3193456249 .stroke-AB5{stroke:#F7F8FE;} + .d2-3193456249 .background-color-N1{background-color:#0A0F25;} + .d2-3193456249 .background-color-N2{background-color:#676C7E;} + .d2-3193456249 .background-color-N3{background-color:#9499AB;} + .d2-3193456249 .background-color-N4{background-color:#CFD2DD;} + .d2-3193456249 .background-color-N5{background-color:#DEE1EB;} + .d2-3193456249 .background-color-N6{background-color:#EEF1F8;} + .d2-3193456249 .background-color-N7{background-color:#FFFFFF;} + .d2-3193456249 .background-color-B1{background-color:#0D32B2;} + .d2-3193456249 .background-color-B2{background-color:#0D32B2;} + .d2-3193456249 .background-color-B3{background-color:#E3E9FD;} + .d2-3193456249 .background-color-B4{background-color:#E3E9FD;} + .d2-3193456249 .background-color-B5{background-color:#EDF0FD;} + .d2-3193456249 .background-color-B6{background-color:#F7F8FE;} + .d2-3193456249 .background-color-AA2{background-color:#4A6FF3;} + .d2-3193456249 .background-color-AA4{background-color:#EDF0FD;} + .d2-3193456249 .background-color-AA5{background-color:#F7F8FE;} + .d2-3193456249 .background-color-AB4{background-color:#EDF0FD;} + .d2-3193456249 .background-color-AB5{background-color:#F7F8FE;} + .d2-3193456249 .color-N1{color:#0A0F25;} + .d2-3193456249 .color-N2{color:#676C7E;} + .d2-3193456249 .color-N3{color:#9499AB;} + .d2-3193456249 .color-N4{color:#CFD2DD;} + .d2-3193456249 .color-N5{color:#DEE1EB;} + .d2-3193456249 .color-N6{color:#EEF1F8;} + .d2-3193456249 .color-N7{color:#FFFFFF;} + .d2-3193456249 .color-B1{color:#0D32B2;} + .d2-3193456249 .color-B2{color:#0D32B2;} + .d2-3193456249 .color-B3{color:#E3E9FD;} + .d2-3193456249 .color-B4{color:#E3E9FD;} + .d2-3193456249 .color-B5{color:#EDF0FD;} + .d2-3193456249 .color-B6{color:#F7F8FE;} + .d2-3193456249 .color-AA2{color:#4A6FF3;} + .d2-3193456249 .color-AA4{color:#EDF0FD;} + .d2-3193456249 .color-AA5{color:#F7F8FE;} + .d2-3193456249 .color-AB4{color:#EDF0FD;} + .d2-3193456249 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxyabcdbabcdabcdc + \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json index dc910ddbb..cb21b8a5d 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json @@ -336,7 +336,7 @@ "type": "rectangle", "pos": { "x": -373, - "y": -630 + "y": -358 }, "width": 227, "height": 302, @@ -377,7 +377,7 @@ "type": "rectangle", "pos": { "x": -323, - "y": -580 + "y": -308 }, "width": 53, "height": 66, @@ -418,7 +418,7 @@ "type": "rectangle", "pos": { "x": -323, - "y": -444 + "y": -172 }, "width": 53, "height": 66, @@ -459,7 +459,7 @@ "type": "rectangle", "pos": { "x": -250, - "y": -580 + "y": -308 }, "width": 53, "height": 66, @@ -500,7 +500,7 @@ "type": "rectangle", "pos": { "x": -250, - "y": -444 + "y": -172 }, "width": 54, "height": 66, @@ -541,7 +541,7 @@ "type": "rectangle", "pos": { "x": 146, - "y": -630 + "y": -358 }, "width": 227, "height": 302, @@ -582,7 +582,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": -580 + "y": -308 }, "width": 53, "height": 66, @@ -623,7 +623,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": -444 + "y": -172 }, "width": 53, "height": 66, @@ -664,7 +664,7 @@ "type": "rectangle", "pos": { "x": 270, - "y": -580 + "y": -308 }, "width": 53, "height": 66, @@ -705,7 +705,7 @@ "type": "rectangle", "pos": { "x": 269, - "y": -444 + "y": -172 }, "width": 54, "height": 66, @@ -851,11 +851,11 @@ "route": [ { "x": -297, - "y": -514 + "y": -242 }, { "x": -297, - "y": -444 + "y": -172 } ], "animated": false, @@ -891,11 +891,11 @@ "route": [ { "x": -223.5, - "y": -514 + "y": -242 }, { "x": -223.5, - "y": -444 + "y": -172 } ], "animated": false, @@ -931,11 +931,11 @@ "route": [ { "x": 223, - "y": -514 + "y": -242 }, { "x": 223, - "y": -444 + "y": -172 } ], "animated": false, @@ -971,11 +971,11 @@ "route": [ { "x": 296.5, - "y": -514 + "y": -242 }, { "x": 296.5, - "y": -444 + "y": -172 } ], "animated": false, diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg index 2f3211cd1..2e3dc5e36 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxyabcdbabcdabcdc - + .d2-3115826996 .fill-N1{fill:#0A0F25;} + .d2-3115826996 .fill-N2{fill:#676C7E;} + .d2-3115826996 .fill-N3{fill:#9499AB;} + .d2-3115826996 .fill-N4{fill:#CFD2DD;} + .d2-3115826996 .fill-N5{fill:#DEE1EB;} + .d2-3115826996 .fill-N6{fill:#EEF1F8;} + .d2-3115826996 .fill-N7{fill:#FFFFFF;} + .d2-3115826996 .fill-B1{fill:#0D32B2;} + .d2-3115826996 .fill-B2{fill:#0D32B2;} + .d2-3115826996 .fill-B3{fill:#E3E9FD;} + .d2-3115826996 .fill-B4{fill:#E3E9FD;} + .d2-3115826996 .fill-B5{fill:#EDF0FD;} + .d2-3115826996 .fill-B6{fill:#F7F8FE;} + .d2-3115826996 .fill-AA2{fill:#4A6FF3;} + .d2-3115826996 .fill-AA4{fill:#EDF0FD;} + .d2-3115826996 .fill-AA5{fill:#F7F8FE;} + .d2-3115826996 .fill-AB4{fill:#EDF0FD;} + .d2-3115826996 .fill-AB5{fill:#F7F8FE;} + .d2-3115826996 .stroke-N1{stroke:#0A0F25;} + .d2-3115826996 .stroke-N2{stroke:#676C7E;} + .d2-3115826996 .stroke-N3{stroke:#9499AB;} + .d2-3115826996 .stroke-N4{stroke:#CFD2DD;} + .d2-3115826996 .stroke-N5{stroke:#DEE1EB;} + .d2-3115826996 .stroke-N6{stroke:#EEF1F8;} + .d2-3115826996 .stroke-N7{stroke:#FFFFFF;} + .d2-3115826996 .stroke-B1{stroke:#0D32B2;} + .d2-3115826996 .stroke-B2{stroke:#0D32B2;} + .d2-3115826996 .stroke-B3{stroke:#E3E9FD;} + .d2-3115826996 .stroke-B4{stroke:#E3E9FD;} + .d2-3115826996 .stroke-B5{stroke:#EDF0FD;} + .d2-3115826996 .stroke-B6{stroke:#F7F8FE;} + .d2-3115826996 .stroke-AA2{stroke:#4A6FF3;} + .d2-3115826996 .stroke-AA4{stroke:#EDF0FD;} + .d2-3115826996 .stroke-AA5{stroke:#F7F8FE;} + .d2-3115826996 .stroke-AB4{stroke:#EDF0FD;} + .d2-3115826996 .stroke-AB5{stroke:#F7F8FE;} + .d2-3115826996 .background-color-N1{background-color:#0A0F25;} + .d2-3115826996 .background-color-N2{background-color:#676C7E;} + .d2-3115826996 .background-color-N3{background-color:#9499AB;} + .d2-3115826996 .background-color-N4{background-color:#CFD2DD;} + .d2-3115826996 .background-color-N5{background-color:#DEE1EB;} + .d2-3115826996 .background-color-N6{background-color:#EEF1F8;} + .d2-3115826996 .background-color-N7{background-color:#FFFFFF;} + .d2-3115826996 .background-color-B1{background-color:#0D32B2;} + .d2-3115826996 .background-color-B2{background-color:#0D32B2;} + .d2-3115826996 .background-color-B3{background-color:#E3E9FD;} + .d2-3115826996 .background-color-B4{background-color:#E3E9FD;} + .d2-3115826996 .background-color-B5{background-color:#EDF0FD;} + .d2-3115826996 .background-color-B6{background-color:#F7F8FE;} + .d2-3115826996 .background-color-AA2{background-color:#4A6FF3;} + .d2-3115826996 .background-color-AA4{background-color:#EDF0FD;} + .d2-3115826996 .background-color-AA5{background-color:#F7F8FE;} + .d2-3115826996 .background-color-AB4{background-color:#EDF0FD;} + .d2-3115826996 .background-color-AB5{background-color:#F7F8FE;} + .d2-3115826996 .color-N1{color:#0A0F25;} + .d2-3115826996 .color-N2{color:#676C7E;} + .d2-3115826996 .color-N3{color:#9499AB;} + .d2-3115826996 .color-N4{color:#CFD2DD;} + .d2-3115826996 .color-N5{color:#DEE1EB;} + .d2-3115826996 .color-N6{color:#EEF1F8;} + .d2-3115826996 .color-N7{color:#FFFFFF;} + .d2-3115826996 .color-B1{color:#0D32B2;} + .d2-3115826996 .color-B2{color:#0D32B2;} + .d2-3115826996 .color-B3{color:#E3E9FD;} + .d2-3115826996 .color-B4{color:#E3E9FD;} + .d2-3115826996 .color-B5{color:#EDF0FD;} + .d2-3115826996 .color-B6{color:#F7F8FE;} + .d2-3115826996 .color-AA2{color:#4A6FF3;} + .d2-3115826996 .color-AA4{color:#EDF0FD;} + .d2-3115826996 .color-AA5{color:#F7F8FE;} + .d2-3115826996 .color-AB4{color:#EDF0FD;} + .d2-3115826996 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxyabcdbabcdabcdc + \ No newline at end of file From 7deb7252521b62e348826811d395fdb9a6bb8cd1 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Fri, 24 Mar 2023 12:20:28 +0800 Subject: [PATCH 15/42] chore: delete redundant code --- d2layouts/d2near/layout.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 42e60c1c2..9c6663870 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -65,17 +65,6 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje } } - // These shapes skipped core layout, which means they also skipped label placements - // for _, obj := range constantNears { - // if obj.HasOutsideBottomLabel() { - // obj.LabelPosition = go2.Pointer(string(label.OutsideBottomCenter)) - // } else if obj.Attributes.Icon != nil { - // obj.LabelPosition = go2.Pointer(string(label.InsideTopCenter)) - // } else { - // obj.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter)) - // } - // } - return nil } From 684441382026928d5571168cc49cb12e85af88cf Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Fri, 24 Mar 2023 13:23:19 +0800 Subject: [PATCH 16/42] chore: new testcase --- e2etests/stable_test.go | 8 + .../dagre/board.exp.json | 164 ++++++++++++++++++ .../dagre/sketch.exp.svg | 160 ++++++++--------- .../elk/board.exp.json | 164 ++++++++++++++++++ .../elk/sketch.exp.svg | 160 ++++++++--------- 5 files changed, 496 insertions(+), 160 deletions(-) diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 5b8594221..3a2bd4ae4 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -37,6 +37,14 @@ func testStable(t *testing.T) { c } } + b: { + near: bottom-right + a: { + c: { + d + } + } + } `, }, { diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json index 6778de2cd..e1f0d9e31 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json @@ -740,6 +740,170 @@ "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 2 + }, + { + "id": "b", + "type": "rectangle", + "pos": { + "x": 143, + "y": -16 + }, + "width": 214, + "height": 325, + "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": "b", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "b.a", + "type": "rectangle", + "pos": { + "x": 163, + "y": 49 + }, + "width": 174, + "height": 230, + "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": "a", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 10, + "labelHeight": 31, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b.a.c", + "type": "rectangle", + "pos": { + "x": 183, + "y": 112 + }, + "width": 134, + "height": 135, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "c", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 9, + "labelHeight": 26, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 3 + }, + { + "id": "b.a.c.d", + "type": "rectangle", + "pos": { + "x": 223, + "y": 147 + }, + "width": 54, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N7", + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 4 } ], "connections": [ diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg index 0d96c0adc..05ae752d1 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxyabcdbabcdabcdc - + .d2-1451290290 .fill-N1{fill:#0A0F25;} + .d2-1451290290 .fill-N2{fill:#676C7E;} + .d2-1451290290 .fill-N3{fill:#9499AB;} + .d2-1451290290 .fill-N4{fill:#CFD2DD;} + .d2-1451290290 .fill-N5{fill:#DEE1EB;} + .d2-1451290290 .fill-N6{fill:#EEF1F8;} + .d2-1451290290 .fill-N7{fill:#FFFFFF;} + .d2-1451290290 .fill-B1{fill:#0D32B2;} + .d2-1451290290 .fill-B2{fill:#0D32B2;} + .d2-1451290290 .fill-B3{fill:#E3E9FD;} + .d2-1451290290 .fill-B4{fill:#E3E9FD;} + .d2-1451290290 .fill-B5{fill:#EDF0FD;} + .d2-1451290290 .fill-B6{fill:#F7F8FE;} + .d2-1451290290 .fill-AA2{fill:#4A6FF3;} + .d2-1451290290 .fill-AA4{fill:#EDF0FD;} + .d2-1451290290 .fill-AA5{fill:#F7F8FE;} + .d2-1451290290 .fill-AB4{fill:#EDF0FD;} + .d2-1451290290 .fill-AB5{fill:#F7F8FE;} + .d2-1451290290 .stroke-N1{stroke:#0A0F25;} + .d2-1451290290 .stroke-N2{stroke:#676C7E;} + .d2-1451290290 .stroke-N3{stroke:#9499AB;} + .d2-1451290290 .stroke-N4{stroke:#CFD2DD;} + .d2-1451290290 .stroke-N5{stroke:#DEE1EB;} + .d2-1451290290 .stroke-N6{stroke:#EEF1F8;} + .d2-1451290290 .stroke-N7{stroke:#FFFFFF;} + .d2-1451290290 .stroke-B1{stroke:#0D32B2;} + .d2-1451290290 .stroke-B2{stroke:#0D32B2;} + .d2-1451290290 .stroke-B3{stroke:#E3E9FD;} + .d2-1451290290 .stroke-B4{stroke:#E3E9FD;} + .d2-1451290290 .stroke-B5{stroke:#EDF0FD;} + .d2-1451290290 .stroke-B6{stroke:#F7F8FE;} + .d2-1451290290 .stroke-AA2{stroke:#4A6FF3;} + .d2-1451290290 .stroke-AA4{stroke:#EDF0FD;} + .d2-1451290290 .stroke-AA5{stroke:#F7F8FE;} + .d2-1451290290 .stroke-AB4{stroke:#EDF0FD;} + .d2-1451290290 .stroke-AB5{stroke:#F7F8FE;} + .d2-1451290290 .background-color-N1{background-color:#0A0F25;} + .d2-1451290290 .background-color-N2{background-color:#676C7E;} + .d2-1451290290 .background-color-N3{background-color:#9499AB;} + .d2-1451290290 .background-color-N4{background-color:#CFD2DD;} + .d2-1451290290 .background-color-N5{background-color:#DEE1EB;} + .d2-1451290290 .background-color-N6{background-color:#EEF1F8;} + .d2-1451290290 .background-color-N7{background-color:#FFFFFF;} + .d2-1451290290 .background-color-B1{background-color:#0D32B2;} + .d2-1451290290 .background-color-B2{background-color:#0D32B2;} + .d2-1451290290 .background-color-B3{background-color:#E3E9FD;} + .d2-1451290290 .background-color-B4{background-color:#E3E9FD;} + .d2-1451290290 .background-color-B5{background-color:#EDF0FD;} + .d2-1451290290 .background-color-B6{background-color:#F7F8FE;} + .d2-1451290290 .background-color-AA2{background-color:#4A6FF3;} + .d2-1451290290 .background-color-AA4{background-color:#EDF0FD;} + .d2-1451290290 .background-color-AA5{background-color:#F7F8FE;} + .d2-1451290290 .background-color-AB4{background-color:#EDF0FD;} + .d2-1451290290 .background-color-AB5{background-color:#F7F8FE;} + .d2-1451290290 .color-N1{color:#0A0F25;} + .d2-1451290290 .color-N2{color:#676C7E;} + .d2-1451290290 .color-N3{color:#9499AB;} + .d2-1451290290 .color-N4{color:#CFD2DD;} + .d2-1451290290 .color-N5{color:#DEE1EB;} + .d2-1451290290 .color-N6{color:#EEF1F8;} + .d2-1451290290 .color-N7{color:#FFFFFF;} + .d2-1451290290 .color-B1{color:#0D32B2;} + .d2-1451290290 .color-B2{color:#0D32B2;} + .d2-1451290290 .color-B3{color:#E3E9FD;} + .d2-1451290290 .color-B4{color:#E3E9FD;} + .d2-1451290290 .color-B5{color:#EDF0FD;} + .d2-1451290290 .color-B6{color:#F7F8FE;} + .d2-1451290290 .color-AA2{color:#4A6FF3;} + .d2-1451290290 .color-AA4{color:#EDF0FD;} + .d2-1451290290 .color-AA5{color:#F7F8FE;} + .d2-1451290290 .color-AB4{color:#EDF0FD;} + .d2-1451290290 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxybabcdbabcdabcdaccd + \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json index cb21b8a5d..1027c67a3 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json @@ -740,6 +740,170 @@ "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 2 + }, + { + "id": "b", + "type": "rectangle", + "pos": { + "x": 146, + "y": -16 + }, + "width": 354, + "height": 366, + "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": "b", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 13, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "b.a", + "type": "rectangle", + "pos": { + "x": 196, + "y": 34 + }, + "width": 254, + "height": 266, + "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": "a", + "fontSize": 24, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 10, + "labelHeight": 31, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 2 + }, + { + "id": "b.a.c", + "type": "rectangle", + "pos": { + "x": 246, + "y": 84 + }, + "width": 154, + "height": 166, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "c", + "fontSize": 20, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 9, + "labelHeight": 26, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 3 + }, + { + "id": "b.a.c.d", + "type": "rectangle", + "pos": { + "x": 296, + "y": 134 + }, + "width": 54, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "N7", + "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": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 4 } ], "connections": [ diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg index 2e3dc5e36..2a478c8b1 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxyabcdbabcdabcdc - + .d2-2717952357 .fill-N1{fill:#0A0F25;} + .d2-2717952357 .fill-N2{fill:#676C7E;} + .d2-2717952357 .fill-N3{fill:#9499AB;} + .d2-2717952357 .fill-N4{fill:#CFD2DD;} + .d2-2717952357 .fill-N5{fill:#DEE1EB;} + .d2-2717952357 .fill-N6{fill:#EEF1F8;} + .d2-2717952357 .fill-N7{fill:#FFFFFF;} + .d2-2717952357 .fill-B1{fill:#0D32B2;} + .d2-2717952357 .fill-B2{fill:#0D32B2;} + .d2-2717952357 .fill-B3{fill:#E3E9FD;} + .d2-2717952357 .fill-B4{fill:#E3E9FD;} + .d2-2717952357 .fill-B5{fill:#EDF0FD;} + .d2-2717952357 .fill-B6{fill:#F7F8FE;} + .d2-2717952357 .fill-AA2{fill:#4A6FF3;} + .d2-2717952357 .fill-AA4{fill:#EDF0FD;} + .d2-2717952357 .fill-AA5{fill:#F7F8FE;} + .d2-2717952357 .fill-AB4{fill:#EDF0FD;} + .d2-2717952357 .fill-AB5{fill:#F7F8FE;} + .d2-2717952357 .stroke-N1{stroke:#0A0F25;} + .d2-2717952357 .stroke-N2{stroke:#676C7E;} + .d2-2717952357 .stroke-N3{stroke:#9499AB;} + .d2-2717952357 .stroke-N4{stroke:#CFD2DD;} + .d2-2717952357 .stroke-N5{stroke:#DEE1EB;} + .d2-2717952357 .stroke-N6{stroke:#EEF1F8;} + .d2-2717952357 .stroke-N7{stroke:#FFFFFF;} + .d2-2717952357 .stroke-B1{stroke:#0D32B2;} + .d2-2717952357 .stroke-B2{stroke:#0D32B2;} + .d2-2717952357 .stroke-B3{stroke:#E3E9FD;} + .d2-2717952357 .stroke-B4{stroke:#E3E9FD;} + .d2-2717952357 .stroke-B5{stroke:#EDF0FD;} + .d2-2717952357 .stroke-B6{stroke:#F7F8FE;} + .d2-2717952357 .stroke-AA2{stroke:#4A6FF3;} + .d2-2717952357 .stroke-AA4{stroke:#EDF0FD;} + .d2-2717952357 .stroke-AA5{stroke:#F7F8FE;} + .d2-2717952357 .stroke-AB4{stroke:#EDF0FD;} + .d2-2717952357 .stroke-AB5{stroke:#F7F8FE;} + .d2-2717952357 .background-color-N1{background-color:#0A0F25;} + .d2-2717952357 .background-color-N2{background-color:#676C7E;} + .d2-2717952357 .background-color-N3{background-color:#9499AB;} + .d2-2717952357 .background-color-N4{background-color:#CFD2DD;} + .d2-2717952357 .background-color-N5{background-color:#DEE1EB;} + .d2-2717952357 .background-color-N6{background-color:#EEF1F8;} + .d2-2717952357 .background-color-N7{background-color:#FFFFFF;} + .d2-2717952357 .background-color-B1{background-color:#0D32B2;} + .d2-2717952357 .background-color-B2{background-color:#0D32B2;} + .d2-2717952357 .background-color-B3{background-color:#E3E9FD;} + .d2-2717952357 .background-color-B4{background-color:#E3E9FD;} + .d2-2717952357 .background-color-B5{background-color:#EDF0FD;} + .d2-2717952357 .background-color-B6{background-color:#F7F8FE;} + .d2-2717952357 .background-color-AA2{background-color:#4A6FF3;} + .d2-2717952357 .background-color-AA4{background-color:#EDF0FD;} + .d2-2717952357 .background-color-AA5{background-color:#F7F8FE;} + .d2-2717952357 .background-color-AB4{background-color:#EDF0FD;} + .d2-2717952357 .background-color-AB5{background-color:#F7F8FE;} + .d2-2717952357 .color-N1{color:#0A0F25;} + .d2-2717952357 .color-N2{color:#676C7E;} + .d2-2717952357 .color-N3{color:#9499AB;} + .d2-2717952357 .color-N4{color:#CFD2DD;} + .d2-2717952357 .color-N5{color:#DEE1EB;} + .d2-2717952357 .color-N6{color:#EEF1F8;} + .d2-2717952357 .color-N7{color:#FFFFFF;} + .d2-2717952357 .color-B1{color:#0D32B2;} + .d2-2717952357 .color-B2{color:#0D32B2;} + .d2-2717952357 .color-B3{color:#E3E9FD;} + .d2-2717952357 .color-B4{color:#E3E9FD;} + .d2-2717952357 .color-B5{color:#EDF0FD;} + .d2-2717952357 .color-B6{color:#F7F8FE;} + .d2-2717952357 .color-AA2{color:#4A6FF3;} + .d2-2717952357 .color-AA4{color:#EDF0FD;} + .d2-2717952357 .color-AA5{color:#F7F8FE;} + .d2-2717952357 .color-AB4{color:#EDF0FD;} + .d2-2717952357 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxybabcdbabcdabcdaccd + \ No newline at end of file From e09a85e80b72d92d706f2c48720ebfc49577a269 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Sat, 25 Mar 2023 01:44:12 +0800 Subject: [PATCH 17/42] fix: recover testcases --- e2etests/stable_test.go | 570 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 570 insertions(+) diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 3a2bd4ae4..c75930dde 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1929,6 +1929,576 @@ i am bottom left: { shape: text; near: bottom-left } i am bottom right: { shape: text; near: bottom-right } `, }, + { + name: "constant_near_title", + script: `title: |md + # A winning strategy +| { near: top-center } + +poll the people -> results +results -> unfavorable -> poll the people +results -> favorable -> will of the people +`, + }, + { + name: "text_font_sizes", + script: `bear: { shape: text; style.font-size: 22; style.bold: true } +mama bear: { shape: text; style.font-size: 28; style.italic: true } +papa bear: { shape: text; style.font-size: 32; style.underline: true } +mama bear -> bear +papa bear -> bear +`, + }, + { + name: "tooltips", + script: `x: { tooltip: Total abstinence is easier than perfect moderation } +y: { tooltip: Gee, I feel kind of LIGHT in the head now,\nknowing I can't make my satellite dish PAYMENTS! } +x -> y +`, + }, + { + name: "links", + script: `x: { link: https://d2lang.com } + y: { link: https://terrastruct.com; tooltip: Gee, I feel kind of LIGHT in the head now,\nknowing I can't make my satellite dish PAYMENTS! } +x -> y +`, + }, + { + name: "unnamed_only_width", + script: ` + +class -> users -> code -> package -> no width + +class: "" { + shape: class + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} + +users: "" { + shape: sql_table + id: int + name: string + email: string + password: string + last_login: datetime +} + +code: |go + a := 5 + b := a + 7 + fmt.Printf("%d", b) +| + +package: "" { shape: package } +no width: "" + + +class.width: 512 +users.width: 512 +code.width: 512 +package.width: 512 +`, + }, + { + name: "unnamed_only_height", + script: ` + +class -> users -> code -> package -> no height + +class: "" { + shape: class + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} + +users: "" { + shape: sql_table + id: int + name: string + email: string + password: string + last_login: datetime +} + +code: |go + a := 5 + b := a + 7 + fmt.Printf("%d", b) +| + +package: "" { shape: package } +no height: "" + + +class.height: 512 +users.height: 512 +code.height: 512 +package.height: 512 +`, + }, + { + name: "container_dimensions", + script: `a: { + width: 500 + b -> c + b.width: 400 + c.width: 600 +} + +b: { + width: 700 + b -> c + e: { + height: 300 + } +} + +c: { + width: 200 + height: 300 + a +} +`, + dagreFeatureError: `Object "a" has attribute "width" and/or "height" set, but layout engine "dagre" does not support dimensions set on containers.`, + }, + { + name: "crow_foot_arrowhead", + script: ` +a1 <-> b1: { + style.stroke-width: 1 + source-arrowhead: { + shape: cf-many + } + target-arrowhead: { + shape: cf-many + } +} +a2 <-> b2: { + style.stroke-width: 3 + source-arrowhead: { + shape: cf-many + } + target-arrowhead: { + shape: cf-many + } +} +a3 <-> b3: { + style.stroke-width: 6 + source-arrowhead: { + shape: cf-many + } + target-arrowhead: { + shape: cf-many + } +} + +c1 <-> d1: { + style.stroke-width: 1 + source-arrowhead: { + shape: cf-many-required + } + target-arrowhead: { + shape: cf-many-required + } +} +c2 <-> d2: { + style.stroke-width: 3 + source-arrowhead: { + shape: cf-many-required + } + target-arrowhead: { + shape: cf-many-required + } +} +c3 <-> d3: { + style.stroke-width: 6 + source-arrowhead: { + shape: cf-many-required + } + target-arrowhead: { + shape: cf-many-required + } +} + +e1 <-> f1: { + style.stroke-width: 1 + source-arrowhead: { + shape: cf-one + } + target-arrowhead: { + shape: cf-one + } +} +e2 <-> f2: { + style.stroke-width: 3 + source-arrowhead: { + shape: cf-one + } + target-arrowhead: { + shape: cf-one + } +} +e3 <-> f3: { + style.stroke-width: 6 + source-arrowhead: { + shape: cf-one + } + target-arrowhead: { + shape: cf-one + } +} + +g1 <-> h1: { + style.stroke-width: 1 + source-arrowhead: { + shape: cf-one-required + } + target-arrowhead: { + shape: cf-one-required + } +} +g2 <-> h2: { + style.stroke-width: 3 + source-arrowhead: { + shape: cf-one-required + } + target-arrowhead: { + shape: cf-one-required + } +} +g3 <-> h3: { + style.stroke-width: 6 + source-arrowhead: { + shape: cf-one-required + } + target-arrowhead: { + shape: cf-one-required + } +} + +c <-> d <-> f: { + style.stroke-width: 1 + style.stroke: "orange" + source-arrowhead: { + shape: cf-many-required + } + target-arrowhead: { + shape: cf-one + } +} +`, + }, + { + name: "circle_arrowhead", + script: ` +a <-> b: circle { + source-arrowhead: { + shape: circle + } + target-arrowhead: { + shape: circle + } +} + +c <-> d: filled-circle { + source-arrowhead: { + shape: circle + style.filled: true + } + target-arrowhead: { + shape: circle + style.filled: true + } +}`, + }, + { + name: "animated", + script: ` +your love life will be -> happy: { style.animated: true } +your love life will be -> harmonious: { style.animated: true } + +boredom <- immortality: { style.animated: true } + +Friday <-> Monday: { style.animated: true } + +Insomnia -- Sleep: { style.animated: true } +Insomnia -- Wake: { + style: { + animated: true + stroke-width: 2 + } +} + +Insomnia -- Dream: { + style: { + animated: true + stroke-width: 8 + } +} + +Listen <-> Talk: { + style.animated: true + source-arrowhead.shape: cf-one + target-arrowhead.shape: diamond + label: hear +} +`, + }, + { + name: "sql_table_tooltip_animated", + script: ` +x: { + shape: sql_table + y + tooltip: I like turtles +} + +a: { + shape: sql_table + b +} + +x.y -> a.b: { + style.animated: true + target-arrowhead.shape: cf-many +} +`, + }, + { + name: "sql_table_column_styles", + script: `Humor in the Court: { + shape: sql_table + Could you see him from where you were standing?: "I could see his head." + And where was his head?: Just above his shoulders. + style.fill: red + style.stroke: lightgray + style.font-color: orange + style.font-size: 20 +} + +Humor in the Court2: { + shape: sql_table + Could you see him from where you were standing?: "I could see his head." + And where was his head?: Just above his shoulders. + style.fill: red + style.stroke: lightgray + style.font-color: orange + style.font-size: 30 +} + +manager: BatchManager { + shape: class + style.font-size: 20 + + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} + +manager2: BatchManager { + shape: class + style.font-size: 30 + + -num: int + -timeout: int + -pid + + +getStatus(): Enum + +getJobs(): "Job[]" + +setTimeout(seconds int) +} +`, + }, + { + name: "near-alone", + script: ` +x: { + near: top-center +} +y: { + near: bottom-center +} +z: { + near: center-left +} +`, + }, + { + name: "border-radius", + script: ` +x: { + style.border-radius: 4 +} +y: { + style.border-radius: 10 +} +multiple2: { + style.border-radius: 6 + style.multiple: true +} +double: { + style.border-radius: 6 + style.double-border: true +} +three-dee: { + style.border-radius: 6 + style.3d: true +} +`, + }, + { + name: "sequence-inter-span-self", + script: ` +shape: sequence_diagram +a: A +b: B + +a.sp1 -> b: foo +a.sp1 -> a.sp2: redirect +a.sp2 -> b: bar +`, + }, + { + name: "people", + script: ` +a.shape: person +b.shape: person +c.shape: person +d.shape: person +e.shape: person +f.shape: person +g.shape: person + +a: - +b: -- +c: ---- +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 +`, + }, + { + name: "ovals", + script: ` +a.shape: oval +b.shape: oval +c.shape: oval +d.shape: oval +e.shape: oval +f.shape: oval +g.shape: oval + +a: - +b: -- +c: ---- +d: -------- +e: ---------------- +f: -------------------------------- +g: ---------------------------------------------------------------- + +1.shape: oval +2.shape: oval +3.shape: oval +4.shape: oval +5.shape: oval + +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 +`, + }, + { + name: "complex-layers", + script: ` +desc: Multi-layer diagram of a home. + +window: { + style.double-border: true +} +roof +garage + +layers: { + window: { + blinds + glass + } + roof: { + shingles + starlink + utility hookup + } + garage: { + tools + vehicles + } + repair: { + desc: How to repair a home. + + steps: { + 1: { + find contractors: { + craigslist + facebook + } + } + 2: { + find contractors -> solicit quotes + } + 3: { + obtain quotes -> negotiate + } + 4: { + negotiate -> book the best bid + } + } + } +} + +scenarios: { + storm: { + water + rain + thunder + } +}`, + }, } runa(t, tcs) From 4e4959f39b10fdf54a9826adb432fa76dbad34a6 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Sat, 25 Mar 2023 02:09:28 +0800 Subject: [PATCH 18/42] fix: cr, delete redundant return value --- d2layouts/d2near/layout.go | 13 ++++++------- d2lib/d2.go | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 9c6663870..fee36c395 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -15,8 +15,8 @@ import ( const pad = 20 // Layout finds the shapes which are assigned constant near keywords and places them. -func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error { - if len(constantNears) == 0 { +func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error { + if len(constantNearGraphs) == 0 { return nil } @@ -24,7 +24,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje // Top left should go left enough to not collide with center. // So place the center ones first, then the later ones will consider them for bounding box for _, processCenters := range []bool{true, false} { - for _, obj := range constantNears { + for obj := range constantNearGraphs { if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") { preX, preY := obj.TopLeft.X, obj.TopLeft.Y obj.TopLeft = geo.NewPoint(place(obj)) @@ -54,7 +54,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje g.Edges = append(g.Edges, subEdges...) } } - for _, obj := range constantNears { + for obj := range constantNearGraphs { if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") { // The z-index for constant nears does not matter, as it will not collide g.Objects = append(g.Objects, obj) @@ -144,7 +144,7 @@ func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, flo // WithoutConstantNears plucks out the graph objects which have "near" set to a constant value // This is to be called before layout engines so they don't take part in regular positioning -func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) { +func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs map[*d2graph.Object]*d2graph.Graph) { constantNearGraphs = make(map[*d2graph.Object]*d2graph.Graph) for i := 0; i < len(g.Objects); i++ { @@ -168,7 +168,6 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra constantNearGraphs[obj] = tempGraph - nears = append(nears, obj) i-- delete(obj.Parent.Children, strings.ToLower(obj.ID)) for i := 0; i < len(obj.Parent.ChildrenArray); i++ { @@ -179,7 +178,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra } } } - return nears, constantNearGraphs + return constantNearGraphs } func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descendantsObjects []*d2graph.Object, edges []*d2graph.Edge) { diff --git a/d2lib/d2.go b/d2lib/d2.go index 377fb7cde..c43bb789e 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -68,7 +68,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta return nil, err } - constantNears, constantNearGraphs := d2near.WithoutConstantNears(ctx, g) + constantNearGraphs := d2near.WithoutConstantNears(ctx, g) // run core layout for constantNears for nearObject, tempGraph := range constantNearGraphs { @@ -88,7 +88,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta return nil, err } - err = d2near.Layout(ctx, g, constantNears, constantNearGraphs) + err = d2near.Layout(ctx, g, constantNearGraphs) if err != nil { return nil, err } From ebab91b043e35c135716ace72a77e4727a42d53f Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Sat, 25 Mar 2023 02:38:05 +0800 Subject: [PATCH 19/42] fix: cr, delete redundant variable --- d2layouts/d2near/layout.go | 19 +++++++------------ d2lib/d2.go | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index fee36c395..ad7fba3bd 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -15,7 +15,7 @@ import ( const pad = 20 // Layout finds the shapes which are assigned constant near keywords and places them. -func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error { +func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs []*d2graph.Graph) error { if len(constantNearGraphs) == 0 { return nil } @@ -24,17 +24,13 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2gra // Top left should go left enough to not collide with center. // So place the center ones first, then the later ones will consider them for bounding box for _, processCenters := range []bool{true, false} { - for obj := range constantNearGraphs { + for _, tempGraph := range constantNearGraphs { + obj := tempGraph.Root.ChildrenArray[0] if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") { preX, preY := obj.TopLeft.X, obj.TopLeft.Y obj.TopLeft = geo.NewPoint(place(obj)) dx, dy := obj.TopLeft.X-preX, obj.TopLeft.Y-preY - tempGraph := constantNearGraphs[obj] - if tempGraph == nil { - continue - } - subObjects, subEdges := tempGraph.Objects, tempGraph.Edges for _, subObject := range subObjects { // `obj` already been replaced above by `place(obj)` @@ -54,7 +50,8 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2gra g.Edges = append(g.Edges, subEdges...) } } - for obj := range constantNearGraphs { + for _, tempGraph := range constantNearGraphs { + obj := tempGraph.Root.ChildrenArray[0] if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") { // The z-index for constant nears does not matter, as it will not collide g.Objects = append(g.Objects, obj) @@ -144,9 +141,7 @@ func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, flo // WithoutConstantNears plucks out the graph objects which have "near" set to a constant value // This is to be called before layout engines so they don't take part in regular positioning -func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs map[*d2graph.Object]*d2graph.Graph) { - constantNearGraphs = make(map[*d2graph.Object]*d2graph.Graph) - +func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs []*d2graph.Graph) { for i := 0; i < len(g.Objects); i++ { obj := g.Objects[i] if obj.Attributes.NearKey == nil { @@ -166,7 +161,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGr tempGraph.Objects = descendantObjects tempGraph.Edges = edges - constantNearGraphs[obj] = tempGraph + constantNearGraphs = append(constantNearGraphs, tempGraph) i-- delete(obj.Parent.Children, strings.ToLower(obj.ID)) diff --git a/d2lib/d2.go b/d2lib/d2.go index c43bb789e..13dccad3f 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -71,11 +71,12 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta constantNearGraphs := d2near.WithoutConstantNears(ctx, g) // run core layout for constantNears - for nearObject, tempGraph := range constantNearGraphs { + for _, tempGraph := range constantNearGraphs { if tempGraph == nil { continue } + nearObject := tempGraph.Root.ChildrenArray[0] nearObject.Parent = tempGraph.Root if err = coreLayout(ctx, tempGraph); err != nil { return nil, err From 77822318aa86ce819749e5c706cdcd56eb7a1671 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Sat, 25 Mar 2023 03:02:44 +0800 Subject: [PATCH 20/42] fix: cr, use method instead of attribute --- d2graph/d2graph.go | 23 +++++++++++++++++------ d2layouts/d2near/layout.go | 3 +-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 74d238b9c..ebeeb0816 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -90,12 +90,11 @@ type Object struct { LabelDimensions d2target.TextDimensions `json:"label_dimensions"` References []Reference `json:"references,omitempty"` - *geo.Box `json:"box,omitempty"` - LabelPosition *string `json:"labelPosition,omitempty"` - LabelWidth *int `json:"labelWidth,omitempty"` - LabelHeight *int `json:"labelHeight,omitempty"` - IconPosition *string `json:"iconPosition,omitempty"` - IsInsideNearContainer bool `json:"isInsideNearContainer,omitempty"` + *geo.Box `json:"box,omitempty"` + LabelPosition *string `json:"labelPosition,omitempty"` + LabelWidth *int `json:"labelWidth,omitempty"` + LabelHeight *int `json:"labelHeight,omitempty"` + IconPosition *string `json:"iconPosition,omitempty"` Class *d2target.Class `json:"class,omitempty"` SQLTable *d2target.SQLTable `json:"sql_table,omitempty"` @@ -969,6 +968,18 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R return &dims, nil } +func (obj *Object) IsInsideNearContainer() bool { + temp := obj + for temp != nil { + fmt.Println(temp.ID) + if temp.Attributes.NearKey != nil { + return true + } + temp = temp.Parent + } + return false +} + type Edge struct { Index int `json:"index"` diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index ad7fba3bd..a20e6bf3e 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -191,7 +191,6 @@ func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descenda if temp.AbsID() == obj.AbsID() { descendantsObjects = append(descendantsObjects, obj) g.Objects = append(g.Objects[:i], g.Objects[i+1:]...) - obj.IsInsideNearContainer = true for _, child := range obj.ChildrenArray { subObjects, subEdges := pluckOutNearObjectAndEdges(g, child) descendantsObjects = append(descendantsObjects, subObjects...) @@ -229,7 +228,7 @@ func boundingBox(g *d2graph.Graph) (tl, br *geo.Point) { y2 = math.Max(y2, obj.TopLeft.Y+obj.Height) } } else { - if obj.IsInsideNearContainer { + if obj.IsInsideNearContainer() { continue } x1 = math.Min(x1, obj.TopLeft.X) From 0df9abc0564185e84c776d922ba6a34a50bad21c Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Sat, 25 Mar 2023 11:31:55 +0800 Subject: [PATCH 21/42] fix: delete redundant file --- ...near_descendant_conent_to_outside.exp.json | 387 ------------------ 1 file changed, 387 deletions(-) delete mode 100644 testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json diff --git a/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json b/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json deleted file mode 100644 index 3af3dc2c5..000000000 --- a/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.exp.json +++ /dev/null @@ -1,387 +0,0 @@ -{ - "graph": { - "name": "", - "isFolderOnly": false, - "ast": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,0:0:0-5:3:39", - "nodes": [ - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-3:5:22", - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:7:8-3:4:21", - "nodes": [ - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "primary": {}, - "value": {} - } - } - ] - } - } - } - }, - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:12:35", - "edges": [ - { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:12:35", - "src": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:8:31", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:5:28", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:6:29-4:7:30", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "src_arrow": "", - "dst": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:10:33-4:12:35", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:11:34-4:12:35", - "value": [ - { - "string": "z", - "raw_string": "z" - } - ] - } - } - ] - }, - "dst_arrow": ">" - } - ], - "primary": {}, - "value": {} - } - } - ] - }, - "root": { - "id": "", - "id_val": "", - "label_dimensions": { - "width": 0, - "height": 0 - }, - "attributes": { - "label": { - "value": "" - }, - "style": {}, - "near_key": null, - "shape": { - "value": "" - }, - "direction": { - "value": "" - }, - "constraint": { - "value": "" - } - }, - "zIndex": 0 - }, - "edges": [ - { - "index": 0, - "minWidth": 0, - "minHeight": 0, - "label_dimensions": { - "width": 0, - "height": 0 - }, - "isCurve": false, - "src_arrow": false, - "dst_arrow": true, - "references": [ - { - "map_key_edge_index": 0 - } - ], - "attributes": { - "label": { - "value": "" - }, - "style": {}, - "near_key": null, - "shape": { - "value": "" - }, - "direction": { - "value": "" - }, - "constraint": { - "value": "" - } - }, - "zIndex": 0 - } - ], - "objects": [ - { - "id": "x", - "id_val": "x", - "label_dimensions": { - "width": 0, - "height": 0 - }, - "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,1:4:5-1:5:6", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:8:31", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:5:28", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:6:29-4:7:30", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 - } - ], - "attributes": { - "label": { - "value": "x" - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": { - "value": "" - } - }, - "zIndex": 0 - }, - { - "id": "y", - "id_val": "y", - "label_dimensions": { - "width": 0, - "height": 0 - }, - "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,2:5:15-2:6:16", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:8:31", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:4:27-4:5:28", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:6:29-4:7:30", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "key_path_index": 1, - "map_key_edge_index": 0 - } - ], - "attributes": { - "label": { - "value": "y" - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": { - "value": "" - } - }, - "zIndex": 0 - }, - { - "id": "z", - "id_val": "z", - "label_dimensions": { - "width": 0, - "height": 0 - }, - "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:10:33-4:12:35", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_conent_to_outside.d2,4:11:34-4:12:35", - "value": [ - { - "string": "z", - "raw_string": "z" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 - } - ], - "attributes": { - "label": { - "value": "z" - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": { - "value": "" - } - }, - "zIndex": 0 - } - ] - }, - "err": null -} From a21f5ec4381f78c770678bbf54b79b3911c6bcdc Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Mon, 27 Mar 2023 20:58:01 +0800 Subject: [PATCH 22/42] fix: cr, calc labelPosition --- d2layouts/d2near/layout.go | 41 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index a20e6bf3e..afbc472ff 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -80,8 +80,9 @@ func place(obj *d2graph.Object) (float64, float64) { w := br.X - tl.X h := br.Y - tl.Y + nearKeyStr := d2graph.Key(obj.Attributes.NearKey)[0] var x, y float64 - switch d2graph.Key(obj.Attributes.NearKey)[0] { + switch nearKeyStr { case "top-left": x, y = tl.X-obj.Width-pad, tl.Y-obj.Height-pad break @@ -108,31 +109,27 @@ func place(obj *d2graph.Object) (float64, float64) { break } - return calcLabelDimension(obj, x, y) -} - -func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, float64) { - var position string - if obj.LabelPosition != nil { + if !strings.Contains(*obj.LabelPosition, "INSIDE") && obj.LabelPosition != nil { if strings.Contains(*obj.LabelPosition, "_TOP_") { - position = "TOP" + // label is on the top, and container is placed on the bottom + if strings.Contains(nearKeyStr, "bottom") { + y += float64(*obj.LabelHeight) + } } else if strings.Contains(*obj.LabelPosition, "_LEFT_") { - position = "LEFT" + // label is on the left, and container is placed on the right + if strings.Contains(nearKeyStr, "bottom") { + x += float64(*obj.LabelWidth) + } } else if strings.Contains(*obj.LabelPosition, "_RIGHT_") { - position = "RIGHT" + // label is on the right, and container is placed on the left + if strings.Contains(nearKeyStr, "bottom") { + x -= float64(*obj.LabelWidth) + } } else if strings.Contains(*obj.LabelPosition, "_BOTTOM_") { - position = "BOTTOM" - } - - switch position { - case "TOP": - return x, y - float64(*obj.LabelHeight) - case "BOTTOM": - return x, y + float64(*obj.LabelHeight) - case "LEFT": - return x - float64(*obj.LabelWidth), y - case "RIGHT": - return x + float64(*obj.LabelWidth), y + // label is on the bottom, and container is placed on the top + if strings.Contains(nearKeyStr, "top") { + y -= float64(*obj.LabelHeight) + } } } From d33efa28f270eca29ff64b87982420e965afba1c Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Mon, 27 Mar 2023 21:27:22 +0800 Subject: [PATCH 23/42] chore: new testcase --- e2etests/stable_test.go | 27 + .../legend_with_near_key/dagre/board.exp.json | 391 ++++++++ .../legend_with_near_key/dagre/sketch.exp.svg | 844 ++++++++++++++++++ .../legend_with_near_key/elk/board.exp.json | 373 ++++++++ .../legend_with_near_key/elk/sketch.exp.svg | 844 ++++++++++++++++++ 5 files changed, 2479 insertions(+) create mode 100644 e2etests/testdata/stable/legend_with_near_key/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/legend_with_near_key/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/legend_with_near_key/elk/board.exp.json create mode 100644 e2etests/testdata/stable/legend_with_near_key/elk/sketch.exp.svg diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index c75930dde..bbfc9344a 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -12,6 +12,33 @@ var testMarkdown string func testStable(t *testing.T) { tcs := []testCase{ + { + name: "legend_with_near_key", + script: ` + direction: right + + x -> y: { + style.stroke: green + } + + y -> z: { + style.stroke: red + } + + legend: { + near: bottom-center + color1: foo { + shape: text + style.font-color: green + } + + color2: bar { + shape: text + style.font-color: red + } + } + `, + }, { name: "near_keys_for_container", script: ` diff --git a/e2etests/testdata/stable/legend_with_near_key/dagre/board.exp.json b/e2etests/testdata/stable/legend_with_near_key/dagre/board.exp.json new file mode 100644 index 000000000..1d2073df6 --- /dev/null +++ b/e2etests/testdata/stable/legend_with_near_key/dagre/board.exp.json @@ -0,0 +1,391 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "rectangle", + "pos": { + "x": 0, + "y": 0 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 153, + "y": 0 + }, + "width": 54, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "z", + "type": "rectangle", + "pos": { + "x": 307, + "y": 0 + }, + "width": 52, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "z", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 7, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "legend", + "type": "rectangle", + "pos": { + "x": 87, + "y": 122 + }, + "width": 184, + "height": 80, + "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": "legend", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 77, + "labelHeight": 36, + "labelPosition": "OUTSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "legend.color1", + "type": "text", + "pos": { + "x": 127, + "y": 151 + }, + "width": 22, + "height": 21, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "N1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "foo", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "green", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 22, + "labelHeight": 21, + "zIndex": 0, + "level": 2 + }, + { + "id": "legend.color2", + "type": "text", + "pos": { + "x": 209, + "y": 151 + }, + "width": 22, + "height": 21, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "N1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "bar", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "red", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 22, + "labelHeight": 21, + "zIndex": 0, + "level": 2 + } + ], + "connections": [ + { + "id": "(x -> y)[0]", + "src": "x", + "srcArrow": "none", + "srcLabel": "", + "dst": "y", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "green", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 53, + "y": 33 + }, + { + "x": 93, + "y": 33 + }, + { + "x": 113, + "y": 33 + }, + { + "x": 153, + "y": 33 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(y -> z)[0]", + "src": "y", + "srcArrow": "none", + "srcLabel": "", + "dst": "z", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "red", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 207, + "y": 33 + }, + { + "x": 247, + "y": 33 + }, + { + "x": 267, + "y": 33 + }, + { + "x": 307, + "y": 33 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ], + "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/stable/legend_with_near_key/dagre/sketch.exp.svg b/e2etests/testdata/stable/legend_with_near_key/dagre/sketch.exp.svg new file mode 100644 index 000000000..25d65d026 --- /dev/null +++ b/e2etests/testdata/stable/legend_with_near_key/dagre/sketch.exp.svg @@ -0,0 +1,844 @@ +xyzlegendfoobar + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/legend_with_near_key/elk/board.exp.json b/e2etests/testdata/stable/legend_with_near_key/elk/board.exp.json new file mode 100644 index 000000000..e2e2ac59b --- /dev/null +++ b/e2etests/testdata/stable/legend_with_near_key/elk/board.exp.json @@ -0,0 +1,373 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "rectangle", + "pos": { + "x": 12, + "y": 12 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 135, + "y": 12 + }, + "width": 54, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "z", + "type": "rectangle", + "pos": { + "x": 259, + "y": 12 + }, + "width": 52, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "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": "z", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 7, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "legend", + "type": "rectangle", + "pos": { + "x": 79, + "y": 98 + }, + "width": 164, + "height": 121, + "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": "legend", + "fontSize": 28, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 77, + "labelHeight": 36, + "labelPosition": "INSIDE_TOP_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "legend.color1", + "type": "text", + "pos": { + "x": 129, + "y": 148 + }, + "width": 22, + "height": 21, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "N1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "foo", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "green", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 22, + "labelHeight": 21, + "zIndex": 0, + "level": 2 + }, + { + "id": "legend.color2", + "type": "text", + "pos": { + "x": 171, + "y": 148 + }, + "width": 22, + "height": 21, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "N1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "bar", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "red", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 22, + "labelHeight": 21, + "zIndex": 0, + "level": 2 + } + ], + "connections": [ + { + "id": "(x -> y)[0]", + "src": "x", + "srcArrow": "none", + "srcLabel": "", + "dst": "y", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "green", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 65, + "y": 45 + }, + { + "x": 135, + "y": 45 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(y -> z)[0]", + "src": "y", + "srcArrow": "none", + "srcLabel": "", + "dst": "z", + "dstArrow": "triangle", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "red", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 189, + "y": 45 + }, + { + "x": 259, + "y": 45 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ], + "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/stable/legend_with_near_key/elk/sketch.exp.svg b/e2etests/testdata/stable/legend_with_near_key/elk/sketch.exp.svg new file mode 100644 index 000000000..ad66e33f7 --- /dev/null +++ b/e2etests/testdata/stable/legend_with_near_key/elk/sketch.exp.svg @@ -0,0 +1,844 @@ +xyzlegendfoobar + + + \ No newline at end of file From 54250d00dd3be706b83db3260c8e332e588fe2e4 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Mon, 27 Mar 2023 21:40:36 +0800 Subject: [PATCH 24/42] fix: nil labelPosition --- d2layouts/d2near/layout.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index afbc472ff..9fc8eabc6 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -109,7 +109,7 @@ func place(obj *d2graph.Object) (float64, float64) { break } - if !strings.Contains(*obj.LabelPosition, "INSIDE") && obj.LabelPosition != nil { + if obj.LabelPosition != nil && !strings.Contains(*obj.LabelPosition, "INSIDE") { if strings.Contains(*obj.LabelPosition, "_TOP_") { // label is on the top, and container is placed on the bottom if strings.Contains(nearKeyStr, "bottom") { From 4760888d15887f583f12690802dfc16c85e65942 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Mon, 27 Mar 2023 21:42:43 +0800 Subject: [PATCH 25/42] chore: regenerate testcases --- .../d2sketch/testdata/animated/sketch.exp.svg | 2 +- .../testdata/animated_dark/sketch.exp.svg | 2 +- .../constant_near_stress/dagre/board.exp.json | 4 +- .../constant_near_stress/dagre/sketch.exp.svg | 170 +++++++++--------- .../constant_near_stress/elk/board.exp.json | 4 +- .../constant_near_stress/elk/sketch.exp.svg | 170 +++++++++--------- .../dagre/board.exp.json | 92 +++++----- .../dagre/sketch.exp.svg | 160 ++++++++--------- .../elk/board.exp.json | 68 +++---- .../elk/sketch.exp.svg | 160 ++++++++--------- 10 files changed, 416 insertions(+), 416 deletions(-) diff --git a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg index becd23be5..5436e2231 100644 --- a/d2renderers/d2sketch/testdata/animated/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/animated/sketch.exp.svg @@ -110,7 +110,7 @@ -wintersummertreessnowsun +wintersummertreessnowsun \ No newline at end of file diff --git a/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg b/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg index 52de585df..94d2f4ef0 100644 --- a/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/animated_dark/sketch.exp.svg @@ -108,7 +108,7 @@ -wintersummertreessnowsun +wintersummertreessnowsun \ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json b/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json index cafa765c0..5b41f8c97 100644 --- a/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json +++ b/e2etests/testdata/stable/constant_near_stress/dagre/board.exp.json @@ -170,7 +170,7 @@ "type": "person", "pos": { "x": -508, - "y": 104 + "y": 83 }, "width": 44, "height": 66, @@ -211,7 +211,7 @@ "type": "person", "pos": { "x": 518, - "y": 104 + "y": 83 }, "width": 65, "height": 66, diff --git a/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg b/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg index 62f1a6897..7f6cf158c 100644 --- a/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_stress/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -xyThe top of the mountain

    Cats, no less liquid than their shadows, offer no angles to the wind.

    If we can't fix it, it ain't broke.

    Dieters live life in the fasting lane.

    -
    JoeDonaldi am top lefti am top righti am bottom lefti am bottom right +JoeDonaldi am top lefti am top righti am bottom lefti am bottom right
    \ No newline at end of file diff --git a/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json b/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json index cc89d016a..340654717 100644 --- a/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json +++ b/e2etests/testdata/stable/constant_near_stress/elk/board.exp.json @@ -170,7 +170,7 @@ "type": "person", "pos": { "x": -496, - "y": 101 + "y": 80 }, "width": 44, "height": 66, @@ -211,7 +211,7 @@ "type": "person", "pos": { "x": 530, - "y": 101 + "y": 80 }, "width": 65, "height": 66, diff --git a/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg b/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg index 16049be97..85d7b032e 100644 --- a/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/constant_near_stress/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -xyThe top of the mountain

    Cats, no less liquid than their shadows, offer no angles to the wind.

    If we can't fix it, it ain't broke.

    Dieters live life in the fasting lane.

    -
    JoeDonaldi am top lefti am top righti am bottom lefti am bottom right +JoeDonaldi am top lefti am top righti am bottom lefti am bottom right
    \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json index e1f0d9e31..97329ee10 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/board.exp.json @@ -8,7 +8,7 @@ "type": "rectangle", "pos": { "x": -123, - "y": -16 + "y": 56 }, "width": 247, "height": 291, @@ -49,7 +49,7 @@ "type": "rectangle", "pos": { "x": -83, - "y": 13 + "y": 85 }, "width": 53, "height": 66, @@ -90,7 +90,7 @@ "type": "rectangle", "pos": { "x": -83, - "y": 179 + "y": 251 }, "width": 53, "height": 66, @@ -131,7 +131,7 @@ "type": "rectangle", "pos": { "x": 30, - "y": 13 + "y": 85 }, "width": 53, "height": 66, @@ -172,7 +172,7 @@ "type": "rectangle", "pos": { "x": 29, - "y": 179 + "y": 251 }, "width": 54, "height": 66, @@ -213,7 +213,7 @@ "type": "rectangle", "pos": { "x": -86, - "y": -281 + "y": -245 }, "width": 173, "height": 225, @@ -254,7 +254,7 @@ "type": "rectangle", "pos": { "x": -66, - "y": -215 + "y": -179 }, "width": 133, "height": 130, @@ -295,7 +295,7 @@ "type": "rectangle", "pos": { "x": -26, - "y": -183 + "y": -147 }, "width": 53, "height": 66, @@ -336,7 +336,7 @@ "type": "rectangle", "pos": { "x": -390, - "y": -347 + "y": -311 }, "width": 247, "height": 291, @@ -377,7 +377,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -317 + "y": -281 }, "width": 53, "height": 66, @@ -418,7 +418,7 @@ "type": "rectangle", "pos": { "x": -350, - "y": -151 + "y": -115 }, "width": 53, "height": 66, @@ -459,7 +459,7 @@ "type": "rectangle", "pos": { "x": -236, - "y": -317 + "y": -281 }, "width": 53, "height": 66, @@ -500,7 +500,7 @@ "type": "rectangle", "pos": { "x": -237, - "y": -151 + "y": -115 }, "width": 54, "height": 66, @@ -541,7 +541,7 @@ "type": "rectangle", "pos": { "x": 143, - "y": -347 + "y": -311 }, "width": 247, "height": 291, @@ -582,7 +582,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -317 + "y": -281 }, "width": 53, "height": 66, @@ -623,7 +623,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": -151 + "y": -115 }, "width": 53, "height": 66, @@ -664,7 +664,7 @@ "type": "rectangle", "pos": { "x": 297, - "y": -317 + "y": -281 }, "width": 53, "height": 66, @@ -705,7 +705,7 @@ "type": "rectangle", "pos": { "x": 296, - "y": -151 + "y": -115 }, "width": 54, "height": 66, @@ -746,7 +746,7 @@ "type": "rectangle", "pos": { "x": 143, - "y": -16 + "y": 56 }, "width": 214, "height": 325, @@ -787,7 +787,7 @@ "type": "rectangle", "pos": { "x": 163, - "y": 49 + "y": 121 }, "width": 174, "height": 230, @@ -828,7 +828,7 @@ "type": "rectangle", "pos": { "x": 183, - "y": 112 + "y": 184 }, "width": 134, "height": 135, @@ -869,7 +869,7 @@ "type": "rectangle", "pos": { "x": 223, - "y": 147 + "y": 219 }, "width": 54, "height": 66, @@ -935,19 +935,19 @@ "route": [ { "x": -57, - "y": 79.5 + "y": 151.5 }, { "x": -57, - "y": 119.5 + "y": 191.5 }, { "x": -57, - "y": 139.5 + "y": 211.5 }, { "x": -57, - "y": 179.5 + "y": 251.5 } ], "isCurve": true, @@ -984,19 +984,19 @@ "route": [ { "x": 56.5, - "y": 79.5 + "y": 151.5 }, { "x": 56.5, - "y": 119.5 + "y": 191.5 }, { "x": 56.5, - "y": 139.5 + "y": 211.5 }, { "x": 56.5, - "y": 179.5 + "y": 251.5 } ], "isCurve": true, @@ -1033,19 +1033,19 @@ "route": [ { "x": -324, - "y": -251.5 + "y": -215.5 }, { "x": -324, - "y": -211.5 + "y": -175.5 }, { "x": -324, - "y": -191.5 + "y": -155.5 }, { "x": -324, - "y": -151.5 + "y": -115.5 } ], "isCurve": true, @@ -1082,19 +1082,19 @@ "route": [ { "x": -210.5, - "y": -251.5 + "y": -215.5 }, { "x": -210.5, - "y": -211.5 + "y": -175.5 }, { "x": -210.5, - "y": -191.5 + "y": -155.5 }, { "x": -210.5, - "y": -151.5 + "y": -115.5 } ], "isCurve": true, @@ -1131,19 +1131,19 @@ "route": [ { "x": 210, - "y": -251.5 + "y": -215.5 }, { "x": 210, - "y": -211.5 + "y": -175.5 }, { "x": 210, - "y": -191.5 + "y": -155.5 }, { "x": 210, - "y": -151.5 + "y": -115.5 } ], "isCurve": true, @@ -1180,19 +1180,19 @@ "route": [ { "x": 323.5, - "y": -251.5 + "y": -215.5 }, { "x": 323.5, - "y": -211.5 + "y": -175.5 }, { "x": 323.5, - "y": -191.5 + "y": -155.5 }, { "x": 323.5, - "y": -151.5 + "y": -115.5 } ], "isCurve": true, diff --git a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg index 05ae752d1..d29991565 100644 --- a/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/dagre/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxybabcdbabcdabcdaccd - + .d2-1209788547 .fill-N1{fill:#0A0F25;} + .d2-1209788547 .fill-N2{fill:#676C7E;} + .d2-1209788547 .fill-N3{fill:#9499AB;} + .d2-1209788547 .fill-N4{fill:#CFD2DD;} + .d2-1209788547 .fill-N5{fill:#DEE1EB;} + .d2-1209788547 .fill-N6{fill:#EEF1F8;} + .d2-1209788547 .fill-N7{fill:#FFFFFF;} + .d2-1209788547 .fill-B1{fill:#0D32B2;} + .d2-1209788547 .fill-B2{fill:#0D32B2;} + .d2-1209788547 .fill-B3{fill:#E3E9FD;} + .d2-1209788547 .fill-B4{fill:#E3E9FD;} + .d2-1209788547 .fill-B5{fill:#EDF0FD;} + .d2-1209788547 .fill-B6{fill:#F7F8FE;} + .d2-1209788547 .fill-AA2{fill:#4A6FF3;} + .d2-1209788547 .fill-AA4{fill:#EDF0FD;} + .d2-1209788547 .fill-AA5{fill:#F7F8FE;} + .d2-1209788547 .fill-AB4{fill:#EDF0FD;} + .d2-1209788547 .fill-AB5{fill:#F7F8FE;} + .d2-1209788547 .stroke-N1{stroke:#0A0F25;} + .d2-1209788547 .stroke-N2{stroke:#676C7E;} + .d2-1209788547 .stroke-N3{stroke:#9499AB;} + .d2-1209788547 .stroke-N4{stroke:#CFD2DD;} + .d2-1209788547 .stroke-N5{stroke:#DEE1EB;} + .d2-1209788547 .stroke-N6{stroke:#EEF1F8;} + .d2-1209788547 .stroke-N7{stroke:#FFFFFF;} + .d2-1209788547 .stroke-B1{stroke:#0D32B2;} + .d2-1209788547 .stroke-B2{stroke:#0D32B2;} + .d2-1209788547 .stroke-B3{stroke:#E3E9FD;} + .d2-1209788547 .stroke-B4{stroke:#E3E9FD;} + .d2-1209788547 .stroke-B5{stroke:#EDF0FD;} + .d2-1209788547 .stroke-B6{stroke:#F7F8FE;} + .d2-1209788547 .stroke-AA2{stroke:#4A6FF3;} + .d2-1209788547 .stroke-AA4{stroke:#EDF0FD;} + .d2-1209788547 .stroke-AA5{stroke:#F7F8FE;} + .d2-1209788547 .stroke-AB4{stroke:#EDF0FD;} + .d2-1209788547 .stroke-AB5{stroke:#F7F8FE;} + .d2-1209788547 .background-color-N1{background-color:#0A0F25;} + .d2-1209788547 .background-color-N2{background-color:#676C7E;} + .d2-1209788547 .background-color-N3{background-color:#9499AB;} + .d2-1209788547 .background-color-N4{background-color:#CFD2DD;} + .d2-1209788547 .background-color-N5{background-color:#DEE1EB;} + .d2-1209788547 .background-color-N6{background-color:#EEF1F8;} + .d2-1209788547 .background-color-N7{background-color:#FFFFFF;} + .d2-1209788547 .background-color-B1{background-color:#0D32B2;} + .d2-1209788547 .background-color-B2{background-color:#0D32B2;} + .d2-1209788547 .background-color-B3{background-color:#E3E9FD;} + .d2-1209788547 .background-color-B4{background-color:#E3E9FD;} + .d2-1209788547 .background-color-B5{background-color:#EDF0FD;} + .d2-1209788547 .background-color-B6{background-color:#F7F8FE;} + .d2-1209788547 .background-color-AA2{background-color:#4A6FF3;} + .d2-1209788547 .background-color-AA4{background-color:#EDF0FD;} + .d2-1209788547 .background-color-AA5{background-color:#F7F8FE;} + .d2-1209788547 .background-color-AB4{background-color:#EDF0FD;} + .d2-1209788547 .background-color-AB5{background-color:#F7F8FE;} + .d2-1209788547 .color-N1{color:#0A0F25;} + .d2-1209788547 .color-N2{color:#676C7E;} + .d2-1209788547 .color-N3{color:#9499AB;} + .d2-1209788547 .color-N4{color:#CFD2DD;} + .d2-1209788547 .color-N5{color:#DEE1EB;} + .d2-1209788547 .color-N6{color:#EEF1F8;} + .d2-1209788547 .color-N7{color:#FFFFFF;} + .d2-1209788547 .color-B1{color:#0D32B2;} + .d2-1209788547 .color-B2{color:#0D32B2;} + .d2-1209788547 .color-B3{color:#E3E9FD;} + .d2-1209788547 .color-B4{color:#E3E9FD;} + .d2-1209788547 .color-B5{color:#EDF0FD;} + .d2-1209788547 .color-B6{color:#F7F8FE;} + .d2-1209788547 .color-AA2{color:#4A6FF3;} + .d2-1209788547 .color-AA4{color:#EDF0FD;} + .d2-1209788547 .color-AA5{color:#F7F8FE;} + .d2-1209788547 .color-AB4{color:#EDF0FD;} + .d2-1209788547 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxybabcdbabcdabcdaccd + \ No newline at end of file diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json index 1027c67a3..942b0e639 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json +++ b/e2etests/testdata/stable/near_keys_for_container/elk/board.exp.json @@ -8,7 +8,7 @@ "type": "rectangle", "pos": { "x": -113, - "y": -16 + "y": 20 }, "width": 227, "height": 302, @@ -49,7 +49,7 @@ "type": "rectangle", "pos": { "x": -63, - "y": 34 + "y": 70 }, "width": 53, "height": 66, @@ -90,7 +90,7 @@ "type": "rectangle", "pos": { "x": -63, - "y": 170 + "y": 206 }, "width": 53, "height": 66, @@ -131,7 +131,7 @@ "type": "rectangle", "pos": { "x": 10, - "y": 34 + "y": 70 }, "width": 53, "height": 66, @@ -172,7 +172,7 @@ "type": "rectangle", "pos": { "x": 9, - "y": 170 + "y": 206 }, "width": 54, "height": 66, @@ -213,7 +213,7 @@ "type": "rectangle", "pos": { "x": -126, - "y": -322 + "y": -286 }, "width": 253, "height": 266, @@ -254,7 +254,7 @@ "type": "rectangle", "pos": { "x": -76, - "y": -272 + "y": -236 }, "width": 153, "height": 166, @@ -295,7 +295,7 @@ "type": "rectangle", "pos": { "x": -26, - "y": -222 + "y": -186 }, "width": 53, "height": 66, @@ -336,7 +336,7 @@ "type": "rectangle", "pos": { "x": -373, - "y": -358 + "y": -322 }, "width": 227, "height": 302, @@ -377,7 +377,7 @@ "type": "rectangle", "pos": { "x": -323, - "y": -308 + "y": -272 }, "width": 53, "height": 66, @@ -418,7 +418,7 @@ "type": "rectangle", "pos": { "x": -323, - "y": -172 + "y": -136 }, "width": 53, "height": 66, @@ -459,7 +459,7 @@ "type": "rectangle", "pos": { "x": -250, - "y": -308 + "y": -272 }, "width": 53, "height": 66, @@ -500,7 +500,7 @@ "type": "rectangle", "pos": { "x": -250, - "y": -172 + "y": -136 }, "width": 54, "height": 66, @@ -541,7 +541,7 @@ "type": "rectangle", "pos": { "x": 146, - "y": -358 + "y": -322 }, "width": 227, "height": 302, @@ -582,7 +582,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": -308 + "y": -272 }, "width": 53, "height": 66, @@ -623,7 +623,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": -172 + "y": -136 }, "width": 53, "height": 66, @@ -664,7 +664,7 @@ "type": "rectangle", "pos": { "x": 270, - "y": -308 + "y": -272 }, "width": 53, "height": 66, @@ -705,7 +705,7 @@ "type": "rectangle", "pos": { "x": 269, - "y": -172 + "y": -136 }, "width": 54, "height": 66, @@ -746,7 +746,7 @@ "type": "rectangle", "pos": { "x": 146, - "y": -16 + "y": 20 }, "width": 354, "height": 366, @@ -787,7 +787,7 @@ "type": "rectangle", "pos": { "x": 196, - "y": 34 + "y": 70 }, "width": 254, "height": 266, @@ -828,7 +828,7 @@ "type": "rectangle", "pos": { "x": 246, - "y": 84 + "y": 120 }, "width": 154, "height": 166, @@ -869,7 +869,7 @@ "type": "rectangle", "pos": { "x": 296, - "y": 134 + "y": 170 }, "width": 54, "height": 66, @@ -935,11 +935,11 @@ "route": [ { "x": -37, - "y": 100 + "y": 136 }, { "x": -37, - "y": 170 + "y": 206 } ], "animated": false, @@ -975,11 +975,11 @@ "route": [ { "x": 36.5, - "y": 100 + "y": 136 }, { "x": 36.5, - "y": 170 + "y": 206 } ], "animated": false, @@ -1015,11 +1015,11 @@ "route": [ { "x": -297, - "y": -242 + "y": -206 }, { "x": -297, - "y": -172 + "y": -136 } ], "animated": false, @@ -1055,11 +1055,11 @@ "route": [ { "x": -223.5, - "y": -242 + "y": -206 }, { "x": -223.5, - "y": -172 + "y": -136 } ], "animated": false, @@ -1095,11 +1095,11 @@ "route": [ { "x": 223, - "y": -242 + "y": -206 }, { "x": 223, - "y": -172 + "y": -136 } ], "animated": false, @@ -1135,11 +1135,11 @@ "route": [ { "x": 296.5, - "y": -242 + "y": -206 }, { "x": 296.5, - "y": -172 + "y": -136 } ], "animated": false, diff --git a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg index 2a478c8b1..595875062 100644 --- a/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/near_keys_for_container/elk/sketch.exp.svg @@ -1,16 +1,16 @@ -zaxybabcdbabcdabcdaccd - + .d2-1517716488 .fill-N1{fill:#0A0F25;} + .d2-1517716488 .fill-N2{fill:#676C7E;} + .d2-1517716488 .fill-N3{fill:#9499AB;} + .d2-1517716488 .fill-N4{fill:#CFD2DD;} + .d2-1517716488 .fill-N5{fill:#DEE1EB;} + .d2-1517716488 .fill-N6{fill:#EEF1F8;} + .d2-1517716488 .fill-N7{fill:#FFFFFF;} + .d2-1517716488 .fill-B1{fill:#0D32B2;} + .d2-1517716488 .fill-B2{fill:#0D32B2;} + .d2-1517716488 .fill-B3{fill:#E3E9FD;} + .d2-1517716488 .fill-B4{fill:#E3E9FD;} + .d2-1517716488 .fill-B5{fill:#EDF0FD;} + .d2-1517716488 .fill-B6{fill:#F7F8FE;} + .d2-1517716488 .fill-AA2{fill:#4A6FF3;} + .d2-1517716488 .fill-AA4{fill:#EDF0FD;} + .d2-1517716488 .fill-AA5{fill:#F7F8FE;} + .d2-1517716488 .fill-AB4{fill:#EDF0FD;} + .d2-1517716488 .fill-AB5{fill:#F7F8FE;} + .d2-1517716488 .stroke-N1{stroke:#0A0F25;} + .d2-1517716488 .stroke-N2{stroke:#676C7E;} + .d2-1517716488 .stroke-N3{stroke:#9499AB;} + .d2-1517716488 .stroke-N4{stroke:#CFD2DD;} + .d2-1517716488 .stroke-N5{stroke:#DEE1EB;} + .d2-1517716488 .stroke-N6{stroke:#EEF1F8;} + .d2-1517716488 .stroke-N7{stroke:#FFFFFF;} + .d2-1517716488 .stroke-B1{stroke:#0D32B2;} + .d2-1517716488 .stroke-B2{stroke:#0D32B2;} + .d2-1517716488 .stroke-B3{stroke:#E3E9FD;} + .d2-1517716488 .stroke-B4{stroke:#E3E9FD;} + .d2-1517716488 .stroke-B5{stroke:#EDF0FD;} + .d2-1517716488 .stroke-B6{stroke:#F7F8FE;} + .d2-1517716488 .stroke-AA2{stroke:#4A6FF3;} + .d2-1517716488 .stroke-AA4{stroke:#EDF0FD;} + .d2-1517716488 .stroke-AA5{stroke:#F7F8FE;} + .d2-1517716488 .stroke-AB4{stroke:#EDF0FD;} + .d2-1517716488 .stroke-AB5{stroke:#F7F8FE;} + .d2-1517716488 .background-color-N1{background-color:#0A0F25;} + .d2-1517716488 .background-color-N2{background-color:#676C7E;} + .d2-1517716488 .background-color-N3{background-color:#9499AB;} + .d2-1517716488 .background-color-N4{background-color:#CFD2DD;} + .d2-1517716488 .background-color-N5{background-color:#DEE1EB;} + .d2-1517716488 .background-color-N6{background-color:#EEF1F8;} + .d2-1517716488 .background-color-N7{background-color:#FFFFFF;} + .d2-1517716488 .background-color-B1{background-color:#0D32B2;} + .d2-1517716488 .background-color-B2{background-color:#0D32B2;} + .d2-1517716488 .background-color-B3{background-color:#E3E9FD;} + .d2-1517716488 .background-color-B4{background-color:#E3E9FD;} + .d2-1517716488 .background-color-B5{background-color:#EDF0FD;} + .d2-1517716488 .background-color-B6{background-color:#F7F8FE;} + .d2-1517716488 .background-color-AA2{background-color:#4A6FF3;} + .d2-1517716488 .background-color-AA4{background-color:#EDF0FD;} + .d2-1517716488 .background-color-AA5{background-color:#F7F8FE;} + .d2-1517716488 .background-color-AB4{background-color:#EDF0FD;} + .d2-1517716488 .background-color-AB5{background-color:#F7F8FE;} + .d2-1517716488 .color-N1{color:#0A0F25;} + .d2-1517716488 .color-N2{color:#676C7E;} + .d2-1517716488 .color-N3{color:#9499AB;} + .d2-1517716488 .color-N4{color:#CFD2DD;} + .d2-1517716488 .color-N5{color:#DEE1EB;} + .d2-1517716488 .color-N6{color:#EEF1F8;} + .d2-1517716488 .color-N7{color:#FFFFFF;} + .d2-1517716488 .color-B1{color:#0D32B2;} + .d2-1517716488 .color-B2{color:#0D32B2;} + .d2-1517716488 .color-B3{color:#E3E9FD;} + .d2-1517716488 .color-B4{color:#E3E9FD;} + .d2-1517716488 .color-B5{color:#EDF0FD;} + .d2-1517716488 .color-B6{color:#F7F8FE;} + .d2-1517716488 .color-AA2{color:#4A6FF3;} + .d2-1517716488 .color-AA4{color:#EDF0FD;} + .d2-1517716488 .color-AA5{color:#F7F8FE;} + .d2-1517716488 .color-AB4{color:#EDF0FD;} + .d2-1517716488 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>zaxybabcdbabcdabcdaccd + \ No newline at end of file From 8e64ada77bafd45ccb8f90e688bae9d1a8a4b0d9 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Mon, 27 Mar 2023 21:44:39 +0800 Subject: [PATCH 26/42] chore: regenerate testcase --- .../testdata/TestCLI_E2E/animation.exp.svg | 174 +++++++++--------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg index 26e0bd29f..3d8067b44 100644 --- a/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg +++ b/e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg @@ -1,16 +1,16 @@ Chicken's plan +}]]>Chicken's plan -Approach roadChicken's plan +Approach roadChicken's plan -Approach roadCross roadChicken's plan +Approach roadCross roadChicken's plan -Approach roadCross roadMake you wonder whyChicken's plan +Approach roadCross roadMake you wonder whyChicken's plan \ No newline at end of file From 66f620f57b7e2af5102d5f23e1d869a11cc6a010 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Mon, 27 Mar 2023 22:48:02 +0800 Subject: [PATCH 27/42] fix: typo --- d2layouts/d2near/layout.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 9fc8eabc6..5b86b892e 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -117,12 +117,12 @@ func place(obj *d2graph.Object) (float64, float64) { } } else if strings.Contains(*obj.LabelPosition, "_LEFT_") { // label is on the left, and container is placed on the right - if strings.Contains(nearKeyStr, "bottom") { + if strings.Contains(nearKeyStr, "right") { x += float64(*obj.LabelWidth) } } else if strings.Contains(*obj.LabelPosition, "_RIGHT_") { // label is on the right, and container is placed on the left - if strings.Contains(nearKeyStr, "bottom") { + if strings.Contains(nearKeyStr, "left") { x -= float64(*obj.LabelWidth) } } else if strings.Contains(*obj.LabelPosition, "_BOTTOM_") { From 3d45f6ab51f171ea0c0d6eac6713c491110e1a6e Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 28 Mar 2023 08:57:15 +0800 Subject: [PATCH 28/42] fix: cr, return value --- d2graph/d2graph.go | 7 +++---- d2layouts/d2near/layout.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index ebeeb0816..5ffa7954b 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -968,16 +968,15 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R return &dims, nil } -func (obj *Object) IsInsideNearContainer() bool { +func (obj *Object) OuterNearContainer() *Object { temp := obj for temp != nil { - fmt.Println(temp.ID) if temp.Attributes.NearKey != nil { - return true + return temp } temp = temp.Parent } - return false + return nil } type Edge struct { diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 5b86b892e..b9d3fcbfa 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -225,7 +225,7 @@ func boundingBox(g *d2graph.Graph) (tl, br *geo.Point) { y2 = math.Max(y2, obj.TopLeft.Y+obj.Height) } } else { - if obj.IsInsideNearContainer() { + if obj.OuterNearContainer() != nil { continue } x1 = math.Min(x1, obj.TopLeft.X) From d85bb2d16f7a3501683a85d074470c353806d386 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 28 Mar 2023 16:55:06 +0800 Subject: [PATCH 29/42] fix: cr, redundant code --- d2lib/d2.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/d2lib/d2.go b/d2lib/d2.go index 13dccad3f..11a1dd521 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -72,10 +72,6 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta // run core layout for constantNears for _, tempGraph := range constantNearGraphs { - if tempGraph == nil { - continue - } - nearObject := tempGraph.Root.ChildrenArray[0] nearObject.Parent = tempGraph.Root if err = coreLayout(ctx, tempGraph); err != nil { From b9dd247c75013d0581d15ae2bb3490ca86e0ba4f Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Tue, 28 Mar 2023 21:10:37 +0800 Subject: [PATCH 30/42] fix: cr, validateNear outside connection --- d2compiler/compile.go | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 424c2795d..8f71f1a6b 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -736,12 +736,14 @@ func (c *compiler) validateNear(g *d2graph.Graph) { continue } - descendantsMap := getNearDescendants(obj) connectToOutside := false for _, edge := range g.Edges { - if (descendantsMap[edge.Src] && !descendantsMap[edge.Dst]) || - (!descendantsMap[edge.Src] && descendantsMap[edge.Dst]) { + srcNearContainer := edge.Src.OuterNearContainer() + dstNearContainer := edge.Dst.OuterNearContainer() + + if srcNearContainer != dstNearContainer { connectToOutside = true + break } } @@ -757,24 +759,6 @@ func (c *compiler) validateNear(g *d2graph.Graph) { } } -func getNearDescendants(nearObj *d2graph.Object) map[*d2graph.Object]bool { - descendantsMap := make(map[*d2graph.Object]bool) - - var helper func(obj *d2graph.Object) - - helper = func(obj *d2graph.Object) { - if obj.ChildrenArray != nil { - for _, child := range obj.ChildrenArray { - descendantsMap[child] = true - helper(child) - } - } - } - - helper(nearObj) - return descendantsMap -} - func (c *compiler) validateBoardLinks(g *d2graph.Graph) { for _, obj := range g.Objects { if obj.Attributes.Link == nil { From 6ee58d756e8cf5a6e72f78d0dce6b04a970909d9 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Thu, 30 Mar 2023 18:15:11 +0800 Subject: [PATCH 31/42] fix: cr, error info --- d2compiler/compile.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 8f71f1a6b..3f53c86ea 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -736,19 +736,19 @@ func (c *compiler) validateNear(g *d2graph.Graph) { continue } - connectToOutside := false + var edgeConnectToOutsideOfNear *d2graph.Edge for _, edge := range g.Edges { srcNearContainer := edge.Src.OuterNearContainer() dstNearContainer := edge.Dst.OuterNearContainer() if srcNearContainer != dstNearContainer { - connectToOutside = true + edgeConnectToOutsideOfNear = edge break } } - if connectToOutside { - c.errorf(obj.Attributes.NearKey, "a child of a near container cannot connect to outside") + if edgeConnectToOutsideOfNear != nil { + c.errorf(edgeConnectToOutsideOfNear.References[0].Edge, "cannot connect objects from within a container, that has near constant set, to objects outside that container") continue } } else { From ad515e6110fa6037fcaff410547c1f18382ea2a1 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Thu, 30 Mar 2023 18:15:35 +0800 Subject: [PATCH 32/42] chore: regenerate testcases --- d2compiler/compile_test.go | 2 +- .../TestCompile/near_descendant_connect_to_outside.exp.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index c8636dd5d..d9e0ac597 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1544,7 +1544,7 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set } x.y -> z `, - expErr: "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2:3:12: a child of a near container cannot connect to outside", + expErr: "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2:6:5: cannot connect objects from within a container, that has near constant set, to objects outside that container", }, { name: "nested_near_constant", diff --git a/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json b/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json index d43007599..ca04fbf51 100644 --- a/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json +++ b/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.exp.json @@ -4,8 +4,8 @@ "ioerr": null, "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2,2:11:21-2:19:29", - "errmsg": "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2:3:12: a child of a near container cannot connect to outside" + "range": "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2,5:4:47-5:12:55", + "errmsg": "d2/testdata/d2compiler/TestCompile/near_descendant_connect_to_outside.d2:6:5: cannot connect objects from within a container, that has near constant set, to objects outside that container" } ] } From a3268f2fd191ad27acac13445585840162fbe4c0 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Thu, 30 Mar 2023 20:31:42 +0800 Subject: [PATCH 33/42] fix: cr, a clean spilit for temp graph --- d2layouts/d2near/layout.go | 4 ++++ d2lib/d2.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index b9d3fcbfa..0379c503a 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -155,6 +155,10 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGr tempGraph := d2graph.NewGraph() tempGraph.Root.ChildrenArray = []*d2graph.Object{obj} tempGraph.Root.Children[obj.ID] = obj + + for _, descendantObj := range descendantObjects { + descendantObj.Graph = tempGraph + } tempGraph.Objects = descendantObjects tempGraph.Edges = edges diff --git a/d2lib/d2.go b/d2lib/d2.go index 11a1dd521..321b776e6 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -78,6 +78,9 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta return nil, err } nearObject.Parent = g.Root + for _, obj := range tempGraph.Objects { + obj.Graph = g + } } err = d2sequence.Layout(ctx, g, coreLayout) From ffa39a0ad86dd518bfc8e3cc16b6a6392abebb49 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Fri, 31 Mar 2023 21:44:10 +0800 Subject: [PATCH 34/42] chore: regenerate testcases --- d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg | 10 +++++----- e2etests-cli/testdata/TestCLI_E2E/animation.exp.svg | 8 ++++---- .../regression/unconnected/dagre/sketch.exp.svg | 10 +++++----- .../testdata/regression/unconnected/elk/sketch.exp.svg | 10 +++++----- .../stable/constant_near_stress/dagre/sketch.exp.svg | 10 +++++----- .../stable/constant_near_stress/elk/sketch.exp.svg | 10 +++++----- .../stable/constant_near_title/dagre/sketch.exp.svg | 10 +++++----- .../stable/constant_near_title/elk/sketch.exp.svg | 10 +++++----- .../stable/legend_with_near_key/dagre/sketch.exp.svg | 6 +++--- .../stable/legend_with_near_key/elk/sketch.exp.svg | 6 +++--- .../near_keys_for_container/dagre/sketch.exp.svg | 6 +++--- .../stable/near_keys_for_container/elk/sketch.exp.svg | 6 +++--- 12 files changed, 51 insertions(+), 51 deletions(-) diff --git a/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg b/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg index 2a56177fa..a4febb5c7 100644 --- a/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg +++ b/d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg @@ -1,16 +1,16 @@ -Chicken's plan +}]]>Chicken's plan -Approach roadChicken's plan +Approach roadChicken's plan -Approach roadCross roadChicken's plan +Approach roadCross roadChicken's plan -Approach roadCross roadMake you wonder whyChicken's plan +Approach roadCross roadMake you wonder whyChicken's plan \ No newline at end of file From 7a395ecf7175d1cd386cfe824c2e1daca20f8820 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 5 Apr 2023 08:31:23 +0800 Subject: [PATCH 40/42] fix: cr, OutNearContianer --- d2compiler/compile.go | 4 ++-- d2graph/d2graph.go | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 34cb7567f..0af1f26b6 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -763,10 +763,10 @@ func (c *compiler) validateNear(g *d2graph.Graph) { var isSrcNearConst, isDstNearConst bool - if srcNearContainer != nil { + if srcNearContainer != nil && srcNearContainer != edge.Src { _, isSrcNearConst = d2graph.NearConstants[d2graph.Key(srcNearContainer.Attributes.NearKey)[0]] } - if dstNearContainer != nil { + if dstNearContainer != nil && dstNearContainer != edge.Dst { _, isDstNearConst = d2graph.NearConstants[d2graph.Key(dstNearContainer.Attributes.NearKey)[0]] } diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 0f3df5683..5f966ddfc 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -969,13 +969,11 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R } func (obj *Object) OuterNearContainer() *Object { - temp := obj - for temp != nil { - // find outer near container that isn't itself - if temp.Attributes.NearKey != nil && temp != obj { - return temp + for obj != nil { + if obj.Attributes.NearKey != nil { + return obj } - temp = temp.Parent + obj = obj.Parent } return nil } From e61629e692a9e500ac22049a95e7d003d71a2573 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Thu, 6 Apr 2023 05:00:12 +0800 Subject: [PATCH 41/42] fix: cr --- ci/release/changelogs/next.md | 1 - d2compiler/compile.go | 16 ++-------------- d2compiler/compile_test.go | 2 +- d2layouts/d2near/layout.go | 9 ++++++++- d2lib/d2.go | 4 ---- .../TestCompile/near_bad_connected.exp.json | 4 ++-- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 6acfa4bcc..041b8e68b 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,7 +1,6 @@ #### Features ๐Ÿš€ - Container with constant key near attribute now can have descendant objects and connections [#1071](https://github.com/terrastruct/d2/pull/1071) - - Multi-board SVG outputs with internal links go to their output paths [#1116](https://github.com/terrastruct/d2/pull/1116) #### Improvements ๐Ÿงน diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 0af1f26b6..e75d791f7 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -734,22 +734,10 @@ func (c *compiler) validateNear(g *d2graph.Graph) { } } } else if isConst { - is := false - for _, e := range g.Edges { - if e.Src == obj || e.Dst == obj { - is = true - break - } - } - if is { - c.errorf(obj.Attributes.NearKey, "constant near keys cannot be set on connected shapes") - continue - } if obj.Parent != g.Root { c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes") continue } - } else { c.errorf(obj.Attributes.NearKey, "near key %#v must be the absolute path to a shape or one of the following constants: %s", d2format.Format(obj.Attributes.NearKey), strings.Join(d2graph.NearConstantsArray, ", ")) continue @@ -763,10 +751,10 @@ func (c *compiler) validateNear(g *d2graph.Graph) { var isSrcNearConst, isDstNearConst bool - if srcNearContainer != nil && srcNearContainer != edge.Src { + if srcNearContainer != nil { _, isSrcNearConst = d2graph.NearConstants[d2graph.Key(srcNearContainer.Attributes.NearKey)[0]] } - if dstNearContainer != nil && dstNearContainer != edge.Dst { + if dstNearContainer != nil { _, isDstNearConst = d2graph.NearConstants[d2graph.Key(dstNearContainer.Attributes.NearKey)[0]] } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 586da1f7b..4a66b8e85 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1567,7 +1567,7 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set } x -> y `, - expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:3:12: constant near keys cannot be set on connected shapes`, + expErr: `d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:5:5: cannot connect objects from within a container, that has near constant set, to objects outside that container`, }, { name: "near_descendant_connect_to_outside", diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 6f3a177be..88b8382d8 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -20,6 +20,13 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs []*d2graph return nil } + for _, tempGraph := range constantNearGraphs { + tempGraph.Root.ChildrenArray[0].Parent = g.Root + for _, obj := range tempGraph.Objects { + obj.Graph = g + } + } + // Imagine the graph has two long texts, one at top center and one at top left. // Top left should go left enough to not collide with center. // So place the center ones first, then the later ones will consider them for bounding box @@ -151,7 +158,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGr tempGraph := d2graph.NewGraph() tempGraph.Root.ChildrenArray = []*d2graph.Object{obj} - tempGraph.Root.Children[obj.ID] = obj + tempGraph.Root.Children[strings.ToLower(obj.ID)] = obj for _, descendantObj := range descendantObjects { descendantObj.Graph = tempGraph diff --git a/d2lib/d2.go b/d2lib/d2.go index 160e73158..8f94d86c2 100644 --- a/d2lib/d2.go +++ b/d2lib/d2.go @@ -75,10 +75,6 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta if err = coreLayout(ctx, tempGraph); err != nil { return nil, err } - tempGraph.Root.ChildrenArray[0].Parent = g.Root - for _, obj := range tempGraph.Objects { - obj.Graph = g - } } err = d2sequence.Layout(ctx, g, coreLayout) diff --git a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json index 03c55a204..b5ac2eb4a 100644 --- a/testdata/d2compiler/TestCompile/near_bad_connected.exp.json +++ b/testdata/d2compiler/TestCompile/near_bad_connected.exp.json @@ -4,8 +4,8 @@ "ioerr": null, "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,2:11:21-2:21:31", - "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:3:12: constant near keys cannot be set on connected shapes" + "range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,4:4:42-4:10:48", + "errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:5:5: cannot connect objects from within a container, that has near constant set, to objects outside that container" } ] } From 59ef4ad832d35fa1df81a38f09e885cbdbe0ddf3 Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Fri, 7 Apr 2023 10:33:19 +0800 Subject: [PATCH 42/42] fix: cr, attach objects of tempGraph --- d2layouts/d2near/layout.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index 88b8382d8..0359b2b70 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -52,18 +52,16 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs []*d2graph point.Y += dy } } - - g.Edges = append(g.Edges, tempGraph.Edges...) } } for _, tempGraph := range constantNearGraphs { obj := tempGraph.Root.ChildrenArray[0] if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") { // The z-index for constant nears does not matter, as it will not collide - g.Objects = append(g.Objects, obj) + g.Objects = append(g.Objects, tempGraph.Objects...) obj.Parent.Children[obj.ID] = obj obj.Parent.ChildrenArray = append(obj.Parent.ChildrenArray, obj) - attachChildren(g, obj) + g.Edges = append(g.Edges, tempGraph.Edges...) } } } @@ -71,13 +69,6 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs []*d2graph return nil } -func attachChildren(g *d2graph.Graph, obj *d2graph.Object) { - for _, child := range obj.ChildrenArray { - g.Objects = append(g.Objects, child) - attachChildren(g, child) - } -} - // place returns the position of obj, taking into consideration its near value and the diagram func place(obj *d2graph.Object) (float64, float64) { tl, br := boundingBox(obj.Graph)