From 4db1f721345c1210ba53c2d2bcfe4c33e3855f14 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 14 Feb 2024 16:46:47 -0800 Subject: [PATCH] allow underlines for connections --- ci/release/changelogs/next.md | 6 +- d2exporter/export.go | 3 + d2renderers/d2svg/d2svg.go | 3 + e2etests/testdata/txtar.txt | 6 + .../connection-underline/dagre/board.exp.json | 178 ++++++++++++++++++ .../connection-underline/dagre/sketch.exp.svg | 107 +++++++++++ .../connection-underline/elk/board.exp.json | 169 +++++++++++++++++ .../connection-underline/elk/sketch.exp.svg | 107 +++++++++++ 8 files changed, 577 insertions(+), 2 deletions(-) create mode 100644 e2etests/testdata/txtar/connection-underline/dagre/board.exp.json create mode 100644 e2etests/testdata/txtar/connection-underline/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/txtar/connection-underline/elk/board.exp.json create mode 100644 e2etests/testdata/txtar/connection-underline/elk/sketch.exp.svg diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index f3a19c9711..d0bb47702b 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,8 +1,10 @@ #### Features ๐Ÿš€ +- `style.underline` works on connections [#1836](https://github.com/terrastruct/d2/pull/1836) + #### Improvements ๐Ÿงน #### Bugfixes โ›‘๏ธ -- Fixes `null` being set on a nested shape not working in certain cases when connections also pointed to that shape [1830](https://github.com/terrastruct/d2/pull/1830) -- Fixes edge case of bad import syntax crashing using d2 as a library [1829](https://github.com/terrastruct/d2/pull/1829) +- Fixes `null` being set on a nested shape not working in certain cases when connections also pointed to that shape [#1830](https://github.com/terrastruct/d2/pull/1830) +- Fixes edge case of bad import syntax crashing using d2 as a library [#1829](https://github.com/terrastruct/d2/pull/1829) diff --git a/d2exporter/export.go b/d2exporter/export.go index 6c25d5b8f9..d01147af92 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -345,6 +345,9 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection if edge.Style.Bold != nil { connection.Bold, _ = strconv.ParseBool(edge.Style.Bold.Value) } + if edge.Style.Underline != nil { + connection.Underline, _ = strconv.ParseBool(edge.Style.Underline.Value) + } if theme != nil && theme.SpecialRules.Mono { connection.FontFamily = "mono" } diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 68e2f18520..41674e1257 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -588,6 +588,9 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co } else if connection.Italic { fontClass += "-italic" } + if connection.Underline { + fontClass += " text-underline" + } if connection.Fill != color.Empty { rectEl := d2themes.NewThemableElement("rect") rectEl.X, rectEl.Y = labelTL.X, labelTL.Y diff --git a/e2etests/testdata/txtar.txt b/e2etests/testdata/txtar.txt index fc009ca2b5..cdcdb05574 100644 --- a/e2etests/testdata/txtar.txt +++ b/e2etests/testdata/txtar.txt @@ -164,3 +164,9 @@ monsters: { } costumes.monster -> monsters.id + +-- connection-underline -- + +a -> b: hi { + style.underline: true +} diff --git a/e2etests/testdata/txtar/connection-underline/dagre/board.exp.json b/e2etests/testdata/txtar/connection-underline/dagre/board.exp.json new file mode 100644 index 0000000000..93d7d24b33 --- /dev/null +++ b/e2etests/testdata/txtar/connection-underline/dagre/board.exp.json @@ -0,0 +1,178 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "a", + "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": "a", + "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": "b", + "type": "rectangle", + "pos": { + "x": 0, + "y": 187 + }, + "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": "b", + "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 + } + ], + "connections": [ + { + "id": "(a -> b)[0]", + "src": "a", + "srcArrow": "none", + "dst": "b", + "dstArrow": "triangle", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "hi", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": true, + "labelWidth": 13, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 26.5, + "y": 65.5 + }, + { + "x": 26.5, + "y": 114.30000305175781 + }, + { + "x": 26.5, + "y": 138.6999969482422 + }, + { + "x": 26.5, + "y": 187.5 + } + ], + "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/txtar/connection-underline/dagre/sketch.exp.svg b/e2etests/testdata/txtar/connection-underline/dagre/sketch.exp.svg new file mode 100644 index 0000000000..c830546b78 --- /dev/null +++ b/e2etests/testdata/txtar/connection-underline/dagre/sketch.exp.svg @@ -0,0 +1,107 @@ +ab hi + + + + + \ No newline at end of file diff --git a/e2etests/testdata/txtar/connection-underline/elk/board.exp.json b/e2etests/testdata/txtar/connection-underline/elk/board.exp.json new file mode 100644 index 0000000000..a1cde3b44c --- /dev/null +++ b/e2etests/testdata/txtar/connection-underline/elk/board.exp.json @@ -0,0 +1,169 @@ +{ + "name": "", + "isFolderOnly": false, + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "a", + "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": "a", + "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": "b", + "type": "rectangle", + "pos": { + "x": 12, + "y": 239 + }, + "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": "b", + "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 + } + ], + "connections": [ + { + "id": "(a -> b)[0]", + "src": "a", + "srcArrow": "none", + "dst": "b", + "dstArrow": "triangle", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "B1", + "borderRadius": 10, + "label": "hi", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "N2", + "italic": true, + "bold": false, + "underline": true, + "labelWidth": 13, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "labelPercentage": 0, + "route": [ + { + "x": 38.5, + "y": 78 + }, + { + "x": 38.5, + "y": 239 + } + ], + "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/txtar/connection-underline/elk/sketch.exp.svg b/e2etests/testdata/txtar/connection-underline/elk/sketch.exp.svg new file mode 100644 index 0000000000..c9917bd079 --- /dev/null +++ b/e2etests/testdata/txtar/connection-underline/elk/sketch.exp.svg @@ -0,0 +1,107 @@ +ab hi + + + + + \ No newline at end of file