Skip to content

Commit 978ecd0

Browse files
authored
Merge pull request #473 from serverlessworkflow/fix-dashboard-graph-improvements
Improved graph rendering in the Dashboard
2 parents f500741 + e52c934 commit 978ecd0

File tree

10 files changed

+39
-11
lines changed

10 files changed

+39
-11
lines changed

src/dashboard/Synapse.Dashboard/Components/WorkflowDiagram/Templates/NodeShapeTemplate.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
c 0 -@((Node.RadiusX / 2).ToInvariantString()) @((Node.RadiusX / 2).ToInvariantString()) -@(Node.RadiusX.ToInvariantString()) @(Node.RadiusX.ToInvariantString()) -@(Node.RadiusX.ToInvariantString())
4343
h @((bounds.Width - (Node.RadiusX * 2)).ToInvariantString())
4444
c @((Node.RadiusX / 2).ToInvariantString()) 0 @(Node.RadiusX.ToInvariantString()) @((Node.RadiusY / 2).ToInvariantString()) @(Node.RadiusX.ToInvariantString()) @(Node.RadiusY.ToInvariantString())
45-
v @(Constants.ClusterHeight + 10)
45+
v @(Constants.ClusterHeight - 10)
4646
h -@(bounds.Width.ToInvariantString())
4747
z"
4848
/>

src/dashboard/Synapse.Dashboard/Components/WorkflowDiagram/Templates/NodeSymbolTemplate.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
(0 - bounds.Height / 4).ToInvariantString() :
3232
!WorkflowNode.IsCluster ?
3333
(0 - _symbolSize / 2).ToInvariantString() :
34-
(0 - (bounds.Height + _symbolSize - (Constants.ClusterHeight+10)) / 2).ToInvariantString();
34+
(0 - (bounds.Height + _symbolSize - (Constants.ClusterHeight-10)) / 2).ToInvariantString();
3535

3636
[CascadingParameter(Name = "Node")] public INodeViewModel Node { get; set; } = null!;
3737
[CascadingParameter(Name = "Symbol")] public string? Symbol { get; set; }

src/dashboard/Synapse.Dashboard/Components/WorkflowDiagram/Templates/NodeTemplate.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@namespace Synapse.Dashboard
1818
@inherits Neuroglia.Blazor.Dagre.Templates.NodeTemplate
1919

20-
<g id="@Node.Id" class="@(WorkflowNode.IsCluster ? "cluster" : "node") @(!string.IsNullOrWhiteSpace(Node.Shape) ? "shape-" + Node.Shape : "shape-rectangle") @Node.CssClass" transform="translate(@((Node.X).ToInvariantString()), @((Node.Y).ToInvariantString()))">
20+
<g id="@Node.Id" class="@(WorkflowNode.IsCluster ? "cluster" : "node") @(!string.IsNullOrWhiteSpace(Node.Shape) ? "shape-" + Node.Shape : "shape-rectangle") @Node.CssClass" transform="translate(@((Node.X).ToInvariantString()), @((Y).ToInvariantString()))">
2121
<CascadingValue Name="Node" Value="Node">
2222
<NodeShapeTemplate />
2323
<CascadingValue Name="LabelTemplate" Value="LabelTemplate">
@@ -37,10 +37,11 @@
3737
</CascadingValue>
3838
</g>
3939

40-
40+
4141
@code {
4242
protected virtual IWorkflowNodeViewModel WorkflowNode => (IWorkflowNodeViewModel)this.Node;
4343
BoundingBox bounds => Node.Bounds!;
44+
double Y => WorkflowNode.IsCluster ? Node.Y : Node.Y + 25; // Slightly offset the nodes (not clusters) to compensate for the clusters' "padding" forced by the Dagre layout. Note, the arrow "refX" has been adjusted accordingly.
4445
4546
RenderFragment? LabelTemplate => !string.IsNullOrWhiteSpace(WorkflowNode.Type) || !string.IsNullOrWhiteSpace(WorkflowNode.Content) ? (__builder) =>
4647
{
@@ -59,7 +60,7 @@
5960
@if (!string.IsNullOrWhiteSpace(WorkflowNode.Type)) {
6061
<p class="fw-bold">@WorkflowNode.Type</p>
6162
}
62-
@if (!string.IsNullOrWhiteSpace(WorkflowNode.Content))
63+
@if (!string.IsNullOrWhiteSpace(WorkflowNode.Content) && !WorkflowNode.IsCluster)
6364
{
6465
<pre class="fw-light fst-italic">@WorkflowNode.Content</pre>
6566
}

src/dashboard/Synapse.Dashboard/Components/WorkflowDiagram/WorkflowDiagram.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
xmlns="http://www.w3.org/2000/svg"
2828
xmlns:xlink="http://www.w3.org/1999/xlink">
2929
<defs>
30+
<!-- Instead of thoses defs, we could use graph.referenceableComponentTypes, but it needs to be set in the constructor which is not handy -->
31+
<marker id="large-end-arrow"
32+
class="marker arrow"
33+
viewBox="0 0 10 10"
34+
refX="0"
35+
refY="5"
36+
markerUnits="strokeWidth"
37+
markerWidth="15"
38+
markerHeight="15"
39+
orient="auto">
40+
<path d="M 0 0 L 10 5 L 0 10 z" />
41+
</marker>
3042
<svg id="legend" viewBox="0 0 18 18">
3143
<!-- from https://www.svgrepo.com/svg/451049/legend -->
3244
<path fill-rule="evenodd" d="m2.4 8.1q-0.2-0.1-0.5-0.3-0.2-0.2-0.3-0.5-0.1-0.3-0.1-0.5c0-0.7 0.4-1.2 0.9-1.4 0.6-0.3 1.2-0.1 1.7 0.3 0.4 0.4 0.5 1.1 0.3 1.6-0.2 0.6-0.8 1-1.4 1q-0.3-0.1-0.6-0.2zm0.3-2q-0.1 0-0.2 0.1-0.1 0.1-0.2 0.3 0 0.1 0 0.3c0 0.3 0.1 0.5 0.4 0.6 0.3 0.2 0.6 0.1 0.8-0.1 0.2-0.2 0.3-0.6 0.2-0.8-0.1-0.3-0.4-0.5-0.7-0.5q-0.1 0-0.3 0.1zm13.8-3.8v0.7h-9.8v-0.7zm0 4.5v0.7h-9.7v-0.7zm0 4.5v0.7h-9.8v-0.7zm0 4.5v0.7h-9.7v-0.7zm-13.5-1.4l1.5 2.9h-3zm0.2 2l-0.2-0.5-0.3 0.5zm1.2-15.7v3h-3v-3zm-0.8 0.7h-1.5v1.5h1.5zm0.8 8.3v3h-3v-3zm-0.8 0.7h-1.5v1.5h1.5z" />

src/dashboard/Synapse.Dashboard/Components/WorkflowDiagram/WorkflowDiagramStore.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public class WorkflowDiagramStore(IWorkflowGraphBuilder workflowGraphBuilder)
6969
public IObservable<DagreGraphOptions> Options => this.Orientation
7070
.Select(orientation => new DagreGraphOptions()
7171
{
72-
Direction = orientation == WorkflowDiagramOrientation.LeftToRight ? DagreGraphDirection.LeftToRight : DagreGraphDirection.TopToBottom
72+
Direction = orientation == WorkflowDiagramOrientation.LeftToRight ? DagreGraphDirection.LeftToRight : DagreGraphDirection.TopToBottom,
73+
RankSeparation = 30
7374
})
7475
.DistinctUntilChanged();
7576

src/dashboard/Synapse.Dashboard/Components/WorkflowDiagram/WorkflowNodeViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public int FaultedInstancesCount
6767
public bool IsCluster => false;
6868

6969
/// <summary>
70-
/// Initialiazes a new <see cref="WorkflowNodeViewModel"/>
70+
/// Initializes a new <see cref="WorkflowNodeViewModel"/>
7171
/// </summary>
7272
/// <param name="taskReference">The node task reference</param>
7373
/// <param name="config">The <see cref="NodeViewModelConfig"/> for the node</param>

src/dashboard/Synapse.Dashboard/Services/WorkflowGraphBuilder.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class WorkflowGraphBuilder(ILogger<WorkflowGraphBuilder> logger, IYamlSer
3333

3434
const string _clusterEntrySuffix = "-cluster-entry-port";
3535
const string _clusterExitSuffix = "-cluster-exit-port";
36-
const string _trySuffix = "-try";
37-
const string _catchSuffix = "-catch";
36+
const string _trySuffix = "/try";
37+
const string _catchSuffix = "/catch";
3838
const double characterSize = 8d;
3939

4040
/// <summary>
@@ -530,6 +530,7 @@ protected virtual NodeViewModel BuildTryTaskNode(TaskNodeRenderingContext<TryTas
530530
this.BuildEdge(context.Graph, containerEntryPort, tryEntryPort);
531531
var innerContext = new TaskNodeRenderingContext(context.Workflow, context.Graph, context.TaskDefinition.Try, null, null, null, tryCluster, context.TaskReference + "/try", context, tryEntryPort, tryExitPort);
532532
this.BuildTransitions(tryEntryPort, innerContext);
533+
//this.BuildEdge(context.Graph, tryExitPort, containerExitPort);
533534

534535
var catchContent = this.YamlSerializer.SerializeToText(context.TaskDefinition.Catch);
535536
if (context.TaskDefinition.Catch.Do == null || context.TaskDefinition.Catch.Do.Count == 0)
@@ -607,6 +608,10 @@ protected virtual IEdgeViewModel BuildEdge(IGraphViewModel graph, INodeViewModel
607608
{
608609
edge.EndMarkerId = null;
609610
}
611+
else
612+
{
613+
edge.EndMarkerId = "large-end-arrow"; ;
614+
}
610615
return graph.AddEdge(edge);
611616
}
612617

src/dashboard/Synapse.Dashboard/wwwroot/css/app.css

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dashboard/Synapse.Dashboard/wwwroot/css/app.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dashboard/Synapse.Dashboard/wwwroot/css/graph.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ $viridisScale: // generated with 13 steps, using 12 to exclude the last yellow
135135
white-space: nowrap;
136136
text-overflow: ellipsis;
137137
overflow: hidden;
138+
font-weight: bold;
138139
}
139140

140141
p {
@@ -216,6 +217,10 @@ $viridisScale: // generated with 13 steps, using 12 to exclude the last yellow
216217
fill: var(--graph-symbol-color);
217218
}
218219

220+
.marker {
221+
fill: #{$mute};
222+
}
223+
219224
.start-node circle {
220225
stroke-width: 2px;
221226
}

0 commit comments

Comments
 (0)