Ejemplo n.º 1
0
        public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
        {
            var center = Left + Width / 2;

            if (IsNew)
            {
                HighToLowLine.X1 = center;
                HighToLowLine.X2 = center;
                HighToLowLine.Y1 = StartReference;
                HighToLowLine.Y2 = StartReference;

                Canvas.SetTop(OpenToCloseRectangle, (Open + Close) / 2);
                Canvas.SetLeft(OpenToCloseRectangle, Left);

                OpenToCloseRectangle.Width  = Width;
                OpenToCloseRectangle.Height = 0;
            }

            if (DataLabel != null && double.IsNaN(Canvas.GetLeft(DataLabel)))
            {
                Canvas.SetTop(DataLabel, current.ChartLocation.Y);
                Canvas.SetLeft(DataLabel, current.ChartLocation.X);
            }

            if (HoverShape != null)
            {
                var h = Math.Abs(High - Low);
                HoverShape.Width  = Width;
                HoverShape.Height = h > 10 ? h : 10;
                Canvas.SetLeft(HoverShape, Left);
                Canvas.SetTop(HoverShape, High);
            }


            var candleSeries = (CandleSeries)current.SeriesView;

            if (candleSeries.ColoringRules == null)
            {
                if (current.Open <= current.Close)
                {
                    HighToLowLine.Stroke        = candleSeries.IncreaseBrush;
                    OpenToCloseRectangle.Fill   = candleSeries.IncreaseBrush;
                    OpenToCloseRectangle.Stroke = candleSeries.IncreaseBrush;
                }
                else
                {
                    HighToLowLine.Stroke        = candleSeries.DecreaseBrush;
                    OpenToCloseRectangle.Fill   = candleSeries.DecreaseBrush;
                    OpenToCloseRectangle.Stroke = candleSeries.DecreaseBrush;
                }
            }
            else
            {
                foreach (var rule in candleSeries.ColoringRules)
                {
                    if (!rule.Condition(current, previousDrawn))
                    {
                        continue;
                    }

                    HighToLowLine.Stroke        = rule.Stroke;
                    OpenToCloseRectangle.Fill   = rule.Fill;
                    OpenToCloseRectangle.Stroke = rule.Stroke;

                    break;
                }
            }


            if (chart.View.DisableAnimations)
            {
                HighToLowLine.Y1 = High;
                HighToLowLine.Y2 = Low;
                HighToLowLine.X1 = center;
                HighToLowLine.X2 = center;

                OpenToCloseRectangle.Width  = Width;
                OpenToCloseRectangle.Height = Math.Abs(Open - Close);

                Canvas.SetTop(OpenToCloseRectangle, Math.Min(Open, Close));
                Canvas.SetLeft(OpenToCloseRectangle, Left);

                if (DataLabel != null)
                {
                    DataLabel.UpdateLayout();

                    var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualHeight * .5, chart);
                    var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualWidth * .5, chart);

                    Canvas.SetTop(DataLabel, cy);
                    Canvas.SetLeft(DataLabel, cx);
                }

                return;
            }


            var animSpeed = chart.View.AnimationsSpeed;

            if (DataLabel != null)
            {
                DataLabel.UpdateLayout();

                var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
                var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);

                DataLabel.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(cx, animSpeed));
                DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(cy, animSpeed));
            }

            HighToLowLine.BeginAnimation(Line.X1Property, new DoubleAnimation(center, animSpeed));
            HighToLowLine.BeginAnimation(Line.X2Property, new DoubleAnimation(center, animSpeed));
            HighToLowLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(High, animSpeed));
            HighToLowLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Low, animSpeed));

            OpenToCloseRectangle.BeginAnimation(Canvas.LeftProperty,
                                                new DoubleAnimation(Left, animSpeed));
            OpenToCloseRectangle.BeginAnimation(Canvas.TopProperty,
                                                new DoubleAnimation(Math.Min(Open, Close), animSpeed));

            OpenToCloseRectangle.BeginAnimation(FrameworkElement.WidthProperty,
                                                new DoubleAnimation(Width, animSpeed));
            OpenToCloseRectangle.BeginAnimation(FrameworkElement.HeightProperty,
                                                new DoubleAnimation(Math.Max(Math.Abs(Open - Close), OpenToCloseRectangle.StrokeThickness), animSpeed));
        }
Ejemplo n.º 2
0
        public override void DrawOrMove(ChartPoint previousDrawn, ChartPoint current, int index, ChartCore chart)
        {
            var center = Left + Width / 2;

            if (IsNew)
            {
                HighToLowLine.X1 = center;
                HighToLowLine.X2 = center;
                HighToLowLine.Y1 = StartReference;
                HighToLowLine.Y2 = StartReference;

                OpenLine.X1 = Left;
                OpenLine.X2 = center;
                OpenLine.Y1 = StartReference;
                OpenLine.Y2 = StartReference;

                CloseLine.X1 = center;
                CloseLine.X2 = Left + Width;
                CloseLine.Y1 = StartReference;
                CloseLine.Y2 = StartReference;

                if (DataLabel != null)
                {
                    Canvas.SetTop(DataLabel, current.ChartLocation.Y);
                    Canvas.SetLeft(DataLabel, current.ChartLocation.X);
                }
            }

            if (HoverShape != null)
            {
                var h = Math.Abs(High - Low);
                HoverShape.Width  = Width;
                HoverShape.Height = h > 10 ? h : 10;
                Canvas.SetLeft(HoverShape, Left);
                Canvas.SetTop(HoverShape, High);
            }

            if (chart.View.DisableAnimations)
            {
                HighToLowLine.Y1 = High;
                HighToLowLine.Y2 = Low;

                OpenLine.Y1 = Open;
                OpenLine.Y2 = Open;

                CloseLine.Y1 = Close;
                CloseLine.Y2 = Close;

                if (DataLabel != null)
                {
                    DataLabel.UpdateLayout();

                    var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualHeight * .5, chart);
                    var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualWidth * .5, chart);

                    Canvas.SetTop(DataLabel, cy);
                    Canvas.SetLeft(DataLabel, cx);
                }

                return;
            }

            var animSpeed = chart.View.AnimationsSpeed;

            if (DataLabel != null)
            {
                DataLabel.UpdateLayout();

                var cx = CorrectXLabel(current.ChartLocation.X - DataLabel.ActualWidth * .5, chart);
                var cy = CorrectYLabel(current.ChartLocation.Y - DataLabel.ActualHeight * .5, chart);

                DataLabel.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation(cx, animSpeed));
                DataLabel.BeginAnimation(Canvas.TopProperty, new DoubleAnimation(cy, animSpeed));
            }

            HighToLowLine.BeginAnimation(Line.X1Property, new DoubleAnimation(center, animSpeed));
            HighToLowLine.BeginAnimation(Line.X2Property, new DoubleAnimation(center, animSpeed));
            OpenLine.BeginAnimation(Line.X1Property, new DoubleAnimation(Left, animSpeed));
            OpenLine.BeginAnimation(Line.X2Property, new DoubleAnimation(center, animSpeed));
            CloseLine.BeginAnimation(Line.X1Property, new DoubleAnimation(center, animSpeed));
            CloseLine.BeginAnimation(Line.X2Property, new DoubleAnimation(Left + Width, animSpeed));

            HighToLowLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(High, animSpeed));
            HighToLowLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Low, animSpeed));
            OpenLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(Open, animSpeed));
            OpenLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Open, animSpeed));
            CloseLine.BeginAnimation(Line.Y1Property, new DoubleAnimation(Close, animSpeed));
            CloseLine.BeginAnimation(Line.Y2Property, new DoubleAnimation(Close, animSpeed));
        }