in src/StructuredLogViewer/Controls/BuildControl.xaml.cs [1869:1942]
private UIElement GetHistogram(List<int> values)
{
double width = 800;
double height = 200;
var fill = Brushes.AliceBlue;
var border = Brushes.LightBlue;
var canvas = new Canvas()
{
Width = width,
Height = height,
Background = Brushes.Azure
};
double max = values.Max();
int count = values.Count;
for (double x = 0; x < width; x++)
{
int startIndex = (int)(x / width * count);
int endIndex = (int)((x + 1) / width * count);
if (startIndex < 0)
{
startIndex = 0;
}
if (endIndex >= count)
{
endIndex = count;
}
if (startIndex >= endIndex)
{
continue;
}
int sum = 0;
int maxInBucket = 0;
for (int i = startIndex; i < endIndex; i++)
{
int value = values[i];
sum += value;
if (maxInBucket < value)
{
maxInBucket = value;
}
}
if (sum == 0)
{
continue;
}
double y = height * maxInBucket / max;
if (y < height / 2)
{
y += 5;
}
var rect = new System.Windows.Shapes.Rectangle
{
Width = 1,
Height = y,
Fill = fill,
Stroke = border
};
Canvas.SetLeft(rect, x);
Canvas.SetTop(rect, height - y);
canvas.Children.Add(rect);
}
return canvas;
}