/// <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 = StringHelper.Format( this.ActualCulture, this.TrackerFormatString, null, this.Title, xaxisTitle, r.DataPoint.X, yaxisTitle, r.DataPoint.Y, zaxisTitle, c.ContourLevel); } } } return(result); }
/// <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); }
/// <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); }
/// <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://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ 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); }
/// <summary> /// Raises the TrackerChanged event. /// </summary> /// <param name="result">The result.</param> /// <remarks> /// This method is public so custom implementations of tracker manipulators can invoke this method. /// </remarks> public void RaiseTrackerChanged(TrackerHitResult result) { var handler = this.TrackerChanged; if (handler != null) { var args = new TrackerEventArgs { HitResult = result }; handler(this, args); } }
/// <summary> /// Raises the TrackerChanged event. /// </summary> /// <param name="result">The result.</param> protected internal virtual void OnTrackerChanged(TrackerHitResult result) { var handler = this.TrackerChanged; if (handler != null) { var args = new TrackerEventArgs { HitResult = result }; handler(this, args); } }
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); }
/// <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); } TrackerHitResult result = null; // http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ double minimumDistance = double.MaxValue; var points = this.Points; 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); }
/// <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); } }
/// <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) { 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 = StringHelper.Format( this.ActualCulture, this.OutlierTrackerFormatString, item, this.Title, 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 = StringHelper.Format( this.ActualCulture, this.TrackerFormatString, item, this.Title, 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 = StringHelper.Format( this.ActualCulture, this.TrackerFormatString, item, this.Title, result.DataPoint.X, item.UpperWhisker, item.BoxTop, item.Median, item.BoxBottom, item.LowerWhisker); minimumDistance = d2; } } if (minimumDistance < double.MaxValue) { return(result); } return(null); }
/// <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; }
/// <summary> /// The show tracker. /// </summary> /// <param name="data"> /// The data. /// </param> public void ShowTracker(TrackerHitResult data) { // not implemented for WindowsForms }
/// <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.trackerLabel.Left = (int)data.Position.X; this.trackerLabel.Visible = true; }
/// <summary> /// Raises the TrackerChanged event. /// </summary> /// <param name="result">The result.</param> protected internal virtual void OnTrackerChanged(TrackerHitResult result) { this.RaiseTrackerChanged(result); }
/// <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; } TrackerHitResult result = null; // http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ double minimumDistance = double.MaxValue; var points = this.Points; 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; }
public void HideTracker() { _tracker = null; _se.Refresh(); }
/// <summary> /// Shows the tracker. /// </summary> /// <param name="trackerHitResult">The tracker data.</param> public void ShowTracker(TrackerHitResult trackerHitResult) { }
/// <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... }
/// <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 (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); minimumDistance = d2; } i++; } return(result); }
public void ShowTracker(TrackerHitResult trackerHitResult) { _tracker = trackerHitResult; _se.Refresh(); }
/// <summary> /// Override it to add a custom tooltip to the chart's tracker /// </summary> protected virtual string GetCustomTooltip(TrackerHitResult hitTestResult) { return string.Empty; }
/// <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) { 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 = StringHelper.Format( this.ActualCulture, this.OutlierTrackerFormatString, item, this.Title, 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 = StringHelper.Format( this.ActualCulture, this.TrackerFormatString, item, this.Title, 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 = StringHelper.Format( this.ActualCulture, this.TrackerFormatString, item, this.Title, result.DataPoint.X, item.UpperWhisker, item.BoxTop, item.Median, item.BoxBottom, item.LowerWhisker); minimumDistance = d2; } } if (minimumDistance < double.MaxValue) { return result; } return null; }
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; }