Skip to content

Commit

Permalink
Merge pull request #1835 from alixander/set-label-near
Browse files Browse the repository at this point in the history
d2oracle: fix label near setting
  • Loading branch information
alixander authored Feb 14, 2024
2 parents 03795d8 + 77aa38b commit 4c845ed
Show file tree
Hide file tree
Showing 7 changed files with 939 additions and 3 deletions.
17 changes: 14 additions & 3 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,20 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
}
}
case "label":
if inlined(&attrs.Label) {
attrs.Label.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
if len(mk.Key.Path[reservedIndex:]) > 1 {
reservedTargetKey = mk.Key.Path[reservedIndex+1].Unbox().ScalarString()
switch reservedTargetKey {
case "near":
if inlined(attrs.LabelPosition) {
attrs.LabelPosition.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
}
} else {
if inlined(&attrs.Label) {
attrs.Label.MapKey.SetScalar(mk.Value.ScalarBox())
return nil
}
}
}
}
Expand Down
70 changes: 70 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,76 @@ layers: {
value: go2.Pointer(`red`),
exp: `...@yo
(a -> b)[0].style.stroke: red
`,
},
{
name: "label-near/1",

text: `x
`,
key: `x.label.near`,
value: go2.Pointer(`bottom-right`),
exp: `x: {label.near: bottom-right}
`,
},
{
name: "label-near/2",

text: `x.label.near: bottom-left
`,
key: `x.label.near`,
value: go2.Pointer(`bottom-right`),
exp: `x.label.near: bottom-right
`,
},
{
name: "label-near/3",

text: `x: {
label.near: bottom-left
}
`,
key: `x.label.near`,
value: go2.Pointer(`bottom-right`),
exp: `x: {
label.near: bottom-right
}
`,
},
{
name: "label-near/4",

text: `x: {
label: hi {
near: bottom-left
}
}
`,
key: `x.label.near`,
value: go2.Pointer(`bottom-right`),
exp: `x: {
label: hi {
near: bottom-right
}
}
`,
},
{
name: "label-near/5",

text: `x: hi {
label: {
near: bottom-left
}
}
`,
key: `x.label.near`,
value: go2.Pointer(`bottom-right`),
exp: `x: hi {
label: {
near: bottom-right
}
}
`,
},
}
Expand Down
159 changes: 159 additions & 0 deletions testdata/d2oracle/TestSet/label-near/1.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4c845ed

Please sign in to comment.