diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go
index 8082c033c..f21b1bce1 100644
--- a/d2renderers/d2svg/d2svg.go
+++ b/d2renderers/d2svg/d2svg.go
@@ -885,6 +885,9 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske
if targetShape.Stroke != "" {
mdStyle += fmt.Sprintf("color:%s;", targetShape.Stroke)
}
+ if targetShape.Opacity != 1.0 {
+ mdStyle += fmt.Sprintf("opacity:%f;", targetShape.Opacity)
+ }
fmt.Fprintf(writer, `
%v
`, mdStyle, render)
fmt.Fprint(writer, ``)
@@ -894,6 +897,9 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske
fontColor = targetShape.Color
}
textStyle := fmt.Sprintf("text-anchor:%s;font-size:%vpx;fill:%s", "middle", targetShape.FontSize, fontColor)
+ if targetShape.Opacity != 1.0 {
+ textStyle += fmt.Sprintf(";opacity:%f;", targetShape.Opacity)
+ }
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/regression_test.go b/e2etests/regression_test.go
index 13646d942..6752d7f73 100644
--- a/e2etests/regression_test.go
+++ b/e2etests/regression_test.go
@@ -380,6 +380,16 @@ no leading: |python
}
x.a -> x.a
+`,
+ },
+ {
+ name: "opacity-on-label",
+ script: `x.style.opacity: 0.4
+y: |md
+ linux: because a PC is a terrible thing to waste
+| {
+ style.opacity: 0.4
+}
`,
},
}
diff --git a/e2etests/testdata/regression/opacity-on-label/dagre/board.exp.json b/e2etests/testdata/regression/opacity-on-label/dagre/board.exp.json
new file mode 100644
index 000000000..db2020838
--- /dev/null
+++ b/e2etests/testdata/regression/opacity-on-label/dagre/board.exp.json
@@ -0,0 +1,86 @@
+{
+ "name": "",
+ "fontFamily": "SourceSansPro",
+ "shapes": [
+ {
+ "id": "x",
+ "type": "",
+ "pos": {
+ "x": 0,
+ "y": 0
+ },
+ "width": 113,
+ "height": 126,
+ "opacity": 0.4,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "#F7F8FE",
+ "stroke": "#0D32B2",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "x",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "#0A0F25",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 13,
+ "labelHeight": 26,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "y",
+ "type": "text",
+ "pos": {
+ "x": 173,
+ "y": 51
+ },
+ "width": 304,
+ "height": 24,
+ "opacity": 0.4,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "transparent",
+ "stroke": "#0A0F25",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "linux: because a PC is a terrible thing to waste",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "markdown",
+ "color": "#0A0F25",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 304,
+ "labelHeight": 24,
+ "zIndex": 0,
+ "level": 1
+ }
+ ],
+ "connections": []
+}
diff --git a/e2etests/testdata/regression/opacity-on-label/dagre/sketch.exp.svg b/e2etests/testdata/regression/opacity-on-label/dagre/sketch.exp.svg
new file mode 100644
index 000000000..8ed199b2a
--- /dev/null
+++ b/e2etests/testdata/regression/opacity-on-label/dagre/sketch.exp.svg
@@ -0,0 +1,817 @@
+
+
\ No newline at end of file
diff --git a/e2etests/testdata/regression/opacity-on-label/elk/board.exp.json b/e2etests/testdata/regression/opacity-on-label/elk/board.exp.json
new file mode 100644
index 000000000..bc30bf771
--- /dev/null
+++ b/e2etests/testdata/regression/opacity-on-label/elk/board.exp.json
@@ -0,0 +1,86 @@
+{
+ "name": "",
+ "fontFamily": "SourceSansPro",
+ "shapes": [
+ {
+ "id": "x",
+ "type": "",
+ "pos": {
+ "x": 12,
+ "y": 12
+ },
+ "width": 113,
+ "height": 126,
+ "opacity": 0.4,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "#F7F8FE",
+ "stroke": "#0D32B2",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "x",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "",
+ "color": "#0A0F25",
+ "italic": false,
+ "bold": true,
+ "underline": false,
+ "labelWidth": 13,
+ "labelHeight": 26,
+ "labelPosition": "INSIDE_MIDDLE_CENTER",
+ "zIndex": 0,
+ "level": 1
+ },
+ {
+ "id": "y",
+ "type": "text",
+ "pos": {
+ "x": 145,
+ "y": 63
+ },
+ "width": 304,
+ "height": 24,
+ "opacity": 0.4,
+ "strokeDash": 0,
+ "strokeWidth": 2,
+ "borderRadius": 0,
+ "fill": "transparent",
+ "stroke": "#0A0F25",
+ "shadow": false,
+ "3d": false,
+ "multiple": false,
+ "tooltip": "",
+ "link": "",
+ "icon": null,
+ "iconPosition": "",
+ "blend": false,
+ "fields": null,
+ "methods": null,
+ "columns": null,
+ "label": "linux: because a PC is a terrible thing to waste",
+ "fontSize": 16,
+ "fontFamily": "DEFAULT",
+ "language": "markdown",
+ "color": "#0A0F25",
+ "italic": false,
+ "bold": false,
+ "underline": false,
+ "labelWidth": 304,
+ "labelHeight": 24,
+ "zIndex": 0,
+ "level": 1
+ }
+ ],
+ "connections": []
+}
diff --git a/e2etests/testdata/regression/opacity-on-label/elk/sketch.exp.svg b/e2etests/testdata/regression/opacity-on-label/elk/sketch.exp.svg
new file mode 100644
index 000000000..fa2b77780
--- /dev/null
+++ b/e2etests/testdata/regression/opacity-on-label/elk/sketch.exp.svg
@@ -0,0 +1,817 @@
+
+
\ No newline at end of file
diff --git a/e2etests/testdata/stable/stylish/dagre/sketch.exp.svg b/e2etests/testdata/stable/stylish/dagre/sketch.exp.svg
index b1f14ed51..12c7c3837 100644
--- a/e2etests/testdata/stable/stylish/dagre/sketch.exp.svg
+++ b/e2etests/testdata/stable/stylish/dagre/sketch.exp.svg
@@ -47,9 +47,9 @@ width="323" height="580" viewBox="-104 -105 323 580">