private SolidColorBrush GetBrush(HierarchicalData data) { if (Highlighing != null && Highlighing.IsHighlighted(data)) { return(DefaultDrawingPrimitives.HighlightBrush); } SolidColorBrush brush; if (data.ColorKey != null) { brush = _colorScheme.GetMediaBrush(data.ColorKey); } else { // For non leaf nodes the weight is 0. We only can merge area metrics. // See HiearchyBuilder.InsertLeaf. var color = DefaultDrawingPrimitives.WhiteToRedGradient.GradientStops.GetRelativeColor(data.NormalizedWeightMetric); brush = new SolidColorBrush(color); brush.Freeze(); } return(brush); }
private void Squarify(Rect availableSpace, HierarchicalData data) { if (DebugEnabled) { // Print the item and the available space. _level++; Debug.WriteLine(GetLevelIndent() + "Squarify - " + data.Name + " Available=" + Format(availableSpace)); } if (data.Children.Count == 0) { // Draw leaf node at its location //DrawRectangle(availableSpace, data); No, just calculate the layout! if (DebugEnabled) { var layout = GetLayout(data); Debug.WriteLine(GetLevelIndent() + "Printing " + data.Name + ", " + "Rect=" + Format(layout.Rect)); } _level--; return; } var itemsToArrange = new List <HierarchicalData>(data.Children); Squarify(availableSpace, itemsToArrange); _level--; }
private CircularLayoutInfo GetLayout(HierarchicalData item) { var layout = item.Layout as CircularLayoutInfo; Debug.Assert(layout != null); return(layout); }
public HierarchicalDataContext GetColoredNestedExample() { var root = new HierarchicalData("root"); var scheme = new ColorScheme(new[] { "c1", "c2", "c3" }); HierarchicalData child; child = new HierarchicalData("ra", 10) { ColorKey = "c1" }; root.AddChild(child); child = new HierarchicalData("ra", 10) { ColorKey = "c2" }; root.AddChild(child); child = new HierarchicalData("ra", 10) { ColorKey = "c3" }; root.AddChild(child); child = new HierarchicalData("ra", 10) { ColorKey = "unknown" }; root.AddChild(child); root.SumAreaMetrics(); Console.WriteLine(root.CountLeafNodes()); return(new HierarchicalDataContext(root, scheme)); }
public bool IsHighlighted(HierarchicalData data) { var isNameMatchingActive = !string.IsNullOrEmpty(_pattern); var isNameMatching = false; if (isNameMatchingActive) { isNameMatching = data.Name.ToLowerInvariant().Contains(_pattern); } // Matching area and weight criteria is optional. var areRangesMatching = _toolViewModel.NoFilterJustHighlight && _toolViewModel.IsAreaValid(data.AreaMetric) && _toolViewModel.IsWeightValid(data.WeightMetric); if (!isNameMatchingActive && _toolViewModel.NoFilterJustHighlight) { // If no name is entered ignore the name filtering return(areRangesMatching); } if (isNameMatchingActive && !_toolViewModel.NoFilterJustHighlight) { return(isNameMatching); } if (isNameMatchingActive && _toolViewModel.NoFilterJustHighlight) { return(isNameMatching && areRangesMatching); } return(false); }
private CircularLayoutInfo CalculateEnclosingCircle(HierarchicalData root, FrontChain frontChain) { // Get extreme points by extending the vector from origin to center by the radius var layouts = frontChain.ToList(); var points = layouts.Select(x => MathHelper.MovePointAlongLine(new Point(), x.Center, x.Radius)).ToList(); var layout = GetLayout(root); Debug.Assert(layout.Center == new Point()); // Since we process bottom up this node was not considered yet. double radius; Point center; if (frontChain.Head.Next == frontChain.Head) // Single element { center = frontChain.Head.Value.Center; radius = frontChain.Head.Value.Radius; } else { // 2 and 3 points seem to be handled correctly. MathHelper.FindMinimalBoundingCircle(points, out center, out radius); } layout.Center = center; Debug.Assert(Math.Abs(radius) > 0.00001); layout.Radius = radius * 1.03; // Just a little larger 3%. return(layout); // Note that this is not exact. It is a difficult problem. // We may have a little overlap. The larger the increment in radius // the smaller this problem gets. }
public void Layout(HierarchicalData root, double width, double height) { var rect = new Rect(new Point(0, 0), new Size(width, height)); var layout = GetLayout(root); layout.Rect = rect; Squarify(rect, root); }
public void LoadData(HierarchicalData data) { _data = data; // Layout once. Later we scale it appropriately var layout = new CirclePackingLayout(); layout.Layout(_data, double.MaxValue, double.MaxValue); }
private static RectangularLayoutInfo GetLayout(HierarchicalData data) { if (data.Layout == null) { data.Layout = new RectangularLayoutInfo(); } return(data.Layout as RectangularLayoutInfo); }
protected override void InitPopup(HierarchicalData hit) { _popupText.Text = hit.Description; _popup.PlacementTarget = GetCanvas(); _popup.Placement = PlacementMode.Mouse; _popup.Visibility = Visibility.Visible; _popup.IsOpen = true; }
public void DeleteShape(List <HierarchicalData> data) { foreach (HierarchicalData hdata in data) { HierarchicalData originalData = DiagramContext.HierarchicalData.Single(h => h.Name == hdata.Name); DiagramContext.HierarchicalData.DeleteOnSubmit(originalData); DiagramContext.SubmitChanges(); } }
private CircularLayoutInfo GetLayout(HierarchicalData item) { if (item.Layout == null) { var layout = new CircularLayoutInfo(); item.Layout = layout; } return(item.Layout as CircularLayoutInfo); }
/// <summary> /// At the beginning any leaf node is simply centered at (0,0) /// </summary> private void InitLayoutForLeafNode(HierarchicalData data) { // Not intersted in non leaf nodes, so we can ask for area metric. Debug.Assert(data.AreaMetric > 0); var layout = GetLayout(data); layout.Radius = AreaToRadius(data.AreaMetric); layout.Center = new Point(0, 0); layout.PendingChildrenMovement = new Vector(0, 0); }
public void UpdateShape(List <HierarchicalData> data) { foreach (HierarchicalData hdata in data) { HierarchicalData originalData = DiagramContext.HierarchicalData.Single(h => h.Name == hdata.Name); originalData.Description = hdata.Description; originalData.Color = hdata.Color; DiagramContext.SubmitChanges(); } }
// Assume root has always at least one child! public HierarchicalData GenerateRandomHierarchy() { var root = new HierarchicalData("root"); var depth = GetRandomDepth(); // At least one child FillChildren(root, GetRandmomNumberOfChildren(), depth); return(root); }
public HierarchicalData CreateHierarchyFromFilesystem(string path, bool subDirs) { var item = new HierarchicalData(path); FillChildren(item, subDirs); item.RemoveLeafNodesWithoutArea(); item.SumAreaMetrics(); item.NormalizeWeightMetrics(); return(item); }
/// <summary> /// For performance optimization we did not apply movements to children until /// all positions are fixed. /// </summary> private void ApplyPendingMovements(HierarchicalData data) { var layout = GetLayout(data); var pending = layout.PendingChildrenMovement; foreach (var child in data.Children) { var childLayout = GetLayout(child); childLayout.Move(pending); ApplyPendingMovements(child); } }
internal HierarchicalData GetNumberOfCircles(int circles, int radius) { var root = new HierarchicalData(""); for (var i = 0; i < circles; i++) { root.AddChild(new HierarchicalData("i", radius)); } root.SumAreaMetrics(); return(root); }
private void Draw(DrawingContext dc, HierarchicalData data) { var brush = GetBrush(data); var layout = GetLayout(data); dc.DrawEllipse(brush, _pen, layout.Center, layout.Radius, layout.Radius); foreach (var child in data.Children) { Draw(dc, child); } }
public HierarchicalDataContext CreateHierarchyFromFilesystem(string path, bool subDirs) { var item = new HierarchicalData(path); FillChildren(item, subDirs); item.RemoveLeafNodesWithoutArea(); item.SumAreaMetrics(); item.NormalizeWeightMetrics(); Debug.WriteLine("Nodes: " + item.CountLeafNodes()); return(new HierarchicalDataContext(item)); }
private void InsertLeaf(HierarchicalData parent, Artifact item, string leafName) { if (!IsAccepted(item)) { // Division 0. No area = no code lines, no weight = no commits return; } var leaf = new HierarchicalData(leafName, GetArea(item), GetWeight(item), GetWeightIsAlreadyNormalized()); leaf.Description = GetDescription(item); leaf.ColorKey = GetColorKey(item); leaf.Tag = item.LocalPath; parent.AddChild(leaf); }
private void Insert(HierarchicalData parent, Artifact item, string[] parts) { if (parts.Length == 1) { InsertLeaf(parent, item, parts[0]); } else { var nextBranch = parts[0]; // Find or create child structure element var branch = GetBranch(parent, nextBranch); Insert(branch, item, parts.Subset(1)); } }
public void Shrink_StopsAtLeafNode() { var a = new HierarchicalData("a"); var b = new HierarchicalData("b"); var c = new HierarchicalData("c"); a.AddChild(b); b.AddChild(c); // c is leaf node var data = a.Shrink(); Assert.AreEqual("c", data.Name); }
public HierarchicalDataContext ShowCollisionWithLastElementProblem() { var root = new HierarchicalData(""); root.AddChild(new HierarchicalData("6", 10)); root.AddChild(new HierarchicalData("6", 10)); root.AddChild(new HierarchicalData("4", 10)); root.AddChild(new HierarchicalData("3", 10)); root.AddChild(new HierarchicalData("1", 10)); root.AddChild(new HierarchicalData("3", 10)); root.AddChild(new HierarchicalData("1", 10)); root.AddChild(new HierarchicalData("3", 10)); root.AddChild(new HierarchicalData("1", 10)); root.SumAreaMetrics(); return(new HierarchicalDataContext(root)); }
protected HierarchicalData GetBranch(HierarchicalData parent, string branch) { var found = parent.Children.FirstOrDefault(child => child.Name == branch); if (found == null) { var newBranch = new HierarchicalData(branch); parent.AddChild(newBranch); // Call when parent relation is set. newBranch.Description = GetDescription(newBranch); found = newBranch; } return((HierarchicalData)found); }
protected IHierarchicalData Build(List <Artifact> artifacts) { var data = BuildHierarchy(artifacts); try { data.RemoveLeafNodesWithoutArea(); // throws if nothing is left data.SumAreaMetrics(); data.NormalizeWeightMetrics(); } catch (Exception) { return(HierarchicalData.NoData()); } return(data.Shrink()); }
public void Shrink_StopsOnMultipleChildren() { var a = new HierarchicalData("a"); var b = new HierarchicalData("b"); var c = new HierarchicalData("c"); var d = new HierarchicalData("d"); a.AddChild(b); b.AddChild(c); b.AddChild(d); // b has two children var data = a.Shrink(); Assert.AreEqual("b", data.Name); }
public void Layout(HierarchicalData root, double actualWidth, double actualHeight) { // actualWidth and actualHeight are not used. We render the circles independent of the sizes and scale them later. // Counters over all steps DebugHelper.ResetDbgCounter(); // Cleanup previous layouting root.TraverseTopDown(x => x.Layout = null); Layout(root); // Center root node to screen. Move to (0,0) var rootLayout = GetLayout(root); MoveCircles(root, -(Vector)rootLayout.Center); ApplyPendingMovements(root); }
public void RemoveLeafNodesWithoutArea_ThrowsIfSingularRootNodeHasNoArea() { // Arrange var root = new HierarchicalData("root"); var a_level = new HierarchicalData("a_level"); var a_leaf = new HierarchicalData("a_leaf", double.NaN); root.AddChild(a_level); a_leaf.AddChild(a_leaf); // Nothing left but the root node! Assert.Throws(typeof(Exception), () => root.RemoveLeafNodesWithoutArea()); // Assert Assert.AreEqual("root", root.Name); Assert.AreEqual(0, root.Children.Count); Assert.IsTrue(double.IsNaN(root.AreaMetric)); }
private void FillChildren(HierarchicalData data, int numChildren, int depth) { depth--; for (var i = 0; i < numChildren; i++) { HierarchicalData newChild; if (GetRandomIsLeaf() || depth <= 0) { newChild = new HierarchicalData("leaf", GetRandomArea()); } else { newChild = new HierarchicalData("folder"); FillChildren(newChild, GetRandmomNumberOfChildren(), depth); } data.AddChild(newChild); } }