void DrawHistogramBar(GraphicsWrapper g, ref PointF drawingPoint, Pen pen, Brush fill,
                              int index, int previousItemIndex, float itemWidth, float itemMargin, int unitsUnification, object tag)
        {
            float y = drawingPoint.Y;

            float height = 0;

            if (unitsUnification > 1)
            {
                double heightSum      = 0;
                int    actualSumCount = 0;

                for (int i = previousItemIndex; i <= index; i++)
                {
                    float value = GetDrawingValueAt(i, tag);
                    if (float.IsNaN(value) ||
                        float.IsInfinity(value))
                    {
                        continue;
                    }

                    heightSum += value;
                    actualSumCount++;
                }

                if (actualSumCount == 0)
                {
                    return;
                }

                height = (float)(heightSum / actualSumCount);
            }
            else
            {
                height = GetDrawingValueAt(index, tag);
            }


            if (height < 0)
            {
                y     += height;
                height = -height;
            }

            if (fill != null)
            {
                g.FillRectangle(fill, drawingPoint.X, y, (itemWidth) * unitsUnification, height);
            }
        }
        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);
            }
        }
        /// <summary>
        /// Override this routine, to add the price labels at the space outside of the current drawing pane.
        /// </summary>
        /// <param name="managingPane"></param>
        /// <param name="g"></param>
        public override void DrawInitialActualSpaceOverlays(ChartPane managingPane, GraphicsWrapper g)
        {
            base.DrawInitialActualSpaceOverlays(managingPane, g);

            if (_dataProvider == null || _dataProvider.OperationalState != OperationalStateEnum.Operational)
            {
                return;
            }

            decimal? ask = _dataProvider.Quotes.Ask;
            decimal? bid = _dataProvider.Quotes.Bid;

            if (ask.HasValue == false
                || bid.HasValue == false)
            {
                return;
            }

            // Measure based on a default format of 6 symbols.
            SizeF size = g.MeasureString("00.0000", managingPane.LabelsFont);

            Brush fillBrush = managingPane.LabelsFill;
            if (fillBrush == null)
            {
                fillBrush = managingPane.ActualDrawingSpaceAreaFill;
            }

            if (_showCurrentAskLine)
            {
                PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Ask), true);
                position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight;
                position.Y -= size.Height;

                if (fillBrush != null)
                {
                    g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height));
                }

                if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null)
                {
                    g.DrawString(ask.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position);
                    g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width/* - 2*/, size.Height));
                }

            }

            if (_showCurrentBidLine)
            {
                PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Bid), true);
                position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight;

                if (fillBrush != null)
                {
                    g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height));
                }

                if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null)
                {
                    g.DrawString(bid.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position);
                    g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width/* - 2*/, size.Height));
                }
            }
        }
        /// <summary>
        /// Override this routine, to add the price labels at the space outside of the current drawing pane.
        /// </summary>
        /// <param name="managingPane"></param>
        /// <param name="g"></param>
        public override void DrawInitialActualSpaceOverlays(ChartPane managingPane, GraphicsWrapper g)
        {
            base.DrawInitialActualSpaceOverlays(managingPane, g);

            if (_dataProvider == null || _dataProvider.OperationalState != OperationalStateEnum.Operational)
            {
                return;
            }

            decimal?ask = _dataProvider.Quotes.Ask;
            decimal?bid = _dataProvider.Quotes.Bid;

            if (ask.HasValue == false ||
                bid.HasValue == false)
            {
                return;
            }

            // Measure based on a default format of 6 symbols.
            SizeF size = g.MeasureString("00.0000", managingPane.LabelsFont);

            Brush fillBrush = managingPane.LabelsFill;

            if (fillBrush == null)
            {
                fillBrush = managingPane.ActualDrawingSpaceAreaFill;
            }

            if (_showCurrentAskLine)
            {
                PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Ask), true);
                position.X  = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight;
                position.Y -= size.Height;

                if (fillBrush != null)
                {
                    g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height));
                }

                if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null)
                {
                    g.DrawString(ask.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position);
                    g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width /* - 2*/, size.Height));
                }
            }

            if (_showCurrentBidLine)
            {
                PointF position = managingPane.GraphicsWrapper.DrawingSpaceToActualSpace(new PointF(0, (float)_dataProvider.Quotes.Bid), true);
                position.X = managingPane.Width - managingPane.ActualDrawingSpaceAreaMarginRight;

                if (fillBrush != null)
                {
                    g.FillRectangle(fillBrush, new RectangleF(position.X, position.Y, size.Width, size.Height));
                }

                if (managingPane.LabelsFont != null && managingPane.LabelsFontBrush != null)
                {
                    g.DrawString(bid.Value.ToString(_dataProvider.SessionInfo.ValueFormat), managingPane.LabelsFont, managingPane.LabelsFontBrush, position);
                    g.DrawRectangle(managingPane.ActualDrawingSpaceAreaBorderPen, new RectangleF(position.X, position.Y, size.Width /* - 2*/, size.Height));
                }
            }
        }
        void DrawHistogramBar(GraphicsWrapper g, ref PointF drawingPoint, Pen pen, Brush fill, 
            int index, int previousItemIndex, float itemWidth, float itemMargin, int unitsUnification, object tag)
        {
            float y = drawingPoint.Y;

            float height = 0;
            if (unitsUnification > 1)
            {
                double heightSum = 0;
                int actualSumCount = 0;

                for (int i = previousItemIndex; i <= index; i++)
                {
                    float value = GetDrawingValueAt(i, tag);
                    if (float.IsNaN(value)
                        || float.IsInfinity(value))
                    {
                        continue;
                    }

                    heightSum += value;
                    actualSumCount++;
                }

                if (actualSumCount == 0)
                {
                    return;
                }

                height = (float)(heightSum / actualSumCount);
            }
            else
            {
                height = GetDrawingValueAt(index, tag);
            }

            if (height < 0)
            {
                y += height;
                height = -height;
            }

            if (fill != null)
            {
                g.FillRectangle(fill, drawingPoint.X, y, (itemWidth) * unitsUnification, height);
            }
        }
        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 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);
                }
            }
        }
        protected virtual 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));
            }
        }
        /// <summary>
        /// Enter locked.
        /// </summary>
        void DrawCandleStick(GraphicsWrapper g, ref PointF startingPoint, DataBar barData, float itemWidth, float itemMargin, int itemUnitification)
        {
            if (barData.IsRising)
            {
                if (_risingBarFill != null)
                {
                    g.FillRectangle(_risingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight);
                }

                if (_risingBarPen != null)
                {
                    if (itemWidth > 4)
                    {
                        g.DrawRectangle(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight);
                    }
                    else
                    {
                        g.FillRectangle(Brushes.Green, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight);
                    }

                    // Draw a horizontal line for 0 height bars.
                    if (barData.AbsoluteBodyHeight == 0)
                    {
                        g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close);
                    }

                    // 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 + (float)barData.High),
                        startingPoint.X + itemWidth / 2,
                        (float)(startingPoint.Y + (float)barData.Close));
                }
            }
            else
            {
                if (_fallingBarFill != null)
                {
                    g.FillRectangle(_fallingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.AbsoluteBodyHeight);
                }

                if (_fallingBarPen != null)
                {
                    if (itemWidth >= 4)
                    {// Only if an item is clearly visible, show the border, otherwise, hide to improve. 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.AbsoluteBodyHeight);
                    }

                    // Draw a horizontal line for 0 height bars.
                    if (barData.AbsoluteBodyHeight == 0)
                    {
                        g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close);
                    }

                    // 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 + (float)barData.High),
                        startingPoint.X + itemWidth / 2,
                        (float)(startingPoint.Y + (float)barData.Open));
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Enter locked.
        /// </summary>
        void DrawCandleStick(GraphicsWrapper g, ref PointF startingPoint, DataBar barData, float itemWidth, float itemMargin, int itemUnitification)
        {
            if (barData.IsRising)
            {
                if (_risingBarFill != null)
                {
                    g.FillRectangle(_risingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight);
                }

                if (_risingBarPen != null)
                {
                    if (itemWidth > 4)
                    {
                        g.DrawRectangle(_risingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight);
                    }
                    else
                    {
                        g.FillRectangle(Brushes.Green, startingPoint.X, startingPoint.Y + (float)barData.Open, itemWidth, (float)barData.AbsoluteBodyHeight);
                    }

                    // Draw a horizontal line for 0 height bars.
                    if (barData.AbsoluteBodyHeight == 0)
                    {
                        g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close);
                    }

                    // 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 + (float)barData.High),
                               startingPoint.X + itemWidth / 2,
                               (float)(startingPoint.Y + (float)barData.Close));
                }
            }
            else
            {
                if (_fallingBarFill != null)
                {
                    g.FillRectangle(_fallingBarFill, startingPoint.X, startingPoint.Y + (float)barData.Close, itemWidth, (float)barData.AbsoluteBodyHeight);
                }

                if (_fallingBarPen != null)
                {
                    if (itemWidth >= 4)
                    {// Only if an item is clearly visible, show the border, otherwise, hide to improve. 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.AbsoluteBodyHeight);
                    }

                    // Draw a horizontal line for 0 height bars.
                    if (barData.AbsoluteBodyHeight == 0)
                    {
                        g.DrawLine(_fallingBarPen, startingPoint.X, startingPoint.Y + (float)barData.Close, startingPoint.X + itemWidth, startingPoint.Y + (float)barData.Close);
                    }

                    // 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 + (float)barData.High),
                               startingPoint.X + itemWidth / 2,
                               (float)(startingPoint.Y + (float)barData.Open));
                }
            }
        }