diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index e560946f9..c3bf3191f 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -20,6 +20,8 @@ import ( "oss.terrastruct.com/d2/lib/textmeasure" ) +const INNER_LABEL_PADDING int = 5 + // TODO: Refactor with a light abstract layer on top of AST implementing scenarios, // variables, imports, substitutions and then a final set of structures representing // a final graph. @@ -865,7 +867,7 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler } var dims *d2target.TextDimensions - var innerLabelPadding = 5 + var innerLabelPadding = INNER_LABEL_PADDING if obj.Attributes.Shape.Value == d2target.ShapeText { if obj.Attributes.Language == "latex" { width, height, err := d2latex.Measure(obj.Text().Text) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 7e429e9f5..50ab5e919 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -22,6 +22,7 @@ import ( "oss.terrastruct.com/util-go/go2" + "oss.terrastruct.com/d2/d2graph" "oss.terrastruct.com/d2/d2renderers/d2fonts" "oss.terrastruct.com/d2/d2renderers/d2latex" "oss.terrastruct.com/d2/d2target" @@ -767,7 +768,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) (labelMask string, fontColor = targetShape.Color } textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", targetShape.FontSize, fontColor) - x := labelTL.X + float64(targetShape.LabelWidth)/2 + x := labelTL.X + float64(targetShape.LabelWidth)/2. // text is vertically positioned at its baseline which is at labelTL+FontSize y := labelTL.Y + float64(targetShape.FontSize) fmt.Fprintf(writer, `%s`, @@ -776,7 +777,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) (labelMask string, textStyle, renderText(targetShape.Label, x, float64(targetShape.LabelHeight)), ) - labelMask = makeLabelMask(labelTL, targetShape.LabelWidth, targetShape.LabelHeight) + labelMask = makeLabelMask(labelTL, targetShape.LabelWidth, targetShape.LabelHeight-d2graph.INNER_LABEL_PADDING) } } fmt.Fprintf(writer, ``) diff --git a/e2etests/testdata/sanity/1_to_2/dagre/sketch.exp.svg b/e2etests/testdata/sanity/1_to_2/dagre/sketch.exp.svg index 0dd00fb61..a27061d62 100644 --- a/e2etests/testdata/sanity/1_to_2/dagre/sketch.exp.svg +++ b/e2etests/testdata/sanity/1_to_2/dagre/sketch.exp.svg @@ -16,9 +16,9 @@ width="486" height="552" viewBox="-100 -100 486 552">abc - - - + + + abc - - - + + + ab - - + + ab - - + + acbd - - - - + + + + acbd - - - - + + + + ab hello - - + + ab hello - - + + rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + cba * - - - + + + cba * - - - + + + ab To err is human, to moo bovine1* - - + + ab To err is human, to moo bovine1* - - + + abcdefghijklmno - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + abcdefghijklmno - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + aaadddeeebbbccc111 222 - - - - - + + + + + aaadddeeebbbccc111 222 - - - - - + + + + + abcd - - - - + + + + abcd - - - - + + + + abc - - - + + + abc - - - + + + acfbdhg - - - - - - - + + + + + + + acfbdhg - - - - - - - + + + + + + + agdfbhec - - - - - - - - + + + + + + + + agdfbhec - - - - - - - - + + + + + + + + abcdefghijklmnopq - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + abcdefghijklmnopq - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + bacde21345abcde - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + bacde21345abcde - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + alphabeta gamma - - + + alphabeta gamma - - + + size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/font_sizes/elk/sketch.exp.svg b/e2etests/testdata/stable/font_sizes/elk/sketch.exp.svg index 1c3944a12..438c51546 100644 --- a/e2etests/testdata/stable/font_sizes/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/font_sizes/elk/sketch.exp.svg @@ -16,18 +16,18 @@ width="1965" height="793" viewBox="-88 -88 1965 793">size XSsize Ssize Msize Lsize XLsize XXLsize XXXLcustom 8custom 12custom 18custom 21custom 64 custom 10custom 15custom 48 - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/giant_markdown_test/dagre/sketch.exp.svg b/e2etests/testdata/stable/giant_markdown_test/dagre/sketch.exp.svg index 6eabdf50e..70857d5dc 100644 --- a/e2etests/testdata/stable/giant_markdown_test/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/giant_markdown_test/dagre/sketch.exp.svg @@ -1029,8 +1029,8 @@ title for the link, surrounded in quotes. For example:

normal paragraph. For example:

ab - - + + hello - + hello - + ab - - + + ab - - + + aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/investigate/elk/sketch.exp.svg b/e2etests/testdata/stable/investigate/elk/sketch.exp.svg index 2368bb846..da9e66679 100644 --- a/e2etests/testdata/stable/investigate/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/investigate/elk/sketch.exp.svg @@ -16,37 +16,37 @@ width="860" height="4868" viewBox="-82 -88 860 4868">aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac 123456 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/large_arch/dagre/sketch.exp.svg b/e2etests/testdata/stable/large_arch/dagre/sketch.exp.svg index f832324d7..95f9a3c5d 100644 --- a/e2etests/testdata/stable/large_arch/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/large_arch/dagre/sketch.exp.svg @@ -16,39 +16,39 @@ width="3244" height="1780" viewBox="-100 -100 3244 1780">abcdefghiqrjmnoszaabbeeffggklptuwxyccddv - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + abcdefghiqrjmnoszaabbeeffggklptuwxyccddv - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + mixed togethersugarsolution we get - - - + + + mixed togethersugarsolution we get - - - + + +

Markdown: Syntax

ab - - + +

Markdown: Syntax

ab - - + +

code

ab - - + +

code

ab - - + + thisgoesmultiple lines - + thisgoesmultiple lines - + abcdefghijklmnopqrstuvw - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + abcdefghijklmnopqrstuvw - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + abcdefghijklmnopqrstu - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + abcdefghijklmnopqrstu - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + Foo Baz12hello - - - - + + + + Foo Baz12hello - - - - + + + + acdefgbh - - - - - - - - + + + + + + + + acdefgbh - - - - - - - - + + + + + + + + topabcbottomstartend - - - - - - - + + + + + + + topabcbottomstartend - - - - - - - + + + + + + + xyz hello - - - + + + xyz hello - - - + + + abcdggggroup 1group bchoonested guy lalaeyokayokaywhat would arnold saythis note - - - - - - - - - + + + + + + + + + - - + + abcdggggroup 1group bchoonested guy lalaeyokayokaywhat would arnold saythis note - - - - - - - - - + + + + + + + + + - - + + scoreritemResponseitemessayRubricconceptitemOutcome - - - - - - + + + + + + scoreritemResponseitemessayRubricconceptitemOutcome - - - - - - + + + + + + abcd okayexplanationanother explanationSome one who believes imaginary things appear right before your i's.The earth is like a tiny grain of sand, only much, much heavier - - - - + + + + - - - - + + + + abcd okayexplanationanother explanationSome one who believes imaginary things appear right before your i's.The earth is like a tiny grain of sand, only much, much heavier - - - - + + + + - - - - + + + + How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutonly if root is not sequence 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVGmeasurements also take place - - - - - - - - - - - + + + + + + + + + + + @@ -40,7 +40,7 @@ width="2374" height="2488" viewBox="-100 -100 2374 2488">How this is renderedCLId2astd2compilerd2layoutd2exporterd2themesd2rendererd2sequencelayoutd2dagrelayoutonly if root is not sequence 'How this is rendered: {...}'tokenized ASTcompile ASTobjects and edgesrun layout enginesrun engine on shape: sequence_diagram, temporarily removerun core engine on rest add back in sequence diagramsdiagram with correct positions and dimensionsexport diagram with chosen theme and rendererget theme stylesrender to SVGresulting SVGmeasurements also take place - - - - - - - - - - - + + + + + + + + + + + @@ -40,7 +40,7 @@ width="2374" height="2488" viewBox="-88 -88 2374 2488">ab a self edge herebetween actorsto descendantto deeper descendantto parentactor - - + + diff --git a/e2etests/testdata/stable/sequence_diagram_self_edges/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_self_edges/elk/sketch.exp.svg index ef3021650..5a25df531 100644 --- a/e2etests/testdata/stable/sequence_diagram_self_edges/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_self_edges/elk/sketch.exp.svg @@ -16,8 +16,8 @@ width="666" height="1366" viewBox="-100 -50 666 1366">ab a self edge herebetween actorsto descendantto deeper descendantto parentactor - - + + diff --git a/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg index a97665af9..bae455c2f 100644 --- a/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_simple/dagre/sketch.exp.svg @@ -16,11 +16,11 @@ width="1285" height="1868" viewBox="-100 -50 1285 1868">AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response - - - - - + + + + + diff --git a/e2etests/testdata/stable/sequence_diagram_simple/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_simple/elk/sketch.exp.svg index a97665af9..bae455c2f 100644 --- a/e2etests/testdata/stable/sequence_diagram_simple/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_simple/elk/sketch.exp.svg @@ -16,11 +16,11 @@ width="1285" height="1868" viewBox="-100 -50 1285 1868">AlicelinebreakerBobdbqueueanoddservicewithanameinmultiple lines Authentication Requestmake request for something that is quite far away and requires a really long label to take all the space between the objectsvalidate credentialsAuthentication ResponseAnother authentication Requestdo it later storedAnother authentication Response - - - - - + + + + + diff --git a/e2etests/testdata/stable/sequence_diagram_span/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_span/dagre/sketch.exp.svg index e563e1df0..a350672a8 100644 --- a/e2etests/testdata/stable/sequence_diagram_span/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_span/dagre/sketch.exp.svg @@ -16,12 +16,12 @@ width="1593" height="2146" viewBox="-100 -50 1593 2146">scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - + + + + + + diff --git a/e2etests/testdata/stable/sequence_diagram_span/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_span/elk/sketch.exp.svg index e563e1df0..a350672a8 100644 --- a/e2etests/testdata/stable/sequence_diagram_span/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_span/elk/sketch.exp.svg @@ -16,12 +16,12 @@ width="1593" height="2146" viewBox="-100 -50 1593 2146">scoreritemResponseitemessayRubricconceptitemOutcome getItem() itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - + + + + + + diff --git a/e2etests/testdata/stable/sequence_diagrams/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagrams/dagre/sketch.exp.svg index 3ac4ca8e0..0c9c21fea 100644 --- a/e2etests/testdata/stable/sequence_diagrams/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagrams/dagre/sketch.exp.svg @@ -16,31 +16,31 @@ width="3244" height="4173" viewBox="-100 -100 3244 4173">a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg index 7a94dcd5f..1155c8d50 100644 --- a/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagrams/elk/sketch.exp.svg @@ -16,31 +16,31 @@ width="3166" height="4293" viewBox="-88 -88 3166 4293">a_shapea_sequenceanotherfinallysequencesequencesequencescoreritemResponseitemessayRubricconceptitemOutcomescorerconceptessayRubricitemitemOutcomeitemResponsescoreritemResponseitemessayRubricconceptitemOutcome getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts)getItem()itemgetRubric()rubricapplyTo(essayResp)match(essayResponse)scorenewgetNormalMinimum()getNormalMaximum()setScore(score)setFeedback(missingConcepts) - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/e2etests/testdata/stable/square_3d/dagre/sketch.exp.svg b/e2etests/testdata/stable/square_3d/dagre/sketch.exp.svg index f66617f27..9d6be448d 100644 --- a/e2etests/testdata/stable/square_3d/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/square_3d/dagre/sketch.exp.svg @@ -20,8 +20,8 @@ width="371" height="580" viewBox="-100 -100 371 580">acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTND - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTND - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + containerfirstsecond 1->2c->2 - - - + + + containerfirstsecond 1->2c->2 - - - + + + ninety ninesixty fourthirty twosixteeneight - - - - - + + + + + ninety ninesixty fourthirty twosixteeneight - - - - - + + + + + eightsixteenthirty twosixty fourninety nine twelvetwenty fourforty eighteighty one - - - - - + + + + + diff --git a/e2etests/testdata/todo/font_sizes_large/elk/sketch.exp.svg b/e2etests/testdata/todo/font_sizes_large/elk/sketch.exp.svg index 8e20cfbee..43821218a 100644 --- a/e2etests/testdata/todo/font_sizes_large/elk/sketch.exp.svg +++ b/e2etests/testdata/todo/font_sizes_large/elk/sketch.exp.svg @@ -16,11 +16,11 @@ width="789" height="2014" viewBox="-39 -88 789 2014">eightsixteenthirty twosixty fourninety nine twelvetwenty fourforty eighteighty one - - - - - + + + + + diff --git a/e2etests/testdata/todo/tall_edge_label/dagre/sketch.exp.svg b/e2etests/testdata/todo/tall_edge_label/dagre/sketch.exp.svg index ba3e7b43e..2a59cfc02 100644 --- a/e2etests/testdata/todo/tall_edge_label/dagre/sketch.exp.svg +++ b/e2etests/testdata/todo/tall_edge_label/dagre/sketch.exp.svg @@ -16,8 +16,8 @@ width="313" height="552" viewBox="-100 -100 313 552">ab Thereoncewasaverytalledgelabel - - + + ab Thereoncewasaverytalledgelabel - - + +