Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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
                    }
                }
            }
        }