diff --git a/Program.cs b/Program.cs index 97f51a2..f1ca1a0 100644 --- a/Program.cs +++ b/Program.cs @@ -1014,13 +1014,13 @@ static class GraphLayoutBuilder Attr = { LayerDirection = LayerDirection.TB, - NodeSeparation = 36, - LayerSeparation = 72, + NodeSeparation = partition.Family == GraphFamily.ControlFlow ? 56 : 42, + LayerSeparation = partition.Family == GraphFamily.ControlFlow ? 104 : 86, BackgroundColor = Color.White, }, }; - graph.LayoutAlgorithmSettings = CreateLayoutSettings(request.LayoutMode); + graph.LayoutAlgorithmSettings = CreateLayoutSettings(request.LayoutMode, partition); var metricsByNodeId = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var noteId in partition.IncludedNoteIds.OrderBy(id => model.DepthById.GetValueOrDefault(id)).ThenBy(id => id, StringComparer.OrdinalIgnoreCase)) @@ -1132,16 +1132,18 @@ static class GraphLayoutBuilder node.Attr.LineWidth = 1.2; } - private static Microsoft.Msagl.Core.Layout.LayoutAlgorithmSettings CreateLayoutSettings(LayoutMode layoutMode) + private static Microsoft.Msagl.Core.Layout.LayoutAlgorithmSettings CreateLayoutSettings( + LayoutMode layoutMode, + GraphPartitionModel partition) { return layoutMode switch { LayoutMode.Mds => new MdsLayoutSettings { - NodeSeparation = 48, - ScaleX = 1.2, - ScaleY = 1.2, - IterationsWithMajorization = 40, + NodeSeparation = partition.Family == GraphFamily.ControlFlow ? 88 : 60, + ScaleX = partition.Family == GraphFamily.ControlFlow ? 1.45 : 1.24, + ScaleY = partition.Family == GraphFamily.ControlFlow ? 1.3 : 1.38, + IterationsWithMajorization = partition.Family == GraphFamily.ControlFlow ? 52 : 46, EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.StraightLine, @@ -1149,8 +1151,8 @@ static class GraphLayoutBuilder }, _ => new SugiyamaLayoutSettings { - NodeSeparation = 40, - LayerSeparation = 80, + NodeSeparation = partition.Family == GraphFamily.ControlFlow ? 90 : 56, + LayerSeparation = partition.Family == GraphFamily.ControlFlow ? 132 : 112, EdgeRoutingSettings = { EdgeRoutingMode = EdgeRoutingMode.Spline, diff --git a/RichSvgRenderer.cs b/RichSvgRenderer.cs index 4439c1e..94a0154 100644 --- a/RichSvgRenderer.cs +++ b/RichSvgRenderer.cs @@ -9,364 +9,423 @@ static class RichSvgRenderer public static string Render(LayoutReport report, Graph graph) { var theme = Theme.For(report.GraphKey); - var degreeByNodeId = CalculateDegrees(report); - var layout = LayoutFrame.Create(report); - var nodes = report.Nodes - .Select(node => NodeVisual.Create(node, layout, theme, degreeByNodeId.GetValueOrDefault(node.Id))) + var degreeByNodeId = CalculateDegrees(graph); + var rawNodes = BuildRawNodes(report, graph, degreeByNodeId); + var projection = Projection.Create(report, rawNodes); + var projectedNodes = rawNodes + .Select(node => ProjectedNode.Create(node, projection, theme)) .ToArray(); - var nodeLookup = nodes.ToDictionary(node => node.Id, StringComparer.OrdinalIgnoreCase); + var projectedLookup = projectedNodes.ToDictionary(node => node.Id, StringComparer.OrdinalIgnoreCase); + var canvas = CanvasLayout.Create(projectedNodes); var document = new StringBuilder(); document.AppendLine(""""""); document.AppendLine( - $""""""); + $""""""); AppendDefs(document, theme); document.AppendLine($""" {Escape(report.GraphTitle)} ({Escape(report.GraphKey)})"""); document.AppendLine( - $""" EpiphanyGraph custom renderer output for {Escape(report.GraphKey)} using {Escape(report.LayoutMode)} layout with {report.NodeCount} nodes and {report.EdgeCount} edges."""); - document.AppendLine($""" """); - document.AppendLine($""" """); - document.AppendLine($""" """); - AppendDepthGuides(document, report, layout, theme); - AppendHeader(document, report, layout, theme); - AppendEdges(document, graph, nodeLookup, layout, theme); - AppendNodes(document, nodes, theme); - AppendLegend(document, report, layout, theme); + $""" EpiphanyGraph rich renderer output for {Escape(report.GraphKey)} using {Escape(report.LayoutMode)} layout with {report.NodeCount} nodes and {report.EdgeCount} edges."""); + document.AppendLine($""" """); + document.AppendLine($""" """); + AppendGuides(document, report, rawNodes, projection, canvas, theme); + AppendHeader(document, report, canvas, theme); + AppendEdges(document, graph, projectedLookup, projection, canvas, theme); + AppendNodes(document, projectedNodes, canvas, theme); + AppendOverlay(document, report, canvas, theme); document.AppendLine(""); return document.ToString(); } + private static IReadOnlyList BuildRawNodes( + LayoutReport report, + Graph graph, + IReadOnlyDictionary degreeByNodeId) + { + var reportNodes = report.Nodes.ToDictionary(node => node.Id, StringComparer.OrdinalIgnoreCase); + return graph.Nodes + .Select(node => + { + var record = reportNodes[node.Id]; + var center = node.BoundingBox.Center; + var category = SemanticCategoryClassifier.Classify(report.GraphKey, record.Title, record.Role, record.IsEntry); + return new RawNode( + Id: record.Id, + Title: record.Title, + Depth: record.Depth, + Role: record.Role, + IsEntry: record.IsEntry, + Degree: degreeByNodeId.GetValueOrDefault(record.Id), + Category: category, + Token: CreateToken(record.Title, record.Role, record.IsEntry), + RawX: center.X, + RawY: center.Y); + }) + .OrderBy(node => node.Depth) + .ThenBy(node => node.Id, StringComparer.OrdinalIgnoreCase) + .ToArray(); + } + private static void AppendDefs(StringBuilder document, Theme theme) { document.AppendLine(" "); - document.AppendLine($""" """); + document.AppendLine(""" """); document.AppendLine($""" """); - document.AppendLine($""" """); + document.AppendLine($""" """); document.AppendLine($""" """); document.AppendLine(" "); - document.AppendLine(""" """); - document.AppendLine(""" """); + document.AppendLine(""" """); + document.AppendLine(""" """); document.AppendLine(""" """); document.AppendLine(" "); - document.AppendLine($""" """); - document.AppendLine($""" """); + document.AppendLine(""" """); + document.AppendLine($""" """); document.AppendLine(" "); - document.AppendLine(""" """); - document.AppendLine(""" """); - document.AppendLine(""" """); + document.AppendLine(""" """); + document.AppendLine(""" """); + document.AppendLine(""" """); document.AppendLine(" "); - document.AppendLine($""" """); - document.AppendLine($""" """); + document.AppendLine($""" """); + document.AppendLine($""" """); document.AppendLine(" "); - document.AppendLine(""" """); + document.AppendLine($""" """); document.AppendLine(""" """); document.AppendLine(" "); document.AppendLine(" "); } - private static void AppendDepthGuides(StringBuilder document, LayoutReport report, LayoutFrame layout, Theme theme) + private static void AppendGuides( + StringBuilder document, + LayoutReport report, + IReadOnlyList rawNodes, + Projection projection, + CanvasLayout canvas, + Theme theme) { - var depths = report.Nodes - .Select(node => node.Depth) - .Where(depth => depth >= 0) - .Distinct() - .OrderBy(depth => depth) + switch (projection.Kind) + { + case ProjectionKind.Arc: + AppendArcGuides(document, rawNodes, projection, canvas, theme); + break; + default: + AppendCartesianGuides(document, rawNodes, projection, canvas, theme); + break; + } + } + + private static void AppendArcGuides( + StringBuilder document, + IReadOnlyList rawNodes, + Projection projection, + CanvasLayout canvas, + Theme theme) + { + var depthGroups = rawNodes + .Where(node => node.Depth >= 0) + .GroupBy(node => node.Depth) + .OrderBy(group => group.Key) .ToArray(); - if (depths.Length == 0) + if (depthGroups.Length == 0) { return; } - var depthMax = depths.Max(); - document.AppendLine(""" """); - - foreach (var depth in depths) + document.AppendLine(""" """); + foreach (var group in depthGroups) { - var y = layout.GraphAreaY + (layout.GraphAreaHeight * ((depth + 0.5) / (depthMax + 1.0))); - var lineColor = theme.GetDepthAccent(depth, GraphPartitionNodeRole.Primary.ToApiValue()); + var averageY = group.Average(node => node.RawY); + var radius = projection.GetArcRadius(averageY); + var path = BuildArcGuidePath(projection, radius, canvas); + var color = theme.GetAccent(group.First().Category, false); + var labelPoint = projection.ProjectArcLabel(radius); + var labelCanvas = canvas.Transform(labelPoint); document.AppendLine( - $""" """); + $""" """); document.AppendLine( - $""" DEPTH {depth}"""); + $""" DEPTH {group.Key}"""); } document.AppendLine(" "); } - private static void AppendHeader(StringBuilder document, LayoutReport report, LayoutFrame layout, Theme theme) + private static void AppendCartesianGuides( + StringBuilder document, + IReadOnlyList rawNodes, + Projection projection, + CanvasLayout canvas, + Theme theme) + { + var depthGroups = rawNodes + .Where(node => node.Depth >= 0) + .GroupBy(node => node.Depth) + .OrderBy(group => group.Key) + .ToArray(); + + if (depthGroups.Length == 0) + { + return; + } + + document.AppendLine(""" """); + foreach (var group in depthGroups) + { + var averageY = group.Average(node => node.RawY); + var lineStart = canvas.Transform(projection.Project(new Microsoft.Msagl.Core.Geometry.Point(projection.RawMinX, averageY))); + var lineEnd = canvas.Transform(projection.Project(new Microsoft.Msagl.Core.Geometry.Point(projection.RawMaxX, averageY))); + var color = theme.GetAccent(group.First().Category, false); + document.AppendLine( + $""" """); + document.AppendLine( + $""" DEPTH {group.Key}"""); + } + + document.AppendLine(" "); + } + + private static string BuildArcGuidePath(Projection projection, double radius, CanvasLayout canvas) + { + var points = Enumerable.Range(0, 40) + .Select(index => + { + var t = index / 39.0; + var point = projection.ProjectArcPoint(radius, t); + return canvas.Transform(point); + }) + .ToArray(); + return BuildPolylinePath(points); + } + + private static void AppendHeader(StringBuilder document, LayoutReport report, CanvasLayout canvas, Theme theme) { - var familyLabel = report.GraphKey.Equals("control-flow", StringComparison.OrdinalIgnoreCase) - ? "CONTROL FLOW" - : "SOURCE TREE"; var subtitle = $"{report.LayoutMode.ToUpperInvariant()} layout | rich renderer | {report.NodeCount} nodes | {report.EdgeCount} edges"; document.AppendLine(""" """); document.AppendLine( - $""" """); + $""" """); document.AppendLine( - $""" {Escape(report.GraphTitle)}"""); + $""" {Escape(report.GraphTitle)}"""); document.AppendLine( - $""" {Escape(subtitle)}"""); - document.AppendLine( - $""" """); - document.AppendLine( - $""" {familyLabel}"""); + $""" {Escape(subtitle)}"""); + + var pills = new[] + { + ("GRAPH", report.GraphKey.ToUpperInvariant()), + ("LAYOUT", report.LayoutMode.ToUpperInvariant()), + ("RENDER", "RICH"), + }; + + var pillX = canvas.Width - 24; + for (var i = pills.Length - 1; i >= 0; i--) + { + var width = 110.0; + pillX -= width; + document.AppendLine( + $""" """); + document.AppendLine( + $""" {Escape(pills[i].Item2)}"""); + pillX -= 10; + } + document.AppendLine(" "); } private static void AppendEdges( StringBuilder document, Graph graph, - IReadOnlyDictionary nodeLookup, - LayoutFrame layout, + IReadOnlyDictionary projectedLookup, + Projection projection, + CanvasLayout canvas, Theme theme) { document.AppendLine(""" """); - foreach (var edge in graph.Edges) { - if (!nodeLookup.TryGetValue(edge.SourceNode.Id, out var source) || !nodeLookup.TryGetValue(edge.TargetNode.Id, out var target)) + if (!projectedLookup.TryGetValue(edge.SourceNode.Id, out var source) || + !projectedLookup.TryGetValue(edge.TargetNode.Id, out var target)) { continue; } var isMuted = source.Role == GraphPartitionNodeRole.Anchor.ToApiValue() || target.Role == GraphPartitionNodeRole.Anchor.ToApiValue(); - var path = BuildEdgePath(edge, source, target, layout); - var stroke = isMuted ? "#94A3B8" : theme.EdgeAccent; - var opacity = isMuted ? "0.28" : "0.52"; - var width = isMuted ? "1.3" : "1.8"; - var marker = isMuted ? "url(#arrow-muted)" : "url(#arrow-accent)"; + var sampledPoints = SampleEdge(edge.EdgeCurve ?? edge.GeometryEdge?.Curve, source, target); + var canvasPoints = sampledPoints + .Select(point => canvas.Transform(projection.Project(point))) + .ToArray(); + if (canvasPoints.Length < 2) + { + continue; + } document.AppendLine( - $""" """); + $""" """); } document.AppendLine(" "); } - private static void AppendNodes(StringBuilder document, IReadOnlyList nodes, Theme theme) + private static void AppendNodes( + StringBuilder document, + IReadOnlyList projectedNodes, + CanvasLayout canvas, + Theme theme) { document.AppendLine(""" """); - - foreach (var node in nodes.OrderBy(node => node.Role == GraphPartitionNodeRole.Anchor.ToApiValue()).ThenBy(node => node.Depth).ThenBy(node => node.Id, StringComparer.OrdinalIgnoreCase)) + foreach (var node in projectedNodes.OrderBy(node => node.IsEntry ? 1 : 0).ThenBy(node => node.Role == GraphPartitionNodeRole.Anchor.ToApiValue() ? 0 : 1)) { - var titleLines = WrapLabel(node.Title, node.TitleCharacterLimit, 3); - var titleY = node.Y + 31; - var titleX = node.X + 18; - var bandHeight = Math.Min(10, Math.Max(6, node.Height * 0.16)); - var badgeVisible = node.DegreeBadgeVisible; - var badgeRadius = 12.5; - var badgeCx = node.X + node.Width - 18; - var badgeCy = node.Y + 18; - var groupFilter = node.IsEntry ? "url(#entry-glow)" : "url(#node-glow)"; + var center = canvas.Transform(node.LocalCenter); + var labelX = center.X - node.LabelWidth / 2.0; + var labelY = center.Y + node.Radius + 9; + var badgeCx = center.X + node.Radius * 0.78; + var badgeCy = center.Y - node.Radius * 0.78; document.AppendLine( - $""" """); + $""" """); if (node.IsEntry) { document.AppendLine( - $""" """); + $""" """); } - document.AppendLine( - $""" """); - document.AppendLine( - $""" """); - document.AppendLine( - $""" """); - document.AppendLine( - $""" {Escape(node.IconTextValue)}"""); - - if (badgeVisible) + if (node.Role == GraphPartitionNodeRole.Anchor.ToApiValue()) + { + var diamond = BuildDiamond(center.X, center.Y, node.Radius + 1.5); + document.AppendLine( + $""" """); + } + else { document.AppendLine( - $""" """); - document.AppendLine( - $""" {node.Degree}"""); - } - - for (var i = 0; i < titleLines.Count; i++) - { - document.AppendLine( - $""" {Escape(titleLines[i])}"""); + $""" """); } document.AppendLine( - $""" {Escape(node.Subtitle)}"""); + $""" """); + document.AppendLine( + $""" {Escape(node.Token)}"""); + + document.AppendLine( + $""" """); + + for (var i = 0; i < node.LabelLines.Count; i++) + { + document.AppendLine( + $""" {Escape(node.LabelLines[i])}"""); + } + + if (node.ShowBadge) + { + document.AppendLine( + $""" """); + document.AppendLine( + $""" {node.Degree}"""); + } + document.AppendLine(" "); } document.AppendLine(" "); } - private static void AppendLegend(StringBuilder document, LayoutReport report, LayoutFrame layout, Theme theme) + private static void AppendOverlay(StringBuilder document, LayoutReport report, CanvasLayout canvas, Theme theme) { - document.AppendLine(""" """); - document.AppendLine( - $""" """); - document.AppendLine( - $""" Render Notes"""); - document.AppendLine( - $""" custom SVG over MSAGL coordinates"""); - - AppendLegendStat(document, layout.SidebarX + 24, layout.GraphAreaY + 96, "Nodes", report.NodeCount.ToString(CultureInfo.InvariantCulture), theme); - AppendLegendStat(document, layout.SidebarX + 24, layout.GraphAreaY + 142, "Edges", report.EdgeCount.ToString(CultureInfo.InvariantCulture), theme); - AppendLegendStat(document, layout.SidebarX + 24, layout.GraphAreaY + 188, "Layout", report.LayoutMode.ToUpperInvariant(), theme); - - var swatchY = layout.GraphAreaY + 256; - AppendLegendSwatch(document, layout.SidebarX + 24, swatchY, theme.EntryAccent, "Entry", "seed or canonical root", theme); - AppendLegendSwatch(document, layout.SidebarX + 24, swatchY + 48, theme.GetDepthAccent(2, GraphPartitionNodeRole.Primary.ToApiValue()), "Primary", "main partition member", theme); - AppendLegendSwatch(document, layout.SidebarX + 24, swatchY + 96, "#94A3B8", "Anchor", "cross-family tether node", theme); - AppendLegendSwatch(document, layout.SidebarX + 24, swatchY + 144, theme.BadgeFill, "Degree Badge", "total edge count on node", theme); + var note = report.GraphKey.Equals("source-tree", StringComparison.OrdinalIgnoreCase) + ? "Arc projection over MSAGL coordinates. More map, less paperwork." + : "Compact glyph rendering over MSAGL coordinates. Still not magic, just less beige."; + document.AppendLine(""" """); document.AppendLine( - $""" The raw MSAGL SVG still exists. This one is just trying harder."""); - document.AppendLine( - $""" Use the benchmark to decide whether it earned the extra attitude."""); + $""" {Escape(note)}"""); document.AppendLine(" "); } - private static void AppendLegendStat(StringBuilder document, double x, double y, string label, string value, Theme theme) + private static IReadOnlyList SampleEdge(ICurve? curve, ProjectedNode source, ProjectedNode target) { - document.AppendLine( - $""" """); - document.AppendLine( - $""" {Escape(label.ToUpperInvariant())}"""); - document.AppendLine( - $""" {Escape(value)}"""); - } - - private static void AppendLegendSwatch(StringBuilder document, double x, double y, string color, string label, string note, Theme theme) - { - document.AppendLine( - $""" """); - document.AppendLine( - $""" {Escape(label)}"""); - document.AppendLine( - $""" {Escape(note)}"""); - } - - private static string BuildEdgePath(Edge edge, NodeVisual source, NodeVisual target, LayoutFrame layout) - { - var curve = edge.EdgeCurve ?? edge.GeometryEdge?.Curve; - if (curve is not null) + if (curve is null) { - return SampleCurvePath(curve, layout); + return + [ + new Microsoft.Msagl.Core.Geometry.Point(source.RawCenter.X, source.RawCenter.Y), + new Microsoft.Msagl.Core.Geometry.Point(target.RawCenter.X, target.RawCenter.Y) + ]; } - return BuildFallbackEdgePath(source, target); - } - - private static string SampleCurvePath(ICurve curve, LayoutFrame layout) - { - var sampleCount = Math.Clamp((int)Math.Ceiling(curve.Length / 28.0), 8, 64); - var parameters = Enumerable.Range(0, sampleCount + 1) - .Select(index => curve.ParStart + ((curve.ParEnd - curve.ParStart) * index / sampleCount)) + var sampleCount = Math.Clamp((int)Math.Ceiling(curve.Length / 24.0), 10, 84); + return Enumerable.Range(0, sampleCount + 1) + .Select(index => curve[curve.ParStart + ((curve.ParEnd - curve.ParStart) * index / sampleCount)]) .ToArray(); - var points = parameters - .Select(parameter => TransformPoint(curve[parameter], layout)) - .ToArray(); - - if (points.Length == 0) - { - return string.Empty; - } - - var builder = new StringBuilder(); - builder.Append($"M {Fmt(points[0].X)} {Fmt(points[0].Y)}"); - for (var i = 1; i < points.Length; i++) - { - builder.Append($" L {Fmt(points[i].X)} {Fmt(points[i].Y)}"); - } - - return builder.ToString(); } - private static string BuildFallbackEdgePath(NodeVisual source, NodeVisual target) + private static IReadOnlyDictionary CalculateDegrees(Graph graph) { - var dx = target.CenterX - source.CenterX; - var dy = target.CenterY - source.CenterY; - var start = ResolveRectAnchor(source.CenterX, source.CenterY, source.Width / 2.0, source.Height / 2.0, dx, dy); - var end = ResolveRectAnchor(target.CenterX, target.CenterY, target.Width / 2.0, target.Height / 2.0, -dx, -dy); - - var controlRatio = Math.Abs(dx) > Math.Abs(dy) ? 0.34 : 0.18; - var c1x = start.X + dx * controlRatio; - var c1y = start.Y + dy * 0.08; - var c2x = end.X - dx * controlRatio; - var c2y = end.Y - dy * 0.08; - - return $"M {Fmt(start.X)} {Fmt(start.Y)} C {Fmt(c1x)} {Fmt(c1y)}, {Fmt(c2x)} {Fmt(c2y)}, {Fmt(end.X)} {Fmt(end.Y)}"; - } - - private static (double X, double Y) TransformPoint(Microsoft.Msagl.Core.Geometry.Point point, LayoutFrame layout) => - ( - X: layout.GraphAreaX + (point.X - layout.MinLeft), - Y: layout.GraphAreaY + (layout.MaxTop - point.Y) - ); - - private static (double X, double Y) ResolveRectAnchor(double centerX, double centerY, double halfWidth, double halfHeight, double dx, double dy) - { - if (Math.Abs(dx) < 0.001 && Math.Abs(dy) < 0.001) + var degrees = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (var node in graph.Nodes) { - return (centerX, centerY); + degrees[node.Id] = 0; } - var scale = 1.0 / Math.Max(Math.Abs(dx) / Math.Max(halfWidth, 1), Math.Abs(dy) / Math.Max(halfHeight, 1)); - return (centerX + dx * scale, centerY + dy * scale); - } - - private static Dictionary CalculateDegrees(LayoutReport report) - { - var degrees = report.Nodes.ToDictionary(node => node.Id, _ => 0, StringComparer.OrdinalIgnoreCase); - foreach (var edge in report.Edges) + foreach (var edge in graph.Edges) { - degrees[edge.SourceId] = degrees.GetValueOrDefault(edge.SourceId) + 1; - degrees[edge.TargetId] = degrees.GetValueOrDefault(edge.TargetId) + 1; + degrees[edge.SourceNode.Id] = degrees.GetValueOrDefault(edge.SourceNode.Id) + 1; + degrees[edge.TargetNode.Id] = degrees.GetValueOrDefault(edge.TargetNode.Id) + 1; } return degrees; } - private static IReadOnlyList WrapLabel(string label, int maxChars, int maxLines) + private static string CreateToken(string title, string role, bool isEntry) { - if (string.IsNullOrWhiteSpace(label)) + if (isEntry) + { + return "E"; + } + + if (role == GraphPartitionNodeRole.Anchor.ToApiValue()) + { + return "A"; + } + + var parts = title + .Split([' ', '/', '-', '_'], StringSplitOptions.RemoveEmptyEntries) + .Where(part => !StopWords.Contains(part)) + .Select(part => part.Trim()) + .Where(part => part.Length > 0) + .ToArray(); + + if (parts.Length == 0) + { + return "N"; + } + + if (parts.Length == 1) + { + return parts[0].Length >= 2 + ? parts[0][..2].ToUpperInvariant() + : parts[0].ToUpperInvariant(); + } + + return $"{char.ToUpperInvariant(parts[0][0])}{char.ToUpperInvariant(parts[1][0])}"; + } + + private static IReadOnlyList WrapLabel(string title, int maxChars, int maxLines) + { + if (string.IsNullOrWhiteSpace(title)) { return ["Untitled"]; } - var tokens = label.Split(' ', StringSplitOptions.RemoveEmptyEntries); - if (tokens.Length == 0) - { - return [label]; - } - + var tokens = title.Split(' ', StringSplitOptions.RemoveEmptyEntries); var lines = new List(); var current = new StringBuilder(); foreach (var token in tokens) { - if (token.Length > maxChars) - { - Flush(); - foreach (var chunk in SplitLongToken(token, maxChars)) - { - lines.Add(chunk); - if (lines.Count == maxLines) - { - lines[^1] = Ellipsize(lines[^1], maxChars); - return lines; - } - } - - continue; - } - var candidateLength = current.Length == 0 ? token.Length : current.Length + 1 + token.Length; - if (candidateLength > maxChars) + if (candidateLength > maxChars && current.Length > 0) { - Flush(); + lines.Add(current.ToString()); + current.Clear(); } if (current.Length > 0) @@ -375,192 +434,433 @@ static class RichSvgRenderer } current.Append(token); + + if (lines.Count == maxLines) + { + break; + } } - Flush(); - - if (lines.Count > maxLines) + if (current.Length > 0 && lines.Count < maxLines) { - lines = lines.Take(maxLines).ToList(); + lines.Add(current.ToString()); + } + + if (lines.Count == 0) + { + lines.Add(title); } if (lines.Count == maxLines && tokens.Length > 0) { - lines[^1] = Ellipsize(lines[^1], maxChars); + var lastLine = lines[^1]; + if (lastLine.Length > maxChars - 3) + { + lines[^1] = $"{lastLine[..Math.Max(1, maxChars - 3)]}..."; + } } return lines; - - void Flush() - { - if (current.Length == 0) - { - return; - } - - lines.Add(current.ToString()); - current.Clear(); - } } - private static IEnumerable SplitLongToken(string token, int maxChars) + private static string BuildPolylinePath(IReadOnlyList<(double X, double Y)> points) { - for (var i = 0; i < token.Length; i += maxChars) + if (points.Count == 0) { - var length = Math.Min(maxChars, token.Length - i); - yield return token.Substring(i, length); + return string.Empty; } + + var builder = new StringBuilder(); + builder.Append($"M {Fmt(points[0].X)} {Fmt(points[0].Y)}"); + for (var i = 1; i < points.Count; i++) + { + builder.Append($" L {Fmt(points[i].X)} {Fmt(points[i].Y)}"); + } + + return builder.ToString(); } - private static string Ellipsize(string value, int maxChars) + private static string BuildDiamond(double centerX, double centerY, double radius) => + $"M {Fmt(centerX)} {Fmt(centerY - radius)} L {Fmt(centerX + radius)} {Fmt(centerY)} L {Fmt(centerX)} {Fmt(centerY + radius)} L {Fmt(centerX - radius)} {Fmt(centerY)} Z"; + + private static string ToDomId(string prefix, params string[] parts) { - if (value.Length <= maxChars) + var normalized = string.Join("-", parts) + .ToLowerInvariant() + .Select(ch => char.IsLetterOrDigit(ch) ? ch : '-') + .ToArray(); + var text = new string(normalized); + while (text.Contains("--", StringComparison.Ordinal)) { - return value; + text = text.Replace("--", "-", StringComparison.Ordinal); } - if (maxChars <= 1) - { - return "…"; - } - - return $"{value[..(maxChars - 1)]}…"; + return $"{prefix}-{text.Trim('-')}"; } - private static string Fmt(double value) => value.ToString("0.##", CultureInfo.InvariantCulture); - private static string Escape(string value) => WebUtility.HtmlEncode(value); - private static string ToDomId(string prefix, params string[] values) + private static string Fmt(double value) => value.ToString("0.##", CultureInfo.InvariantCulture); + + private static readonly HashSet StopWords = new(StringComparer.OrdinalIgnoreCase) { - var joined = string.Join("-", values); - var normalized = new string(joined - .Select(ch => char.IsLetterOrDigit(ch) ? char.ToLowerInvariant(ch) : '-') - .ToArray()); - while (normalized.Contains("--", StringComparison.Ordinal)) - { - normalized = normalized.Replace("--", "-", StringComparison.Ordinal); - } + "and", + "the", + "of", + "for", + "to", + "a", + "an", + "with", + }; - return $"{prefix}-{normalized.Trim('-')}"; - } - - private sealed record LayoutFrame( - double CanvasWidth, - double CanvasHeight, - double GraphAreaX, - double GraphAreaY, - double GraphAreaWidth, - double GraphAreaHeight, - double SidebarX, - double SidebarWidth, - double MinLeft, - double MaxTop) - { - public static LayoutFrame Create(LayoutReport report) - { - const double outerPadding = 54; - const double headerHeight = 108; - const double footerHeight = 38; - const double sidebarWidth = 280; - const double sidebarGap = 30; - - var minLeft = report.Nodes.Min(node => node.Bounds.Left); - var maxRight = report.Nodes.Max(node => node.Bounds.Left + node.Bounds.Width); - var maxTop = report.Nodes.Max(node => node.Bounds.Bottom + node.Bounds.Height); - var minBottom = report.Nodes.Min(node => node.Bounds.Bottom); - - var graphWidth = Math.Max(640, maxRight - minLeft); - var graphHeight = Math.Max(520, maxTop - minBottom); - var graphAreaX = outerPadding; - var graphAreaY = headerHeight; - var canvasWidth = outerPadding * 2 + graphWidth + sidebarGap + sidebarWidth; - var canvasHeight = graphAreaY + graphHeight + outerPadding + footerHeight; - var sidebarX = graphAreaX + graphWidth + sidebarGap; - - return new LayoutFrame( - CanvasWidth: canvasWidth, - CanvasHeight: canvasHeight, - GraphAreaX: graphAreaX, - GraphAreaY: graphAreaY, - GraphAreaWidth: graphWidth, - GraphAreaHeight: graphHeight, - SidebarX: sidebarX, - SidebarWidth: sidebarWidth, - MinLeft: minLeft, - MaxTop: maxTop); - } - } - - private sealed record NodeVisual( + private sealed record RawNode( string Id, string Title, int Depth, string Role, bool IsEntry, int Degree, - bool DegreeBadgeVisible, - double X, - double Y, - double Width, - double Height, - double CenterX, - double CenterY, - double CornerRadius, - double StrokeWidth, - double TitleFontSize, - int TitleCharacterLimit, - string Subtitle, - string PanelFill, - string PanelOpacity, - string Stroke, - string Accent, - string TitleColor, - string IconStroke, - string IconText, - string IconTextValue) - { - public static NodeVisual Create(LayoutNodeRecord node, LayoutFrame layout, Theme theme, int degree) - { - var x = layout.GraphAreaX + (node.Bounds.Left - layout.MinLeft); - var y = layout.GraphAreaY + (layout.MaxTop - (node.Bounds.Bottom + node.Bounds.Height)); - var accent = theme.GetDepthAccent(node.Depth, node.Role, node.IsEntry); - var isAnchor = node.Role == GraphPartitionNodeRole.Anchor.ToApiValue(); - var subtitle = node.IsEntry - ? "ENTRY NODE" - : isAnchor - ? "ANCHOR" - : $"DEPTH {Math.Max(node.Depth, 0)}"; - var characterLimit = Math.Clamp((int)Math.Floor((node.Bounds.Width - 38) / 7.15), 12, 28); - var degreeBadgeVisible = degree >= 3 || node.IsEntry; + SemanticCategory Category, + string Token, + double RawX, + double RawY); - return new NodeVisual( + private sealed record ProjectedNode( + string Id, + string Title, + int Depth, + string Role, + bool IsEntry, + int Degree, + SemanticCategory Category, + string Token, + Microsoft.Msagl.Core.Geometry.Point RawCenter, + (double X, double Y) LocalCenter, + double Radius, + double StrokeWidth, + double TokenFontSize, + double LabelFontSize, + double LabelWidth, + double LabelHeight, + double LabelPadding, + double LineHeight, + bool ShowBadge, + string Fill, + string InnerFill, + string Stroke, + string InnerStroke, + string TokenColor, + string LabelFill, + string LabelText, + IReadOnlyList LabelLines) + { + public static ProjectedNode Create(RawNode node, Projection projection, Theme theme) + { + var localCenter = projection.Project(new Microsoft.Msagl.Core.Geometry.Point(node.RawX, node.RawY)); + var radius = node.IsEntry + ? 18 + : node.Role == GraphPartitionNodeRole.Anchor.ToApiValue() + ? 11.5 + : Math.Min(16.5, 12.5 + node.Degree * 0.12); + var labelFontSize = projection.Kind == ProjectionKind.Arc ? 10.6 : 11.3; + var labelLines = WrapLabel(node.Title, projection.Kind == ProjectionKind.Arc ? 18 : 20, 2); + var labelPadding = 7.5; + var lineHeight = labelFontSize + 4.5; + var labelWidth = Math.Max( + radius * 2 + 10, + labelLines.Max(line => line.Length) * labelFontSize * 0.57 + labelPadding * 2); + var labelHeight = labelLines.Count * lineHeight + labelPadding * 2 - 2; + var accent = theme.GetAccent(node.Category, node.IsEntry); + + return new ProjectedNode( Id: node.Id, Title: node.Title, Depth: node.Depth, Role: node.Role, IsEntry: node.IsEntry, - Degree: degree, - DegreeBadgeVisible: degreeBadgeVisible, - X: x, - Y: y, - Width: node.Bounds.Width, - Height: node.Bounds.Height, - CenterX: x + node.Bounds.Width / 2.0, - CenterY: y + node.Bounds.Height / 2.0, - CornerRadius: isAnchor ? 18 : 22, - StrokeWidth: node.IsEntry ? 2.1 : isAnchor ? 1.25 : 1.55, - TitleFontSize: isAnchor ? 11.5 : node.IsEntry ? 15 : 13.5, - TitleCharacterLimit: characterLimit, - Subtitle: subtitle, - PanelFill: isAnchor ? "#111827" : "#08111F", - PanelOpacity: isAnchor ? "0.78" : "0.88", - Stroke: node.IsEntry ? theme.EntryAccent : isAnchor ? "#94A3B8" : accent, - Accent: node.IsEntry ? theme.EntryAccent : accent, - TitleColor: node.IsEntry ? "#FFF8E8" : "#F8FAFC", - IconStroke: isAnchor ? "#E2E8F0" : "#FFFFFF", - IconText: isAnchor ? "#0F172A" : "#08111F", - IconTextValue: node.IsEntry ? "E" : isAnchor ? "A" : theme.IconLetter); + Degree: node.Degree, + Category: node.Category, + Token: node.Token, + RawCenter: new Microsoft.Msagl.Core.Geometry.Point(node.RawX, node.RawY), + LocalCenter: localCenter, + Radius: radius, + StrokeWidth: node.IsEntry ? 2.2 : node.Role == GraphPartitionNodeRole.Anchor.ToApiValue() ? 1.35 : 1.55, + TokenFontSize: node.Token.Length > 1 ? 9.2 : 10.6, + LabelFontSize: labelFontSize, + LabelWidth: labelWidth, + LabelHeight: labelHeight, + LabelPadding: labelPadding, + LineHeight: lineHeight, + ShowBadge: node.Degree >= 4 || node.IsEntry, + Fill: accent, + InnerFill: theme.NodeInnerFill, + Stroke: node.IsEntry ? "#FDE68A" : accent, + InnerStroke: accent, + TokenColor: node.Role == GraphPartitionNodeRole.Anchor.ToApiValue() ? "#0F172A" : "#F8FAFC", + LabelFill: theme.LabelFill, + LabelText: theme.LabelText, + LabelLines: labelLines); + } + } + + private sealed record CanvasLayout( + double Width, + double Height, + double OffsetX, + double OffsetY) + { + public static CanvasLayout Create(IReadOnlyList nodes) + { + const double padding = 52; + const double headerHeight = 94; + const double footerHeight = 36; + + var minX = nodes.Min(node => Math.Min(node.LocalCenter.X - node.Radius - 12, node.LocalCenter.X - node.LabelWidth / 2.0)); + var maxX = nodes.Max(node => Math.Max(node.LocalCenter.X + node.Radius + 12, node.LocalCenter.X + node.LabelWidth / 2.0)); + var minY = nodes.Min(node => node.LocalCenter.Y - node.Radius - 22); + var maxY = nodes.Max(node => node.LocalCenter.Y + node.Radius + 12 + node.LabelHeight); + + return new CanvasLayout( + Width: Math.Max(1280, maxX - minX + padding * 2), + Height: Math.Max(860, headerHeight + maxY - minY + padding + footerHeight), + OffsetX: padding - minX, + OffsetY: headerHeight + padding - minY); + } + + public (double X, double Y) Transform((double X, double Y) point) => + (point.X + OffsetX, point.Y + OffsetY); + } + + private sealed class Projection + { + public ProjectionKind Kind { get; } + public double RawMinX { get; } + public double RawMaxX { get; } + public double RawMinY { get; } + public double RawMaxY { get; } + public double ArcStartRadians { get; } + public double ArcEndRadians { get; } + public double ArcInnerRadius { get; } + public double ArcOuterRadius { get; } + public double CartesianWidth { get; } + public double CartesianHeight { get; } + public double CartesianHorizontalScale { get; } + + private Projection( + ProjectionKind kind, + double rawMinX, + double rawMaxX, + double rawMinY, + double rawMaxY, + double arcStartRadians, + double arcEndRadians, + double arcInnerRadius, + double arcOuterRadius, + double cartesianWidth, + double cartesianHeight, + double cartesianHorizontalScale) + { + Kind = kind; + RawMinX = rawMinX; + RawMaxX = rawMaxX; + RawMinY = rawMinY; + RawMaxY = rawMaxY; + ArcStartRadians = arcStartRadians; + ArcEndRadians = arcEndRadians; + ArcInnerRadius = arcInnerRadius; + ArcOuterRadius = arcOuterRadius; + CartesianWidth = cartesianWidth; + CartesianHeight = cartesianHeight; + CartesianHorizontalScale = cartesianHorizontalScale; + } + + public static Projection Create(LayoutReport report, IReadOnlyList rawNodes) + { + var rawMinX = rawNodes.Min(node => node.RawX); + var rawMaxX = rawNodes.Max(node => node.RawX); + var rawMinY = rawNodes.Min(node => node.RawY); + var rawMaxY = rawNodes.Max(node => node.RawY); + var distinctDepths = rawNodes.Where(node => node.Depth >= 0).Select(node => node.Depth).Distinct().Count(); + + if (report.GraphKey.Equals("source-tree", StringComparison.OrdinalIgnoreCase) && + report.LayoutMode.Equals("sugiyama", StringComparison.OrdinalIgnoreCase)) + { + return new Projection( + ProjectionKind.Arc, + rawMinX, + rawMaxX, + rawMinY, + rawMaxY, + arcStartRadians: DegreesToRadians(162), + arcEndRadians: DegreesToRadians(18), + arcInnerRadius: 180, + arcOuterRadius: Math.Max(430, 210 + distinctDepths * 86), + cartesianWidth: 0, + cartesianHeight: 0, + cartesianHorizontalScale: 1); + } + + var rawWidth = Math.Max(320, rawMaxX - rawMinX); + var rawHeight = Math.Max(260, rawMaxY - rawMinY); + var horizontalScale = report.GraphKey.Equals("control-flow", StringComparison.OrdinalIgnoreCase) ? 1.18 : 0.92; + var verticalScale = report.GraphKey.Equals("control-flow", StringComparison.OrdinalIgnoreCase) ? 1.22 : 1.04; + + return new Projection( + ProjectionKind.Cartesian, + rawMinX, + rawMaxX, + rawMinY, + rawMaxY, + arcStartRadians: 0, + arcEndRadians: 0, + arcInnerRadius: 0, + arcOuterRadius: 0, + cartesianWidth: rawWidth * horizontalScale, + cartesianHeight: rawHeight * verticalScale, + cartesianHorizontalScale: horizontalScale); + } + + public (double X, double Y) Project(Microsoft.Msagl.Core.Geometry.Point point) + { + var nx = Normalize(point.X, RawMinX, RawMaxX); + var ny = Normalize(point.Y, RawMinY, RawMaxY); + + return Kind switch + { + ProjectionKind.Arc => ProjectArc(nx, 1 - ny), + _ => ProjectCartesian(nx, ny), + }; + } + + public double GetArcRadius(double rawY) + { + var ny = Normalize(rawY, RawMinY, RawMaxY); + return ArcInnerRadius + ((1 - ny) * (ArcOuterRadius - ArcInnerRadius)); + } + + public (double X, double Y) ProjectArcPoint(double radius, double t) + { + var angle = ArcStartRadians + ((ArcEndRadians - ArcStartRadians) * t); + return PolarPoint(radius, angle); + } + + public (double X, double Y) ProjectArcLabel(double radius) + { + var angle = ArcStartRadians - DegreesToRadians(7); + return PolarPoint(radius, angle); + } + + private (double X, double Y) ProjectArc(double nx, double radialT) + { + var angle = ArcStartRadians + ((ArcEndRadians - ArcStartRadians) * nx); + var radius = ArcInnerRadius + ((ArcOuterRadius - ArcInnerRadius) * radialT); + return PolarPoint(radius, angle); + } + + private (double X, double Y) ProjectCartesian(double nx, double ny) + { + var centeredX = (nx * 2.0) - 1.0; + var compressedX = Math.Sign(centeredX) * Math.Pow(Math.Abs(centeredX), 0.88); + var x = compressedX * (CartesianWidth / 2.0); + var y = (1 - ny) * CartesianHeight; + return (x, y); + } + + private static (double X, double Y) PolarPoint(double radius, double angle) => + (Math.Cos(angle) * radius, -Math.Sin(angle) * radius); + + private static double Normalize(double value, double min, double max) + { + var range = Math.Max(0.0001, max - min); + return Math.Clamp((value - min) / range, 0, 1); + } + + private static double DegreesToRadians(double value) => value * (Math.PI / 180.0); + } + + private enum ProjectionKind + { + Cartesian, + Arc, + } + + private enum SemanticCategory + { + Root, + Anchor, + Shared, + Client, + Server, + Simulation, + Content, + Default, + } + + private static class SemanticCategoryClassifier + { + public static SemanticCategory Classify(string graphKey, string title, string role, bool isEntry) + { + if (isEntry) + { + return SemanticCategory.Root; + } + + if (role == GraphPartitionNodeRole.Anchor.ToApiValue()) + { + return SemanticCategory.Anchor; + } + + if (title.Contains("Shared", StringComparison.OrdinalIgnoreCase)) + { + return SemanticCategory.Shared; + } + + if (title.Contains("Server", StringComparison.OrdinalIgnoreCase) || + title.Contains("Auth", StringComparison.OrdinalIgnoreCase) || + title.Contains("Persistence", StringComparison.OrdinalIgnoreCase) || + title.Contains("Serialization", StringComparison.OrdinalIgnoreCase) || + title.Contains("Bootstrap", StringComparison.OrdinalIgnoreCase) || + title.Contains("Network", StringComparison.OrdinalIgnoreCase)) + { + return SemanticCategory.Server; + } + + if (title.Contains("Client", StringComparison.OrdinalIgnoreCase) || + title.Contains("UI", StringComparison.OrdinalIgnoreCase) || + title.Contains("HUD", StringComparison.OrdinalIgnoreCase) || + title.Contains("Menu", StringComparison.OrdinalIgnoreCase) || + title.Contains("Input", StringComparison.OrdinalIgnoreCase) || + title.Contains("View", StringComparison.OrdinalIgnoreCase) || + title.Contains("Weapons", StringComparison.OrdinalIgnoreCase)) + { + return SemanticCategory.Client; + } + + if (title.Contains("Simulation", StringComparison.OrdinalIgnoreCase) || + title.Contains("Math", StringComparison.OrdinalIgnoreCase) || + title.Contains("Zone", StringComparison.OrdinalIgnoreCase) || + title.Contains("Galaxy", StringComparison.OrdinalIgnoreCase) || + title.Contains("Shader", StringComparison.OrdinalIgnoreCase) || + title.Contains("GPU", StringComparison.OrdinalIgnoreCase) || + title.Contains("Render", StringComparison.OrdinalIgnoreCase) || + title.Contains("Algorithm", StringComparison.OrdinalIgnoreCase)) + { + return SemanticCategory.Simulation; + } + + if (title.Contains("Audio", StringComparison.OrdinalIgnoreCase) || + title.Contains("Narrative", StringComparison.OrdinalIgnoreCase) || + title.Contains("Prefab", StringComparison.OrdinalIgnoreCase) || + title.Contains("Asset", StringComparison.OrdinalIgnoreCase) || + title.Contains("Corpus", StringComparison.OrdinalIgnoreCase) || + title.Contains("Data", StringComparison.OrdinalIgnoreCase) || + title.Contains("Authoring", StringComparison.OrdinalIgnoreCase)) + { + return SemanticCategory.Content; + } + + return SemanticCategory.Default; } } @@ -569,121 +869,72 @@ static class RichSvgRenderer string BackgroundStart, string BackgroundMid, string BackgroundEnd, - string GraphPanelFill, - string GraphPanelStroke, string HeaderFill, string HeaderStroke, string HeaderText, string MutedText, - string GlowColor, - string SidebarFill, - string SidebarStroke, - string StatFill, - string StatStroke, string PillFill, string PillStroke, + string LabelFill, + string LabelText, + string NodeInnerFill, + string EdgeStroke, + string GlowColor, string BadgeFill, - string BadgeText, - string EdgeAccent, - string EntryAccent, - string IconLetter, - IReadOnlyList PrimaryDepthPalette) + string BadgeText) { public static Theme For(string graphKey) { - if (graphKey.Equals("control-flow", StringComparison.OrdinalIgnoreCase)) - { - return new Theme( + return graphKey.Equals("control-flow", StringComparison.OrdinalIgnoreCase) + ? new Theme( FontFamily: "Bahnschrift, Segoe UI, sans-serif", - BackgroundStart: "#070C15", - BackgroundMid: "#161022", - BackgroundEnd: "#291017", - GraphPanelFill: "#0A1020", - GraphPanelStroke: "#F97316", + BackgroundStart: "#0C0914", + BackgroundMid: "#121424", + BackgroundEnd: "#180D12", HeaderFill: "#120E1C", HeaderStroke: "#FB7185", HeaderText: "#FFF7ED", MutedText: "#FDBA74", - GlowColor: "#FB7185", - SidebarFill: "#0B1120", - SidebarStroke: "#F97316", - StatFill: "#111827", - StatStroke: "#FB7185", - PillFill: "#2B1320", + PillFill: "#221120", PillStroke: "#FB7185", - BadgeFill: "#180E1D", - BadgeText: "#FFF7ED", - EdgeAccent: "#FB7185", - EntryAccent: "#FDE68A", - IconLetter: "C", - PrimaryDepthPalette: - [ - "#FB7185", - "#F97316", - "#F59E0B", - "#FDE68A", - "#67E8F9", - "#A78BFA" - ]); - } - - return new Theme( - FontFamily: "Bahnschrift, Segoe UI, sans-serif", - BackgroundStart: "#061019", - BackgroundMid: "#0B1529", - BackgroundEnd: "#111827", - GraphPanelFill: "#08131F", - GraphPanelStroke: "#22D3EE", - HeaderFill: "#091525", - HeaderStroke: "#38BDF8", - HeaderText: "#F8FAFC", - MutedText: "#A5F3FC", - GlowColor: "#22D3EE", - SidebarFill: "#09131F", - SidebarStroke: "#22D3EE", - StatFill: "#0F172A", - StatStroke: "#38BDF8", - PillFill: "#10263C", - PillStroke: "#22D3EE", - BadgeFill: "#0B1220", - BadgeText: "#F8FAFC", - EdgeAccent: "#22D3EE", - EntryAccent: "#FDE68A", - IconLetter: "S", - PrimaryDepthPalette: - [ - "#38BDF8", - "#22D3EE", - "#2DD4BF", - "#86EFAC", - "#C4B5FD", - "#F9A8D4" - ]); + LabelFill: "#151224", + LabelText: "#FFF7ED", + NodeInnerFill: "#10151F", + EdgeStroke: "#FB7185", + GlowColor: "#FB7185", + BadgeFill: "#140E18", + BadgeText: "#FFF7ED") + : new Theme( + FontFamily: "Bahnschrift, Segoe UI, sans-serif", + BackgroundStart: "#061019", + BackgroundMid: "#0B1424", + BackgroundEnd: "#111827", + HeaderFill: "#091525", + HeaderStroke: "#22D3EE", + HeaderText: "#F8FAFC", + MutedText: "#A5F3FC", + PillFill: "#10263C", + PillStroke: "#22D3EE", + LabelFill: "#0A1524", + LabelText: "#F8FAFC", + NodeInnerFill: "#09111D", + EdgeStroke: "#22D3EE", + GlowColor: "#22D3EE", + BadgeFill: "#0B1220", + BadgeText: "#F8FAFC"); } - public string GetDepthAccent(int depth, string role, bool isEntry = false) - { - if (isEntry) + public string GetAccent(SemanticCategory category, bool isEntry) => + isEntry ? "#FDE68A" : category switch { - return EntryAccent; - } - - if (role == GraphPartitionNodeRole.Anchor.ToApiValue()) - { - return "#94A3B8"; - } - - if (PrimaryDepthPalette.Count == 0) - { - return EdgeAccent; - } - - if (depth < 0) - { - return PrimaryDepthPalette[^1]; - } - - return PrimaryDepthPalette[depth % PrimaryDepthPalette.Count]; - } + SemanticCategory.Root => "#FDE68A", + SemanticCategory.Anchor => "#94A3B8", + SemanticCategory.Shared => "#67E8F9", + SemanticCategory.Client => "#4ADE80", + SemanticCategory.Server => "#60A5FA", + SemanticCategory.Simulation => "#C084FC", + SemanticCategory.Content => "#F472B6", + _ => "#22D3EE", + }; } }