コード例 #1
0
        /// <summary>
        /// Gets the nearest tracker hit.
        /// </summary>
        /// <param name="s">
        /// The series.
        /// </param>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="snap">
        /// Snap to points.
        /// </param>
        /// <param name="pointsOnly">
        /// Check points only (no interpolation).
        /// </param>
        /// <returns>
        /// A tracker hit result.
        /// </returns>
        private static TrackerHitResult GetNearestHit(ITrackableSeries s, ScreenPoint point, bool snap, bool pointsOnly)
        {
            if (s == null)
            {
                return(null);
            }

            // Check data points only
            if (snap || pointsOnly)
            {
                TrackerHitResult result = s.GetNearestPoint(point, false);
                if (result != null)
                {
                    if (result.Position.DistanceTo(point) < 20)
                    {
                        return(result);
                    }
                }
            }

            // Check between data points (if possible)
            if (!pointsOnly)
            {
                TrackerHitResult result = s.GetNearestPoint(point, true);
                return(result);
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Tracker is calling to determine the nearest point.
        /// </summary>
        /// <param name="point">The point clicked</param>
        /// <param name="interpolate">A value indicating whether interpolation should be used.</param>
        /// <returns>The return hit result</returns>
        public override TrackerHitResult GetNearestPoint(OxyPlot.ScreenPoint point, bool interpolate)
        {
            TrackerHitResult hitResult = base.GetNearestPoint(point, interpolate);

            if (hitResult != null && OnHoverOverPoint != null)
            {
                HoverPointArgs e = new HoverPointArgs();
                if (Title == null)
                {
                    e.SeriesName = ToolTip;
                }
                else
                {
                    e.SeriesName = Title;
                }

                e.X = hitResult.DataPoint.X;
                e.Y = hitResult.DataPoint.Y;
                OnHoverOverPoint.Invoke(this, e);
                if (e.HoverText != null)
                {
                    hitResult.Series.TrackerFormatString = e.HoverText + "\n{1}: {2}\n{3}: {4}";
                }
            }

            return(hitResult);
        }
コード例 #3
0
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (interpolate && !this.CanTrackerInterpolatePoints)
            {
                return(null);
            }

            TrackerHitResult result = null;

            if (interpolate)
            {
                result = this.GetNearestInterpolatedPointInternal(this.ActualPoints, point);
            }

            if (result == null)
            {
                result = this.GetNearestPointInternal(this.ActualPoints, point);
            }

            if (result != null)
            {
                result.Text = StringHelper.Format(
                    this.ActualCulture,
                    this.TrackerFormatString,
                    result.Item,
                    this.Title,
                    this.XAxis.Title ?? XYAxisSeries.DefaultXAxisTitle,
                    this.XAxis.GetValue(result.DataPoint.X),
                    this.YAxis.Title ?? XYAxisSeries.DefaultYAxisTitle,
                    this.YAxis.GetValue(result.DataPoint.Y));
            }

            return(result);
        }
コード例 #4
0
ファイル: PlotView.cs プロジェクト: oxyplot/oxyplot-gtksharp
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="data">The data.</param>
        public void ShowTracker(TrackerHitResult data)
        {
            if (this.trackerLabel == null)
            {
                // Holding the tracker label inside an EventBox allows
                // us to set the background color
                Gtk.EventBox labelHolder = new Gtk.EventBox();
                this.trackerLabel = new Gtk.Label();
                this.trackerLabel.SetPadding(3, 3);
                OxyColor bgColor = OxyColors.LightSkyBlue;
                labelHolder.ModifyBg(StateType.Normal, new Gdk.Color(bgColor.R, bgColor.G, bgColor.B));
                labelHolder.Add(this.trackerLabel);
                this.Add(labelHolder);
                labelHolder.ShowAll();
            }
            this.trackerLabel.Parent.Visible = true;
            this.trackerLabel.Text           = data.ToString();
            Gtk.Requisition req  = this.trackerLabel.Parent.SizeRequest();
            int             xPos = (int)data.Position.X - req.Width / 2;
            int             yPos = (int)data.Position.Y - req.Height;

            xPos = Math.Max(0, Math.Min(xPos, this.Allocation.Width - req.Width));
            yPos = Math.Max(0, Math.Min(yPos, this.Allocation.Height - req.Height));
            this.Move(trackerLabel.Parent, xPos, yPos);
        }
コード例 #5
0
        TrackerHitResult GetNearestPointSelf(ScreenPoint point, bool interpolate)
        {
            if (interpolate && !this.CanTrackerInterpolatePoints)
            {
                return(null);
            }

            TrackerHitResult result = null;

            if (interpolate)
            {
                result = this.GetNearestInterpolatedPointInternal(this.ActualPoints, point);
            }

            if (result == null)
            {
                result = this.GetNearestPointInternal(this.ActualPoints, point);
            }

            if (result != null)
            {
                //result.Text = this.Format(
                //    this.TrackerFormatString,
                //    result.Item,
                //    this.Title,
                //    XTitle ?? XYAxisSeries.DefaultXAxisTitle,
                //    this.XAxis.GetValue(result.DataPoint.X),
                //    YTitle ?? XYAxisSeries.DefaultYAxisTitle,
                //    this.YAxis.GetValue(result.DataPoint.Y));

                //this.format
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Gets the point in the dataset that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">The interpolate.</param>
        /// <returns>A hit result object.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            TrackerHitResult result = null;

            var xaxisTitle = this.XAxis.Title ?? "X";
            var yaxisTitle = this.YAxis.Title ?? "Y";
            var zaxisTitle = "Z";

            foreach (var c in this.contours)
            {
                var r = interpolate ? this.GetNearestInterpolatedPointInternal(c.Points, point) : this.GetNearestPointInternal(c.Points, point);
                if (r != null)
                {
                    if (result == null || result.Position.DistanceToSquared(point) > r.Position.DistanceToSquared(point))
                    {
                        result      = r;
                        result.Text = this.Format(
                            this.TrackerFormatString,
                            null,
                            this.Title,
                            xaxisTitle,
                            r.DataPoint.X,
                            yaxisTitle,
                            r.DataPoint.Y,
                            zaxisTitle,
                            c.ContourLevel);
                    }
                }
            }

            return(result);
        }
コード例 #7
0
ファイル: PlotView.cs プロジェクト: choenden/oxyplot
 /// <summary>
 /// Hides the tracker.
 /// </summary>
 public virtual void HideTracker()
 {
     lock (trackerLock)
     {
         actualTrackerHitResult = null;
     }
     QueueDraw();
 }
コード例 #8
0
ファイル: PlotView.cs プロジェクト: choenden/oxyplot
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="trackerHitResult">The data.</param>
 public virtual void ShowTracker(TrackerHitResult trackerHitResult)
 {
     lock (trackerLock)
     {
         actualTrackerHitResult = trackerHitResult;
     }
     QueueDraw();
 }
コード例 #9
0
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="interpolate">
        /// interpolate if set to <c>true</c> .
        /// </param>
        /// <returns>
        /// A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            TrackerHitResult result = null;

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistance = double.MaxValue;

            for (int i = 0; i + 1 < this.Points.Count; i++)
            {
                var p1  = this.Points[i];
                var p2  = this.Points[i + 1];
                var sp1 = this.Transform(p1.X, p1.Y);
                var sp2 = this.Transform(p2.X, p1.Y);

                double spdx = sp2.x - sp1.x;
                double spdy = sp2.y - sp1.y;
                double u1   = ((point.x - sp1.x) * spdx) + ((point.y - sp1.y) * spdy);
                double u2   = (spdx * spdx) + (spdy * spdy);
                double ds   = (spdx * spdx) + (spdy * spdy);

                if (ds < 4)
                {
                    // if the points are very close, we can get numerical problems, just use the first point...
                    u1 = 0;
                    u2 = 1;
                }

                if (Math.Abs(u2) < double.Epsilon)
                {
                    continue; // P1 && P2 coincident
                }

                double u = u1 / u2;
                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                double sx = sp1.x + (u * spdx);
                double sy = sp1.y + (u * spdy);

                double dx       = point.x - sx;
                double dy       = point.y - sy;
                double distance = (dx * dx) + (dy * dy);

                if (distance < minimumDistance)
                {
                    double px = p1.X + (u * (p2.X - p1.X));
                    double py = p1.Y;
                    result = new TrackerHitResult(
                        this, new DataPoint(px, py), new ScreenPoint(sx, sy), this.GetItem(i), i);
                    minimumDistance = distance;
                }
            }

            return(result);
        }
コード例 #10
0
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>
        /// A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (interpolate)
            {
                return(null);
            }

            double minimumDistance = double.MaxValue;
            var    result          = new TrackerHitResult(this, DataPoint.Undefined, ScreenPoint.Undefined);

            Action <DataPoint, HighLowItem, int> check = (p, item, index) =>
            {
                var    sp = this.Transform(p);
                double dx = sp.x - point.x;
                double dy = sp.y - point.y;
                double d2 = (dx * dx) + (dy * dy);

                if (d2 < minimumDistance)
                {
                    result.DataPoint = p;
                    result.Position  = sp;
                    result.Item      = item;
                    result.Index     = index;
                    if (this.TrackerFormatString != null)
                    {
                        result.Text = StringHelper.Format(
                            this.ActualCulture,
                            this.TrackerFormatString,
                            item,
                            this.Title,
                            p.X,
                            item.High,
                            item.Low,
                            item.Open,
                            item.Close);
                    }

                    minimumDistance = d2;
                }
            };
            int i = 0;

            foreach (var item in this.items)
            {
                check(new DataPoint(item.X, item.High), item, i);
                check(new DataPoint(item.X, item.Low), item, i);
                check(new DataPoint(item.X, item.Open), item, i);
                check(new DataPoint(item.X, item.Close), item, i++);
            }

            if (minimumDistance < double.MaxValue)
            {
                return(result);
            }

            return(null);
        }
コード例 #11
0
ファイル: ImpulseResponseGraph.cs プロジェクト: Jonarw/filter
        /// <summary>
        ///     Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>
        ///     A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if ((this.XAxis == null) || (this.YAxis == null))
            {
                return(null);
            }

            if (interpolate)
            {
                return(null);
            }

            var p1     = this.InverseTransform(point);
            var points = this.ActualPoints;
            int c;

            for (c = 0; c <= points.Count - 1; c++)
            {
                if ((p1.X - points[c].X < 0.5) && (p1.X - points[c].X > -0.5))
                {
                    break;
                }
            }

            if (c >= points.Count)
            {
                return(null);
            }

            var p2 = points[c];

            var result = new TrackerHitResult
            {
                Series    = this,
                DataPoint = p2,
                Position  = this.Transform(p2.X, p2.Y),
                Item      = this.GetItem(c),
                Index     = c,
                Text      =
                    StringHelper.Format(
                        this.ActualCulture,
                        this.TrackerFormatString,
                        p2,
                        this.Title,
                        this.XAxis.Title ?? DefaultXAxisTitle,
                        this.XAxis.GetValue(p2.X),
                        this.YAxis.Title ?? DefaultYAxisTitle,
                        this.YAxis.GetValue(p2.Y))
            };

            return(result);
        }
コード例 #12
0
ファイル: PlotView.cs プロジェクト: TDControlsGroup/CLARA_RGA
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="data">The data.</param>
        public void ShowTracker(TrackerHitResult data)
        {
            if (this.trackerLabel == null)
            {
                this.trackerLabel = new Label {
                    Parent = this, BackColor = Color.LightSkyBlue, AutoSize = true, Padding = new Padding(5)
                };
            }

            this.trackerLabel.Text    = data.ToString();
            this.trackerLabel.Top     = (int)data.Position.Y - this.trackerLabel.Height;
            this.trackerLabel.Left    = (int)data.Position.X - this.trackerLabel.Width / 2;
            this.trackerLabel.Visible = true;
        }
コード例 #13
0
ファイル: StemSeries.cs プロジェクト: wolf9s/oxyplot
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            if (interpolate)
            {
                return(null);
            }

            TrackerHitResult result = null;

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistance = double.MaxValue;
            var    points          = this.ActualPoints;

            for (int i = 0; i < points.Count; i++)
            {
                var p1        = points[i];
                var basePoint = new DataPoint(p1.X, this.Base);
                var sp1       = this.Transform(p1);
                var sp2       = this.Transform(basePoint);
                var u         = ScreenPointHelper.FindPositionOnLine(point, sp1, sp2);

                if (double.IsNaN(u))
                {
                    continue;
                }

                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                var    sp       = sp1 + ((sp2 - sp1) * u);
                double distance = (point - sp).LengthSquared;

                if (distance < minimumDistance)
                {
                    result = new TrackerHitResult(
                        this, new DataPoint(p1.X, p1.Y), new ScreenPoint(sp1.x, sp1.y), this.GetItem(i));
                    minimumDistance = distance;
                }
            }

            return(result);
        }
コード例 #14
0
        override public TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            TrackerHitResult result = base.GetNearestPoint(point, interpolate);

            // いずれかがnullではないとき
            if (this.oldResult != null || result != null)
            {
                // TrackerHitResult が変化していたとき
                if ((this.oldResult == null && result != null) || (this.oldResult != null && result == null))
                {
                    // 通知する
                    TrackerHitResultChanged?.Invoke(this, new EventArgs <TrackerHitResult>(result));
                }
            }
            this.oldResult = result;

            return(result);
        }
コード例 #15
0
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">The tracker data.</param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult == null)
            {
                this.HideTracker();
                return;
            }

            var ts = trackerHitResult.Series as ITrackableSeries;
            var trackerTemplate = this.DefaultTrackerTemplate;

            if (ts != null && !string.IsNullOrEmpty(ts.TrackerKey))
            {
                var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == ts.TrackerKey);
                if (match != null)
                {
                    trackerTemplate = match.TrackerTemplate;
                }
            }

            if (trackerTemplate == null)
            {
                this.HideTracker();
                return;
            }

            var tracker = new ContentControl {
                Template = trackerTemplate
            };

            // ReSharper disable once RedundantNameQualifier
            if (!object.ReferenceEquals(tracker, this.currentTracker))
            {
                this.HideTracker();
                this.overlays.Children.Add(tracker);
                this.currentTracker = tracker;
            }

            if (this.currentTracker != null)
            {
                this.currentTracker.DataContext = trackerHitResult;
            }
        }
コード例 #16
0
ファイル: PlotViewBase.cs プロジェクト: am1752/StudyCSharpp
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">The tracker data.</param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult == null)
            {
                this.HideTracker();
                return;
            }

            var trackerTemplate = this.DefaultTrackerTemplate;

            if (trackerHitResult.Series != null && !string.IsNullOrEmpty(trackerHitResult.Series.TrackerKey))
            {
                var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == trackerHitResult.Series.TrackerKey);
                if (match != null)
                {
                    trackerTemplate = match.TrackerTemplate;
                }
            }

            if (trackerTemplate == null)
            {
                this.HideTracker();
                return;
            }

            if (!ReferenceEquals(trackerTemplate, this.currentTrackerTemplate))
            {
                this.HideTracker();

                var tracker = new ContentControl {
                    Template = trackerTemplate
                };
                this.overlays.Children.Add(tracker);
                this.currentTracker         = tracker;
                this.currentTrackerTemplate = trackerTemplate;
            }

            if (this.currentTracker != null)
            {
                this.currentTracker.DataContext = trackerHitResult;
            }
        }
コード例 #17
0
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">The tracker data.</param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult == null)
            {
                this.HideTracker();
                return;
            }

            var trackerTemplate = this.DefaultTrackerTemplate;

            if (trackerHitResult.Series != null && !string.IsNullOrEmpty(trackerHitResult.Series.TrackerKey))
            {
                var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == trackerHitResult.Series.TrackerKey);
                if (match != null)
                {
                    trackerTemplate = match.TrackerTemplate;
                }
            }

            if (trackerTemplate == null)
            {
                this.HideTracker();
                return;
            }

            if (!ReferenceEquals(trackerTemplate, this.currentTrackerTemplate))
            {
                this.HideTracker();

                var tracker = (ContentView)trackerTemplate.CreateContent();
                this.overlays.Children.Add(tracker);
                AbsoluteLayout.SetLayoutBounds(tracker, new Rectangle(0, 0, 0, 0));
                this.currentTracker         = tracker;
                this.currentTrackerTemplate = trackerTemplate;
            }

            if (this.currentTracker != null)
            {
                this.currentTracker.BindingContext = trackerHitResult;
            }
        }
コード例 #18
0
        /// <summary>
        /// Occurs when the input device changes position during a manipulation.
        /// </summary>
        /// <param name="e">
        /// The <see cref="OxyPlot.ManipulationEventArgs"/> instance containing the event data.
        /// </param>
        public override void Delta(ManipulationEventArgs e)
        {
            base.Delta(e);
            if (this.currentSeries == null)
            {
                return;
            }

            if (!this.PlotControl.ActualModel.PlotArea.Contains(e.CurrentPosition.X, e.CurrentPosition.Y))
            {
                return;
            }

            TrackerHitResult result = GetNearestHit(this.currentSeries, e.CurrentPosition, this.Snap, this.PointsOnly);

            if (result != null)
            {
                result.PlotModel = this.PlotControl.ActualModel;
                this.PlotControl.ShowTracker(result);
            }
        }
コード例 #19
0
ファイル: PlotBase.cs プロジェクト: oxyplot/oxyplot-avalonia
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">The tracker data.</param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult == null)
            {
                HideTracker();
                return;
            }

            var trackerTemplate = DefaultTrackerTemplate;

            if (trackerHitResult.Series != null && !string.IsNullOrEmpty(trackerHitResult.Series.TrackerKey))
            {
                var match = TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == trackerHitResult.Series.TrackerKey);
                if (match != null)
                {
                    trackerTemplate = match.TrackerTemplate;
                }
            }

            if (trackerTemplate == null)
            {
                HideTracker();
                return;
            }

            var tracker = trackerTemplate.Build(new ContentControl());

            // ReSharper disable once RedundantNameQualifier
            if (!object.ReferenceEquals(tracker, currentTracker))
            {
                HideTracker();
                overlays.Children.Add(tracker.Control);
                currentTracker = tracker.Control;
            }

            if (currentTracker != null)
            {
                currentTracker.DataContext = trackerHitResult;
            }
        }
コード例 #20
0
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">
        /// The tracker data.
        /// </param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult != null)
            {
                var ts = trackerHitResult.Series as ITrackableSeries;
                var trackerTemplate = this.DefaultTrackerTemplate;
                if (ts != null && !string.IsNullOrEmpty(ts.TrackerKey))
                {
                    var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == ts.TrackerKey);
                    if (match != null)
                    {
                        trackerTemplate = match.TrackerTemplate;
                    }
                }

                var tracker = new ContentControl {
                    Template = trackerTemplate
                };

                if (tracker != this.currentTracker)
                {
                    this.HideTracker();
                    if (trackerTemplate != null)
                    {
                        this.overlays.Children.Add(tracker);
                        this.currentTracker = tracker;
                    }
                }

                if (this.currentTracker != null)
                {
                    this.currentTracker.DataContext = trackerHitResult;
                }
            }
            else
            {
                this.HideTracker();
            }
        }
コード例 #21
0
ファイル: MainViewModel.cs プロジェクト: yao-yi/DNTProfiler
        protected override string GetCustomTooltip(TrackerHitResult hitTestResult)
        {
            var lineSeries = hitTestResult.Series as LineSeries;

            if (lineSeries == null)
            {
                return(string.Empty);
            }

            if (GuiModelData.SelectedApplicationIdentity == null)
            {
                return(string.Empty);
            }

            var requestId    = getSelectedRequestId(hitTestResult.Index, lineSeries);
            var firstCommand = PluginContext.ProfilerData.Commands
                               .FirstOrDefault(command => command.HttpInfo.HttpContextCurrentId == requestId &&
                                               command.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity));


            return(firstCommand == null ? string.Empty : string.Format("URL: {0}", firstCommand.HttpInfo.Url));
        }
コード例 #22
0
ファイル: PlotView.cs プロジェクト: oxyplot/oxyplot-xwt
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="trackerHitResult">The data.</param>
 public virtual void ShowTracker(TrackerHitResult trackerHitResult)
 {
     lock (trackerLock)
     {
         actualTrackerHitResult = trackerHitResult;
     }
     QueueDraw();
 }
コード例 #23
0
ファイル: HighLowSeries.cs プロジェクト: benjaminrupp/oxyplot
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            if (interpolate)
            {
                return null;
            }

            double minimumDistance = double.MaxValue;

            TrackerHitResult result = null;
            Action<DataPoint, HighLowItem, int> check = (p, item, index) =>
                {
                    var sp = this.Transform(p);
                    double dx = sp.x - point.x;
                    double dy = sp.y - point.y;
                    double d2 = (dx * dx) + (dy * dy);

                    if (d2 < minimumDistance)
                    {
                        result = new TrackerHitResult
                        {
                            Series = this,
                            DataPoint = p,
                            Position = sp,
                            Item = item,
                            Index = index,
                            Text =
                                StringHelper.Format(
                                    this.ActualCulture,
                                    this.TrackerFormatString,
                                    item,
                                    this.Title,
                                    this.XAxis.Title ?? DefaultXAxisTitle,
                                    this.XAxis.GetValue(p.X),
                                    this.YAxis.GetValue(item.High),
                                    this.YAxis.GetValue(item.Low),
                                    this.YAxis.GetValue(item.Open),
                                    this.YAxis.GetValue(item.Close))
                        };

                        minimumDistance = d2;
                    }
                };
            int i = 0;
            foreach (var item in this.items)
            {
                check(new DataPoint(item.X, item.High), item, i);
                check(new DataPoint(item.X, item.Low), item, i);
                check(new DataPoint(item.X, item.Open), item, i);
                check(new DataPoint(item.X, item.Close), item, i++);
            }

            if (minimumDistance < double.MaxValue)
            {
                return result;
            }

            return null;
        }
コード例 #24
0
ファイル: StemSeries.cs プロジェクト: Cheesebaron/oxyplot
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            if (interpolate)
            {
                return null;
            }

            TrackerHitResult result = null;

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistance = double.MaxValue;
            var points = this.ActualPoints;

            for (int i = 0; i < points.Count; i++)
            {
                var p1 = points[i];
                var basePoint = new DataPoint(p1.X, this.Base);
                var sp1 = this.Transform(p1);
                var sp2 = this.Transform(basePoint);
                var u = ScreenPointHelper.FindPositionOnLine(point, sp1, sp2);

                if (double.IsNaN(u))
                {
                    continue;
                }

                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                var sp = sp1 + ((sp2 - sp1) * u);
                double distance = (point - sp).LengthSquared;

                if (distance < minimumDistance)
                {
                    result = new TrackerHitResult(
                        this, new DataPoint(p1.X, p1.Y), new ScreenPoint(sp1.x, sp1.y), this.GetItem(i));
                    minimumDistance = distance;
                }
            }

            return result;
        }
コード例 #25
0
ファイル: PlotView.cs プロジェクト: sami1971/oxyplot-xamarin
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="trackerHitResult">The tracker data.</param>
 public void ShowTracker(TrackerHitResult trackerHitResult)
 {
     // TODO
 }
コード例 #26
0
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            if (interpolate)
            {
                return(null);
            }

            double minimumDistance = double.MaxValue;

            TrackerHitResult result = null;
            Action <DataPoint, HighLowItem, int> check = (p, item, index) =>
            {
                var    sp = this.Transform(p);
                double dx = sp.x - point.x;
                double dy = sp.y - point.y;
                double d2 = (dx * dx) + (dy * dy);

                if (d2 < minimumDistance)
                {
                    result = new TrackerHitResult
                    {
                        Series    = this,
                        DataPoint = p,
                        Position  = sp,
                        Item      = item,
                        Index     = index,
                        Text      =
                            StringHelper.Format(
                                this.ActualCulture,
                                this.TrackerFormatString,
                                item,
                                this.Title,
                                this.XAxis.Title ?? DefaultXAxisTitle,
                                this.XAxis.GetValue(p.X),
                                this.YAxis.GetValue(item.High),
                                this.YAxis.GetValue(item.Low),
                                this.YAxis.GetValue(item.Open),
                                this.YAxis.GetValue(item.Close))
                    };

                    minimumDistance = d2;
                }
            };
            int i = 0;

            foreach (var item in this.items)
            {
                check(new DataPoint(item.X, item.High), item, i);
                check(new DataPoint(item.X, item.Low), item, i);
                check(new DataPoint(item.X, item.Open), item, i);
                check(new DataPoint(item.X, item.Close), item, i++);
            }

            if (minimumDistance < double.MaxValue)
            {
                return(result);
            }

            return(null);
        }
コード例 #27
0
ファイル: Plot.cs プロジェクト: aleksanderkobylak/oxyplot
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">
        /// The tracker data.
        /// </param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult != null)
            {
                var ts = trackerHitResult.Series as ITrackableSeries;
                var trackerTemplate = this.DefaultTrackerTemplate;
                if (ts != null && !string.IsNullOrEmpty(ts.TrackerKey))
                {
                    var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == ts.TrackerKey);
                    if (match != null)
                    {
                        trackerTemplate = match.TrackerTemplate;
                    }
                }

                var tracker = new ContentControl { Template = trackerTemplate };

                if (tracker != this.currentTracker)
                {
                    this.HideTracker();
                    if (trackerTemplate != null)
                    {
                        this.overlays.Children.Add(tracker);
                        this.currentTracker = tracker;
                    }
                }

                if (this.currentTracker != null)
                {
                    this.currentTracker.DataContext = trackerHitResult;
                }
            }
            else
            {
                this.HideTracker();
            }
        }
コード例 #28
0
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="interpolate">
        /// interpolate if set to <c>true</c> .
        /// </param>
        /// <returns>
        /// A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            TrackerHitResult result = null;

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistance = double.MaxValue;

            for (int i = 0; i + 1 < this.Points.Count; i++)
            {
                var p1 = this.Points[i];
                var p2 = this.Points[i + 1];
                var sp1 = this.Transform(p1.X, p1.Y);
                var sp2 = this.Transform(p2.X, p1.Y);

                double spdx = sp2.x - sp1.x;
                double spdy = sp2.y - sp1.y;
                double u1 = ((point.x - sp1.x) * spdx) + ((point.y - sp1.y) * spdy);
                double u2 = (spdx * spdx) + (spdy * spdy);
                double ds = (spdx * spdx) + (spdy * spdy);

                if (ds < 4)
                {
                    // if the points are very close, we can get numerical problems, just use the first point...
                    u1 = 0;
                    u2 = 1;
                }

                if (Math.Abs(u2) < double.Epsilon)
                {
                    continue; // P1 && P2 coincident
                }

                double u = u1 / u2;
                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                double sx = sp1.x + (u * spdx);
                double sy = sp1.y + (u * spdy);

                double dx = point.x - sx;
                double dy = point.y - sy;
                double distance = (dx * dx) + (dy * dy);

                if (distance < minimumDistance)
                {
                    double px = p1.X + (u * (p2.X - p1.X));
                    double py = p1.Y;
                    result = new TrackerHitResult(
                        this, new DataPoint(px, py), new ScreenPoint(sx, sy), this.GetItem(i), i);
                    minimumDistance = distance;
                }
            }

            return result;
        }
コード例 #29
0
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistanceSquared = 16 * 16;

            // snap to the nearest point
            var result = this.GetNearestPointInternal(this.ActualPoints, point);
            if (!interpolate && result != null && result.Position.DistanceToSquared(point) < minimumDistanceSquared)
            {
                return result;
            }

            result = null;

            // find the nearest point on the horizontal line segments
            int n = this.ActualPoints.Count;
            for (int i = 0; i < n; i++)
            {
                var p1 = this.ActualPoints[i];
                var p2 = this.ActualPoints[i + 1 < n ? i + 1 : i];
                var sp1 = this.Transform(p1.X, p1.Y);
                var sp2 = this.Transform(p2.X, p1.Y);

                double spdx = sp2.x - sp1.x;
                double spdy = sp2.y - sp1.y;
                double u1 = ((point.x - sp1.x) * spdx) + ((point.y - sp1.y) * spdy);
                double u2 = (spdx * spdx) + (spdy * spdy);
                double ds = (spdx * spdx) + (spdy * spdy);

                if (ds < 4)
                {
                    // if the points are very close, we can get numerical problems, just use the first point...
                    u1 = 0;
                    u2 = 1;
                }

                if (Math.Abs(u2) < double.Epsilon)
                {
                    continue; // P1 && P2 coincident
                }

                double u = u1 / u2;
                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                double sx = sp1.x + (u * spdx);
                double sy = sp1.y + (u * spdy);

                double dx = point.x - sx;
                double dy = point.y - sy;
                double distanceSquared = (dx * dx) + (dy * dy);

                if (distanceSquared < minimumDistanceSquared)
                {
                    double px = p1.X + (u * (p2.X - p1.X));
                    double py = p1.Y;
                    result = new TrackerHitResult(
                        this, new DataPoint(px, py), new ScreenPoint(sx, sy), this.GetItem(i), i);
                    minimumDistanceSquared = distanceSquared;
                }
            }

            return result;
        }
コード例 #30
0
ファイル: PlotView.cs プロジェクト: huoxudong125/oxyplot
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="data">The data.</param>
 public void ShowTracker(TrackerHitResult data)
 {
     if (this.trackerLabel == null)
     {
         // Holding the tracker label inside an EventBox allows
         // us to set the background color
         Gtk.EventBox labelHolder = new Gtk.EventBox();
         this.trackerLabel = new Gtk.Label();
         this.trackerLabel.SetPadding(3, 3);
         OxyColor bgColor = OxyColors.LightSkyBlue;
         labelHolder.ModifyBg(StateType.Normal, new Gdk.Color(bgColor.R, bgColor.G, bgColor.B));
         labelHolder.Add(this.trackerLabel);
         this.Add(labelHolder);
         labelHolder.ShowAll();
     }
     this.trackerLabel.Parent.Visible = true;
     this.trackerLabel.Text = data.ToString();
     Gtk.Requisition req = this.trackerLabel.Parent.SizeRequest();
     int xPos = (int)data.Position.X - req.Width / 2;
     int yPos = (int)data.Position.Y - req.Height;
     xPos = Math.Max(0, Math.Min(xPos, this.Allocation.Width - req.Width));
     yPos = Math.Max(0, Math.Min(yPos, this.Allocation.Height - req.Height));
     this.Move(trackerLabel.Parent, xPos, yPos);
 }
コード例 #31
0
ファイル: PlotView.cs プロジェクト: Celderon/oxyplot
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="data">The data.</param>
 public void ShowTracker(TrackerHitResult data)
 {
     // not implemented for GtkSharp
 }
コード例 #32
0
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="trackerHitResult">The tracker data.</param>
 public void ShowTracker(TrackerHitResult trackerHitResult)
 {
     // TODO: how to show a tracker on iOS
     // the tracker must be moved away from the finger...
 }
コード例 #33
0
ファイル: BoxPlotSeries.cs プロジェクト: Keyabob/MMG
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            double minimumDistance = double.MaxValue;
            TrackerHitResult result = null;
            foreach (var item in this.ActualItems)
            {
                foreach (var outlier in item.Outliers)
                {
                    var sp = this.Transform(item.X, outlier);
                    double d = (sp - point).LengthSquared;
                    if (d < minimumDistance)
                    {
                        result = new TrackerHitResult
                        {
                            Series = this,
                            DataPoint = new DataPoint(item.X, outlier),
                            Position = sp,
                            Item = item,
                            Text =
                                StringHelper.Format(
                                    this.ActualCulture,
                                    this.OutlierTrackerFormatString,
                                    item,
                                    this.Title,
                                    this.XAxis.Title ?? DefaultXAxisTitle,
                                    this.XAxis.GetValue(item.X),
                                    outlier)
                        };
                        minimumDistance = d;
                    }
                }

                var hitPoint = DataPoint.Undefined;

                // check if we are inside the box rectangle
                var rect = this.GetBoxRect(item);
                if (rect.Contains(point))
                {
                    hitPoint = new DataPoint(item.X, this.YAxis.InverseTransform(point.Y));
                    minimumDistance = 0;
                }

                var topWhisker = this.Transform(item.X, item.UpperWhisker);
                var bottomWhisker = this.Transform(item.X, item.LowerWhisker);

                // check if we are near the line
                var p = ScreenPointHelper.FindPointOnLine(point, topWhisker, bottomWhisker);
                double d2 = (p - point).LengthSquared;
                if (d2 < minimumDistance)
                {
                    hitPoint = this.InverseTransform(p);
                    minimumDistance = d2;
                }

                if (hitPoint.IsDefined())
                {
                    result = new TrackerHitResult
                    {
                        Series = this,
                        DataPoint = hitPoint,
                        Position = this.Transform(hitPoint),
                        Item = item,
                        Text =
                            StringHelper.Format(
                                this.ActualCulture,
                                this.TrackerFormatString,
                                item,
                                this.Title,
                                this.XAxis.Title ?? DefaultXAxisTitle,
                                this.XAxis.GetValue(item.X),
                                this.YAxis.GetValue(item.UpperWhisker),
                                this.YAxis.GetValue(item.BoxTop),
                                this.YAxis.GetValue(item.Median),
                                this.YAxis.GetValue(item.BoxBottom),
                                this.YAxis.GetValue(item.LowerWhisker),
                                this.YAxis.GetValue(item.Mean))
                    };
                }
            }

            if (minimumDistance < double.MaxValue)
            {
                return result;
            }

            return null;
        }
コード例 #34
0
ファイル: HighLowSeries.cs プロジェクト: Cheesebaron/oxyplot
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            if (interpolate)
            {
                return null;
            }

            double minimumDistance = double.MaxValue;
            var result = new TrackerHitResult(this, DataPoint.Undefined, ScreenPoint.Undefined);

            Action<DataPoint, HighLowItem, int> check = (p, item, index) =>
                {
                    var sp = this.Transform(p);
                    double dx = sp.x - point.x;
                    double dy = sp.y - point.y;
                    double d2 = (dx * dx) + (dy * dy);

                    if (d2 < minimumDistance)
                    {
                        result.DataPoint = p;
                        result.Position = sp;
                        result.Item = item;
                        result.Index = index;
                        if (this.TrackerFormatString != null)
                        {
                            result.Text = this.Format(
                                this.TrackerFormatString,
                                item,
                                this.Title,
                                this.XAxis.GetValue(p.X),
                                item.High,
                                item.Low,
                                item.Open,
                                item.Close);
                        }

                        minimumDistance = d2;
                    }
                };
            int i = 0;
            foreach (var item in this.items)
            {
                check(new DataPoint(item.X, item.High), item, i);
                check(new DataPoint(item.X, item.Low), item, i);
                check(new DataPoint(item.X, item.Open), item, i);
                check(new DataPoint(item.X, item.Close), item, i++);
            }

            if (minimumDistance < double.MaxValue)
            {
                return result;
            }

            return null;
        }
コード例 #35
0
ファイル: PlotView.cs プロジェクト: trinnguyen/oxyplot-xammac
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="trackerHitResult">The tracker data.</param>
 public void ShowTracker(TrackerHitResult trackerHitResult)
 {
     // TODO
 }
コード例 #36
0
ファイル: BoxPlotSeries.cs プロジェクト: hcoona/OneDotNet
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            double           minimumDistance = double.MaxValue;
            TrackerHitResult result          = null;

            foreach (var item in this.ActualItems)
            {
                foreach (var outlier in item.Outliers)
                {
                    var    sp = this.Transform(item.X, outlier);
                    double d  = (sp - point).LengthSquared;
                    if (d < minimumDistance)
                    {
                        result = new TrackerHitResult
                        {
                            Series    = this,
                            DataPoint = new DataPoint(item.X, outlier),
                            Position  = sp,
                            Item      = item,
                            Text      =
                                StringHelper.Format(
                                    this.ActualCulture,
                                    this.OutlierTrackerFormatString,
                                    item,
                                    this.Title,
                                    this.XAxis.Title ?? DefaultXAxisTitle,
                                    this.XAxis.GetValue(item.X),
                                    outlier)
                        };
                        minimumDistance = d;
                    }
                }

                var hitPoint = DataPoint.Undefined;

                // check if we are inside the box rectangle
                var rect = this.GetBoxRect(item);
                if (rect.Contains(point))
                {
                    hitPoint        = new DataPoint(item.X, this.YAxis.InverseTransform(point.Y));
                    minimumDistance = 0;
                }

                var topWhisker    = this.Transform(item.X, item.UpperWhisker);
                var bottomWhisker = this.Transform(item.X, item.LowerWhisker);

                // check if we are near the line
                var    p  = ScreenPointHelper.FindPointOnLine(point, topWhisker, bottomWhisker);
                double d2 = (p - point).LengthSquared;
                if (d2 < minimumDistance)
                {
                    hitPoint        = this.InverseTransform(p);
                    minimumDistance = d2;
                }

                if (hitPoint.IsDefined())
                {
                    result = new TrackerHitResult
                    {
                        Series    = this,
                        DataPoint = hitPoint,
                        Position  = this.Transform(hitPoint),
                        Item      = item,
                        Text      =
                            StringHelper.Format(
                                this.ActualCulture,
                                this.TrackerFormatString,
                                item,
                                this.Title,
                                this.XAxis.Title ?? DefaultXAxisTitle,
                                this.XAxis.GetValue(item.X),
                                this.YAxis.GetValue(item.UpperWhisker),
                                this.YAxis.GetValue(item.BoxTop),
                                this.YAxis.GetValue(item.Median),
                                this.YAxis.GetValue(item.BoxBottom),
                                this.YAxis.GetValue(item.LowerWhisker),
                                this.YAxis.GetValue(item.Mean))
                    };
                }
            }

            if (minimumDistance < double.MaxValue)
            {
                return(result);
            }

            return(null);
        }
コード例 #37
0
ファイル: StairStepSeries.cs プロジェクト: ywscr/oxyplot
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistanceSquared = 16 * 16;

            // snap to the nearest point
            var result = this.GetNearestPointInternal(this.ActualPoints, point);

            if (!interpolate && result != null && result.Position.DistanceToSquared(point) < minimumDistanceSquared)
            {
                result.Text = StringHelper.Format(
                    this.ActualCulture,
                    this.TrackerFormatString,
                    result.Item,
                    this.Title,
                    this.XAxis.Title ?? XYAxisSeries.DefaultXAxisTitle,
                    this.XAxis.GetValue(result.DataPoint.X),
                    this.YAxis.Title ?? XYAxisSeries.DefaultYAxisTitle,
                    this.YAxis.GetValue(result.DataPoint.Y));
                return(result);
            }

            result = null;

            // find the nearest point on the horizontal line segments
            int n = this.ActualPoints.Count;

            for (int i = 0; i < n; i++)
            {
                var p1  = this.ActualPoints[i];
                var p2  = this.ActualPoints[i + 1 < n ? i + 1 : i];
                var sp1 = this.Transform(p1.X, p1.Y);
                var sp2 = this.Transform(p2.X, p1.Y);

                double spdx = sp2.x - sp1.x;
                double spdy = sp2.y - sp1.y;
                double u1   = ((point.x - sp1.x) * spdx) + ((point.y - sp1.y) * spdy);
                double u2   = (spdx * spdx) + (spdy * spdy);
                double ds   = (spdx * spdx) + (spdy * spdy);

                if (ds < 4)
                {
                    // if the points are very close, we can get numerical problems, just use the first point...
                    u1 = 0;
                    u2 = 1;
                }

                if (Math.Abs(u2) < double.Epsilon)
                {
                    continue; // P1 && P2 coincident
                }

                double u = u1 / u2;
                if (u < 0 || u > 1)
                {
                    continue; // outside line
                }

                double sx = sp1.x + (u * spdx);
                double sy = sp1.y + (u * spdy);

                double dx = point.x - sx;
                double dy = point.y - sy;
                double distanceSquared = (dx * dx) + (dy * dy);

                if (distanceSquared < minimumDistanceSquared)
                {
                    double px   = p1.X + (u * (p2.X - p1.X));
                    double py   = p1.Y;
                    var    item = this.GetItem(i);
                    result = new TrackerHitResult
                    {
                        Series    = this,
                        DataPoint = new DataPoint(px, py),
                        Position  = new ScreenPoint(sx, sy),
                        Item      = item,
                        Index     = i,
                        Text      = StringHelper.Format(this.ActualCulture, this.TrackerFormatString, item, this.Title, this.XAxis.Title ?? DefaultXAxisTitle, this.XAxis.GetValue(px), this.YAxis.Title ?? DefaultYAxisTitle, this.YAxis.GetValue(py))
                    };
                    minimumDistanceSquared = distanceSquared;
                }
            }

            return(result);
        }
コード例 #38
0
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">
        /// The point.
        /// </param>
        /// <param name="interpolate">
        /// interpolate if set to <c>true</c> .
        /// </param>
        /// <returns>
        /// A TrackerHitResult for the current hit.
        /// </returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            if (interpolate)
            {
                return null;
            }

            TrackerHitResult result = null;
            double minimumDistance = double.MaxValue;
            int i = 0;

            var xaxisTitle = this.XAxis.Title ?? "X";
            var yaxisTitle = this.YAxis.Title ?? "Y";
            var colorAxisTitle = (this.ColorAxis != null ? this.ColorAxis.Title : null) ?? "Z";

            var formatString = TrackerFormatString;
            if (string.IsNullOrEmpty(this.TrackerFormatString))
            {
                // Create a default format string
                formatString = "{1}: {2}\n{3}: {4}";
                if (this.ColorAxis != null)
                {
                    formatString += "\n{5}: {6}";
                }
            }

            foreach (var p in this.Points)
            {
                if (p.X < this.XAxis.ActualMinimum || p.X > this.XAxis.ActualMaximum || p.Y < this.YAxis.ActualMinimum || p.Y > this.YAxis.ActualMaximum)
                {
                    i++;
                    continue;
                }

                var dp = new DataPoint(p.X, p.Y);
                var sp = Axis.Transform(dp, this.XAxis, this.YAxis);
                double dx = sp.x - point.x;
                double dy = sp.y - point.y;
                double d2 = (dx * dx) + (dy * dy);

                if (d2 < minimumDistance)
                {
                    var item = this.GetItem(i);

                    object xvalue = this.XAxis.GetValue(dp.X);
                    object yvalue = this.YAxis.GetValue(dp.Y);
                    object zvalue = null;

                    var scatterPoint = p as ScatterPoint;
                    if (scatterPoint != null)
                    {
                        if (!double.IsNaN(scatterPoint.Value) && !double.IsInfinity(scatterPoint.Value))
                        {
                            zvalue = scatterPoint.Value;
                        }
                    }

                    var text = StringHelper.Format(
                        this.ActualCulture,
                        formatString,
                        item,
                        this.Title,
                        xaxisTitle,
                        xvalue,
                        yaxisTitle,
                        yvalue,
                        colorAxisTitle,
                        zvalue);

                    result = new TrackerHitResult(this, dp, sp, item, i, text);

                    minimumDistance = d2;
                }

                i++;
            }

            return result;
        }
コード例 #39
0
ファイル: BoxPlotSeries.cs プロジェクト: Cheesebaron/oxyplot
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            double minimumDistance = double.MaxValue;
            var result = new TrackerHitResult(this, DataPoint.Undefined, ScreenPoint.Undefined);
            foreach (var item in this.Items)
            {
                foreach (var outlier in item.Outliers)
                {
                    var sp = this.Transform(item.X, outlier);
                    double d = (sp - point).LengthSquared;
                    if (d < minimumDistance)
                    {
                        result.DataPoint = new DataPoint(item.X, outlier);
                        result.Position = sp;
                        result.Item = item;
                        result.Text = this.Format(
                            this.OutlierTrackerFormatString,
                            item,
                            this.Title,
                            this.XAxis.GetValue(result.DataPoint.X),
                            outlier);
                        minimumDistance = d;
                    }
                }

                // check if we are inside the box rectangle
                var rect = this.GetBoxRect(item);
                if (rect.Contains(point))
                {
                    result.DataPoint = new DataPoint(item.X, this.YAxis.InverseTransform(point.Y));
                    result.Position = this.Transform(result.DataPoint);
                    result.Item = item;

                    result.Text = this.Format(
                        this.TrackerFormatString,
                        item,
                        this.Title,
                        this.XAxis.GetValue(result.DataPoint.X),
                        item.UpperWhisker,
                        item.BoxTop,
                        item.Median,
                        item.BoxBottom,
                        item.LowerWhisker);

                    minimumDistance = 0;
                }

                var topWhisker = this.Transform(item.X, item.UpperWhisker);
                var bottomWhisker = this.Transform(item.X, item.LowerWhisker);

                // check if we are near the line
                var p = ScreenPointHelper.FindPointOnLine(point, topWhisker, bottomWhisker);
                double d2 = (p - point).LengthSquared;
                if (d2 < minimumDistance)
                {
                    result.DataPoint = this.InverseTransform(p);
                    result.Position = this.Transform(result.DataPoint);
                    result.Item = item;
                    result.Text = this.Format(
                        this.TrackerFormatString,
                        item,
                        this.Title,
                        this.XAxis.GetValue(result.DataPoint.X),
                        item.UpperWhisker,
                        item.BoxTop,
                        item.Median,
                        item.BoxBottom,
                        item.LowerWhisker);
                    minimumDistance = d2;
                }
            }

            if (minimumDistance < double.MaxValue)
            {
                return result;
            }

            return null;
        }
コード例 #40
0
ファイル: PlotView.cs プロジェクト: oxyplot/oxyplot-xwt
 /// <summary>
 /// Hides the tracker.
 /// </summary>
 public virtual void HideTracker()
 {
     lock (trackerLock)
     {
         actualTrackerHitResult = null;
     }
     QueueDraw();
 }
コード例 #41
0
ファイル: StemSeries.cs プロジェクト: olga-ivanova-me/oxyplot
        /// <summary>
        /// Gets the point on the series that is nearest the specified point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">Interpolate the series if this flag is set to <c>true</c>.</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return null;
            }

            if (interpolate)
            {
                return null;
            }

            TrackerHitResult result = null;

            // http://paulbourke.net/geometry/pointlineplane/
            double minimumDistance = double.MaxValue;
            var points = this.ActualPoints;

            for (int i = 0; i < points.Count; i++)
            {
                var p1 = points[i];
                var basePoint = new DataPoint(p1.X, this.Base);
                var sp1 = this.Transform(p1);
                var sp2 = this.Transform(basePoint);
                var u = ScreenPointHelper.FindPositionOnLine(point, sp1, sp2);

                if (double.IsNaN(u))
                {
                    u = 1; // we are a tiny line, snap to the end
                }

                if (u < 0 || u > 1)
                {
                    u = 1; // we are outside the line, snap to the end
                }

                var sp = sp1 + ((sp2 - sp1) * u);
                double distance = (point - sp).LengthSquared;

                if (distance < minimumDistance)
                {
                    var item = this.GetItem(i);
                    result = new TrackerHitResult
                    {
                        Series = this,
                        DataPoint = new DataPoint(p1.X, p1.Y),
                        Position = new ScreenPoint(sp1.x, sp1.y),
                        Item = this.GetItem(i),
                        Index = i,
                        Text =
                            StringHelper.Format(
                                this.ActualCulture,
                                this.TrackerFormatString,
                                item,
                                this.Title,
                                this.XAxis.Title ?? XYAxisSeries.DefaultXAxisTitle,
                                this.XAxis.GetValue(p1.X),
                                this.YAxis.Title ?? XYAxisSeries.DefaultYAxisTitle,
                                this.YAxis.GetValue(p1.Y))
                    };
                    minimumDistance = distance;
                }
            }

            return result;
        }
コード例 #42
0
ファイル: PlotView.cs プロジェクト: huoxudong125/oxyplot
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">The tracker data.</param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult == null)
            {
                this.HideTracker();
                return;
            }

            var trackerTemplate = this.DefaultTrackerTemplate;
            if (trackerHitResult.Series != null && !string.IsNullOrEmpty(trackerHitResult.Series.TrackerKey))
            {
                var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == trackerHitResult.Series.TrackerKey);
                if (match != null)
                {
                    trackerTemplate = match.TrackerTemplate;
                }
            }

            if (trackerTemplate == null)
            {
                this.HideTracker();
                return;
            }

            var tracker = new ContentControl { Template = trackerTemplate };

            if (tracker != this.currentTracker)
            {
                this.HideTracker();
                this.plotImage.Overlay.Children.Add(tracker);
                this.currentTracker = tracker;
            }

            if (this.currentTracker != null)
            {
                this.currentTracker.DataContext = trackerHitResult;
            }
        }
コード例 #43
0
ファイル: PlotView.cs プロジェクト: Cheesebaron/oxyplot
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="trackerHitResult">The tracker data.</param>
        public void ShowTracker(TrackerHitResult trackerHitResult)
        {
            if (trackerHitResult == null)
            {
                this.HideTracker();
                return;
            }

            var ts = trackerHitResult.Series as ITrackableSeries;
            var trackerTemplate = this.DefaultTrackerTemplate;
            if (ts != null && !string.IsNullOrEmpty(ts.TrackerKey))
            {
                var match = this.TrackerDefinitions.FirstOrDefault(t => t.TrackerKey == ts.TrackerKey);
                if (match != null)
                {
                    trackerTemplate = match.TrackerTemplate;
                }
            }

            if (trackerTemplate == null)
            {
                this.HideTracker();
                return;
            }

            var tracker = new ContentControl { Template = trackerTemplate };

            // ReSharper disable once RedundantNameQualifier
            if (!object.ReferenceEquals(tracker, this.currentTracker))
            {
                this.HideTracker();
                this.overlays.Children.Add(tracker);
                this.currentTracker = tracker;
            }

            if (this.currentTracker != null)
            {
                this.currentTracker.DataContext = trackerHitResult;
            }
        }
コード例 #44
0
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            if (interpolate)
            {
                return(null);
            }

            TrackerHitResult result          = null;
            double           minimumDistance = double.MaxValue;
            int i = 0;

            var xaxisTitle     = this.XAxis.Title ?? DefaultXAxisTitle;
            var yaxisTitle     = this.YAxis.Title ?? DefaultYAxisTitle;
            var colorAxisTitle = (this.ColorAxis != null ? ((Axis)this.ColorAxis).Title : null) ?? DefaultColorAxisTitle;

            foreach (var p in this.ActualPointsList)
            {
                if (p.X < this.XAxis.ActualMinimum || p.X > this.XAxis.ActualMaximum || p.Y < this.YAxis.ActualMinimum || p.Y > this.YAxis.ActualMaximum)
                {
                    i++;
                    continue;
                }

                var    sp = this.XAxis.Transform(p.X, p.Y, this.YAxis);
                double dx = sp.x - point.x;
                double dy = sp.y - point.y;
                double d2 = (dx * dx) + (dy * dy);

                if (d2 < minimumDistance)
                {
                    var item = this.GetItem(i) ?? p;

                    object zvalue = null;

                    if (!double.IsNaN(p.Value) && !double.IsInfinity(p.Value))
                    {
                        zvalue = p.Value;
                    }

                    result = new TrackerHitResult
                    {
                        Series    = this,
                        DataPoint = new DataPoint(p.X, p.Y),
                        Position  = sp,
                        Item      = item,
                        Index     = i,
                        Text      =
                            StringHelper.Format(
                                this.ActualCulture,
                                this.TrackerFormatString,
                                item,
                                this.Title,
                                xaxisTitle,
                                this.XAxis.GetValue(p.X),
                                yaxisTitle,
                                this.YAxis.GetValue(p.Y),
                                colorAxisTitle,
                                zvalue),
                    };

                    minimumDistance = d2;
                }

                i++;
            }

            return(result);
        }
コード例 #45
0
        /// <summary>
        /// Gets the nearest point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="interpolate">interpolate if set to <c>true</c> .</param>
        /// <returns>A TrackerHitResult for the current hit.</returns>
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            if (interpolate)
            {
                return(null);
            }

            TrackerHitResult result          = null;
            double           minimumDistance = double.MaxValue;
            int i = 0;

            var xaxisTitle     = this.XAxis.Title ?? "X";
            var yaxisTitle     = this.YAxis.Title ?? "Y";
            var colorAxisTitle = (this.ColorAxis != null ? ((Axis)this.ColorAxis).Title : null) ?? "Z";

            var formatString = this.TrackerFormatString;

            if (string.IsNullOrEmpty(this.TrackerFormatString))
            {
                // Create a default format string
                formatString = "{1}: {2}\n{3}: {4}";
                if (this.ColorAxis != null)
                {
                    formatString += "\n{5}: {6}";
                }
            }

            foreach (var p in this.ActualPoints)
            {
                if (p.X < this.XAxis.ActualMinimum || p.X > this.XAxis.ActualMaximum || p.Y < this.YAxis.ActualMinimum || p.Y > this.YAxis.ActualMaximum)
                {
                    i++;
                    continue;
                }

                var    sp = this.XAxis.Transform(p.X, p.Y, this.YAxis);
                double dx = sp.x - point.x;
                double dy = sp.y - point.y;
                double d2 = (dx * dx) + (dy * dy);

                if (d2 < minimumDistance)
                {
                    var item = this.GetItem(i) ?? p;

                    object xvalue = this.XAxis.GetValue(p.X);
                    object yvalue = this.YAxis.GetValue(p.Y);
                    object zvalue = null;

                    if (!double.IsNaN(p.Value) && !double.IsInfinity(p.Value))
                    {
                        zvalue = p.Value;
                    }

                    var text = this.Format(
                        formatString,
                        item,
                        this.Title,
                        xaxisTitle,
                        xvalue,
                        yaxisTitle,
                        yvalue,
                        colorAxisTitle,
                        zvalue);

                    result = new TrackerHitResult(this, new DataPoint(p.X, p.Y), sp, item, i, text);

                    minimumDistance = d2;
                }

                i++;
            }

            return(result);
        }
コード例 #46
0
ファイル: PlotView.cs プロジェクト: choenden/oxyplot
 /// <summary>
 /// Shows the tracker.
 /// </summary>
 /// <param name="data">The data.</param>
 public void ShowTracker(TrackerHitResult data)
 {
     // not implemented for GtkSharp
 }
コード例 #47
0
ファイル: Plot.cs プロジェクト: jwolfm98/HardwareMonitor
 /// <summary>
 /// The show tracker.
 /// </summary>
 /// <param name="data">
 /// The data.
 /// </param>
 public void ShowTracker(TrackerHitResult data)
 {
     // not implemented for WindowsForms
 }
コード例 #48
0
        public override TrackerHitResult GetNearestPoint(ScreenPoint point, bool interpolate)
        {
            if (this.XAxis == null || this.YAxis == null)
            {
                return(null);
            }

            if (interpolate)
            {
                return(null);
            }

            TrackerHitResult result          = null;
            double           minimumDistance = double.MaxValue;
            int i = 0;

            var xaxisTitle     = this.XAxis.Title ?? "X";
            var yaxisTitle     = this.YAxis.Title ?? "Y";
            var colorAxisTitle = (this.ColorAxis != null ? this.ColorAxis.Title : null) ?? "Z";

            var formatString = TrackerFormatString;

            if (string.IsNullOrEmpty(this.TrackerFormatString))
            {
                // Create a default format string
                formatString = "{1}: {2}\n{3}: {4}";
                if (this.ColorAxis != null)
                {
                    formatString += "\n{5}: {6}";
                }
            }

            foreach (var p in this.Points)
            {
                if (this.XAxis == null || this.YAxis == null || p.X < this.XAxis.ActualMinimum || p.X > this.XAxis.ActualMaximum || p.Y < this.YAxis.ActualMinimum ||
                    p.Y > this.YAxis.ActualMaximum)
                {
                    i++;
                    continue;
                }

                var    dp = new DataPoint(p.X, p.Y);
                var    sp = Axis.Transform(dp, this.XAxis, this.YAxis);
                double dx = sp.X - point.X;
                double dy = sp.Y - point.Y;
                double d2 = (dx * dx) + (dy * dy);

                if (d2 < minimumDistance)
                {
                    var item = this.GetItem(i);
                    result = new TrackerHitResult(this, dp, sp, item);

                    object xvalue = this.XAxis != null?this.XAxis.GetValue(dp.X) : dp.X;

                    object yvalue = this.YAxis != null?this.YAxis.GetValue(dp.Y) : dp.Y;

                    object zvalue = null;

                    var scatterPoint = p as ScatterPoint;
                    if (scatterPoint != null)
                    {
                        if (!double.IsNaN(scatterPoint.Value) && !double.IsInfinity(scatterPoint.Value))
                        {
                            zvalue = scatterPoint.Value;
                        }
                    }

                    //result.Text = StringHelper.Format(
                    //	this.ActualCulture,
                    //	formatString,
                    //	item,
                    //	this.Title,
                    //	xaxisTitle,
                    //	xvalue,
                    //	yaxisTitle,
                    //	yvalue,
                    //	colorAxisTitle,
                    //	zvalue);

                    var rdp = p as BrainDataPoint;

                    if (rdp != null)
                    {
                        result.Text = rdp.ROI.Name;
                    }

                    minimumDistance = d2;
                }

                i++;
            }

            return(result);
        }
コード例 #49
0
ファイル: PlotView.cs プロジェクト: benjaminrupp/oxyplot
        /// <summary>
        /// Shows the tracker.
        /// </summary>
        /// <param name="data">The data.</param>
        public void ShowTracker(TrackerHitResult data)
        {
            if (this.trackerLabel == null)
            {
                this.trackerLabel = new Label { Parent = this, BackColor = Color.LightSkyBlue, AutoSize = true };
            }

            this.trackerLabel.Text = data.ToString();
            this.trackerLabel.Top = (int)data.Position.Y - this.Top;
            this.trackerLabel.Left = (int)data.Position.X - this.Left;
            this.trackerLabel.Visible = true;
        }