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

connection arrowhead font color #1582

Merged
merged 4 commits into from
Sep 12, 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
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