コード例 #1
0
ファイル: VisualElement.cs プロジェクト: Uwy/Live-Charts
        /// <summary>
        /// Adds the or move.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// </exception>
        public void AddOrMove(ChartCore chart)
        {
            if (chart?.AxisX == null || chart?.AxisY == null || UIElement == null)
            {
                return;
            }
            if (UIElement.Parent == null)
            {
                chart.View.AddToDrawMargin(UIElement);
                Canvas.SetZIndex(UIElement, 1000);
            }

            var coordinate = new CorePoint(ChartFunctions.ToDrawMargin(X, AxisOrientation.X, chart, AxisX),
                                           ChartFunctions.ToDrawMargin(Y, AxisOrientation.Y, chart, AxisY));

            var uwpChart = (CartesianChart)chart.View;

            var uw = new CorePoint(
                uwpChart.AxisX[AxisX].Model.EvaluatesUnitWidth
                    ? ChartFunctions.GetUnitWidth(AxisOrientation.X, chart, AxisX) / 2
                    : 0,
                uwpChart.AxisY[AxisY].Model.EvaluatesUnitWidth
                    ? ChartFunctions.GetUnitWidth(AxisOrientation.Y, chart, AxisY) / 2
                    : 0);

            coordinate += uw;

            UIElement.UpdateLayout();

            switch (VerticalAlignment)
            {
            case VerticalAlignment.Top:
                coordinate = new CorePoint(coordinate.X, coordinate.Y - UIElement.ActualHeight);
                break;

            case VerticalAlignment.Center:
                coordinate = new CorePoint(coordinate.X, coordinate.Y - UIElement.ActualHeight / 2);
                break;

            case VerticalAlignment.Bottom:
                coordinate = new CorePoint(coordinate.X, coordinate.Y);
                break;

            case VerticalAlignment.Stretch:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (HorizontalAlignment)
            {
            case HorizontalAlignment.Left:
                coordinate = new CorePoint(coordinate.X - UIElement.ActualWidth, coordinate.Y);
                break;

            case HorizontalAlignment.Center:
                coordinate = new CorePoint(coordinate.X - UIElement.ActualWidth / 2, coordinate.Y);
                break;

            case HorizontalAlignment.Right:
                coordinate = new CorePoint(coordinate.X, coordinate.Y);
                break;

            case HorizontalAlignment.Stretch:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (chart.View.DisableAnimations)
            {
                Canvas.SetLeft(UIElement, coordinate.X);
                Canvas.SetTop(UIElement, coordinate.Y);
            }
            else
            {
                if (double.IsNaN(Canvas.GetLeft(UIElement)))
                {
                    Canvas.SetLeft(UIElement, coordinate.X);
                    Canvas.SetTop(UIElement, coordinate.Y);
                }

                var x = AnimationsHelper.CreateDouble(coordinate.X, uwpChart.AnimationsSpeed, "(Canvas.Left)");
                var y = AnimationsHelper.CreateDouble(coordinate.Y, uwpChart.AnimationsSpeed, "(Canvas.Top)");
                AnimationsHelper.CreateStoryBoardAndBegin(UIElement, x, y);
            }
            _owner = chart;
        }
コード例 #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;

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

            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.CreateCanvasStoryBoardAndBegin(cx, cy, animSpeed);
            }

            var x1Animation = AnimationsHelper.CreateDouble(center, animSpeed, "Line.X1");
            var x2Animation = AnimationsHelper.CreateDouble(center, animSpeed, "Line.X2");

            AnimationsHelper.CreateStoryBoard(HighToLowLine, x1Animation, x2Animation);

            var y1Animation = AnimationsHelper.CreateDouble(High, animSpeed, "Line.Y1");
            var y2Animation = AnimationsHelper.CreateDouble(Low, animSpeed, "Line.Y2");

            AnimationsHelper.CreateStoryBoardAndBegin(HighToLowLine, y1Animation, y2Animation);

            OpenToCloseRectangle.BeginDoubleAnimation("(Canvas.Left)", Left, animSpeed);
            OpenToCloseRectangle.BeginDoubleAnimation("(Canvas.Top)", Math.Min(Open, Close), animSpeed);

            OpenToCloseRectangle.BeginDoubleAnimation("Width", Width, animSpeed);
            OpenToCloseRectangle.BeginDoubleAnimation("Height", Math.Max(Math.Abs(Open - Close), OpenToCloseRectangle.StrokeThickness), animSpeed);
        }