public void CreateLegendBitmap(string file) { var bitmap = new System.Drawing.Bitmap(2000, 2000); var graphics = Graphics.FromImage(bitmap); var line = 0; Debug.Assert(_names.Count > 0); foreach (var name in _names) { // Legend var x = 0; var y = 30 * line; const int offsetColorName = 25; const int offsetDeveloperName = 200; var brush = ToDrawingBrush(_brushFactory.GetBrush(name)); graphics.FillRectangle(brush, x, y, 20, 20); graphics.DrawString("(" + GetColorName(name) + ")", new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, x + offsetColorName, y); graphics.DrawString(name, new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, x + offsetDeveloperName, y); line++; } var trimmed = BitmapManipulation.TrimBitmap(bitmap); trimmed.Save(file); }
public void CreateLegendBitmap(string file) { var bitmap = new System.Drawing.Bitmap(2000, 2000); var graphics = Graphics.FromImage(bitmap); var line = 0; var developersToPrint = ColorScheme.Names.ToList(); Debug.Assert(developersToPrint.Count > 0); foreach (var developer in developersToPrint) { // Legend var x = 0; var y = 30 * line; var offsetColorName = 25; var offsetDeveloperName = 200; var brush = ColorScheme.GetBrush(developer); graphics.FillRectangle(brush, x, y, 20, 20); graphics.DrawString("(" + ColorScheme.GetColorName(developer) + ")", new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, x + offsetColorName, y); graphics.DrawString(developer, new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, x + offsetDeveloperName, y); line++; } var trimmed = BitmapManipulation.TrimBitmap(bitmap); trimmed.Save(file); }
public void Create(string filename, Dictionary <string, uint> workByDevelopers, ColorScheme colorMapperMapping, bool legend) { double allWork = workByDevelopers.Values.Sum(w => w); // For the fractal var width = 200; var height = 200; var remainingWidth = width; var remainingHeight = height; // Reserve plenty of space. Trimmed later. var bitmap = new System.Drawing.Bitmap(2000, 2000); var graphics = Graphics.FromImage(bitmap); var sorted = workByDevelopers.ToList().OrderByDescending(pair => pair.Value).ToList(); var oneUnitOfWork = width * height / allWork; var x = 0; var y = 0; var vertical = true; var index = 0; foreach (var developersWork in sorted) { var brush = colorMapperMapping.GetBrush(developersWork.Key); if (legend) { var legendY = index * 30; var legendX = 250; graphics.DrawString(developersWork.Key, new Font(FontFamily.GenericSansSerif, 12), Brushes.Black, legendX + 25, legendY); graphics.FillRectangle(brush, legendX, legendY, 20, 20); } var workArea = developersWork.Value; var pixelArea = oneUnitOfWork * workArea; if (index == sorted.Count - 1) { // Due to rounding there is always some pixels left. Give the last // developer the remaining space. pixelArea = remainingWidth * remainingHeight; } if (vertical) { var widthOfWork = (int)Math.Round(pixelArea / remainingHeight); graphics.FillRectangle(brush, x, y, widthOfWork, remainingHeight); graphics.DrawRectangle(Pens.Black, x, y, widthOfWork, remainingHeight); x += widthOfWork; remainingWidth -= widthOfWork; } else { var heightOfWork = (int)Math.Round(pixelArea / remainingWidth); graphics.FillRectangle(brush, x, y, remainingWidth, heightOfWork); graphics.DrawRectangle(Pens.Black, x, y, remainingWidth, heightOfWork); y += heightOfWork; remainingHeight -= heightOfWork; } // Toggle next orientation vertical = !vertical; index++; } graphics.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1); BitmapManipulation.TrimBitmap(bitmap).Save(filename); }