From d683904d4d0049a73eff5db2ab68ecf58a691342 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Fri, 25 Nov 2022 16:47:27 -0800 Subject: [PATCH] render labels with font-color attribute --- d2renderers/d2svg/d2svg.go | 12 ++++++++-- .../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/code_snippet/dagre/sketch.exp.svg | 2 +- .../stable/code_snippet/elk/sketch.exp.svg | 2 +- .../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 | 2 +- .../giant_markdown_test/elk/sketch.exp.svg | 2 +- .../testdata/stable/hr/dagre/sketch.exp.svg | 2 +- .../testdata/stable/hr/elk/sketch.exp.svg | 2 +- .../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 | 2 +- .../testdata/stable/li1/elk/sketch.exp.svg | 2 +- .../testdata/stable/li2/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li2/elk/sketch.exp.svg | 2 +- .../testdata/stable/li3/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li3/elk/sketch.exp.svg | 2 +- .../testdata/stable/li4/dagre/sketch.exp.svg | 2 +- .../testdata/stable/li4/elk/sketch.exp.svg | 2 +- .../stable/lone_h1/dagre/sketch.exp.svg | 2 +- .../stable/lone_h1/elk/sketch.exp.svg | 2 +- .../stable/markdown/dagre/sketch.exp.svg | 2 +- .../stable/markdown/elk/sketch.exp.svg | 2 +- .../md_2space_newline/dagre/sketch.exp.svg | 2 +- .../md_2space_newline/elk/sketch.exp.svg | 2 +- .../md_backslash_newline/dagre/sketch.exp.svg | 2 +- .../md_backslash_newline/elk/sketch.exp.svg | 2 +- .../md_code_block_fenced/dagre/sketch.exp.svg | 2 +- .../md_code_block_fenced/elk/sketch.exp.svg | 2 +- .../dagre/sketch.exp.svg | 2 +- .../md_code_block_indented/elk/sketch.exp.svg | 2 +- .../md_code_inline/dagre/sketch.exp.svg | 2 +- .../stable/md_code_inline/elk/sketch.exp.svg | 2 +- .../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 | 2 +- e2etests/testdata/stable/p/elk/sketch.exp.svg | 2 +- .../testdata/stable/pre/dagre/sketch.exp.svg | 2 +- .../testdata/stable/pre/elk/sketch.exp.svg | 2 +- .../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 ++--- 97 files changed, 154 insertions(+), 146 deletions(-) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index d32a1749a..ba1459c9e 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -437,7 +437,11 @@ func drawConnection(writer io.Writer, connection d2target.Connection, markers ma } else if connection.Italic { fontClass += "-italic" } - textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", connection.FontSize, "black") + fontColor := "black" + if connection.Color != "" { + fontColor = connection.Color + } + textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", connection.FontSize, fontColor) x := labelTL.X + float64(connection.LabelWidth)/2 y := labelTL.Y + float64(connection.FontSize) fmt.Fprintf(writer, `%s`, @@ -706,7 +710,11 @@ func drawShape(writer io.Writer, targetShape d2target.Shape) error { fmt.Fprintf(writer, `
%v
`, render) fmt.Fprint(writer, ``) default: - textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", targetShape.FontSize, "black") + fontColor := "black" + if targetShape.Color != "" { + 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 // text is vertically positioned at its baseline which is at labelTL+FontSize y := labelTL.Y + float64(targetShape.FontSize) 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 73c194056..3d41cc01a 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 acfbdhg acfbdhg acfbdhg acfbdhg agdfbhec agdfbhec agdfbhec agdfbhec abcdefghijklmnopq abcdefghijklmnopq abcdefghijklmnopq abcdefghijklmnopq finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot finallyatreeandnodessomemoremanythenhereyouhavehierarchyanotherofnestingtreesatreeinsidehierarchyroot alphabeta +alphabeta -gammaalphabeta +alphabeta -gammaab ab ab ab aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac +aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac -1 +1 -2 +2 -3 +3 -4 +4 -5 +5 -6aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac +aabbccddllffwwyyadnniijjkkssuurmeemmmmgghhzzooppqqrrttvvxxabac -1 +1 -2 +2 -3 +3 -4 +4 -5 +5 -6abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv abcdefghiqrjmnoszaabbeeffggklptuwxyccddv

Markdown: Syntax

-
ab

Markdown: Syntax

-
ab 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.

code

-
ab

code

-
ab thisgoesmultiple linesthisgoesmultiple linesthisgoesmultiple linesthisgoesmultiple linesabcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstuvw abcdefghijklmnopqrstu abcdefghijklmnopqrstu abcdefghijklmnopqrstu abcdefghijklmnopqrstu acdefgbh acdefgbh acdefgbh acdefgbh topabcbottomstartend topabcbottomstartend topabcbottomstartend topabcbottomstartend rectanglesquare rectanglesquare rectanglesquare rectanglesquare acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc acbl1l2c1l2c3l2c2l3c1l3c2l4bacacbabcc1c2c3abc AKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDAKHIALFLGAMSTNAZCANVNMUTARLAMOOKTXORCOKSNEWYCTMANYRIDEMDNJPANCSCIDMTWAILINIAMIKYWIOHMNSDVAWVMENHVTNDcontainerfirstsecond +containerfirstsecond -1->2 +1->2 -c->2containerfirstsecond +containerfirstsecond -1->2 +1->2 -c->2