d2ir: Filter glob creation of edges with edge index where appropriate
On query globs, filtering without the edge index overfilters as we only match one of the edge instead all of them.
This commit is contained in:
parent
69df741a6b
commit
57ffc8dbbd
9 changed files with 19695 additions and 3 deletions
13
d2ir/d2ir.go
13
d2ir/d2ir.go
|
|
@ -1237,10 +1237,14 @@ func (m *Map) createEdge2(eid *EdgeID, refctx *RefContext, gctx *globContext, sr
|
|||
|
||||
if gctx != nil {
|
||||
var ks string
|
||||
// We only ever want to create one of the edge per glob so we filter without the edge index.
|
||||
e2 := e.Copy(e.Parent()).(*Edge)
|
||||
e2.ID = e2.ID.Copy()
|
||||
e2.ID.Index = nil
|
||||
if refctx.Key.HasTripleGlob() {
|
||||
ks = d2format.Format(d2ast.MakeKeyPath(IDA(e)))
|
||||
ks = d2format.Format(d2ast.MakeKeyPath(IDA(e2)))
|
||||
} else {
|
||||
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(e)))
|
||||
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(e2)))
|
||||
}
|
||||
if _, ok := gctx.appliedEdges[ks]; ok {
|
||||
return nil, nil
|
||||
|
|
@ -1304,6 +1308,11 @@ func (e *Edge) AST() d2ast.Node {
|
|||
|
||||
func (e *Edge) IDString() string {
|
||||
ast := e.AST().(*d2ast.Key)
|
||||
if e.ID.Index != nil {
|
||||
ast.EdgeIndex = &d2ast.EdgeIndex{
|
||||
Int: e.ID.Index,
|
||||
}
|
||||
}
|
||||
ast.Primary = d2ast.ScalarBox{}
|
||||
ast.Value = d2ast.ValueBox{}
|
||||
return d2format.Format(ast)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ x -> y
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "label-filter",
|
||||
name: "label-filter/1",
|
||||
run: func(t testing.TB) {
|
||||
m, err := compile(t, `
|
||||
x
|
||||
|
|
@ -129,6 +129,27 @@ a -> z: delta
|
|||
assertQuery(t, m, 0, 0, "diamond", "(a -> z).target-arrowhead.shape")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "label-filter/2",
|
||||
run: func(t testing.TB) {
|
||||
m, err := compile(t, `
|
||||
(* -> *)[*].style.opacity: 0.1
|
||||
|
||||
(* -> *)[*]: {
|
||||
&label: hi
|
||||
style.opacity: 1
|
||||
}
|
||||
|
||||
x -> y: hi
|
||||
x -> y
|
||||
`)
|
||||
assert.Success(t, err)
|
||||
assertQuery(t, m, 6, 2, nil, "")
|
||||
assertQuery(t, m, 2, 0, "hi", "(x -> y)[0]")
|
||||
assertQuery(t, m, 0, 0, 1, "(x -> y)[0].style.opacity")
|
||||
assertQuery(t, m, 0, 0, 0.1, "(x -> y)[1].style.opacity")
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
runa(t, tca)
|
||||
|
|
|
|||
|
|
@ -500,6 +500,21 @@ scenarios: {
|
|||
assertQuery(t, m, 0, 0, "red", "scenarios.b.b.style.fill")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "alixander-review/6",
|
||||
run: func(t testing.TB) {
|
||||
m, err := compile(t, `
|
||||
(* -> *)[*].style.opacity: 0.1
|
||||
|
||||
x -> y: hi
|
||||
x -> y
|
||||
`)
|
||||
assert.Success(t, err)
|
||||
assertQuery(t, m, 6, 2, nil, "")
|
||||
assertQuery(t, m, 0, 0, 0.1, "(x -> y)[0].style.opacity")
|
||||
assertQuery(t, m, 0, 0, 0.1, "(x -> y)[1].style.opacity")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "override/1",
|
||||
run: func(t testing.TB) {
|
||||
|
|
|
|||
1356
testdata/d2ir/TestCompile/filters/edge.exp.json
generated
vendored
1356
testdata/d2ir/TestCompile/filters/edge.exp.json
generated
vendored
File diff suppressed because it is too large
Load diff
4654
testdata/d2ir/TestCompile/filters/label-filter/1.exp.json
generated
vendored
Normal file
4654
testdata/d2ir/TestCompile/filters/label-filter/1.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
3068
testdata/d2ir/TestCompile/filters/label-filter/2.exp.json
generated
vendored
Normal file
3068
testdata/d2ir/TestCompile/filters/label-filter/2.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
2199
testdata/d2ir/TestCompile/patterns/alixander-review/6.exp.json
generated
vendored
Normal file
2199
testdata/d2ir/TestCompile/patterns/alixander-review/6.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
4572
testdata/d2ir/TestCompile/patterns/edge-glob-index.exp.json
generated
vendored
4572
testdata/d2ir/TestCompile/patterns/edge-glob-index.exp.json
generated
vendored
File diff suppressed because it is too large
Load diff
3798
testdata/d2ir/TestCompile/patterns/glob-edge-glob-index.exp.json
generated
vendored
3798
testdata/d2ir/TestCompile/patterns/glob-edge-glob-index.exp.json
generated
vendored
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue