Beispiel #1
0
        /*
         * Returns true if the iter provided is within the visible
         * rectangle, false otherwise.  If it returns false, the values
         * of x and y will be -1.
         */
        private bool GetPlotPoint(LinePlot plot, TreeIter iter, out int x, out int y)
        {
            x = y = -1;

            IComparable x_val, y_val;

            if (!plot.GetValue(iter, 0, out x_val) ||
                !plot.GetValue(iter, 1, out y_val))
            {
                return(false);
            }

            if (x_axis == null || y_axis == null)
            {
                return(false);
            }

            if (x_axis.IsInRange(x_val) &&
                y_axis.IsInRange(y_val))
            {
                x = GridXToRender(x_axis.ValueToGridCoords(x_val));
                y = GridYToRender(y_axis.ValueToGridCoords(y_val));
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        private void FindPointsInRange(IAxis x_axis, IAxis y_axis, out Point[] points)
        {
            points = new Point[0];

            if ((x_axis == null || !x_axis.HasValidRange) ||
                (y_axis == null || !y_axis.HasValidRange))
            {
                // we need both axes to be valid to draw anything
                return;
            }

            ArrayList points_list = new ArrayList();

            TreeIter iter;

            if (!model.GetIterFirst(out iter))
            {
                return;
            }

            Point prev_point = null;

            do
            {
                IComparable x_val, y_val;
                if (!GetValue(iter, 0, out x_val) ||
                    !GetValue(iter, 1, out y_val))
                {
                    continue;
                }

                // don't clip a gapped point
                if (PointGapFunc != null &&
                    PointGapFunc(model, iter))
                {
                    if (x_axis.IsInRange(x_val))
                    {
                        Point p = new Point(x_axis.ValueToGridCoords(x_val),
                                            y_axis.ValueToGridCoords(y_val),
                                            x_val, y_val);
                        p.IsAGap = true;
                        points_list.Add(p);
                    }
                    continue;
                }

                // create a line segment between the previous
                // point and the current point and see if the
                // segment intersects the viewing plane
                Point b = new Point(x_axis.ValueToGridCoords(x_val),
                                    y_axis.ValueToGridCoords(y_val),
                                    x_val, y_val);
                Point a = new Point(b.X, b.Y, b.XValue, b.YValue);

                if (prev_point != null)
                {
                    a = prev_point;
                }

                // copy b before it becomes clipped
                prev_point = b.Clone() as Point;

                TreePath path = model.GetPath(iter);
                if (selected_path != null &&
                    selected_path.Compare(path) == 0)
                {
                    b.IsSelected = true;
                }

                if (focused_path != null &&
                    focused_path.Compare(path) == 0)
                {
                    b.IsFocused = true;
                }

                if (ClipSegment(x_axis, y_axis, ref a, ref b))
                {
                    if (a != b && a.IsClipped)
                    {
                        points_list.Add(a);
                    }

                    points_list.Add(b);
                }
            } while (model.IterNext(ref iter));

            // Sort this list on the x axis
            points_list.Sort(new PointXAxisIComparer());

            points = (Point[])points_list.ToArray(typeof(Point));
        }