Skip to content

Instantly share code, notes, and snippets.

@mjs3339
Created April 19, 2020 09:47
Show Gist options
  • Save mjs3339/9b745f46082b84a2659fe99b58bb1b62 to your computer and use it in GitHub Desktop.
Save mjs3339/9b745f46082b84a2659fe99b58bb1b62 to your computer and use it in GitHub Desktop.
Progress Graph Class
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public sealed class ProgressGraph : UserControl
{
public enum direction
{
LeftToRight,
RightToLeft
}
public enum PlotTypes
{
None,
Line,
Pixel,
Cross
}
public enum TextDrawingMode
{
None,
Standard,
AsPercentage
}
public enum TitleDrawingMode
{
None,
UpperLeft
}
public enum TitleJustify
{
Right,
Left,
Center
}
private const int Numberofgraphs = 10;
private readonly List<double> _firsttermavg = new List<double>();
private readonly List<double> _secondtermavg = new List<double>();
private readonly List<float[]> FastValues = new List<float[]>();
private byte _borderalpha = byte.MaxValue;
private Color _borderColor = Color.DodgerBlue;
private Pen _borderpen;
private int _borderWidth;
private byte _centerlinealpha = byte.MaxValue;
private Color _centerlinecolor = Color.White;
private Pen _centerlinepen;
private Bitmap[] _cross;
private Size[] _crosssize;
private direction _direction = direction.LeftToRight;
private bool _enableautosize;
private bool[] _enableaveraging;
private bool _enableBorder;
private bool _enablecenterline;
private bool _enableForeColorEdit;
private bool[] _enableGraph;
private bool[] _enableinterpolate;
private bool _enablepercentbar;
private bool[] _enabletrend;
private bool[] _enableunderfill;
private bool[] _enablexplottingline;
private bool[] _enableyplottingline;
private float _fontReduction = 1f;
private byte[] _graphAlpha;
private int[] _graphavergingsamplesize;
private Color[] _graphColor;
private float _graphmaxValue = 1f;
private float _graphminValue = 1f;
private float[] _graphpenwidth;
private PlotTypes[] _graphplottype;
private byte[] _graphunderfillAlpha;
private Color[] _graphunderfillColor;
private byte _gridalpha = 127;
private Color _gridColor = Color.DodgerBlue;
private bool _gridhorzshow;
private int _gridhorzstep = 10;
private Pen _gridpen;
private bool _gridvertshow;
private int _gridvertstep = 10;
private float _maxxstep;
private float _percent;
private byte _percentbaralpha = 127;
private Color _percentbarcolor = Color.Lime;
private Pen _percentbarpen;
private Color _percentFontColor = Color.White;
private Pen _percentPen;
private Bitmap[] _pixel;
private byte[] _plottingxlinealpha;
private Color[] _plottingxlinecolor;
private float[] _plottingxlinewidth;
private byte[] _plottingylinealpha;
private Color[] _plottingylinecolor;
private float[] _plottingylinewidth;
private SmoothingMode _quality = SmoothingMode.HighQuality;
private string _text = "";
private TextDrawingMode _textDrawingMode = TextDrawingMode.Standard;
private Rectangle _thisRectangle;
public string[] _Title = new string[4];
private TitleDrawingMode _titleDrawingMode = TitleDrawingMode.None;
private TitleJustify _titleJustify = TitleJustify.Left;
private int _trendsamplesize = 11;
private float _vector = 1f;
private Font _writingFont;
private int _xcurrent;
private float _xfactor;
private float _ycurrent;
private int[] _yplottinglineavergingsamplesize;
private int ArraySize;
public graph[] Graph;
private bool UseFastValues;
private float[] ValueHold;
public List<BArray<Element>> Values = new List<BArray<Element>>();
public ProgressGraph()
{
BackColor = Color.White;
DoubleBuffered = true;
Enabled = false;
Name = @"ProgressGraph";
Size = new Size(100, 41);
_thisRectangle = ClientRectangle;
InitializeStartValues();
}
[Description("Sets the direction the graph will be drawn.")]
public direction Direction
{
get => _direction;
set
{
_direction = value;
Invalidate();
}
}
[Description("Sets the color alpha of the x-axis plotting line.")]
public byte[] PlottingXLineAlpha
{
get => _plottingxlinealpha;
set
{
_plottingxlinealpha = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Plottingxlinealpha = _plottingxlinealpha[g];
Graph[g].Plottingxlinepen = new Pen(Graph[g].Plottingxlinecolor, Graph[g].Plottingxlinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingxlinealpha, Graph[g].Plottingxlinecolor))
};
}
Invalidate();
}
}
[Description("Sets the color of the Progress Rectangle (Under fill)")]
public Color[] PlottingXLineColor
{
get => _plottingxlinecolor;
set
{
_plottingxlinecolor = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Plottingxlinecolor = _plottingxlinecolor[g];
Graph[g].Plottingxlinepen = new Pen(Graph[g].Plottingxlinecolor, Graph[g].Plottingxlinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingxlinealpha, Graph[g].Plottingxlinecolor))
};
}
Invalidate();
}
}
[Description("Sets the x-axis pen line width")]
public float[] PlottingXLineWidth
{
get => _plottingxlinewidth;
set
{
_plottingxlinewidth = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Plottingxlinewidth = _plottingxlinewidth[g];
Graph[g].Plottingxlinepen = new Pen(Graph[g].Plottingxlinecolor, Graph[g].Plottingxlinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingxlinealpha, Graph[g].Plottingxlinecolor))
};
}
Invalidate();
}
}
[Description("Sets the color alpha of the plotting line.")]
public byte[] PlottingYLineAlpha
{
get => _plottingylinealpha;
set
{
_plottingylinealpha = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Plottingylinealpha = _plottingylinealpha[g];
Graph[g].Plottingylinepen = new Pen(Graph[g].Plottingylinecolor, Graph[g].Plottingylinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingylinealpha, Graph[g].Plottingylinecolor))
};
}
Invalidate();
}
}
[Description("Sets the color of the plotting line")]
public Color[] PlottingYLineColor
{
get => _plottingylinecolor;
set
{
_plottingylinecolor = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Plottingylinecolor = _plottingylinecolor[g];
Graph[g].Plottingylinepen = new Pen(Graph[g].Plottingylinecolor, Graph[g].Plottingylinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingylinealpha, Graph[g].Plottingylinecolor))
};
}
Invalidate();
}
}
[Description("Sets the y-axis pen line width")]
public float[] PlottingYLineWidth
{
get => _plottingylinewidth;
set
{
_plottingylinewidth = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Plottingylinewidth = _plottingylinewidth[g];
Graph[g].Plottingylinepen = new Pen(Graph[g].Plottingylinecolor, Graph[g].Plottingylinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingylinealpha, Graph[g].Plottingylinecolor))
};
}
Invalidate();
}
}
[Category("Behavior")]
[Description("If Enabled draws an x-axis plotting line.")]
public bool[] EnableXPlottingLine
{
get => _enablexplottingline;
set
{
_enablexplottingline = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Enablexplottingline = _enablexplottingline[g];
Invalidate();
}
}
[Description("Sets the sample size for averaging of the graph.")]
public int[] GraphAveragingSampleSize
{
get => _graphavergingsamplesize;
set
{
_graphavergingsamplesize = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Graphavergingsamplesize = _graphavergingsamplesize[g];
Invalidate();
}
}
[Description("Sets the sample size for averaging of the y-axis plotting line.")]
public int[] YPlottingLineAveragingSampleSize
{
get => _yplottinglineavergingsamplesize;
set
{
_yplottinglineavergingsamplesize = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Yplottinglineavergingsamplesize = _yplottinglineavergingsamplesize[g];
Invalidate();
}
}
[Description("Enable or disable an y-axis plotting line.")]
public bool[] EnableYPlottingLine
{
get => _enableyplottingline;
set
{
_enableyplottingline = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Enableyplottingline = _enableyplottingline[g];
Invalidate();
}
}
[Description("Enable or disable xy-axis graph averaging.")]
public bool[] EnableAveraging
{
get => _enableaveraging;
set
{
_enableaveraging = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Enableaveraging = _enableaveraging[g];
Invalidate();
}
}
[Description("Set the plot type(Cross) size.")]
public Size[] CrossSize
{
get => _crosssize;
set
{
_crosssize = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Crosssize = _crosssize[g];
Graph[g].Cross = new Bitmap(_crosssize[g].Width, _crosssize[g].Height, PixelFormat.Format32bppArgb);
_cross[g] = new Bitmap(_crosssize[g].Width, _crosssize[g].Height, PixelFormat.Format32bppArgb);
DrawCross(g);
}
Invalidate();
}
}
[Description("Set the graph plot type.")]
public PlotTypes[] GraphPlotType
{
get => _graphplottype;
set
{
_graphplottype = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Graphplottype = _graphplottype[g];
Invalidate();
}
}
[Description("Enable or disable the graph trend")]
public bool[] EnableTrend
{
get => _enabletrend;
set
{
_enabletrend = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Enabletrend = _enabletrend[g];
Invalidate();
}
}
[Description("Enable or disable the graph under fill.")]
public bool[] EnableUnderFill
{
get => _enableunderfill;
set
{
_enableunderfill = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Enableunderfill = _enableunderfill[g];
Invalidate();
}
}
[Description("Enable or disable data interpolation")]
public bool[] EnableInterpolate
{
get => _enableinterpolate;
set
{
_enableinterpolate = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g].Enableinterpolate = _enableinterpolate[g];
Invalidate();
}
}
[Description("Enable or disable the graph")]
public bool[] EnableGraph
{
get => _enableGraph;
set
{
_enableGraph = value;
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g]._EnableGraph = _enableGraph[g];
Invalidate();
}
}
[Description("Sets the color of the Graph (Under fill)")]
public Color[] GraphUnderFillColor
{
get => _graphunderfillColor;
set
{
_graphunderfillColor = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].GraphunderfillColor = _graphunderfillColor[g];
Graph[g].Graphpen = new Pen(Graph[g]._graphColor, Graph[g].Graphpenwidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g]._graphAlpha, Graph[g]._graphColor))
};
Graph[g].FilledPlotPen = new Pen(Graph[g].GraphunderfillColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].GraphunderfillAlpha, Graph[g].GraphunderfillColor))
};
}
Invalidate();
}
}
[Description("Sets the color alpha of the graph (Under fill)")]
public byte[] GraphUnderFillAlpha
{
get => _graphunderfillAlpha;
set
{
_graphunderfillAlpha = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].GraphunderfillAlpha = _graphunderfillAlpha[g];
Graph[g].Graphpen = new Pen(Graph[g]._graphColor, Graph[g].Graphpenwidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g]._graphAlpha, Graph[g]._graphColor))
};
Graph[g].FilledPlotPen = new Pen(Graph[g].GraphunderfillColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].GraphunderfillAlpha, Graph[g].GraphunderfillColor))
};
}
Invalidate();
}
}
[Description("Sets the color alpha of the graph")]
public byte[] GraphAlpha
{
get => _graphAlpha;
set
{
_graphAlpha = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g]._graphAlpha = _graphAlpha[g];
Graph[g].Graphpen = new Pen(Graph[g]._graphColor, Graph[g].Graphpenwidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g]._graphAlpha, Graph[g]._graphColor))
};
Graph[g].FilledPlotPen = new Pen(Graph[g].GraphunderfillColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].GraphunderfillAlpha, Graph[g].GraphunderfillColor))
};
}
Invalidate();
}
}
[Description("Sets the color of the Graph")]
public Color[] GraphColor
{
get => _graphColor;
set
{
_graphColor = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g]._graphColor = _graphColor[g];
Graph[g].Pixel.SetPixel(0, 0, Graph[g]._graphColor);
_pixel[g].SetPixel(0, 0, Graph[g]._graphColor);
Graph[g].Graphpen = new Pen(Graph[g]._graphColor, Graph[g].Graphpenwidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g]._graphAlpha, Graph[g]._graphColor))
};
Graph[g].FilledPlotPen = new Pen(Graph[g].GraphunderfillColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].GraphunderfillAlpha, Graph[g].GraphunderfillColor))
};
DrawCross(g);
}
Invalidate();
}
}
[Description("Sets the color alpha of the graph")]
public float[] GraphPenWidth
{
get => _graphpenwidth;
set
{
_graphpenwidth = value;
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Graphpenwidth = _graphpenwidth[g];
Graph[g].Graphpen = new Pen(Graph[g]._graphColor, Graph[g].Graphpenwidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g]._graphAlpha, Graph[g]._graphColor))
};
Graph[g].FilledPlotPen = new Pen(Graph[g].GraphunderfillColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].GraphunderfillAlpha, Graph[g].GraphunderfillColor))
};
}
Invalidate();
}
}
[Description("Sets the color alpha of the percent bar")]
public byte PercentBarAlpha
{
get => _percentbaralpha;
set
{
_percentbaralpha = value;
_percentbarpen = new Pen(_percentbarcolor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_percentbaralpha, _percentbarcolor))
};
Invalidate();
}
}
[Description("Sets the color of the Percent bar")]
public Color PercentBarColor
{
get => _percentbarcolor;
set
{
_percentbarcolor = value;
_percentbarpen = new Pen(_percentbarcolor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_percentbaralpha, _percentbarcolor))
};
Invalidate();
}
}
[Description("Enable or disable the percent bar")]
public bool EnablePercentBar
{
get => _enablepercentbar;
set
{
_enablepercentbar = value;
Invalidate();
}
}
[Description("Sets the color alpha of the border")]
public byte BorderAlpha
{
get => _borderalpha;
set
{
_borderalpha = value;
_borderpen = new Pen(_borderColor, BorderWidth)
{
Brush = new SolidBrush(Color.FromArgb(_borderalpha, _borderColor))
};
Invalidate();
}
}
[Description("Sets the color of the border")]
public Color BorderColor
{
get => _borderColor;
set
{
_borderColor = value;
_borderpen = new Pen(_borderColor, BorderWidth)
{
Brush = new SolidBrush(Color.FromArgb(_borderalpha, _borderColor))
};
Invalidate();
}
}
[Description("Adjusts the border width")]
public int BorderWidth
{
get => _borderWidth;
set
{
_borderWidth = value;
_borderpen = new Pen(_borderColor, BorderWidth)
{
Brush = new SolidBrush(Color.FromArgb(_borderalpha, _borderColor))
};
Invalidate();
}
}
[Description("Sets the color alpha of the center line.")]
public byte CenterLineAlpha
{
get => _centerlinealpha;
set
{
_centerlinealpha = value;
_centerlinepen = new Pen(_centerlinecolor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_centerlinealpha, _centerlinecolor))
};
Invalidate();
}
}
[Description("Sets the color of the center line")]
public Color CenterLineColor
{
get => _centerlinecolor;
set
{
_centerlinecolor = value;
_centerlinepen = new Pen(_centerlinecolor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_centerlinealpha, _centerlinecolor))
};
Invalidate();
}
}
[Description("Enable or disable the graph auto size.")]
public bool EnableAutoSize
{
get => _enableautosize;
set
{
_enableautosize = value;
_graphmaxValue = !value ? _thisRectangle.Height : 1f;
Invalidate();
}
}
[Description("Enable or disable the border")]
public bool EnableBorder
{
get => _enableBorder;
set
{
_enableBorder = value;
_borderpen = new Pen(_borderColor, BorderWidth)
{
Brush = new SolidBrush(Color.FromArgb(_borderalpha, _borderColor))
};
Invalidate();
}
}
[Description("Enable or disable the graph center line.")]
public bool EnableCenterLine
{
get => _enablecenterline;
set
{
_enablecenterline = value;
Invalidate();
}
}
[Category("Behavior")]
[Description("Enable Edit of the forecolor, default is auto edit")]
public bool EnableForeColorEdit
{
get => _enableForeColorEdit;
set
{
_enableForeColorEdit = value;
Invalidate();
}
}
[Category("Layout")]
[Description("Sets the size reduction in font size i.e. .5 would be 1/2 the font size.")]
public float FontReduction
{
get => _fontReduction;
set
{
_fontReduction = value;
Invalidate();
}
}
[Category("Layout")]
[Description("Specify the maximum value the graph can increased to")]
public float GraphMaximum
{
get => _graphmaxValue;
set
{
_graphmaxValue = value;
Invalidate();
}
}
[Category("Layout")]
[Description("Specifies the minimum value the graph can decreased to")]
public float GraphMinimum
{
get => _graphminValue;
set
{
_graphminValue = value;
Invalidate();
}
}
[Description("Sets the color alpha of the Grid")]
public byte GridAlpha
{
get => _gridalpha;
set
{
_gridalpha = value;
_gridpen = new Pen(_gridColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_gridalpha, _gridColor))
};
Invalidate();
}
}
[Description("Sets the color of the Grid")]
public Color GridColor
{
get => _gridColor;
set
{
_gridColor = value;
_gridpen = new Pen(_gridColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_gridalpha, _gridColor))
};
Invalidate();
}
}
[Description("Enable or disable the graph horizontal grid")]
public bool GridHorzShow
{
get => _gridhorzshow;
set
{
_gridhorzshow = value;
Invalidate();
}
}
[Description("Set the graph horizontal step")]
public int GridHorzStep
{
get => _gridhorzstep;
set
{
_gridhorzstep = value;
Invalidate();
}
}
[Description("Enable or disable the graph vertical grid")]
public bool GridVertShow
{
get => _gridvertshow;
set
{
_gridvertshow = value;
Invalidate();
}
}
[Description("Set the graph vertical step")]
public int GridVertStep
{
get => _gridvertstep;
set
{
_gridvertstep = value;
Invalidate();
}
}
[Description("Gets the maximum percentage step.")]
public float PercentageStep
{
get;
private set;
} = 0.1f;
[Category("Behavior")]
[Description("Gets or Sets Font color for drawing text")]
public Color PercentFontColor
{
get => _percentFontColor;
set
{
_percentFontColor = value;
_percentPen = new Pen(_percentFontColor)
{
Brush = new SolidBrush(Color.FromArgb(byte.MaxValue, _percentFontColor))
};
Invalidate();
}
}
[Description("Gets or Sets the 2D drawing quality.")]
public SmoothingMode Quality
{
get => _quality;
set
{
_quality = value;
Invalidate();
}
}
[Category("Text")]
[Description("Gets or sets the current text value")]
public string TextEx
{
get => _text;
set
{
_text = value;
Invalidate();
}
}
[Category("Behavior")]
[Description("Specify if text is displayed")]
public TextDrawingMode TextMode
{
get => _textDrawingMode;
set
{
_textDrawingMode = value;
Invalidate();
}
}
[Category("Text")]
[Description("Gets or sets the current text value")]
public string[] Title
{
get => _Title;
set
{
_Title = value;
Invalidate();
}
}
[Category("Behavior")]
[Description("Get or InUse the title justification")]
public TitleJustify TitleJustifification
{
get => _titleJustify;
set
{
_titleJustify = value;
Invalidate();
}
}
[Category("Behavior")]
[Description("Specify how to display the title value")]
public TitleDrawingMode TitleMode
{
get => _titleDrawingMode;
set
{
_titleDrawingMode = value;
Invalidate();
}
}
[Description("Get or Set the trend sample window size")]
public int TrendSampleSize
{
get => _trendsamplesize;
set
{
_trendsamplesize = value;
Invalidate();
}
}
[Description("Gets the number of x-axis plotting interpolating points added.")]
public int InterpolationPoints
{
get;
private set;
}
[Description("Get the number of x-axis over plotting occurrences. If any may need to increase percentage step")]
public int XPlottingOverPlots
{
get;
private set;
}
[Description("Gets the number of Errors.")]
public int GeneralErrors
{
get;
private set;
}
[Description("Gets the number of point averaging.")]
public int TotalPointAveraging
{
get;
private set;
}
private void InitializeStartValues()
{
Graph = new graph[Numberofgraphs];
for (var g = 0; g < Numberofgraphs; ++g)
Graph[g] = new graph();
_graphAlpha = new byte[Numberofgraphs];
_graphColor = new Color[Numberofgraphs];
_graphpenwidth = new float[Numberofgraphs];
_graphunderfillAlpha = new byte[Numberofgraphs];
_graphunderfillColor = new Color[Numberofgraphs];
_enableGraph = new bool[Numberofgraphs];
_enableinterpolate = new bool[Numberofgraphs];
_enableunderfill = new bool[Numberofgraphs];
_enabletrend = new bool[Numberofgraphs];
_graphplottype = new PlotTypes[Numberofgraphs];
_pixel = new Bitmap[Numberofgraphs];
_crosssize = new Size[Numberofgraphs];
_cross = new Bitmap[Numberofgraphs];
_enableaveraging = new bool[Numberofgraphs];
_plottingxlinealpha = new byte[Numberofgraphs];
_plottingxlinecolor = new Color[Numberofgraphs];
_plottingxlinewidth = new float[Numberofgraphs];
_plottingylinealpha = new byte[Numberofgraphs];
_plottingylinecolor = new Color[Numberofgraphs];
_plottingylinewidth = new float[Numberofgraphs];
_enablexplottingline = new bool[Numberofgraphs];
_enableyplottingline = new bool[Numberofgraphs];
_yplottinglineavergingsamplesize = new int[Numberofgraphs];
_graphavergingsamplesize = new int[Numberofgraphs];
for (var g = 0; g < Numberofgraphs; ++g)
{
Graph[g].Yplottinglineavergingsamplesize = 15;
_yplottinglineavergingsamplesize[g] = 15;
Graph[g].Graphavergingsamplesize = 30;
_graphavergingsamplesize[g] = 30;
Graph[g].Enablexplottingline = false;
_enablexplottingline[g] = false;
Graph[g].Enableyplottingline = false;
_enableyplottingline[g] = false;
Graph[g].Plottingylinewidth = 1f;
_plottingylinewidth[g] = 1f;
Graph[g].Plottingylinealpha = 127;
_plottingylinealpha[g] = 127;
Graph[g].Plottingylinecolor = Color.DodgerBlue;
_plottingylinecolor[g] = Color.DodgerBlue;
Graph[g].Plottingylinepen = new Pen(Graph[g].Plottingylinecolor, Graph[g].Plottingylinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingylinealpha, Graph[g].Plottingylinecolor))
};
Graph[g].Plottingxlinewidth = 1f;
_plottingxlinewidth[g] = 1f;
Graph[g].Plottingxlinealpha = 127;
_plottingxlinealpha[g] = 127;
Graph[g].Plottingxlinecolor = Color.DodgerBlue;
_plottingxlinecolor[g] = Color.DodgerBlue;
Graph[g].Plottingxlinepen = new Pen(Graph[g].Plottingxlinecolor, Graph[g].Plottingxlinewidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].Plottingxlinealpha, Graph[g].Plottingxlinecolor))
};
Graph[g].Enableaveraging = false;
_enableaveraging[g] = false;
Graph[g].Crosssize = new Size(3, 3);
_crosssize[g] = new Size(3, 3);
Graph[g].Cross = new Bitmap(_crosssize[g].Width, _crosssize[g].Height, PixelFormat.Format32bppArgb);
_cross[g] = new Bitmap(_crosssize[g].Width, _crosssize[g].Height, PixelFormat.Format32bppArgb);
Graph[g].Pixel = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
_pixel[g] = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
Graph[g].Graphplottype = PlotTypes.Line;
_graphplottype[g] = PlotTypes.Line;
Graph[g].Enabletrend = false;
_enabletrend[g] = false;
Graph[g].Enableunderfill = false;
_enableunderfill[g] = false;
Graph[g]._EnableGraph = false;
_enableGraph[g] = false;
Graph[g].Enableinterpolate = true;
_enableinterpolate[g] = true;
Graph[g]._graphAlpha = 127;
_graphAlpha[g] = 127;
Graph[g]._graphColor = Color.Fuchsia;
_graphColor[g] = Color.Fuchsia;
Graph[g].Pixel.SetPixel(0, 0, _graphColor[g]);
_pixel[g].SetPixel(0, 0, _graphColor[g]);
Graph[g].Graphpenwidth = 1f;
_graphpenwidth[g] = 1f;
Graph[g].GraphunderfillAlpha = 127;
_graphunderfillAlpha[g] = 127;
Graph[g].GraphunderfillColor = Color.Red;
_graphunderfillColor[g] = Color.Red;
Graph[g].Graphpen = new Pen(Graph[g]._graphColor, Graph[g].Graphpenwidth)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g]._graphAlpha, Graph[g]._graphColor))
};
Graph[g].FilledPlotPen = new Pen(Graph[g].GraphunderfillColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(Graph[g].GraphunderfillAlpha, Graph[g].GraphunderfillColor))
};
DrawCross(g);
}
for (var i = 0; i < Numberofgraphs; i++)
{
var ba = new BArray<Element>
{
GrowthFactor = 1f,
UseSequentialIndexing = false
};
Values.Add(ba);
}
_gridpen = new Pen(_gridColor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_gridalpha, _gridColor))
};
_borderpen = new Pen(_borderColor, BorderWidth)
{
Brush = new SolidBrush(Color.FromArgb(_borderalpha, _borderColor))
};
_centerlinepen = new Pen(_centerlinecolor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_centerlinealpha, _centerlinecolor))
};
_percentbarpen = new Pen(_percentbarcolor, 1f)
{
Brush = new SolidBrush(Color.FromArgb(_percentbaralpha, _percentbarcolor))
};
_writingFont = Font;
DoubleBuffered = true;
_percentPen = new Pen(_percentFontColor)
{
Brush = new SolidBrush(Color.FromArgb(byte.MaxValue, _percentFontColor))
};
Invalidate();
}
private void DrawCross(int g)
{
var gcbm = Graphics.FromImage(Graph[g].Cross);
gcbm.DrawLine(Graph[g].Graphpen, Graph[g].Crosssize.Width / 2, 0, Graph[g].Crosssize.Width / 2, Graph[g].Crosssize.Height);
gcbm.DrawLine(Graph[g].Graphpen, 0, Graph[g].Crosssize.Height / 2, Graph[g].Crosssize.Width, Graph[g].Crosssize.Height / 2);
var _gcbm = Graphics.FromImage(_cross[g]);
_gcbm.DrawLine(Graph[g].Graphpen, Graph[g].Crosssize.Width / 2, 0, Graph[g].Crosssize.Width / 2, Graph[g].Crosssize.Height);
_gcbm.DrawLine(Graph[g].Graphpen, 0, Graph[g].Crosssize.Height / 2, Graph[g].Crosssize.Width, Graph[g].Crosssize.Height / 2);
}
public void AddArray(float[] nValue, int graphindex)
{
if (nValue.Length > _thisRectangle.Width)
throw new Exception("Error: Array length cannot exceed client width.");
UseFastValues = true;
try
{
for (var v = 0; v < ArraySize; ++v)
{
var nv = nValue[v];
if (_enableautosize)
if (nv > (long) _graphmaxValue)
_graphmaxValue = nv;
}
FastValues[graphindex] = nValue;
Invalidate();
}
catch (Exception ex)
{
GeneralErrors++;
ExceptionLog.ExLog(ex, "ProgressGraph", "AddArray");
}
}
/// <summary>
/// Adds value points to the left side of the graph to the right side.
/// </summary>
/// <param name="Value">The value.</param>
/// <param name="graphindex">The graphindex.</param>
public void AddGraphPoint(long Value, int graphindex)
{
UseFastValues = true;
try
{
var y = Value;
if (_enableautosize)
if (y > (long) _graphmaxValue)
_graphmaxValue = y;
if (y < _graphminValue)
y = (long) _graphminValue;
for (var i = 0; i < ArraySize - 1; i++)
FastValues[graphindex][i] = FastValues[graphindex][i + 1];
FastValues[graphindex][ArraySize - 1] = y;
Slope(graphindex);
Invalidate();
}
catch (Exception ex)
{
GeneralErrors++;
ExceptionLog.ExLog(ex, "ProgressGraph", "AddGraphPoint");
}
}
public void Add(double percent, double ItemsPerSecond, int graphindex)
{
var percentvalue = percent;
try
{
var lta = ItemsPerSecond;
if (Graph[graphindex].Enableyplottingline)
{
_firsttermavg.Add(ItemsPerSecond);
if (_firsttermavg.Count < _yplottinglineavergingsamplesize[graphindex])
lta = _firsttermavg.Where(k => k > 0).Gmean();
else
lta = _firsttermavg.Skip(Math.Max(0, _firsttermavg.Count - _yplottinglineavergingsamplesize[graphindex])).Where(k => k > 0).Gmean();
}
_ycurrent = (float) lta;
_percent = (float) percentvalue;
var element1 = new Element();
if ((int) _xfactor == 0)
{
_xfactor = _thisRectangle.Width / 100f;
_maxxstep = 1f / _xfactor;
PercentageStep = _maxxstep;
}
if (percentvalue + _maxxstep >= 100.0)
_percent = 100f;
var x = (float) Math.Floor(_xfactor * percentvalue);
var sta = ItemsPerSecond;
if (Graph[graphindex].Enableaveraging)
{
_secondtermavg.Add(ItemsPerSecond);
if (_secondtermavg.Count < _graphavergingsamplesize[graphindex])
sta = _secondtermavg.Where(k => k > 0).Gmean();
else
sta = _secondtermavg.Skip(Math.Max(0, _secondtermavg.Count - _graphavergingsamplesize[graphindex])).Where(k => k > 0).Gmean();
}
var y = (float) sta;
if (_enableautosize)
{
var mv = (float) Math.Max(lta, sta);
if ((int) mv > (int) _graphmaxValue)
_graphmaxValue = mv;
}
if (y < _graphminValue)
y = _graphminValue;
element1.X = x;
if (Values[graphindex][(int) x] != null)
{
element1.Ytotal = Values[graphindex][(int) x].Ytotal + y;
element1.N = Values[graphindex][(int) x].N + 1;
TotalPointAveraging++;
}
else
{
element1.Ytotal = y;
element1.N = 1;
}
element1.Y = element1.Ytotal / element1.N;
if ((int) element1.Y == 0)
element1.Y = y;
Values[graphindex][(int) x] = element1;
Interpolate(graphindex);
Slope(graphindex);
Invalidate();
}
catch (Exception ex)
{
GeneralErrors++;
ExceptionLog.ExLog(ex, "ProgressGraph", "AddToChain");
}
}
public void Add(ProcessGraphTimer pgt, int graphindex)
{
var percentvalue = pgt.Percent;
try
{
var lta = pgt.ItemsPerSecond;
if (Graph[graphindex].Enableyplottingline)
{
_firsttermavg.Add(pgt.ItemsPerSecond);
if (_firsttermavg.Count < _yplottinglineavergingsamplesize[graphindex])
lta = _firsttermavg.Where(k => k > 0).Gmean();
else
lta = _firsttermavg.Skip(Math.Max(0, _firsttermavg.Count - _yplottinglineavergingsamplesize[graphindex])).Where(k => k > 0).Gmean();
}
_ycurrent = (float) lta;
_percent = (float) percentvalue;
var element1 = new Element();
if ((int) _xfactor == 0)
{
_xfactor = _thisRectangle.Width / 100f;
_maxxstep = 1f / _xfactor;
PercentageStep = _maxxstep;
}
if (percentvalue + _maxxstep >= 100.0)
_percent = 100f;
var x = (float) Math.Floor(_xfactor * percentvalue);
var sta = pgt.ItemsPerSecond;
if (Graph[graphindex].Enableaveraging)
{
_secondtermavg.Add(pgt.ItemsPerSecond);
if (_secondtermavg.Count < _graphavergingsamplesize[graphindex])
sta = _secondtermavg.Where(k => k > 0).Gmean();
else
sta = _secondtermavg.Skip(Math.Max(0, _secondtermavg.Count - _graphavergingsamplesize[graphindex])).Where(k => k > 0).Gmean();
}
var y = (float) sta;
if (_enableautosize)
{
var mv = (float) Math.Max(lta, sta);
if ((int) mv > (int) _graphmaxValue)
_graphmaxValue = mv;
}
if (y < _graphminValue)
y = _graphminValue;
element1.X = x;
if (Values[graphindex][(int) x] != null)
{
element1.Ytotal = Values[graphindex][(int) x].Ytotal + y;
element1.N = Values[graphindex][(int) x].N + 1;
TotalPointAveraging++;
}
else
{
element1.Ytotal = y;
element1.N = 1;
}
element1.Y = element1.Ytotal / element1.N;
if ((int) element1.Y == 0)
element1.Y = y;
Values[graphindex][(int) x] = element1;
Interpolate(graphindex);
Slope(graphindex);
Invalidate();
}
catch (Exception ex)
{
GeneralErrors++;
ExceptionLog.ExLog(ex, "ProgressGraph", "AddToChain");
}
}
public void Reset()
{
Values.Clear();
for (var i = 0; i < Numberofgraphs; i++)
{
var ba = new BArray<Element>
{
GrowthFactor = 1f,
UseSequentialIndexing = false
};
Values.Add(ba);
}
for (var i = 0; i < Numberofgraphs; ++i)
FastValues.Add(new float[_thisRectangle.Width]);
ValueHold = new float[Numberofgraphs];
_xfactor = 0.0f;
_maxxstep = 0.0f;
InterpolationPoints = 0;
XPlottingOverPlots = 0;
TotalPointAveraging = 0;
PercentageStep = 0.1f;
_firsttermavg.Clear();
_secondtermavg.Clear();
_graphmaxValue = !_enableautosize ? _thisRectangle.Height : 1f;
_ycurrent = 0;
_xcurrent = 0;
UseFastValues = false;
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
try
{
PlotGrid(e.Graphics);
PlotCenterLine(e.Graphics);
PlotPercent(e);
PlotPercentbar(e.Graphics);
PlotText(e);
PlotUnderfill(e.Graphics);
PlotGraph(e.Graphics);
PlotXPlottingLine(e.Graphics);
PlotYPlottingLine(e.Graphics);
PlotBorder(e);
}
catch (Exception ex)
{
GeneralErrors++;
ExceptionLog.ExLog(ex, "ProgressGraph", "OnPaint");
}
}
protected override void OnResize(EventArgs e)
{
FastValues.Clear();
_thisRectangle = Rectangle.Inflate(ClientRectangle, -_borderWidth, -_borderWidth);
for (var i = 0; i < Numberofgraphs; ++i)
FastValues.Add(new float[_thisRectangle.Width]);
Values.Clear();
for (var i = 0; i < Numberofgraphs; i++)
{
var ba = new BArray<Element>
{
GrowthFactor = 1f,
UseSequentialIndexing = false
};
Values.Add(ba);
}
ArraySize = _thisRectangle.Width;
ValueHold = new float[Numberofgraphs];
Reset();
}
private static bool ColorHighOrLow(Color c)
{
return c.R == byte.MaxValue || c.G == byte.MaxValue || c.B == byte.MaxValue || c.R + c.G + c.B > 381;
}
private Element FindNextValidPoint(int gi, int invalidindex)
{
if (Values[gi].IsDirty)
Values[gi].Clean();
for (var i = invalidindex + 1; i < Values[gi].Count; ++i)
if (Values[gi][i] != null)
return Values[gi][i];
var ne = new Element {X = -1};
return ne;
}
private void Interpolate(int gi)
{
if (!Graph[gi].Enableinterpolate)
return;
if (Values[gi].IsDirty)
Values[gi].Clean();
for (var i = 0; i < Values[gi].Count; ++i)
if (Values[gi][i] == null && i != 0)
{
var fvp = FindNextValidPoint(gi, i);
if ((int) fvp.X != -1)
{
var lastvalidy = fvp.Y;
if (i > 1)
lastvalidy = Values[gi][i - 1].Y;
var newy = (fvp.Y + lastvalidy) / 2;
var pe = new Element
{
X = i,
Y = newy
};
InterpolationPoints++;
Values[gi][i] = pe;
}
}
}
private void PlotBorder(PaintEventArgs e)
{
if (!_enableBorder)
return;
e.Graphics.DrawRectangle(_borderpen, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
}
private void PlotCenterLine(Graphics g)
{
if (!_enablecenterline)
return;
g.DrawLine(_centerlinepen, 0, _thisRectangle.Height / 2, _thisRectangle.Width, _thisRectangle.Height / 2);
}
private void PlotPercentbar(Graphics g1)
{
if (!_enablepercentbar)
return;
for (var g = 0; g < Numberofgraphs; ++g)
{
if (Values[g].Count == 0)
continue;
var ptrx = _thisRectangle.Left;
foreach (var Element in Values[g])
if (Element != null)
{
g1.DrawLine(_percentbarpen, ptrx, _thisRectangle.Top, ptrx, _thisRectangle.Height);
ptrx++;
}
}
}
private void PlotGraph(Graphics g1)
{
for (var g = 0; g < Numberofgraphs; ++g)
{
if (!Graph[g]._EnableGraph)
continue;
if (!UseFastValues)
if (Values[g].Count == 0)
continue;
var ScalingVector = _thisRectangle.Height / _graphmaxValue;
if (Graph[g].Graphplottype == PlotTypes.Line)
{
if (!UseFastValues)
{
var sy = Values[g][0] != null ? _thisRectangle.Height - Values[g].First().Y * ScalingVector + _thisRectangle.Top : 1;
var lPoint = new PointF {Y = sy};
var ptrx = _thisRectangle.Left;
if (_direction == direction.RightToLeft)
{
sy = Values[g].Last() != null ? _thisRectangle.Height - Values[g].Last().Y * ScalingVector + _thisRectangle.Top : 1;
lPoint.Y = sy;
lPoint.X = _thisRectangle.Right;
ptrx = _thisRectangle.Right;
}
foreach (var Element in Values[g])
if (Element != null)
{
var ptry = _thisRectangle.Height - Element.Y * ScalingVector + _thisRectangle.Top;
if (_direction == direction.LeftToRight)
{
g1.DrawLine(Graph[g].Graphpen, lPoint.X, lPoint.Y, ptrx + _thisRectangle.Left, ptry);
lPoint.X = ptrx;
lPoint.Y = ptry;
ptrx++;
}
else
{
g1.DrawLine(Graph[g].Graphpen, lPoint.X, lPoint.Y, ptrx, ptry);
lPoint.X = ptrx;
lPoint.Y = ptry;
ptrx--;
if (ptrx < 0)
ptrx = 0;
}
}
}
else
{
var sy = _thisRectangle.Height - FastValues[g].First() * ScalingVector + _thisRectangle.Top;
var lPoint = new PointF {Y = sy, X = 0};
var ptrx = _thisRectangle.Left;
if (_direction == direction.RightToLeft)
{
sy = _thisRectangle.Height - FastValues[g].Last() * ScalingVector + _thisRectangle.Top;
lPoint.Y = sy;
lPoint.X = _thisRectangle.Right;
ptrx = _thisRectangle.Right;
}
for (var e = 1; e < ArraySize; ++e)
{
var y = FastValues[g][e];
if (y <= 0) continue;
var ptry = _thisRectangle.Height - y * ScalingVector + _thisRectangle.Top;
if (_direction == direction.LeftToRight)
{
g1.DrawLine(Graph[g].Graphpen, lPoint.X, lPoint.Y, ptrx + _thisRectangle.Left, ptry);
lPoint.X = ptrx;
lPoint.Y = ptry;
ptrx++;
}
else
{
g1.DrawLine(Graph[g].Graphpen, lPoint.X, lPoint.Y, ptrx, ptry);
lPoint.X = ptrx;
lPoint.Y = ptry;
ptrx--;
if (ptrx < 0)
ptrx = 0;
}
}
}
}
if (Graph[g].Graphplottype == PlotTypes.Pixel)
{
var ptrx = _thisRectangle.Left;
if (_direction == direction.RightToLeft)
ptrx = _thisRectangle.Right;
if (!UseFastValues)
{
foreach (var Element in Values[g])
if (Element != null)
{
var ptry = _thisRectangle.Height - Element.Y * ScalingVector + _thisRectangle.Top;
if (_direction == direction.LeftToRight)
{
g1.DrawImageUnscaled(Graph[g].Pixel, ptrx + _thisRectangle.Left, (int) ptry);
ptrx++;
}
else
{
g1.DrawImageUnscaled(Graph[g].Pixel, ptrx - _thisRectangle.Right, (int) ptry);
ptrx--;
if (ptrx < 0)
ptrx = 0;
}
}
}
else
{
for (var e = 0; e < ArraySize; ++e)
{
var y = FastValues[g][e];
var ptry = _thisRectangle.Height - y * ScalingVector + _thisRectangle.Top;
g1.DrawImageUnscaled(Graph[g].Pixel, ptrx++, (int) ptry);
}
}
}
if (Graph[g].Graphplottype == PlotTypes.Cross)
{
var ptrx = _thisRectangle.Left;
if (_direction == direction.RightToLeft)
ptrx = _thisRectangle.Right;
if (!UseFastValues)
{
foreach (var Element in Values[g])
if (Element != null)
{
var ptry = _thisRectangle.Height - Element.Y * ScalingVector + _thisRectangle.Top;
if (_direction == direction.LeftToRight)
{
g1.DrawImageUnscaled(Graph[g].Cross, ptrx + _thisRectangle.Left, (int) ptry);
ptrx++;
}
else
{
g1.DrawImageUnscaled(Graph[g].Cross, ptrx - _thisRectangle.Right, (int) ptry);
ptrx--;
if (ptrx < 0)
ptrx = 0;
}
}
}
else
{
for (var e = 0; e < ArraySize; ++e)
{
var y = FastValues[g][e];
var ptry = _thisRectangle.Height - y * ScalingVector + _thisRectangle.Top;
g1.DrawImageUnscaled(Graph[g].Cross, ptrx++, (int) ptry);
}
}
}
}
}
private void PlotUnderfill(Graphics g1)
{
for (var g = 0; g < Numberofgraphs; ++g)
{
if (Values[g].Count == 0)
continue;
if (!Graph[g].Enableunderfill)
continue;
var ScalingVector = _thisRectangle.Height / _graphmaxValue;
var ptrx = _thisRectangle.Left;
foreach (var Element in Values[g])
if (Element != null)
{
var ptry = _thisRectangle.Height - Element.Y * ScalingVector + _thisRectangle.Top;
g1.DrawLine(Graph[g].FilledPlotPen, ptrx, _thisRectangle.Bottom, ptrx, (int) ptry);
ptrx++;
}
}
}
private void PlotGrid(Graphics g)
{
if (_gridvertshow)
{
var lim = 0;
while (true)
if (lim < _thisRectangle.Width)
{
g.DrawLine(_gridpen, lim, 0, lim, _thisRectangle.Height);
lim += _gridvertstep;
}
else
{
break;
}
}
if (_gridhorzshow)
{
var lim = _thisRectangle.Height - 1;
while (true)
if (lim > 0)
{
g.DrawLine(_gridpen, 0, lim, _thisRectangle.Width, lim);
lim -= _gridhorzstep;
}
else
{
break;
}
}
}
private void PlotPercent(PaintEventArgs e)
{
if (!_enableForeColorEdit)
_percentFontColor = ColorHighOrLow(ForeColor) ? Color.Black : Color.White;
using (_writingFont = new Font(_writingFont.Name, (float) (_thisRectangle.Height - 4) / 2 * _fontReduction, _writingFont.Style, GraphicsUnit.Point))
{
var WritingPen = new Pen(_percentFontColor) {Brush = new SolidBrush(Color.FromArgb(255, _percentFontColor))};
var st1 = "";
switch (_textDrawingMode)
{
case TextDrawingMode.AsPercentage:
st1 = $"{_percent:0.0}%";
break;
case TextDrawingMode.Standard:
st1 = $"{_text}";
break;
}
e.Graphics.DrawString(st1, _writingFont, WritingPen.Brush, _thisRectangle.Width / 2f - _writingFont.Size * st1.Length / 2f, _thisRectangle.Height / 2f - _writingFont.Height / 2f);
}
}
private void PlotText(PaintEventArgs e)
{
if (!_enableForeColorEdit)
_percentFontColor = ColorHighOrLow(ForeColor) ? Color.Black : Color.White;
if (_textDrawingMode != TextDrawingMode.Standard && _textDrawingMode != TextDrawingMode.AsPercentage)
return;
var stringFormat = new StringFormat
{
Alignment = StringAlignment.Far
};
using (_writingFont = new Font(_writingFont.Name, (float) (_thisRectangle.Height - 4) / 2 * _fontReduction, _writingFont.Style, GraphicsUnit.Point))
{
if (_Title.Length != 0)
if (_titleDrawingMode != TitleDrawingMode.None)
{
var s = e.Graphics.MeasureString("A", _writingFont);
if (_titleDrawingMode == TitleDrawingMode.UpperLeft)
try
{
if (_titleJustify == TitleJustify.Right)
{
var maxw = _Title.Select(T => (int) e.Graphics.MeasureString(T, _writingFont).Width).Concat(new[] {0}).Max();
for (var i = 0; i < _Title.Length; i++)
e.Graphics.DrawString(_Title[i], _writingFont, _percentPen.Brush, maxw, i * (s.Height - 4), stringFormat);
}
if (_titleJustify == TitleJustify.Center)
for (var i = 0; i < _Title.Length; i++)
{
var tw = (int) e.Graphics.MeasureString(_Title[i], _writingFont).Width;
e.Graphics.DrawString(_Title[i], _writingFont, _percentPen.Brush, e.ClipRectangle.Width / 2 + tw / 2, i * (s.Height - 4), stringFormat);
}
if (_titleJustify == TitleJustify.Left)
for (var i = 0; i < _Title.Length; i++)
e.Graphics.DrawString(_Title[i], _writingFont, _percentPen.Brush, 0f, i * (s.Height - 4));
}
catch (Exception ex)
{
ExceptionLog.ExLog(ex, "ProgressGraph", "PlotText");
}
}
}
}
private void PlotXPlottingLine(Graphics g1)
{
for (var g = 0; g < Numberofgraphs; ++g)
{
if (!Graph[g].Enablexplottingline || Values[g].Count == 0)
return;
g1.DrawLine(Graph[g].Plottingxlinepen, Values[g].Last().X, 0.0f, Values[g].Last().X, _thisRectangle.Height);
}
}
private void PlotYPlottingLine(Graphics g1)
{
for (var g = 0; g < Numberofgraphs; ++g)
{
if (!Graph[g].Enableyplottingline || Values[g].Count == 0)
return;
var ScalingVector = _thisRectangle.Height / _graphmaxValue;
var ptry = _thisRectangle.Height - _ycurrent * ScalingVector + _thisRectangle.Top;
g1.DrawLine(Graph[g].Plottingylinepen, 0.0f, ptry, _thisRectangle.Width, ptry);
}
}
private void Slope(int gi)
{
if (!Graph[gi].Enabletrend)
return;
if (Values[gi].Count == 0)
{
Graph[gi].Trend = "∞";
return;
}
Values[gi].Clean();
var SamplesWindow = new BArray<float>
{
GrowthFactor = 1f,
UseSequentialIndexing = false
};
var ptr = 0;
foreach (var Element in Values[gi])
if (Element != null && (uint) (int) Element.Y > 0U)
SamplesWindow[ptr++] = Element.Y;
var TrendArray = SamplesWindow.Skip(Math.Max(0, SamplesWindow.Count() - _trendsamplesize)).Reverse().Where(v => (int) v > 0).ToArray().MAPf().GroupBy(v => v.Key).ToArray();
var rv = "•";
var first = (int) TrendArray.First().Key;
var last = (int) TrendArray.Last().Key;
if (first < last)
rv = "↑";
if (first == last)
rv = "→";
if (first > last)
rv = "↓";
Graph[gi].Trend = rv;
}
public class graph
{
public bool _EnableGraph;
public byte _graphAlpha;
public Color _graphColor;
public Bitmap Cross;
public Size Crosssize;
public bool Enableautoscaling;
public bool Enableaveraging;
public bool Enableinterpolate;
public bool Enabletrend;
public bool Enableunderfill;
public bool Enablexplottingline;
public bool Enableyplottingline;
public Pen FilledPlotPen;
public int Graphavergingsamplesize;
public Pen Graphpen;
public float Graphpenwidth;
public PlotTypes Graphplottype;
public byte GraphunderfillAlpha;
public Color GraphunderfillColor;
public Bitmap Pixel;
public byte Plottingxlinealpha;
public Color Plottingxlinecolor;
public Pen Plottingxlinepen;
public float Plottingxlinewidth;
public byte Plottingylinealpha;
public Color Plottingylinecolor;
public Pen Plottingylinepen;
public float Plottingylinewidth;
public string Trend;
public int Yplottinglineavergingsamplesize;
}
public class Element
{
public int N;
public float X = -1;
public float Y;
public float Ytotal;
}
public class BArray<T> : IEnumerable<T>
{
private bool _setSize;
public T[] _thing;
public float GrowthFactor = 1.5f;
public bool UseSequentialIndexing = true;
public BArray()
{
_thing = new T[0];
_setSize = false;
}
public BArray(int capacity)
{
_thing = new T[capacity];
_setSize = true;
}
public int Count
{
get;
private set;
}
public bool IsDirty => _thing.Length != Count;
public T this[int index]
{
get
{
if (index + 1 > _thing.Length)
EnsureSize(index + 1);
if (IsDirty)
Clean();
return _thing[index];
}
set
{
if (!_setSize)
{
if (!UseSequentialIndexing)
{
EnsureSize(index + 1);
_thing[index] = value;
Count = _thing.Length;
}
else
{
EnsureSize(Count + 1);
_thing[index] = value;
Count++;
}
}
else
{
if (index > Count)
EnsureSize(index + 1);
_thing[index] = value;
Count++;
}
}
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return new Enumerator<T>(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return new Enumerator<T>(this);
}
public void Add(T value)
{
EnsureSize(Count + 1);
_thing[Count] = value;
Count++;
}
public void AddRange(IEnumerable<T> collection)
{
if (collection == null)
throw new Exception("Error: Collection cannot be null.");
var Collection = collection as T[] ?? collection.ToArray();
var count = Collection.Count();
if (count <= 0)
return;
EnsureSize(Count + count);
var tarray = new T[count];
Collection.CopyTo(tarray, 0);
tarray.CopyTo(_thing, Count);
Count += count;
}
public void Clear()
{
_thing = new T[0];
Count = 0;
_setSize = false;
}
public void Clean()
{
if (!IsDirty)
return;
var newtArray = new T[Count];
for (int i = 0, ptr = 0; i < _thing.Length; ++i)
if (_thing[i] != null)
newtArray[ptr++] = _thing[i];
_thing = newtArray;
}
private void EnsureSize(int MinimumSize)
{
if (_thing.Length >= MinimumSize)
return;
var NewLength = (int)(MinimumSize * GrowthFactor);
var newtArray = new T[NewLength];
Array.Copy(_thing, 0, newtArray, 0, _thing.Length);
_thing = newtArray;
Count = _thing.Length;
}
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct Enumerator<T1> : IEnumerator<T1>, IDisposable, IEnumerator
{
private readonly BArray<T1> thing;
private int index;
internal Enumerator(BArray<T1> thing)
{
this.thing = thing;
if (this.thing.IsDirty)
this.thing.Clean();
index = 0;
Current = default;
}
public void Dispose()
{
}
public bool MoveNext()
{
var tthing = thing;
if (index < tthing.Count)
{
Current = tthing._thing[index];
index++;
return true;
}
index = thing.Count + 1;
Current = default;
return false;
}
public T1 Current
{
get;
private set;
}
object IEnumerator.Current => Current;
void IEnumerator.Reset()
{
index = 0;
Current = default;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment