From efcebb355272eda15ceaacc25d4dc57252851a0a Mon Sep 17 00:00:00 2001 From: donglixiaoche Date: Wed, 8 Mar 2023 16:46:32 +0800 Subject: [PATCH] fix: border-radius for only class and table header --- d2renderers/d2svg/class.go | 11 +++++++++-- d2renderers/d2svg/table.go | 11 ++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/d2renderers/d2svg/class.go b/d2renderers/d2svg/class.go index 82be116a8..01469a037 100644 --- a/d2renderers/d2svg/class.go +++ b/d2renderers/d2svg/class.go @@ -119,8 +119,15 @@ func drawClass(writer io.Writer, targetShape d2target.Shape) { } lineEl := d2themes.NewThemableElement("line") - lineEl.X1, lineEl.Y1 = rowBox.TopLeft.X, rowBox.TopLeft.Y - lineEl.X2, lineEl.Y2 = rowBox.TopLeft.X+rowBox.Width, rowBox.TopLeft.Y + + if targetShape.BorderRadius != 0 && len(targetShape.Methods) == 0 { + lineEl.X1, lineEl.Y1 = rowBox.TopLeft.X+float64(targetShape.BorderRadius), rowBox.TopLeft.Y + lineEl.X2, lineEl.Y2 = rowBox.TopLeft.X+rowBox.Width-float64(targetShape.BorderRadius), rowBox.TopLeft.Y + } else { + lineEl.X1, lineEl.Y1 = rowBox.TopLeft.X, rowBox.TopLeft.Y + lineEl.X2, lineEl.Y2 = rowBox.TopLeft.X+rowBox.Width, rowBox.TopLeft.Y + } + lineEl.Stroke = targetShape.Fill lineEl.Style = "stroke-width:1" fmt.Fprint(writer, lineEl.Render()) diff --git a/d2renderers/d2svg/table.go b/d2renderers/d2svg/table.go index 1de55d4aa..5bebab10f 100644 --- a/d2renderers/d2svg/table.go +++ b/d2renderers/d2svg/table.go @@ -25,7 +25,16 @@ func tableHeaderBorderRadius(shape d2target.Shape) string { out += fmt.Sprintf(`L %f %f L %f %f `, box.TopLeft.X+box.Width-float64(shape.BorderRadius), box.TopLeft.Y, topX-float64(shape.BorderRadius), topY) out += fmt.Sprintf(`S %f %f %f %f `, topX, topY, topX, topY+float64(shape.BorderRadius)) - out += fmt.Sprintf(`L %f %f L %f %f `, topX, topY+box.Height, box.TopLeft.X, box.TopLeft.Y+box.Height) + out += fmt.Sprintf(`L %f %f `, topX, topY+box.Height-float64(shape.BorderRadius)) + + if len(shape.Columns) != 0 { + out += fmt.Sprintf(`L %f %f L %f %f`, topX, topY+box.Height, box.TopLeft.X, box.TopLeft.Y+box.Height) + } else { + out += fmt.Sprintf(`S %f % f %f %f `, topX, topY+box.Height, topX-float64(shape.BorderRadius), topY+box.Height) + out += fmt.Sprintf(`L %f %f `, box.TopLeft.X+float64(shape.BorderRadius), box.TopLeft.Y+box.Height) + out += fmt.Sprintf(`S %f %f %f %f`, box.TopLeft.X, box.TopLeft.Y+box.Height, box.TopLeft.X, box.TopLeft.Y+box.Height-float64(shape.BorderRadius)) + out += fmt.Sprintf(`L %f %f`, box.TopLeft.X, box.TopLeft.Y+float64(shape.BorderRadius)) + } out += fmt.Sprintf(`Z %f %f" `, box.TopLeft.X, box.TopLeft.Y) return out + `fill="none" /> ` }