From 8891227045f417bd789354e596c89af1895dc6a9 Mon Sep 17 00:00:00 2001 From: harryjrk Date: Sat, 31 Dec 2022 11:59:40 +0100 Subject: [PATCH 1/4] Add the crow feet variants to arrowheads Introduce new styles for arrowhead: - crows-feet-many-required - crows-feet-many-optional - crows-feet-one-required - crows-feet-one-optional --- d2renderers/d2svg/d2svg.go | 56 ++++++++++++++++++++++++++++++++++++++ d2target/d2target.go | 18 ++++++++++++ 2 files changed, 74 insertions(+) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index cc735055a..056167495 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -113,6 +113,15 @@ func arrowheadDimensions(arrowhead d2target.Arrowhead, strokeWidth float64) (wid case d2target.DiamondArrowhead: widthMultiplier = 11 heightMultiplier = 9 + case d2target.CrowsFeetManyOptional: + fallthrough + case d2target.CrowsFeetManyRequired: + fallthrough + case d2target.CrowsFeetOneOptional: + fallthrough + case d2target.CrowsFeetOneRequired: + widthMultiplier = 14 + heightMultiplier = 15 } clippedStrokeWidth := go2.Max(MIN_ARROWHEAD_STROKE_WIDTH, strokeWidth) @@ -220,6 +229,53 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s width*0.6, height*7/8, ) } + case d2target.CrowsFeetOneRequired: + fallthrough + case d2target.CrowsFeetOneOptional: + fallthrough + case d2target.CrowsFeetManyRequired: + fallthrough + case d2target.CrowsFeetManyOptional: + attrs := fmt.Sprintf(`class="connection" stroke="%s" stroke-width="%d" fill="white"`, connection.Stroke, connection.StrokeWidth) + offset := 4.0 + (float64(connection.StrokeWidth) * 2.0) + var modifier string + if arrowhead == d2target.CrowsFeetManyRequired || arrowhead == d2target.CrowsFeetOneRequired { + modifier = fmt.Sprintf(``, + attrs, + width, height/2.0, + offset/2.0+1.0, height/2.0, + offset, 0., + offset, height, + ) + } else { + modifier = fmt.Sprintf(``, + attrs, + offset/2.0+1.0, height/2.0, + offset/2.0, + ) + } + if !isTarget { + attrs = fmt.Sprintf(`%s transform="scale(-1) translate(-%f, -%f)"`, attrs, width, height) + } + if arrowhead == d2target.CrowsFeetManyOptional || arrowhead == d2target.CrowsFeetManyRequired { + path = fmt.Sprintf(`%s`, + attrs, modifier, + offset+2.0, height/2.0, + width+offset, height/2.0, + offset+2.0, height/2.0, + width+offset, 0., + offset+2.0, height/2.0, + width+offset, height, + ) + } else { + path = fmt.Sprintf(`%s`, + attrs, modifier, + offset+2.0, height/2.0, + width+offset, height/2.0, + offset*1.8, 0., + offset*1.8, height, + ) + } default: return "" } diff --git a/d2target/d2target.go b/d2target/d2target.go index ea54ee52f..58fe683e3 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -280,6 +280,12 @@ const ( // For fat arrows LineArrowhead Arrowhead = "line" + + // Crows feet notation + CrowsFeetManyRequired Arrowhead = "crows-feet-many-required" + CrowsFeetManyOptional Arrowhead = "crows-feet-many-optional" + CrowsFeetOneRequired Arrowhead = "crows-feet-one-required" + CrowsFeetOneOptional Arrowhead = "crows-feet-one-optional" ) var Arrowheads = map[string]struct{}{ @@ -288,6 +294,10 @@ var Arrowheads = map[string]struct{}{ string(TriangleArrowhead): {}, string(DiamondArrowhead): {}, string(FilledDiamondArrowhead): {}, + string(CrowsFeetManyRequired): {}, + string(CrowsFeetManyOptional): {}, + string(CrowsFeetOneRequired): {}, + string(CrowsFeetOneOptional): {}, } func ToArrowhead(arrowheadType string, filled bool) Arrowhead { @@ -299,6 +309,14 @@ func ToArrowhead(arrowheadType string, filled bool) Arrowhead { return DiamondArrowhead case string(ArrowArrowhead): return ArrowArrowhead + case string(CrowsFeetManyRequired): + return CrowsFeetManyRequired + case string(CrowsFeetManyOptional): + return CrowsFeetManyOptional + case string(CrowsFeetOneRequired): + return CrowsFeetOneRequired + case string(CrowsFeetOneOptional): + return CrowsFeetOneOptional default: return TriangleArrowhead } From 847b7121019745ae78683e803405da0679c2c0f8 Mon Sep 17 00:00:00 2001 From: harryjrk Date: Sat, 31 Dec 2022 17:50:40 +0100 Subject: [PATCH 2/4] add next.MD message, replace falltrough with comma --- ci/release/changelogs/next.md | 2 ++ d2renderers/d2svg/d2svg.go | 16 ++-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index f3c0d2a77..3d3a7413f 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,5 +1,7 @@ #### Features ๐Ÿš€ +- Crow foot notation is now supported. [#578](https://github.com/terrastruct/d2/pull/578) + #### Improvements ๐Ÿงน #### Bugfixes โ›‘๏ธ diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 056167495..ba95620e6 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -113,13 +113,7 @@ func arrowheadDimensions(arrowhead d2target.Arrowhead, strokeWidth float64) (wid case d2target.DiamondArrowhead: widthMultiplier = 11 heightMultiplier = 9 - case d2target.CrowsFeetManyOptional: - fallthrough - case d2target.CrowsFeetManyRequired: - fallthrough - case d2target.CrowsFeetOneOptional: - fallthrough - case d2target.CrowsFeetOneRequired: + case d2target.CfOne, d2target.CfMany, d2target.CfOneRequired, d2target.CfManyRequired: widthMultiplier = 14 heightMultiplier = 15 } @@ -229,13 +223,7 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s width*0.6, height*7/8, ) } - case d2target.CrowsFeetOneRequired: - fallthrough - case d2target.CrowsFeetOneOptional: - fallthrough - case d2target.CrowsFeetManyRequired: - fallthrough - case d2target.CrowsFeetManyOptional: + case d2target.CfOne, d2target.CfMany, d2target.CfOneRequired, d2target.CfManyRequired: attrs := fmt.Sprintf(`class="connection" stroke="%s" stroke-width="%d" fill="white"`, connection.Stroke, connection.StrokeWidth) offset := 4.0 + (float64(connection.StrokeWidth) * 2.0) var modifier string From 2bff170c6f14b85c8367fc47677f27e4dc831fbb Mon Sep 17 00:00:00 2001 From: harryjrk Date: Sat, 31 Dec 2022 18:56:34 +0100 Subject: [PATCH 3/4] rename crow foot to shorter name, add tests --- d2renderers/d2svg/d2svg.go | 4 +- d2target/d2target.go | 32 +- e2etests/stable_test.go | 36 ++ .../crow_foot_arrowhead/dagre/board.exp.json | 520 ++++++++++++++++++ .../crow_foot_arrowhead/dagre/sketch.exp.svg | 31 ++ .../crow_foot_arrowhead/elk/board.exp.json | 484 ++++++++++++++++ .../crow_foot_arrowhead/elk/sketch.exp.svg | 31 ++ 7 files changed, 1120 insertions(+), 18 deletions(-) create mode 100644 e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json create mode 100644 e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg create mode 100644 e2etests/testdata/stable/crow_foot_arrowhead/elk/board.exp.json create mode 100644 e2etests/testdata/stable/crow_foot_arrowhead/elk/sketch.exp.svg diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index ba95620e6..ec3347d55 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -227,7 +227,7 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s attrs := fmt.Sprintf(`class="connection" stroke="%s" stroke-width="%d" fill="white"`, connection.Stroke, connection.StrokeWidth) offset := 4.0 + (float64(connection.StrokeWidth) * 2.0) var modifier string - if arrowhead == d2target.CrowsFeetManyRequired || arrowhead == d2target.CrowsFeetOneRequired { + if arrowhead == d2target.CfOneRequired || arrowhead == d2target.CfManyRequired { modifier = fmt.Sprintf(``, attrs, width, height/2.0, @@ -245,7 +245,7 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s if !isTarget { attrs = fmt.Sprintf(`%s transform="scale(-1) translate(-%f, -%f)"`, attrs, width, height) } - if arrowhead == d2target.CrowsFeetManyOptional || arrowhead == d2target.CrowsFeetManyRequired { + if arrowhead == d2target.CfMany || arrowhead == d2target.CfManyRequired { path = fmt.Sprintf(`%s`, attrs, modifier, offset+2.0, height/2.0, diff --git a/d2target/d2target.go b/d2target/d2target.go index 58fe683e3..b426adfd9 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -282,10 +282,10 @@ const ( LineArrowhead Arrowhead = "line" // Crows feet notation - CrowsFeetManyRequired Arrowhead = "crows-feet-many-required" - CrowsFeetManyOptional Arrowhead = "crows-feet-many-optional" - CrowsFeetOneRequired Arrowhead = "crows-feet-one-required" - CrowsFeetOneOptional Arrowhead = "crows-feet-one-optional" + CfOne Arrowhead = "cf-one" + CfMany Arrowhead = "cf-many" + CfOneRequired Arrowhead = "cf-one-required" + CfManyRequired Arrowhead = "cf-many-required" ) var Arrowheads = map[string]struct{}{ @@ -294,10 +294,10 @@ var Arrowheads = map[string]struct{}{ string(TriangleArrowhead): {}, string(DiamondArrowhead): {}, string(FilledDiamondArrowhead): {}, - string(CrowsFeetManyRequired): {}, - string(CrowsFeetManyOptional): {}, - string(CrowsFeetOneRequired): {}, - string(CrowsFeetOneOptional): {}, + string(CfOne): {}, + string(CfMany): {}, + string(CfOneRequired): {}, + string(CfManyRequired): {}, } func ToArrowhead(arrowheadType string, filled bool) Arrowhead { @@ -309,14 +309,14 @@ func ToArrowhead(arrowheadType string, filled bool) Arrowhead { return DiamondArrowhead case string(ArrowArrowhead): return ArrowArrowhead - case string(CrowsFeetManyRequired): - return CrowsFeetManyRequired - case string(CrowsFeetManyOptional): - return CrowsFeetManyOptional - case string(CrowsFeetOneRequired): - return CrowsFeetOneRequired - case string(CrowsFeetOneOptional): - return CrowsFeetOneOptional + case string(CfOne): + return CfOne + case string(CfMany): + return CfMany + case string(CfOneRequired): + return CfOneRequired + case string(CfManyRequired): + return CfManyRequired default: return TriangleArrowhead } diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 6590d295e..3e442c4a4 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1724,6 +1724,42 @@ code.height: 512 package.height: 512 `, }, + { + name: "crow_foot_arrowhead", + script: ` +a <-> b: { + source-arrowhead: { + shape: cf-many + } + target-arrowhead: { + shape: cf-many + } +} +c <--> d: { + source-arrowhead: { + shape: cf-many-required + } + target-arrowhead: { + shape: cf-many-required + } +} +g <--> h: { + source-arrowhead: { + shape: cf-one + } + target-arrowhead: { + shape: cf-one + } +} +e <--> f: { + source-arrowhead: { + shape: cf-one-required + } + target-arrowhead: { + shape: cf-one-required + } +}`, + }, } runa(t, tcs) diff --git a/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json new file mode 100644 index 000000000..afdf45d69 --- /dev/null +++ b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json @@ -0,0 +1,520 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "a", + "type": "", + "pos": { + "x": 0, + "y": 0 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "b", + "type": "", + "pos": { + "x": 0, + "y": 226 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "c", + "type": "", + "pos": { + "x": 174, + "y": 0 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "d", + "type": "", + "pos": { + "x": 173, + "y": 226 + }, + "width": 114, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "g", + "type": "", + "pos": { + "x": 347, + "y": 0 + }, + "width": 114, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "g", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "h", + "type": "", + "pos": { + "x": 347, + "y": 226 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "h", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "e", + "type": "", + "pos": { + "x": 521, + "y": 0 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "e", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "f", + "type": "", + "pos": { + "x": 522, + "y": 226 + }, + "width": 111, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "f", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 11, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(a <-> b)[0]", + "src": "a", + "srcArrow": "cf-many", + "srcLabel": "", + "dst": "b", + "dstArrow": "cf-many", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 56.5, + "y": 126 + }, + { + "x": 56.5, + "y": 166 + }, + { + "x": 56.5, + "y": 186 + }, + { + "x": 56.5, + "y": 226 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(c <-> d)[0]", + "src": "c", + "srcArrow": "cf-many-required", + "srcLabel": "", + "dst": "d", + "dstArrow": "cf-many-required", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 230, + "y": 126 + }, + { + "x": 230, + "y": 166 + }, + { + "x": 230, + "y": 186 + }, + { + "x": 230, + "y": 226 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(g <-> h)[0]", + "src": "g", + "srcArrow": "cf-one", + "srcLabel": "", + "dst": "h", + "dstArrow": "cf-one", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 403.5, + "y": 126 + }, + { + "x": 403.5, + "y": 166 + }, + { + "x": 403.5, + "y": 186 + }, + { + "x": 403.5, + "y": 226 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(e <-> f)[0]", + "src": "e", + "srcArrow": "cf-one-required", + "srcLabel": "", + "dst": "f", + "dstArrow": "cf-one-required", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 577, + "y": 126 + }, + { + "x": 577, + "y": 166 + }, + { + "x": 577, + "y": 186 + }, + { + "x": 577, + "y": 226 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg new file mode 100644 index 000000000..221316bd3 --- /dev/null +++ b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg @@ -0,0 +1,31 @@ + +abcdghef + + + \ No newline at end of file diff --git a/e2etests/testdata/stable/crow_foot_arrowhead/elk/board.exp.json b/e2etests/testdata/stable/crow_foot_arrowhead/elk/board.exp.json new file mode 100644 index 000000000..f4b918447 --- /dev/null +++ b/e2etests/testdata/stable/crow_foot_arrowhead/elk/board.exp.json @@ -0,0 +1,484 @@ +{ + "name": "", + "fontFamily": "SourceSansPro", + "shapes": [ + { + "id": "a", + "type": "", + "pos": { + "x": 12, + "y": 12 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "a", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "b", + "type": "", + "pos": { + "x": 12, + "y": 238 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "b", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "c", + "type": "", + "pos": { + "x": 145, + "y": 12 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "c", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "d", + "type": "", + "pos": { + "x": 145, + "y": 238 + }, + "width": 114, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "d", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "g", + "type": "", + "pos": { + "x": 278, + "y": 12 + }, + "width": 114, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "g", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 14, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "h", + "type": "", + "pos": { + "x": 279, + "y": 238 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "h", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "e", + "type": "", + "pos": { + "x": 412, + "y": 12 + }, + "width": 113, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "e", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 13, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, + { + "id": "f", + "type": "", + "pos": { + "x": 413, + "y": 238 + }, + "width": 111, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "f", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 11, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + } + ], + "connections": [ + { + "id": "(a <-> b)[0]", + "src": "a", + "srcArrow": "cf-many", + "srcLabel": "", + "dst": "b", + "dstArrow": "cf-many", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 68.5, + "y": 138 + }, + { + "x": 68.5, + "y": 238 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(c <-> d)[0]", + "src": "c", + "srcArrow": "cf-many-required", + "srcLabel": "", + "dst": "d", + "dstArrow": "cf-many-required", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 202, + "y": 138 + }, + { + "x": 202, + "y": 238 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(g <-> h)[0]", + "src": "g", + "srcArrow": "cf-one", + "srcLabel": "", + "dst": "h", + "dstArrow": "cf-one", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 335.5, + "y": 138 + }, + { + "x": 335.5, + "y": 238 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, + { + "id": "(e <-> f)[0]", + "src": "e", + "srcArrow": "cf-one-required", + "srcLabel": "", + "dst": "f", + "dstArrow": "cf-one-required", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "stroke": "#0D32B2", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 469, + "y": 138 + }, + { + "x": 469, + "y": 238 + } + ], + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + } + ] +} diff --git a/e2etests/testdata/stable/crow_foot_arrowhead/elk/sketch.exp.svg b/e2etests/testdata/stable/crow_foot_arrowhead/elk/sketch.exp.svg new file mode 100644 index 000000000..083eed231 --- /dev/null +++ b/e2etests/testdata/stable/crow_foot_arrowhead/elk/sketch.exp.svg @@ -0,0 +1,31 @@ + +abcdghef + + + \ No newline at end of file From e3047b6aba3783c96e173e02de4e5c105a90f9d1 Mon Sep 17 00:00:00 2001 From: harryjrk Date: Sun, 1 Jan 2023 11:31:45 +0100 Subject: [PATCH 4/4] fix curved connections issues --- d2renderers/d2svg/d2svg.go | 16 +- e2etests/stable_test.go | 6 +- .../crow_foot_arrowhead/dagre/board.exp.json | 156 ++++++++++++------ .../crow_foot_arrowhead/dagre/sketch.exp.svg | 6 +- .../crow_foot_arrowhead/elk/board.exp.json | 145 ++++++++++------ .../crow_foot_arrowhead/elk/sketch.exp.svg | 6 +- 6 files changed, 216 insertions(+), 119 deletions(-) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index ec3347d55..2f7f931f0 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -225,18 +225,16 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s } case d2target.CfOne, d2target.CfMany, d2target.CfOneRequired, d2target.CfManyRequired: attrs := fmt.Sprintf(`class="connection" stroke="%s" stroke-width="%d" fill="white"`, connection.Stroke, connection.StrokeWidth) - offset := 4.0 + (float64(connection.StrokeWidth) * 2.0) + offset := 4.0 + float64(connection.StrokeWidth*2) var modifier string if arrowhead == d2target.CfOneRequired || arrowhead == d2target.CfManyRequired { - modifier = fmt.Sprintf(``, + modifier = fmt.Sprintf(``, attrs, - width, height/2.0, - offset/2.0+1.0, height/2.0, offset, 0., offset, height, ) } else { - modifier = fmt.Sprintf(``, + modifier = fmt.Sprintf(``, attrs, offset/2.0+1.0, height/2.0, offset/2.0, @@ -246,9 +244,9 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s attrs = fmt.Sprintf(`%s transform="scale(-1) translate(-%f, -%f)"`, attrs, width, height) } if arrowhead == d2target.CfMany || arrowhead == d2target.CfManyRequired { - path = fmt.Sprintf(`%s`, + path = fmt.Sprintf(`%s`, attrs, modifier, - offset+2.0, height/2.0, + width-3.0, height/2.0, width+offset, height/2.0, offset+2.0, height/2.0, width+offset, 0., @@ -256,9 +254,9 @@ func arrowheadMarker(isTarget bool, id string, connection d2target.Connection) s width+offset, height, ) } else { - path = fmt.Sprintf(`%s`, + path = fmt.Sprintf(`%s`, attrs, modifier, - offset+2.0, height/2.0, + width-3.0, height/2.0, width+offset, height/2.0, offset*1.8, 0., offset*1.8, height, diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 3e442c4a4..a8acc138a 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1728,6 +1728,8 @@ package.height: 512 name: "crow_foot_arrowhead", script: ` a <-> b: { + style.stroke-width: 3 + style.stroke: "#20222a" source-arrowhead: { shape: cf-many } @@ -1735,7 +1737,9 @@ a <-> b: { shape: cf-many } } -c <--> d: { +c <--> d <-> f: { + style.stroke-width: 1 + style.stroke: "orange" source-arrowhead: { shape: cf-many-required } diff --git a/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json index afdf45d69..0784c5506 100644 --- a/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json +++ b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/board.exp.json @@ -162,6 +162,46 @@ "zIndex": 0, "level": 1 }, + { + "id": "f", + "type": "", + "pos": { + "x": 348, + "y": 452 + }, + "width": 111, + "height": 126, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "#F7F8FE", + "stroke": "#0D32B2", + "shadow": false, + "3d": false, + "multiple": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "f", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#0A0F25", + "italic": false, + "bold": true, + "underline": false, + "labelWidth": 11, + "labelHeight": 26, + "labelPosition": "INSIDE_MIDDLE_CENTER", + "zIndex": 0, + "level": 1 + }, { "id": "g", "type": "", @@ -246,8 +286,8 @@ "id": "e", "type": "", "pos": { - "x": 521, - "y": 0 + "x": 520, + "y": 226 }, "width": 113, "height": 126, @@ -281,46 +321,6 @@ "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 - }, - { - "id": "f", - "type": "", - "pos": { - "x": 522, - "y": 226 - }, - "width": 111, - "height": 126, - "opacity": 1, - "strokeDash": 0, - "strokeWidth": 2, - "borderRadius": 0, - "fill": "#F7F8FE", - "stroke": "#0D32B2", - "shadow": false, - "3d": false, - "multiple": false, - "tooltip": "", - "link": "", - "icon": null, - "iconPosition": "", - "blend": false, - "fields": null, - "methods": null, - "columns": null, - "label": "f", - "fontSize": 16, - "fontFamily": "DEFAULT", - "language": "", - "color": "#0A0F25", - "italic": false, - "bold": true, - "underline": false, - "labelWidth": 11, - "labelHeight": 26, - "labelPosition": "INSIDE_MIDDLE_CENTER", - "zIndex": 0, - "level": 1 } ], "connections": [ @@ -334,8 +334,8 @@ "dstLabel": "", "opacity": 1, "strokeDash": 0, - "strokeWidth": 2, - "stroke": "#0D32B2", + "strokeWidth": 3, + "stroke": "#20222a", "label": "", "fontSize": 16, "fontFamily": "DEFAULT", @@ -382,8 +382,8 @@ "dstLabel": "", "opacity": 1, "strokeDash": 0, - "strokeWidth": 2, - "stroke": "#0D32B2", + "strokeWidth": 1, + "stroke": "orange", "label": "", "fontSize": 16, "fontFamily": "DEFAULT", @@ -420,6 +420,54 @@ "icon": null, "zIndex": 0 }, + { + "id": "(d <-> f)[0]", + "src": "d", + "srcArrow": "cf-many-required", + "srcLabel": "", + "dst": "f", + "dstArrow": "cf-many-required", + "dstLabel": "", + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 1, + "stroke": "orange", + "label": "", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "", + "color": "#676C7E", + "italic": true, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0, + "labelPosition": "", + "labelPercentage": 0, + "route": [ + { + "x": 230, + "y": 352 + }, + { + "x": 230, + "y": 392 + }, + { + "x": 253.55, + "y": 417.36017316017313 + }, + { + "x": 347.75, + "y": 478.8008658008658 + } + ], + "isCurve": true, + "animated": false, + "tooltip": "", + "icon": null, + "zIndex": 0 + }, { "id": "(g <-> h)[0]", "src": "g", @@ -494,20 +542,20 @@ "labelPercentage": 0, "route": [ { - "x": 577, - "y": 126 + "x": 576.5, + "y": 352 }, { - "x": 577, - "y": 166 + "x": 576.5, + "y": 392 }, { - "x": 577, - "y": 186 + "x": 552.9, + "y": 417.4 }, { - "x": 577, - "y": 226 + "x": 458.5, + "y": 479 } ], "isCurve": true, diff --git a/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg index 221316bd3..cc439add7 100644 --- a/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/crow_foot_arrowhead/dagre/sketch.exp.svg @@ -2,7 +2,7 @@ abcdfghe + abcdghef - +abcdfghe +