示例#1
0
        internal override void UpdateTooltip(object originalSource)
        {
            if (ShowTooltip)
            {
                FrameworkElement element      = originalSource as FrameworkElement;
                object           chartSegment = null;
                int index = -1;
                if (element != null)
                {
                    if (element.Tag is ChartSegment)
                    {
                        chartSegment = element.Tag;
                    }
                    else if (Segments.Count > 0)
                    {
                        chartSegment = Segments[0];
                    }
                    else
                    {
                        // WPF-28526- Tooltip not shown when set the single data point with adornments for continuous series.
                        index        = ChartExtensionUtils.GetAdornmentIndex(element);
                        chartSegment = index != -1 ? new StackingAreaSegment() : null;
                    }
                }

                if (chartSegment == null)
                {
                    return;
                }

                SetTooltipDuration();
                var    canvas        = this.Area.GetAdorningCanvas();
                double xVal          = 0;
                double yVal          = 0;
                double stackedYValue = double.NaN;
                object data          = null;
                index = 0;

                if (this.Area.SeriesClipRect.Contains(mousePos))
                {
                    var point = new Point(
                        mousePos.X - this.Area.SeriesClipRect.Left,
                        mousePos.Y - this.Area.SeriesClipRect.Top);

                    this.FindNearestChartPoint(point, out xVal, out yVal, out stackedYValue);
                    if (double.IsNaN(xVal))
                    {
                        return;
                    }
                    if (ActualXAxis is CategoryAxis && (ActualXAxis as CategoryAxis).IsIndexed)
                    {
                        index = YValues.IndexOf(yVal);
                    }
                    else
                    {
                        index = this.GetXValues().IndexOf(xVal);
                    }
                    foreach (var series in Area.Series)
                    {
                        if (series == this)
                        {
                            data = this.ActualData[index];
                        }
                    }
                }

                if (data == null)
                {
                    return;               // To ignore tooltip when mousePos is not inside the SeriesClipRect.
                }
                if (this.Area.Tooltip == null)
                {
                    this.Area.Tooltip = new ChartTooltip();
                }
                var chartTooltip = this.Area.Tooltip as ChartTooltip;

                var stackingAreaSegment = chartSegment as StackingAreaSegment;
                stackingAreaSegment.Item  = data;
                stackingAreaSegment.XData = xVal;
                stackingAreaSegment.YData = yVal;
                if (chartTooltip != null)
                {
                    if (canvas.Children.Count == 0 || (canvas.Children.Count > 0 && !IsTooltipAvailable(canvas)))
                    {
                        chartTooltip.Content = chartSegment;
                        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 = chartSegment;

                        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
                    }
                    else if (EnableAnimation == false)
                    {
                        Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                        Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                    }
#endif
                    }
                }
            }
        }
        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
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Updates the tooltip for the series.
        /// </summary>
        /// <param name="source">The Hit Object</param>
        /// <param name="pos">The Mouse Position</param>
        private void UpdateToolTip(object source, Point pos)
        {
            if (this.ShowTooltip)
            {
                object customTag = null;
                this.SetTooltipDuration();
                var canvas = this.Area.GetAdorningCanvas();
                this.mousePos = pos;
                double xVal          = 0;
                double yVal          = 0;
                double stackedYValue = double.NaN;
                object data          = null;
                int    index         = 0;

                var shape = source as Shape;
                if (shape != null && shape.Tag is ChartSegment3D)
                {
                    customTag = shape.Tag;
                }
                else
                {
                    customTag = this.Segments[0];
                }

                var lineSegment = customTag as LineSegment3D;

                if (this.Area.SeriesClipRect.Contains(this.mousePos))
                {
                    var point = new Point(
                        mousePos.X - this.Area.SeriesClipRect.Left,
                        mousePos.Y - this.Area.SeriesClipRect.Top);

                    this.FindNearestChartPoint(point, out xVal, out yVal, out stackedYValue);
                    if (double.IsNaN(xVal))
                    {
                        return;
                    }

                    if (ActualXAxis is CategoryAxis3D && !(ActualXAxis as CategoryAxis3D).IsIndexed)
                    {
                        index = (int)GroupedXValuesIndexes[(int)xVal];
                    }
                    else
                    {
                        index = this.GetXValues().IndexOf(xVal);
                    }

                    data = this.ActualData[index];
                }

                if (this.Area.Tooltip == null)
                {
                    this.Area.Tooltip = new ChartTooltip();
                }

                var chartTooltip = this.Area.Tooltip as ChartTooltip;
                lineSegment.Item  = data;
                lineSegment.XData = xVal;
                lineSegment.YData = yVal;
                if (chartTooltip != null)
                {
                    chartTooltip.ClearValue(ChartTooltip.ContentProperty);
                    chartTooltip.ClearValue(ChartTooltip.ContentTemplateProperty);
                    if (canvas.Children.Count == 0 || (canvas.Children.Count > 0 && !this.IsTooltipAvailable(canvas)))
                    {
                        chartTooltip.Content = customTag;
                        if (chartTooltip.Content == null)
                        {
                            return;
                        }

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

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

                        if (ChartTooltip.GetEnableAnimation(this))
                        {
                            this.SetDoubleAnimation(chartTooltip);
                            storyBoard.Children.Add(this.leftDoubleAnimation);
                            storyBoard.Children.Add(this.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 = customTag;
                        if (chartTooltip.Content == null)
                        {
                            this.RemoveTooltip();
                            return;
                        }

                        chartTooltip.ContentTemplate = this.GetTooltipTemplate();
                        this.AddTooltip();
#if NETFX_CORE
                        if (_stopwatch.ElapsedMilliseconds > 100)
                        {
#endif
                        if (ChartTooltip.GetEnableAnimation(this))
                        {
                            _stopwatch.Restart();
                            if (this.leftDoubleAnimation == null || this.topDoubleAnimation == null || this.storyBoard == null)
                            {
                                this.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
                    }
                    else if (this.EnableAnimation == false)
                    {
                        Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                        Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                    }
#endif
                    }
                }
            }
        }
示例#4
0
        internal override void UpdateTooltip(object originalSource)
        {
            if (ShowTooltip)
            {
                FrameworkElement element      = originalSource as FrameworkElement;
                object           chartSegment = null;

                if (element != null)
                {
                    if (element.Tag is ChartSegment)
                    {
                        chartSegment = element.Tag;
                    }
                    else if (element.DataContext is ChartSegment && !(element.DataContext is ChartAdornment))
                    {
                        chartSegment = element.DataContext;
                    }
                    else
                    {
                        int index = ChartExtensionUtils.GetAdornmentIndex(element);
                        if (index != -1)
                        {
                            if (index < Segments.Count)
                            {
                                chartSegment = Segments[index];
                            }
                            else if (Segments.Count > 0)
                            {
                                chartSegment = Segments[index - 1];
                            }
                            else if (index < Adornments.Count)
                            {
                                // WPF-28526- Tooltip not shown when set the single data point with adornments for continuous series.
                                ChartAdornment adornment = Adornments[index];
                                chartSegment = new StepLineSegment()
                                {
                                    X1Value = adornment.XData,
                                    Y1Value = adornment.YData,
                                    X1Data  = adornment.XData,
                                    Y1Data  = adornment.YData,
                                    X1      = adornment.XData,
                                    Y1      = adornment.YData,
                                    XData   = adornment.XData,
                                    YData   = adornment.YData,
                                    Item    = adornment.Item
                                };
                            }
                        }
                    }
                }

                if (chartSegment == null)
                {
                    return;
                }

                SetTooltipDuration();
                var canvas = this.Area.GetAdorningCanvas();
                if (this.Area.Tooltip == null)
                {
                    this.Area.Tooltip = new ChartTooltip();
                }
                var chartTooltip = this.Area.Tooltip as ChartTooltip;
                if (chartTooltip != null)
                {
                    var lineSegment = chartSegment as StepLineSegment;
                    if (canvas.Children.Count == 0 || (canvas.Children.Count > 0 && !IsTooltipAvailable(canvas)))
                    {
                        SetTooltipSegmentItem(lineSegment);
                        chartTooltip.Content = chartSegment;

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

                        SetTooltipSegmentItem(lineSegment);
                        chartTooltip.Content         = chartSegment;
                        chartTooltip.ContentTemplate = this.GetTooltipTemplate();
                        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
                        {
                            Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                            Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                        }
#if NETFX_CORE
                    }
                    else if (EnableAnimation == false)
                    {
                        Canvas.SetLeft(chartTooltip, chartTooltip.LeftOffset);
                        Canvas.SetTop(chartTooltip, chartTooltip.TopOffset);
                    }
#endif
                    }
                }
            }
        }