Skip to content

Commit

Permalink
Merge pull request #1582 from gavin-ts/arrowhead-font-color
Browse files Browse the repository at this point in the history
connection arrowhead font color
  • Loading branch information
gavin-ts authored Sep 12, 2023
2 parents cb0c19f + fdf9ec1 commit b785229
Show file tree
Hide file tree
Showing 9 changed files with 627 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Latex now includes Mathjax's ASM extension for more powerful Latex functionality [#1544](https://github.com/terrastruct/d2/pull/1544)
- `font-color` works on Markdown [#1546](https://github.com/terrastruct/d2/pull/1546)
- `font-color` works on arrowheads [#1582](https://github.com/terrastruct/d2/pull/1582)

#### Bugfixes ⛑️

Expand Down
6 changes: 6 additions & 0 deletions d2exporter/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
LabelWidth: edge.SrcArrowhead.LabelDimensions.Width,
LabelHeight: edge.SrcArrowhead.LabelDimensions.Height,
}
if edge.SrcArrowhead.Style.FontColor != nil {
connection.SrcLabel.Color = edge.SrcArrowhead.Style.FontColor.Value
}
}
}
if edge.DstArrow {
Expand All @@ -228,6 +231,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
LabelWidth: edge.DstArrowhead.LabelDimensions.Width,
LabelHeight: edge.DstArrowhead.LabelDimensions.Height,
}
if edge.DstArrowhead.Style.FontColor != nil {
connection.DstLabel.Color = edge.DstArrowhead.Style.FontColor.Value
}
}
}
if theme != nil && theme.SpecialRules.NoCornerRadius {
Expand Down
9 changes: 9 additions & 0 deletions d2renderers/d2svg/d2svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,15 @@ func renderArrowheadLabel(connection d2target.Connection, text string, isDst boo
textEl.X = baselineCenter.X
textEl.Y = baselineCenter.Y
textEl.Fill = d2target.FG_COLOR
if isDst {
if connection.DstLabel.Color != "" {
textEl.Fill = connection.DstLabel.Color
}
} else {
if connection.SrcLabel.Color != "" {
textEl.Fill = connection.SrcLabel.Color
}
}
textEl.ClassName = "text-italic"
textEl.Style = fmt.Sprintf("text-anchor:middle;font-size:%vpx", connection.FontSize)
textEl.Content = RenderText(text, textEl.X, height)
Expand Down
1 change: 1 addition & 0 deletions e2etests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ cf many required: {
loadFromFile(t, "icons_on_top"),
loadFromFile(t, "dagre_disconnected_edge"),
loadFromFile(t, "outside_grid_label_position"),
loadFromFile(t, "arrowhead_font_color"),
}

runa(t, tcs)
Expand Down
9 changes: 9 additions & 0 deletions e2etests/testdata/files/arrowhead_font_color.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
direction: right
x <-> y: {
source-arrowhead: eth1 {
style.font-color: green
}
target-arrowhead: eth2 {
style.font-color: red
}
}
202 changes: 202 additions & 0 deletions e2etests/testdata/regression/arrowhead_font_color/dagre/board.exp.json

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

103 changes: 103 additions & 0 deletions e2etests/testdata/regression/arrowhead_font_color/dagre/sketch.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b785229

Please sign in to comment.