示例#1
0
        protected override Point GetToolTipPosition(ShapeMap sender, List <ShapeMap> sibilings)
        {
            DataTooltip.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var unitW    = ToPlotArea(1, AxisTags.X) - PlotArea.X + 5;
            var overflow = unitW - MaxColumnWidth > 0 ? unitW - MaxColumnWidth : 0;

            unitW = unitW > MaxColumnWidth ? MaxColumnWidth : unitW;
            var x = sender.ChartPoint.X + 1 > (Min.X + Max.X) / 2
                ? ToPlotArea(sender.ChartPoint.X, AxisTags.X) + overflow * .5 - DataTooltip.DesiredSize.Width
                : ToPlotArea(sender.ChartPoint.X, AxisTags.X) + unitW + overflow * .5;
            var y = ToPlotArea(sibilings.Where(s => s.Series is StackedBarSeries).Select(s => s.ChartPoint.Y).DefaultIfEmpty(0).Sum() * 0.5, AxisTags.Y);

            y = y + DataTooltip.DesiredSize.Height > ActualHeight
                ? y - (y + DataTooltip.DesiredSize.Height - ActualHeight) - 5
                : y;
            return(new Point(x, y));
        }
示例#2
0
        protected override Point GetToolTipPosition(HoverableShape sender, List <HoverableShape> sibilings)
        {
            DataTooltip.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var unitW    = ToPlotArea(1, AxisTags.X) - PlotArea.X + 5;
            var overflow = unitW - MaxColumnWidth * 3 > 0 ? unitW - MaxColumnWidth * 3 : 0;

            unitW = unitW > MaxColumnWidth * 3 ? MaxColumnWidth * 3 : unitW;
            var x = sender.Value.X + 1 > (Min.X + Max.X) / 2
                ? ToPlotArea(sender.Value.X, AxisTags.X) + overflow * .5 - DataTooltip.DesiredSize.Width
                : ToPlotArea(sender.Value.X, AxisTags.X) + unitW + overflow * .5;
            var y = ToPlotArea(sibilings.Select(s => s.Value.Y).DefaultIfEmpty(0).Sum()
                               / sibilings.Count, AxisTags.Y);

            y = y + DataTooltip.DesiredSize.Height > ActualHeight
                ? y - (y + DataTooltip.DesiredSize.Height - ActualHeight) - 5
                : y;
            return(new Point(x, y));
        }
示例#3
0
        protected override Point GetToolTipPosition(ShapeMap sender, List <ShapeMap> sibilings)
        {
            DataTooltip.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var unitW    = ToPlotArea(1, AxisTags.X) - System.Windows.Controls.Canvas.GetLeft(DrawMargin) + 5;
            var overflow = unitW - MaxColumnWidth * 3 > 0 ? unitW - MaxColumnWidth * 3 : 0;

            unitW = unitW > MaxColumnWidth * 3 ? MaxColumnWidth * 3 : unitW;
            var targetAxis = Invert ? sender.Series.ScalesYAt : sender.Series.ScalesXAt;
            var x          = sender.ChartPoint.X + 1 > (AxisX[targetAxis].MaxLimit + AxisX[targetAxis].MaxLimit) / 2
                ? ToPlotArea(sender.ChartPoint.X, AxisTags.X) + overflow * .5 - DataTooltip.DesiredSize.Width
                : ToPlotArea(sender.ChartPoint.X, AxisTags.X) + unitW + overflow * .5;
            var y = ToPlotArea(sibilings.Select(s => s.ChartPoint.Y).DefaultIfEmpty(0).Sum()
                               / sibilings.Count, AxisTags.Y);

            y = y + DataTooltip.DesiredSize.Height > ActualHeight
                ? y - (y + DataTooltip.DesiredSize.Height - ActualHeight) - 5
                : y;
            return(new Point(x, y));
        }
示例#4
0
        protected internal override void DataMouseEnter(object sender, MouseEventArgs e)
        {
            if (DataTooltip == null || !Hoverable)
            {
                return;
            }

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

            var senderShape = ShapesMapper.FirstOrDefault(s => Equals(s.HoverShape, sender));

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

            if (pieSlice == null)
            {
                return;
            }

            var xi = senderShape.Series.ScalesXAt;
            var yi = senderShape.Series.ScalesYAt;

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

            senderShape.Shape.Opacity = .8;
            var vx = senderShape.ChartPoint.X;

            var indexedToolTip = DataTooltip as IndexedTooltip;

            if (indexedToolTip != null)
            {
                indexedToolTip.Header = null;
                //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.HoverShape.Stroke,
                        Fill   = senderShape.HoverShape.Fill,
                        Series = senderShape.Series,
                        Point  = senderShape.ChartPoint,
                        Value  = AxisY[yi].LabelFormatter == null
                            ? senderShape.ChartPoint.Y.ToString(CultureInfo.InvariantCulture)
                            : AxisY[yi].LabelFormatter(senderShape.ChartPoint.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);
        }
示例#5
0
        protected internal override void DataMouseEnter(object sender, MouseEventArgs e)
        {
            //this is only while we fix PCL try...
            if (DataTooltip == null || !Hoverable)
            {
                return;
            }

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

            var senderShape = Series.SelectMany(
                x =>
                x.IsPrimitive
                        ? x.Tracker.Primitives.Select(v => v.Value)
                        : x.Tracker.Instances.Select(v => v.Value))
                              .FirstOrDefault(x => Equals(x.HoverShape, sender));

            if (senderShape == null)
            {
                return;
            }

            var targetAxis = Invert ? senderShape.Series.ScalesYAt : senderShape.Series.ScalesXAt;

            var sibilings = Invert
                ? Series.SelectMany(
                x =>
                x.IsPrimitive
                            ? x.Tracker.Primitives.Select(v => v.Value)
                            : x.Tracker.Instances.Select(v => v.Value))
                            .Where(s => Math.Abs(s.ChartPoint.Y - senderShape.ChartPoint.Y) < AxisY[targetAxis].S * .01)
                            .ToList()
                : Series.SelectMany(
                x =>
                x.IsPrimitive
                            ? x.Tracker.Primitives.Select(v => v.Value)
                            : x.Tracker.Instances.Select(v => v.Value))
                            .Where(s => Math.Abs(s.ChartPoint.X - senderShape.ChartPoint.X) < AxisX[targetAxis].S * .01)
                            .ToList();

            var first = sibilings.Count > 0 ? sibilings[0] : null;
            var vx    = first != null ? (Invert ? first.ChartPoint.Y : first.ChartPoint.X) : 0;

            foreach (var sibiling in sibilings)
            {
                if (ShapeHoverBehavior == ShapeHoverBehavior.Dot)
                {
                    sibiling.Shape.Stroke = sibiling.Series.Stroke;
                    sibiling.Shape.Fill   = new SolidColorBrush {
                        Color = PointHoverColor
                    };
                }
                else
                {
                    sibiling.Shape.Opacity = .8;
                }
                sibiling.IsHighlighted = true;
            }

            var indexedToolTip = DataTooltip as IndexedTooltip;

            if (indexedToolTip != null)
            {
                var fh = (Invert ? AxisY[targetAxis] : AxisX[targetAxis]).GetFormatter();
                var fs = (Invert ? AxisX[targetAxis] : AxisY[targetAxis]).GetFormatter();

                indexedToolTip.Header = fh(vx);
                indexedToolTip.Data   = sibilings.Select(x => new IndexedTooltipData
                {
                    Index  = Series.IndexOf(x.Series),
                    Series = x.Series,
                    Stroke = x.Series.Stroke,
                    Fill   = x.Series.Fill,
                    Point  = x.ChartPoint,
                    Value  = fs(Invert ? x.ChartPoint.X : x.ChartPoint.Y)
                }).ToArray();
            }

            //var p = GetToolTipPosition(senderShape, sibilings);

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

            var xt = senderShape.ChartPoint.X > (AxisX[targetAxis].MinLimit + AxisX[targetAxis].MaxLimit) / 2
                ? senderShape.ChartPoint.Location.X - 10 - DataTooltip.DesiredSize.Width
                : senderShape.ChartPoint.Location.X + 10;

            xt += System.Windows.Controls.Canvas.GetLeft(DrawMargin);

            var y = sibilings.Select(s => s.ChartPoint.Location.Y).DefaultIfEmpty(0).Sum() / sibilings.Count;

            y = y + DataTooltip.DesiredSize.Height > ActualHeight ? y - (y + DataTooltip.DesiredSize.Height - ActualHeight) - 5 : y;
            var p = new Point(xt, y);

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