예제 #1
0
        public override bool Paint()
        {
            if (_series.OHLCType == SeriesTypeOHLC.Volume)
            {
                return(false);
            }
            //Find Series
            Series open = _series._chartPanel.GetSeriesOHLCV(_series, SeriesTypeOHLC.Open);

            if (open == null || open.RecordCount == 0 || open.Painted)
            {
                return(false);
            }
            Series high = _series._chartPanel.GetSeriesOHLCV(_series, SeriesTypeOHLC.High);

            if (high == null || high.RecordCount == 0 || high.Painted)
            {
                return(false);
            }
            Series low = _series._chartPanel.GetSeriesOHLCV(_series, SeriesTypeOHLC.Low);

            if (low == null || low.RecordCount == 0 || low.Painted)
            {
                return(false);
            }
            Series close = _series._chartPanel.GetSeriesOHLCV(_series, SeriesTypeOHLC.Close);

            if (close == null || close.RecordCount == 0 || close.Painted)
            {
                return(false);
            }

            _series = close;

            open.Painted = high.Painted = low.Painted = close.Painted = true;

            CalculateCandleSpacing();
            if (ChartX._barSpacing < 0)
            {
                return(false);
            }

            _upColor   = _series._upColor.HasValue ? _series._upColor.Value : ChartX.UpColor;
            _downColor = _series._downColor.HasValue ? _series._downColor.Value : ChartX.DownColor;

            if (_oldOptimizePainting.HasValue && _oldOptimizePainting.Value != ChartX.OptimizePainting)
            {
                if (!ChartX.OptimizePainting)
                {
                    Canvas c = _series._chartPanel._rootCanvas;
                    c.Children.Remove(_pathCandlesDown);
                    c.Children.Remove(_pathCandlesUp);
                    c.Children.Remove(_pathWicksUp);
                    c.Children.Remove(_pathWicksDown);

                    _pathCandlesDown = null;
                    _pathCandlesUp   = null;
                    _pathWicksUp     = null;
                    _pathWicksDown   = null;
                }
                else
                {
                    _candles.RemoveAll();
                }
            }
            _oldOptimizePainting = ChartX.OptimizePainting;

            if (ChartX.OptimizePainting)
            {
                return(PaintOptimized(new[] { open, high, low, close }, _series));
            }

            if (!_subscribedToCustomBrush)
            {
                _subscribedToCustomBrush    = true;
                ChartX.OnCandleCustomBrush += ChartX_OnCandleCustomBrush;
            }


            //bool setBrushes = false;
            if (!_old3DStyle.HasValue || _old3DStyle.Value != ChartX.ThreeDStyle ||
                !_oldUpColor.HasValue || _oldUpColor.Value != _upColor ||
                !_oldDownColor.HasValue || _oldDownColor.Value != _downColor ||
                (ChartX._candleDownOutlineColor.HasValue && ChartX._candleDownOutlineColor.Value != _oldCandleDownOutline) ||
                ChartX._candleUpOutlineColor.HasValue && ChartX._candleUpOutlineColor.Value != _oldCandleUpOutline)
            {
                //setBrushes = true;
                _old3DStyle   = ChartX.ThreeDStyle;
                _oldUpColor   = _upColor;
                _oldDownColor = _downColor;

                _upBrush = !ChartX.ThreeDStyle
                     ? (Brush) new SolidColorBrush(_upColor)
                     : new LinearGradientBrush
                {
                    StartPoint    = new Point(0, 0.5),
                    EndPoint      = new Point(1, 0.5),
                    GradientStops =
                    {
                        new GradientStop
                        {
                            Color  = _upColor,
                            Offset = 0
                        },
                        new GradientStop
                        {
                            Color  = Constants.FadeColor,
                            Offset = 1.25
                        }
                    }
                };
#if WPF
                _upBrush.Freeze();
#endif

                _downBrush = !ChartX.ThreeDStyle
                       ? (Brush) new SolidColorBrush(_downColor)
                       : new LinearGradientBrush
                {
                    StartPoint    = new Point(0, 0.5),
                    EndPoint      = new Point(1, 0.5),
                    GradientStops =
                    {
                        new GradientStop
                        {
                            Color  = _downColor,
                            Offset = 0
                        },
                        new GradientStop
                        {
                            Color  = Constants.FadeColor,
                            Offset = 1.25
                        }
                    }
                };
#if WPF
                _downBrush.Freeze();
#endif

                if (ChartX._candleDownOutlineColor.HasValue)
                {
                    _oldCandleDownOutline   = ChartX._candleDownOutlineColor.Value;
                    _candleDownOutlineBrush = new SolidColorBrush(ChartX._candleDownOutlineColor.Value);
#if WPF
                    _candleDownOutlineBrush.Freeze();
#endif
                }
                if (ChartX._candleUpOutlineColor.HasValue)
                {
                    _oldCandleUpOutline   = ChartX._candleUpOutlineColor.Value;
                    _candleUpOutlineBrush = new SolidColorBrush(ChartX._candleUpOutlineColor.Value);
#if WPF
                    _candleUpOutlineBrush.Freeze();
#endif
                }
            }

            int n;

            _candles.C = _series._chartPanel._rootCanvas;
            _candles.Start();

            for (n = ChartX._startIndex; n < ChartX._endIndex; n++)
            {
                if (!open[n].Value.HasValue || !high[n].Value.HasValue || !low[n].Value.HasValue || !close[n].Value.HasValue)
                {
                    continue;
                }

                Candle candle = _candles.GetPaintObject(_upBrush, _downBrush);
                candle.Init(_series);
                //if (setBrushes)   //because if we have a small number of bars, then enlarge the new brushes won't be propagated to new candles.
                candle.SetBrushes(_upBrush, _downBrush, _candleUpOutlineBrush, _candleDownOutlineBrush);
                candle.SetValues(open[n].Value.Value, high[n].Value.Value, low[n].Value.Value, close[n].Value.Value, ChartX._barSpacing,
                                 _halfwick, n - ChartX._startIndex);
            }
            _candles.Stop();

            _candles.Do(c => c.ZIndex = ZIndexConstants.PriceStyles1);

            return(true);
        }