From 32b6bcc5d78256e0d10b407783290077c468a89a Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Fri, 25 Nov 2022 19:31:54 -0800 Subject: [PATCH 1/2] wrap shapes and connections in tag --- d2renderers/d2svg/d2svg.go | 8 +++++-- .../sanity/1_to_2/dagre/sketch.exp.svg | 2 +- .../testdata/sanity/1_to_2/elk/sketch.exp.svg | 2 +- .../sanity/basic/dagre/sketch.exp.svg | 2 +- .../testdata/sanity/basic/elk/sketch.exp.svg | 2 +- .../child_to_child/dagre/sketch.exp.svg | 2 +- .../sanity/child_to_child/elk/sketch.exp.svg | 2 +- .../connection_label/dagre/sketch.exp.svg | 4 ++-- .../connection_label/elk/sketch.exp.svg | 4 ++-- .../stable/all_shapes/dagre/sketch.exp.svg | 2 +- .../stable/all_shapes/elk/sketch.exp.svg | 2 +- .../all_shapes_multiple/dagre/sketch.exp.svg | 2 +- .../all_shapes_multiple/elk/sketch.exp.svg | 2 +- .../all_shapes_shadow/dagre/sketch.exp.svg | 2 +- .../all_shapes_shadow/elk/sketch.exp.svg | 2 +- .../arrowhead_adjustment/dagre/sketch.exp.svg | 2 +- .../arrowhead_adjustment/elk/sketch.exp.svg | 2 +- .../arrowhead_labels/dagre/sketch.exp.svg | 4 ++-- .../arrowhead_labels/elk/sketch.exp.svg | 4 ++-- .../stable/binary_tree/dagre/sketch.exp.svg | 2 +- .../stable/binary_tree/elk/sketch.exp.svg | 2 +- .../stable/chaos1/dagre/sketch.exp.svg | 6 ++--- .../testdata/stable/chaos1/elk/sketch.exp.svg | 6 ++--- .../stable/chaos2/dagre/sketch.exp.svg | 24 +++++++++---------- .../testdata/stable/chaos2/elk/sketch.exp.svg | 24 +++++++++---------- .../child_parent_edges/dagre/sketch.exp.svg | 2 +- .../child_parent_edges/elk/sketch.exp.svg | 2 +- .../circular_dependency/dagre/sketch.exp.svg | 2 +- .../circular_dependency/elk/sketch.exp.svg | 2 +- .../stable/class/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/class/elk/sketch.exp.svg | 4 ++-- .../stable/code_snippet/dagre/sketch.exp.svg | 4 ++-- .../stable/code_snippet/elk/sketch.exp.svg | 4 ++-- .../connected_container/dagre/sketch.exp.svg | 2 +- .../connected_container/elk/sketch.exp.svg | 2 +- .../container_edges/dagre/sketch.exp.svg | 2 +- .../stable/container_edges/elk/sketch.exp.svg | 2 +- .../stable/dense/dagre/sketch.exp.svg | 2 +- .../testdata/stable/dense/elk/sketch.exp.svg | 2 +- .../different_subgraphs/dagre/sketch.exp.svg | 2 +- .../different_subgraphs/elk/sketch.exp.svg | 2 +- .../stable/font_colors/dagre/sketch.exp.svg | 4 ++-- .../stable/font_colors/elk/sketch.exp.svg | 4 ++-- .../giant_markdown_test/dagre/sketch.exp.svg | 4 ++-- .../giant_markdown_test/elk/sketch.exp.svg | 4 ++-- .../testdata/stable/hr/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/hr/elk/sketch.exp.svg | 4 ++-- .../stable/images/dagre/sketch.exp.svg | 2 +- .../testdata/stable/images/elk/sketch.exp.svg | 2 +- .../stable/investigate/dagre/sketch.exp.svg | 14 +++++------ .../stable/investigate/elk/sketch.exp.svg | 14 +++++------ .../stable/large_arch/dagre/sketch.exp.svg | 2 +- .../stable/large_arch/elk/sketch.exp.svg | 2 +- .../testdata/stable/li1/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/li1/elk/sketch.exp.svg | 4 ++-- .../testdata/stable/li2/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/li2/elk/sketch.exp.svg | 4 ++-- .../testdata/stable/li3/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/li3/elk/sketch.exp.svg | 4 ++-- .../testdata/stable/li4/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/li4/elk/sketch.exp.svg | 4 ++-- .../stable/lone_h1/dagre/sketch.exp.svg | 4 ++-- .../stable/lone_h1/elk/sketch.exp.svg | 4 ++-- .../stable/markdown/dagre/sketch.exp.svg | 4 ++-- .../stable/markdown/elk/sketch.exp.svg | 4 ++-- .../md_2space_newline/dagre/sketch.exp.svg | 4 ++-- .../md_2space_newline/elk/sketch.exp.svg | 4 ++-- .../md_backslash_newline/dagre/sketch.exp.svg | 4 ++-- .../md_backslash_newline/elk/sketch.exp.svg | 4 ++-- .../md_code_block_fenced/dagre/sketch.exp.svg | 4 ++-- .../md_code_block_fenced/elk/sketch.exp.svg | 4 ++-- .../dagre/sketch.exp.svg | 4 ++-- .../md_code_block_indented/elk/sketch.exp.svg | 4 ++-- .../md_code_inline/dagre/sketch.exp.svg | 4 ++-- .../stable/md_code_inline/elk/sketch.exp.svg | 4 ++-- .../multiline_text/dagre/sketch.exp.svg | 2 +- .../stable/multiline_text/elk/sketch.exp.svg | 2 +- .../multiple_trees/dagre/sketch.exp.svg | 2 +- .../stable/multiple_trees/elk/sketch.exp.svg | 2 +- .../stable/n22_e32/dagre/sketch.exp.svg | 2 +- .../stable/n22_e32/elk/sketch.exp.svg | 2 +- .../one_container_loop/dagre/sketch.exp.svg | 2 +- .../one_container_loop/elk/sketch.exp.svg | 2 +- .../dagre/sketch.exp.svg | 2 +- .../elk/sketch.exp.svg | 2 +- .../testdata/stable/p/dagre/sketch.exp.svg | 4 ++-- e2etests/testdata/stable/p/elk/sketch.exp.svg | 4 ++-- .../testdata/stable/pre/dagre/sketch.exp.svg | 4 ++-- .../testdata/stable/pre/elk/sketch.exp.svg | 4 ++-- .../stable/sql_tables/dagre/sketch.exp.svg | 10 ++++---- .../stable/sql_tables/elk/sketch.exp.svg | 10 ++++---- .../stable/square_3d/dagre/sketch.exp.svg | 2 +- .../stable/square_3d/elk/sketch.exp.svg | 2 +- .../dagre/sketch.exp.svg | 2 +- .../elk/sketch.exp.svg | 2 +- .../stable/stylish/dagre/sketch.exp.svg | 2 +- .../stable/stylish/elk/sketch.exp.svg | 2 +- .../stable/us_map/dagre/sketch.exp.svg | 2 +- .../testdata/stable/us_map/elk/sketch.exp.svg | 2 +- .../container_child_edge/dagre/sketch.exp.svg | 6 ++--- .../container_child_edge/elk/sketch.exp.svg | 6 ++--- 101 files changed, 196 insertions(+), 192 deletions(-) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index ba1459c9e..1349183fa 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -354,6 +354,7 @@ func labelMask(id string, connection d2target.Connection, labelTL, tl, br *geo.P } func drawConnection(writer io.Writer, connection d2target.Connection, markers map[string]struct{}, idToShape map[string]d2target.Shape) { + fmt.Fprintf(writer, ``, escapeText(connection.ID)) var markerStart string if connection.SrcArrow != d2target.NoArrowhead { id := arrowheadMarkerID(false, connection) @@ -471,6 +472,7 @@ func drawConnection(writer io.Writer, connection d2target.Connection, markers ma } fmt.Fprint(writer, renderArrowheadLabel(connection, connection.DstLabel, position, size, size)) } + fmt.Fprintf(writer, ``) } func renderArrowheadLabel(connection d2target.Connection, text string, position, width, height float64) string { @@ -507,6 +509,7 @@ func defineShadowFilter(writer io.Writer) { } func drawShape(writer io.Writer, targetShape d2target.Shape) error { + fmt.Fprintf(writer, ``, escapeText(targetShape.ID)) tl := geo.NewPoint(float64(targetShape.Pos.X), float64(targetShape.Pos.Y)) width := float64(targetShape.Width) height := float64(targetShape.Height) @@ -537,11 +540,11 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error { switch targetShape.Type { case d2target.ShapeClass: drawClass(writer, targetShape) - fmt.Fprintf(writer, ``) + fmt.Fprintf(writer, ``) return nil case d2target.ShapeSQLTable: drawTable(writer, targetShape) - fmt.Fprintf(writer, ``) + fmt.Fprintf(writer, ``) return nil case d2target.ShapeOval: if targetShape.Multiple { @@ -726,6 +729,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error { ) } } + fmt.Fprintf(writer, ``) return nil } 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 3d41cc01a..83b048166 100644 --- a/e2etests/testdata/sanity/1_to_2/dagre/sketch.exp.svg +++ b/e2etests/testdata/sanity/1_to_2/dagre/sketch.exp.svg @@ -14,7 +14,7 @@ width="486" height="552" viewBox="-100 -100 486 552">abc abc abc abc ab ab ab ab acbd acbd acbd acbd ab +ab -helloab +ab -hellorectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud rectanglesquarepageparallelogramdocumentcylinderqueuepackagestepcalloutstored_datapersondiamondovalcirclehexagoncloud cba * cba * cba * cba * ab +ab -To err is human, to moo bovine1*ab +ab -To err is human, to moo bovine1*abcdefghijklmno abcdefghijklmno abcdefghijklmno abcdefghijklmno aaadddeeebbbccc +aaadddeeebbbccc -111 +111 -222aaadddeeebbbccc +aaadddeeebbbccc -111 +111 -222aabbllmm

nn

-
oocciikkdd

gg

-
hhjj

ee

-
ff +aabbllmm

nn

+
oocciikkdd

gg

+
hhjj

ee

+
ff -11 +11 -22 +22 -33 +33 -44 +44 -55 +55 -66 +66 -77 +77 -88aabbllmm

nn

-
oocciikkdd

gg

-
hhjj

ee

-
ff +aabbllmm

nn

+
oocciikkdd

gg

+
hhjj

ee

+
ff -11 +11 -22 +22 -33 +33 -44 +44 -55 +55 -66 +66 -77 +77 -88abcd abcd abcd abcd abc abc abc abc BatchManager- +BatchManager- num int- timeout @@ -26,7 +26,7 @@ width="539" height="568" viewBox="-100 -100 539 568">BatchManager- +BatchManager- num int- timeout @@ -26,7 +26,7 @@ width="539" height="568" viewBox="-88 -88 539 568">// RegisterHash registers a function that returns a new instance of the given +// RegisterHash registers a function that returns a new instance of the given // hash function. This is intended to be called from the init function in // packages that implement hash functions. func RegisterHash(h Hash, f func() hash.Hash) { @@ -22,7 +22,7 @@ width="955" height="818" viewBox="-100 -100 955 818">// RegisterHash registers a function that returns a new instance of the given +// RegisterHash registers a function that returns a new instance of the given // hash function. This is intended to be called from the init function in // packages that implement hash functions. func RegisterHash(h Hash, f func() hash.Hash) { @@ -22,7 +22,7 @@ width="1382" height="366" viewBox="-88 -88 1382 366">acfbdhg acfbdhg acfbdhg acfbdhg agdfbhec agdfbhec agdfbhec agdfbhec abcdefghijklmnopq abcdefghijklmnopq abcdefghijklmnopq abcdefghijklmnopq finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot alphabeta +alphabeta -gammaalphabeta +alphabeta -gamma

Markdown: Syntax

+

Markdown: Syntax

  • Overview
      @@ -1027,7 +1027,7 @@ title for the link, surrounded in quotes. For example:

      Code

      Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example:

      -
ab

Markdown: Syntax

+

Markdown: Syntax

  • Overview
      @@ -1027,7 +1027,7 @@ title for the link, surrounded in quotes. For example:

      Code

      Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example:

      -
ab

Note: This document is itself written using Markdown; you +

Note: This document is itself written using Markdown; you can see the source for it by adding '.text' to the URL.


Overview

-
ab

Note: This document is itself written using Markdown; you +

Note: This document is itself written using Markdown; you can see the source for it by adding '.text' to the URL.


Overview

-
ab ab ab ab ab aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac -1 +1 -2 +2 -3 +3 -4 +4 -5 +5 -6aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac +aabbccddllffwwyynniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac -1 +1 -2 +2 -3 +3 -4 +4 -5 +5 -6abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv
    +
    • Overview
      • Philosophy
      • @@ -782,7 +782,7 @@ width="579" height="752" viewBox="-100 -100 579 752">
          +
          • Overview
            • Philosophy
            • @@ -782,7 +782,7 @@ width="1005" height="326" viewBox="-88 -88 1005 326">
                +
                • Overview ok this is all measured
                  • Philosophy
                  • @@ -778,7 +778,7 @@ width="445" height="728" viewBox="-100 -100 445 728">
                      +
                      • Overview ok this is all measured
                        • Philosophy
                        • @@ -778,7 +778,7 @@ width="871" height="326" viewBox="-88 -88 871 326">
                            +
                            • Overview
                              • Philosophy
                              • @@ -803,7 +803,7 @@ width="547" height="1164" viewBox="-100 -100 547 1164">
                                  +
                                  • Overview
                                    • Philosophy
                                    • @@ -803,7 +803,7 @@ width="973" height="712" viewBox="-88 -88 973 712">

                                      List items may consist of multiple paragraphs. Each subsequent +

                                      List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab:

                                        @@ -801,7 +801,7 @@ sit amet, consectetuer adipiscing elit.

                                        Another item in the same list.

                                    -
                                  ab

                                  List items may consist of multiple paragraphs. Each subsequent +

                                  List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab:

                                    @@ -801,7 +801,7 @@ sit amet, consectetuer adipiscing elit.

                                    Another item in the same list.

                                -
                                ab

                                Markdown: Syntax

                                -
                                ab

                                Markdown: Syntax

                                +
                                ab

                                Markdown: Syntax

                                -
                                ab

                                Markdown: Syntax

                                +
                                ab

                                Every frustum longs to be a cone

                                +

                                Every frustum longs to be a cone

                                • A continuing flow of paper is sufficient to continue the flow of paper
                                • Please remain calm, it's no use both of us being hysterical at the same time
                                • Visits always give pleasure: if not on arrival, then on the departure

                                Festivity Level 1: Your guests are chatting amiably with each other.

                                -
                                xy

                                Every frustum longs to be a cone

                                +

                                Every frustum longs to be a cone

                                • A continuing flow of paper is sufficient to continue the flow of paper
                                • Please remain calm, it's no use both of us being hysterical at the same time
                                • Visits always give pleasure: if not on arrival, then on the departure

                                Festivity Level 1: Your guests are chatting amiably with each other.

                                -
                                xy markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                +markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

                                -
                                markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                +markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

                                -
                                markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                +markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

                                -
                                markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                +markdown

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                                sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

                                -
                                {
                                +
                                {
                                 	fenced: "block",
                                 	of: "json",
                                 }
                                 
                                -
                                ab
                                {
                                +
                                {
                                 	fenced: "block",
                                 	of: "json",
                                 }
                                 
                                -
                                ab

                                a line of text and an

                                +

                                a line of text and an

                                {
                                 	indented: "block",
                                 	of: "json",
                                 }
                                 
                                -
                                ab

                                a line of text and an

                                +

                                a line of text and an

                                {
                                 	indented: "block",
                                 	of: "json",
                                 }
                                 
                                -
                                ab

                                code

                                -
                                ab

                                code

                                +
                                ab

                                code

                                -
                                ab

                                code

                                +
                                ab thisgoesmultiple linesthisgoesmultiple linesthisgoesmultiple linesthisgoesmultiple linesabcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstu abcdefghijklmnopqrstu abcdefghijklmnopqrstu abcdefghijklmnopqrstu acdefgbh acdefgbh acdefgbh acdefgbh topabcbottomstartend topabcbottomstartend topabcbottomstartend topabcbottomstartend

                                A paragraph is simply one or more consecutive lines of text, separated +

                                A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.

                                -
                                ab

                                A paragraph is simply one or more consecutive lines of text, separated +

                                A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.

                                -
                                ab

                                Here is an example of AppleScript:

                                +

                                Here is an example of AppleScript:

                                tell application "Foo"
                                     beep
                                 end tell
                                 

                                A code block continues until it reaches a line that is not indented (or the end of the article).

                                -
                                ab

                                Here is an example of AppleScript:

                                +

                                Here is an example of AppleScript:

                                tell application "Foo"
                                     beep
                                 end tell
                                 

                                A code block continues until it reaches a line that is not indented (or the end of the article).

                                -
                                ab usersid +usersid int name string @@ -24,7 +24,7 @@ width="1162" height="660" viewBox="-100 -100 1162 660">usersid +usersid int name string @@ -24,7 +24,7 @@ width="808" height="816" viewBox="-88 -88 808 816">rectanglesquare rectanglesquare rectanglesquare rectanglesquare acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDcontainerfirstsecond +containerfirstsecond -1->2 +1->2 -c->2containerfirstsecond +containerfirstsecond -1->2 +1->2 -c->2