Hi,
We're trying to create a simple proof of concept to create a swimlane with 2 lanes, and a single node in each lane.
I would appreciate it of someone can review my code below and tell me what I'm doing wrong.
Running version 16.3.0.29.
Here's what my code generates:
And here's my code:
var swimlane = AddSwimlane("My Process");
var laneCollection = new Collection();
var lane1 = AddLane("Change Mgr.");
laneCollection.Add(lane1);
var lane1ChildrenCollection = new Collection();
var child1 = CreateNode("Task", "Task 1", pathDataTask, "white", true, true, 60, 120, 200, 70);
lane1ChildrenCollection.Add(child1);
lane1.Children = lane1ChildrenCollection;
var lane2 = AddLane("Customer");
laneCollection.Add(lane2);
var lane2ChildrenCollection = new Collection();
var child2 = CreateNode("Task", "Task 2", pathDataTask, "white", true, true, 60, 120, 200, 70);
lane2ChildrenCollection.Add(child2);
lane2.Children = lane2ChildrenCollection;
swimlane.Lanes = laneCollection;
swimlane.OffsetX = (int)(swimlane.Width / 2 + 150);
swimlane.OffsetY = (int)(swimlane.Height / 2 + 150);
DiagramContent.Model.Nodes.Add(swimlane);
protected SwimLane AddSwimlane(string Title)
{
var swimlane = new SwimLane();
swimlane.Type = "swimlane";
swimlane.Name = "Horizontal-Lane-swimlane";
Header header = new Header();
header.Text = Title;
header.Height = 50;
header.FillColor = "lightyellow";
header.FontSize = 18;
swimlane.Header = header;
swimlane.FillColor = "white";
swimlane.Orientation = "horizontal";
swimlane.Height = 100;
swimlane.Width = 900;
swimlane.PhaseSize = 0;
swimlane.MaxWidth = 1300;
swimlane.MaxHeight = 1000;
swimlane.PhaseSize = 0;
return swimlane;
}
protected Lane AddLane(string headerText)
{
Lane lane = new Lane();
lane.Name = "lane" + RandomString(4);
Header header = new Header();
header.Text = headerText;
header.Width = 60;
header.FillColor = "yellow";
header.FontSize = 12;
header.FontColor = "#000000";
lane.FillColor = "white";
lane.Header = header;
lane.Height = 120;
return lane;
}
private BasicShape CreateNode(string type, string mainlabel, string pathData, string color, bool mainLabel, bool identifierLabel, int height, int width, double offsetX, double offsetY)
{
var node = new BasicShape();
node.Name = type + RandomString(4);
node.Width = width;
node.Height = height;
node.OffsetX = offsetX;
node.OffsetY = offsetY;
node.Shape = BasicShapes.Path;
node.PathData = pathData;
node.BorderWidth = 1;
node.FillColor = (color != null) ? color : "white";
if (mainLabel)
{
var label =
new Syncfusion.JavaScript.DataVisualization.Models.Diagram.Label(); // Add the main node label
label.FontColor = "black";
label.Name = "mainLabel";
if (type.StartsWith("Data"))
{
label.Margin = new LabelMargin { Top = 50 }; // Place the label below Data & Event shapes
node.Constraints = NodeConstraints.Default | NodeConstraints.DragLabel; // Allow the label to be moved by user
}
if (type.EndsWith("Event")) // TFS1241
{
label.Margin = new LabelMargin { Top = 35 }; // Place the label below Data & Event shapes
node.Constraints = NodeConstraints.Default | NodeConstraints.DragLabel; // Allow the label to be moved by user
}
if (type == "InterProcess") // For InterProcess shapes force the label to occupy the right rectangle - added 27Oct2015 by Jim
{
label.Offset = new DiagramPoint(0.58f, 0.5f);
label.HorizontalAlignment = HorizontalAlignment.Center;
label.TextAlign = Syncfusion.JavaScript.DataVisualization.DiagramEnums.TextAlign.Center;
label.Margin = new LabelMargin { Left = 8, Right = 7 };
}
if (type == "Unknown")
{
label.Bold = true;
}
label.Text = mainlabel;
node.Labels.Add(label);
}
if (identifierLabel)
{
var label = new Syncfusion.JavaScript.DataVisualization.Models.Diagram.Label();
// Add the task identifier label
label.Offset = new DiagramPoint(0.95f, 0.1f);
label.HorizontalAlignment = HorizontalAlignment.Right;
label.TextAlign = Syncfusion.JavaScript.DataVisualization.DiagramEnums.TextAlign.Right;
label.FontColor = "blue";
label.Name = "identifierLabel";
node.Labels.Add(label);
}
CreateRectanglePorts(node);
return node;
}
Any suggestions would be much appreciated.
Thanks in advance.
Jim