Example #1
0
        internal override void DataMouseEnter(object sender, MouseEventArgs e)
        {
            if (DataTooltip == null)
            {
                return;
            }

            DataTooltip.Visibility = Visibility.Visible;
            TooltipTimer.Stop();

            var senderShape = HoverableShapes.FirstOrDefault(s => Equals(s.Shape, sender));

            if (senderShape == null)
            {
                return;
            }
            var pieSlice = senderShape.Shape as PieSlice;

            if (pieSlice == null)
            {
                return;
            }

            var labels = AxisX.Labels != null?AxisX.Labels.ToArray() : null;

            senderShape.Target.Opacity = .8;
            var vx = senderShape.Value.X;

            var indexedToolTip = DataTooltip as IndexedTooltip;

            if (indexedToolTip != null)
            {
                indexedToolTip.Header = labels == null
                        ? (AxisX.LabelFormatter == null
                            ? vx.ToString(CultureInfo.InvariantCulture)
                            : AxisX.LabelFormatter(vx))
                        : (labels.Length > vx
                            ? labels[(int)vx]
                            : "");
                indexedToolTip.Data = new[]
                {
                    new IndexedTooltipData
                    {
                        Index  = (int)vx,
                        Stroke = senderShape.Shape.Stroke,
                        Fill   = senderShape.Shape.Fill,
                        Series = senderShape.Series,
                        Point  = senderShape.Value,
                        Value  = AxisY.LabelFormatter == null
                            ? senderShape.Value.Y.ToString(CultureInfo.InvariantCulture)
                            : AxisY.LabelFormatter(senderShape.Value.Y)
                    }
                };
            }

            var alpha         = pieSlice.RotationAngle + pieSlice.WedgeAngle * .5 + 180;
            var alphaRad      = alpha * Math.PI / 180;
            var sliceMidAngle = alpha - 180;

            DataTooltip.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            var y = Canvas.ActualHeight * .5 + (sliceMidAngle > 90 && sliceMidAngle < 270 ? -1 : 0) * DataTooltip.DesiredSize.Height - Math.Cos(alphaRad) * 15;
            var x = Canvas.ActualWidth * .5 + (sliceMidAngle > 0 && sliceMidAngle < 180 ? -1 : 0) * DataTooltip.DesiredSize.Width + Math.Sin(alphaRad) * 15;

            var p = new Point(x, y);

            DataTooltip.BeginAnimation(Canvas.LeftProperty, new DoubleAnimation
            {
                To       = p.X,
                Duration = TimeSpan.FromMilliseconds(200)
            });
            DataTooltip.BeginAnimation(Canvas.TopProperty, new DoubleAnimation
            {
                To       = p.Y,
                Duration = TimeSpan.FromMilliseconds(200)
            });

            pieSlice.Opacity = .8;

            var anim = new DoubleAnimation
            {
                To       = 5,
                Duration = TimeSpan.FromMilliseconds(150)
            };

            pieSlice.BeginAnimation(PieSlice.PushOutProperty, anim);
        }