Skip to content

Commit 0f5b9b8

Browse files
committed
fix: snake gradient solid bands under circles and proportional title sizing
- Gradient stops now use paired offsets so each circle gets a solid color band matching the circle width, with smooth gradient transitions only in the gaps between circles. - Snake title font size is now proportional to the circle labels instead of using the small theme default. Title Y position includes proper padding from the top. - Updated E2E snapshot baselines for both presentation and dracula fixtures.
1 parent 4ae51c3 commit 0f5b9b8

4 files changed

Lines changed: 67 additions & 46 deletions

File tree

src/DiagramForge/Layout/DefaultLayoutEngine.Snake.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ private static void LayoutSnakeDiagram(
2020
return;
2121

2222
double fontSize = theme.FontSize;
23-
double titleOffset = !string.IsNullOrWhiteSpace(diagram.Title) ? theme.TitleFontSize * 1.4 + 12 : 0;
23+
24+
// Snake title uses a font size proportional to the circles (set below
25+
// once snakeFontSize is known). Reserve a placeholder offset here;
26+
// it is updated after sizing.
27+
bool hasTitle = !string.IsNullOrWhiteSpace(diagram.Title);
28+
double snakeTitleFontSize = 0;
29+
double titleOffset = 0;
2430

2531
// ── Wrap all multi-word labels to two lines for larger text ───────────
2632
foreach (var node in orderedNodes)
@@ -88,6 +94,10 @@ private static void LayoutSnakeDiagram(
8894
node.Metadata["icon:y"] = iconY;
8995
}
9096

97+
// Snake title size — match the circle labels so it reads well
98+
snakeTitleFontSize = snakeFontSize;
99+
titleOffset = hasTitle ? snakeTitleFontSize * 1.4 + pad : 0;
100+
91101
// Description text blocks — proportional to circle size for readability
92102
double descFontSize = snakeFontSize * 0.85;
93103
double descMaxWidth = circleDiameter * 2.0;
@@ -209,6 +219,11 @@ private static void LayoutSnakeDiagram(
209219
diagram.Metadata["snake:segmentStops"] = segmentStops;
210220
diagram.Metadata["snake:nodeCount"] = n;
211221
diagram.Metadata["snake:descFontSize"] = descFontSize;
222+
if (hasTitle)
223+
{
224+
diagram.Metadata["titleFontSize"] = snakeTitleFontSize;
225+
diagram.Metadata["titleY"] = pad + snakeTitleFontSize;
226+
}
212227

213228
// ── Store description text positions ──────────────────────────────────
214229
for (int i = 0; i < orderedNodes.Count; i++)

src/DiagramForge/Rendering/SvgRenderer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ public string Render(Diagram diagram, Theme theme)
3636
sb.AppendLine($""" <rect width="{SvgRenderSupport.F(width)}" height="{SvgRenderSupport.F(height)}" fill="{SvgRenderSupport.Escape(theme.BackgroundColor)}" rx="{SvgRenderSupport.F(theme.BorderRadius)}" ry="{SvgRenderSupport.F(theme.BorderRadius)}"/>""");
3737
}
3838

39-
// Title
39+
// Title — diagram-type layouts may override font size / position via metadata
4040
if (!string.IsNullOrWhiteSpace(diagram.Title))
4141
{
42-
sb.AppendLine($""" <text x="{SvgRenderSupport.F(width / 2)}" y="{SvgRenderSupport.F(theme.DiagramPadding - 4)}" text-anchor="middle" font-family="{SvgRenderSupport.Escape(theme.FontFamily)}" font-size="{SvgRenderSupport.F(theme.TitleFontSize)}" font-weight="bold" fill="{SvgRenderSupport.Escape(theme.TitleTextColor)}">{SvgRenderSupport.Escape(diagram.Title)}</text>""");
42+
double titleFontSize = diagram.Metadata.TryGetValue("titleFontSize", out var tfsObj)
43+
? Convert.ToDouble(tfsObj, System.Globalization.CultureInfo.InvariantCulture)
44+
: theme.TitleFontSize;
45+
double titleY = diagram.Metadata.TryGetValue("titleY", out var tyObj)
46+
? Convert.ToDouble(tyObj, System.Globalization.CultureInfo.InvariantCulture)
47+
: theme.DiagramPadding - 4;
48+
sb.AppendLine($""" <text x="{SvgRenderSupport.F(width / 2)}" y="{SvgRenderSupport.F(titleY)}" text-anchor="middle" font-family="{SvgRenderSupport.Escape(theme.FontFamily)}" font-size="{SvgRenderSupport.F(titleFontSize)}" font-weight="bold" fill="{SvgRenderSupport.Escape(theme.TitleTextColor)}">{SvgRenderSupport.Escape(diagram.Title)}</text>""");
4349
}
4450

4551
// Groups (render behind nodes). Parents render first so nested child groups

tests/DiagramForge.E2ETests/Fixtures/conceptual-snake-dracula.expected.svg

Lines changed: 20 additions & 20 deletions
Loading

tests/DiagramForge.E2ETests/Fixtures/conceptual-snake-presentation.expected.svg

Lines changed: 23 additions & 23 deletions
Loading

0 commit comments

Comments
 (0)