fix: cr
This commit is contained in:
parent
7a395ecf71
commit
e61629e692
6 changed files with 13 additions and 23 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
#### Features 🚀
|
#### Features 🚀
|
||||||
|
|
||||||
- Container with constant key near attribute now can have descendant objects and connections [#1071](https://github.com/terrastruct/d2/pull/1071)
|
- 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)
|
- Multi-board SVG outputs with internal links go to their output paths [#1116](https://github.com/terrastruct/d2/pull/1116)
|
||||||
|
|
||||||
#### Improvements 🧹
|
#### Improvements 🧹
|
||||||
|
|
|
||||||
|
|
@ -734,22 +734,10 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if isConst {
|
} 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 {
|
if obj.Parent != g.Root {
|
||||||
c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes")
|
c.errorf(obj.Attributes.NearKey, "constant near keys can only be set on root level shapes")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} 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, ", "))
|
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
|
continue
|
||||||
|
|
@ -763,10 +751,10 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
|
||||||
|
|
||||||
var isSrcNearConst, isDstNearConst bool
|
var isSrcNearConst, isDstNearConst bool
|
||||||
|
|
||||||
if srcNearContainer != nil && srcNearContainer != edge.Src {
|
if srcNearContainer != nil {
|
||||||
_, isSrcNearConst = d2graph.NearConstants[d2graph.Key(srcNearContainer.Attributes.NearKey)[0]]
|
_, 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]]
|
_, isDstNearConst = d2graph.NearConstants[d2graph.Key(dstNearContainer.Attributes.NearKey)[0]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1567,7 +1567,7 @@ d2/testdata/d2compiler/TestCompile/near-invalid.d2:14:9: near keys cannot be set
|
||||||
}
|
}
|
||||||
x -> y
|
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",
|
name: "near_descendant_connect_to_outside",
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,13 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs []*d2graph
|
||||||
return nil
|
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.
|
// 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.
|
// 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
|
// 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 := d2graph.NewGraph()
|
||||||
tempGraph.Root.ChildrenArray = []*d2graph.Object{obj}
|
tempGraph.Root.ChildrenArray = []*d2graph.Object{obj}
|
||||||
tempGraph.Root.Children[obj.ID] = obj
|
tempGraph.Root.Children[strings.ToLower(obj.ID)] = obj
|
||||||
|
|
||||||
for _, descendantObj := range descendantObjects {
|
for _, descendantObj := range descendantObjects {
|
||||||
descendantObj.Graph = tempGraph
|
descendantObj.Graph = tempGraph
|
||||||
|
|
|
||||||
|
|
@ -75,10 +75,6 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta
|
||||||
if err = coreLayout(ctx, tempGraph); err != nil {
|
if err = coreLayout(ctx, tempGraph); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
tempGraph.Root.ChildrenArray[0].Parent = g.Root
|
|
||||||
for _, obj := range tempGraph.Objects {
|
|
||||||
obj.Graph = g
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = d2sequence.Layout(ctx, g, coreLayout)
|
err = d2sequence.Layout(ctx, g, coreLayout)
|
||||||
|
|
|
||||||
4
testdata/d2compiler/TestCompile/near_bad_connected.exp.json
generated
vendored
4
testdata/d2compiler/TestCompile/near_bad_connected.exp.json
generated
vendored
|
|
@ -4,8 +4,8 @@
|
||||||
"ioerr": null,
|
"ioerr": null,
|
||||||
"errs": [
|
"errs": [
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,2:11:21-2:21:31",
|
"range": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2,4:4:42-4:10:48",
|
||||||
"errmsg": "d2/testdata/d2compiler/TestCompile/near_bad_connected.d2:3:12: constant near keys cannot be set on connected shapes"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue