private void UpdateUIRepresentation() { if (Plotter == null) { return; } PointsGraphBase source = this.PointSource; if (source == null || (source != null && source.VisiblePoints == null)) { SetValue(MarkerPositionPropertyKey, new Point(Double.NaN, Double.NaN)); marker.Visibility = Visibility.Hidden; return; } else { Point mousePos = Mouse.GetPosition(Plotter.CentralGrid); var transform = Plotter.Transform; Point viewportPos = mousePos.ScreenToViewport(transform); double x = viewportPos.X; searchResult = searcher.SearchXBetween(x, searchResult); SetValue(ClosestPointIndexPropertyKey, searchResult.Index); if (!searchResult.IsEmpty) { marker.Visibility = Visibility.Visible; IList <Point> points = source.VisiblePoints; Point ptBefore = points[searchResult.Index]; Point ptAfter = points[searchResult.Index + 1]; double ratio = (x - ptBefore.X) / (ptAfter.X - ptBefore.X); double y = ptBefore.Y + (ptAfter.Y - ptBefore.Y) * ratio; Point temp = new Point(x, y); SetX(marker, temp.X); SetY(marker, temp.Y); Point markerPosition = temp; followDataContext.Position = markerPosition; SetValue(MarkerPositionPropertyKey, markerPosition); } else { SetValue(MarkerPositionPropertyKey, new Point(Double.NaN, Double.NaN)); marker.Visibility = Visibility.Hidden; } } }
/// <summary> /// Generates ticks for given range and preferred ticks count. /// </summary> /// <param name="range">The range.</param> /// <param name="ticksCount">The ticks count.</param> /// <returns></returns> public ITicksInfo <TAxis> GetTicks(Range <TAxis> range, int ticksCount) { EnsureSearcher(); //minResult = searcher.SearchBetween(range.Min, minResult); //maxResult = searcher.SearchBetween(range.Max, maxResult); minResult = searcher.SearchFirstLess(range.Min); maxResult = searcher.SearchGreater(range.Max); if (!(minResult.IsEmpty && maxResult.IsEmpty)) { int startIndex = !minResult.IsEmpty ? minResult.Index : 0; int endIndex = !maxResult.IsEmpty ? maxResult.Index : collection.Count - 1; int count = endIndex - startIndex + 1; TAxis[] ticks = new TAxis[count]; for (int i = startIndex; i <= endIndex; i++) { ticks[i - startIndex] = axisMapping(collection[i]); } TicksInfo <TAxis> result = new TicksInfo <TAxis> { Info = startIndex, TickSizes = ArrayExtensions.CreateArray(count, 1.0), Ticks = ticks }; return(result); } else { return(TicksInfo <TAxis> .Empty); } }