public static void SetColor <TNodeSource, TGraphElement>(this ElementSourceDictionary elementVsSources, Func <TNodeSource, String> BackgroundFunction = null, Func <TNodeSource, String> ForegroundFunction = null) where TGraphElement : GraphNodeElement { foreach (var pair in elementVsSources) { foreach (var sourceObject in pair.Value) { TGraphElement nodeA = pair.Key as TGraphElement; if (nodeA != null) { if (sourceObject is TNodeSource nodeSource) { if (BackgroundFunction != null) { nodeA.Background = BackgroundFunction(nodeSource); } if (ForegroundFunction != null) { nodeA.Foreground = ForegroundFunction(nodeSource); } } } } } }
/// <summary> /// Creates links (and nodes, if not existing) /// </summary> /// <typeparam name="TLinkSource">The type of the link source.</typeparam> /// <param name="graph">The graph.</param> /// <param name="link">The link.</param> /// <param name="NodeAUID">The node auid.</param> /// <param name="NodeBUID">The node buid.</param> /// <param name="LinkLabel">The link label.</param> /// <param name="setProperties">if set to <c>true</c> [set properties].</param> public static ElementSourceDictionary Link <TLinkSource>(this DirectedGraph graph, IEnumerable <TLinkSource> link, Func <TLinkSource, String> NodeAUID, Func <TLinkSource, String> NodeBUID, Func <TLinkSource, String> LinkLabel, Boolean setProperties = true) { var linkIndex = link.ToList(); ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary(); for (int i = 0; i < linkIndex.Count; i++) { Link linkAK = graph.Links.AddOrGetLink(NodeAUID(linkIndex[i]), NodeBUID(linkIndex[i])); linkAK.Label = LinkLabel(linkIndex[i]); ElementToSourceObject[linkAK].Add(linkIndex[i]); } if (graph is DirectedGraphWithSourceData graphWithData) { graphWithData.Sources.AddRange(ElementToSourceObject, true); } return(ElementToSourceObject); }
public static void SetStroke <TNodeSource, TGraphElement>(this ElementSourceDictionary elementVsSources, Func <TNodeSource, String> StrokeColorFunction = null, Func <TNodeSource, Int32> StrokeWidthFunction = null, Func <TNodeSource, String> StrokeDashArrayFunction = null) where TGraphElement : GraphElement { foreach (var pair in elementVsSources) { foreach (var sourceObject in pair.Value) { TGraphElement nodeA = pair.Key as TGraphElement; if (nodeA != null) { if (sourceObject is TNodeSource nodeSource) { if (StrokeColorFunction != null) { nodeA.Stroke = StrokeColorFunction(nodeSource); } if (StrokeWidthFunction != null) { nodeA.StrokeThinkness = StrokeWidthFunction(nodeSource); } if (StrokeDashArrayFunction != null) { nodeA.StrokeDashArray = StrokeDashArrayFunction(nodeSource); } } } } } }
public static ElementSourceDictionary Select <TNodeSource>(this DirectedGraph graph, IEnumerable <TNodeSource> nodes, Func <TNodeSource, String> NodeUID, Boolean includeSourceLinks = false, Boolean includeTargetLinks = true) { ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary(); foreach (TNodeSource node in nodes) { Node nodeA = graph.Nodes[NodeUID(node)]; ElementToSourceObject[nodeA].Add(node); if (includeSourceLinks) { foreach (var l in graph.Links.Where(x => x.Source == nodeA.Id)) { ElementToSourceObject[l].Add(node); } } if (includeTargetLinks) { foreach (var l in graph.Links.Where(x => x.Target == nodeA.Id)) { ElementToSourceObject[l].Add(node); } } } return(ElementToSourceObject); }
public static ElementSourceDictionary Populate <TNodeSource, TChildNodeSource>(this DirectedGraph graph, IEnumerable <TNodeSource> nodes, Func <TNodeSource, IEnumerable <TChildNodeSource> > linkedNodesFunction, Func <TNodeSource, String> NodeUID, Func <TNodeSource, String> NodeLabel, Func <TChildNodeSource, String> ChildNodeUID, Func <TChildNodeSource, String> ChildNodeLabel, Boolean setProperties = true, Boolean useFormatting = true) { ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary(); foreach (TNodeSource node in nodes) { Node nodeA = graph.Nodes.AddOrGet(NodeUID(node), NodeLabel(node)); ElementToSourceObject[nodeA].Add(node); graph.DeployPropertiesAndFormatting(nodeA, node, setProperties, useFormatting); // nodeA.DeployColor(node, NodeColor) var child_nodes = linkedNodesFunction(node); foreach (TChildNodeSource child in child_nodes) { Node nodeB = graph.Nodes.AddOrGet(ChildNodeUID(child), ChildNodeLabel(child)); ElementToSourceObject[nodeB].Add(child); graph.DeployPropertiesAndFormatting(nodeB, child, setProperties, useFormatting); Link linkAK = graph.Links.AddOrGetLink(NodeUID(node), ChildNodeUID(child)); ElementToSourceObject[linkAK].Add(node); ElementToSourceObject[linkAK].Add(child); } } if (graph is DirectedGraphWithSourceData graphWithData) { graphWithData.Sources.AddRange(ElementToSourceObject, true); } return(ElementToSourceObject); }
public static ListDictionary <GraphElement, Object> Link <TNodeASource, TNodeBSource>(this DirectedGraph graph, IEnumerable <TNodeASource> nodesA, Func <TNodeASource, String> NodeAUID, Func <TNodeASource, String> NodeALabel, IEnumerable <TNodeBSource> nodesB, Func <TNodeBSource, String> NodeBUID, Func <TNodeBSource, String> NodeBLabel, Func <TNodeASource, TNodeBSource, String> LinkABLabel, Boolean setProperties = true, Boolean useFormatting = true) { var nodeAIndex = nodesA.ToList(); var nodeBIndex = nodesB.ToList(); ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary(); for (int i = 0; i < Math.Min(nodeAIndex.Count, nodeBIndex.Count); i++) { Node nodeA = graph.Nodes.AddOrGet(NodeAUID(nodeAIndex[i]), NodeALabel(nodeAIndex[i])); Node nodeB = graph.Nodes.AddOrGet(NodeBUID(nodeBIndex[i]), NodeBLabel(nodeBIndex[i])); graph.DeployPropertiesAndFormatting(nodeA, nodeAIndex[i], setProperties, useFormatting); graph.DeployPropertiesAndFormatting(nodeB, nodeBIndex[i], setProperties, useFormatting); ElementToSourceObject[nodeA].Add(nodeAIndex[i]); ElementToSourceObject[nodeB].Add(nodeBIndex[i]); Link linkAK = graph.Links.AddOrGetLink(NodeAUID(nodeAIndex[i]), NodeBUID(nodeBIndex[i])); linkAK.Label = LinkABLabel(nodeAIndex[i], nodeBIndex[i]); ElementToSourceObject[linkAK].Add(nodeAIndex[i]); ElementToSourceObject[linkAK].Add(nodeBIndex[i]); } if (graph is DirectedGraphWithSourceData graphWithData) { graphWithData.Sources.AddRange(ElementToSourceObject, true); } return(ElementToSourceObject); }
public static ElementSourceDictionary Populate <TNodeSource>(this DirectedGraph graph, IEnumerable <TNodeSource> nodes, Func <TNodeSource, String> NodeUID, Func <TNodeSource, String> NodeLabel) { ElementSourceDictionary ElementToSourceObject = new ElementSourceDictionary(); foreach (TNodeSource node in nodes) { if (node == null) { continue; } Node nodeA = graph.Nodes.AddOrGet(NodeUID(node), NodeLabel(node)); ElementToSourceObject[nodeA].Add(node); graph.DeployPropertiesAndFormatting(nodeA, node, false, false); } if (graph is DirectedGraphWithSourceData graphWithData) { graphWithData.Sources.AddRange(ElementToSourceObject, true); } return(ElementToSourceObject); }