/// <summary> /// Serializes an attribute set to a string builder in form " [a = b]" /// </summary> private void AppendAttributeSet(IAttrSet attrSet, StringBuilder sb) { if (!AttrSet.NotNullOrEmpty(attrSet)) { return; } sb.Append(" ["); bool wroteFirst = false; foreach (IAttribute attribute in attrSet) { if (wroteFirst) { sb.Append(", "); } string record = _dotHelper.GetRecordFromAttribute(attribute); sb.Append(record); wroteFirst = true; } sb.Append("]"); }
private void WriteBranchLabel(string id, IBranch b, IRemoteWebUrlProvider remoteUrlProvider) { IAttrSet style = _style.LabelBranch; string url = remoteUrlProvider?.GetBranchLink(b); _gvWriter.Node(id, style.Label(b.Label).Url(url)); }
public void RawAttributes(IAttrSet attributesSet) { foreach (IAttribute attr in attributesSet) { string record = _dotHelper.GetRecordFromAttribute(attr); Line($"{record};"); } }
private void WriteNode(INode n, IRemoteWebUrlProvider remoteUrlProvider) { string url = remoteUrlProvider?.GetCommitLink(n.Commit); string tooltip = _tooltipHelper.MakeNodeTooltip(n); IAttrSet nodeAttrs = AttrSet.Empty .Url(url) .Tooltip(tooltip); _gvWriter.Node(n.Commit, nodeAttrs); }
private void WriteBranchEndingEdge( INode pointedNode, string id, IBranch b, IRemoteWebUrlProvider remoteUrlProvider ) { IAttrSet style = _style.EdgeBranchLabel; string url = remoteUrlProvider?.GetBranchMetaLink(b); _gvWriter.Edge(pointedNode.Commit, id, style.Url(url)); }
public void SetNodeAttributes(IAttrSet attributesSet) { if (!AttrSet.NotNullOrEmpty(attributesSet)) { return; } StringBuilder sb = new StringBuilder(); sb.Append("node"); AppendAttributeSet(attributesSet, sb); sb.Append(";"); Line(sb.ToString()); }
public void GivenAttributeWithNullValue_ThenDoesntEnumerateIt() { UrlAttribute a1 = new UrlAttribute("abc"); LabelAttribute a2 = new LabelAttribute("xyz"); IAttrSet set = AttrSet.Empty.Add(a1).Add(a2); Assert.Equal(new IAttribute[] { a1, a2 }, set); UrlAttribute a3 = new UrlAttribute(null); set = set.Add(a3); Assert.Equal(new IAttribute[] { a2 }, set); }
public void Node(string id, IAttrSet attrSet = null) { string aw = _dotHelper.EscapeId(id); StringBuilder sb = new StringBuilder(); sb.Append(aw); AppendAttributeSet(attrSet, sb); sb.Append(";"); string wholeString = sb.ToString(); Line(wholeString); }
private void WriteHeader() { _gvWriter.StartGraph(GraphMode.Digraph, true); IAttrSet graphStyle = _style.GraphGeneric; _gvWriter.SetGraphAttributes(graphStyle); IAttrSet genericNodeStyle = _style.NodeGeneric; _gvWriter.SetNodeAttributes(genericNodeStyle); IAttrSet genericEdgeStyle = _style.EdgeGeneric; _gvWriter.SetEdgeAttributes(genericEdgeStyle); }
private void WriteEdge(INode a, INode b, IRemoteWebUrlProvider remoteUrlProvider) { string url = remoteUrlProvider?.GetCompareCommitsLink(a.Commit, b.Commit); string tooltip = _tooltipHelper.MakeEdgeTooltip(a, b); IAttrSet attrSet = AttrSet.Empty .Url(url) .Tooltip(tooltip); bool hasMergedCommits = b.AbsorbedParentCommits.Any(); if (hasMergedCommits) { attrSet = attrSet.Add(_style.EdgeMergedCommits); } _gvWriter.Edge(a.Commit, b.Commit, attrSet); }
public IAttrSet Add(IAttrSet attrSet) { bool shouldAdd = attrSet.Any(); if (!shouldAdd) { // Since no change return(this); } AttrSet clonedSet = new AttrSet(_set); foreach (IAttribute item in attrSet) { clonedSet._set[item.Key] = item; } return(clonedSet); }
public void GivenNodeWithTwoAttributes_ThenWritesThemCorrectly() { IAttrSet attributes = AttrSet.Empty.Width(1).Label("x"); IStringWriter writer = new StringWriterAdapter(); var dotHelperMock = new Mock <IDotHelper>(); dotHelperMock.Setup(m => m.EscapeId(It.IsAny <string>())).Returns((string s) => s); dotHelperMock.Setup(m => m.GetRecordFromAttribute(It.IsAny <IAttribute>())) .Returns((IAttribute a) => $"{a.Key}={a.StringValue}"); GraphVizWriter g = new GraphVizWriter(writer, dotHelperMock.Object); g.Node("z", attributes); string result = writer.GetStringBuilder().ToString(); string expected = $"z [width=1, label=x];{Environment.NewLine}"; Assert.Equal(expected, result); }
public void Edge(string a, string b, IAttrSet attrSet = null) { string aw = _dotHelper.EscapeId(a); string bw = _dotHelper.EscapeId(b); StringBuilder sb = new StringBuilder(); sb.Append(aw); sb.Append(' '); sb.Append(GetEdgeMarker()); sb.Append(' '); sb.Append(bw); AppendAttributeSet(attrSet, sb); sb.Append(";"); string wholeString = sb.ToString(); Line(wholeString); }
public static IAttrSet Color(this IAttrSet attrSet, Color value) { return(attrSet.Color(GraphVizColor.FromRgb(value))); }
public static IAttrSet ForceLabels(this IAttrSet attrSet, bool value) { ForceLabelsAttribute a = new ForceLabelsAttribute(value); return(attrSet.Add(a)); }
public static IAttrSet Margin(this IAttrSet attrSet, decimal horizontal, decimal vertical) { MarginAttribute a = new MarginAttribute(horizontal, vertical); return(attrSet.Add(a)); }
public static IAttrSet Margin(this IAttrSet attrSet, decimal value) { return(attrSet.Margin(value, value)); }
public static IAttrSet Width(this IAttrSet attrSet, decimal value) { WidthAttribute a = new WidthAttribute(value); return(attrSet.Add(a)); }
/// <summary> /// Font used for text. /// </summary> public static IAttrSet FontName(this IAttrSet attrSet, string value) { FontNameAttribute a = new FontNameAttribute(value); return(attrSet.Add(a)); }
public static IAttrSet FixedSize(this IAttrSet attrSet, bool value) { FixedSizeAttribute a = new FixedSizeAttribute(value); return(attrSet.Add(a)); }
public void Render( ITree tree, IRemote usedRemote, IBranchesKnowledge branchesKnowledge, ITreeRenderingOptions options) { IRemoteWebUrlProvider remoteUrlProvider = _remoteWebUrlProviderFactory.CreateUrlProvider(usedRemote.Url, options.ForceTreatAsGitHub); WriteHeader(); IBranch[] branchesWithNodes = tree.Branches.Where(b => tree.EnumerateNodes(b).Any()).ToArray(); IBranch[] currentBranchesSorted = OrderByFirstCommitDate(branchesWithNodes, tree).ToArray(); IPairList <INode, INode> unwrittenMerges = new PairList <INode, INode>(); IPairList <INode, INode> writtenMerges = new PairList <INode, INode>(); // Main branches. foreach (IBranch b in currentBranchesSorted) { _gvWriter.EmptyLine(); _gvWriter.Comment($"Branch {b.Label}."); using (_gvWriter.StartSubGraph()) { _gvWriter.SetNodeAttributes(AttrSet.Empty.Group(b.Label)); Color drawColor = branchesKnowledge.GetSuggestedDrawingColorFor(b); bool isLesser = branchesKnowledge.IsAWorkItemBranch(b); IAttrSet nodeStyle = _style.GetBranchNodeStyle(drawColor, isLesser); IAttrSet edgeStyle = _style.GetBranchEdgeStyle(drawColor, isLesser); _gvWriter.SetNodeAttributes(nodeStyle); _gvWriter.SetEdgeAttributes(edgeStyle); INode[] nodes = tree.EnumerateNodes(b).ToArray(); for (int i = 0; i < nodes.Length; i++) { INode currentNode = nodes[i]; WriteNode(currentNode, remoteUrlProvider); if (i == 0) { // Starting node. INode parent = currentNode.Parents.FirstOrDefault(); bool hasParent = parent != null; if (!hasParent) { _gvWriter.Comment("Starting line."); string id = string.Format($"{currentNode.Commit.Treeish}_start"); // Write starting empty node. using (_gvWriter.StartSubGraph()) { _gvWriter.RawAttributes(AttrSet.Empty.Rank(RankType.Source)); _gvWriter.Node(id, AttrSet.Empty.Width(0).Height(0).PenWidth(0)); } _gvWriter.Edge(id, currentNode.Commit, _style.EdgeBranchStartVirtual); _gvWriter.EmptyLine(); } else { // It is some other branch, and we draw that edge. WriteEdge(parent, currentNode, remoteUrlProvider); writtenMerges.Add(parent, currentNode); } } bool isLast = i == nodes.Length - 1; INode nextNode = isLast ? null : nodes[i + 1]; if (!isLast) { // Edge to the next node. WriteEdge(currentNode, nextNode, remoteUrlProvider); } else { WriteBranchPointer(b, tree, isLesser, remoteUrlProvider); } INode[] otherChildren = currentNode.Children.Except(nextNode).ToArray(); foreach (INode child in otherChildren) { unwrittenMerges.Add(currentNode, child); } } } } IBranch[] branchesWithoutNodes = tree.Branches.Except(branchesWithNodes).ToArray(); foreach (IBranch b in branchesWithoutNodes) { bool isLesser = branchesKnowledge.IsAWorkItemBranch(b); WriteBranchPointer(b, tree, isLesser, remoteUrlProvider); } // Tags. ITag[] tags = tree.Tags.ToArray(); foreach (ITag t in tags) { _gvWriter.EmptyLine(); INode n = tree.GetNode(t.Tip); string id = MakeNodeIdForPointerLabel(n, t); using (_gvWriter.StartSubGraph()) { _gvWriter.Comment($"Tag {t.Label}."); _gvWriter.RawAttributes(AttrSet.Empty.Rank(RankType.Same)); string url = remoteUrlProvider?.GetTagLink(t); _gvWriter.Node(id, _style.LabelTag.Label(t.Label).Url(url)); _gvWriter.Edge(n.Commit, id, _style.EdgeTagLabel); } } INode[] allLeftOvers = tree.Nodes.Where(n => tree.GetContainingBranch(n) == null).ToArray(); if (allLeftOvers.Length > 0) { using (_gvWriter.StartSubGraph()) { _gvWriter.EmptyLine(); _gvWriter.Comment("Leftover nodes."); _gvWriter.SetNodeAttributes(_style.NodeOrphaned); foreach (INode currentNode in allLeftOvers) { WriteNode(currentNode, remoteUrlProvider); // Remember children. foreach (INode child in currentNode.Children) { unwrittenMerges.Add(currentNode, child); } } } } PairList <INode, INode> edgesToWrite = unwrittenMerges.Except(writtenMerges).ToPairList(); if (edgesToWrite.Count > 0) { using (_gvWriter.StartSubGraph()) { _gvWriter.EmptyLine(); _gvWriter.Comment("Other edges."); _gvWriter.SetEdgeAttributes(_style.EdgeOther); foreach (Tuple <INode, INode> edge in edgesToWrite) { _gvWriter.Edge(edge.Item1.Commit, edge.Item2.Commit); } } } WriteFooter(); }
public static IAttrSet Rankdir(this IAttrSet attrSet, Rankdir value) { RankdirAttribute a = new RankdirAttribute(value); return(attrSet.Add(a)); }
public static IAttrSet Shape(this IAttrSet attrSet, Shape value) { ShapeAttribute a = new ShapeAttribute(value); return(attrSet.Add(a)); }
/// <summary> /// Font size, in points, used for text. /// </summary> public static IAttrSet FontSize(this IAttrSet attrSet, decimal value) { FontSizeAttribute a = new FontSizeAttribute(value); return(attrSet.Add(a)); }
/// <summary> /// Text label attached to objects. /// </summary> public static IAttrSet Label(this IAttrSet attrSet, string value) { LabelAttribute a = new LabelAttribute(value); return(attrSet.Add(a)); }
public static IAttrSet Height(this IAttrSet attrSet, decimal value) { HeightAttribute a = new HeightAttribute(value); return(attrSet.Add(a)); }
public static IAttrSet Color(this IAttrSet attrSet, string hexString) { return(attrSet.Color(GraphVizColor.FromHex(hexString))); }
public static bool NotNullOrEmpty(IAttrSet attrSet) { return(attrSet != null && attrSet.Any()); }
public static IAttrSet Color(this IAttrSet attrSet, IGraphVizColor value) { ColorAttribute a = new ColorAttribute(value); return(attrSet.Add(a)); }
public static IAttrSet NodeSep(this IAttrSet attrSet, decimal value) { NodeSepAttribute a = new NodeSepAttribute(value); return(attrSet.Add(a)); }