public void RePlot() { treemap = null; treemap = new TreeMapItem(); try { prm prm = new prm(); prm.treemap = this; prm.treemapitem = treemap; prm.fileitem = currentObject; prm.rect = new RectangleF(0, 0, this.Width, this.Height); Thread myThread; myThread = new Thread(new ParameterizedThreadStart(Plotter), 10000000); myThread.IsBackground = false; myThread.Start(prm); //treemap.Plot(currentObject, new RectangleF(0, 0, this.Width, this.Height)); } catch (Exception ex) { MessageBox.Show(ex.Message); } GC.Collect(); }
private void Squarify(TreeMapItem values, List <TreeMapItem> currentRow, float width) { if (values.TreeMapItems.Count == 0) { return; } if (width <= 0) { return; } List <TreeMapItem> nextIterationPreview = new List <TreeMapItem>(); try { nextIterationPreview.AddRange(currentRow.ToArray()); } catch (System.StackOverflowException ex) { Console.WriteLine(ex.Message); } //foreach (TreeMapItem item in currentRow) nextIterationPreview.Add(item); try { if (values.TreeMapItems.Count > 1) { nextIterationPreview.Add(values.TreeMapItems[0]); } }catch (System.StackOverflowException ex) { Console.WriteLine(ex.Message); } double aspectRatio = CalculateAspectRatio(currentRow, width); double nextAspectRatio = CalculateAspectRatio(nextIterationPreview, width); if (aspectRatio == 0 || (nextAspectRatio < aspectRatio && nextAspectRatio >= 1)) { currentRow.Add(values.TreeMapItems[0]); values.TreeMapItems.RemoveAt(0); currentHeight = CalculateHeight(currentRow, width); if (values.TreeMapItems.Count > 0) { Squarify(values, currentRow, width); } else { LayoutRow(currentRow); } } else { // Row has reached it's optimum size LayoutRow(currentRow); // Start the next row, by passing an empty list of row values and recalculating the current width List <TreeMapItem> newlist = new List <TreeMapItem>(); Squarify(values, newlist, GetWidth()); } }
internal void Highlight(Graphics g, bool highlight, TreeMapItem next) { while (next != null) { if (next.DiskItem.Type == DiskItem.NodeType.File) { DrawFile(g, next.Rectangle, next.DiskItem.Name, highlight, next.DiskItem); } else { DrawFolder(g, next.Rectangle, next.DiskItem.Name, highlight, next.DiskItem); } next = next.Parent; } }
void FindNode(TreeMapItem node, float x, float y) { if (node == null) { return; } if (node.Rectangle.Contains(x, y)) { foundNode = node; } foreach (TreeMapItem n in node.TreeMapItems) { FindNode(n, x, y); } }
public void Load(TreeNode parent) { this.TreeNode = parent; if (!Visible) { return; } currentObject = null; disk = null; treemap = null; if (root != null) { root.Dispose(); } root = null; if (diskReader != null) { diskReader.Cancel = true; } diskReader = null; if (copy != null) { copy.Dispose(); } copy = null; root = (PIDL)((PIDL)parent.Tag).Clone(); if (root.PhysicalPath.Length > 0) { using (Graphics g = Graphics.FromImage(Image)) { g.Clear(Color.White); WriteCaption(g, "Loading " + " " + root.DisplayName, new Rectangle(0, 0, this.Width, this.Height), Color.Black, true, 30f); this.Invoke(new UpdateScreenCallback(this.Refresh), null); } diskReader = new DiskReader(root.PhysicalPath, null); diskReader.DiskReadComplete += DiskReader_DiskReadComplete; diskReader.Progress += DiskReader_Progress; } }
private TreeMapItem PrepareTreeMapItems(List <DiskItem> values) { TreeMapItem TreeMapItems = new TreeMapItem(); try { values.Sort(delegate(DiskItem x, DiskItem y) { return(y.Size.CompareTo(x.Size)); }); } catch { return(TreeMapItems); } totalArea = workAreaWidth * workAreaHeight; float sumOfValues = this.TreeeNodeSize; for (int i = 0; i < values.Count; i++) { DiskItem diskItem = values[i]; double percentage = (diskItem.Size / sumOfValues) * 100; float area = (float)((totalArea / 100) * percentage); if (area > 0) { TreeMapItem tm = new TreeMapItem(); tm.Key = diskItem.FullPath; tm.Area = area; tm.Percentage = percentage; tm.DiskItem = diskItem; tm.TreeeNodeSize = diskItem.Size; tm.Key = diskItem.FullPath; tm.DisplayName = diskItem.Name; TreeMapItems.Area += area; TreeMapItems.Add(tm); } } return(TreeMapItems); }
protected override void OnMouseMove(MouseEventArgs e) { if (this.X == e.X && this.Y == e.Y) { return; } this.X = e.X; this.Y = e.Y; base.OnMouseMove(e); try { Task t = Task.Run(() => { lastFoundNode = foundNode; FindNode(treemap, X, Y); }); t.Wait(); if (foundNode != null) { tooltip.Filename = foundNode.DiskItem.FullPath; if (foundNode.DiskItem.Type == DiskItem.NodeType.Folder || foundNode.DiskItem.Type == DiskItem.NodeType.Disk) { tooltip.Caption = foundNode.DisplayName + Environment.NewLine + " Size:" + foundNode.DiskItem.Size.ToString("#,##0") + " bytes" + Environment.NewLine + " Files:" + foundNode.DiskItem.Files.ToString("#,##0") + Environment.NewLine + " Folders:" + foundNode.DiskItem.Folders.ToString("#,##0"); } else { tooltip.Caption = foundNode.DisplayName + Environment.NewLine + " Size:" + foundNode.DiskItem.Size.ToString("#,##0") + " bytes"; } tooltip.SetToolTip(this, tooltip.Caption); using (Graphics offScreenDC = Graphics.FromImage(this.Image)) { using (Graphics clientDC = Graphics.FromImage(this.Image)) clientDC.DrawImage(copy, 0, 0); Highlight(offScreenDC, true, foundNode); } tooltip.Show(tooltip.Caption, this); } using (Graphics clientDC = this.CreateGraphics()) clientDC.DrawImage(this.Image, 0, 0); //{ // // Restore background // using (Graphics clientDC = Graphics.FromImage(this.Image)) clientDC.DrawImage(copy, 0, 0); // if (foundNode != null) // { // //Highlight(offScreenDC, true, foundNode); // using (PIDL pidl = new PIDL(foundNode.FileItem.FullPath)) // { // string counters = ""; // string attributes = ""; // string ishidden = ""; // string issystem = ""; // if (foundNode.FileItem.IsHidden) ishidden = "Hidden"; // if (foundNode.FileItem.IsSystem) issystem = "System"; // if (ishidden.Length > 0 || issystem.Length > 0) // attributes = Environment.NewLine + ishidden + " " + issystem; // if (foundNode.FileItem.FileItemType != FileItem.FileItemTypes.File) // counters = Environment.NewLine + "Contains: " + foundNode.FileItem.Files.ToString("#,##0") + " Files, " + foundNode.FileItem.Folders.ToString("#,##0") + " Folders"; // tooltip.Filename = foundNode.FileItem.FullPath; // tooltip.Caption = foundNode.DisplayName + Environment.NewLine // + pidl.TypeName + Environment.NewLine // + foundNode.FileItem.ActualSize.ToString("#,##0") + " bytes" + counters // + attributes // ; // if (lastTooltip != tooltip.Caption) // tooltip.SetToolTip(this, tooltip.Caption); // lastTooltip = tooltip.Caption; // } // } // using (Graphics clientDC = this.CreateGraphics()) clientDC.DrawImage(this.Image, 0, 0); //} } catch { } }
public TreeMapItem Add(TreeMapItem item) { TreeMapItems.Add(item); return(item); }
private void LayoutRow(List <TreeMapItem> rowTreeMapItems) { PointF brushStartingPoint = new PointF(brushX, brushY); if (!vertical) { if (workAreaHeight != currentHeight) { brushY = workAreaHeight - currentHeight + top; } } // Draw each TreeMapItem in the current row float width; float height; foreach (TreeMapItem TreeMapItem in rowTreeMapItems) { if (TreeMapItem.Area > 0) { // Calculate Width & Height if (vertical) { width = currentHeight; height = TreeMapItem.Area / currentHeight; } else { width = TreeMapItem.Area / currentHeight; height = currentHeight; } TreeMapItem.Rectangle = new RectangleF(brushX, brushY, width, height); // Recursivley Add Folder objects TreeMapItem.Parent = this; if (TreeMapItem.DiskItemNodeType != DiskItem.NodeType.File) { //if (height >= 20f && width >= 6f) if (height > maxHeight && width > maxWidth) { TreeMapItem.Plot(TreeMapItem.DiskItem, TreeMapItem.Rectangle, this.maxDepth); } } this.Add(TreeMapItem); // Reposition brush for the next TreeMapItem if (vertical) { brushY += height; } else { brushX += width; } } } // Finished drawing all TreeMapItems in the row // Reposition the brush ready for the next row if (vertical) { // x increase by width (in vertical, currentHeight is width) // y reset to starting position brushX += currentHeight; brushY = brushStartingPoint.Y; workAreaWidth -= currentHeight; } else { brushX = brushStartingPoint.X; brushY = brushStartingPoint.Y; workAreaHeight -= currentHeight; } currentHeight = 0; }