public static double[] CheckOutstanding(double[] data, out double[] clearData, float alpha) { List <double> dataList = new List <double>(data); List <double> trashList = new List <double>(); bool changes; do { changes = false; data = dataList.ToArray(); double mean = StatisticsProcessor.Srednee(data); double S = Math.Sqrt(StatisticsProcessor.Dispersion(data)); double Xmax = StatisticsProcessor.FindMax(data); double TnMax = (Xmax - mean) / S; if (TnMax > TTable(alpha, (uint)(data.Length))) { changes = true; dataList.Remove(Xmax); trashList.Add(Xmax); } double Xmin = StatisticsProcessor.FindMin(data); double TnMin = (mean - Xmin) / S; if (TnMin > TTable(alpha, (uint)(data.Length))) { changes = true; dataList.Remove(Xmin); trashList.Add(Xmin); } }while (changes); clearData = dataList.ToArray(); return(trashList.Count > 0 ? trashList.ToArray() : null); }
public void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.HighQuality; //Color cl = Color.FromArgb(255, 250, 242); Color cl = Color.FromArgb(240, 240, 242); g.Clear(cl); g.Transform = new Matrix(1, 0, 0, -1, 0, sz.Height - 1); #region Zoom calculation zoom_x = sz.Width / (Y.Length + 1f); ptMargins = new PointF(zoom_x, new Font(FONT_FACE, FONT_HEIGHT).GetHeight() * 2f); float MaxMin = (float)(StatisticsProcessor.FindMax(Y) - StatisticsProcessor.FindMin(Y)); float Ampl = (MaxMin > float.Epsilon ? MaxMin : 1); zoom_y = (sz.Height - 2 * ptMargins.Y - 1) / Ampl; #endregion #region switch on the kind of the diagram switch (kindOfDiagram) { case KindOfDiagram.LeftArrows: DrawLeftSideArrows(g, zoom_x, zoom_y); break; case KindOfDiagram.Histogram: DrawHistogram(g, zoom_x, zoom_y); break; case KindOfDiagram.Polygon: DrawPolygon(g, zoom_x, zoom_y); break; case KindOfDiagram.Metrolog: DrawMetrolog(g, zoom_x, zoom_y); break; default: DrawHistogram(g, zoom_x, zoom_y); break; } #endregion }
private void DrawValues(Graphics g, float oy, float zoom_x, float zoom_y) { Font font = new Font(FONT_FACE, FONT_HEIGHT, FontStyle.Bold); SolidBrush brush = new SolidBrush(Color.FromKnownColor(KnownColor.ControlText)); double max = StatisticsProcessor.FindMax(Y); double min = StatisticsProcessor.FindMin(Y); int stps = 20; g.ScaleTransform(1, -1); for (int i = 0; i <= stps; i++) { PointF point = new PointF( 0, -((float)((max - min) * i / stps + min) * zoom_y + 0.5f * font.Height + oy) ); string valStr = string.Format("{0:F2}", (max - min) * i / stps + min); g.DrawString(valStr, font, brush, point); } g.ScaleTransform(1, -1); }
private void DrawHistogram(Graphics g, float zoom_x, float zoom_y) { double min = StatisticsProcessor.FindMin(Y); double max = StatisticsProcessor.FindMax(Y); float oy = 0; float zy = zoom_y; if (max < 0) // signs equals - { oy = sz.Height - ptMargins.Y; zy = (sz.Height - 2 * ptMargins.Y - 1) / (float)Math.Abs(min); } else if (min > 0) // signs equals + { oy = ptMargins.Y; zy = (sz.Height - 2 * ptMargins.Y - 1) / (float)Math.Abs(max); } else if (max != min) // signs differs { oy = (sz.Height - 2 * ptMargins.Y - 1) * (float)(Math.Abs(min) / (max - min)) + ptMargins.Y; zy = (sz.Height - 2 * ptMargins.Y - 1) / (float)(Math.Abs(min) + Math.Abs(max)); } else // stable zero { oy = 0; zy = sz.Height - 2 * ptMargins.Y - 1; } DrawAxes(g, oy); for (int i = 0; i < Y.Length; i++) { RectangleF rect = new RectangleF( i * zoom_x + 0.1f * zoom_x + ptMargins.X / 2f, (float)(Y[i] * zy > 0 ? 0 : Y[i] * zy) + oy, 1f * zoom_x - 0.2f * zoom_x, (float)(Math.Abs(Y[i]) * zy)); if (rect.Height < float.Epsilon) { rect.Height += 1.5f; } //0e+20f * float.Epsilon; LinearGradientBrush lgb = new LinearGradientBrush(rect, penColor, Color.FromKnownColor(KnownColor.ControlDark), 75); g.FillRectangle(lgb, rect); } Font font = new Font(FONT_FACE, FONT_HEIGHT); SolidBrush brush = new SolidBrush(Color.FromKnownColor(KnownColor.ControlText)); g.ScaleTransform(1, -1); for (int i = 0; i < Y.Length; i++) { PointF point = new PointF( (i + .5f) * zoom_x + ptMargins.X / 2f, -(float)(Y[i] * zy + 1.0f * font.Height * Math.Sign(Y[i]) + oy) ); string valStr = Y[i].ToString(); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; float actual_width = 0; int dig_count = 1; while (actual_width < 0.9f * zoom_x && dig_count <= 15) { double trim_val = Math.Round(Y[i], dig_count++); valStr = trim_val.ToString(); actual_width = g.MeasureString(valStr, font, point, sf).Width; } g.DrawString(valStr, font, brush, point, sf); } g.ScaleTransform(1, -1); }