diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index bae88cb9e..9a8c1e422 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -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 ⛑️ diff --git a/d2exporter/export.go b/d2exporter/export.go index ed746b867..f79e98af6 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -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 { @@ -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 { diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 2a7428ac5..f4994f137 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -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) diff --git a/e2etests/regression_test.go b/e2etests/regression_test.go index f1d20808f..6377a70f5 100644 --- a/e2etests/regression_test.go +++ b/e2etests/regression_test.go @@ -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) diff --git a/e2etests/testdata/files/arrowhead_font_color.d2 b/e2etests/testdata/files/arrowhead_font_color.d2 new file mode 100644 index 000000000..2187ced7b --- /dev/null +++ b/e2etests/testdata/files/arrowhead_font_color.d2 @@ -0,0 +1,9 @@ +direction: right +x <-> y: { + source-arrowhead: eth1 { + style.font-color: green + } + target-arrowhead: eth2 { + style.font-color: red + } +} diff --git a/e2etests/testdata/regression/arrowhead_font_color/dagre/board.exp.json b/e2etests/testdata/regression/arrowhead_font_color/dagre/board.exp.json new file mode 100644 index 000000000..b5243d082 --- /dev/null +++ b/e2etests/testdata/regression/arrowhead_font_color/dagre/board.exp.json @@ -0,0 +1,202 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "rectangle", + "pos": { + "x": 0, + "y": 0 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 153, + "y": 0 + }, + "width": 54, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(x <-> y)[0]", + "src": "x", + "srcArrow": "triangle", + "srcLabel": { + "label": "eth1", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "green", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 29, + "labelHeight": 21 + }, + "dst": "y", + "dstArrow": "triangle", + "dstLabel": { + "label": "eth2", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "red", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 30, + "labelHeight": 21 + }, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 53, + "y": 33 + }, + { + "x": 93, + "y": 33 + }, + { + "x": 113, + "y": 33 + }, + { + "x": 153, + "y": 33 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ], + "root": { + "id": "", + "type": "", + "pos": { + "x": 0, + "y": 0 + }, + "width": 0, + "height": 0, + "opacity": 0, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "N7", + "stroke": "", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "zIndex": 0, + "level": 0 + } +} diff --git a/e2etests/testdata/regression/arrowhead_font_color/dagre/sketch.exp.svg b/e2etests/testdata/regression/arrowhead_font_color/dagre/sketch.exp.svg new file mode 100644 index 000000000..7297a6468 --- /dev/null +++ b/e2etests/testdata/regression/arrowhead_font_color/dagre/sketch.exp.svg @@ -0,0 +1,103 @@ +xy eth1eth2 + + + + \ No newline at end of file diff --git a/e2etests/testdata/regression/arrowhead_font_color/elk/board.exp.json b/e2etests/testdata/regression/arrowhead_font_color/elk/board.exp.json new file mode 100644 index 000000000..e080bbbcc --- /dev/null +++ b/e2etests/testdata/regression/arrowhead_font_color/elk/board.exp.json @@ -0,0 +1,193 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "x", + "type": "rectangle", + "pos": { + "x": 12, + "y": 12 + }, + "width": 53, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "x", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 8, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "y", + "type": "rectangle", + "pos": { + "x": 135, + "y": 12 + }, + "width": 54, + "height": 66, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "B6", + "stroke": "B1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "y", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N1", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 9, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(x <-> y)[0]", + "src": "x", + "srcArrow": "triangle", + "srcLabel": { + "label": "eth1", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "green", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 29, + "labelHeight": 21 + }, + "dst": "y", + "dstArrow": "triangle", + "dstLabel": { + "label": "eth2", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "red", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 30, + "labelHeight": 21 + }, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 65, + "y": 45 + }, + { + "x": 135, + "y": 45 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ], + "root": { + "id": "", + "type": "", + "pos": { + "x": 0, + "y": 0 + }, + "width": 0, + "height": 0, + "opacity": 0, + "strokeDash": 0, + "strokeWidth": 0, + "borderRadius": 0, + "fill": "N7", + "stroke": "", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "zIndex": 0, + "level": 0 + } +} diff --git a/e2etests/testdata/regression/arrowhead_font_color/elk/sketch.exp.svg b/e2etests/testdata/regression/arrowhead_font_color/elk/sketch.exp.svg new file mode 100644 index 000000000..df409a223 --- /dev/null +++ b/e2etests/testdata/regression/arrowhead_font_color/elk/sketch.exp.svg @@ -0,0 +1,103 @@ +xy eth1eth2 + + + + \ No newline at end of file