private void SetTreemapItemsParameters(int i, List <TreemapItem> items) { TreemapIndex index = Parameters.Indexes[i]; foreach (TreemapItem item in items) { item.IndexParameters = index; if (index.HasHeader && Parameters.Algorithm != TreemapAlgorithm.Circular) { FontStyle style = index.FontBold ? FontStyle.Bold : FontStyle.Regular; Font font = new Font(DefaultFontFamily, (float)index.FontSize, style, GraphicsUnit.Pixel); float height = font.RenderText(item.Indexes.Last()).Height; item.SetMargin(new Margin(index.Padding.Left, height, index.Padding.Right, index.Padding.Bottom)); } if (i == Indexes.Count - 1) { item.FillColor = Parameters.Color.GetColor(item.Color); } else { item.FillColor = index.FillColor; } } }
private void Draw(TreemapItem item) { TreemapIndex index = item.IndexParameters; //Add background shapes if (!item.IsParent() && (index.HasHeader || item.IsChild() || Parameters.Algorithm == TreemapAlgorithm.Circular)) { Excel.Shape shape = AddShape(ShapeType, item.Rectangle, item.FillColor); SetShapeLine(shape, index.GetLineOptions()); SetShapeText(shape, item); } //Add Children Items foreach (var child in item.Items) { Draw(child); } //Add front shapes if (!item.IsParent() && !item.IsChild()) { Excel.Shape frontShape = AddShape(ShapeType, item.InnerRectangle, Color.Transparent); if (Parameters.Algorithm == TreemapAlgorithm.Circular) { frontShape.Line.Visible = GetState(false); SetShapeText(frontShape, item); } else if (!index.HasHeader) { SetShapeLine(frontShape, index.GetLineOptions()); SetShapeText(frontShape, item); } else //Case Header : inner border & no text { SetShapeLine(frontShape, index.GetLineOptions().With(o => o.Weight = 1)); } } }
public TreemapIndex GetTreemapIndex() { TreemapIndex index = new TreemapIndex(); index.HasHeader = HasHeader; index.Padding = new Margin(Margin); index.FillColor = System.Drawing.Color.FromArgb(FillColor.R, FillColor.G, FillColor.B); index.LineVisible = LineVisible; index.LineWeight = LineWeight; index.LineColor = System.Drawing.Color.FromArgb(LineColor.R, LineColor.G, LineColor.B); index.FontSize = FontSize; index.FontColor = System.Drawing.Color.FromArgb(FontColor.R, FontColor.G, FontColor.B); index.FontBold = FontBold; index.FontOutline = FontOutline; index.FontOutlineColor = System.Drawing.Color.FromArgb(FontOutlineColor.R, FontOutlineColor.G, FontOutlineColor.B); index.FontOutlineWeight = FontOutlineWeight; index.FontGlowRadius = 0; index.FontGlowColor = System.Drawing.Color.Transparent; return index; }
public TreemapParameters AddIndex(TreemapIndex index) { Indexes.Add(index); return this; }
public TreemapParameters AddIndex(TreemapIndex index) { Indexes.Add(index); return(this); }
private void SetShapeText(Excel.Shape shape, TreemapItem item) { TreemapIndex index = item.IndexParameters; shape.TextFrame2.WordWrap = Microsoft.Office.Core.MsoTriState.msoTrue; shape.TextFrame2.MarginBottom = 0.01f; shape.TextFrame2.MarginTop = 0.01f; shape.TextFrame2.MarginLeft = 0.01f; shape.TextFrame2.MarginRight = 0.01f; if (index.HasHeader && Parameters.Algorithm != TreemapAlgorithm.Circular) { shape.TextFrame.VerticalAlignment = Excel.XlVAlign.xlVAlignTop; } else { shape.TextFrame.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; } shape.TextFrame.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; shape.TextFrame.Characters().Font.Bold = index.FontBold; shape.TextFrame.Characters().Font.Size = index.FontSize; shape.TextFrame.Characters().Font.Color = index.FontColor.ToRgb(); if (index.FontOutline) { shape.TextFrame2.TextRange.Font.Line.Visible = GetState(index.FontOutline); shape.TextFrame2.TextRange.Font.Line.ForeColor.RGB = index.FontOutlineColor.ToRgb(); shape.TextFrame2.TextRange.Font.Line.Weight = (float)index.FontOutlineWeight; } if (item.Items.Count == 0) { if (item.FillColor.GetBrightness() < 0.7) { shape.TextFrame.Characters().Font.Color = Color.White.ToRgb(); } else { shape.TextFrame.Characters().Font.Color = Color.Black.ToRgb(); } } string text = item.Indexes.Last(); float size = (float)index.FontSize; SizeF textSize = new Font(DefaultFontFamily, size).RenderText(text); int lines = (int)Math.Floor(textSize.Width / item.Rectangle.Width) + 1; while (size > 1 && lines * textSize.Height > item.Rectangle.Height) { size--; textSize = new Font(DefaultFontFamily, size).RenderText(text); lines = (int)Math.Floor(textSize.Width / item.Rectangle.Width) + 1; } if (size > 3) { shape.TextFrame.Characters().Text = text; shape.TextFrame.Characters().Font.Size = size; } }