diff --git a/d2renderers/d2sketch/sketch.go b/d2renderers/d2sketch/sketch.go index fc34270b0..aa48de619 100644 --- a/d2renderers/d2sketch/sketch.go +++ b/d2renderers/d2sketch/sketch.go @@ -382,7 +382,7 @@ func Table(r *Runner, shape d2target.Shape) (string, error) { textEl := d2themes.NewThemableElement("text") textEl.X = tl.X textEl.Y = tl.Y + float64(shape.LabelHeight)*3/4 - textEl.Fill = shape.Stroke + textEl.Fill = shape.GetFontColor() textEl.ClassName = "text" textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "start", 4+shape.FontSize, @@ -532,7 +532,7 @@ func Class(r *Runner, shape d2target.Shape) (string, error) { textEl := d2themes.NewThemableElement("text") textEl.X = tl.X + float64(shape.LabelWidth)/2 textEl.Y = tl.Y + float64(shape.LabelHeight)*3/4 - textEl.Fill = shape.Stroke + textEl.Fill = shape.GetFontColor() textEl.ClassName = "text-mono" textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "middle", diff --git a/d2renderers/d2svg/class.go b/d2renderers/d2svg/class.go index 7b5e2b59a..6cf8e6889 100644 --- a/d2renderers/d2svg/class.go +++ b/d2renderers/d2svg/class.go @@ -30,7 +30,7 @@ func classHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex textEl := d2themes.NewThemableElement("text") textEl.X = tl.X + textWidth/2 textEl.Y = tl.Y + textHeight*3/4 - textEl.Fill = shape.Stroke + textEl.Fill = shape.GetFontColor() textEl.ClassName = "text-mono" textEl.Style = fmt.Sprintf(`text-anchor:%s;font-size:%vpx;`, "middle", 4+fontSize, diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 87d403ac0..61d54b6f6 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -562,11 +562,6 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co } else if connection.Italic { fontClass += "-italic" } - fontColor := color.N1 - if connection.Color != color.Empty { - fontColor = connection.Color - } - if connection.Fill != color.Empty { rectEl := d2themes.NewThemableElement("rect") rectEl.X, rectEl.Y = labelTL.X, labelTL.Y @@ -578,7 +573,7 @@ func drawConnection(writer io.Writer, labelMaskID string, connection d2target.Co textEl := d2themes.NewThemableElement("text") textEl.X = labelTL.X + float64(connection.LabelWidth)/2 textEl.Y = labelTL.Y + float64(connection.FontSize) - textEl.Fill = fontColor + textEl.Fill = connection.GetFontColor() textEl.ClassName = fontClass textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "middle", connection.FontSize) textEl.Content = RenderText(connection.Label, textEl.X, float64(connection.LabelHeight)) @@ -1112,10 +1107,6 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske fmt.Fprint(writer, mdEl.Render()) fmt.Fprint(writer, ``) } else { - fontColor := color.N1 - if targetShape.Color != color.Empty { - fontColor = targetShape.Color - } if targetShape.LabelFill != "" { rectEl := d2themes.NewThemableElement("rect") rectEl.X = labelTL.X @@ -1129,7 +1120,7 @@ func drawShape(writer io.Writer, targetShape d2target.Shape, sketchRunner *d2ske textEl.X = labelTL.X + float64(targetShape.LabelWidth)/2 // text is vertically positioned at its baseline which is at labelTL+FontSize textEl.Y = labelTL.Y + float64(targetShape.FontSize) - textEl.Fill = fontColor + textEl.Fill = targetShape.GetFontColor() textEl.ClassName = fontClass textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "middle", targetShape.FontSize) textEl.Content = RenderText(targetShape.Label, textEl.X, float64(targetShape.LabelHeight)) diff --git a/d2renderers/d2svg/table.go b/d2renderers/d2svg/table.go index 383b6aab5..e4f0695ac 100644 --- a/d2renderers/d2svg/table.go +++ b/d2renderers/d2svg/table.go @@ -31,7 +31,7 @@ func tableHeader(shape d2target.Shape, box *geo.Box, text string, textWidth, tex textEl := d2themes.NewThemableElement("text") textEl.X = tl.X textEl.Y = tl.Y + textHeight*3/4 - textEl.Fill = shape.Stroke + textEl.Fill = shape.GetFontColor() textEl.ClassName = "text" textEl.Style = fmt.Sprintf("text-anchor:%s;font-size:%vpx", "start", 4+fontSize, diff --git a/d2target/d2target.go b/d2target/d2target.go index cc445d674..2a3aa5ff8 100644 --- a/d2target/d2target.go +++ b/d2target/d2target.go @@ -197,6 +197,19 @@ type Shape struct { NeutralAccentColor string `json:"neutralAccentColor,omitempty"` } +func (s Shape) GetFontColor() string { + if s.Type == ShapeClass || s.Type == ShapeSQLTable { + if !color.IsThemeColor(s.Color) { + return s.Color + } + return s.Stroke + } + if s.Color != color.Empty { + return s.Color + } + return color.N1 +} + func (s Shape) CSSStyle() string { out := "" @@ -302,6 +315,13 @@ func BaseConnection() *Connection { } } +func (c Connection) GetFontColor() string { + if c.Color != color.Empty { + return c.Color + } + return color.N1 +} + func (c Connection) CSSStyle() string { out := "" diff --git a/e2etests/testdata/regression/class_font_style_sequence/dagre/sketch.exp.svg b/e2etests/testdata/regression/class_font_style_sequence/dagre/sketch.exp.svg index 682ad03a0..10929229e 100644 --- a/e2etests/testdata/regression/class_font_style_sequence/dagre/sketch.exp.svg +++ b/e2etests/testdata/regression/class_font_style_sequence/dagre/sketch.exp.svg @@ -37,7 +37,7 @@ svgEl.setAttribute("height", height * ratio - 16); } }); -]]>a +]]>a \ No newline at end of file diff --git a/e2etests/testdata/regression/class_font_style_sequence/elk/sketch.exp.svg b/e2etests/testdata/regression/class_font_style_sequence/elk/sketch.exp.svg index 682ad03a0..10929229e 100644 --- a/e2etests/testdata/regression/class_font_style_sequence/elk/sketch.exp.svg +++ b/e2etests/testdata/regression/class_font_style_sequence/elk/sketch.exp.svg @@ -37,7 +37,7 @@ svgEl.setAttribute("height", height * ratio - 16); } }); -]]>a +]]>a \ No newline at end of file diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json index f1d01a939..7c4a835c0 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/board.exp.json @@ -97,7 +97,7 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "B5", + "fill": "N1", "stroke": "N7", "shadow": false, "3d": false, @@ -819,7 +819,7 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "B5", + "fill": "N1", "stroke": "N7", "shadow": false, "3d": false, diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg index 090313fe6..5fa77ee27 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/dagre/sketch.exp.svg @@ -65,9 +65,9 @@ svgEl.setAttribute("height", height * ratio - 16); } }); -]]>a labelblabelsa class+public() boolvoid-private() intvoidcloudyyyy:= 5 +]]>a labelblabelsa class+public() boolvoid-private() intvoidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersidintnamevarchar result := callThisFunction(obj, 5) midthis sideother side +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersidintnamevarchar result := callThisFunction(obj, 5) midthis sideother side diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json index f1d01a939..7c4a835c0 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/board.exp.json @@ -97,7 +97,7 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "B5", + "fill": "N1", "stroke": "N7", "shadow": false, "3d": false, @@ -819,7 +819,7 @@ "strokeDash": 0, "strokeWidth": 2, "borderRadius": 0, - "fill": "B5", + "fill": "N1", "stroke": "N7", "shadow": false, "3d": false, diff --git a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg index 090313fe6..5fa77ee27 100644 --- a/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sequence_diagram_all_shapes/elk/sketch.exp.svg @@ -65,9 +65,9 @@ svgEl.setAttribute("height", height * ratio - 16); } }); -]]>a labelblabelsa class+public() boolvoid-private() intvoidcloudyyyy:= 5 +]]>a labelblabelsa class+public() boolvoid-private() intvoidcloudyyyy:= 5 := a + 7 -fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersidintnamevarchar result := callThisFunction(obj, 5) midthis sideother side +fmt.Printf("%d", b)cyldiadocssix cornersa random iconoverpackdocs pagetoohard o saysinglepersona queuea squarea step at a timedatausersidintnamevarchar result := callThisFunction(obj, 5) midthis sideother side diff --git a/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg b/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg index 1bf933cc1..4c4b64541 100644 --- a/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_column_styles/dagre/sketch.exp.svg @@ -44,7 +44,7 @@ svgEl.setAttribute("height", height * ratio - 16); } }); -]]>Humor in the CourtCould you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.Humor in the Court2Could you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.BatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)voidBatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)void +]]>Humor in the CourtCould you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.Humor in the Court2Could you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.BatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)voidBatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)void \ No newline at end of file diff --git a/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg b/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg index 03f8b18c1..08f8ef62d 100644 --- a/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/sql_table_column_styles/elk/sketch.exp.svg @@ -44,7 +44,7 @@ svgEl.setAttribute("height", height * ratio - 16); } }); -]]>Humor in the CourtCould you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.Humor in the Court2Could you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.BatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)voidBatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)void +]]>Humor in the CourtCould you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.Humor in the Court2Could you see him from where you were standing?I could see his head.And where was his head?Just above his shoulders.BatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)voidBatchManager-numint-timeoutint-pid+getStatus()Enum+getJobs()Job[]+setTimeout(seconds int)void \ No newline at end of file diff --git a/testdata/d2compiler/TestCompile/near_sequence.exp.json b/testdata/d2compiler/TestCompile/near_sequence.exp.json new file mode 100644 index 000000000..dc86eb89c --- /dev/null +++ b/testdata/d2compiler/TestCompile/near_sequence.exp.json @@ -0,0 +1,12 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/near_sequence.d2,4:8:45-4:11:48", + "errmsg": "d2/testdata/d2compiler/TestCompile/near_sequence.d2:5:9: near keys cannot be set to an object within sequence diagrams" + } + ] + } +}