Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiple classes modifying arrowheads #1362

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
- Fixes fonts not rendering correctly on certain platforms. Thanks @mikeday for identifying the solution. [#1356](https://github.com/terrastruct/d2/pull/1356)
- Fixes folders not rendering in animations (`--animate-interval`) [#1357](https://github.com/terrastruct/d2/pull/1357)
- Fixes panic using reserved keywords as containers [#1358](https://github.com/terrastruct/d2/pull/1358)
- When multiple classes are applied changing different attributes of arrowheads, they are
all applied instead of only the last one [#1362](https://github.com/terrastruct/d2/pull/1362)
8 changes: 6 additions & 2 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,14 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
var attrs *d2graph.Attributes
if f.Name == "source-arrowhead" {
edge.SrcArrowhead = &d2graph.Attributes{}
if edge.SrcArrowhead == nil {
edge.SrcArrowhead = &d2graph.Attributes{}
}
attrs = edge.SrcArrowhead
} else {
edge.DstArrowhead = &d2graph.Attributes{}
if edge.DstArrowhead == nil {
edge.DstArrowhead = &d2graph.Attributes{}
}
attrs = edge.DstArrowhead
}

Expand Down
23 changes: 23 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,29 @@ classes.x.shape: diamond
tassert.Equal(t, "diamond", g.Objects[0].Shape.Value)
},
},
{
name: "nested-array-classes",
text: `classes: {
one target: {
target-arrowhead.label: 1
}
association: {
target-arrowhead.shape: arrow
}
}

a -> b: { class: [one target; association] }
a -> b: { class: [association; one target] }
`,
assertions: func(t *testing.T, g *d2graph.Graph) {
// They have the same, regardless of order of class application
// since the classes modify attributes exclusive of each other
tassert.Equal(t, "1", g.Edges[0].DstArrowhead.Label.Value)
tassert.Equal(t, "1", g.Edges[1].DstArrowhead.Label.Value)
tassert.Equal(t, "arrow", g.Edges[0].DstArrowhead.Shape.Value)
tassert.Equal(t, "arrow", g.Edges[1].DstArrowhead.Shape.Value)
},
},
{
name: "class-shape-class",
text: `classes: {
Expand Down
Loading