protected void DrawIcon(GraphicsWrapper g, Pen pen, Brush fill, Rectangle rectangle) { if (Visible == false) { return; } if (fill != null) { g.FillRectangle(fill, rectangle); } if (pen != null) { g.DrawRectangle(pen, rectangle); } }
void DrawHistogramBar(GraphicsWrapper g, ref PointF drawingPoint, float[] values, Pen pen, Brush fill, int index, int previousItemIndex, float itemWidth, float itemMargin) { float y = drawingPoint.Y; double heightSum = 0; int actualSumCount = 0; int unificationCount = index - previousItemIndex; for (int i = previousItemIndex; i <= index; i++) { if (float.IsNaN(values[i]) || float.IsInfinity(values[i])) { continue; } heightSum += values[i]; actualSumCount++; } if (actualSumCount == 0) { return; } float height = (float)(heightSum / actualSumCount); if (height < 0) { y += height; height = -height; } if (fill != null) { g.FillRectangle(fill, drawingPoint.X, y, (itemWidth) * unificationCount, height); } if (pen != null) { g.DrawRectangle(pen, drawingPoint.X, y, itemWidth, height); } }
/// <summary> /// Enter locked. /// </summary> void DrawCandleStick(GraphicsWrapper g, ref PointF startingPoint, BarData barData, float itemWidth, float itemMargin, int itemUnitification) { if (barData.BarIsRising || (barData.IsHigherPrev && barData.BarBodyLength == 0)) { if (_risingBarFill != null) { g.FillRectangle(_risingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.BarBodyLength); } if (_risingBarPen != null) { if (itemWidth > 4) { g.DrawRectangle(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.BarBodyLength); // Harry -- Draw a line for open = = close if ((float)barData.BarBodyLength <= 0) { g.DrawLine(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close); } } else { g.FillRectangle(Brushes.Green, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.BarBodyLength); } // Lower shadow g.DrawLine(_risingBarPen, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Low, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Open); // Upper shadow g.DrawLine(_risingBarPen, startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + barData.High), startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + barData.Close)); //Console.WriteLine(" startingPoint.X " + startingPoint.X + " startingPoint.Y " + startingPoint.Y + " (float)barData.Low " + (float)barData.Low + " (float)barData.Close " + (float)barData.Close + " (float)barData.High " + (float)barData.High + " (float)barData.Open " + (float)barData.Open); } } else { if (_fallingBarFill != null) { g.FillRectangle(_fallingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.BarBodyLength); // Harry -- Draw a line for open = = close if ((float)barData.BarBodyLength <= 0) { g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close); } } if (_fallingBarPen != null) { if (itemWidth >= 4) {// Only if an item is clearly visible, show the border, otherwise, hide to improver overal visibility. // Showing this border adds nice detail on close zooming, but not useful otherwise. g.DrawRectangle(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.BarBodyLength); } // Lower shadow g.DrawLine(_fallingBarPen, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Low, startingPoint.X + itemWidth / 2, startingPoint.Y + (float)barData.Close); // Upper shadow g.DrawLine(_fallingBarPen, startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + barData.High), startingPoint.X + itemWidth / 2, (float)(startingPoint.Y + barData.Open)); } } }
void DrawSelection(GraphicsWrapper g) { if (CurrentSelectionRectangle.HasValue == false) { return; } RectangleF selectionRectangle = CurrentSelectionRectangle.Value; if (selectionRectangle.Width > 0 && selectionRectangle.Height > 0 && _lastDrawingSpaceMouseRightButtonPosition.HasValue && _currentDrawingSpaceMousePosition.HasValue) { if (_selectionPen != null) { g.DrawRectangle(_selectionPen, selectionRectangle.X, selectionRectangle.Y, selectionRectangle.Width, selectionRectangle.Height); } if (_selectionFill != null) { g.FillRectangle(_selectionFill, selectionRectangle); } } }
void DrawGraphicSeriesLabels(GraphicsWrapper g, int initialMarginLeft) { _currentLabelsRectangles = new Rectangle[_series.Count]; for (int i = 0; i < _series.Count; i++) { if (i == 0) { _currentLabelsRectangles[0].X = initialMarginLeft; } else { _currentLabelsRectangles[i].X = _currentLabelsRectangles[i - 1].Right + (int)_labelsMargin; } _currentLabelsRectangles[i].Y = (int)_labelsTopMargin; SizeF seriesSize = g.MeasureString(_series[i].Name, _labelsFont); _currentLabelsRectangles[i].Size = new Size((int)seriesSize.Width, (int)seriesSize.Height); int iconWidth = 18; // Add space for series icon _currentLabelsRectangles[i].Width += iconWidth; if (_labelsFill != null) { g.FillRectangle(_labelsFill, _currentLabelsRectangles[i]); } if (_labelsFont != null) { g.DrawString(_series[i].Name, _labelsFont, _labelsFontBrush, _currentLabelsRectangles[i].X + iconWidth, _currentLabelsRectangles[i].Y); } _series[i].DrawSeriesIcon(g, new Rectangle(_currentLabelsRectangles[i].X + 2, _currentLabelsRectangles[i].Y + 2, 14, _currentLabelsRectangles[i].Height - 4)); } }