Skip to content

Commit

Permalink
Merge pull request #1362 from alixander/classes-overriding
Browse files Browse the repository at this point in the history
fix multiple classes modifying arrowheads
  • Loading branch information
alixander authored Jun 2, 2023
2 parents 3b52e1b + f6b1d75 commit e40a65a
Show file tree
Hide file tree
Showing 4 changed files with 687 additions and 2 deletions.
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

0 comments on commit e40a65a

Please sign in to comment.