public void PaintLevels(Graphics canvas, Rectangle rectPaint) { if (this.CollectionLevels.IsNull()) { return; } this.CountLevels = this.CollectionLevels.Count(); if (this.CountLevels == 0) { return; } if (this.CountLevels < MinCountLevels) { this.CountLevels = MinCountLevels; } int index = 1; foreach (var valLevel in this.CollectionLevels) { //***************************** this.PaintOneLevel(canvas, rectPaint, valLevel.Volume, index); index++; } GraphicShape.PaintLine(canvas, new Point(rectPaint.X, rectPaint.Y), new Point(rectPaint.X + rectPaint.Width, rectPaint.Y), Color.Black); PanelValues.CurrentValue = this.CollectionLevels.ElementAt(0).Volume; PanelValues.RectPaint = rectPaint; PanelValues.ColorLines = Color.DarkGray; PanelValues.minStepPrice = this.MinStepPrice; PanelValues.PaintPrices(canvas, this.Max, this.Min); PanelValues.PaintCurrentValue(canvas, this.Max, this.Min); }
private void PaintOneLevel(Graphics canvas, Rectangle rectPaint, MarketObject.Chart Value, decimal MaxPrice, decimal MinPrice) { int y = GraphicShape.GetCoordinate(rectPaint.Height, MaxPrice, MinPrice, Value.Price); int x1 = rectPaint.X + GraphicShape.GetCoordinate(rectPaint.Width, this.Max, this.Min, Value.Volume > 0 ? 0 : Value.Volume); int x2 = rectPaint.X + GraphicShape.GetCoordinate(rectPaint.Width, this.Max, this.Min, Value.Volume < 0 ? 0 : Value.Volume); GraphicShape.PaintLine(canvas, new Point(x1, y), new Point(x2, y), Value.Volume < 0 ? Color.Red : Color.Green, 2); }
public void PaintOrders(Graphics canvas, Rectangle rectPaint, decimal MaxPrice, decimal MinPrice, decimal minStepPrice) { int count = this.CollectionOrders.Count(); if (count == 0) { return; } foreach (var ord in this.CollectionOrders) { var vol = ord.Volume < 0 ? ord.Volume * -1 : ord.Volume; GraphicShape.PaintHLine(canvas, rectPaint, ord.Price, ord.Price + "(" + vol + ")", MaxPrice, MinPrice, ord.Volume > 0 ? Color.DarkGreen : Color.DarkRed, "left"); } }
private void PaintOneLevel(Graphics canvas, Rectangle rectPaint, decimal Value, int index) { rectPaint = RectanglePaint.DeleteRight(rectPaint, new Rectangle(0, 0, this.PanelValues.WidthBorder, 0)); int Y1 = GraphicShape.GetCoordinate(rectPaint.Height, this.Max, this.Min, Value > 0 ? Value : 0); int Y2 = GraphicShape.GetCoordinate(rectPaint.Height, this.Max, this.Min, Value < 0 ? Value : 0); int bodyX = (int)(rectPaint.Width - this.WidthOneLevel * index); int bodyY = rectPaint.Y + Y1; int bodyWidth = this.WidthOneLevel - 2; //-2 чтобы свечки не слипались int bodyHeight = Y2 - Y1; //bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; GraphicShape.PaintRectangle(canvas, bodyX, bodyY, bodyWidth, bodyHeight, Color.Black, Value < 0 ? Color.Red : Color.Green); }
/// <summary> /// Рисует вертикальнцю линию с надписью /// </summary> /// <param name="g"></param> /// <param name="rectPaint"></param> /// <param name="ValText"></param> /// <param name="pStart"></param> /// <param name="pEnd"></param> /// <param name="color"></param> /// <param name="WidthLine"></param> /// <param name="TextVAlign"></param> public static void PaintVLine(Graphics g, Rectangle rectPaint, string ValText, Point pStart, Point pEnd, Color color, int WidthLine = 1, string TextVAlign = "bottom") { int WidthText = Convert.ToInt32(ValText.Length * 6.5); int HeightText = 12; pEnd.Y -= HeightText; //ВЫравнивание лейбла switch (TextVAlign) { case "bottom": int fontSize = 8; g.DrawString(ValText, new Font(new FontFamily("Helvetica"), fontSize, FontStyle.Regular, GraphicsUnit.Point), new SolidBrush(color), pEnd.X - WidthText / 2, pEnd.Y); break; } GraphicShape.PaintLine(g, pStart, pEnd, color, WidthLine); }
/// <summary>Отрисовка перекрестья</summary> /// <param name="coord"></param> void PaintCrossLines(Point coord, Candles.DataCandle candle) { if (candle.IsNull()) { return; } string d = candle.Candle.Time.Day.ToString(); string m = candle.Candle.Time.Month.ToString(); string y = candle.Candle.Time.Year.ToString(); string min = candle.Candle.Time.Minute.ToString(); string hour = candle.Candle.Time.Hour.ToString(); string time = (d.Length < 2 ? '0' + d : d) + "." + (m.Length < 2 ? '0' + m : m) + "." + y + " " + (hour.Length < 2 ? '0' + hour : hour) + ":" + (min.Length < 2 ? '0' + min : min) + " (" + candle.Description + ")"; //GraphicShape.PaintLine(this.Canvas, new Point(coord.X, 0), new Point(coord.X, 1000), Color.Black); decimal priceY = GraphicShape.GetValueFromCoordinate(this.RectAllTop.Height, this.MaxPrice, this.MinPrice, coord.Y, this.PanelPrices.CountFloat); GraphicShape.PaintVLine(this.Canvas, this.RectAllTop, time, new Point(coord.X, 0), new Point(coord.X, this.RectAllTop.Height), Color.Black); GraphicShape.PaintHLine(this.Canvas, this.RectAllTop, priceY, this.MaxPrice, this.MinPrice, Color.Black); }
public static void PaintHLine(Graphics g, Rectangle rectPaint, decimal valPrice, string Text, decimal maxPrice, decimal minPrice, Color color, string TextHAlign = "right") { int Y = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, valPrice); //Если выходит за пределы, удаляем if (Y < 0 || Y > rectPaint.Y + rectPaint.Height) { return; } string ValText = Text; int WidthText = ValText.Length * 7; int fontSize = 8; Point pLine1 = new Point(rectPaint.X, rectPaint.Y + Y); Point pLine2 = new Point(rectPaint.X + rectPaint.Width - WidthText - 2, rectPaint.Y + Y); //ВЫравнивание лейбла switch (TextHAlign) { case "left": g.DrawString(ValText, new Font(new FontFamily("Helvetica"), fontSize, FontStyle.Regular, GraphicsUnit.Point), new SolidBrush(color), rectPaint.X, rectPaint.Y + Y - (fontSize)); pLine1 = new Point(rectPaint.X + WidthText, rectPaint.Y + Y); pLine2 = new Point(rectPaint.X + rectPaint.Width, rectPaint.Y + Y); break; case "center": //Canvas.SetLeft(this.TextLabel, PaintPanel.X + (PaintPanel.Width / 2 - this.TextLabel.ActualWidth)); break; default: // Canvas.SetLeft(this.TextLabel, PaintPanel.X + PaintPanel.Width - this.TextLabel.ActualWidth - this.MarginRight); g.DrawString(ValText, new Font(new FontFamily("Helvetica"), fontSize, FontStyle.Regular, GraphicsUnit.Point), new SolidBrush(color), rectPaint.X + rectPaint.Width - WidthText, rectPaint.Y + Y - (fontSize)); break; } GraphicShape.PaintLine(g, pLine1, pLine2, color); }
/// <summary> Рисует объемы по активной свечке </summary> private void PaintHorVolByCandle(Graphics canvas, Candles.DataCandle activeCandle, Point crossLines) { if (activeCandle.Candle.HorVolumes.HVolCollection.Count == 0) { return; } Rectangle rectPaint = new Rectangle(); rectPaint.X = activeCandle.TailCoord.High.X + 1; rectPaint.Width = 30 * 2; rectPaint.Y = activeCandle.TailCoord.High.Y; rectPaint.Height = activeCandle.TailCoord.Low.Y - rectPaint.Y; long MaxVol = activeCandle.Candle.HorVolumes.HVolCollection.CollectionArray.Max(e => e.VolBuy + e.VolSell); long MinVol = 0; SolidBrush solidBrush = new SolidBrush(Color.LightGray); canvas.FillRectangle(solidBrush, rectPaint); activeCandle.Candle.HorVolumes.HVolCollection.CollectionArray.ForEach <MarketObject.ChartVol>((hv) => { int y = GraphicShape.GetCoordinate(this.RectAllTop.Height, this.MaxPrice, this.MinPrice, hv.Price); int x2 = (int)GraphicShape.GetCoordinate(rectPaint.Width, MaxVol, MinVol, hv.VolBuy + hv.VolSell); var p1 = new Point(rectPaint.X, y); var p2 = new Point(rectPaint.X + rectPaint.Width - x2, y); if (hv.VolBuy + hv.VolSell == MaxVol) { GraphicShape.PaintText(canvas, MaxVol.ToString(), activeCandle.TailCoord.High.X, activeCandle.TailCoord.High.Y - 11, Color.Blue); } if (crossLines.Y + 5 > y && crossLines.Y - 5 < y) { decimal priceY = GraphicShape.GetValueFromCoordinate(this.RectAllTop.Height, this.MaxPrice, this.MinPrice, crossLines.Y, this.PanelPrices.CountFloat); if (hv.Price == priceY) { activeCandle.Description = (hv.VolBuy + hv.VolSell).ToString(); } } GraphicShape.PaintLine(canvas, p1, p2, Color.Blue, 2); }); }
/// <summary> Инициализируем внутренние события </summary> private void InitEvents() { //Перед отриосвкой свечей PanelCandels.OnBeforePaintCandle += (emptyCandle) => { this.ActiveCandle = null; }; //Отрисовка одной свечи PanelCandels.OnPaintCandle += (candle) => { if (candle.Body.X <= this.CrossLine.X && candle.Body.X + candle.Body.Width >= this.CrossLine.X) { this.ActiveCandle = candle; } if (candle.Index == this.CountCandleShowHVol) { Point p1 = new Point() { X = candle.Body.X, Y = candle.PaintRect.Y }; Point p2 = new Point() { X = candle.Body.X, Y = candle.PaintRect.Y + candle.PaintRect.Height }; GraphicShape.PaintVLine(this.Canvas, candle.PaintRect, candle.Index.ToString(), p1, p2, Color.Blue, 2); } }; //Отрисовка свечей завершена PanelCandels.OnPaintedCandles += () => { if (!this.ActiveCandle.IsNull()) { this.PaintHorVolByCandle(this.Canvas, ActiveCandle, this.CrossLine); this.PanelCandels.MoveVerticalActiveCandle(this.ActiveCandle); } this.PaintCrossLines(this.CrossLine, ActiveCandle); }; }
public void PaintLevels(Graphics canvas, Rectangle rectPaint, decimal MaxPrice, decimal MinPrice) { if (this.CollectionLevels == null) { return; } this.CountLevels = this.CollectionLevels.Count(); if (this.CountLevels == 0) { return; } foreach (var valLevel in this.CollectionLevels) { //***************************** this.PaintOneLevel(canvas, rectPaint, valLevel, MaxPrice, MinPrice); } GraphicShape.PaintLine(canvas, new Point(rectPaint.X, rectPaint.Y), new Point(rectPaint.X, rectPaint.Y + rectPaint.Height), Color.Black); GraphicShape.PaintText(canvas, "min:" + this.Min.ToString(), rectPaint.X, rectPaint.Y + rectPaint.Height - 12, Color.Black); GraphicShape.PaintText(canvas, "max:" + this.Max.ToString(), rectPaint.X, rectPaint.Y + 1, Color.Black); }
/// <summary> Рисует одну свечку </summary> /// <param name="canvas"></param> /// <param name="rectPaint"></param> /// <param name="candleData"></param> /// <param name="index"></param> /// <param name="maxPrice"></param> /// <param name="minPrice"></param> private void PaintOneCandle(Graphics canvas, Rectangle rectPaint, CandleLib.CandleData candleData, int index, decimal maxPrice, decimal minPrice) { int tailY1 = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.High); int tailY2 = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.Low); int tailX1 = (int)((rectPaint.Width - this.WidthOneCandle * index) + this.WidthOneCandle / 2); int bodyX = (int)(rectPaint.Width - this.WidthOneCandle * index); int bodyY = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.Open > candleData.Close ? candleData.Open : candleData.Close); int bodyWidth = this.WidthOneCandle - MarginCandle; //- чтобы свечки не слипались int bodyHeight = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.Open < candleData.Close ? candleData.Open : candleData.Close); bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; GraphicShape.PaintLine(canvas, new Point(tailX1, tailY1), new Point(tailX1, tailY2), Color.Black, 2); GraphicShape.PaintRectangle(canvas, bodyX, bodyY, bodyWidth, bodyHeight, Color.Black, candleData.Open > candleData.Close ? Color.LightCoral : Color.LightGreen); if (OnPaintCandle != null) { OnPaintCandle(new DataCandle() { PaintRect = rectPaint, Candle = candleData, TailCoord = new TailCoord() { High = new Point(tailX1, tailY1), Low = new Point(tailX1, tailY2) }, Body = new Rectangle() { X = bodyX, Y = bodyY, Width = bodyWidth, Height = bodyHeight }, Index = index }); } }