Выкладываю своё решение, на случай если кто-то тоже столкнется с похожей задачей:
private void PB_Paint(object sender, PaintEventArgs e)
{
const float DayMinuts = 1440;
const float RowHeight = 20;
const float MinWidth = 15;
var rect1 = new Rectangle(0, 0, PB.Width, 50);
var rect2 = new Rectangle(0, 50, 80, PB.Height - rect1.Height);
var rect3 = new Rectangle(80, rect1.Height, PB.Width - rect2.Width - 20, PB.Height - rect1.Height - 10);
var tariffZones = _viewModel.CurrentCategory.TariffZones;
var uniqueTimes = tariffZones.SelectMany(x => new[] {x.TimeStart, x.TimeEnd}).Distinct().ToList();
var columnsWidth = tariffZones.Select(tz => (float) Math.Round(rect3.Width * (float) tz.Period / DayMinuts)).ToList();
if (columnsWidth.Any(x => x < MinWidth))
columnsWidth = RecalculateWidths(columnsWidth, MinWidth);
columnsWidth.Insert(0, 0);
var sortingData = tariffZones.OrderBy(x => x.TariffNumber)
.GroupBy(x => x.TariffNumber)
.ToDictionary(g => g.Key, g => g.ToList());
var drawFormat = new StringFormat { FormatFlags = StringFormatFlags.DirectionVertical };
using (var penLine = new Pen(Color.LightGray, 2))
{
var width = 0f;
for (var j = 0; j < uniqueTimes.Count; j++)
{
var str = uniqueTimes[j].ToString("HH:mm");
if (j == uniqueTimes.Count - 1)
str = midnight;
var margin = TextRenderer.MeasureText(str, Font);
width += columnsWidth[j];
e.Graphics.DrawString(str, Font, Brushes.Black, rect3.X - margin.Height / 1.5f + width, 10, drawFormat);
}
var height = 0f;
foreach (var tz in sortingData)
{
width = 0;
var drawStr = true;
for (var j = 0; j < uniqueTimes.Count; j++)
{
var X = rect3.X + width;
var Y = rect3.Y + height;
e.Graphics.DrawRectangle(penLine, X, Y, columnsWidth[j], RowHeight);
width += columnsWidth[j];
if (drawStr)
{
var str = string.Format(CultureInfo.InvariantCulture, Resources.EM_TariffNumber, tz.Key);
var margin = (RowHeight - TextRenderer.MeasureText(str, Font).Height) / 2;
e.Graphics.DrawString(str, Font, Brushes.Black, 10, rect3.Y + margin + height);
drawStr = false;
}
}
height += RowHeight;
}
height = 0;
foreach (var date in sortingData)
{
width = 0f;
for (var j = 0; j < tariffZones.Count; j++)
{
var X = rect3.X + width;
var Y = rect3.Y + height;
if (date.Value.Any(t => t.TimeStart == uniqueTimes[j]))
{
var t = columnsWidth[j + 1];
e.Graphics.FillRectangle(Brushes.CornflowerBlue, X + 1, Y + 1, columnsWidth[j + 1] - 2,
RowHeight - 2);
}
width += columnsWidth[j + 1];
}
height += RowHeight;
}
}
PB.Height = (int) (rect1.Height + sortingData.Count * RowHeight);
}