private void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e) { if (e.PropertyName == "Visible") { DataRect currVisible = (DataRect)e.NewValue; if (increasedVisible.Contains(currVisible)) { var increasedSquare = increasedVisible.GetSquare(); if (increasedSquare > 0) { var squareRatio = increasedSquare / currVisible.GetSquare(); if (2 < squareRatio && squareRatio < 6) { // keeping old value of increasedVisible return; } } } increasedVisible = currVisible.ZoomOutFromCenter(2.0); chart.OnReset(); } else if (e.PropertyName == "Output") { chart.OnReset(); } }
private void CheckPosAgainstData(PositionAndCheckDistance currentPos) { IEnumerable <(Point start, Point end, string label)> lines = null; IEnumerable <(Point start, Point end, string label)> rectangles = null; Dispatcher.Invoke(() => { lines = NearestVisualSources.OfType <NearestLineSource>().Select(nsl => nsl.ItemsSource).Where(items => items != null).SelectMany(x => x).ToList(); rectangles = NearestVisualSources.OfType <NearestRectangleSource>().Select(nsl => nsl.ItemsSource).Where(items => items != null).SelectMany(x => x).ToList(); }); Point dataPosition = currentPos.DataPosition; Point screenPosition = currentPos.ScreenPosition; Point dataBottomLeft = currentPos.DataBottomLeft; Point dataTopRight = currentPos.DataTopRight; double?minDistance = currentPos.ScreenDistance.X; string closestLine = null; Point? closestScreenPoint = null; // First see if mouse is inside one of the rectangles foreach (var rectangle in rectangles) { DataRect dataRect = new DataRect(rectangle.start, rectangle.end); if (dataRect.Contains(dataPosition)) { minDistance = 0; closestScreenPoint = screenPosition; closestLine = rectangle.label; break; } } if (!closestScreenPoint.HasValue) { // Get the rectangle sides var rectangleLines = rectangles.Select(rect => { return(new[] { (rect.start, new Point(rect.start.X, rect.end.Y), rect.label), (new Point(rect.start.X, rect.end.Y), rect.end, rect.label), (rect.end, new Point(rect.end.X, rect.start.Y), rect.label), (new Point(rect.end.X, rect.start.Y), rect.start, rect.label) });
protected internal override IEnumerable<Point> Filter(IEnumerable<Point> series) { prevOutput = Output; var visible = Visible; prevVisible = visible; bounds = DataRect.FromCenterSize(visible.GetCenter(), new Size(visible.Width * visibleIncreaseRatio, visible.Height * visibleIncreaseRatio)); //IParallelEnumerable<Point> parallel = (IParallelEnumerable<Point>)series; //Trace.WriteLine("In BoundsFilter: " + Environment.TickCount); IEnumerable<Point> result; if (Environment.FirstDraw) result = series; else result = series.Where(p => bounds.Contains(p)); return result; }
public static Range <double> GetMinMax(this IDataSource2D <double> dataSource, DataRect area) { if (dataSource == null) { throw new ArgumentNullException("dataSource"); } double min = Double.PositiveInfinity; double max = Double.NegativeInfinity; int width = dataSource.Width; int height = dataSource.Height; var grid = dataSource.Grid; var data = dataSource.Data; for (int ix = 0; ix < width; ix++) { for (int iy = 0; iy < height; iy++) { if (area.Contains(grid[ix, iy])) { var value = data[ix, iy]; if (value < min) { min = value; } if (value > max) { max = value; } } } } if (min < max) { return(new Range <double>(min, max)); } else { return(new Range <double>()); } }
private void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e) { var transform = plotter.Viewport.Transform; double prevLevel = tileProvider.Level; UpdateLevel(transform); bool shouldRedraw = prevLevel != tileProvider.Level; if (e.PropertyName == "Visible") { DataRect currVisible = (DataRect)e.NewValue; shouldRedraw |= !(drawnBounds.Contains(currVisible) || showsWholeMap); } else if (e.PropertyName == "Transform") { } if (shouldRedraw) { BeginInvalidateVisual(); } }
protected internal override IEnumerable <Point> Filter(IEnumerable <Point> series) { prevOutput = Output; var visible = Visible; prevVisible = visible; bounds = DataRect.FromCenterSize(visible.GetCenter(), new Size(visible.Width * visibleIncreaseRatio, visible.Height * visibleIncreaseRatio)); //IParallelEnumerable<Point> parallel = (IParallelEnumerable<Point>)series; //Trace.WriteLine("In BoundsFilter: " + Environment.TickCount); IEnumerable <Point> result; if (Environment.FirstDraw) { result = series; } else { result = series.Where(p => bounds.Contains(p)); } return(result); }
private void UpdateUIRepresentation() { foreach (var path in linePaths) { LevelLine line = (LevelLine)path.Tag; path.Data = CreateGeometry(line); } var transform = Plotter2D.Viewport.Transform; Rect output = Plotter2D.Viewport.Output; DataRect visible = Plotter2D.Viewport.Visible; if (rebuildText) { foreach (var text in textBlocks) { if (text.Visibility == Visibility.Visible) { content.Children.Remove(text); } } textBlocks.Clear(); double wayBeforeText = new Rect(new Size(100, 100)).ScreenToData(transform).Width; Annotater.WayBeforeText = wayBeforeText; var textLabels = Annotater.Annotate(Collection, Plotter2D.Viewport.Visible); foreach (var textLabel in textLabels) { TextBlock text = CreateTextLabel(textLabel); textBlocks.Add(text); if (visible.Contains(textLabel.Position)) { content.Children.Add(text); } else { text.Visibility = Visibility.Hidden; } } } else { foreach (var text in textBlocks) { IsolineTextLabel label = (IsolineTextLabel)text.Tag; Point screenPos = label.Position.DataToScreen(transform); Size textSize = text.DesiredSize; Point position = new Point(screenPos.X - textSize.Width / 2, screenPos.Y - textSize.Height / 2); if (output.Contains(position)) { Canvas.SetLeft(text, position.X); Canvas.SetTop(text, position.Y); if (text.Visibility == Visibility.Hidden) { text.Visibility = Visibility.Visible; content.Children.Add(text); } } else if (text.Visibility == Visibility.Visible) { text.Visibility = Visibility.Hidden; content.Children.Remove(text); } } } }