From f6caac01276f81b12bcfcf50c4602b413a5ee0f9 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Fri, 27 Jan 2023 10:57:55 -0800 Subject: [PATCH] use label height for padding shapes with icons --- d2graph/d2graph.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 334455f1a..2ce350996 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1163,10 +1163,12 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler } } - // give shapes with icons extra padding + // give shapes with icons extra padding to fit their label if obj.Attributes.Icon != nil { - paddingX += 20 - paddingY += 20 + labelHeight := float64(obj.LabelDimensions.Height) + // Evenly pad enough to fit label above icon + paddingX += labelHeight + paddingY += labelHeight } switch shapeType { case shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE, shape.IMAGE_TYPE: