/// <summary> /// This method used to get the chart data index at an SfChart co-ordinates /// </summary> /// <param name="index"></param> /// <returns></returns> internal override int GetDataPointIndex(Point point) { Canvas canvas = Area.GetAdorningCanvas(); double left = Area.ActualWidth - canvas.ActualWidth; double top = Area.ActualHeight - canvas.ActualHeight; ChartDataPointInfo data = null; point.X = point.X - left + Area.Margin.Left; point.Y = point.Y - top + Area.Margin.Top; Point mousePos = new Point(point.X - Area.SeriesClipRect.Left, point.Y - Area.SeriesClipRect.Top); double currentBitmapPixel = (Area.fastRenderSurface.PixelWidth * (int)mousePos.Y + (int)mousePos.X); if (!Area.isBitmapPixelsConverted) { Area.ConvertBitmapPixels(); } if (Pixels.Contains((int)currentBitmapPixel)) { data = GetDataPoint(point); } if (data != null) { return(data.Index); } else { return(-1); } }
public void DrawPoint(int x, int y, Color color) { if (Pixels.Contains(x, y)) { Pixels.SetValue(color, x, y); } }
public override bool Equals(object obj) { foreach (var endPoint in (obj as Line)?.EndPoints) { if (!Pixels.Contains(endPoint)) { return(false); } } return(true); }
public void DrawLine(int ax, int ay, int bx, int by, Color color) { var pixels = GetLinePixels(ax, ay, bx, by); foreach (Point pixel in pixels) { if (Pixels.Contains(pixel.X, pixel.Y)) { Pixels.SetValue(color, pixel.X, pixel.Y); } } }
// REF: https://en.wikipedia.org/wiki/Midpoint_circle_algorithm // REF: https://www.geeksforgeeks.org/mid-point-circle-drawing-algorithm/ // NOTE: This method draws a circle using the Midpoint Circle Algorithm public void DrawCircle(int originX, int originY, int radius, Color color) { var pixels = GetCirclePixels(originX, originY, radius); foreach (Point pixel in pixels) { if (Pixels.Contains(pixel.X, pixel.Y)) { Pixels.SetValue(color, pixel.X, pixel.Y); } } }
/// <summary> /// Method used to return the hittest series while mouse action. /// </summary> /// <returns></returns> internal virtual bool IsHitTestSeries() { if (!Area.isBitmapPixelsConverted) { Area.ConvertBitmapPixels(); } if (Pixels.Contains(Area.currentBitmapPixel)) { return(true); } return(false); }
public void DrawRectangle(int x, int y, int width, int height, Color color) { var top = GetLinePixels(x, y, x + width, y); var left = GetLinePixels(x, y, x, y + height); var right = GetLinePixels(x + width, y, x + width, y + height); var bottom = GetLinePixels(x, y + height, x + width, y + height); var pixels = new List <Point>(); // TODO: Remove existing points. pixels.AddRange(top); pixels.AddRange(left); pixels.AddRange(right); pixels.AddRange(bottom); foreach (Point pixel in pixels) { if (Pixels.Contains(pixel.X, pixel.Y)) { Pixels.SetValue(color, pixel.X, pixel.Y); } } }
private void OnBitmapHollowSelection(List <int> SegmentPixels, List <int> BorderPixels) { if (SegmentPixels != null && SegmentPixels.Count > 0) { int seriesIndex = Area.Series.IndexOf(this); if (!Area.isBitmapPixelsConverted) { Area.ConvertBitmapPixels(); } // Gets the upper series from the selected series var upperSeriesCollection = (from series in Area.Series where Area.Series.IndexOf(series) > seriesIndex select series).ToList(); // Gets the upper series pixels in to single collection foreach (var series in upperSeriesCollection) { upperSeriesPixels.UnionWith(series.Pixels); } { byte[] buffer = Area.GetFastBuffer(); int j = 0; Color SegmentColor = Colors.Transparent; Color BorderColor = ((Segments[0] as FastCandleBitmapSegment).GetSegmentBrush(dataPoint.Index)); foreach (var pixel in SegmentPixels) { if (Pixels.Contains(pixel) && !upperSeriesPixels.Contains(pixel)) { buffer[pixel] = SegmentColor.A; } } foreach (var pixel1 in BorderPixels) { if (Pixels.Contains(pixel1) && !upperSeriesPixels.Contains(pixel1)) { if (j == 0) { buffer[pixel1] = BorderColor.B; j = j + 1; } else if (j == 1) { buffer[pixel1] = BorderColor.G; j = j + 1; } else if (j == 2) { buffer[pixel1] = BorderColor.R; j = j + 1; } else if (j == 3) { buffer[pixel1] = BorderColor.A; j = 0; } } } Area.RenderToBuffer(); } upperSeriesPixels.Clear(); } }
internal void OnBitmapSelection(List <int> pixels, Brush brush, bool isSelected) { if (pixels != null && pixels.Count > 0) { int seriesIndex = Area.Series.IndexOf(this); if (!Area.isBitmapPixelsConverted) { Area.ConvertBitmapPixels(); } // Gets the upper series from the selected series var upperSeriesCollection = (from series in Area.Series where Area.Series.IndexOf(series) > seriesIndex select series).ToList(); // Gets the upper series pixels in to single collection foreach (var series in upperSeriesCollection) { upperSeriesPixels.UnionWith(series.Pixels); } { byte[] buffer = Area.GetFastBuffer(); int j = 0; Color uiColor; if (isSelected && brush != null) { uiColor = (brush as SolidColorBrush).Color; } else { if (this is FastHiLoOpenCloseBitmapSeries) { uiColor = ((Segments[0] as FastHiLoOpenCloseSegment).GetSegmentBrush(dataPoint.Index)); } else if (this is FastCandleBitmapSeries) { uiColor = ((Segments[0] as FastCandleBitmapSegment).GetSegmentBrush(dataPoint.Index)); } else { Brush interior = GetInteriorColor(dataPoint.Index); var linearGradienBrush = interior as LinearGradientBrush; uiColor = linearGradienBrush != null ? linearGradienBrush.GradientStops[0].Color : (interior as SolidColorBrush).Color; } } foreach (var pixel in pixels) { if (Pixels.Contains(pixel) && !upperSeriesPixels.Contains(pixel)) { if (j == 0) { buffer[pixel] = uiColor.B; j = j + 1; } else if (j == 1) { buffer[pixel] = uiColor.G; j = j + 1; } else if (j == 2) { buffer[pixel] = uiColor.R; j = j + 1; } else if (j == 3) { buffer[pixel] = uiColor.A; j = 0; } } } Area.RenderToBuffer(); } upperSeriesPixels.Clear(); } }
public override string ToString() { return(Enumerable.Range(0, Height) .StrJoin("\n", y => Enumerable.Range(0, Width).StrJoin(x => Pixels.Contains(new Vec(x, y)) ? "#" : "."))); }