ZedGraph: get PointPairList of only visible curve points

How to get PointPairList only for visible curve data, and not for all points in the Curveitem list? This list should change dynamically when zooming or panning.

Thank.

+3
source share
3 answers

There seems to be no ZedGraph API method that does this for you. However, the code below demonstrates the VisiblePoints method, which returns a PointPairList and works in one specific case of using ZedGraph.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ZedGraph;

namespace ZedGraphMain
{
    public class ZedGraphDemo : Form
    {
        public ZedGraphDemo()
        {
            var graphControl = new ZedGraphControl();
            graphControl.Dock = DockStyle.Fill;
            graphControl.IsShowPointValues = true;
            Controls.Add(graphControl);
            var points = new PointPairList();
            for (double i = 0; i <= 5.0; i += 1)
                points.Add(i, i);

            var curve = graphControl.GraphPane.AddCurve("A Label", points, Color.ForestGreen);

            graphControl.RestoreScale(graphControl.GraphPane);
            graphControl.ZoomEvent += (_, __, ___) => LogVisibility(graphControl, curve, points);
        }

        private static PointPairList VisiblePoints(ZedGraphControl control, LineItem lineItem, PointPairList points)
        {
            var pointPairList = new PointPairList();
            pointPairList.AddRange(points.Where(pp => IsVisible(control, lineItem, pp)).ToList());
            return pointPairList;
        }

        private static bool IsVisible(ZedGraphControl control, LineItem lineItem, PointPair point)
        {
            GraphPane pane = control.GraphPane;
            Scale xScale = lineItem.GetXAxis(pane).Scale;
            Scale yScale = lineItem.GetYAxis(pane).Scale;
            return point.X > xScale.Min && point.X < xScale.Max && point.Y > yScale.Min && point.Y < yScale.Max;
        }

        private static void LogVisibility(ZedGraphControl control, LineItem lineItem, PointPairList points)
        {
            List<PointPair> visiblePoints = VisiblePoints(control, lineItem, points);
            Console.Out.WriteLine(DateTime.Now + ": " + string.Join(",", visiblePoints.Select(pp => string.Format("({0:N1}, {1:N1})", pp.X, pp.Y))));
        }
    }
}
+1
source

I believe that PointPairList always contains ALL points.

There are always customized points, it's just how they are converted to pixels using scaling and panning.

, AverageFilteredList . , - ( ):

public class AverageFilteredPointList : IPointList 
{
  <snip>

  public int Count { get; set; }
  public int MaxPts { get; set; }

  public PointPair this[int index] { get; set; }
  public void SetBounds(double min, double max, int maxPts) { }
}

, IPointList, /, , , "" .

, , , GraphPane, , DataPoint :

ReverseTransform(pt, out xSampleData, out ySampleData);
0

FilteredPointList .

It contains a detailed explanation of how to use it, as well as a link to the ZedGraph wiki page .

0
source

All Articles