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); }
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); }
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> /// <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 }); } }