/// <summary>
/// Sets the chart parameters
/// </summary>
public void InitChart(Over_optimization_Data_Table table)
{
this.table = table;
// Chart Title
chartTitle = table.Name;
font = new Font(Font.FontFamily, 9);
captionHeight = (float)Math.Max(font.Height, 18);
rectfCaption = new RectangleF(0, 0, ClientSize.Width, captionHeight);
stringFormatCaption = new StringFormat();
stringFormatCaption.Alignment = StringAlignment.Center;
stringFormatCaption.LineAlignment = StringAlignment.Center;
stringFormatCaption.Trimming = StringTrimming.EllipsisCharacter;
stringFormatCaption.FormatFlags = StringFormatFlags.NoWrap;
brushFore = new SolidBrush(LayoutColors.ColorChartFore);
penGrid = new Pen(LayoutColors.ColorChartGrid);
penGrid.DashStyle = DashStyle.Dash;
penGrid.DashPattern = new float [] { 4, 2 };
penBorder = new Pen(Data.GetGradientColor(LayoutColors.ColorCaptionBack, -LayoutColors.DepthCaption), border);
devSteps = table.CountDeviationSteps;
percentDev = (devSteps - 1) / 2;
parameters = table.CountStrategyParams;
if (parameters == 0)
{
return;
}
double minValue = double.MaxValue;
double maxValue = double.MinValue;
for (int param = 0; param < parameters; param++)
{
double min = double.MaxValue;
double max = double.MinValue;
for (int dev = 0; dev < devSteps; dev++)
{
int index = percentDev - dev;
double value = table.GetData(index, param);
if (min > value)
{
min = value;
}
if (max < value)
{
max = value;
}
}
if (minValue > min)
{
minValue = min;
}
if (maxValue < max)
{
maxValue = max;
}
}
maximum = (int)Math.Round(maxValue + 0.1 * Math.Abs(maxValue));
minimum = (int)Math.Round(minValue - 0.1 * Math.Abs(minValue));
int roundStep = Math.Abs(minimum) > 1 ? 10 : 1;
minimum = (int)(Math.Floor(minimum / (float)roundStep) * roundStep);
if (Math.Abs(maximum - minimum) < 1)
{
maximum = minimum + 1;
}
YTop = (int)captionHeight + 2 * space + 1;
YBottom = ClientSize.Height - 2 * space - 1 - border - space - Font.Height;
Graphics g = CreateGraphics();
labelWidth = (int)Math.Max(g.MeasureString(minimum.ToString(), font).Width, g.MeasureString(maximum.ToString(), font).Width);
g.Dispose();
labelWidth = Math.Max(labelWidth, 30);
XLeft = border + 3 * space;
XRight = ClientSize.Width - border - 2 * space - labelWidth;
XScale = (XRight - XLeft) / (float)(devSteps - 1);
XMiddle = (int)(XLeft + percentDev * XScale);
countLabels = (int)Math.Max((YBottom - YTop) / 20, 2);
delta = (float)Math.Max(Math.Round((maximum - minimum) / (float)countLabels), roundStep);
step = (int)Math.Ceiling(delta / roundStep) * roundStep;
countLabels = (int)Math.Ceiling((maximum - minimum) / (float)step);
maximum = minimum + countLabels * step;
YScale = (YBottom - YTop) / (countLabels * (float)step);
apntParameters = new PointF[parameters][];
for (int param = 0; param < parameters; param++)
{
apntParameters[param] = new PointF[devSteps];
for (int dev = 0; dev < devSteps; dev++)
{
int index = percentDev - dev;
apntParameters[param][dev].X = XLeft + dev * XScale;
apntParameters[param][dev].Y = (float)(YBottom - (table.GetData(index, param) - minimum) * YScale);
}
}
}