Beispiel #1
0
        /// <summary>
        /// Return IChartTranform value based upon the given size
        /// </summary>
        /// <param name="size"></param>
        /// <param name="create"></param>
        /// <returns></returns>
        protected internal override IChartTransformer CreateTransformer(Size size, bool create)
        {
            if (create || ChartTransformer == null)
            {
                ChartTransformer = ChartTransform.CreatePolar(new Rect(new Point(), size), this);
            }

            return(ChartTransformer);
        }
Beispiel #2
0
        /// <summary>
        /// Return IChartTransformer value from the given size
        /// </summary>
        /// <param name="size"></param>
        /// <param name="create"></param>
        /// <returns></returns>
        protected internal override IChartTransformer CreateTransformer(Size size, bool create)
        {
            if (create || ChartTransformer == null)
            {
                ChartTransformer = ChartTransform.CreateSimple(size);
            }

            return(ChartTransformer);
        }
Beispiel #3
0
        /// <summary>
        /// Renders the labels.
        /// </summary>
        private void RenderLabels()
        {
            double aroundRadius = this.Radius + Math.Max(Axis.TickLineSize, 0);

            int pos = 0;


            foreach (ChartAxisLabel label in Axis.VisibleLabels)
            {
                double coef = this.Axis.ValueToPolarCoefficient(label.Position);

                FrameworkElement element = (FrameworkElement)contentControlRecycler[pos];

                Point vector       = ChartTransform.ValueToVector(this.Axis, label.Position);
                Point connectPoint = new Point(this.Center.X + aroundRadius * vector.X,
                                               this.Center.Y + aroundRadius * vector.Y);

                var labelwidth = ((element as UIElement).DesiredSize.Width) / 2;

                if (coef == 0.25d)
                {
                    connectPoint.X -= element.DesiredSize.Width;
                    connectPoint.Y -= element.DesiredSize.Height / 2;
                }
                else if (coef == 0.5d)
                {
                    connectPoint.X -= element.DesiredSize.Width / 2;
                }
                else if (coef == 0.75d)
                {
                    connectPoint.Y -= element.DesiredSize.Height / 2;
                }
                else if (coef == 1d || coef == 0d)
                {
                    connectPoint.X -= element.DesiredSize.Width / 2;
                    connectPoint.Y -= element.DesiredSize.Height;
                }
                else if (0 < coef && coef < 0.25d)
                {
                    connectPoint.X -= element.DesiredSize.Width;
                    connectPoint.Y -= element.DesiredSize.Height;
                }
                else if (0.25d < coef && coef < 0.5d)
                {
                    connectPoint.X -= element.DesiredSize.Width;
                }
                else if (0.75d < coef && coef < 1d)
                {
                    connectPoint.Y -= element.DesiredSize.Height;
                }

                // element.Arrange(new Rect(connectPoint, element.DesiredSize));
                Canvas.SetLeft(element, connectPoint.X);
                Canvas.SetTop(element, connectPoint.Y);
                pos++;
            }
        }
Beispiel #4
0
            /// <summary>
            /// Transforms chart cordinates to real coordinates.
            /// </summary>
            /// <param name="x">The x value.</param>
            /// <param name="y">The y value.</param>
            /// <returns>The visible point</returns>
            public Point TransformToVisible(double x, double y)
            {
                x = x = x_IsLogarithmic && x > 0 ? Math.Log(x, xlogarithmicBase) : x;
                y = y_IsLogarithmic && y > 0 ? Math.Log(y, ylogarithmicBase) : y;

                double radius = m_radius * m_yAxis.ValueToCoefficient(y);
                Point  point  = ChartTransform.ValueToVector(m_xAxis, x);

                return(new Point(m_center.X + radius * point.X, m_center.Y + radius * point.Y));
            }
Beispiel #5
0
        /// <summary>
        /// Renders the tick lines.
        /// </summary>
        private void RenderTicks()
        {
            Point  center = this.Center;
            double radius = this.Radius;
            int    pos    = 0;

            foreach (ChartAxisLabel label in Axis.VisibleLabels)
            {
                Point vector       = ChartTransform.ValueToVector(this.Axis, label.Position);
                Line  line         = lineRecycler[pos];
                Point connectPoint = new Point(center.X + radius * vector.X, center.Y + radius * vector.Y);
                line.X1 = connectPoint.X;
                line.Y1 = connectPoint.Y;
                line.X2 = connectPoint.X + Axis.TickLineSize * vector.X;
                line.Y2 = connectPoint.Y + Axis.TickLineSize * vector.Y;
                pos++;
            }
        }
        internal override int GetDataPointIndex(Point point)
        {
            Canvas canvas = Area.GetAdorningCanvas();
            double left   = Area.ActualWidth - canvas.ActualWidth;
            double top    = Area.ActualHeight - canvas.ActualHeight;

            point.X = point.X - left - Area.SeriesClipRect.Left + Area.Margin.Left;
            point.Y = point.Y - top - Area.SeriesClipRect.Top + Area.Margin.Top;
            double xVal   = 0;
            double xStart = ActualXAxis.VisibleRange.Start;
            double xEnd   = ActualXAxis.VisibleRange.End;
            int    index  = -1;
            double center = 0.5 * Math.Min(this.Area.SeriesClipRect.Width, this.Area.SeriesClipRect.Height);
            double radian = ChartTransform.PointToPolarRadian(point, center);
            double coeff  = ChartTransform.RadianToPolarCoefficient(radian);

            xVal = Math.Round(this.Area.InternalPrimaryAxis.PolarCoefficientToValue(coeff));
            if (xVal <= xEnd && xVal >= xStart)
            {
                index = this.GetXValues().IndexOf((int)xVal);
            }
            return(index);
        }
        internal override void UpdateTooltip(object originalSource)
        {
            if (ShowTooltip)
            {
                var shape = (originalSource as Shape);
                if (shape == null || (shape != null && shape.Tag == null))
                {
                    return;
                }
                SetTooltipDuration();
                var canvas = this.Area.GetAdorningCanvas();

                double xVal   = 0;
                object data   = null;
                double xStart = ActualXAxis.VisibleRange.Start;
                double xEnd   = ActualXAxis.VisibleRange.End;
                int    index  = 0;

                if (this.Area.SeriesClipRect.Contains(mousePos))
                {
                    var point = new Point(
                        mousePos.X - this.Area.SeriesClipRect.Left,
                        mousePos.Y - this.Area.SeriesClipRect.Top);
                    double center = 0.5 * Math.Min(this.Area.SeriesClipRect.Width, this.Area.SeriesClipRect.Height);
                    double radian = ChartTransform.PointToPolarRadian(point, center);
                    double coeff  = ChartTransform.RadianToPolarCoefficient(radian);
                    xVal = Math.Round(this.Area.InternalPrimaryAxis.PolarCoefficientToValue(coeff));
                    if (xVal <= xEnd && xVal >= xStart)
                    {
                        index = this.GetXValues().IndexOf((int)xVal);
                    }
                    data = this.ActualData[index];
                }

                var chartTooltip = this.Area.Tooltip as ChartTooltip;
                if (this.DrawType == ChartSeriesDrawType.Area)
                {
                    var areaSegment = shape.Tag as AreaSegment;
                    areaSegment.Item  = data;
                    areaSegment.XData = xVal;
                    areaSegment.YData = this.YValues[(int)index];
                }
                else
                {
                    var lineSegment = shape.Tag as LineSegment;
                    lineSegment.Item  = data;
                    lineSegment.YData = this.YValues[(int)index];
                }

                if (chartTooltip != null)
                {
                    var tag = shape.Tag;

                    if (canvas.Children.Count == 0 || (canvas.Children.Count > 0 && !IsTooltipAvailable(canvas)))
                    {
                        chartTooltip.Content = tag;
                        if (chartTooltip.Content == null)
                        {
                            return;
                        }

                        if (ChartTooltip.GetInitialShowDelay(this) == 0)
                        {
                            canvas.Children.Add(chartTooltip);
                        }

                        chartTooltip.ContentTemplate = this.GetTooltipTemplate();
                        AddTooltip();

                        if (ChartTooltip.GetEnableAnimation(this))
                        {
                            SetDoubleAnimation(chartTooltip);
                            storyBoard.Children.Add(leftDoubleAnimation);
                            storyBoard.Children.Add(topDoubleAnimation);
                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                            _stopwatch.Start();
                        }
                        else
                        {
                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                            _stopwatch.Start();
                        }
                    }
                    else
                    {
                        foreach (var child in canvas.Children)
                        {
                            var tooltip = child as ChartTooltip;
                            if (tooltip != null)
                            {
                                chartTooltip = tooltip;
                            }
                        }

                        chartTooltip.Content = tag;
                        if (chartTooltip.Content == null)
                        {
                            RemoveTooltip();
                            return;
                        }

                        AddTooltip();
#if NETFX_CORE
                        if (_stopwatch.ElapsedMilliseconds > 100)
                        {
#endif
                        if (ChartTooltip.GetEnableAnimation(this))
                        {
                            _stopwatch.Restart();

                            if (leftDoubleAnimation == null || topDoubleAnimation == null || storyBoard == null)
                            {
                                SetDoubleAnimation(chartTooltip);
                            }
                            else
                            {
                                leftDoubleAnimation.To = chartTooltip.LeftOffset;
                                topDoubleAnimation.To  = chartTooltip.TopOffset;
                                storyBoard.Begin();
                            }
                        }
                        else
                        {
                            _stopwatch.Restart();

                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                        }
#if NETFX_CORE
                    }
#endif
                    }
                }
            }
        }