From cfdf59b6b6b1c2b9b6948c40a577998ff193e123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Mon, 16 Jan 2023 15:15:01 +0100 Subject: [PATCH] arrowheads respect background color in sketch mode --- d2renderers/d2sketch/sketch.go | 17 ++++++++++------- d2renderers/d2svg/d2svg.go | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go index 9f450f0ed..5157f08a5 100644 --- a/d2renderers/d2sketch/sketch.go +++ b/d2renderers/d2sketch/sketch.go @@ -572,7 +572,7 @@ func extractPathData(roughPaths []roughPath) ([]string, error) { return paths, nil } -func ArrowheadJS(r *Runner, arrowhead d2target.Arrowhead, stroke string, strokeWidth int) (arrowJS, extraJS string) { +func ArrowheadJS(r *Runner, bgColor string, arrowhead d2target.Arrowhead, stroke string, strokeWidth int) (arrowJS, extraJS string) { // Note: selected each seed that looks the good for consistent renders switch arrowhead { case d2target.ArrowArrowhead: @@ -592,10 +592,11 @@ func ArrowheadJS(r *Runner, arrowhead d2target.Arrowhead, stroke string, strokeW ) case d2target.DiamondArrowhead: arrowJS = fmt.Sprintf( - `node = rc.polygon(%s, { strokeWidth: %d, stroke: "%s", fill: "white", fillStyle: "solid", seed: 1 })`, + `node = rc.polygon(%s, { strokeWidth: %d, stroke: "%s", fill: "%s", fillStyle: "solid", seed: 1 })`, `[[-20, 0], [-10, 5], [0, 0], [-10, -5], [-20, 0]]`, strokeWidth, stroke, + bgColor, ) case d2target.FilledDiamondArrowhead: arrowJS = fmt.Sprintf( @@ -623,9 +624,10 @@ func ArrowheadJS(r *Runner, arrowhead d2target.Arrowhead, stroke string, strokeW stroke, ) extraJS = fmt.Sprintf( - `node = rc.circle(-20, 0, 8, { strokeWidth: %d, stroke: "%s", fill: "white", fillStyle: "solid", fillWeight: 1, seed: 4 })`, + `node = rc.circle(-20, 0, 8, { strokeWidth: %d, stroke: "%s", fill: "%s", fillStyle: "solid", fillWeight: 1, seed: 4 })`, strokeWidth, stroke, + bgColor, ) case d2target.CfOneRequired: arrowJS = fmt.Sprintf( @@ -644,19 +646,20 @@ func ArrowheadJS(r *Runner, arrowhead d2target.Arrowhead, stroke string, strokeW stroke, ) extraJS = fmt.Sprintf( - `node = rc.circle(-20, 0, 8, { strokeWidth: %d, stroke: "%s", fill: "white", fillStyle: "solid", fillWeight: 1, seed: 5 })`, + `node = rc.circle(-20, 0, 8, { strokeWidth: %d, stroke: "%s", fill: "%s", fillStyle: "solid", fillWeight: 1, seed: 5 })`, strokeWidth, stroke, + bgColor, ) } return } -func Arrowheads(r *Runner, connection d2target.Connection, srcAdj, dstAdj *geo.Point) (string, error) { +func Arrowheads(r *Runner, bgColor string, connection d2target.Connection, srcAdj, dstAdj *geo.Point) (string, error) { arrowPaths := []string{} if connection.SrcArrow != d2target.NoArrowhead { - arrowJS, extraJS := ArrowheadJS(r, connection.SrcArrow, connection.Stroke, connection.StrokeWidth) + arrowJS, extraJS := ArrowheadJS(r, bgColor, connection.SrcArrow, connection.Stroke, connection.StrokeWidth) if arrowJS == "" { return "", nil } @@ -694,7 +697,7 @@ func Arrowheads(r *Runner, connection d2target.Connection, srcAdj, dstAdj *geo.P } if connection.DstArrow != d2target.NoArrowhead { - arrowJS, extraJS := ArrowheadJS(r, connection.DstArrow, connection.Stroke, connection.StrokeWidth) + arrowJS, extraJS := ArrowheadJS(r, bgColor, connection.DstArrow, connection.Stroke, connection.StrokeWidth) if arrowJS == "" { return "", nil } diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 5a0c3bc37..ddb4b458a 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -489,7 +489,7 @@ func drawConnection(writer io.Writer, bgColor string, fgColor string, labelMaskI fmt.Fprint(writer, out) // render sketch arrowheads separately - arrowPaths, err := d2sketch.Arrowheads(sketchRunner, connection, srcAdj, dstAdj) + arrowPaths, err := d2sketch.Arrowheads(sketchRunner, bgColor, connection, srcAdj, dstAdj) if err != nil { return "", err } @@ -994,7 +994,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske addAppendixItems(writer, targetShape) - fmt.Fprintf(writer, closingTag) + fmt.Fprint(writer, closingTag) return labelMask, nil }