示例#1
0
        private object GetTooltipContext(Point location)
        {
            ChartDataContext defaultContext = this.GetDataContext(location, true);

            this.closestDataPointInfo = defaultContext.ClosestDataPoint;

            if (this.closestDataPointInfo != null && this.closestDataPointInfo.DataPoint.Presenter != null)
            {
                var template = GetContentTemplate(this.closestDataPointInfo.DataPoint.Presenter as ChartSeries);

                if (template != null)
                {
                    this.toolTipContent.ContentTemplate = template;
                }

                if (template == null)
                {
                    template = GetContentTemplate(this);
                    this.toolTipContent.ContentTemplate = template;
                }

                if (template == null)
                {
                    this.toolTipContent.ClearValue(ContentControl.ContentTemplateProperty);
                }
            }

            return(this.OnContextNeeded(defaultContext));
        }
        private void ArrangeIndividualTrackInfos()
        {
            int   index      = 0;
            Point plotOrigin = this.chart.PlotOrigin;

            foreach (ContentPresenter presenter in this.individualTrackInfos)
            {
                if (presenter.Visibility == Visibility.Collapsed)
                {
                    continue;
                }

                DataPointInfo info       = presenter.Content as DataPointInfo;
                RadRect       layoutSlot = info.DataPoint.layoutSlot;

                Size size = presenter.DesiredSize;
                HorizontalAlignment horizontalAlign = index % 2 == 0 ? HorizontalAlignment.Left : HorizontalAlignment.Right;
                double x = 0;

                switch (horizontalAlign)
                {
                case HorizontalAlignment.Left:
                    x = layoutSlot.X - size.Width;
                    break;

                case HorizontalAlignment.Center:
                    x = layoutSlot.Center.X - size.Width / 2;
                    break;

                case HorizontalAlignment.Right:
                    x = layoutSlot.Right;
                    break;
                }

                double y = layoutSlot.Center.Y - size.Height / 2;

                Canvas.SetLeft(presenter, x + plotOrigin.X);
                Canvas.SetTop(presenter, y + plotOrigin.Y);

                index++;
            }
        }
示例#3
0
 internal ChartDataContext(List <DataPointInfo> infos, DataPointInfo closestPoint)
 {
     this.DataPoints       = infos;
     this.ClosestDataPoint = closestPoint;
 }
示例#4
0
        /// <summary>
        /// Gets <see cref="ChartDataContext"/> associated with a gives physical location.
        /// </summary>
        /// <param name="tapLocation">The relative physical position of the requested data context.</param>
        /// <param name="pointDistanceMode">The point distance calculation mode to be used in finding closest point.</param>
        /// <returns>Returns <see cref="ChartDataContext"/> object holding information for the requested physical location.</returns>
        protected virtual ChartDataContext GetDataContextCore(Point tapLocation, ChartPointDistanceCalculationMode pointDistanceMode)
        {
            List <DataPointInfo> closestPoints = new List <DataPointInfo>();
            double totalMinDistance            = double.PositiveInfinity;

            DataPointInfo closestPoint = null;

            foreach (ChartSeriesModel series in this.chartArea.Series)
            {
                if (!series.Presenter.IsVisible)
                {
                    continue;
                }

                DataPointInfo currentClosestDataPoint = null;
                double        minDistance             = double.PositiveInfinity;
                ChartSeries   visualSeries            = series.presenter as ChartSeries;

                foreach (DataPoint dataPoint in series.DataPointsInternal)
                {
                    if (dataPoint.isEmpty)
                    {
                        continue;
                    }

                    double distance;
                    if (dataPoint.ContainsPosition(tapLocation.X, tapLocation.Y))
                    {
                        distance = 0;
                    }
                    else
                    {
                        distance = visualSeries.GetDistanceToPoint(dataPoint, tapLocation, pointDistanceMode);
                    }

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        if (currentClosestDataPoint == null)
                        {
                            currentClosestDataPoint = new DataPointInfo();
                        }

                        currentClosestDataPoint.DataPoint   = dataPoint;
                        currentClosestDataPoint.SeriesModel = series;
                    }

                    if (distance < totalMinDistance)
                    {
                        totalMinDistance = distance;
                        closestPoint     = currentClosestDataPoint;
                        if (distance == 0)
                        {
                            closestPoint.ContainsTouchLocation = true;
                        }
                    }
                }

                if (currentClosestDataPoint != null)
                {
                    closestPoints.Add(currentClosestDataPoint);
                }
            }

            return(new ChartDataContext(closestPoints, closestPoint)
            {
                TouchLocation = tapLocation
            });
        }