private static void DrawLabels(Graphics g, HeatmapData data, int cellWidth, int cellHeight) { var font = new Font(FontFamily.GenericMonospace, 10); for (var x = 0; x < data.XLabels.Length; x++) { var text = data.XLabels[x]; var labelRect = new RectangleF(cellWidth * (1 + x), data.YLabels.Length * cellHeight, cellWidth, cellHeight); var format = new StringFormat(); format.LineAlignment = StringAlignment.Near; format.Alignment = StringAlignment.Center; g.DrawString(text, font, new SolidBrush(Color.Black), labelRect, format); } for (var y = 0; y < data.YLabels.Length; y++) { var text = data.YLabels[y]; var labelRect = new RectangleF(0, y * cellHeight, cellWidth, cellHeight); var format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Far; g.DrawString(text, font, new SolidBrush(Color.Black), labelRect, format); } }
private static void DrawHeatmap(Rectangle clientRect, Graphics g, HeatmapData data) { var values = data.Heat.Cast <double>().ToList(); var avgHeat = values.Average(); var sigma = Math.Sqrt(values.Average(x => (x - avgHeat) * (x - avgHeat))); var cellWidth = clientRect.Width / (data.XLabels.Length + 1); var cellHeight = clientRect.Height / (data.YLabels.Length + 1); for (var x = 0; x < data.XLabels.Length; x++) { for (var y = 0; y < data.YLabels.Length; y++) { var color = GetColor(data.Heat[x, y], avgHeat, sigma); var cellRect = new Rectangle( clientRect.Left + cellWidth * (1 + x), clientRect.Top + cellHeight * y, cellWidth, cellHeight ); g.FillRectangle(new SolidBrush(color), cellRect); } } DrawLabels(g, data, cellWidth, cellHeight); }
public bool Equals(HeatmapData other) { return(Enumerable.Range(0, 2) .All(dimension => Heat.GetLength(dimension) == other.Heat.GetLength(dimension)) && Heat .Cast <double>() .SequenceEqual(other.Heat .Cast <double>())); }
public static void ShowHeatmap(HeatmapData stats) { var form = new Form { Text = stats.Title, Size = new Size(800, 600) }; form.Paint += (s, e) => DrawHeatmap(form.ClientRectangle, e.Graphics, stats); form.ShowDialog(); }
public static HeatmapData GetBirthsPerDateHeatmap(NameData[] names) { var label = ArrayInit(30, 2); var months = ArrayInit(12, 1); var heatMap = new double[30, 12]; for (int i = 0; i < names.Length; i++) { if (names[i].BirthDate.Day != 1) { heatMap[names[i].BirthDate.Day - 2, names[i].BirthDate.Month - 1]++; } } var result = new HeatmapData("Тепловая карта рождаемости в зависимости от дня и месяца для заданного имени", heatMap, label, months); return(result); }