diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index ccce03afb..26bac5e62 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -1906,6 +1906,9 @@ func Render(diagram *d2target.Diagram, opts *RenderOpts) ([]byte, error) { if color.IsGradient(c.Stroke) { defineGradients(buf, c.Stroke) } + if color.IsGradient(c.Fill) { + defineGradients(buf, c.Fill) + } } // Apply hash on IDs for targeting, to be specific for this diagram diff --git a/e2etests/testdata/txtar/gradient/dagre/board.exp.json b/e2etests/testdata/txtar/gradient/dagre/board.exp.json index 4ff7e0a79..35b556c52 100644 --- a/e2etests/testdata/txtar/gradient/dagre/board.exp.json +++ b/e2etests/testdata/txtar/gradient/dagre/board.exp.json @@ -58,7 +58,7 @@ "type": "rectangle", "pos": { "x": 9, - "y": 166 + "y": 187 }, "width": 89, "height": 66, @@ -106,37 +106,38 @@ "opacity": 1, "strokeDash": 0, "strokeWidth": 2, - "stroke": "B1", + "stroke": "red", + "fill": "radial-gradient(#ffffff, #000000)", "borderRadius": 10, - "label": "", + "label": "foobar", "fontSize": 16, "fontFamily": "DEFAULT", "language": "", - "color": "N2", + "color": "red", "italic": true, "bold": false, "underline": false, - "labelWidth": 0, - "labelHeight": 0, - "labelPosition": "", + "labelWidth": 46, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", "labelPercentage": 0, "link": "", "route": [ { "x": 53, - "y": 66 + "y": 65.5 }, { "x": 53, - "y": 106 + "y": 114.30000305175781 }, { "x": 53, - "y": 126 + "y": 138.6999969482422 }, { "x": 53, - "y": 166 + "y": 187.5 } ], "isCurve": true, diff --git a/e2etests/testdata/txtar/gradient/dagre/sketch.exp.svg b/e2etests/testdata/txtar/gradient/dagre/sketch.exp.svg index ea298f1f3..2939c7f01 100644 --- a/e2etests/testdata/txtar/gradient/dagre/sketch.exp.svg +++ b/e2etests/testdata/txtar/gradient/dagre/sketch.exp.svg @@ -1,10 +1,17 @@ - + .d2-1069291522 .fill-N1{fill:#0A0F25;} + .d2-1069291522 .fill-N2{fill:#676C7E;} + .d2-1069291522 .fill-N3{fill:#9499AB;} + .d2-1069291522 .fill-N4{fill:#CFD2DD;} + .d2-1069291522 .fill-N5{fill:#DEE1EB;} + .d2-1069291522 .fill-N6{fill:#EEF1F8;} + .d2-1069291522 .fill-N7{fill:#FFFFFF;} + .d2-1069291522 .fill-B1{fill:#0D32B2;} + .d2-1069291522 .fill-B2{fill:#0D32B2;} + .d2-1069291522 .fill-B3{fill:#E3E9FD;} + .d2-1069291522 .fill-B4{fill:#E3E9FD;} + .d2-1069291522 .fill-B5{fill:#EDF0FD;} + .d2-1069291522 .fill-B6{fill:#F7F8FE;} + .d2-1069291522 .fill-AA2{fill:#4A6FF3;} + .d2-1069291522 .fill-AA4{fill:#EDF0FD;} + .d2-1069291522 .fill-AA5{fill:#F7F8FE;} + .d2-1069291522 .fill-AB4{fill:#EDF0FD;} + .d2-1069291522 .fill-AB5{fill:#F7F8FE;} + .d2-1069291522 .stroke-N1{stroke:#0A0F25;} + .d2-1069291522 .stroke-N2{stroke:#676C7E;} + .d2-1069291522 .stroke-N3{stroke:#9499AB;} + .d2-1069291522 .stroke-N4{stroke:#CFD2DD;} + .d2-1069291522 .stroke-N5{stroke:#DEE1EB;} + .d2-1069291522 .stroke-N6{stroke:#EEF1F8;} + .d2-1069291522 .stroke-N7{stroke:#FFFFFF;} + .d2-1069291522 .stroke-B1{stroke:#0D32B2;} + .d2-1069291522 .stroke-B2{stroke:#0D32B2;} + .d2-1069291522 .stroke-B3{stroke:#E3E9FD;} + .d2-1069291522 .stroke-B4{stroke:#E3E9FD;} + .d2-1069291522 .stroke-B5{stroke:#EDF0FD;} + .d2-1069291522 .stroke-B6{stroke:#F7F8FE;} + .d2-1069291522 .stroke-AA2{stroke:#4A6FF3;} + .d2-1069291522 .stroke-AA4{stroke:#EDF0FD;} + .d2-1069291522 .stroke-AA5{stroke:#F7F8FE;} + .d2-1069291522 .stroke-AB4{stroke:#EDF0FD;} + .d2-1069291522 .stroke-AB5{stroke:#F7F8FE;} + .d2-1069291522 .background-color-N1{background-color:#0A0F25;} + .d2-1069291522 .background-color-N2{background-color:#676C7E;} + .d2-1069291522 .background-color-N3{background-color:#9499AB;} + .d2-1069291522 .background-color-N4{background-color:#CFD2DD;} + .d2-1069291522 .background-color-N5{background-color:#DEE1EB;} + .d2-1069291522 .background-color-N6{background-color:#EEF1F8;} + .d2-1069291522 .background-color-N7{background-color:#FFFFFF;} + .d2-1069291522 .background-color-B1{background-color:#0D32B2;} + .d2-1069291522 .background-color-B2{background-color:#0D32B2;} + .d2-1069291522 .background-color-B3{background-color:#E3E9FD;} + .d2-1069291522 .background-color-B4{background-color:#E3E9FD;} + .d2-1069291522 .background-color-B5{background-color:#EDF0FD;} + .d2-1069291522 .background-color-B6{background-color:#F7F8FE;} + .d2-1069291522 .background-color-AA2{background-color:#4A6FF3;} + .d2-1069291522 .background-color-AA4{background-color:#EDF0FD;} + .d2-1069291522 .background-color-AA5{background-color:#F7F8FE;} + .d2-1069291522 .background-color-AB4{background-color:#EDF0FD;} + .d2-1069291522 .background-color-AB5{background-color:#F7F8FE;} + .d2-1069291522 .color-N1{color:#0A0F25;} + .d2-1069291522 .color-N2{color:#676C7E;} + .d2-1069291522 .color-N3{color:#9499AB;} + .d2-1069291522 .color-N4{color:#CFD2DD;} + .d2-1069291522 .color-N5{color:#DEE1EB;} + .d2-1069291522 .color-N6{color:#EEF1F8;} + .d2-1069291522 .color-N7{color:#FFFFFF;} + .d2-1069291522 .color-B1{color:#0D32B2;} + .d2-1069291522 .color-B2{color:#0D32B2;} + .d2-1069291522 .color-B3{color:#E3E9FD;} + .d2-1069291522 .color-B4{color:#E3E9FD;} + .d2-1069291522 .color-B5{color:#EDF0FD;} + .d2-1069291522 .color-B6{color:#F7F8FE;} + .d2-1069291522 .color-AA2{color:#4A6FF3;} + .d2-1069291522 .color-AA4{color:#EDF0FD;} + .d2-1069291522 .color-AA5{color:#F7F8FE;} + .d2-1069291522 .color-AB4{color:#EDF0FD;} + .d2-1069291522 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker-d2-1069291522);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker-d2-1069291522);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark-d2-1069291522);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker-d2-1069291522);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark-d2-1069291522);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal-d2-1069291522);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal-d2-1069291522);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright-d2-1069291522);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]> @@ -118,8 +125,12 @@ -gradientcolors - + + + +gradientcolors foobar + - + + \ No newline at end of file diff --git a/e2etests/testdata/txtar/gradient/elk/board.exp.json b/e2etests/testdata/txtar/gradient/elk/board.exp.json index 85dab3899..cfeb60cb8 100644 --- a/e2etests/testdata/txtar/gradient/elk/board.exp.json +++ b/e2etests/testdata/txtar/gradient/elk/board.exp.json @@ -58,7 +58,7 @@ "type": "rectangle", "pos": { "x": 20, - "y": 148 + "y": 239 }, "width": 89, "height": 66, @@ -106,19 +106,20 @@ "opacity": 1, "strokeDash": 0, "strokeWidth": 2, - "stroke": "B1", + "stroke": "red", + "fill": "radial-gradient(#ffffff, #000000)", "borderRadius": 10, - "label": "", + "label": "foobar", "fontSize": 16, "fontFamily": "DEFAULT", "language": "", - "color": "N2", + "color": "red", "italic": true, "bold": false, "underline": false, - "labelWidth": 0, - "labelHeight": 0, - "labelPosition": "", + "labelWidth": 46, + "labelHeight": 21, + "labelPosition": "INSIDE_MIDDLE_CENTER", "labelPercentage": 0, "link": "", "route": [ @@ -128,7 +129,7 @@ }, { "x": 65, - "y": 148 + "y": 239 } ], "animated": false, diff --git a/e2etests/testdata/txtar/gradient/elk/sketch.exp.svg b/e2etests/testdata/txtar/gradient/elk/sketch.exp.svg index 3574722eb..b5b9047d3 100644 --- a/e2etests/testdata/txtar/gradient/elk/sketch.exp.svg +++ b/e2etests/testdata/txtar/gradient/elk/sketch.exp.svg @@ -1,10 +1,17 @@ - + .d2-2458666147 .fill-N1{fill:#0A0F25;} + .d2-2458666147 .fill-N2{fill:#676C7E;} + .d2-2458666147 .fill-N3{fill:#9499AB;} + .d2-2458666147 .fill-N4{fill:#CFD2DD;} + .d2-2458666147 .fill-N5{fill:#DEE1EB;} + .d2-2458666147 .fill-N6{fill:#EEF1F8;} + .d2-2458666147 .fill-N7{fill:#FFFFFF;} + .d2-2458666147 .fill-B1{fill:#0D32B2;} + .d2-2458666147 .fill-B2{fill:#0D32B2;} + .d2-2458666147 .fill-B3{fill:#E3E9FD;} + .d2-2458666147 .fill-B4{fill:#E3E9FD;} + .d2-2458666147 .fill-B5{fill:#EDF0FD;} + .d2-2458666147 .fill-B6{fill:#F7F8FE;} + .d2-2458666147 .fill-AA2{fill:#4A6FF3;} + .d2-2458666147 .fill-AA4{fill:#EDF0FD;} + .d2-2458666147 .fill-AA5{fill:#F7F8FE;} + .d2-2458666147 .fill-AB4{fill:#EDF0FD;} + .d2-2458666147 .fill-AB5{fill:#F7F8FE;} + .d2-2458666147 .stroke-N1{stroke:#0A0F25;} + .d2-2458666147 .stroke-N2{stroke:#676C7E;} + .d2-2458666147 .stroke-N3{stroke:#9499AB;} + .d2-2458666147 .stroke-N4{stroke:#CFD2DD;} + .d2-2458666147 .stroke-N5{stroke:#DEE1EB;} + .d2-2458666147 .stroke-N6{stroke:#EEF1F8;} + .d2-2458666147 .stroke-N7{stroke:#FFFFFF;} + .d2-2458666147 .stroke-B1{stroke:#0D32B2;} + .d2-2458666147 .stroke-B2{stroke:#0D32B2;} + .d2-2458666147 .stroke-B3{stroke:#E3E9FD;} + .d2-2458666147 .stroke-B4{stroke:#E3E9FD;} + .d2-2458666147 .stroke-B5{stroke:#EDF0FD;} + .d2-2458666147 .stroke-B6{stroke:#F7F8FE;} + .d2-2458666147 .stroke-AA2{stroke:#4A6FF3;} + .d2-2458666147 .stroke-AA4{stroke:#EDF0FD;} + .d2-2458666147 .stroke-AA5{stroke:#F7F8FE;} + .d2-2458666147 .stroke-AB4{stroke:#EDF0FD;} + .d2-2458666147 .stroke-AB5{stroke:#F7F8FE;} + .d2-2458666147 .background-color-N1{background-color:#0A0F25;} + .d2-2458666147 .background-color-N2{background-color:#676C7E;} + .d2-2458666147 .background-color-N3{background-color:#9499AB;} + .d2-2458666147 .background-color-N4{background-color:#CFD2DD;} + .d2-2458666147 .background-color-N5{background-color:#DEE1EB;} + .d2-2458666147 .background-color-N6{background-color:#EEF1F8;} + .d2-2458666147 .background-color-N7{background-color:#FFFFFF;} + .d2-2458666147 .background-color-B1{background-color:#0D32B2;} + .d2-2458666147 .background-color-B2{background-color:#0D32B2;} + .d2-2458666147 .background-color-B3{background-color:#E3E9FD;} + .d2-2458666147 .background-color-B4{background-color:#E3E9FD;} + .d2-2458666147 .background-color-B5{background-color:#EDF0FD;} + .d2-2458666147 .background-color-B6{background-color:#F7F8FE;} + .d2-2458666147 .background-color-AA2{background-color:#4A6FF3;} + .d2-2458666147 .background-color-AA4{background-color:#EDF0FD;} + .d2-2458666147 .background-color-AA5{background-color:#F7F8FE;} + .d2-2458666147 .background-color-AB4{background-color:#EDF0FD;} + .d2-2458666147 .background-color-AB5{background-color:#F7F8FE;} + .d2-2458666147 .color-N1{color:#0A0F25;} + .d2-2458666147 .color-N2{color:#676C7E;} + .d2-2458666147 .color-N3{color:#9499AB;} + .d2-2458666147 .color-N4{color:#CFD2DD;} + .d2-2458666147 .color-N5{color:#DEE1EB;} + .d2-2458666147 .color-N6{color:#EEF1F8;} + .d2-2458666147 .color-N7{color:#FFFFFF;} + .d2-2458666147 .color-B1{color:#0D32B2;} + .d2-2458666147 .color-B2{color:#0D32B2;} + .d2-2458666147 .color-B3{color:#E3E9FD;} + .d2-2458666147 .color-B4{color:#E3E9FD;} + .d2-2458666147 .color-B5{color:#EDF0FD;} + .d2-2458666147 .color-B6{color:#F7F8FE;} + .d2-2458666147 .color-AA2{color:#4A6FF3;} + .d2-2458666147 .color-AA4{color:#EDF0FD;} + .d2-2458666147 .color-AA5{color:#F7F8FE;} + .d2-2458666147 .color-AB4{color:#EDF0FD;} + .d2-2458666147 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker-d2-2458666147);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker-d2-2458666147);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark-d2-2458666147);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker-d2-2458666147);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark-d2-2458666147);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal-d2-2458666147);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal-d2-2458666147);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright-d2-2458666147);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]> @@ -118,8 +125,12 @@ -gradientcolors - + + + +gradientcolors foobar + - + + \ No newline at end of file diff --git a/e2etests/txtar.txt b/e2etests/txtar.txt index a93f6518d..fae92f88b 100644 --- a/e2etests/txtar.txt +++ b/e2etests/txtar.txt @@ -468,7 +468,7 @@ colors: { style.stroke: "linear-gradient(to right, red, blue, green)" style.font-color: "linear-gradient(to bottom right, red 0%, yellow 25%, green 50%, cyan 75%, blue 100%)" } -gradient -> colors +gradient -> colors: foobar {style.font-color: red; style.stroke: red; style.fill: "radial-gradient(#ffffff, #000000)"} -- var_in_markdown -- vars: {