few changes to the source and one potential issue found

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

chage wrote at 2013-05-03 19:35:

Hi objo,
I started to use oxyplot not long ago, thanks for the great library.
While developing I traced into oxyplot source and make some changes. Need to know if the changes are good, and could it be included into official trunk?
  1. Added "Resolution" properties to LineSeries to give option on lower resolution drawing in high data count use case.
  2. BoxPlotSeries GetNearestPoint TrackerHitResult.Text should return DateTime for DateTimeAxis.
 -                            result.DataPoint.X,
+                            this.XAxis != null ? this.XAxis.GetValue(result.DataPoint.X) : result.DataPoint.X,
  1. RenderingExtension DrawClippedLine exception when trying to draw a line with single point. So I added a check for single point case and create an offset just like what the code did in latter single point case. Not sure if this is the best way.
// render the line if we are leaving the clipping region););
                    if (!clipping.IsInside(s1))
                        if (pts.Count > 0)
                          // Check if the line contains a single point
                          if (pts.Count == 1) {
                            // Add a second point to make sure the line is being rendered as a small dot
                            pts.Add(new ScreenPoint(pts[0].X + 1, pts[0].Y));
                            pts[0] = new ScreenPoint(pts[0].X - 1, pts[0].Y);

                                pts, stroke, strokeThickness, lineStyle.GetDashArray(), lineJoin, aliased);
                            if (pointsRendered != null)

                            pts = new List<ScreenPoint>();

objo wrote at 2013-05-06 10:29:

thanks for the bug reports and correction code! I have corrected #2 and #3, and added examples to make sure it works.
How did you implement lower resolution in #1? The LineSeries has a MinimumSegmentLength property that works in screen coordinates.
Are you sampling the input data points - I think this could be handled by the application, not by the plotting library.

chage wrote at 2013-05-06 18:17:

Hi objo,
Thanks for the updated code, your changes are much elegant by moving the single point handling to a separate method.

As for #1 (resolution), I simply added a Resolution property to LineSeries and pass it along to RenderingExtensions.DrawMarkers.
            if (this.MarkerType != MarkerType.None)
                    new[] { this.MarkerSize }, 
                    this.Resolution); // added Resolution property and pass it to draw markers
Some background on my intention: I realize the 100K performance test is only good for non-markers line series. When there is markers, the performance degraded drastically due to markers drawing, obviously markers drawing requires much heavier processing than simple line drawing. Hence I try to reduce the number of markers when they overlapped, which is what DrawMarkers resolution argument is doing. Honestly the resolution method that I use (resolution 5) is just slight better than the original code, still not good enough for my application but I will look at possible way to improve that later.

I was considering handling in application code, but found DrawMarkers method to be resolution capable, so i just reuse it. After take a look at MinimumSegmentLeght, it is mainly to optimize line drawing, the markers drawing is not affected by this property, if I read it correctly... But I do see that I can use ScreenPointHelper.ResamplePoints to get resample screenpoints and pass it to DrawMarkers, what do you think?

objo wrote at 2013-06-08 11:55:

ok, I added a MarkerResolution property to the LineSeries.
Note: the last argument of the DrawMarkers method should also be provided when using the resolution argument (otherwise you will get marker flickering when panning)

chage wrote at 2013-06-13 18:35:

Thanks objo, that works great!